summaryrefslogtreecommitdiff
path: root/src/gui/window.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-08-24 12:32:19 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-08-24 12:32:19 +0000
commit2debd445c71e65265359b6471795cab2cb2c7086 (patch)
tree695f276a3ae343f2a182dd2d3bb75afa6254f899 /src/gui/window.cpp
parent15c9ca70fa37dc8bae6b9ebd63209f5d0f7b0756 (diff)
downloadmana-2debd445c71e65265359b6471795cab2cb2c7086.tar.gz
mana-2debd445c71e65265359b6471795cab2cb2c7086.tar.bz2
mana-2debd445c71e65265359b6471795cab2cb2c7086.tar.xz
mana-2debd445c71e65265359b6471795cab2cb2c7086.zip
Added trimming of name for new character creation and of chat messages
appearing above players. Also improved resize mouse cursor indication, removing duplicated code and fixing indicator above resize grip.
Diffstat (limited to 'src/gui/window.cpp')
-rw-r--r--src/gui/window.cpp133
1 files changed, 62 insertions, 71 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 7df5e3ac..8cacd23e 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -345,63 +345,46 @@ void Window::mousePressed(gcn::MouseEvent &event)
// Let Guichan move window to top and figure out title bar drag
gcn::Window::mousePressed(event);
- const int x = event.getX();
- const int y = event.getY();
- mouseResize = 0;
-
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- // Close Button Handler
+ const int x = event.getX();
+ const int y = event.getY();
+
+ // Handle close button
if (mCloseButton)
{
- gcn::Rectangle tCloseButtonRect(
+ gcn::Rectangle closeButtonRect(
getWidth() - closeImage->getWidth() - getPadding(),
getPadding(),
closeImage->getWidth(),
- closeImage->getHeight()
- );
- if (tCloseButtonRect.isPointInRect(x, y))
+ closeImage->getHeight());
+
+ if (closeButtonRect.isPointInRect(x, y))
{
setVisible(false);
- return;
}
}
- // Resize Window Handler
- if (mResizable &&
- event.getSource() == this &&
- !getChildrenArea().isPointInRect(x, y))
- {
- mouseResize |= (x > getWidth() - resizeBorderWidth) ? RIGHT :
- (x < resizeBorderWidth) ? LEFT : 0;
- mouseResize |= (y > getHeight() - resizeBorderWidth) ? BOTTOM :
- (y < resizeBorderWidth) ? TOP : 0;
- return;
- }
- if (event.getSource() == mGrip &&
- event.getButton() == gcn::MouseEvent::LEFT)
- {
- mDragOffsetX = x;
- mDragOffsetY = y;
- mouseResize |= BOTTOM | RIGHT;
- mIsMoving = false;
- }
+
+ // Handle window resizing
+ mouseResize = getResizeHandles(event);
}
}
void Window::mouseReleased(gcn::MouseEvent &event)
{
- if (mResizable &&
- mouseResize)
+ if (mResizable && mouseResize)
{
mouseResize = 0;
gui->setCursorType(Gui::CURSOR_POINTER);
}
+
+ // This should be the responsibility of Guichan (and is from 0.8.0 on)
+ mIsMoving = false;
}
void Window::mouseExited(gcn::MouseEvent &event)
{
- if (mResizable &&
- !mouseResize)
+ if (mResizable && !mouseResize)
{
gui->setCursorType(Gui::CURSOR_POINTER);
}
@@ -409,47 +392,26 @@ void Window::mouseExited(gcn::MouseEvent &event)
void Window::mouseMoved(gcn::MouseEvent &event)
{
- const int x = event.getX();
- const int y = event.getY();
+ int resizeHandles = getResizeHandles(event);
- // changes the custom mouse cursor based on it's current position.
- if (mResizable &&
- !mouseResize)
+ // Changes the custom mouse cursor based on it's current position.
+ switch (resizeHandles)
{
- gcn::Rectangle tContainerRect(
- getPadding(),
- getPadding(),
- getWidth()-(getPadding() * 2),
- getHeight()-(getPadding() * 2)
- );
- if (!tContainerRect.isPointInRect(x, y))
- {
- int tMouseResize = 0;
- tMouseResize |= (x > getWidth() - resizeBorderWidth) ? RIGHT :
- (x < resizeBorderWidth) ? LEFT : 0;
- tMouseResize |= (y > getHeight() - resizeBorderWidth) ? BOTTOM :
- (y < resizeBorderWidth) ? TOP : 0;
- switch (tMouseResize)
- {
- case BOTTOM | RIGHT:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_RIGHT);
- break;
- case BOTTOM | LEFT:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_LEFT);
- break;
- case BOTTOM:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN);
- break;
- case RIGHT:
- case LEFT:
- gui->setCursorType(Gui::CURSOR_RESIZE_ACROSS);
- break;
- }
- }
- else
- {
+ case BOTTOM | RIGHT:
+ gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_RIGHT);
+ break;
+ case BOTTOM | LEFT:
+ gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_LEFT);
+ break;
+ case BOTTOM:
+ gui->setCursorType(Gui::CURSOR_RESIZE_DOWN);
+ break;
+ case RIGHT:
+ case LEFT:
+ gui->setCursorType(Gui::CURSOR_RESIZE_ACROSS);
+ break;
+ default:
gui->setCursorType(Gui::CURSOR_POINTER);
- }
}
}
@@ -570,3 +532,32 @@ void Window::resetToDefaultSize()
setPosition(mDefaultX, mDefaultY);
setContentSize(mDefaultWidth, mDefaultHeight);
}
+
+int Window::getResizeHandles(gcn::MouseEvent &event)
+{
+ int resizeHandles = 0;
+ const int y = event.getY();
+
+ if (mResizable && y > (int) mTitleBarHeight)
+ {
+ const int x = event.getX();
+
+ if (!getChildrenArea().isPointInRect(x, y) &&
+ event.getSource() == this)
+ {
+ resizeHandles |= (x > getWidth() - resizeBorderWidth) ? RIGHT :
+ (x < resizeBorderWidth) ? LEFT : 0;
+ resizeHandles |= (y > getHeight() - resizeBorderWidth) ? BOTTOM :
+ (y < resizeBorderWidth) ? TOP : 0;
+ }
+
+ if (event.getSource() == mGrip)
+ {
+ mDragOffsetX = x;
+ mDragOffsetY = y;
+ resizeHandles |= BOTTOM | RIGHT;
+ }
+ }
+
+ return resizeHandles;
+}