summaryrefslogtreecommitdiff
path: root/src/guichan/gui.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-31 01:27:37 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-31 01:27:37 +0300
commit9d3b975bcb84ad1c61d628de2804751c0d0707dd (patch)
treefe7494b1ecd561a40dc96d088c77d69b6d4ce13e /src/guichan/gui.cpp
parent1d0044cbc81e547ad688a295288910d58e1a3fb1 (diff)
downloadmanaverse-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.gz
manaverse-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.bz2
manaverse-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.xz
manaverse-9d3b975bcb84ad1c61d628de2804751c0d0707dd.zip
Fix code style and missing members initialisations.
Diffstat (limited to 'src/guichan/gui.cpp')
-rw-r--r--src/guichan/gui.cpp332
1 files changed, 152 insertions, 180 deletions
diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp
index ae9adea13..f8376646f 100644
--- a/src/guichan/gui.cpp
+++ b/src/guichan/gui.cpp
@@ -60,21 +60,21 @@
namespace gcn
{
- Gui::Gui()
- :mTop(NULL),
- mGraphics(NULL),
- mInput(NULL),
- mTabbing(true),
- mShiftPressed(false),
- mMetaPressed(false),
- mControlPressed(false),
- mAltPressed(false),
- mLastMousePressButton(0),
- mLastMousePressTimeStamp(0),
- mLastMouseX(0),
- mLastMouseY(0),
- mClickCount(1),
- mLastMouseDragButton(0)
+ Gui::Gui() :
+ mTop(NULL),
+ mGraphics(NULL),
+ mInput(NULL),
+ mTabbing(true),
+ mShiftPressed(false),
+ mMetaPressed(false),
+ mControlPressed(false),
+ mAltPressed(false),
+ mLastMousePressButton(0),
+ mLastMousePressTimeStamp(0),
+ mLastMouseX(0),
+ mLastMouseY(0),
+ mClickCount(1),
+ mLastMouseDragButton(0)
{
mFocusHandler = new FocusHandler();
}
@@ -82,9 +82,7 @@ namespace gcn
Gui::~Gui()
{
if (Widget::widgetExists(mTop))
- {
setTop(NULL);
- }
delete mFocusHandler;
}
@@ -92,13 +90,9 @@ namespace gcn
void Gui::setTop(Widget* top)
{
if (mTop != NULL)
- {
mTop->_setFocusHandler(NULL);
- }
if (top != NULL)
- {
top->_setFocusHandler(mFocusHandler);
- }
mTop = top;
}
@@ -131,9 +125,7 @@ namespace gcn
void Gui::logic()
{
if (mTop == NULL)
- {
throw GCN_EXCEPTION("No top widget set");
- }
handleModalFocus();
handleModalMouseInputFocus();
@@ -153,18 +145,12 @@ namespace gcn
void Gui::draw()
{
if (mTop == NULL)
- {
throw GCN_EXCEPTION("No top widget set");
- }
if (mGraphics == NULL)
- {
throw GCN_EXCEPTION("No graphics set");
- }
if (!mTop->isVisible())
- {
return;
- }
mGraphics->_beginDraw();
@@ -227,24 +213,24 @@ namespace gcn
switch (mouseInput.getType())
{
- case MouseInput::PRESSED:
- handleMousePressed(mouseInput);
- break;
- case MouseInput::RELEASED:
- handleMouseReleased(mouseInput);
- break;
- case MouseInput::MOVED:
- handleMouseMoved(mouseInput);
- break;
- case MouseInput::WHEEL_MOVED_DOWN:
- handleMouseWheelMovedDown(mouseInput);
- break;
- case MouseInput::WHEEL_MOVED_UP:
- handleMouseWheelMovedUp(mouseInput);
- break;
- default:
- throw GCN_EXCEPTION("Unknown mouse input type.");
- break;
+ case MouseInput::PRESSED:
+ handleMousePressed(mouseInput);
+ break;
+ case MouseInput::RELEASED:
+ handleMouseReleased(mouseInput);
+ break;
+ case MouseInput::MOVED:
+ handleMouseMoved(mouseInput);
+ break;
+ case MouseInput::WHEEL_MOVED_DOWN:
+ handleMouseWheelMovedDown(mouseInput);
+ break;
+ case MouseInput::WHEEL_MOVED_UP:
+ handleMouseWheelMovedUp(mouseInput);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown mouse input type.");
+ break;
}
}
}
@@ -270,17 +256,16 @@ namespace gcn
keyInput.isNumericPad(),
keyInput.getKey());
- distributeKeyEventToGlobalKeyListeners(keyEventToGlobalKeyListeners);
+ 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() != NULL)
{
@@ -292,16 +277,11 @@ namespace gcn
keyInput.getType(),
keyInput.isNumericPad(),
keyInput.getKey());
-
if (!mFocusHandler->getFocused()->isFocusable())
- {
mFocusHandler->focusNone();
- }
else
- {
- distributeKeyEvent(keyEvent);
- }
+ distributeKeyEvent(keyEvent);
keyEventConsumed = keyEvent.isConsumed();
}
@@ -309,34 +289,27 @@ namespace gcn
// If the key event hasn't been consumed and
// tabbing is enable check for tab press and
// change focus.
- if (!keyEventConsumed
- && mTabbing
+ 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)
{
// Check if the mouse leaves the application window.
- if (!mWidgetWithMouseQueue.empty()
- && (mouseInput.getX() < 0
- || mouseInput.getY() < 0
- || !mTop->getDimension().isPointInRect(mouseInput.getX(), mouseInput.getY()))
- )
+ if (!mWidgetWithMouseQueue.empty() && (mouseInput.getX() < 0
+ || mouseInput.getY() < 0 || !mTop->getDimension().isPointInRect(
+ mouseInput.getX(), mouseInput.getY())))
{
- // Distribute an event to all widgets in the "widget with mouse" queue.
+ // Distribute an event to all widgets in the
+ // "widget with mouse" queue.
while (!mWidgetWithMouseQueue.empty())
{
Widget* widget = mWidgetWithMouseQueue.front();
@@ -367,10 +340,10 @@ namespace gcn
std::deque<Widget*>::iterator iter;
for (iter = mWidgetWithMouseQueue.begin();
iter != mWidgetWithMouseQueue.end();
- iter++)
+ ++ iter)
{
Widget* widget = *iter;
-
+
// If a widget in the "widget with mouse queue" doesn't
// exists anymore it should be removed from the queue.
if (!Widget::widgetExists(widget))
@@ -395,7 +368,7 @@ namespace gcn
mouseInput.getX(),
mouseInput.getY(),
true,
- true);
+ true);
mClickCount = 1;
mLastMousePressTimeStamp = 0;
mWidgetWithMouseQueue.erase(iter);
@@ -406,21 +379,24 @@ namespace gcn
iterations++;
}
- widgetWithMouseQueueCheckDone = iterations == mWidgetWithMouseQueue.size();
+ widgetWithMouseQueueCheckDone =
+ (iterations == mWidgetWithMouseQueue.size());
}
// Check all widgets below the mouse to see if they are
// present in the "widget with mouse" queue. If a widget
// is not then it should be added and an entered event should
// be sent to it.
- Widget* parent = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* parent = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
Widget* widget = parent;
// If a widget has modal mouse input focus then it will
- // always be returned from getMouseEventSource, but we only wan't to send
- // mouse entered events if the mouse has actually entered the widget with
- // modal mouse input focus, hence we need to check if that's the case. If
- // it's not we should simply ignore to send any mouse entered events.
+ // always be returned from getMouseEventSource, but we only wan't to
+ // send mouse entered events if the mouse has actually entered the
+ // widget with modal mouse input focus, hence we need to check if
+ // that's the case. If it's not we should simply ignore to send any
+ // mouse entered events.
if (mFocusHandler->getModalMouseInputFocused() != NULL
&& widget == mFocusHandler->getModalMouseInputFocused()
&& Widget::widgetExists(widget))
@@ -428,9 +404,8 @@ namespace gcn
int x, y;
widget->getAbsolutePosition(x, y);
- if (x > mouseInput.getX()
- || y > mouseInput.getY()
- || x + widget->getWidth() <= mouseInput.getX()
+ if (x > mouseInput.getX() || y > mouseInput.getY()
+ || x + widget->getWidth() <= mouseInput.getX()
|| y + widget->getHeight() <= mouseInput.getY())
{
parent = NULL;
@@ -446,7 +421,7 @@ namespace gcn
std::deque<Widget*>::iterator iter;
for (iter = mWidgetWithMouseQueue.begin();
iter != mWidgetWithMouseQueue.end();
- iter++)
+ ++ iter)
{
if (*iter == widget)
{
@@ -485,7 +460,9 @@ namespace gcn
}
else
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
+
distributeMouseEvent(sourceWidget,
MouseEvent::MOVED,
mouseInput.getButton(),
@@ -496,12 +473,11 @@ namespace gcn
void Gui::handleMousePressed(const MouseInput& mouseInput)
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
if (mFocusHandler->getDraggedWidget() != NULL)
- {
sourceWidget = mFocusHandler->getDraggedWidget();
- }
int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
@@ -540,12 +516,11 @@ namespace gcn
void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput)
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
if (mFocusHandler->getDraggedWidget() != NULL)
- {
sourceWidget = mFocusHandler->getDraggedWidget();
- }
int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
@@ -559,12 +534,11 @@ namespace gcn
void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput)
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
if (mFocusHandler->getDraggedWidget() != NULL)
- {
sourceWidget = mFocusHandler->getDraggedWidget();
- }
int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
@@ -578,28 +552,27 @@ namespace gcn
void Gui::handleMouseReleased(const MouseInput& mouseInput)
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
if (mFocusHandler->getDraggedWidget() != NULL)
{
if (sourceWidget != mFocusHandler->getLastWidgetPressed())
- {
mFocusHandler->setLastWidgetPressed(NULL);
- }
-
+
sourceWidget = mFocusHandler->getDraggedWidget();
}
int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
-
+
distributeMouseEvent(sourceWidget,
MouseEvent::RELEASED,
mouseInput.getButton(),
mouseInput.getX(),
mouseInput.getY());
- if (mouseInput.getButton() == mLastMousePressButton
+ if (mouseInput.getButton() == mLastMousePressButton
&& mFocusHandler->getLastWidgetPressed() == sourceWidget)
{
distributeMouseEvent(sourceWidget,
@@ -607,7 +580,7 @@ namespace gcn
mouseInput.getButton(),
mouseInput.getX(),
mouseInput.getY());
-
+
mFocusHandler->setLastWidgetPressed(NULL);
}
else
@@ -617,9 +590,7 @@ namespace gcn
}
if (mFocusHandler->getDraggedWidget() != NULL)
- {
mFocusHandler->setDraggedWidget(NULL);
- }
}
Widget* Gui::getWidgetAt(int x, int y)
@@ -707,9 +678,7 @@ namespace gcn
// If the widget has been removed due to input
// cancel the distribution.
if (!Widget::widgetExists(widget))
- {
break;
- }
parent = (Widget*)widget->getParent();
@@ -720,53 +689,52 @@ namespace gcn
mouseEvent.mX = x - widgetX;
mouseEvent.mY = y - widgetY;
-
- std::list<MouseListener*> mouseListeners = widget->_getMouseListeners();
+
+ std::list<MouseListener*> mouseListeners
+ = widget->_getMouseListeners();
// Send the event to all mouse listeners of the widget.
- for (std::list<MouseListener*>::iterator it = mouseListeners.begin();
+ for (std::list<MouseListener*>::iterator
+ it = mouseListeners.begin();
it != mouseListeners.end();
++it)
{
switch (mouseEvent.getType())
{
- case MouseEvent::ENTERED:
- (*it)->mouseEntered(mouseEvent);
- break;
- case MouseEvent::EXITED:
- (*it)->mouseExited(mouseEvent);
- break;
- case MouseEvent::MOVED:
- (*it)->mouseMoved(mouseEvent);
- break;
- case MouseEvent::PRESSED:
- (*it)->mousePressed(mouseEvent);
- break;
- case MouseEvent::RELEASED:
- (*it)->mouseReleased(mouseEvent);
- break;
- case MouseEvent::WHEEL_MOVED_UP:
- (*it)->mouseWheelMovedUp(mouseEvent);
- break;
- case MouseEvent::WHEEL_MOVED_DOWN:
- (*it)->mouseWheelMovedDown(mouseEvent);
- break;
- case MouseEvent::DRAGGED:
- (*it)->mouseDragged(mouseEvent);
- break;
- case MouseEvent::CLICKED:
- (*it)->mouseClicked(mouseEvent);
- break;
- default:
- throw GCN_EXCEPTION("Unknown mouse event type.");
- }
+ case MouseEvent::ENTERED:
+ (*it)->mouseEntered(mouseEvent);
+ break;
+ case MouseEvent::EXITED:
+ (*it)->mouseExited(mouseEvent);
+ break;
+ case MouseEvent::MOVED:
+ (*it)->mouseMoved(mouseEvent);
+ break;
+ case MouseEvent::PRESSED:
+ (*it)->mousePressed(mouseEvent);
+ break;
+ case MouseEvent::RELEASED:
+ (*it)->mouseReleased(mouseEvent);
+ break;
+ case MouseEvent::WHEEL_MOVED_UP:
+ (*it)->mouseWheelMovedUp(mouseEvent);
+ break;
+ case MouseEvent::WHEEL_MOVED_DOWN:
+ (*it)->mouseWheelMovedDown(mouseEvent);
+ break;
+ case MouseEvent::DRAGGED:
+ (*it)->mouseDragged(mouseEvent);
+ break;
+ case MouseEvent::CLICKED:
+ (*it)->mouseClicked(mouseEvent);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown mouse event type.");
+ }
}
-
+
if (toSourceOnly)
- {
break;
- }
-
}
Widget* swap = widget;
@@ -821,24 +789,26 @@ namespace gcn
if (widget->isEnabled())
{
- std::list<KeyListener*> keyListeners = widget->_getKeyListeners();
-
+ std::list<KeyListener*> keyListeners
+ = widget->_getKeyListeners();
+
// Send the event to all key listeners of the source widget.
- for (std::list<KeyListener*>::iterator it = keyListeners.begin();
+ for (std::list<KeyListener*>::iterator
+ it = keyListeners.begin();
it != keyListeners.end();
++it)
{
switch (keyEvent.getType())
{
- case KeyEvent::PRESSED:
- (*it)->keyPressed(keyEvent);
- break;
- case KeyEvent::RELEASED:
- (*it)->keyReleased(keyEvent);
- break;
- default:
- throw GCN_EXCEPTION("Unknown key event type.");
- }
+ case KeyEvent::PRESSED:
+ (*it)->keyPressed(keyEvent);
+ break;
+ case KeyEvent::RELEASED:
+ (*it)->keyReleased(keyEvent);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown key event type.");
+ }
}
}
@@ -860,24 +830,22 @@ namespace gcn
{
KeyListenerListIterator it;
- for (it = mKeyListeners.begin(); it != mKeyListeners.end(); it++)
+ for (it = mKeyListeners.begin(); it != mKeyListeners.end(); ++ it)
{
switch (keyEvent.getType())
{
- case KeyEvent::PRESSED:
- (*it)->keyPressed(keyEvent);
- break;
- case KeyEvent::RELEASED:
- (*it)->keyReleased(keyEvent);
- break;
- default:
- throw GCN_EXCEPTION("Unknown key event type.");
+ case KeyEvent::PRESSED:
+ (*it)->keyPressed(keyEvent);
+ break;
+ case KeyEvent::RELEASED:
+ (*it)->keyReleased(keyEvent);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown key event type.");
}
if (keyEvent.isConsumed())
- {
break;
- }
}
}
@@ -885,36 +853,40 @@ namespace gcn
{
// Check if modal mouse input focus has been gained by a widget.
if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus()
- != mFocusHandler->getModalMouseInputFocused())
- && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() == NULL))
+ != mFocusHandler->getModalMouseInputFocused())
+ && (mFocusHandler->getLastWidgetWithModalMouseInputFocus()
+ == NULL))
{
handleModalFocusGained();
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused());
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(
+ mFocusHandler->getModalMouseInputFocused());
}
// Check if modal mouse input focus has been released.
else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus()
- != mFocusHandler->getModalMouseInputFocused())
- && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() != NULL))
+ != mFocusHandler->getModalMouseInputFocused())
+ && (mFocusHandler->getLastWidgetWithModalMouseInputFocus()
+ != NULL))
{
handleModalFocusReleased();
mFocusHandler->setLastWidgetWithModalMouseInputFocus(NULL);
}
}
- void Gui::handleModalFocus()
+ void Gui::handleModalFocus()
{
// Check if modal focus has been gained by a widget.
if ((mFocusHandler->getLastWidgetWithModalFocus()
- != mFocusHandler->getModalFocused())
- && (mFocusHandler->getLastWidgetWithModalFocus() == NULL))
+ != mFocusHandler->getModalFocused())
+ && (mFocusHandler->getLastWidgetWithModalFocus() == NULL))
{
handleModalFocusGained();
- mFocusHandler->setLastWidgetWithModalFocus(mFocusHandler->getModalFocused());
+ mFocusHandler->setLastWidgetWithModalFocus(
+ mFocusHandler->getModalFocused());
}
// Check if modal focus has been released.
else if ((mFocusHandler->getLastWidgetWithModalFocus()
- != mFocusHandler->getModalFocused())
- && (mFocusHandler->getLastWidgetWithModalFocus() != NULL))
+ != mFocusHandler->getModalFocused())
+ && (mFocusHandler->getLastWidgetWithModalFocus() != NULL))
{
handleModalFocusReleased();
mFocusHandler->setLastWidgetWithModalFocus(NULL);
@@ -942,7 +914,8 @@ namespace gcn
mWidgetWithMouseQueue.pop_front();
}
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused());
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(
+ mFocusHandler->getModalMouseInputFocused());
}
void Gui::handleModalFocusReleased()
@@ -963,7 +936,7 @@ namespace gcn
std::deque<Widget*>::iterator iter;
for (iter = mWidgetWithMouseQueue.begin();
iter != mWidgetWithMouseQueue.end();
- iter++)
+ ++ iter)
{
if (*iter == widget)
{
@@ -974,8 +947,7 @@ namespace gcn
// Widget is not present, send an entered event and add
// it to the "widget with mouse" queue.
- if (!widgetIsPresentInQueue
- && Widget::widgetExists(widget))
+ if (!widgetIsPresentInQueue && Widget::widgetExists(widget))
{
distributeMouseEvent(widget,
MouseEvent::ENTERED,