summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-24 00:31:26 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-24 21:08:17 +0300
commit076e2f4655c43e7dc79a01d576551942c7c3c057 (patch)
tree39bce5d299283f2bf00c24bff414331e714d8f21 /src
parentc88734cc2b8a0785c23531ce70bf703887aa0c4b (diff)
downloadmanaverse-076e2f4655c43e7dc79a01d576551942c7c3c057.tar.gz
manaverse-076e2f4655c43e7dc79a01d576551942c7c3c057.tar.bz2
manaverse-076e2f4655c43e7dc79a01d576551942c7c3c057.tar.xz
manaverse-076e2f4655c43e7dc79a01d576551942c7c3c057.zip
show/hide mouse cursor if mouse in/out window.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp45
-rw-r--r--src/client.h2
-rw-r--r--src/game.cpp11
-rw-r--r--src/gui/gui.cpp8
4 files changed, 49 insertions, 17 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 76f12d021..8a197d5aa 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -994,11 +994,12 @@ int Client::gameExec()
#ifdef USE_SDL2
case SDL_WINDOWEVENT:
- {
handleSDL2WindowEvent(event);
break;
- }
#else
+ case SDL_ACTIVEEVENT:
+ handleActive(event);
+ break;
case SDL_VIDEORESIZE:
resizeVideo(event.resize.w, event.resize.h, false);
break;
@@ -2866,7 +2867,7 @@ void Client::applyKeyRepeat()
void Client::setIsMinimized(const bool n)
{
mIsMinimized = n;
- if (!n && client->mNewMessageFlag)
+ if (!n && mNewMessageFlag)
{
mNewMessageFlag = false;
SDL::SetWindowTitle(mainGraphics->getWindow(), mCaption.c_str());
@@ -3119,8 +3120,46 @@ void Client::handleSDL2WindowEvent(const SDL_Event &event)
case SDL_WINDOWEVENT_RESIZED:
resizeVideo(event.window.data1, event.window.data2, false);
break;
+ case SDL_WINDOWEVENT_ENTER:
+ setMouseFocused(true);
+ break;
+ case SDL_WINDOWEVENT_LEAVE:
+ setMouseFocused(false);
+ break;
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
+ setInputFocused(true);
+ break;
+ case SDL_WINDOWEVENT_FOCUS_LOST:
+ setInputFocused(false);
+ break;
default:
break;
}
}
+#else
+void Client::handleActive(const SDL_Event &event)
+{
+ if (event.active.state & SDL_APPACTIVE)
+ {
+ if (event.active.gain)
+ { // window restore
+ setIsMinimized(false);
+ setPriority(true);
+ }
+ else
+ { // window minimization
+#ifdef ANDROID
+ setState(STATE_EXIT);
+#else
+ setIsMinimized(true);
+ setPriority(false);
+#endif
+ }
+ }
+
+ if (event.active.state & SDL_APPINPUTFOCUS)
+ setInputFocused(event.active.gain);
+ if (event.active.state & SDL_APPMOUSEFOCUS)
+ setMouseFocused(event.active.gain);
+}
#endif
diff --git a/src/client.h b/src/client.h
index 4b550ad16..257180a73 100644
--- a/src/client.h
+++ b/src/client.h
@@ -314,6 +314,8 @@ public:
#ifdef USE_SDL2
void handleSDL2WindowEvent(const SDL_Event &event);
+#else
+ void handleActive(const SDL_Event &event);
#endif
void optionChanged(const std::string &name) override;
diff --git a/src/game.cpp b/src/game.cpp
index d15c79a36..41a036c0f 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -876,18 +876,13 @@ void Game::moveInDirection(const unsigned char direction)
void Game::handleActive(const SDL_Event &event)
{
-// logger->log("SDL_ACTIVEEVENT");
-// logger->log("state: %d", (int)event.active.state);
-// logger->log("gain: %d", (int)event.active.gain);
-
- // +++ need use window events
#ifndef USE_SDL2
int fpsLimit = 0;
if (event.active.state & SDL_APPACTIVE)
{
if (event.active.gain)
{ // window restore
- Client::setIsMinimized(false);
+ client->setIsMinimized(false);
if (player_node)
{
if (!player_node->getAway())
@@ -901,7 +896,7 @@ void Game::handleActive(const SDL_Event &event)
#ifdef ANDROID
client->setState(STATE_EXIT);
#else
- Client::setIsMinimized(true);
+ client->setIsMinimized(true);
if (player_node && !player_node->getAway())
{
fpsLimit = config.getIntValue("altfpslimit");
@@ -919,7 +914,7 @@ void Game::handleActive(const SDL_Event &event)
if (event.active.state & SDL_APPINPUTFOCUS)
client->setInputFocused(event.active.gain);
if (event.active.state & SDL_APPMOUSEFOCUS)
- Client::setMouseFocused(event.active.gain);
+ client->setMouseFocused(event.active.gain);
if (!fpsLimit)
{
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 9441677a6..dda067644 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -32,6 +32,7 @@
#include "gui/widgets/mouseevent.h"
#include "gui/widgets/window.h"
+#include "client.h"
#include "configuration.h"
#include "dragdrop.h"
#include "keydata.h"
@@ -446,13 +447,8 @@ void Gui::draw()
int mouseX, mouseY;
const uint8_t button = SDL_GetMouseState(&mouseX, &mouseY);
-#ifdef USE_SDL2
- // +++ need check also is window have mouse focus SDL_GetMouseFocus
- if (mMouseCursors && mCustomCursor && mMouseCursorAlpha > 0.0f)
-#else
- if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1))
+ if ((client->getMouseFocused() || button & SDL_BUTTON(1))
&& mMouseCursors && mCustomCursor && mMouseCursorAlpha > 0.0f)
-#endif
{
Graphics *g2 = static_cast<Graphics*>(mGraphics);
const Image *const image = dragDrop.getItemImage();