Working on the testbed application
This commit is contained in:
parent
be5d635e81
commit
58992169e7
@ -149,7 +149,8 @@ struct GuiState
|
|||||||
mx(-1), my(-1), scroll(0),
|
mx(-1), my(-1), scroll(0),
|
||||||
active(0), hot(0), hotToBe(0), isHot(false), isActive(false), wentActive(false),
|
active(0), hot(0), hotToBe(0), isHot(false), isActive(false), wentActive(false),
|
||||||
dragX(0), dragY(0), dragOrig(0), widgetX(0), widgetY(0), widgetW(100),
|
dragX(0), dragY(0), dragOrig(0), widgetX(0), widgetY(0), widgetW(100),
|
||||||
insideCurrentScroll(false), nextItemSameLine(false), areaId(0), widgetId(0)
|
insideCurrentScroll(false), nextItemSameLine(false), newLinePreviousX(0),
|
||||||
|
areaId(0), widgetId(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +169,7 @@ struct GuiState
|
|||||||
int widgetX, widgetY, widgetW;
|
int widgetX, widgetY, widgetW;
|
||||||
bool insideCurrentScroll;
|
bool insideCurrentScroll;
|
||||||
bool nextItemSameLine;
|
bool nextItemSameLine;
|
||||||
|
int newLinePreviousX;
|
||||||
|
|
||||||
unsigned int areaId;
|
unsigned int areaId;
|
||||||
unsigned int widgetId;
|
unsigned int widgetId;
|
||||||
@ -324,7 +326,7 @@ bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scr
|
|||||||
const int areaHeading = name ? AREA_HEADER : 0;
|
const int areaHeading = name ? AREA_HEADER : 0;
|
||||||
|
|
||||||
g_state.widgetX = x + SCROLL_AREA_PADDING;
|
g_state.widgetX = x + SCROLL_AREA_PADDING;
|
||||||
g_state.widgetY = y+h-areaHeading + (*scroll);
|
g_state.widgetY = y+h-areaHeading + (*scroll) - SCROll_AREA_TOP_PADDING;
|
||||||
g_state.widgetW = w - SCROLL_AREA_PADDING*4;
|
g_state.widgetW = w - SCROLL_AREA_PADDING*4;
|
||||||
g_scrollTop = y-areaHeading+h;
|
g_scrollTop = y-areaHeading+h;
|
||||||
g_scrollBottom = y+SCROLL_AREA_PADDING;
|
g_scrollBottom = y+SCROLL_AREA_PADDING;
|
||||||
@ -339,7 +341,7 @@ bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scr
|
|||||||
g_insideScrollArea = inRect(x, y, w, h, false);
|
g_insideScrollArea = inRect(x, y, w, h, false);
|
||||||
g_state.insideCurrentScroll = g_insideScrollArea;
|
g_state.insideCurrentScroll = g_insideScrollArea;
|
||||||
|
|
||||||
addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 6, imguiRGBA(0,0,0,192));
|
addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 6, imguiRGBA(40,40,40,192));
|
||||||
|
|
||||||
if (name) addGfxCmdText(x+areaHeading/2, y+h-areaHeading/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, name, imguiRGBA(255,255,255,128));
|
if (name) addGfxCmdText(x+areaHeading/2, y+h-areaHeading/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, name, imguiRGBA(255,255,255,128));
|
||||||
|
|
||||||
@ -430,10 +432,10 @@ bool imguiButton(const char* text, bool enabled, int width)
|
|||||||
int w = width > 0 ? width : g_state.widgetW;
|
int w = width > 0 ? width : g_state.widgetW;
|
||||||
int h = BUTTON_HEIGHT;
|
int h = BUTTON_HEIGHT;
|
||||||
if (g_state.nextItemSameLine) {
|
if (g_state.nextItemSameLine) {
|
||||||
g_state.widgetX += width + DEFAULT_HORIZONTAL_SPACING;
|
g_state.widgetX += width;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
g_state.widgetY -= BUTTON_HEIGHT + DEFAULT_VERTICAL_SPACING;
|
g_state.widgetY -= BUTTON_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool over = enabled && inRect(x, y, w, h);
|
bool over = enabled && inRect(x, y, w, h);
|
||||||
@ -482,7 +484,12 @@ bool imguiCheck(const char* text, bool checked, bool enabled)
|
|||||||
int y = g_state.widgetY - BUTTON_HEIGHT;
|
int y = g_state.widgetY - BUTTON_HEIGHT;
|
||||||
int w = g_state.widgetW;
|
int w = g_state.widgetW;
|
||||||
int h = BUTTON_HEIGHT;
|
int h = BUTTON_HEIGHT;
|
||||||
g_state.widgetY -= BUTTON_HEIGHT + DEFAULT_VERTICAL_SPACING;
|
if (g_state.nextItemSameLine) {
|
||||||
|
g_state.widgetX += w;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g_state.widgetY -= BUTTON_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
bool over = enabled && inRect(x, y, w, h);
|
bool over = enabled && inRect(x, y, w, h);
|
||||||
bool res = buttonLogic(id, over);
|
bool res = buttonLogic(id, over);
|
||||||
@ -626,40 +633,35 @@ bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vin
|
|||||||
return res || valChanged;
|
return res || valChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiStartLineOfItems() {
|
void imguiStartLine() {
|
||||||
g_state.nextItemSameLine = true;
|
g_state.nextItemSameLine = true;
|
||||||
|
g_state.newLinePreviousX = g_state.widgetX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiEndLineOfItems() {
|
void imguiEndLine() {
|
||||||
g_state.nextItemSameLine = false;
|
g_state.nextItemSameLine = false;
|
||||||
|
g_state.widgetX = g_state.newLinePreviousX;
|
||||||
|
g_state.newLinePreviousX = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiIndent()
|
void imguiVerticalSpace(int spaceY)
|
||||||
{
|
{
|
||||||
g_state.widgetX += INDENT_SIZE;
|
g_state.widgetY -= spaceY;
|
||||||
g_state.widgetW -= INDENT_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiUnindent()
|
void imguiHorizontalSpace(int spaceX) {
|
||||||
{
|
g_state.widgetX += spaceX;
|
||||||
g_state.widgetX -= INDENT_SIZE;
|
|
||||||
g_state.widgetW += INDENT_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void imguiSeparator()
|
|
||||||
{
|
|
||||||
g_state.widgetY -= DEFAULT_VERTICAL_SPACING*3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiSeparatorLine()
|
void imguiSeparatorLine()
|
||||||
{
|
{
|
||||||
int x = g_state.widgetX;
|
int x = g_state.widgetX;
|
||||||
int y = g_state.widgetY - DEFAULT_VERTICAL_SPACING*2;
|
int y = g_state.widgetY;
|
||||||
int w = g_state.widgetW;
|
int w = g_state.widgetW;
|
||||||
int h = 1;
|
int h = SEPARATOR_LINE_WIDTH;
|
||||||
g_state.widgetY -= DEFAULT_VERTICAL_SPACING*4;
|
g_state.widgetY -= SEPARATOR_LINE_WIDTH;
|
||||||
|
|
||||||
addGfxCmdRect((float)x, (float)y, (float)w, (float)h, imguiRGBA(255,255,255,32));
|
addGfxCmdRect((float)x, (float)y, (float)w, (float)h, imguiRGBA(255,255,255,70));
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiDrawText(int x, int y, int align, const char* text, unsigned int color)
|
void imguiDrawText(int x, int y, int align, const char* text, unsigned int color)
|
||||||
|
|||||||
@ -23,16 +23,18 @@
|
|||||||
#define IMGUI_H
|
#define IMGUI_H
|
||||||
|
|
||||||
static const int BUTTON_HEIGHT = 40;
|
static const int BUTTON_HEIGHT = 40;
|
||||||
static const int SLIDER_HEIGHT = 20;
|
static const int SLIDER_HEIGHT = 30;
|
||||||
static const int SLIDER_MARKER_WIDTH = 10;
|
static const int SLIDER_MARKER_WIDTH = 10;
|
||||||
static const int CHECK_SIZE = 18;
|
static const int CHECK_SIZE = 18;
|
||||||
static const int DEFAULT_VERTICAL_SPACING = 14;
|
static const int DEFAULT_VERTICAL_SPACING = 14;
|
||||||
static const int DEFAULT_HORIZONTAL_SPACING = 14;
|
static const int DEFAULT_HORIZONTAL_SPACING = 14;
|
||||||
static const int TEXT_HEIGHT = 16;
|
static const int TEXT_HEIGHT = 16;
|
||||||
static const int FONT_HEIGHT = 30;
|
static const int FONT_HEIGHT = 30;
|
||||||
static const int SCROLL_AREA_PADDING = 6;
|
static const int SCROll_AREA_TOP_PADDING = 5;
|
||||||
|
static const int SCROLL_AREA_PADDING = 5;
|
||||||
static const int INDENT_SIZE = 16;
|
static const int INDENT_SIZE = 16;
|
||||||
static const int AREA_HEADER = 28;
|
static const int AREA_HEADER = 20;
|
||||||
|
static const int SEPARATOR_LINE_WIDTH = 2;
|
||||||
|
|
||||||
enum imguiMouseButton
|
enum imguiMouseButton
|
||||||
{
|
{
|
||||||
@ -58,11 +60,12 @@ void imguiEndFrame();
|
|||||||
bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scroll);
|
bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scroll);
|
||||||
void imguiEndScrollArea();
|
void imguiEndScrollArea();
|
||||||
|
|
||||||
void imguiStartLineOfItems();
|
void imguiStartLine();
|
||||||
void imguiEndLineOfItems();
|
void imguiEndLine();
|
||||||
void imguiIndent();
|
void imguiIndent();
|
||||||
void imguiUnindent();
|
void imguiUnindent();
|
||||||
void imguiSeparator();
|
void imguiVerticalSpace(int spaceY);
|
||||||
|
void imguiHorizontalSpace(int spaceX);
|
||||||
void imguiSeparatorLine();
|
void imguiSeparatorLine();
|
||||||
|
|
||||||
bool imguiButton(const char* text, bool enabled = true, int width = -1);
|
bool imguiButton(const char* text, bool enabled = true, int width = -1);
|
||||||
|
|||||||
@ -96,7 +96,9 @@ void Gui::displayHeader() {
|
|||||||
app.mWindowToFramebufferRatio.x * windowWidth,
|
app.mWindowToFramebufferRatio.x * windowWidth,
|
||||||
app.mWindowToFramebufferRatio.y * HEADER_HEIGHT, &scrollarea);
|
app.mWindowToFramebufferRatio.y * HEADER_HEIGHT, &scrollarea);
|
||||||
|
|
||||||
imguiStartLineOfItems();
|
imguiHorizontalSpace(10);
|
||||||
|
imguiVerticalSpace(20);
|
||||||
|
imguiStartLine();
|
||||||
|
|
||||||
// ----- Left Pane Header ----- //
|
// ----- Left Pane Header ----- //
|
||||||
|
|
||||||
@ -104,18 +106,20 @@ void Gui::displayHeader() {
|
|||||||
if (imguiButton(app.mTimer.isRunning() ? "Pause" : "Play", true, button_width)) {
|
if (imguiButton(app.mTimer.isRunning() ? "Pause" : "Play", true, button_width)) {
|
||||||
app.togglePlayPauseSimulation();
|
app.togglePlayPauseSimulation();
|
||||||
}
|
}
|
||||||
|
imguiHorizontalSpace(5);
|
||||||
|
|
||||||
// Step
|
// Step
|
||||||
if (imguiButton("Step", !app.mTimer.isRunning(), button_width)) {
|
if (imguiButton("Step", !app.mTimer.isRunning(), button_width)) {
|
||||||
app.toggleTakeSinglePhysicsStep();
|
app.toggleTakeSinglePhysicsStep();
|
||||||
}
|
}
|
||||||
|
imguiHorizontalSpace(5);
|
||||||
|
|
||||||
// Restart
|
// Restart
|
||||||
if (imguiButton("Restart", true, button_width)) {
|
if (imguiButton("Restart", true, button_width)) {
|
||||||
app.restartSimulation();
|
app.restartSimulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
imguiEndLineOfItems();
|
imguiEndLine();
|
||||||
imguiEndScrollArea();
|
imguiEndScrollArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,21 +135,30 @@ void Gui::displayLeftPane() {
|
|||||||
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
||||||
app.mWindowToFramebufferRatio.y * LEFT_PANE_HEADER_HEIGHT, &scrollarea);
|
app.mWindowToFramebufferRatio.y * LEFT_PANE_HEADER_HEIGHT, &scrollarea);
|
||||||
|
|
||||||
imguiStartLineOfItems();
|
imguiSeparatorLine();
|
||||||
|
imguiVerticalSpace(5);
|
||||||
|
imguiStartLine();
|
||||||
|
|
||||||
// ----- Left Pane Header ----- //
|
// ----- Left Pane Header ----- //
|
||||||
int widthButton = app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH / 5;
|
int widthButton = app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH / 4.3;
|
||||||
if (imguiButton("Scenes", true, widthButton)) {
|
if (imguiButton("Scenes", true, widthButton)) {
|
||||||
mLeftPane = SCENES;
|
mLeftPane = SCENES;
|
||||||
}
|
}
|
||||||
|
imguiHorizontalSpace(5);
|
||||||
|
|
||||||
if (imguiButton("Physics", true, widthButton)) {
|
if (imguiButton("Physics", true, widthButton)) {
|
||||||
mLeftPane = PHYSICS;
|
mLeftPane = PHYSICS;
|
||||||
}
|
}
|
||||||
|
imguiHorizontalSpace(5);
|
||||||
|
|
||||||
imguiButton("Rendering", true, widthButton);
|
imguiButton("Rendering", true, widthButton);
|
||||||
|
imguiHorizontalSpace(5);
|
||||||
|
|
||||||
imguiButton("Profiling", true, widthButton);
|
imguiButton("Profiling", true, widthButton);
|
||||||
imguiEndLineOfItems();
|
|
||||||
|
imguiEndLine();
|
||||||
|
imguiVerticalSpace(BUTTON_HEIGHT + 8);
|
||||||
|
imguiSeparatorLine();
|
||||||
imguiEndScrollArea();
|
imguiEndScrollArea();
|
||||||
|
|
||||||
// Display the left pane content
|
// Display the left pane content
|
||||||
@ -175,6 +188,8 @@ void Gui::displayScenesPane() {
|
|||||||
app.mWindowToFramebufferRatio.y * (windowHeight - HEADER_HEIGHT - LEFT_PANE_HEADER_HEIGHT),
|
app.mWindowToFramebufferRatio.y * (windowHeight - HEADER_HEIGHT - LEFT_PANE_HEADER_HEIGHT),
|
||||||
&scrollarea);
|
&scrollarea);
|
||||||
|
|
||||||
|
imguiVerticalSpace(15);
|
||||||
|
|
||||||
// For each scene
|
// For each scene
|
||||||
for (int i=0; i<scenes.size(); i++) {
|
for (int i=0; i<scenes.size(); i++) {
|
||||||
|
|
||||||
@ -203,6 +218,8 @@ void Gui::displayPhysicsPane() {
|
|||||||
app.mWindowToFramebufferRatio.y * (windowHeight - HEADER_HEIGHT - LEFT_PANE_HEADER_HEIGHT),
|
app.mWindowToFramebufferRatio.y * (windowHeight - HEADER_HEIGHT - LEFT_PANE_HEADER_HEIGHT),
|
||||||
&scrollarea);
|
&scrollarea);
|
||||||
|
|
||||||
|
imguiVerticalSpace(15);
|
||||||
|
|
||||||
// Enabled/Disable Sleeping
|
// Enabled/Disable Sleeping
|
||||||
bool toggle = imguiCheck("Sleeping enabled", app.mEngineSettings.isSleepingEnabled);
|
bool toggle = imguiCheck("Sleeping enabled", app.mEngineSettings.isSleepingEnabled);
|
||||||
if (toggle) {
|
if (toggle) {
|
||||||
@ -302,7 +319,8 @@ void Gui::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
imguiBeginFrame(app.mWindowToFramebufferRatio.x * mouseX,
|
imguiBeginFrame(app.mWindowToFramebufferRatio.x * mouseX,
|
||||||
app.mWindowToFramebufferRatio.y * (windowHeight - mouseY), mousebutton, -mScrollY);
|
app.mWindowToFramebufferRatio.y * (windowHeight - mouseY), mousebutton,
|
||||||
|
- app.mWindowToFramebufferRatio.y * mScrollY);
|
||||||
resetScroll();
|
resetScroll();
|
||||||
|
|
||||||
displayHeader();
|
displayHeader();
|
||||||
|
|||||||
@ -37,7 +37,7 @@
|
|||||||
const float GUI_SCALING = 2.0f;
|
const float GUI_SCALING = 2.0f;
|
||||||
const int HEADER_HEIGHT = 80;
|
const int HEADER_HEIGHT = 80;
|
||||||
const int LEFT_PANE_WIDTH = 300;
|
const int LEFT_PANE_WIDTH = 300;
|
||||||
const int LEFT_PANE_HEADER_HEIGHT = 60;
|
const int LEFT_PANE_HEADER_HEIGHT = 50;
|
||||||
|
|
||||||
using namespace openglframework;
|
using namespace openglframework;
|
||||||
|
|
||||||
|
|||||||
@ -131,7 +131,7 @@ void TestbedApplication::init() {
|
|||||||
glfwSetScrollCallback(mWindow, scroll);
|
glfwSetScrollCallback(mWindow, scroll);
|
||||||
|
|
||||||
// Define the background color (black)
|
// Define the background color (black)
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0, 0, 0, 1.0);
|
||||||
|
|
||||||
// Create all the scenes
|
// Create all the scenes
|
||||||
createScenes();
|
createScenes();
|
||||||
@ -164,7 +164,7 @@ void TestbedApplication::createScenes() {
|
|||||||
mScenes.push_back(raycastScene);
|
mScenes.push_back(raycastScene);
|
||||||
|
|
||||||
assert(mScenes.size() > 0);
|
assert(mScenes.size() > 0);
|
||||||
mCurrentScene = mScenes[1];
|
mCurrentScene = mScenes[0];
|
||||||
|
|
||||||
// Get the engine settings from the scene
|
// Get the engine settings from the scene
|
||||||
mEngineSettings = mCurrentScene->getEngineSettings();
|
mEngineSettings = mCurrentScene->getEngineSettings();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user