I'm trying to draw a grid of the dimensions of m_GCodeBuilder.GetBilletSize().x
by m_GCodeBuilder.GetBilletSize().y
in a new ImGui window right underneath the main menu. My Program
class has a Run
function with the meat of the program. Here it is:
void Program::Run() {
SDL_Event e;
while (m_Running) {
while (SDL_PollEvent(&e)) {
m_Renderer.ProcessEvent(&e);
switch (e.type) {
case SDL_QUIT: {
m_Running = false;
break;
}
case SDL_WINDOWEVENT: {
if (e.window.event == SDL_WINDOWEVENT_RESIZED) {
m_Window.UpdateWindowSize();
}
}
}
}
m_Renderer.NewFrame();
//
// Main Menu Bar
//
if (ImGui::BeginMainMenuBar()) {
// MENU BAR STUFF
ImGui::EndMainMenuBar();
}
float menuHeight = ImGui::GetFrameHeight(); // this is 19
ImVec2 windowSize = ImGui::GetIO().DisplaySize;
// Subtract the height of the menu bar
windowSize.y -= menuHeight;
// Set the position and size of the window
ImGui::SetNextWindowPos(ImVec2(0, menuHeight));
ImGui::SetNextWindowSize(windowSize);
if (ImGui::Begin("Content", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus))
{
// With the billet being 150 x 100 the squareSize ends up being 4 (without resizing the 600 x 600 window)
const auto squareSize = std::min(windowSize.x / m_GCodeBuilder.GetBilletSize().x, windowSize.y / m_GCodeBuilder.GetBilletSize().y);
auto drawList = ImGui::GetWindowDrawList();
ImVec2 windowPos = ImGui::GetWindowPos(); // gets the current position of the cursor in window coordinates
for (std::int32_t i = 0; i < m_GCodeBuilder.GetBilletSize().x; i++) {
for (std::int32_t j = 0; j < m_GCodeBuilder.GetBilletSize().y; j++) {
const ImVec2 markerMin = ImVec2(windowPos.x + i * squareSize, windowPos.y + j * squareSize);
const ImVec2 markerMax = ImVec2(windowPos.x + (i + 1) * squareSize, windowPos.y + (j + 1) * squareSize);
spdlog::info("Window position: ({}, {})", windowPos.x, windowPos.y);
spdlog::info("Marker min: ({}, {})", markerMin.x, markerMin.y);
spdlog::info("Marker max: ({}, {})", markerMax.x, markerMax.y);
if ((i + j) % 2 == 0) {
drawList->AddRectFilled(markerMin, markerMax, ImGui::GetColorU32(m_GridColor1));
} else {
drawList->AddRectFilled(markerMin, markerMax, ImGui::GetColorU32(m_GridColor2));
}
}
}
ImGui::End();
}
m_Renderer.Render();
}
}
What am I doing wrong? Did I mess up the coordinates? I would really appreciate any help, Mike