summaryrefslogtreecommitdiff
path: root/src/gui/widgets
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/widgets
parent6d349121a70377723e53b92a8990e56ee3e4fd88 (diff)
downloadmv-adeb8e6091694e228f081ca8843e101ae598f26c.tar.gz
mv-adeb8e6091694e228f081ca8843e101ae598f26c.tar.bz2
mv-adeb8e6091694e228f081ca8843e101ae598f26c.tar.xz
mv-adeb8e6091694e228f081ca8843e101ae598f26c.zip
Add ability to lock any window position and size. Using sticky image for this.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/window.cpp52
-rw-r--r--src/gui/widgets/window.h15
2 files changed, 55 insertions, 12 deletions
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 */