summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-08-31 23:24:57 +0300
committerAndrei Karas <akaras@inbox.ru>2011-08-31 23:24:57 +0300
commitadeb8e6091694e228f081ca8843e101ae598f26c (patch)
treea8a9caf4cbaf6b5d9a99f9b5e4e56f9b3203aa38 /src/gui
parent6d349121a70377723e53b92a8990e56ee3e4fd88 (diff)
downloadmanaverse-adeb8e6091694e228f081ca8843e101ae598f26c.tar.gz
manaverse-adeb8e6091694e228f081ca8843e101ae598f26c.tar.bz2
manaverse-adeb8e6091694e228f081ca8843e101ae598f26c.tar.xz
manaverse-adeb8e6091694e228f081ca8843e101ae598f26c.zip
Add ability to lock any window position and size. Using sticky image for this.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/botcheckerwindow.cpp1
-rw-r--r--src/gui/buydialog.cpp1
-rw-r--r--src/gui/charcreatedialog.cpp3
-rw-r--r--src/gui/chatwindow.cpp4
-rw-r--r--src/gui/debugwindow.cpp2
-rw-r--r--src/gui/didyouknowwindow.cpp2
-rw-r--r--src/gui/equipmentwindow.cpp2
-rw-r--r--src/gui/helpwindow.cpp2
-rw-r--r--src/gui/inventorywindow.cpp1
-rw-r--r--src/gui/killstats.cpp1
-rw-r--r--src/gui/npcdialog.cpp1
-rw-r--r--src/gui/outfitwindow.cpp2
-rw-r--r--src/gui/selldialog.cpp1
-rw-r--r--src/gui/setup.cpp1
-rw-r--r--src/gui/shopwindow.cpp1
-rw-r--r--src/gui/skilldialog.cpp1
-rw-r--r--src/gui/socialwindow.cpp2
-rw-r--r--src/gui/specialswindow.cpp1
-rw-r--r--src/gui/statuswindow.cpp1
-rw-r--r--src/gui/tradewindow.cpp1
-rw-r--r--src/gui/whoisonline.cpp1
-rw-r--r--src/gui/widgets/window.cpp52
-rw-r--r--src/gui/widgets/window.h15
23 files changed, 86 insertions, 13 deletions
diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp
index 4a8f8cf0d..7c0339ead 100644
--- a/src/gui/botcheckerwindow.cpp
+++ b/src/gui/botcheckerwindow.cpp
@@ -302,6 +302,7 @@ BotCheckerWindow::BotCheckerWindow():
setWindowName("BotCheckerWindow");
setCloseButton(true);
+ setStickyButtonLock(true);
setDefaultSize(w, h, ImageRect::CENTER);
playersScrollArea = new ScrollArea(mTable);
diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp
index 04dd425c1..8c1ad62ce 100644
--- a/src/gui/buydialog.cpp
+++ b/src/gui/buydialog.cpp
@@ -72,6 +72,7 @@ void BuyDialog::init()
setWindowName("Buy");
setResizable(true);
setCloseButton(true);
+ setStickyButtonLock(true);
setMinWidth(260);
setMinHeight(230);
setDefaultSize(260, 230, ImageRect::CENTER);
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index 91c284985..d1773e7f3 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -60,6 +60,9 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
mRace(0),
mSlot(slot)
{
+ setStickyButtonLock(true);
+ setSticky(true);
+
mPlayer = new Being(0, ActorSprite::PLAYER, mRace, NULL);
mPlayer->setGender(GENDER_MALE);
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 9c75320a6..784fb812a 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -167,6 +167,8 @@ ChatWindow::ChatWindow():
setResizable(true);
setDefaultVisible(true);
setSaveVisible(true);
+ setStickyButtonLock(true);
+
setDefaultSize(600, 123, ImageRect::LOWER_LEFT);
setMinWidth(150);
setMinHeight(90);
@@ -660,7 +662,7 @@ void ChatWindow::mouseDragged(gcn::MouseEvent &event)
if (event.isConsumed())
return;
- if (isMovable() && mMoved)
+ if (canMove() && isMovable() && mMoved)
{
int newX = std::max(0, getX() + event.getX() - mDragOffsetX);
int newY = std::max(0, getY() + event.getY() - mDragOffsetY);
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index 0b84dda1e..dc540a782 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -60,6 +60,8 @@ DebugWindow::DebugWindow():
setResizable(true);
setCloseButton(true);
setSaveVisible(true);
+ setStickyButtonLock(true);
+
setDefaultSize(400, 150, ImageRect::CENTER);
mTabs = new TabbedArea;
diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp
index 4d89bd924..d62417fc4 100644
--- a/src/gui/didyouknowwindow.cpp
+++ b/src/gui/didyouknowwindow.cpp
@@ -51,6 +51,8 @@ DidYouKnowWindow::DidYouKnowWindow():
setContentSize(455, 350);
setWindowName("DidYouKnow");
setResizable(true);
+ setStickyButtonLock(true);
+
setupWindow->registerWindowForReset(this);
setDefaultSize(500, 400, ImageRect::CENTER);
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 3abd97c73..0375d096f 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -80,6 +80,8 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being,
setCloseButton(true);
setSaveVisible(true);
+ setStickyButtonLock(true);
+
setDefaultSize(180, 345, ImageRect::CENTER);
mBoxes.reserve(13);
diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp
index 368049389..b772ea36a 100644
--- a/src/gui/helpwindow.cpp
+++ b/src/gui/helpwindow.cpp
@@ -47,6 +47,8 @@ HelpWindow::HelpWindow():
setContentSize(455, 350);
setWindowName("Help");
setResizable(true);
+ setStickyButtonLock(true);
+
setupWindow->registerWindowForReset(this);
setDefaultSize(500, 400, ImageRect::CENTER);
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 3b7b7b273..d0454c4e1 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -89,6 +89,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
setResizable(true);
setCloseButton(true);
setSaveVisible(true);
+ setStickyButtonLock(true);
setDefaultSize(387, 307, ImageRect::CENTER);
setMinWidth(316);
diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp
index 05a265da7..b9ce7c2a7 100644
--- a/src/gui/killstats.cpp
+++ b/src/gui/killstats.cpp
@@ -55,6 +55,7 @@ KillStats::KillStats():
setWindowName("Kill stats");
setCloseButton(true);
setResizable(true);
+ setStickyButtonLock(true);
setDefaultSize(250, 250, 350, 300);
listen(Mana::CHANNEL_ATTRIBUTES);
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index 36677446d..0db618d69 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -69,6 +69,7 @@ NpcDialog::NpcDialog(int npcId)
setResizable(true);
//setupWindow->registerWindowForReset(this);
setFocusable(true);
+ setStickyButtonLock(true);
setMinWidth(200);
setMinHeight(150);
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index d3bc6a302..3845aaf64 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -72,6 +72,8 @@ OutfitWindow::OutfitWindow():
setWindowName("Outfits");
setResizable(true);
setCloseButton(true);
+ setStickyButtonLock(true);
+
setDefaultSize(250, 400, 150, 230);
setMinWidth(145);
setMinHeight(220);
diff --git a/src/gui/selldialog.cpp b/src/gui/selldialog.cpp
index cf9bfb667..d9030e3fb 100644
--- a/src/gui/selldialog.cpp
+++ b/src/gui/selldialog.cpp
@@ -69,6 +69,7 @@ void SellDialog::init()
//setupWindow->registerWindowForReset(this);
setResizable(true);
setCloseButton(true);
+ setStickyButtonLock(true);
setMinWidth(260);
setMinHeight(230);
setDefaultSize(260, 230, ImageRect::CENTER);
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 690871189..76e3936c2 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -55,6 +55,7 @@ Setup::Setup():
{
setCloseButton(true);
setResizable(true);
+ setStickyButtonLock(true);
int width = 620;
int height = 450;
diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp
index 38985a01c..9aaf88bf3 100644
--- a/src/gui/shopwindow.cpp
+++ b/src/gui/shopwindow.cpp
@@ -86,6 +86,7 @@ ShopWindow::ShopWindow():
setWindowName("Personal Shop");
setResizable(true);
setCloseButton(true);
+ setStickyButtonLock(true);
setMinWidth(260);
setMinHeight(230);
setDefaultSize(380, 300, ImageRect::CENTER);
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index ff57195a9..bf87e804d 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -279,6 +279,7 @@ SkillDialog::SkillDialog():
setCloseButton(true);
setResizable(true);
setSaveVisible(true);
+ setStickyButtonLock(true);
setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425);
setupWindow->registerWindowForReset(this);
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index b9c8cb365..749f26f85 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -1129,6 +1129,8 @@ SocialWindow::SocialWindow() :
setResizable(true);
setSaveVisible(true);
setCloseButton(true);
+ setStickyButtonLock(true);
+
setMinWidth(120);
setMinHeight(55);
setDefaultSize(590, 200, 150, 120);
diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp
index a5d95c7ff..702c31718 100644
--- a/src/gui/specialswindow.cpp
+++ b/src/gui/specialswindow.cpp
@@ -82,6 +82,7 @@ SpecialsWindow::SpecialsWindow():
setCloseButton(true);
setResizable(true);
setSaveVisible(true);
+ setStickyButtonLock(true);
setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425);
setupWindow->registerWindowForReset(this);
diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp
index 7ab2afa2d..d1fde2dd1 100644
--- a/src/gui/statuswindow.cpp
+++ b/src/gui/statuswindow.cpp
@@ -132,6 +132,7 @@ StatusWindow::StatusWindow():
setResizable(true);
setCloseButton(true);
setSaveVisible(true);
+ setStickyButtonLock(true);
setDefaultSize((windowContainer->getWidth() - 365) / 2,
(windowContainer->getHeight() - 255) / 2, 365, 275);
diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp
index d00fb61f4..3c19ee9c2 100644
--- a/src/gui/tradewindow.cpp
+++ b/src/gui/tradewindow.cpp
@@ -78,6 +78,7 @@ TradeWindow::TradeWindow():
setWindowName("Trade");
setResizable(true);
setCloseButton(true);
+ setStickyButtonLock(true);
setDefaultSize(386, 180, ImageRect::CENTER);
setMinWidth(386);
setMinHeight(180);
diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp
index 99da53c66..1e9f686e4 100644
--- a/src/gui/whoisonline.cpp
+++ b/src/gui/whoisonline.cpp
@@ -97,6 +97,7 @@ WhoIsOnline::WhoIsOnline():
// setContentSize(w, h);
setCloseButton(true);
setResizable(true);
+ setStickyButtonLock(true);
mUpdateButton = new Button(_("Update"), "update", this);
mUpdateButton->setEnabled(false);
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index cdb9d3d55..9cb7cb620 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -60,6 +60,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
mSaveVisible(false),
mStickyButton(false),
mSticky(false),
+ mStickyButtonLock(false),
mMinWinWidth(100),
mMinWinHeight(40),
mMaxWinWidth(graphics->mWidth),
@@ -158,9 +159,9 @@ void Window::draw(gcn::Graphics *graphics)
// Draw Close Button
if (mCloseButton && mSkin->getCloseImage())
{
- g->drawImage(mSkin->getCloseImage(),
- getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(),
- getPadding());
+ Image *button = mSkin->getCloseImage();
+ const int x = getWidth() - button->getWidth() - getPadding();
+ g->drawImage(button, x, getPadding());
}
// Draw Sticky Button
@@ -171,7 +172,7 @@ void Window::draw(gcn::Graphics *graphics)
{
int x = getWidth() - button->getWidth() - getPadding();
if (mCloseButton && mSkin->getCloseImage())
- x -= mSkin->getCloseImage()->getWidth();
+ x -= mSkin->getCloseImage()->getWidth() + getPadding();
g->drawImage(button, x, getPadding());
}
@@ -399,6 +400,13 @@ void Window::setSticky(bool sticky)
mSticky = sticky;
}
+void Window::setStickyButtonLock(bool lock)
+{
+ mStickyButtonLock = lock;
+ mStickyButton = lock;
+// mMovable = false;
+}
+
void Window::setVisible(bool visible)
{
setVisible(visible, false);
@@ -413,7 +421,10 @@ void Window::setVisible(bool visible, bool forceSticky)
if (visible)
checkIfIsOffScreen();
- gcn::Window::setVisible((!forceSticky && isSticky()) || visible);
+ if (isStickyButtonLock())
+ gcn::Window::setVisible(visible);
+ else
+ gcn::Window::setVisible((!forceSticky && isSticky()) || visible);
}
void Window::scheduleDelete()
@@ -479,7 +490,10 @@ void Window::mousePressed(gcn::MouseEvent &event)
// Handle window resizing
mouseResize = getResizeHandles(event);
- mMoved = !mouseResize;
+ if (canMove())
+ mMoved = !mouseResize;
+ else
+ mMoved = false;
}
}
@@ -541,10 +555,24 @@ void Window::mouseMoved(gcn::MouseEvent &event)
viewport->hideBeingPopup();
}
+bool Window::canMove()
+{
+ return !mStickyButtonLock || !mSticky;
+}
+
void Window::mouseDragged(gcn::MouseEvent &event)
{
- // Let Guichan handle title bar drag
- gcn::Window::mouseDragged(event);
+ if (canMove())
+ {
+ // Let Guichan handle title bar drag
+ gcn::Window::mouseDragged(event);
+ }
+ else
+ {
+ if (!event.isConsumed() && event.getSource() == this)
+ event.consume();
+ return;
+ }
// Keep guichan window inside screen when it may be moved
if (isMovable() && mMoved)
@@ -638,18 +666,18 @@ void Window::loadWindowState()
assert(!name.empty());
setPosition(config.getValueInt(name + "WinX", mDefaultX),
- config.getValueInt(name + "WinY", mDefaultY));
+ config.getValueInt(name + "WinY", mDefaultY));
if (mSaveVisible)
{
setVisible(config.getValueBool(name
- + "Visible", mDefaultVisible));
+ + "Visible", mDefaultVisible));
}
if (mStickyButton)
{
setSticky(config.getValueBool(name
- + "Sticky", isSticky()));
+ + "Sticky", isSticky()));
}
if (mGrip)
@@ -811,7 +839,7 @@ void Window::resetToDefaultSize()
int Window::getResizeHandles(gcn::MouseEvent &event)
{
- if (event.getX() < 0 || event.getY() < 0)
+ if ((mStickyButtonLock && mSticky) || event.getX() < 0 || event.getY() < 0)
return 0;
int resizeHandles = 0;
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index d36d6c5ad..b9f65dceb 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -189,6 +189,17 @@ class Window : public gcn::Window, gcn::WidgetListener
{ return mSticky; }
/**
+ * Sets whether the window sticky mean window locked or not.
+ */
+ void setStickyButtonLock(bool sticky);
+
+ /**
+ * Returns whether the window sticky locking window.
+ */
+ bool isStickyButtonLock() const
+ { return mStickyButtonLock; }
+
+ /**
* Overloads window setVisible by Guichan to allow sticky window
* handling.
*/
@@ -387,6 +398,9 @@ class Window : public gcn::Window, gcn::WidgetListener
void setCaptionFont(gcn::Font *font)
{ mCaptionFont = font; }
+ protected:
+ bool canMove();
+
private:
enum ResizeHandles
{
@@ -423,6 +437,7 @@ class Window : public gcn::Window, gcn::WidgetListener
bool mSaveVisible; /**< Window will save visibility */
bool mStickyButton; /**< Window has a sticky button */
bool mSticky; /**< Window resists hiding*/
+ bool mStickyButtonLock; /**< Window locked if sticky enabled*/
int mMinWinWidth; /**< Minimum window width */
int mMinWinHeight; /**< Minimum window height */
int mMaxWinWidth; /**< Maximum window width */