diff options
-rw-r--r-- | src/gui/theme.cpp | 24 | ||||
-rw-r--r-- | src/gui/theme.h | 5 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 25 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 6 |
4 files changed, 42 insertions, 18 deletions
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 99dac7887..fe1591de2 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -69,12 +69,19 @@ Skin::Skin(const ImageRect &skin, const ImageRect &images, mName(name), mBorder(skin), mCloseImage(images.grid[0]), - mStickyImageUp(images.grid[1]), - mStickyImageDown(images.grid[2]), + mCloseImageHighlighted(images.grid[1]), + mStickyImageUp(images.grid[2]), + mStickyImageDown(images.grid[3]), mPadding(padding), mTitlePadding(titlePadding), mOptions(options) { + if (!mCloseImageHighlighted) + { + mCloseImageHighlighted = mCloseImage; + if (mCloseImageHighlighted) + mCloseImageHighlighted->incRef(); + } } Skin::~Skin() @@ -95,6 +102,12 @@ Skin::~Skin() mCloseImage = nullptr; } + if (mCloseImageHighlighted) + { + mCloseImageHighlighted->decRef(); + mCloseImageHighlighted = nullptr; + } + if (mStickyImageUp) { mStickyImageUp->decRef(); @@ -125,6 +138,8 @@ void Skin::updateAlpha(float minimumOpacityAllowed) if (mCloseImage) mCloseImage->setAlpha(alpha); + if (mCloseImageHighlighted) + mCloseImageHighlighted->setAlpha(alpha); if (mStickyImageUp) mStickyImageUp->setAlpha(alpha); if (mStickyImageDown) @@ -370,8 +385,9 @@ static const SkinParameter skinParam[] = static const SkinParameter imageParam[] = { {0, "closeImage"}, - {1, "stickyImageUp"}, - {2, "stickyImageDown"}, + {1, "closeImageHighlighted"}, + {2, "stickyImageUp"}, + {3, "stickyImageDown"}, }; struct SkinHelper diff --git a/src/gui/theme.h b/src/gui/theme.h index 04c355e0f..245289096 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -72,8 +72,8 @@ class Skin /** * Returns the image used by a close button for this skin. */ - Image *getCloseImage() const - { return mCloseImage; } + Image *getCloseImage(const bool state) const + { return state ? mCloseImageHighlighted : mCloseImage; } /** * Returns the image used by a sticky button for this skin. @@ -117,6 +117,7 @@ class Skin std::string mName; /**< Name of the skin to use */ ImageRect mBorder; /**< The window border and background */ Image *mCloseImage; /**< Close Button Image */ + Image *mCloseImageHighlighted; /**< Highlighted close Button Image */ Image *mStickyImageUp; /**< Sticky Button Image */ Image *mStickyImageDown; /**< Sticky Button Image */ int mPadding; diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 751980d75..e49af5f15 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -75,6 +75,7 @@ Window::Window(const std::string &caption, const bool modal, mCaptionOffsetY(5), mCaptionAlign(gcn::Graphics::LEFT), mTitlePadding(4), + mResizeHandles(-1), mRedraw(true), mCaptionFont(getFont()) { @@ -195,7 +196,8 @@ void Window::draw(gcn::Graphics *graphics) // Draw Close Button if (mCloseButton) { - const Image *const button = mSkin->getCloseImage(); + const Image *const button = mSkin->getCloseImage( + mResizeHandles == CLOSE); if (button) g->drawImage(button, mCloseRect.x, mCloseRect.y); } @@ -388,11 +390,11 @@ void Window::widgetResized(const gcn::Event &event A_UNUSED) int h = area.height; mLayout->reflow(w, h); } - const bool showClose = mCloseButton && mSkin->getCloseImage(); + const bool showClose = mCloseButton && mSkin->getCloseImage(false); const int closePadding = getOption("closePadding"); if (showClose) { - const Image *const button = mSkin->getCloseImage(); + const Image *const button = mSkin->getCloseImage(false); const int x = getWidth() - button->getWidth() - closePadding; mCloseRect.x = x; mCloseRect.y = closePadding; @@ -406,7 +408,7 @@ void Window::widgetResized(const gcn::Event &event A_UNUSED) { int x = getWidth() - button->getWidth() - closePadding; if (showClose) - x -= mSkin->getCloseImage()->getWidth() + closePadding; + x -= mSkin->getCloseImage(false)->getWidth() + closePadding; mStickyRect.x = x; mStickyRect.y = closePadding; @@ -520,7 +522,7 @@ void Window::mousePressed(gcn::MouseEvent &event) } // Handle window resizing - mouseResize = getResizeHandles(event); + mouseResize = getResizeHandles(event) & resizeMask; if (canMove()) mMoved = !mouseResize; else @@ -557,10 +559,10 @@ void Window::mouseMoved(gcn::MouseEvent &event) if (!gui) return; - const int resizeHandles = getResizeHandles(event); + mResizeHandles = getResizeHandles(event); // Changes the custom mouse cursor based on it's current position. - switch (resizeHandles) + switch (mResizeHandles & resizeMask) { case BOTTOM | RIGHT: case TOP | LEFT: @@ -890,15 +892,16 @@ int Window::getResizeHandles(const gcn::MouseEvent &event) return 0; int resizeHandles = 0; + const unsigned y = event.getY(); + const unsigned x = event.getX(); + if (mCloseRect.isPointInRect(x, y)) + return CLOSE; + if (!mStickyButtonLock || !mSticky) { - const unsigned y = event.getY(); - if (mGrip && (y > mTitleBarHeight || (y < getPadding() && mTitleBarHeight > getPadding()))) { - const unsigned x = event.getX(); - if (!getWindowArea().isPointInRect(x, y) && event.getSource() == this) { diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 28976f2ca..01519e271 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -422,9 +422,12 @@ class Window : public gcn::Window, private gcn::WidgetListener TOP = 0x01, RIGHT = 0x02, BOTTOM = 0x04, - LEFT = 0x08 + LEFT = 0x08, + CLOSE = 0x10 }; + const int resizeMask = 8 + 4 + 2 + 1; + /** * Ensures the window is on the screen, moving it if necessary. This is * used by loadWindowState and setVisible(true), and when the screen @@ -479,6 +482,7 @@ class Window : public gcn::Window, private gcn::WidgetListener int mCaptionOffsetY; int mCaptionAlign; int mTitlePadding; + int mResizeHandles; bool mRedraw; gcn::Font *mCaptionFont; }; |