Commit a7b1bccd authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: fix building with SDL 1.2

parent 4f1e9ab8
...@@ -248,7 +248,11 @@ engine_obj := $(obj)/$(engine) ...@@ -248,7 +248,11 @@ engine_obj := $(obj)/$(engine)
engine_cflags := -I$(engine_src) -I$(mimalloc_inc) -I$(imgui_inc) engine_cflags := -I$(engine_src) -I$(mimalloc_inc) -I$(imgui_inc)
engine_deps := mimalloc imgui engine_deps := mimalloc
ifneq (1,$(SDL_TARGET))
engine_deps += imgui
endif
ifneq (0,$(USE_PHYSFS)) ifneq (0,$(USE_PHYSFS))
engine_deps += physfs engine_deps += physfs
......
...@@ -3598,7 +3598,12 @@ void editorMaybeWarpMouse(int searchx, int searchy) ...@@ -3598,7 +3598,12 @@ void editorMaybeWarpMouse(int searchx, int searchy)
// force g_mouseAbs here because we seem to get a frame of rendering with the old values // force g_mouseAbs here because we seem to get a frame of rendering with the old values
// despite pumping the SDL event queue immediately after SDL_WarpMouseInWindow // despite pumping the SDL event queue immediately after SDL_WarpMouseInWindow
g_mouseAbs = { searchx*upscalefactor, searchy*upscalefactor }; g_mouseAbs = { searchx*upscalefactor, searchy*upscalefactor };
#if SDL_MAJOR_VERSION >= 2
SDL_WarpMouseInWindow(NULL, searchx*upscalefactor, searchy*upscalefactor); SDL_WarpMouseInWindow(NULL, searchx*upscalefactor, searchy*upscalefactor);
#else
// this would be FIXME if anyone gave a shit about using the editor with SDL 1.2
SDL_WarpMouse(searchx*upscalefactor, searchy*upscalefactor);
#endif
handleevents(); handleevents();
mouseLockToWindow(0); mouseLockToWindow(0);
#endif #endif
......
...@@ -15,15 +15,18 @@ ...@@ -15,15 +15,18 @@
#include "sdl_inc.h" #include "sdl_inc.h"
#include "softsurface.h" #include "softsurface.h"
#if SDL_MAJOR_VERSION >= 2
# include "imgui.h" # include "imgui.h"
# include "imgui_impl_sdl.h" # include "imgui_impl_sdl.h"
#ifdef USE_OPENGL
# include "imgui_impl_opengl3.h"
#endif
#endif
#ifdef USE_OPENGL #ifdef USE_OPENGL
# include "glad/glad.h" # include "glad/glad.h"
# include "glbuild.h" # include "glbuild.h"
# include "glsurface.h" # include "glsurface.h"
# include "imgui_impl_opengl3.h"
#endif #endif
#if defined HAVE_GTK2 #if defined HAVE_GTK2
...@@ -121,11 +124,11 @@ static SDL_Surface *loadappicon(void); ...@@ -121,11 +124,11 @@ static SDL_Surface *loadappicon(void);
#endif #endif
static mutex_t m_initprintf; static mutex_t m_initprintf;
#if SDL_MAJOR_VERSION >= 2
static ImGuiIO *g_ImGui_IO; static ImGuiIO *g_ImGui_IO;
bool g_ImGuiCaptureInput = true; bool g_ImGuiCaptureInput = true;
#endif
uint8_t g_ImGuiCapturedDevices; uint8_t g_ImGuiCapturedDevices;
#ifdef _WIN32 #ifdef _WIN32
# if SDL_MAJOR_VERSION >= 2 # if SDL_MAJOR_VERSION >= 2
// //
...@@ -1289,7 +1292,9 @@ void mouseGrabInput(bool grab) ...@@ -1289,7 +1292,9 @@ void mouseGrabInput(bool grab)
void mouseLockToWindow(char a) void mouseLockToWindow(char a)
{ {
#if SDL_MAJOR_VERSION >= 2
if (!g_ImGui_IO || !g_ImGui_IO->WantCaptureMouse) if (!g_ImGui_IO || !g_ImGui_IO->WantCaptureMouse)
#endif
if (!(a & 2)) if (!(a & 2))
{ {
mouseGrabInput(a); mouseGrabInput(a);
...@@ -1300,6 +1305,7 @@ void mouseLockToWindow(char a) ...@@ -1300,6 +1305,7 @@ void mouseLockToWindow(char a)
SDL_ShowCursor(newstate); SDL_ShowCursor(newstate);
#if SDL_MAJOR_VERSION >= 2
if (g_ImGui_IO) if (g_ImGui_IO)
{ {
if (newstate) if (newstate)
...@@ -1307,6 +1313,7 @@ void mouseLockToWindow(char a) ...@@ -1307,6 +1313,7 @@ void mouseLockToWindow(char a)
else else
g_ImGui_IO->ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; g_ImGui_IO->ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
} }
#endif
} }
...@@ -1506,33 +1513,40 @@ bool g_ImGuiFrameActive; ...@@ -1506,33 +1513,40 @@ bool g_ImGuiFrameActive;
void engineBeginImGuiFrame(void) void engineBeginImGuiFrame(void)
{ {
Bassert(g_ImGuiFrameActive == false); Bassert(g_ImGuiFrameActive == false);
#if SDL_MAJOR_VERSION >= 2
#ifdef USE_OPENGL #ifdef USE_OPENGL
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
#endif #endif
ImGui_ImplSDL2_NewFrame(); ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
g_ImGuiFrameActive = true; g_ImGuiFrameActive = true;
#endif
} }
void engineEndImGuiInput(void) void engineEndImGuiInput(void)
{ {
keyFlushChars(); keyFlushChars();
keyFlushScans(); keyFlushScans();
#if SDL_MAJOR_VERSION >= 2
ImGui::GetIO().ClearInputKeys(); ImGui::GetIO().ClearInputKeys();
// ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; // ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
SDL_StopTextInput(); SDL_StopTextInput();
#endif
} }
void engineBeginImGuiInput(void) void engineBeginImGuiInput(void)
{ {
keyFlushChars(); keyFlushChars();
keyFlushScans(); keyFlushScans();
#if SDL_MAJOR_VERSION >= 2
SDL_StartTextInput(); SDL_StartTextInput();
// ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NoMouseCursorChange; // ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NoMouseCursorChange;
#endif
} }
void engineSetupImGui(void) void engineSetupImGui(void)
{ {
#if SDL_MAJOR_VERSION >= 2
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
g_ImGui_IO = &ImGui::GetIO(); g_ImGui_IO = &ImGui::GetIO();
...@@ -1551,6 +1565,7 @@ void engineSetupImGui(void) ...@@ -1551,6 +1565,7 @@ void engineSetupImGui(void)
g_ImGui_IO->Fonts->AddFontDefault(); g_ImGui_IO->Fonts->AddFontDefault();
//ImFont* font = g_ImGui_IO->Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\consola.ttf", 12.0f); //ImFont* font = g_ImGui_IO->Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\consola.ttf", 12.0f);
//IM_ASSERT(font != NULL); //IM_ASSERT(font != NULL);
#endif
} }
#ifdef USE_OPENGL #ifdef USE_OPENGL
...@@ -1990,14 +2005,14 @@ void videoShowFrame(int32_t w) ...@@ -1990,14 +2005,14 @@ void videoShowFrame(int32_t w)
{ {
glsurface_blitBuffer(); glsurface_blitBuffer();
} }
#if SDL_MAJOR_VERSION >= 2
if (g_ImGuiFrameActive) if (g_ImGuiFrameActive)
{ {
ImGui::Render(); ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
g_ImGuiFrameActive = false; g_ImGuiFrameActive = false;
} }
#endif
if ((r_glfinish == 1 && r_finishbeforeswap == 1) || vsync_renderlayer == 2) if ((r_glfinish == 1 && r_finishbeforeswap == 1) || vsync_renderlayer == 2)
{ {
MICROPROFILE_SCOPEI("Engine", "glFinish", MP_GREEN); MICROPROFILE_SCOPEI("Engine", "glFinish", MP_GREEN);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment