summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-03 01:29:22 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-03 01:29:22 +0300
commit5e4a1bf239d76a5525a4409dc7a2094fbffe0eb3 (patch)
tree2563cd7dd22fb1370b0311e9b7b45b8657f9ecdf
parenta56d6c4d316551940982d622e9b0e3b0f1ad1863 (diff)
downloadmanaverse-5e4a1bf239d76a5525a4409dc7a2094fbffe0eb3.tar.gz
manaverse-5e4a1bf239d76a5525a4409dc7a2094fbffe0eb3.tar.bz2
manaverse-5e4a1bf239d76a5525a4409dc7a2094fbffe0eb3.tar.xz
manaverse-5e4a1bf239d76a5525a4409dc7a2094fbffe0eb3.zip
Put gui input logic before most game input logic.
This solving game and gui shortcuts conflicts.
-rw-r--r--src/client.cpp2
-rw-r--r--src/game.cpp54
-rw-r--r--src/gui/gui.cpp90
-rw-r--r--src/gui/gui.h4
-rw-r--r--src/guichan/gui.cpp78
5 files changed, 124 insertions, 104 deletions
diff --git a/src/client.cpp b/src/client.cpp
index dd8838244..875d70a46 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -882,6 +882,8 @@ int Client::gameExec()
gui->logic();
if (mGame)
mGame->logic();
+ else if (gui)
+ gui->handleInput();
sound.logic();
diff --git a/src/game.cpp b/src/game.cpp
index 143751731..5c4785ef0 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -955,18 +955,10 @@ void Game::handleInput()
SDL_Event event;
while (SDL_PollEvent(&event))
{
- bool used = false;
-
updateHistory(event);
checkKeys();
- if (event.type == SDL_VIDEORESIZE)
- {
- // Let the client deal with this one (it'll pass down from there)
- Client::resize(event.resize.w, event.resize.h);
- }
- // Keyboard events (for discontinuous keys)
- else if (event.type == SDL_KEYDOWN)
+ if (event.type == SDL_KEYDOWN)
{
if (setupWindow && setupWindow->isVisible() &&
keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE)
@@ -985,6 +977,8 @@ void Game::handleInput()
{
if (guiInput)
guiInput->pushInput(event);
+ if (gui)
+ gui->handleInput();
}
catch (const gcn::Exception &e)
{
@@ -993,7 +987,33 @@ void Game::handleInput()
}
return;
}
+ }
+
+ try
+ {
+ if (guiInput)
+ guiInput->pushInput(event);
+ }
+ catch (const gcn::Exception &e)
+ {
+ const char *err = e.getMessage().c_str();
+ logger->log("Warning: guichan input exception: %s", err);
+ }
+ if (gui)
+ {
+ bool res = gui->handleInput();
+ if (res && event.type == SDL_KEYDOWN)
+ return;
+ }
+ if (event.type == SDL_VIDEORESIZE)
+ {
+ // Let the client deal with this one (it'll pass down from there)
+ Client::resize(event.resize.w, event.resize.h);
+ }
+ // Keyboard events (for discontinuous keys)
+ else if (event.type == SDL_KEYDOWN)
+ {
if (inputManager.handleKeyEvent(event))
return;
}
@@ -1007,22 +1027,6 @@ void Game::handleInput()
{
Client::setState(STATE_EXIT);
}
-
- // Push input to GUI when not used
- if (!used)
- {
- try
- {
- if (guiInput)
- guiInput->pushInput(event);
- }
- catch (const gcn::Exception &e)
- {
- const char *err = e.getMessage().c_str();
- logger->log("Warning: guichan input exception: %s", err);
- }
- }
-
} // End while
// If the user is configuring the keys then don't respond.
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 9d111141b..19361cf2d 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -259,7 +259,95 @@ void Gui::logic()
Palette::advanceGradients();
- gcn::Gui::logic();
+ if (!mTop)
+ return;
+
+ handleModalFocus();
+ handleModalMouseInputFocus();
+
+ if (mInput)
+ {
+// mInput->_pollInput();
+ handleMouseInput();
+ }
+
+ mTop->logic();
+}
+
+bool Gui::handleInput()
+{
+ if (mInput)
+ return handleKeyInput2();
+ else
+ return false;
+}
+
+bool Gui::handleKeyInput2()
+{
+ bool consumed(false);
+
+ while (!mInput->isKeyQueueEmpty())
+ {
+ gcn::KeyInput keyInput = mInput->dequeueKeyInput();
+
+ // Save modifiers state
+ mShiftPressed = keyInput.isShiftPressed();
+ mMetaPressed = keyInput.isMetaPressed();
+ mControlPressed = keyInput.isControlPressed();
+ mAltPressed = keyInput.isAltPressed();
+
+ gcn::KeyEvent keyEventToGlobalKeyListeners(nullptr,
+ mShiftPressed, mControlPressed, mAltPressed, mMetaPressed,
+ keyInput.getType(), keyInput.isNumericPad(), keyInput.getKey());
+
+ distributeKeyEventToGlobalKeyListeners(
+ keyEventToGlobalKeyListeners);
+
+ // If a global key listener consumes the event it will not be
+ // sent further to the source of the event.
+ if (keyEventToGlobalKeyListeners.isConsumed())
+ {
+ consumed = true;
+ continue;
+ }
+
+ bool keyEventConsumed = false;
+
+ if (mFocusHandler)
+ {
+ // Send key inputs to the focused widgets
+ if (mFocusHandler->getFocused())
+ {
+ gcn::KeyEvent keyEvent(getKeyEventSource(),
+ mShiftPressed, mControlPressed, mAltPressed, mMetaPressed,
+ keyInput.getType(), keyInput.isNumericPad(),
+ keyInput.getKey());
+
+ if (!mFocusHandler->getFocused()->isFocusable())
+ mFocusHandler->focusNone();
+ else
+ distributeKeyEvent(keyEvent);
+
+ keyEventConsumed = keyEvent.isConsumed();
+ if (keyEventConsumed)
+ consumed = true;
+ }
+
+ // If the key event hasn't been consumed and
+ // tabbing is enable check for tab press and
+ // change focus.
+ if (!keyEventConsumed && mTabbing
+ && keyInput.getKey().getValue() == Key::TAB
+ && keyInput.getType() == gcn::KeyInput::PRESSED)
+ {
+ if (keyInput.isShiftPressed())
+ mFocusHandler->tabPrevious();
+ else
+ mFocusHandler->tabNext();
+ }
+ }
+ } // end while
+ return consumed;
}
void Gui::draw()
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 5ace42323..33940ba5e 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -116,6 +116,10 @@ class Gui : public gcn::Gui
void updateFonts();
+ bool handleInput();
+
+ bool handleKeyInput2();
+
/**
* Cursors are in graphic order from left to right.
* CURSOR_POINTER should be left untouched.
diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp
index 5a3e16784..bd811014f 100644
--- a/src/guichan/gui.cpp
+++ b/src/guichan/gui.cpp
@@ -128,22 +128,6 @@ namespace gcn
void Gui::logic()
{
- if (!mTop)
- throw GCN_EXCEPTION("No top widget set");
-
- handleModalFocus();
- handleModalMouseInputFocus();
-
- if (mInput)
- {
- mInput->_pollInput();
-
- handleKeyInput();
- handleMouseInput();
-
- } // end if
-
- mTop->logic();
}
void Gui::draw()
@@ -241,68 +225,6 @@ namespace gcn
void Gui::handleKeyInput()
{
- while (!mInput->isKeyQueueEmpty())
- {
- KeyInput keyInput = mInput->dequeueKeyInput();
-
- // Save modifiers state
- mShiftPressed = keyInput.isShiftPressed();
- mMetaPressed = keyInput.isMetaPressed();
- mControlPressed = keyInput.isControlPressed();
- mAltPressed = keyInput.isAltPressed();
-
- KeyEvent keyEventToGlobalKeyListeners(nullptr,
- mShiftPressed,
- mControlPressed,
- mAltPressed,
- mMetaPressed,
- keyInput.getType(),
- keyInput.isNumericPad(),
- keyInput.getKey());
-
- distributeKeyEventToGlobalKeyListeners(
- keyEventToGlobalKeyListeners);
-
- // If a global key listener consumes the event it will not be
- // sent further to the source of the event.
- if (keyEventToGlobalKeyListeners.isConsumed())
- continue;
-
- bool keyEventConsumed = false;
-
- // Send key inputs to the focused widgets
- if (mFocusHandler->getFocused())
- {
- KeyEvent keyEvent(getKeyEventSource(),
- mShiftPressed,
- mControlPressed,
- mAltPressed,
- mMetaPressed,
- keyInput.getType(),
- keyInput.isNumericPad(),
- keyInput.getKey());
-
- if (!mFocusHandler->getFocused()->isFocusable())
- mFocusHandler->focusNone();
- else
- distributeKeyEvent(keyEvent);
-
- keyEventConsumed = keyEvent.isConsumed();
- }
-
- // If the key event hasn't been consumed and
- // tabbing is enable check for tab press and
- // change focus.
- if (!keyEventConsumed && mTabbing
- && keyInput.getKey().getValue() == Key::TAB
- && keyInput.getType() == KeyInput::PRESSED)
- {
- if (keyInput.isShiftPressed())
- mFocusHandler->tabPrevious();
- else
- mFocusHandler->tabNext();
- }
- } // end while
}
void Gui::handleMouseMoved(const MouseInput& mouseInput)