- try to fix mouse pointer for issue #94

This commit is contained in:
SoftCoder
2016-01-04 20:56:48 -08:00
parent 03f5455eb2
commit c25867b5d8
8 changed files with 118 additions and 12 deletions

View File

@@ -60,7 +60,7 @@ namespace Glest{ namespace Game{
// class Text // 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->text= text;
this->pos= pos; this->pos= pos;
this->time= time; this->time= time;
@@ -69,7 +69,7 @@ Text::Text(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D
this->font3D = 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->pos= pos;
this->size= size; this->size= size;
this->time= time; this->time= time;
@@ -322,7 +322,7 @@ Intro::Intro(Program *program):
textureHeight = strToInt(lang.getString(introTagTextureHeightName,"",true)); 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 // This is a line of text
else { 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 { else {
@@ -496,7 +496,7 @@ Intro::Intro(Program *program):
textureStartTime = strToInt(lang.getString("IntroTextureStartMilliseconds","",true)); 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(); renderer.reset2d();
for(int i = 0; i < (int)texts.size(); ++i) { 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(); int difTime= 1000 * timer / GameConstants::updateFps - text->getTime();

View File

@@ -48,7 +48,7 @@ namespace Glest{ namespace Game{
// class Text // class Text
// ===================================================== // =====================================================
class Text { class IntroText {
private: private:
string text; string text;
Vec2i pos; Vec2i pos;
@@ -59,8 +59,8 @@ private:
const Texture2D *texture; const Texture2D *texture;
public: public:
Text(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D *font3D); IntroText(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 Texture2D *texture, const Vec2i &pos, const Vec2i &size, int time);
const string &getText() const {return text;} const string &getText() const {return text;}
Font2D *getFont() {return font;} Font2D *getFont() {return font;}
@@ -85,7 +85,7 @@ private:
static int disapearTime; static int disapearTime;
private: private:
vector<Text *> texts; vector<IntroText *> texts;
int timer; int timer;
int mouse2d; int mouse2d;

View File

@@ -81,6 +81,7 @@
#include "network_protocol.h" #include "network_protocol.h"
#include "conversion.h" #include "conversion.h"
#include "gen_uuid.h" #include "gen_uuid.h"
//#include "intro.h"
#include "leak_dumper.h" #include "leak_dumper.h"
#if defined(WIN32) #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); 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<Intro *>(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) { void MainWindow::eventActivate(bool active) {
if(!active){ if(!active){
//minimize(); //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()); ::Shared::Platform::PlatformContextGl::charSet = config.getInt("FONT_CHARSET",intToStr(::Shared::Platform::PlatformContextGl::charSet).c_str());
if(config.getBool("No2DMouseRendering","false") == false) { if(config.getBool("No2DMouseRendering","false") == false) {
showCursor(false); showCursor(false);
//showWindowCursorState = false;
} }
if(config.getInt("DEFAULT_HTTP_TIMEOUT",intToStr(SystemFlags::DEFAULT_HTTP_TIMEOUT).c_str()) >= 0) { 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()); 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__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
showCursor(true); showCursor(true);
//showWindowCursorState = true;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); 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__); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }

View File

@@ -57,6 +57,7 @@ public:
virtual void eventActivate(bool active); virtual void eventActivate(bool active);
virtual void eventResize(SizeState sizeState); virtual void eventResize(SizeState sizeState);
virtual void eventClose(); virtual void eventClose();
virtual void eventWindowEvent(SDL_WindowEvent event);
virtual void render(); virtual void render();
void toggleLanguage(string language); void toggleLanguage(string language);

View File

@@ -215,6 +215,7 @@ protected:
virtual void eventClose() {}; virtual void eventClose() {};
virtual void eventDestroy() {}; virtual void eventDestroy() {};
virtual void eventToggleFullScreen(bool isFullscreen) {}; virtual void eventToggleFullScreen(bool isFullscreen) {};
virtual void eventWindowEvent(SDL_WindowEvent event) {}
private: private:
/// needed to detect double clicks /// needed to detect double clicks

View File

@@ -1716,6 +1716,9 @@ bool isCursorShowing() {
} }
void showCursor(bool b) { void showCursor(bool b) {
//printf("In showCursor, b: %d, isCursorShowing(): %d\n",b,isCursorShowing());
if(isCursorShowing() == b) { if(isCursorShowing() == b) {
return; return;
} }

View File

@@ -462,7 +462,35 @@ bool Window::handleEvent() {
// bool willShowCursor = (!Window::isActive || (Window::lastShowMouseState == SDL_ENABLE) || Window::getUseDefaultCursorOnly()); // bool willShowCursor = (!Window::isActive || (Window::lastShowMouseState == SDL_ENABLE) || Window::getUseDefaultCursorOnly());
// showCursor(willShowCursor); // 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; break;
} }