summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-06-16 01:29:37 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-06-16 01:29:37 +0000
commit06afc063b8538b90b8dd8eb662a9ae0e11812963 (patch)
treefbae681cc37ebac36a1ededa7a292d5ec8505842
parentcf0b73ed23fa2213521c23fcd927aab37151a484 (diff)
downloadmana-client-06afc063b8538b90b8dd8eb662a9ae0e11812963.tar.gz
mana-client-06afc063b8538b90b8dd8eb662a9ae0e11812963.tar.bz2
mana-client-06afc063b8538b90b8dd8eb662a9ae0e11812963.tar.xz
mana-client-06afc063b8538b90b8dd8eb662a9ae0e11812963.zip
Fixed window resizing to work properly, and on all edges and corners.
-rw-r--r--ChangeLog1
-rw-r--r--src/gui/inventory.cpp26
-rw-r--r--src/gui/itemcontainer.cpp6
-rw-r--r--src/gui/window.cpp222
-rw-r--r--src/gui/window.h15
5 files changed, 177 insertions, 93 deletions
diff --git a/ChangeLog b/ChangeLog
index 90d0989c..601bab05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
0.0.14 (3 July 2005)
- Added support for map properties (to be used for music and minimap settings)
- Added background image to minimap
+- Fixed window resizing (applies to inventory window)
0.0.13 (5 June 2005)
- Added ability to trade items and money
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp
index 66ccff58..59be88b8 100644
--- a/src/gui/inventory.cpp
+++ b/src/gui/inventory.cpp
@@ -63,7 +63,7 @@ InventoryWindow::InventoryWindow():
add(itemDescriptionLabel);
add(weightLabel);
- setResizeable(true);
+ setResizable(true);
setMinWidth(240);
setMinHeight(150);
@@ -215,18 +215,26 @@ void InventoryWindow::mouseMotion(int mx, int my)
void InventoryWindow::updateWidgets()
{
+ int width = getContent()->getWidth();
+ int height = getContent()->getHeight();
+ int columns = width / 24;
+
+ if (columns < 1)
+ {
+ columns = 1;
+ }
+
// Resize widgets
- useButton->setPosition(8, getHeight() - 24);
- dropButton->setPosition(48 + 16, getHeight() - 24);
- items->setSize(getWidth() - 24 - 12 - 1,
- (INVENTORY_SIZE * 24) / (getWidth() / 24) - 1);
- invenScroll->setSize(getWidth() - 16, getHeight() - 90);
+ useButton->setPosition(8, height - 24);
+ dropButton->setPosition(48 + 16, height - 24);
+ items->setSize(width - 24 - 12 - 1,
+ (INVENTORY_SIZE * 24) / columns - 1);
+ invenScroll->setSize(width - 16, height - 90);
- itemNameLabel->setPosition(8, invenScroll->getY() + invenScroll->getHeight() + 4);
+ itemNameLabel->setPosition(8,
+ invenScroll->getY() + invenScroll->getHeight() + 4);
itemDescriptionLabel->setPosition(8,
itemNameLabel->getY() + itemNameLabel->getHeight() + 4);
-
- setContentSize(getWidth(), getHeight());
}
void InventoryWindow::updateButtons()
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 2cc6b8e2..cdf77436 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -64,6 +64,12 @@ void ItemContainer::draw(gcn::Graphics* graphics)
int x, y;
getAbsolutePosition(x, y);
+ // Have at least 1 column
+ if (columns < 1)
+ {
+ columns = 1;
+ }
+
// Reset selected item when quantity not above 0 (should probably be made
// sure somewhere else)
if (items[selectedItem].quantity <= 0)
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index c5ef7a54..aa8569f2 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -35,11 +35,12 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
parent(parent),
snapSize(8),
modal(modal),
- resizeable(false),
- minWinWidth(256),
- minWinHeight(128),
- maxWinWidth(512),
- maxWinHeight(512)
+ resizable(false),
+ mMouseResize(false),
+ minWinWidth(6),
+ minWinHeight(23),
+ maxWinWidth(INT_MAX),
+ maxWinHeight(INT_MAX)
{
logger->log("Window::Window(\"%s\")", caption.c_str());
@@ -192,14 +193,14 @@ void Window::setMaxHeight(unsigned int height)
maxWinHeight = height;
}
-void Window::setResizeable(bool r)
+void Window::setResizable(bool r)
{
- resizeable = r;
+ resizable = r;
}
-bool Window::getResizeable()
+bool Window::getResizable()
{
- return resizeable;
+ return resizable;
}
Window *Window::getParentWindow()
@@ -224,94 +225,158 @@ void Window::add(gcn::Widget *w, int x, int y)
void Window::mousePress(int x, int y, int button)
{
- if (getParent() != NULL)
+ // Let Guichan move window to top and figure out title bar drag
+ gcn::Window::mousePress(x, y, button);
+
+ // If the mouse is not inside the content, the press must have been on the
+ // border, and is a candidate for a resize.
+ if (getResizable() && button == 1 &&
+ !getContentDimension().isPointInRect(x, y) &&
+ !(mMouseDrag && y > (int)getPadding()))
{
- getParent()->moveToTop(this);
+ mMouseResize = true;
+ mMouseXOffset = x;
+ mMouseYOffset = y;
+
+ // Determine which borders are being dragged
+ mLeftBorderDrag = (x < 10);
+ mTopBorderDrag = (y < 10);
+ mRightBorderDrag = (x >= getWidth() - 10);
+ mBottomBorderDrag = (y >= getHeight() - 10);
}
+}
- if (hasMouse() && button == 1)
+void Window::mouseMotion(int x, int y)
+{
+ if (mMouseDrag || mMouseResize)
{
- mMouseXOffset = x;
- mMouseYOffset = y;
-
- if (isMovable() && y < (int)(getTitleBarHeight() + getPadding()))
+ int dx = x - mMouseXOffset;
+ int dy = y - mMouseYOffset;
+ gcn::Rectangle newDim = getDimension();
+
+ // Change the dimension according to dragging and moving
+ if (mMouseResize && getResizable())
{
- mMouseDrag = true;
+ if (mLeftBorderDrag)
+ {
+ newDim.x += dx;
+ newDim.width -= dx;
+ }
+
+ if (mTopBorderDrag)
+ {
+ newDim.y += dy;
+ newDim.height -= dy;
+ }
+
+ if (mBottomBorderDrag)
+ {
+ newDim.height += dy;
+ }
+
+ if (mRightBorderDrag)
+ {
+ newDim.width += dx;
+ }
+ }
+ else if (mMouseDrag && isMovable())
+ {
+ newDim.x += dx;
+ newDim.y += dy;
}
- if (getResizeable())
+ // Keep guichan window inside screen
+ if (newDim.x < 0)
{
- if (x > (getWidth() - 2 * getPadding()))
- {
- winXResizing = true;
- mMouseDrag = true;
- }
-
- if (y > (getHeight() - 2 * getPadding()))
- {
- winYResizing = true;
- mMouseDrag = true;
- }
+ if (mMouseResize)
+ {
+ newDim.width += newDim.x;
+ }
+
+ newDim.x = 0;
}
- }
-}
+ if (newDim.y < 0)
+ {
+ if (mMouseResize)
+ {
+ newDim.height += newDim.y;
+ }
-void Window::mouseMotion(int mx, int my)
-{
- if (mMouseDrag && isMovable())
- {
- int x = mx - mMouseXOffset + getX();
- int y = my - mMouseYOffset + getY();
+ newDim.y = 0;
+ }
+ if (newDim.x + newDim.width > screen->w)
+ {
+ if (mMouseResize)
+ {
+ newDim.width = screen->w - newDim.x;
+ }
+ else
+ {
+ newDim.x = screen->w - newDim.width;
+ }
+ }
+ if (newDim.y + newDim.height > screen->h)
+ {
+ if (mMouseResize)
+ {
+ newDim.height = screen->h - newDim.y;
+ }
+ else
+ {
+ newDim.y = screen->h - newDim.height;
+ }
+ }
+
+ // Keep the window at least its minimum size
+ int Xcorrection = 0;
+ int Ycorrection = 0;
+
+ if (newDim.width < minWinWidth)
+ {
+ Xcorrection = minWinWidth - newDim.width;
+ }
+ else if (newDim.width > maxWinWidth)
+ {
+ Xcorrection = maxWinWidth - newDim.width;
+ }
+
+ if (newDim.height < minWinHeight)
+ {
+ Ycorrection = minWinHeight - newDim.height;
+ }
+ else if (newDim.height > maxWinHeight)
+ {
+ Ycorrection = maxWinHeight - newDim.height;
+ }
- // Keep guichan window inside window
- if (x < 0) x = 0;
- if (y < 0) y = 0;
- if (x + getWidth() > screen->w) x = screen->w - getWidth();
- if (y + getHeight() > screen->h) y = screen->h - getHeight();
+ if (mLeftBorderDrag) newDim.x -= Xcorrection;
+ newDim.width += Xcorrection;
+
+ if (mTopBorderDrag) newDim.y -= Ycorrection;
+ newDim.height += Ycorrection;
// Snap window to edges
//if (x < snapSize) x = 0;
//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 (getResizeable() &&
- ((mx > (getWidth() - 16)) || (my > (getHeight() - 16))))
+
+ // Update mouse offset when dragging bottom or right border
+ if (mBottomBorderDrag)
{
- // 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);
- }
+ mMouseYOffset += newDim.height - getHeight();
}
- else
+ if (mRightBorderDrag)
+ {
+ mMouseXOffset += newDim.width - getWidth();
+ }
+
+ // Set the new window and content dimensions
+ setDimension(newDim);
+
+ if (mContent != NULL && mMouseResize)
{
- // Move
- setPosition(x, y);
+ mContent->setDimension(getContentDimension());
}
}
}
@@ -320,9 +385,8 @@ void Window::mouseRelease(int x, int y, int button)
{
if (button == 1)
{
+ mMouseResize = false;
mMouseDrag = false;
- winXResizing = false;
- winYResizing = false;
}
}
diff --git a/src/gui/window.h b/src/gui/window.h
index 2986bad1..3c9201ce 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -100,12 +100,12 @@ class Window : public gcn::Window, public ConfigListener
/**
* Sets whether of not the window can be resized.
*/
- void setResizeable(bool resize);
+ void setResizable(bool resize);
/**
* Returns whether the window can be resized.
*/
- bool getResizeable();
+ bool getResizable();
/**
* Sets the minimum width of the window.
@@ -158,9 +158,14 @@ class Window : public gcn::Window, public ConfigListener
Window *parent; /**< The parent window */
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 */
+ bool resizable; /**< Window can be resized */
+
+ bool mMouseResize; /**< Window is being resized */
+ bool mTopBorderDrag; /**< Top border is being dragged */
+ bool mLeftBorderDrag; /**< Left border is being dragged */
+ bool mRightBorderDrag; /**< Right border is being dragged */
+ bool mBottomBorderDrag; /**< Bottom border is being dragged */
+
int minWinWidth; /**< Minimum window width */
int minWinHeight; /**< Minimum window height */
int maxWinWidth; /**< Maximum window width */