From c25867b5d860f18145f60dd6f6e507f111d3e9e5 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Mon, 4 Jan 2016 20:56:48 -0800 Subject: [PATCH] - try to fix mouse pointer for issue #94 --- data/glest_game | 2 +- source/glest_game/main/intro.cpp | 12 +-- source/glest_game/main/intro.h | 8 +- source/glest_game/main/main.cpp | 73 +++++++++++++++++++ source/glest_game/main/main.h | 1 + .../shared_lib/include/platform/sdl/window.h | 1 + .../platform/common/platform_common.cpp | 3 + .../sources/platform/sdl/window.cpp | 30 +++++++- 8 files changed, 118 insertions(+), 12 deletions(-) diff --git a/data/glest_game b/data/glest_game index 0ebb6df9..f22554bc 160000 --- a/data/glest_game +++ b/data/glest_game @@ -1 +1 @@ -Subproject commit 0ebb6df9491841a83a872d2a95291e6ee6f17750 +Subproject commit f22554bcfa828545a8996e8f08a49c9f96848283 diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index c6d347d0..2a57e9d5 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -60,7 +60,7 @@ namespace Glest{ namespace Game{ // class Text // ===================================================== -Text::Text(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D *font3D) { +IntroText::IntroText(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D *font3D) { this->text= text; this->pos= pos; this->time= time; @@ -69,7 +69,7 @@ Text::Text(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D this->font3D = font3D; } -Text::Text(const Texture2D *texture, const Vec2i &pos, const Vec2i &size, int time) { +IntroText::IntroText(const Texture2D *texture, const Vec2i &pos, const Vec2i &size, int time) { this->pos= pos; this->size= size; this->time= time; @@ -322,7 +322,7 @@ Intro::Intro(Program *program): textureHeight = strToInt(lang.getString(introTagTextureHeightName,"",true)); } - texts.push_back(new Text(logoTexture, Vec2i(w/2-(textureWidth/2), h/2-(textureHeight/2)), Vec2i(textureWidth, textureHeight), displayTime)); + texts.push_back(new IntroText(logoTexture, Vec2i(w/2-(textureWidth/2), h/2-(textureHeight/2)), Vec2i(textureWidth, textureHeight), displayTime)); } // This is a line of text else { @@ -385,7 +385,7 @@ Intro::Intro(Program *program): } } - texts.push_back(new Text(lineText, Vec2i(textX, textY), displayTime, font,font3d)); + texts.push_back(new IntroText(lineText, Vec2i(textX, textY), displayTime, font,font3d)); } } else { @@ -496,7 +496,7 @@ Intro::Intro(Program *program): textureStartTime = strToInt(lang.getString("IntroTextureStartMilliseconds","",true)); } - texts.push_back(new Text(tex, texPlacement, Vec2i(tex->getTextureWidth(), tex->getTextureHeight()), textureStartTime +(showMiscTime*(i+1)))); + texts.push_back(new IntroText(tex, texPlacement, Vec2i(tex->getTextureWidth(), tex->getTextureHeight()), textureStartTime +(showMiscTime*(i+1)))); } } @@ -682,7 +682,7 @@ void Intro::render() { renderer.reset2d(); for(int i = 0; i < (int)texts.size(); ++i) { - Text *text= texts[i]; + IntroText *text= texts[i]; int difTime= 1000 * timer / GameConstants::updateFps - text->getTime(); diff --git a/source/glest_game/main/intro.h b/source/glest_game/main/intro.h index 80417742..856a8726 100644 --- a/source/glest_game/main/intro.h +++ b/source/glest_game/main/intro.h @@ -48,7 +48,7 @@ namespace Glest{ namespace Game{ // class Text // ===================================================== -class Text { +class IntroText { private: string text; Vec2i pos; @@ -59,8 +59,8 @@ private: const Texture2D *texture; public: - Text(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D *font3D); - Text(const Texture2D *texture, const Vec2i &pos, const Vec2i &size, int time); + IntroText(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D *font3D); + IntroText(const Texture2D *texture, const Vec2i &pos, const Vec2i &size, int time); const string &getText() const {return text;} Font2D *getFont() {return font;} @@ -85,7 +85,7 @@ private: static int disapearTime; private: - vector texts; + vector texts; int timer; int mouse2d; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 862a4fab..414978f5 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -81,6 +81,7 @@ #include "network_protocol.h" #include "conversion.h" #include "gen_uuid.h" +//#include "intro.h" #include "leak_dumper.h" #if defined(WIN32) @@ -1327,6 +1328,76 @@ void MainWindow::eventKeyPress(SDL_KeyboardEvent c) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,c); } +void MainWindow::eventWindowEvent(SDL_WindowEvent event) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,event.event); + if(program == NULL) { + throw megaglest_runtime_error("In [MainWindow::eventKeyPress] ERROR, program == NULL!"); + } + +// if(program->getState() != NULL && dynamic_cast(program->getState()) != NULL) { +// printf("In eventWindowEvent skip\n"); +// return; +// } + //Renderer &renderer= Renderer::getInstance(); + switch(event.event) { + case SDL_WINDOWEVENT_ENTER: + { + //printf("In SDL_WINDOWEVENT_ENTER\n"); +// bool showCursorState = Window::lastShowMouseState; +// showCursor(showCursorState); +// renderer.setNo2DMouseRendering(showCursorState); +// +// Window::lastShowMouseState = SDL_ShowCursor(SDL_QUERY); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::lastShowMouseState = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::lastShowMouseState); + } + break; + case SDL_WINDOWEVENT_LEAVE: + { + //printf("In SDL_WINDOWEVENT_LEAVE\n"); +// bool showCursorState = false; +// int state = SDL_ShowCursor(SDL_QUERY); +// if(state == SDL_DISABLE) { +// showCursorState = true; +// } +// showCursor(showCursorState); +// renderer.setNo2DMouseRendering(showCursorState); +// +// Window::lastShowMouseState = SDL_ShowCursor(SDL_QUERY); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::lastShowMouseState = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::lastShowMouseState); + } + break; + case SDL_WINDOWEVENT_FOCUS_GAINED: + { + //printf("SDL_WINDOWEVENT_FOCUS_GAINED\n"); +// bool showCursorState = Window::lastShowMouseState; +// showCursor(showCursorState); +// renderer.setNo2DMouseRendering(showCursorState); +// +// Window::lastShowMouseState = SDL_ShowCursor(SDL_QUERY); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::lastShowMouseState = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::lastShowMouseState); + } + break; + case SDL_WINDOWEVENT_FOCUS_LOST: + { + //printf("SDL_WINDOWEVENT_FOCUS_LOST\n"); +// bool showCursorState = false; +// int state = SDL_ShowCursor(SDL_QUERY); +// if(state == SDL_DISABLE) { +// showCursorState = true; +// } +// showCursor(showCursorState); +// renderer.setNo2DMouseRendering(showCursorState); +// +// Window::lastShowMouseState = SDL_ShowCursor(SDL_QUERY); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::lastShowMouseState = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::lastShowMouseState); + } + break; + + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,event.event); +} + void MainWindow::eventActivate(bool active) { if(!active){ //minimize(); @@ -4786,6 +4857,7 @@ int glestMain(int argc, char** argv) { ::Shared::Platform::PlatformContextGl::charSet = config.getInt("FONT_CHARSET",intToStr(::Shared::Platform::PlatformContextGl::charSet).c_str()); if(config.getBool("No2DMouseRendering","false") == false) { showCursor(false); + //showWindowCursorState = false; } if(config.getInt("DEFAULT_HTTP_TIMEOUT",intToStr(SystemFlags::DEFAULT_HTTP_TIMEOUT).c_str()) >= 0) { SystemFlags::DEFAULT_HTTP_TIMEOUT = config.getInt("DEFAULT_HTTP_TIMEOUT",intToStr(SystemFlags::DEFAULT_HTTP_TIMEOUT).c_str()); @@ -5645,6 +5717,7 @@ int glestMain(int argc, char** argv) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); showCursor(true); + //showWindowCursorState = true; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/main/main.h b/source/glest_game/main/main.h index 98cd4d6c..819f828e 100644 --- a/source/glest_game/main/main.h +++ b/source/glest_game/main/main.h @@ -57,6 +57,7 @@ public: virtual void eventActivate(bool active); virtual void eventResize(SizeState sizeState); virtual void eventClose(); + virtual void eventWindowEvent(SDL_WindowEvent event); virtual void render(); void toggleLanguage(string language); diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index 773e463f..22fdb2fe 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -215,6 +215,7 @@ protected: virtual void eventClose() {}; virtual void eventDestroy() {}; virtual void eventToggleFullScreen(bool isFullscreen) {}; + virtual void eventWindowEvent(SDL_WindowEvent event) {} private: /// needed to detect double clicks diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index ffeb9f14..d416b0d8 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -1716,6 +1716,9 @@ bool isCursorShowing() { } void showCursor(bool b) { + //printf("In showCursor, b: %d, isCursorShowing(): %d\n",b,isCursorShowing()); + + if(isCursorShowing() == b) { return; } diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index a3e3face..551e6a3e 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -462,7 +462,35 @@ bool Window::handleEvent() { // bool willShowCursor = (!Window::isActive || (Window::lastShowMouseState == SDL_ENABLE) || Window::getUseDefaultCursorOnly()); // showCursor(willShowCursor); // } - showCursor(false); + + //printf("In SDL_WINDOWEVENT, event.window.event: %d\n",event.window.event); + + /* + switch(event.window.event) { + case SDL_WINDOWEVENT_ENTER: + printf("In SDL_WINDOWEVENT_ENTER\n"); + showCursor(true); + break; + case SDL_WINDOWEVENT_LEAVE: + printf("In SDL_WINDOWEVENT_LEAVE\n"); + showCursor(false); + break; + case SDL_WINDOWEVENT_FOCUS_GAINED: + printf("SDL_WINDOWEVENT_FOCUS_GAINED\n"); + showCursor(true); + break; + case SDL_WINDOWEVENT_FOCUS_LOST: + printf("SDL_WINDOWEVENT_FOCUS_LOST\n"); + showCursor(false); + break; + } + */ + //showCursor(false); + + if(global_window) { + global_window->eventWindowEvent(event.window); + } + } break; }