diff --git a/testbed/imgui/imgui.cpp b/testbed/imgui/imgui.cpp index 6c962314..27f84fe2 100644 --- a/testbed/imgui/imgui.cpp +++ b/testbed/imgui/imgui.cpp @@ -422,44 +422,49 @@ void imguiEndScrollArea() g_state.insideCurrentScroll = false; } -bool imguiButton(const char* text, bool enabled, int width) +bool imguiButton(const char* text, bool enabled, int width, int height, float scaleX, float scaleY) { g_state.widgetId++; unsigned int id = (g_state.areaId<<16) | g_state.widgetId; + int textHeight = TEXT_HEIGHT * scaleY; + int h = height > 0 ? height : BUTTON_HEIGHT; int x = g_state.widgetX; - int y = g_state.widgetY - BUTTON_HEIGHT; + int y = g_state.widgetY - h; int w = width > 0 ? width : g_state.widgetW; - int h = BUTTON_HEIGHT; if (g_state.nextItemSameLine) { g_state.widgetX += width; } else { - g_state.widgetY -= BUTTON_HEIGHT; + g_state.widgetY -= h; } bool over = enabled && inRect(x, y, w, h); bool res = buttonLogic(id, over); - addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, (float)BUTTON_HEIGHT/2-1, imguiRGBA(128,128,128, isActive(id)?196:96)); + addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, (float)h/2-1, imguiRGBA(128,128,128, isActive(id)?196:96)); if (enabled) - addGfxCmdText(x+w/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_CENTER, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200)); + addGfxCmdText(x+w/2, y+h/2-textHeight/2, IMGUI_ALIGN_CENTER, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200)); else - addGfxCmdText(x+w/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_CENTER, text, imguiRGBA(128,128,128,200)); + addGfxCmdText(x+w/2, y+h/2-textHeight/2, IMGUI_ALIGN_CENTER, text, imguiRGBA(128,128,128,200)); return res; } -bool imguiItem(const char* text, bool enabled) +bool imguiItem(const char* text, bool enabled, float scaleX, float scaleY) { g_state.widgetId++; unsigned int id = (g_state.areaId<<16) | g_state.widgetId; + + int vertSpacing = scaleY * DEFAULT_VERTICAL_SPACING; + int heightItem = scaleY * BUTTON_HEIGHT; + int heightText = scaleY * TEXT_HEIGHT; int x = g_state.widgetX; - int y = g_state.widgetY - BUTTON_HEIGHT; + int y = g_state.widgetY - heightItem; int w = g_state.widgetW; - int h = BUTTON_HEIGHT; - g_state.widgetY -= BUTTON_HEIGHT + DEFAULT_VERTICAL_SPACING; + int h = heightItem; + g_state.widgetY -= heightItem + vertSpacing; bool over = enabled && inRect(x, y, w, h); bool res = buttonLogic(id, over); @@ -468,47 +473,50 @@ bool imguiItem(const char* text, bool enabled) addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 2.0f, imguiRGBA(255,196,0,isActive(id)?196:96)); if (enabled) - addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(255,255,255,200)); + addGfxCmdText(x+heightItem/2, y+heightItem/2-heightText/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(255,255,255,200)); else - addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200)); + addGfxCmdText(x+heightItem/2, y+heightItem/2-heightText/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200)); return res; } -bool imguiCheck(const char* text, bool checked, bool enabled) +bool imguiCheck(const char* text, bool checked, bool enabled, float scaleX, float scaleY) { g_state.widgetId++; unsigned int id = (g_state.areaId<<16) | g_state.widgetId; + int spacingX = DEFAULT_HORIZONTAL_SPACING * scaleX; int x = g_state.widgetX; - int y = g_state.widgetY - BUTTON_HEIGHT; + int heightText = scaleY * TEXT_HEIGHT; + int sizeCheck = scaleY * CHECK_SIZE; + int y = g_state.widgetY - heightText - DEFAULT_VERTICAL_SPACING * scaleY; int w = g_state.widgetW; - int h = BUTTON_HEIGHT; + int h = heightText; if (g_state.nextItemSameLine) { g_state.widgetX += w; } else { - g_state.widgetY -= BUTTON_HEIGHT; + g_state.widgetY -= heightText + DEFAULT_VERTICAL_SPACING * scaleY; } bool over = enabled && inRect(x, y, w, h); bool res = buttonLogic(id, over); - const int cx = x+BUTTON_HEIGHT/2-CHECK_SIZE/2; - const int cy = y+BUTTON_HEIGHT/2-CHECK_SIZE/2; - addGfxCmdRoundedRect((float)cx-3, (float)cy-3, (float)CHECK_SIZE+6, (float)CHECK_SIZE+6, 4, imguiRGBA(128,128,128, isActive(id)?196:96)); + const int cx = x; + const int cy = y+heightText/2-sizeCheck/2; + addGfxCmdRoundedRect((float)cx-3, (float)cy-3, (float)sizeCheck+6, (float)sizeCheck+6, 4, imguiRGBA(128,128,128, isActive(id)?196:96)); if (checked) { if (enabled) - addGfxCmdRoundedRect((float)cx, (float)cy, (float)CHECK_SIZE, (float)CHECK_SIZE, (float)CHECK_SIZE/2-1, imguiRGBA(255,255,255,isActive(id)?255:200)); + addGfxCmdRoundedRect((float)cx, (float)cy, (float)sizeCheck, (float)sizeCheck, (float)sizeCheck/2-1, imguiRGBA(255,255,255,isActive(id)?255:200)); else - addGfxCmdRoundedRect((float)cx, (float)cy, (float)CHECK_SIZE, (float)CHECK_SIZE, (float)CHECK_SIZE/2-1, imguiRGBA(128,128,128,200)); + addGfxCmdRoundedRect((float)cx, (float)cy, (float)sizeCheck, (float)sizeCheck, (float)sizeCheck/2-1, imguiRGBA(128,128,128,200)); } if (enabled) - addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200)); + addGfxCmdText(x+sizeCheck + spacingX, y+heightText/2-sizeCheck/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200)); else - addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200)); + addGfxCmdText(x+sizeCheck + spacingX, y+heightText/2-sizeCheck/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200)); return res; } @@ -564,27 +572,33 @@ void imguiValue(const char* text) addGfxCmdText(x+w-BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_RIGHT, text, imguiRGBA(255,255,255,200)); } -bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled) +bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled, + float scalingX, float scalingY) { g_state.widgetId++; unsigned int id = (g_state.areaId<<16) | g_state.widgetId; + int buttonHeight = BUTTON_HEIGHT * scalingY; + int sliderHeight = SLIDER_HEIGHT * scalingY; + int textHeight = TEXT_HEIGHT * scalingY; + int sliderMarkerWidth = SLIDER_MARKER_WIDTH * scalingX; + int x = g_state.widgetX; - int y = g_state.widgetY - BUTTON_HEIGHT; + int y = g_state.widgetY - buttonHeight; int w = g_state.widgetW; - int h = SLIDER_HEIGHT; - g_state.widgetY -= SLIDER_HEIGHT + DEFAULT_VERTICAL_SPACING; + int h = sliderHeight; + g_state.widgetY -= sliderHeight + DEFAULT_VERTICAL_SPACING * scalingY; addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 4.0f, imguiRGBA(0,0,0,128)); - const int range = w - SLIDER_MARKER_WIDTH; + const int range = w - sliderMarkerWidth; float u = (*val - vmin) / (vmax-vmin); if (u < 0) u = 0; if (u > 1) u = 1; int m = (int)(u * range); - bool over = enabled && inRect(x+m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT); + bool over = enabled && inRect(x+m, y, sliderMarkerWidth, sliderHeight); bool res = buttonLogic(id, over); bool valChanged = false; @@ -608,9 +622,9 @@ bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vin } if (isActive(id)) - addGfxCmdRoundedRect((float)(x+m), (float)y, (float)SLIDER_MARKER_WIDTH, (float)SLIDER_HEIGHT, 4.0f, imguiRGBA(255,255,255,255)); + addGfxCmdRoundedRect((float)(x+m), (float)y, (float)sliderMarkerWidth, (float)sliderHeight, 4.0f, imguiRGBA(255,255,255,255)); else - addGfxCmdRoundedRect((float)(x+m), (float)y, (float)SLIDER_MARKER_WIDTH, (float)SLIDER_HEIGHT, 4.0f, isHot(id) ? imguiRGBA(255,196,0,128) : imguiRGBA(255,255,255,64)); + addGfxCmdRoundedRect((float)(x+m), (float)y, (float)sliderMarkerWidth, (float)sliderHeight, 4.0f, isHot(id) ? imguiRGBA(255,196,0,128) : imguiRGBA(255,255,255,64)); // TODO: fix this, take a look at 'nicenum'. int digits = (int)(ceilf(log10f(vinc))); @@ -621,13 +635,13 @@ bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vin if (enabled) { - addGfxCmdText(x+SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200)); - addGfxCmdText(x+w-SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_RIGHT, msg, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200)); + addGfxCmdText(x+sliderHeight/2, y+sliderHeight/2-textHeight/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200)); + addGfxCmdText(x+w-sliderHeight/2, y+sliderHeight/2-textHeight/2, IMGUI_ALIGN_RIGHT, msg, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200)); } else { - addGfxCmdText(x+SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200)); - addGfxCmdText(x+w-SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_RIGHT, msg, imguiRGBA(128,128,128,200)); + addGfxCmdText(x+sliderHeight/2, y+sliderHeight/2-textHeight/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200)); + addGfxCmdText(x+w-sliderHeight/2, y+sliderHeight/2-textHeight/2, IMGUI_ALIGN_RIGHT, msg, imguiRGBA(128,128,128,200)); } return res || valChanged; diff --git a/testbed/imgui/imgui.h b/testbed/imgui/imgui.h index 64f28109..4d11fa6c 100644 --- a/testbed/imgui/imgui.h +++ b/testbed/imgui/imgui.h @@ -22,13 +22,13 @@ #ifndef IMGUI_H #define IMGUI_H -static const int BUTTON_HEIGHT = 40; -static const int SLIDER_HEIGHT = 30; -static const int SLIDER_MARKER_WIDTH = 10; -static const int CHECK_SIZE = 18; -static const int DEFAULT_VERTICAL_SPACING = 14; +static const int BUTTON_HEIGHT = 20; +static const int SLIDER_HEIGHT = 20; +static const int SLIDER_MARKER_WIDTH = 5; +static const int CHECK_SIZE = 10; +static const int DEFAULT_VERTICAL_SPACING = 7; static const int DEFAULT_HORIZONTAL_SPACING = 14; -static const int TEXT_HEIGHT = 16; +static const int TEXT_HEIGHT = 10; static const int FONT_HEIGHT = 30; static const int SCROll_AREA_TOP_PADDING = 5; static const int SCROLL_AREA_PADDING = 5; @@ -68,13 +68,13 @@ void imguiVerticalSpace(int spaceY); void imguiHorizontalSpace(int spaceX); void imguiSeparatorLine(); -bool imguiButton(const char* text, bool enabled = true, int width = -1); -bool imguiItem(const char* text, bool enabled = true); -bool imguiCheck(const char* text, bool checked, bool enabled = true); +bool imguiButton(const char* text, bool enabled = true, int width = -1, int height = -1, float scaleX=1, float scaleY=1); +bool imguiItem(const char* text, bool enabled = true, float scaleX=1, float scaleY=1); +bool imguiCheck(const char* text, bool checked, bool enabled = true, float scaleX = 1, float scaleY = 1); bool imguiCollapse(const char* text, const char* subtext, bool checked, bool enabled = true); void imguiLabel(const char* text); void imguiValue(const char* text); -bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled = true); +bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled = true, float scalingX = 1.0f, float scalingY = 1.0f); void imguiDrawText(int x, int y, int align, const char* text, unsigned int color); void imguiDrawLine(float x0, float y0, float x1, float y1, float r, unsigned int color); diff --git a/testbed/src/Gui.cpp b/testbed/src/Gui.cpp index a80ed525..b52668fc 100644 --- a/testbed/src/Gui.cpp +++ b/testbed/src/Gui.cpp @@ -94,6 +94,9 @@ void Gui::displayLeftPane() { TestbedApplication& app = TestbedApplication::getInstance(); + const float scalingX = app.mWindowToFramebufferRatio.x; + const float scalingY = app.mWindowToFramebufferRatio.y; + int windowWidth, windowHeight; glfwGetWindowSize(mWindow, &windowWidth, &windowHeight); @@ -104,60 +107,61 @@ void Gui::displayLeftPane() { // ------ Header ----- // - imguiHorizontalSpace(10); - imguiVerticalSpace(20); + imguiHorizontalSpace(scalingX * 2.5); + imguiVerticalSpace(scalingY * 5); imguiStartLine(); - const int button_width = 150; + const int button_width = app.mWindowToFramebufferRatio.x * 75.0f; + const int button_height = app.mWindowToFramebufferRatio.y * 20.0f; // Play/Pause - if (imguiButton(app.mTimer.isRunning() ? "Pause" : "Play", true, button_width)) { + if (imguiButton(app.mTimer.isRunning() ? "Pause" : "Play", true, button_width, button_height, scalingX, scalingY)) { app.togglePlayPauseSimulation(); } - imguiHorizontalSpace(5); + imguiHorizontalSpace(scalingX * 2.5); // Step - if (imguiButton("Step", !app.mTimer.isRunning(), button_width)) { + if (imguiButton("Step", !app.mTimer.isRunning(), button_width, button_height, scalingX, scalingY)) { app.toggleTakeSinglePhysicsStep(); } - imguiHorizontalSpace(5); + imguiHorizontalSpace(scalingX * 2.5); // Restart - if (imguiButton("Restart", true, button_width)) { + if (imguiButton("Restart", true, button_width, button_height, scalingX, scalingY)) { app.restartSimulation(); } imguiEndLine(); - imguiVerticalSpace(70); + imguiVerticalSpace(scalingY * 35); imguiSeparatorLine(); - imguiVerticalSpace(5); + imguiVerticalSpace(scalingY * 2.5); imguiStartLine(); // ----- Left Pane Tabs ----- // int widthButton = app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH / 4.3; - if (imguiButton("Scenes", true, widthButton)) { + if (imguiButton("Scenes", true, widthButton, button_height, scalingX, scalingY)) { mLeftPane = SCENES; } - imguiHorizontalSpace(5); + imguiHorizontalSpace(scalingX * 2.5); - if (imguiButton("Physics", true, widthButton)) { + if (imguiButton("Physics", true, widthButton, button_height, scalingX, scalingY)) { mLeftPane = PHYSICS; } - imguiHorizontalSpace(5); + imguiHorizontalSpace(scalingX * 2.5); - if (imguiButton("Rendering", true, widthButton)) { + if (imguiButton("Rendering", true, widthButton, button_height, scalingX, scalingY)) { mLeftPane = RENDERING; } - imguiHorizontalSpace(5); + imguiHorizontalSpace(scalingX * 2.5); - if (imguiButton("Profiling", true, widthButton)) { + if (imguiButton("Profiling", true, widthButton, button_height, scalingX, scalingY)) { mLeftPane = PROFILING; } imguiEndLine(); - imguiVerticalSpace(BUTTON_HEIGHT + 8); + imguiVerticalSpace(scalingY * (BUTTON_HEIGHT/2 + 15)); imguiSeparatorLine(); imguiEndScrollArea(); @@ -175,6 +179,9 @@ void Gui::displayScenesPane() { TestbedApplication& app = TestbedApplication::getInstance(); + const float scalingX = app.mWindowToFramebufferRatio.x; + const float scalingY = app.mWindowToFramebufferRatio.y; + static int choice = 0; int startChoice = choice; int scrollarea = 1; @@ -194,7 +201,7 @@ void Gui::displayScenesPane() { for (int i=0; igetName().c_str(), choice == i)) { + if (imguiCheck(scenes[i]->getName().c_str(), choice == i, true, scalingX, scalingY)) { choice = i; } } @@ -209,6 +216,9 @@ void Gui::displayPhysicsPane() { TestbedApplication& app = TestbedApplication::getInstance(); + const float scalingX = app.mWindowToFramebufferRatio.x; + const float scalingY = app.mWindowToFramebufferRatio.y; + int windowWidth, windowHeight; glfwGetWindowSize(mWindow, &windowWidth, &windowHeight); @@ -218,66 +228,68 @@ void Gui::displayPhysicsPane() { app.mWindowToFramebufferRatio.y * (windowHeight - LEFT_PANE_HEADER_HEIGHT), &scrollarea); - imguiVerticalSpace(15); + imguiVerticalSpace(10 * scalingY); // Enabled/Disable Sleeping - bool toggle = imguiCheck("Sleeping enabled", app.mEngineSettings.isSleepingEnabled); + bool toggle = imguiCheck("Sleeping enabled", app.mEngineSettings.isSleepingEnabled, true, scalingX, scalingY); if (toggle) { app.mEngineSettings.isSleepingEnabled = !app.mEngineSettings.isSleepingEnabled; } // Enabled/Disable Gravity - toggle = imguiCheck("Gravity enabled", app.mEngineSettings.isGravityEnabled); + toggle = imguiCheck("Gravity enabled", app.mEngineSettings.isGravityEnabled, true, scalingX, scalingY); if (toggle) { app.mEngineSettings.isGravityEnabled = !app.mEngineSettings.isGravityEnabled; } + imguiVerticalSpace(10 * scalingY); + // Timestep float timeStep = app.mEngineSettings.timeStep; - if (imguiSlider("Timestep", &timeStep, 0.001f, 1.0f, 0.001f)) { + if (imguiSlider("Timestep", &timeStep, 0.001f, 1.0f, 0.001f, true, scalingX, scalingY)) { app.mEngineSettings.timeStep = timeStep; } // Nb velocity solver iterations float nbVelocityIterations = static_cast(app.mEngineSettings.nbVelocitySolverIterations); - if (imguiSlider("Velocity Solver Iterations", &nbVelocityIterations, 1.0f, 100.0f, 1.0f)) { + if (imguiSlider("Velocity Solver Iterations", &nbVelocityIterations, 1.0f, 100.0f, 1.0f, true, scalingX, scalingY)) { app.mEngineSettings.nbVelocitySolverIterations = static_cast(nbVelocityIterations); } // Nb position solver iterations float nbPositionIterations = static_cast(app.mEngineSettings.nbPositionSolverIterations); - if (imguiSlider("Position Solver Iterations", &nbPositionIterations, 1.0f, 100.0f, 1.0f)) { + if (imguiSlider("Position Solver Iterations", &nbPositionIterations, 1.0f, 100.0f, 1.0f, true, scalingX, scalingY)) { app.mEngineSettings.nbPositionSolverIterations = static_cast(nbPositionIterations); } // Time before sleep float timeBeforeSleep = app.mEngineSettings.timeBeforeSleep; - if (imguiSlider("Time before sleep", &timeBeforeSleep, 0.0f, 60.0f, 0.5f)) { + if (imguiSlider("Time before sleep", &timeBeforeSleep, 0.0f, 60.0f, 0.5f, true, scalingX, scalingY)) { app.mEngineSettings.timeBeforeSleep = timeBeforeSleep; } // Sleep linear velocity float sleepLinearVelocity = app.mEngineSettings.sleepLinearVelocity; - if (imguiSlider("Sleep linear velocity", &sleepLinearVelocity, 0.0f, 30.0f, 0.5f)) { + if (imguiSlider("Sleep linear velocity", &sleepLinearVelocity, 0.0f, 30.0f, 0.5f, true, scalingX, scalingY)) { app.mEngineSettings.sleepLinearVelocity = sleepLinearVelocity; } // Sleep angular velocity float sleepAngularVelocity = app.mEngineSettings.sleepAngularVelocity; - if (imguiSlider("Sleep angular velocity", &sleepAngularVelocity, 0.0f, 30.0f, 0.5f)) { + if (imguiSlider("Sleep angular velocity", &sleepAngularVelocity, 0.0f, 30.0f, 0.5f, true, scalingX, scalingY)) { app.mEngineSettings.sleepAngularVelocity = sleepAngularVelocity; } // Gravity vector openglframework::Vector3 gravity = app.mEngineSettings.gravity; float gravityX = gravity.x, gravityY = gravity.y, gravityZ = gravity.z; - if (imguiSlider("Gravity X", &gravityX, -50.0f, 50.0f, 0.5f)) { + if (imguiSlider("Gravity X", &gravityX, -50.0f, 50.0f, 0.5f, true, scalingX, scalingY)) { app.mEngineSettings.gravity.x = gravityX; } - if (imguiSlider("Gravity Y", &gravityY, -50.0f, 50.0f, 0.5f)) { + if (imguiSlider("Gravity Y", &gravityY, -50.0f, 50.0f, 0.5f, true, scalingX, scalingY)) { app.mEngineSettings.gravity.y = gravityY; } - if (imguiSlider("Gravity Z", &gravityZ, -50.0f, 50.0f, 0.5f)) { + if (imguiSlider("Gravity Z", &gravityZ, -50.0f, 50.0f, 0.5f, true, scalingX, scalingY)) { app.mEngineSettings.gravity.z = gravityZ; } @@ -288,6 +300,9 @@ void Gui::displayRenderingPane() { TestbedApplication& app = TestbedApplication::getInstance(); + const float scalingX = app.mWindowToFramebufferRatio.x; + const float scalingY = app.mWindowToFramebufferRatio.y; + int windowWidth, windowHeight; glfwGetWindowSize(mWindow, &windowWidth, &windowHeight); @@ -299,21 +314,20 @@ void Gui::displayRenderingPane() { imguiVerticalSpace(15); - // Display/Hide contact points - bool toggleContactPoints = imguiCheck("Contacts", app.mIsContactPointsDisplayed); + bool toggleContactPoints = imguiCheck("Contacts", app.mIsContactPointsDisplayed, true, scalingX, scalingY); if (toggleContactPoints) { app.displayContactPoints(!app.mIsContactPointsDisplayed); } // Enabled/Disable VSync - bool toggleVSync = imguiCheck("V Sync", app.mIsVSyncEnabled); + bool toggleVSync = imguiCheck("V Sync", app.mIsVSyncEnabled, true, scalingX, scalingY); if (toggleVSync) { app.enableVSync(!app.mIsVSyncEnabled); } // Enabled/Disable Shadows - bool toggleShadows = imguiCheck("Shadows", app.mIsShadowMappingEnabled); + bool toggleShadows = imguiCheck("Shadows", app.mIsShadowMappingEnabled, true, scalingX, scalingY); if (toggleShadows) { app.enableShadows(!app.mIsShadowMappingEnabled); } @@ -325,6 +339,9 @@ void Gui::displayProfilingPane() { TestbedApplication& app = TestbedApplication::getInstance(); + const float scalingX = app.mWindowToFramebufferRatio.x; + const float scalingY = app.mWindowToFramebufferRatio.y; + double currentTime = glfwGetTime(); if ((currentTime - mTimeSinceLastProfilingDisplay) > TIME_INTERVAL_DISPLAY_PROFILING_INFO) { mTimeSinceLastProfilingDisplay = currentTime; @@ -348,20 +365,20 @@ void Gui::displayProfilingPane() { std::stringstream ss; ss << std::setprecision(4) << mCachedFPS; std::string fps = std::string("FPS : ") + ss.str(); - imguiItem(fps.c_str()); + imguiItem(fps.c_str(), true, scalingX, scalingY); // Update time std::stringstream ss1; double updateTime = mCachedUpdateTime * 1000.0; ss1 << std::setprecision(4) << updateTime; std::string updateTimeStr = std::string("Update time (ms) : ") + ss1.str(); - imguiItem(updateTimeStr.c_str()); + imguiItem(updateTimeStr.c_str(), true, scalingX, scalingY); // Update time (physics) std::stringstream ss2; ss2 << std::setprecision(4) << (mCachedPhysicsUpdateTime * 1000.0); std::string updatePhysicsTimeStr = std::string("Update physics time (ms) : ") + ss2.str(); - imguiItem(updatePhysicsTimeStr.c_str()); + imguiItem(updatePhysicsTimeStr.c_str(), true, scalingX, scalingY); imguiEndScrollArea(); } diff --git a/testbed/src/Gui.h b/testbed/src/Gui.h index 2bf6ae43..9ce9d033 100644 --- a/testbed/src/Gui.h +++ b/testbed/src/Gui.h @@ -37,6 +37,7 @@ const int LEFT_PANE_WIDTH = 300; const int LEFT_PANE_HEADER_HEIGHT = 90; const double TIME_INTERVAL_DISPLAY_PROFILING_INFO = 0.3; +const int CHECKBOX_SIZE = 9; using namespace openglframework;