diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-06-18 21:48:09 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-06-18 21:48:09 +0300 |
commit | 0778877b4af281b259ff9efb304ffae147fd1729 (patch) | |
tree | 70754defdeb259b49289e54fa33bc1985596269b | |
parent | b6c4f2b9afac13ec056ba72543f69f9843500039 (diff) | |
download | manaverse-0778877b4af281b259ff9efb304ffae147fd1729.tar.gz manaverse-0778877b4af281b259ff9efb304ffae147fd1729.tar.bz2 manaverse-0778877b4af281b259ff9efb304ffae147fd1729.tar.xz manaverse-0778877b4af281b259ff9efb304ffae147fd1729.zip |
improve window.
-rw-r--r-- | src/gui/widgets/window.cpp | 141 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 40 |
2 files changed, 89 insertions, 92 deletions
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index de49ac876..64b16b19a 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -64,14 +64,6 @@ Window::Window(const std::string &caption, const bool modal, mStickyRect(), mGripRect(), mWindowName("window"), - mShowTitle(true), - mModal(modal), - mCloseButton(false), - mDefaultVisible(false), - mSaveVisible(false), - mStickyButton(false), - mSticky(false), - mStickyButtonLock(false), mMinWinWidth(100), mMinWinHeight(40), mMaxWinWidth(mainGraphics->mWidth), @@ -84,8 +76,16 @@ Window::Window(const std::string &caption, const bool modal, mGripPadding(2), mResizeHandles(-1), mOldResizeHandles(-1), - mPlayVisibleSound(false), - mCaptionFont(getFont()) + mCaptionFont(getFont()), + mShowTitle(true), + mModal(modal), + mCloseButton(false), + mDefaultVisible(false), + mSaveVisible(false), + mStickyButton(false), + mSticky(false), + mStickyButtonLock(false), + mPlayVisibleSound(false) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -108,9 +108,10 @@ Window::Window(const std::string &caption, const bool modal, int childPalette = 1; // Loads the skin - if (Theme::instance()) + Theme *const theme = Theme::instance(); + if (theme) { - mSkin = Theme::instance()->load(skin, "window.xml"); + mSkin = theme->load(skin, "window.xml"); if (mSkin) { setPadding(mSkin->getPadding()); @@ -140,7 +141,6 @@ Window::Window(const std::string &caption, const bool modal, } } - // Add this window to the window container windowContainer->add(this); @@ -186,8 +186,9 @@ Window::~Window() if (mSkin) { - if (Theme::instance()) - Theme::instance()->unload(mSkin); + Theme *const theme = Theme::instance(); + if (theme) + theme->unload(mSkin); mSkin = nullptr; } if (mGrip) @@ -197,7 +198,7 @@ Window::~Window() } } -void Window::setWindowContainer(WindowContainer *wc) +void Window::setWindowContainer(WindowContainer *const wc) { windowContainer = wc; } @@ -317,16 +318,16 @@ void Window::draw(gcn::Graphics *graphics) void Window::setContentSize(int width, int height) { width = width + 2 * mPadding; - height = height + mPadding + getTitleBarHeight(); + height = height + mPadding + mTitleBarHeight; - if (getMinWidth() > width) - width = getMinWidth(); - else if (getMaxWidth() < width) - width = getMaxWidth(); - if (getMinHeight() > height) - height = getMinHeight(); - else if (getMaxHeight() < height) - height = getMaxHeight(); + if (mMinWinWidth > width) + width = mMinWinWidth; + else if (mMaxWinWidth < width) + width = mMaxWinWidth; + if (mMinWinHeight > height) + height = mMinWinHeight; + else if (mMaxWinHeight < height) + height = mMaxWinHeight; setSize(width, height); } @@ -409,7 +410,7 @@ void Window::setLocationRelativeTo(const ImageRect::ImagePosition &position, setPosition(offsetX, offsetY); } -void Window::setMinWidth(int width) +void Window::setMinWidth(const int width) { if (mSkin) { @@ -422,12 +423,12 @@ void Window::setMinWidth(int width) } } -void Window::setMinHeight(int height) +void Window::setMinHeight(const int height) { if (mSkin) { - mMinWinHeight = height > mSkin->getMinHeight() ? - height : mSkin->getMinHeight(); + mMinWinHeight = height > mSkin->getMinHeight() + ? height : mSkin->getMinHeight(); } else { @@ -485,10 +486,10 @@ void Window::widgetResized(const gcn::Event &event A_UNUSED) if (showClose) { const Image *const button = mSkin->getCloseImage(false); - const int x = mDimension.width - button->getWidth() - closePadding; - mCloseRect.x = x; + const int buttonWidth = button->getWidth(); + mCloseRect.x = mDimension.width - buttonWidth - closePadding; mCloseRect.y = closePadding; - mCloseRect.width = button->getWidth(); + mCloseRect.width = buttonWidth; mCloseRect.height = button->getHeight(); } if (mStickyButton) @@ -496,7 +497,8 @@ void Window::widgetResized(const gcn::Event &event A_UNUSED) const Image *const button = mSkin->getStickyImage(mSticky); if (button) { - int x = mDimension.width - button->getWidth() + const int buttonWidth = button->getWidth(); + int x = mDimension.width - buttonWidth - getOption("stickySpacing") - closePadding; if (showClose) @@ -504,7 +506,7 @@ void Window::widgetResized(const gcn::Event &event A_UNUSED) mStickyRect.x = x; mStickyRect.y = getOption("stickyPadding"); - mStickyRect.width = button->getWidth(); + mStickyRect.width = buttonWidth; mStickyRect.height = button->getHeight(); } } @@ -564,9 +566,9 @@ void Window::setVisible(bool visible) setVisible(visible, false); } -void Window::setVisible(bool visible, bool forceSticky) +void Window::setVisible(const bool visible, const bool forceSticky) { - if (visible == isWindowVisible()) + if (visible == mVisible) return; // Check if the window is off screen... @@ -579,17 +581,17 @@ void Window::setVisible(bool visible, bool forceSticky) mResizeHandles = 0; } - if (isStickyButtonLock()) + if (mStickyButtonLock) gcn::Window::setVisible(visible); else - gcn::Window::setVisible((!forceSticky && isSticky()) || visible); + gcn::Window::setVisible((!forceSticky && mSticky) || visible); if (visible) { if (mPlayVisibleSound) soundManager.playGuiSound(SOUND_SHOW_WINDOW); if (gui) { - gcn::MouseEvent *event = reinterpret_cast<gcn::MouseEvent*>( + gcn::MouseEvent *const event = reinterpret_cast<gcn::MouseEvent*>( gui->createMouseEvent(this)); if (event) { @@ -711,6 +713,7 @@ void Window::updateResizeHandler(gcn::MouseEvent &event) break; default: gui->setCursorType(Cursor::CURSOR_POINTER); + break; } } @@ -760,7 +763,7 @@ void Window::mouseDragged(gcn::MouseEvent &event) const int newHeight = newDim.height + ((mouseResize & TOP) ? -dy : dy); newDim.height = std::min(mMaxWinHeight, - std::max(mMinWinHeight, newHeight)); + std::max(mMinWinHeight, newHeight)); if (mouseResize & TOP) newDim.y -= newDim.height - getHeight(); @@ -771,7 +774,7 @@ void Window::mouseDragged(gcn::MouseEvent &event) const int newWidth = newDim.width + ((mouseResize & LEFT) ? -dx : dx); newDim.width = std::min(mMaxWinWidth, - std::max(mMinWinWidth, newWidth)); + std::max(mMinWinWidth, newWidth)); if (mouseResize & LEFT) newDim.x -= newDim.width - mDimension.width; @@ -805,7 +808,7 @@ void Window::mouseDragged(gcn::MouseEvent &event) } } -void Window::setModal(bool modal) +void Window::setModal(const bool modal) { if (mModal != modal) { @@ -916,17 +919,17 @@ void Window::saveWindowState() } } -void Window::setDefaultSize(int defaultX, int defaultY, +void Window::setDefaultSize(const int defaultX, const int defaultY, int defaultWidth, int defaultHeight) { - if (getMinWidth() > defaultWidth) - defaultWidth = getMinWidth(); - else if (getMaxWidth() < defaultWidth) - defaultWidth = getMaxWidth(); - if (getMinHeight() > defaultHeight) - defaultHeight = getMinHeight(); - else if (getMaxHeight() < defaultHeight) - defaultHeight = getMaxHeight(); + if (mMinWinWidth > defaultWidth) + defaultWidth = mMinWinWidth; + else if (mMaxWinWidth < defaultWidth) + defaultWidth = mMaxWinWidth; + if (mMinWinHeight > defaultHeight) + defaultHeight = mMinWinHeight; + else if (mMaxWinHeight < defaultHeight) + defaultHeight = mMaxWinHeight; mDefaultX = defaultX; mDefaultY = defaultY; @@ -942,11 +945,12 @@ void Window::setDefaultSize() mDefaultHeight = mDimension.height; } -void Window::setDefaultSize(int defaultWidth, int defaultHeight, +void Window::setDefaultSize(const int defaultWidth, const int defaultHeight, const ImageRect::ImagePosition &position, const int offsetX, const int offsetY) { - int x = 0, y = 0; + int x = 0; + int y = 0; if (position == ImageRect::UPPER_LEFT) { @@ -1004,18 +1008,15 @@ void Window::resetToDefaultSize() void Window::adjustPositionAfterResize(const int oldScreenWidth, const int oldScreenHeight) { - gcn::Rectangle dimension = getDimension(); - // If window was aligned to the right or bottom, keep it there const int rightMargin = oldScreenWidth - (mDimension.x + mDimension.width); const int bottomMargin = oldScreenHeight - (mDimension.y + mDimension.height); if (mDimension.x > 0 && mDimension.x > rightMargin) - dimension.x = mainGraphics->mWidth - rightMargin - mDimension.width; + mDimension.x = mainGraphics->mWidth - rightMargin - mDimension.width; if (mDimension.y > 0 && mDimension.y > bottomMargin) - dimension.y = mainGraphics->mHeight - bottomMargin - mDimension.height; + mDimension.y = mainGraphics->mHeight - bottomMargin - mDimension.height; - setDimension(dimension); ensureOnScreen(); } @@ -1075,7 +1076,7 @@ bool Window::isResizeAllowed(const gcn::MouseEvent &event) const return false; } -int Window::getGuiAlpha() +int Window::getGuiAlpha() const { const float alpha = std::max(Client::getGuiAlpha(), Theme::instance()->getMinimumOpacity()); @@ -1151,21 +1152,17 @@ void Window::ensureOnScreen() if (mDimension.width == 0 && mDimension.height == 0) return; - gcn::Rectangle dimension = getDimension(); - // Check the left and bottom screen boundaries - if (dimension.x + dimension.width > mainGraphics->mWidth) - dimension.x = mainGraphics->mWidth - dimension.width; - if (dimension.y + dimension.height > mainGraphics->mHeight) - dimension.y = mainGraphics->mHeight - dimension.height; + if (mDimension.x + mDimension.width > mainGraphics->mWidth) + mDimension.x = mainGraphics->mWidth - mDimension.width; + if (mDimension.y + mDimension.height > mainGraphics->mHeight) + mDimension.y = mainGraphics->mHeight - mDimension.height; // But never allow the windows to disappear in to the right and top - if (dimension.x < 0) - dimension.x = 0; - if (dimension.y < 0) - dimension.y = 0; - - setDimension(dimension); + if (mDimension.x < 0) + mDimension.x = 0; + if (mDimension.y < 0) + mDimension.y = 0; } gcn::Rectangle Window::getWindowArea() const @@ -1188,7 +1185,7 @@ int Window::getOption(const std::string &name, const int def) const return def; } -bool Window::getOptionBool(std::string name) +bool Window::getOptionBool(const std::string &name) const { if (mSkin) return mSkin->getOption(name) != 0; diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 3bea54bbb..11b30eba9 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -75,7 +75,7 @@ class Window : public gcn::Window, /** * Sets the window container to be used by new windows. */ - static void setWindowContainer(WindowContainer *windowContainer); + static void setWindowContainer(WindowContainer *const windowContainer); /** * Draws the window. @@ -136,7 +136,7 @@ class Window : public gcn::Window, /** * Sets the minimum width of the window. */ - void setMinWidth(int width); + void setMinWidth(const int width); int getMinWidth() const A_WARN_UNUSED { return mMinWinWidth; } @@ -144,7 +144,7 @@ class Window : public gcn::Window, /** * Sets the minimum height of the window. */ - void setMinHeight(int height); + void setMinHeight(const int height); int getMinHeight() const A_WARN_UNUSED { return mMinWinHeight; } @@ -210,7 +210,7 @@ class Window : public gcn::Window, * Overloads window setVisible by Guichan to allow sticky window * handling, or not, if you force the sticky state. */ - void setVisible(bool visible, bool forceSticky); + void setVisible(const bool visible, const bool forceSticky); /** * Returns whether the window is visible by default. @@ -221,7 +221,7 @@ class Window : public gcn::Window, /** * Sets whether the window is visible by default. */ - void setDefaultVisible(bool save) + void setDefaultVisible(const bool save) { mDefaultVisible = save; } /** @@ -233,7 +233,7 @@ class Window : public gcn::Window, /** * Sets whether the window will save it's visibility. */ - void setSaveVisible(bool save) + void setSaveVisible(const bool save) { mSaveVisible = save; } /** @@ -314,7 +314,7 @@ class Window : public gcn::Window, * Set the default win pos and size. * (which can be different of the actual ones.) */ - void setDefaultSize(int defaultX, int defaultY, + void setDefaultSize(const int defaultX, const int defaultY, int defaultWidth, int defaultHeight); /** @@ -328,7 +328,7 @@ class Window : public gcn::Window, * This version of setDefaultSize sets the window's position based * on a relative enumerated position, rather than a coordinate position. */ - void setDefaultSize(int defaultWidth, int defaultHeight, + void setDefaultSize(const int defaultWidth, const int defaultHeight, const ImageRect::ImagePosition &position, const int offsetx = 0, const int offsetY = 0); @@ -397,12 +397,12 @@ class Window : public gcn::Window, /** * Allows the windows modal status to change */ - void setModal(bool modal); + void setModal(const bool modal); /** * Gets the alpha value used by the window, in a GUIChan usable format. */ - int getGuiAlpha() A_WARN_UNUSED; + int getGuiAlpha() const A_WARN_UNUSED; gcn::Rectangle getWindowArea() const A_WARN_UNUSED; @@ -423,7 +423,7 @@ class Window : public gcn::Window, int getOption(const std::string &name, const int def = 0) const A_WARN_UNUSED; - bool getOptionBool(std::string name) A_WARN_UNUSED; + bool getOptionBool(const std::string &name) const A_WARN_UNUSED; void setTitlePadding(int p) { mTitlePadding = p; } @@ -472,14 +472,6 @@ class Window : public gcn::Window, 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 */ - bool mCloseButton; /**< Window has a close button */ - bool mDefaultVisible; /**< Window's default visibility */ - 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 */ @@ -503,8 +495,16 @@ class Window : public gcn::Window, int mGripPadding; int mResizeHandles; int mOldResizeHandles; - bool mPlayVisibleSound; gcn::Font *mCaptionFont; + bool mShowTitle; /**< Window has a title bar */ + bool mModal; /**< Window is modal */ + bool mCloseButton; /**< Window has a close button */ + bool mDefaultVisible; /**< Window's default visibility */ + 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*/ + bool mPlayVisibleSound; }; #endif // GUI_WIDGETS_WINDOW_H |