summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJosé Ávila <linux@javila.net>2005-06-06 21:30:37 +0000
committerJosé Ávila <linux@javila.net>2005-06-06 21:30:37 +0000
commit8e9df978f664ee4b415ab672e9eba5037d62af5e (patch)
treec57e17cd4505d2ea12123a83212f1479db9f79fa /src/gui
parent821241e469bcf649d1c1e04e8bdb4b462b21daa4 (diff)
downloadmana-8e9df978f664ee4b415ab672e9eba5037d62af5e.tar.gz
mana-8e9df978f664ee4b415ab672e9eba5037d62af5e.tar.bz2
mana-8e9df978f664ee4b415ab672e9eba5037d62af5e.tar.xz
mana-8e9df978f664ee4b415ab672e9eba5037d62af5e.zip
Fixed resizing window function
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/window.cpp95
-rw-r--r--src/gui/window.h8
2 files changed, 86 insertions, 17 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 980f8270..95965960 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -221,6 +221,40 @@ void Window::add(gcn::Widget *w, int x, int y)
chrome->add(w, x, y);
}
+void Window::mousePress(int x, int y, int button)
+{
+ if (getParent() != NULL)
+ {
+ getParent()->moveToTop(this);
+ }
+
+ if (hasMouse() && button == 1)
+ {
+ mMouseXOffset = x;
+ mMouseYOffset = y;
+
+ if (isMovable() && y < (int)(getTitleBarHeight() + getPadding()))
+ {
+ mMouseDrag = true;
+ }
+
+ if (getResizeable())
+ {
+ if (x > (getWidth() - 2 * getPadding()))
+ {
+ winXResizing = true;
+ mMouseDrag = true;
+ }
+
+ if (y > (getHeight() - 2 * getPadding()))
+ {
+ winYResizing = true;
+ mMouseDrag = true;
+ }
+ }
+ }
+}
+
void Window::mouseMotion(int mx, int my)
{
if (mMouseDrag && isMovable())
@@ -239,27 +273,58 @@ void Window::mouseMotion(int mx, int my)
//if (y < snapSize) y = 0;
//if (x + winWidth + snapSize > screen->w) x = screen->w - winWidth;
//if (y + winHeight + snapSize > screen->h) y = screen->h - winHeight;
-
- if (resizeable && mx > getWidth() - 16) {
- // Resize
- if (mx < minWinWidth)
- mx = minWinWidth;
- if (my < minWinHeight)
- my = minWinHeight;
- if (mx >= maxWinWidth)
- mx = maxWinWidth - 1;
- if (my >= maxWinHeight)
- my = maxWinHeight - 1;
-
- setWidth(mx);
- setHeight(my);
- } else {
+
+ if (getResizeable() &&
+ ((mx > (getWidth() - 16)) || (my > (getHeight() - 16))))
+ {
+ // Resize in X direction
+ if (winXResizing)
+ {
+ if (mx < minWinWidth)
+ {
+ mx = minWinWidth;
+ }
+ else if (mx >= maxWinWidth)
+ {
+ mx = maxWinWidth - 1;
+ }
+
+ setWidth(mx);
+ }
+
+ // Resize in Y direction
+ if (winYResizing)
+ {
+ if (my < minWinHeight)
+ {
+ my = minWinHeight;
+ }
+ else if (my >= maxWinHeight)
+ {
+ my = maxWinHeight - 1;
+ }
+
+ setHeight(my);
+ }
+ }
+ else
+ {
// Move
setPosition(x, y);
}
}
}
+void Window::mouseRelease(int x, int y, int button)
+{
+ if (button == 1)
+ {
+ mMouseDrag = false;
+ winXResizing = false;
+ winYResizing = false;
+ }
+}
+
void Window::optionChanged(const std::string &name)
{
if (name == "guialpha")
diff --git a/src/gui/window.h b/src/gui/window.h
index 95db2f4b..2986bad1 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -141,10 +141,12 @@ class Window : public gcn::Window, public ConfigListener
void scheduleDelete();
/**
- * Window dragging. This method also makes sure the window is not
- * dragged outside of the screen.
+ * Window dragging and resizing. These methods also makes sure the
+ * window is not dragged/resized outside of the screen.
*/
+ void mousePress(int x, int y, int button);
void mouseMotion(int mx, int my);
+ void mouseRelease(int x, int y, int button);
/**
* Called when an config option changes.
@@ -157,6 +159,8 @@ class Window : public gcn::Window, public ConfigListener
int snapSize; /**< Snap distance to window edge */
bool modal; /**< Window is modal */
bool resizeable; /**< Window can be resized */
+ bool winXResizing; /**< Window being resized in X direction */
+ bool winYResizing; /**< Window being resized in Y direction */
int minWinWidth; /**< Minimum window width */
int minWinHeight; /**< Minimum window height */
int maxWinWidth; /**< Maximum window width */