gui refactor
This commit is contained in:
@@ -8,6 +8,12 @@
|
|||||||
|
|
||||||
static std::string equationsResultImage;
|
static std::string equationsResultImage;
|
||||||
|
|
||||||
|
struct GuiMatrix {
|
||||||
|
std::vector<std::vector<int>> matrixValues;
|
||||||
|
int matrixSizeX = 4;
|
||||||
|
int matrixSizeY = 4;
|
||||||
|
};
|
||||||
|
|
||||||
static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
|
static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
|
||||||
Matrix result {data.size(), data.empty() ? 0 : data[0].size()};
|
Matrix result {data.size(), data.empty() ? 0 : data[0].size()};
|
||||||
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
||||||
@@ -45,41 +51,35 @@ static std::string PrintVect(const Vect& vect) {
|
|||||||
|
|
||||||
void PivotGui::Init() {}
|
void PivotGui::Init() {}
|
||||||
|
|
||||||
void PivotGui::Render() {
|
static void RenderSystemTab() {}
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
static std::vector<std::vector<int>> matrixValues;
|
|
||||||
static int matrixSizeX = 4;
|
|
||||||
static int matrixSizeY = 4;
|
|
||||||
static Solver solver;
|
|
||||||
|
|
||||||
static bool refresh = true;
|
|
||||||
|
|
||||||
|
static void RenderLeftGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
|
||||||
// divisions des fenetres
|
// divisions des fenetres
|
||||||
ImVec2 topLeftWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y);
|
ImVec2 topLeftWindowSize(ImGui::GetContentRegionAvail().x * 0.5f, 0);
|
||||||
ImVec2 topRightWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y);
|
|
||||||
|
|
||||||
// Begin fenetre top left
|
// Begin fenetre top left
|
||||||
ImGui::SetNextWindowSize(topLeftWindowSize);
|
// ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
|
ImGui::BeginChild("Left Top Window", topLeftWindowSize, ImGuiChildFlags_Border);
|
||||||
ImGui::Begin("Left Top Window", nullptr,
|
/*ImGui::Begin(, nullptr,
|
||||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
*/
|
||||||
|
// ImGui::BeginTabBar("MainMenu");
|
||||||
|
|
||||||
// Get window position
|
// Get window position
|
||||||
ImVec2 windowPos = ImGui::GetWindowPos();
|
ImVec2 windowPos = ImGui::GetWindowPos();
|
||||||
|
|
||||||
ImGui::Text("Matrice initiale:");
|
ImGui::Text("Matrice initiale:");
|
||||||
|
|
||||||
if (ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY))
|
if (ImGui::InputInt("##RowsMatriceInitiale", &guiMatrix.matrixSizeY))
|
||||||
refresh = true;
|
refresh = true;
|
||||||
matrixSizeY = std::max(1, matrixSizeY);
|
guiMatrix.matrixSizeY = std::max(1, guiMatrix.matrixSizeY);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text("Lignes");
|
ImGui::Text("Lignes");
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX))
|
if (ImGui::InputInt("##ColumnsMatriceInitiale", &guiMatrix.matrixSizeX))
|
||||||
refresh = true;
|
refresh = true;
|
||||||
matrixSizeX = std::max(1, matrixSizeX);
|
guiMatrix.matrixSizeX = std::max(1, guiMatrix.matrixSizeX);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text("Colonnes");
|
ImGui::Text("Colonnes");
|
||||||
|
|
||||||
@@ -90,19 +90,19 @@ void PivotGui::Render() {
|
|||||||
// Resize matrixValues and initialize new elements to 0
|
// Resize matrixValues and initialize new elements to 0
|
||||||
|
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
matrixValues.resize(matrixSizeY);
|
guiMatrix.matrixValues.resize(guiMatrix.matrixSizeY);
|
||||||
for (auto& row : matrixValues) {
|
for (auto& row : guiMatrix.matrixValues) {
|
||||||
row.resize(matrixSizeX, 0);
|
row.resize(guiMatrix.matrixSizeX, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < matrixSizeY; y++) {
|
for (int y = 0; y < guiMatrix.matrixSizeY; y++) {
|
||||||
for (int x = 0; x < matrixSizeX; x++) {
|
for (int x = 0; x < guiMatrix.matrixSizeX; x++) {
|
||||||
if (x > 0)
|
if (x > 0)
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::PushID(y * matrixSizeX + x);
|
ImGui::PushID(y * guiMatrix.matrixSizeX + x);
|
||||||
ImGui::PushItemWidth(60); // Adjust this value to change the cell size
|
ImGui::PushItemWidth(60); // Adjust this value to change the cell size
|
||||||
if (ImGui::InputInt("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
|
if (ImGui::InputInt("", &guiMatrix.matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
|
||||||
refresh = true;
|
refresh = true;
|
||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
@@ -116,7 +116,7 @@ void PivotGui::Render() {
|
|||||||
ImGui::Text("Matrice échelonnée:");
|
ImGui::Text("Matrice échelonnée:");
|
||||||
|
|
||||||
// Convert the "result" string back to a matrix
|
// Convert the "result" string back to a matrix
|
||||||
Matrix resultMatrix = LoadMatrixFromStdVect(matrixValues);
|
Matrix resultMatrix = LoadMatrixFromStdVect(guiMatrix.matrixValues);
|
||||||
|
|
||||||
// Apply the Gauss-Jordan elimination to the matrix
|
// Apply the Gauss-Jordan elimination to the matrix
|
||||||
Gauss::GaussJordan(resultMatrix, true, true); // Assuming you want to reduce and normalize the matrix
|
Gauss::GaussJordan(resultMatrix, true, true); // Assuming you want to reduce and normalize the matrix
|
||||||
@@ -134,13 +134,17 @@ void PivotGui::Render() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End(); // End fenetre top left
|
ImGui::EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RenderRightGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
|
||||||
|
static Solver solver;
|
||||||
// Begin fenetre top right
|
// Begin fenetre top right
|
||||||
ImGui::SetNextWindowSize(topRightWindowSize);
|
// ImGui::SetNextWindowSize(topRightWindowSize);
|
||||||
ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
|
// ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
|
||||||
ImGui::Begin("Right Top Window", nullptr,
|
ImGui::BeginChild("Right Top Window", {0, 0}, ImGuiChildFlags_Border);
|
||||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
// ImGui::Begin("Right Top Window", nullptr,
|
||||||
|
// ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
|
||||||
// rajouter le code pour la partie top right
|
// rajouter le code pour la partie top right
|
||||||
|
|
||||||
@@ -149,7 +153,7 @@ void PivotGui::Render() {
|
|||||||
if (refresh) {
|
if (refresh) {
|
||||||
|
|
||||||
// Calculate the kernel and image
|
// Calculate the kernel and image
|
||||||
Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues));
|
Vect image = solver.Image(LoadMatrixFromStdVect(guiMatrix.matrixValues));
|
||||||
Matrix linearSystem = image.GetLinearSystem();
|
Matrix linearSystem = image.GetLinearSystem();
|
||||||
|
|
||||||
// Store the equationsResult strings in the global variable
|
// Store the equationsResult strings in the global variable
|
||||||
@@ -162,9 +166,9 @@ void PivotGui::Render() {
|
|||||||
equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n";
|
equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
result = std::string("Noyau: ") + "\n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" +
|
result = std::string("Noyau: ") + "\n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" +
|
||||||
"Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + "Image: " + "\n" +
|
"\n" + "Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" + "\n" +
|
||||||
PrintVect(image);
|
"Image: " + "\n" + PrintVect(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh = false;
|
refresh = false;
|
||||||
@@ -176,7 +180,45 @@ void PivotGui::Render() {
|
|||||||
|
|
||||||
ImGui::TextWrapped("%s", result.c_str());
|
ImGui::TextWrapped("%s", result.c_str());
|
||||||
|
|
||||||
ImGui::End(); // End fenetre top right
|
ImGui::EndChild(); // End fenetre top right
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RenderGaussTab() {
|
||||||
|
static GuiMatrix guiMatrix;
|
||||||
|
static bool refresh = true;
|
||||||
|
|
||||||
|
RenderLeftGaussChild(refresh, guiMatrix);
|
||||||
|
ImGui::SameLine();
|
||||||
|
RenderRightGaussChild(refresh, guiMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RenderMainWindow() {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
ImGui::SetNextWindowSize(io.DisplaySize);
|
||||||
|
ImGui::SetNextWindowPos({0, 0});
|
||||||
|
ImGui::Begin("MainWindow", nullptr,
|
||||||
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
ImGui::BeginTabBar("MainBar");
|
||||||
|
if (ImGui::BeginTabItem("Noyau et Image")) {
|
||||||
|
RenderGaussTab();
|
||||||
|
ImGui::EndTabItem();
|
||||||
|
}
|
||||||
|
if (ImGui::BeginTabItem("Systèmes")) {
|
||||||
|
RenderSystemTab();
|
||||||
|
ImGui::EndTabItem();
|
||||||
|
}
|
||||||
|
ImGui::EndTabBar();
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PivotGui::Render() {
|
||||||
|
|
||||||
|
RenderMainWindow();
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
ImGui::ShowDemoWindow(nullptr);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PivotGui::Destroy() {}
|
void PivotGui::Destroy() {}
|
||||||
Reference in New Issue
Block a user