diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-09-19 00:21:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-09-19 00:21:38 +0300 |
commit | 9847915fafee7fc3872aafb4395543b12174a1ae (patch) | |
tree | 2230ad7e345fdc46bd30c2c49864194ba1180ab6 /src/gui/widgets | |
parent | 0ebeb9512515249f33a9334abf1c52cbb0b6b7bb (diff) | |
download | mv-9847915fafee7fc3872aafb4395543b12174a1ae.tar.gz mv-9847915fafee7fc3872aafb4395543b12174a1ae.tar.bz2 mv-9847915fafee7fc3872aafb4395543b12174a1ae.tar.xz mv-9847915fafee7fc3872aafb4395543b12174a1ae.zip |
Add resize grip padding.
Fix resize grip position.
New theme option: resizePadding
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/resizegrip.cpp | 86 | ||||
-rw-r--r-- | src/gui/widgets/resizegrip.h | 61 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 46 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 4 |
4 files changed, 24 insertions, 173 deletions
diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp deleted file mode 100644 index d1c9ee8a9..000000000 --- a/src/gui/widgets/resizegrip.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2012 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "gui/widgets/resizegrip.h" - -#include "client.h" -#include "configuration.h" -#include "graphics.h" - -#include "gui/theme.h" - -#include "resources/image.h" - -#include <guichan/graphics.hpp> - -#include "debug.h" - -Image *ResizeGrip::gripImage = nullptr; -int ResizeGrip::mInstances = 0; -float ResizeGrip::mAlpha = 1.0; - -ResizeGrip::ResizeGrip(const std::string &image) : - gcn::Widget() -{ - if (mInstances == 0) - { - // Load the grip image - gripImage = Theme::getImageFromThemeXml(image, ""); - - if (gripImage) - gripImage->setAlpha(mAlpha); - } - - mInstances++; - - if (gripImage) - { - setWidth(gripImage->mBounds.w + 2); - setHeight(gripImage->mBounds.h + 2); - } - else - { - setWidth(2); - setHeight(2); - } -} - -ResizeGrip::~ResizeGrip() -{ - mInstances--; - if (mInstances == 0 && gripImage) - gripImage->decRef(); -} - -void ResizeGrip::draw(gcn::Graphics *graphics) -{ - if (!gripImage) - return; - - if (Client::getGuiAlpha() != mAlpha) - { - mAlpha = Client::getGuiAlpha(); - gripImage->setAlpha(mAlpha); - } - - static_cast<Graphics*>(graphics)->drawImage(gripImage, 0, 0); -} diff --git a/src/gui/widgets/resizegrip.h b/src/gui/widgets/resizegrip.h deleted file mode 100644 index af94854a3..000000000 --- a/src/gui/widgets/resizegrip.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2012 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef RESIZEGRIP_H -#define RESIZEGRIP_H - -#include <guichan/widget.hpp> - -class Image; - -/** - * Resize grip. The resize grip is part of a resizable Window. It relies on the - * fact that uncaught mouse events are automatically routed to the parent - * window. - * - * \ingroup GUI - */ -class ResizeGrip : public gcn::Widget -{ - public: - /** - * Constructor. - */ - ResizeGrip(const std::string &image = "resize.xml"); - - /** - * Destructor. - */ - ~ResizeGrip(); - - /** - * Draws the resize grip. - */ - void draw(gcn::Graphics *graphics); - - private: - static Image *gripImage; /**< Resize grip image */ - static int mInstances; /**< Number of resize grip instances */ - static float mAlpha; -}; - -#endif diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index ce893c360..0a0951f9e 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -33,7 +33,6 @@ #include "gui/viewport.h" #include "gui/widgets/layout.h" -#include "gui/widgets/resizegrip.h" #include "resources/image.h" @@ -77,6 +76,7 @@ Window::Window(const std::string &caption, const bool modal, mCaptionOffsetY(5), mCaptionAlign(gcn::Graphics::LEFT), mTitlePadding(4), + mGripPadding(2), mResizeHandles(-1), mRedraw(true), mCaptionFont(getFont()) @@ -106,6 +106,7 @@ Window::Window(const std::string &caption, const bool modal, mCaptionFont = reinterpret_cast<gcn::Font*>(boldFont); setTitlePadding(mSkin->getTitlePadding()); setTitleBarHeight(getOption("titlebarHeight")); + mGripPadding = getOption("resizePadding"); mCaptionOffsetX = getOption("captionoffsetx"); if (!mCaptionOffsetX) mCaptionOffsetX = 7; @@ -121,6 +122,7 @@ Window::Window(const std::string &caption, const bool modal, } } + // Add this window to the window container windowContainer->add(this); @@ -163,6 +165,11 @@ Window::~Window() Theme::instance()->unload(mSkin); mSkin = nullptr; } + if (mGrip) + { + mGrip->decRef(); + mGrip = nullptr; + } } void Window::setWindowContainer(WindowContainer *wc) @@ -213,6 +220,9 @@ void Window::draw(gcn::Graphics *graphics) g->drawImage(button, mStickyRect.x, mStickyRect.y); } + if (mGrip) + g->drawImage(mGrip, mGripRect.x, mGripRect.y); + if (update) { g->setRedraw(update); @@ -358,27 +368,19 @@ void Window::setMaxHeight(const int height) void Window::setResizable(const bool r) { - if (static_cast<bool>(mGrip) == r) + if ((mGrip != nullptr) == r) return; + if (mGrip) + mGrip->decRef(); if (r) { - if (mGrip) - { - remove(mGrip); - delete mGrip; - } - mGrip = new ResizeGrip; - mGrip->setX(mDimension.width - mGrip->getWidth() - - getChildrenArea().x); - mGrip->setY(mDimension.height - mGrip->getHeight() - - getChildrenArea().y); - add(mGrip); + mGrip = Theme::getImageFromThemeXml("resize.xml", ""); + mGripRect.x = mDimension.width - mGrip->getWidth() - mGripPadding; + mGripRect.y = mDimension.height - mGrip->getHeight() - mGripPadding; } else { - remove(mGrip); - delete mGrip; mGrip = nullptr; } } @@ -389,8 +391,8 @@ void Window::widgetResized(const gcn::Event &event A_UNUSED) if (mGrip) { - mGrip->setPosition(mDimension.width - mGrip->getWidth() - area.x, - mDimension.height - mGrip->getHeight() - area.y); + mGripRect.x = mDimension.width - mGrip->getWidth() - mGripPadding; + mGripRect.y = mDimension.height - mGrip->getHeight() - mGripPadding; } if (mLayout) @@ -474,7 +476,6 @@ void Window::setStickyButtonLock(const bool lock) { mStickyButtonLock = lock; mStickyButton = lock; -// mMovable = false; } void Window::setVisible(bool visible) @@ -919,8 +920,7 @@ int Window::getResizeHandles(const gcn::MouseEvent &event) resizeHandles |= (y > mDimension.height - resizeBorderWidth) ? BOTTOM : (y < resizeBorderWidth) ? TOP : 0; } - - if (event.getSource() == mGrip) + if (x >= mGripRect.x && y >= mGripRect.y) { mDragOffsetX = x; mDragOffsetY = y; @@ -944,7 +944,7 @@ bool Window::isResizeAllowed(const gcn::MouseEvent &event) const if (!getWindowArea().isPointInRect(x, y) && event.getSource() == this) return true; - if (event.getSource() == mGrip) + if (x >= mGripRect.x && y >= mGripRect.y) return true; } @@ -969,10 +969,6 @@ void Window::clearLayout() { clear(); - // Restore the resize grip - if (mGrip) - add(mGrip); - // Recreate layout instance when one is present if (mLayout) { diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 1e1caa6cd..fdcfc23de 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -442,11 +442,12 @@ class Window : public gcn::Window, private gcn::WidgetListener */ int getResizeHandles(const gcn::MouseEvent &event); - ResizeGrip *mGrip; /**< Resize grip */ + Image *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ Layout *mLayout; /**< Layout handler */ gcn::Rectangle mCloseRect; /**< Close button rectangle */ gcn::Rectangle mStickyRect; /**< Sticky button rectangle */ + gcn::Rectangle mGripRect; /**< Resize grip rectangle */ std::string mWindowName; /**< Name of the window */ bool mShowTitle; /**< Window has a title bar */ bool mModal; /**< Window is modal */ @@ -480,6 +481,7 @@ class Window : public gcn::Window, private gcn::WidgetListener int mCaptionOffsetY; int mCaptionAlign; int mTitlePadding; + int mGripPadding; int mResizeHandles; bool mRedraw; gcn::Font *mCaptionFont; |