From b3ae2976c55f4aac310c69f16e4934b84eb1970d Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 8 Jul 2015 09:46:55 -0600 Subject: [PATCH] SDL example: tweaks and fixes. --- .../opengl_sdl_example/imgui_impl_sdl.cpp | 37 +++++++------------ examples/opengl_sdl_example/imgui_impl_sdl.h | 1 - examples/opengl_sdl_example/main.cpp | 13 +++---- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/examples/opengl_sdl_example/imgui_impl_sdl.cpp b/examples/opengl_sdl_example/imgui_impl_sdl.cpp index 2ac1f5be..b1e129ec 100644 --- a/examples/opengl_sdl_example/imgui_impl_sdl.cpp +++ b/examples/opengl_sdl_example/imgui_impl_sdl.cpp @@ -1,4 +1,3 @@ - #ifdef _MSC_VER #include #include @@ -25,9 +24,6 @@ static GLuint g_FontTexture = 0; // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) static void ImGui_ImplSdl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { - if (cmd_lists_count == 0) - return; - // We are using the OpenGL fixed pipeline to make the example code simpler to read! // A probable faster way to render would be to collate all vertices from all cmd_lists into a single vertex buffer. // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers. @@ -208,7 +204,7 @@ bool ImGui_ImplSdl_NewFrame(SDL_Window *window) ImGuiIO& io = ImGui::GetIO(); - bool done(false); + bool done = false; SDL_Event event; while (SDL_PollEvent(&event)) { @@ -218,14 +214,15 @@ bool ImGui_ImplSdl_NewFrame(SDL_Window *window) done = true; break; case SDL_MOUSEWHEEL: - if (event.wheel.y>0 ) - { + if (event.wheel.y > 0) g_MouseWheel = 1; - } - if (event.wheel.y<0 ) - { + if (event.wheel.y < 0) g_MouseWheel = -1; - } + break; + case SDL_MOUSEBUTTONDOWN: + if (event.button.button == SDL_BUTTON_LEFT) g_MousePressed[0] = true; + if (event.button.button == SDL_BUTTON_RIGHT) g_MousePressed[1] = true; + if (event.button.button == SDL_BUTTON_MIDDLE) g_MousePressed[2] = true; break; case SDL_TEXTINPUT: ImGui_ImplSdl_CharCallback(event.text.text[0]); @@ -258,27 +255,21 @@ bool ImGui_ImplSdl_NewFrame(SDL_Window *window) // Setup inputs // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) - Uint32 windowFlags = SDL_GetWindowFlags(window); - if (windowFlags&SDL_WINDOW_MOUSE_FOCUS) - { + if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) - } else - { io.MousePos = ImVec2(-1,-1); - } - for (int i = 0; i < 3; i++) - { - io.MouseDown[i] = g_MousePressed[i] || (mouseMask&(1< #include "imgui_impl_sdl.h" @@ -12,10 +12,10 @@ #ifdef MACOSX #include - #endif #include +#include int SDL_main(int /*argc*/, char* /*argv*/[]) { @@ -27,16 +27,13 @@ int SDL_main(int /*argc*/, char* /*argv*/[]) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); - int width(1024), height(576); - // SDL window SDL_DisplayMode current; SDL_GetCurrentDisplayMode(0, ¤t); - SDL_Window *window = SDL_CreateWindow( "ImGui OpenGL2/SDL2 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE ); + SDL_Window *window = SDL_CreateWindow("ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); // Create an OpenGL context associated with the window. SDL_GLContext glcontext = SDL_GL_CreateContext(window); @@ -55,9 +52,9 @@ int SDL_main(int /*argc*/, char* /*argv*/[]) bool show_another_window = false; ImVec4 clear_color = ImColor(114, 144, 154); - bool done(false); // Main loop - while(!done) + bool done = false; + while (!done) { done = ImGui_ImplSdl_NewFrame(window);