Working on GUI for testbed application

This commit is contained in:
Daniel Chappuis 2016-03-03 21:46:45 +01:00
parent 7d0b5df216
commit b15d46a95f
3 changed files with 11 additions and 80 deletions

View File

@ -47,7 +47,6 @@ Gui::Gui(TestbedApplication* app) : mApp(app) {
Gui::~Gui() {
//imguiRenderGLDestroy();
}
/// Initialize the GUI
@ -217,7 +216,7 @@ void Gui::createSettingsPanel() {
// Velocity solver iterations
Widget* panelVelocityIterations = new Widget(mPhysicsPanel);
panelVelocityIterations->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Fill, 0, 5));
panelVelocityIterations->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
Label* labelVelocityIterations = new Label(panelVelocityIterations, "Velocity solver","sans-bold");
labelVelocityIterations->setFixedWidth(120);
TextBox* textboxVelocityIterations = new TextBox(panelVelocityIterations);
@ -229,6 +228,8 @@ void Gui::createSettingsPanel() {
try {
float value = std::stof(str);
std::ostringstream out;
out << std::setprecision(0) << std::fixed << value;
if (value < 1 || value > 1000) return false;
@ -246,7 +247,7 @@ void Gui::createSettingsPanel() {
// Position solver iterations
Widget* panelPositionIterations = new Widget(mPhysicsPanel);
panelPositionIterations->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Fill, 0, 5));
panelPositionIterations->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
Label* labelPositionIterations = new Label(panelPositionIterations, "Position solver","sans-bold");
labelPositionIterations->setFixedWidth(120);
TextBox* textboxPositionIterations = new TextBox(panelPositionIterations);
@ -258,6 +259,8 @@ void Gui::createSettingsPanel() {
try {
float value = std::stof(str);
std::ostringstream out;
out << std::setprecision(0) << std::fixed << value;
if (value < 1 || value > 1000) return false;
@ -275,7 +278,7 @@ void Gui::createSettingsPanel() {
// Time before sleep
Widget* panelTimeSleep = new Widget(mPhysicsPanel);
panelTimeSleep->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Fill, 0, 5));
panelTimeSleep->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
Label* labelTimeSleep = new Label(panelTimeSleep, "Time before sleep","sans-bold");
labelTimeSleep->setFixedWidth(120);
out.str("");
@ -307,10 +310,9 @@ void Gui::createSettingsPanel() {
textboxTimeSleep->setFontSize(16);
textboxTimeSleep->setAlignment(TextBox::Alignment::Right);
// Sleep linear velocity
Widget* panelSleepLinearVel = new Widget(mPhysicsPanel);
panelSleepLinearVel->setLayout(new GridLayout(Orientation::Horizontal, 2, Alignment::Middle, 5, 5));
panelSleepLinearVel->setLayout(new GridLayout(Orientation::Horizontal, 2, Alignment::Middle, 0, 5));
Label* labelSleepLinearVel = new Label(panelSleepLinearVel, "Sleep linear velocity","sans-bold");
labelSleepLinearVel->setFixedWidth(120);
out.str("");
@ -344,7 +346,7 @@ void Gui::createSettingsPanel() {
// Sleep angular velocity
Widget* panelSleepAngularVel = new Widget(mPhysicsPanel);
panelSleepAngularVel->setLayout(new GridLayout(Orientation::Horizontal, 2, Alignment::Fill, 5, 5));
panelSleepAngularVel->setLayout(new GridLayout(Orientation::Horizontal, 2, Alignment::Middle, 0, 5));
Label* labelSleepAngularVel = new Label(panelSleepAngularVel, "Sleep angular velocity","sans-bold");
labelSleepAngularVel->setFixedWidth(120);
out.str("");
@ -408,7 +410,7 @@ void Gui::createSettingsPanel() {
void Gui::createProfilingPanel() {
Widget* profilingPanel = new Window(mApp, "Profiling");
profilingPanel->setPosition(Vector2i(15, 530));
profilingPanel->setPosition(Vector2i(15, 525));
profilingPanel->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 5));
profilingPanel->setId("SettingsPanel");
profilingPanel->setFixedWidth(220);

View File

@ -216,7 +216,6 @@ void TestbedApplication::drawContents() {
// Check the OpenGL errors
checkOpenGLErrors();
mGui.update();
// Compute the current framerate
@ -324,17 +323,6 @@ void TestbedApplication::computeFPS() {
mPreviousTime = mCurrentTime;
}
// GLFW error callback method
void TestbedApplication::error_callback(int error, const char* description) {
fputs(description, stderr);
}
// Callback method to receive keyboard events
void TestbedApplication::keyboard(GLFWwindow* window, int key, int scancode,
int action, int mods) {
//getInstance().mCurrentScene->keyboardEvent(key, scancode, action, mods);
}
bool TestbedApplication::keyboardEvent(int key, int scancode, int action, int modifiers) {
if (Screen::keyboardEvent(key, scancode, action, modifiers)) {
@ -387,49 +375,5 @@ bool TestbedApplication::scrollEvent(const Vector2i &p, const Vector2f &rel) {
return true;
}
// Update scroll on the GUI
//Gui::getInstance().setScroll(xAxis, yAxis);
return mCurrentScene->scrollingEvent(rel[0], rel[1], SCROLL_SENSITIVITY);
}
void TestbedApplication::drawAll() {
glClearColor(mBackground[0], mBackground[1], mBackground[2], 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
drawContents();
drawWidgets();
glfwSwapBuffers(mGLFWWindow);
}
// Callback method to receive scrolling events
void TestbedApplication::scroll(GLFWwindow* window, double xAxis, double yAxis) {
// Update scroll on the GUI
//Gui::getInstance().setScroll(xAxis, yAxis);
//getInstance().mCurrentScene->scrollingEvent(xAxis, yAxis, SCROLL_SENSITIVITY);
}
// Called when a mouse button event occurs
void TestbedApplication::mouseButton(GLFWwindow* window, int button, int action, int mods) {
// Get the mouse cursor position
double x, y;
glfwGetCursorPos(window, &x, &y);
//getInstance().mCurrentScene->mouseButtonEvent(button, action, mods, x, y);
}
// Called when a mouse motion event occurs
void TestbedApplication::mouseMotion(GLFWwindow* window, double x, double y) {
int leftButtonState = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT);
int rightButtonState = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT);
int middleButtonState = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_MIDDLE);
int altKeyState = glfwGetKey(window, GLFW_KEY_LEFT_ALT);
/*getInstance().mCurrentScene->mouseMotionEvent(x, y, leftButtonState, rightButtonState,
middleButtonState, altKeyState);*/
}

View File

@ -135,21 +135,6 @@ class TestbedApplication : public Screen {
/// Compute the FPS
void computeFPS();
/// GLFW error callback method
static void error_callback(int error, const char* description);
/// Callback method to receive keyboard events
static void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods);
/// Callback method to receive scrolling events
static void scroll(GLFWwindow* window, double xAxis, double yAxis);
/// Called when a mouse button event occurs
static void mouseButton(GLFWwindow* window, int button, int action, int mods);
/// Called when a mouse motion event occurs
static void mouseMotion(GLFWwindow* window, double x, double y);
/// Initialize all the scenes
void createScenes();
@ -190,7 +175,7 @@ class TestbedApplication : public Screen {
/// Destructor
virtual ~TestbedApplication();
virtual void drawAll();
/// Render the content of the application
virtual void drawContents();
/// Window resize event handler