diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-06-08 20:59:57 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-07-11 20:41:55 +0200 |
commit | 6b89b661df1a2682edfa491e1bb9a21c4ab0943c (patch) | |
tree | 11bbe888ecf9b45eeb78e371c00b950e9c4c4cac /src/gui/widgets/window.cpp | |
parent | b3836dd46658d8bc24af2d60c5e7904d7f051bca (diff) | |
download | mana-6b89b661df1a2682edfa491e1bb9a21c4ab0943c.tar.gz mana-6b89b661df1a2682edfa491e1bb9a21c4ab0943c.tar.bz2 mana-6b89b661df1a2682edfa491e1bb9a21c4ab0943c.tar.xz mana-6b89b661df1a2682edfa491e1bb9a21c4ab0943c.zip |
Cleaned up ImageRect a little
* Use `std::unique_ptr`, so we can get rid of the custom move
constructor and destructor.
* Move and rename the `ImagePosition` enum to `WindowAlignment`, which
fits better with what this enum is actually used for.
Diffstat (limited to 'src/gui/widgets/window.cpp')
-rw-r--r-- | src/gui/widgets/window.cpp | 68 |
1 files changed, 11 insertions, 57 deletions
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index b05731bd..bf496bd8 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -191,52 +191,6 @@ void Window::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } -void Window::setLocationRelativeTo(ImageRect::ImagePosition position, - int offsetX, int offsetY) -{ - if (position == ImageRect::UPPER_LEFT) - { - } - else if (position == ImageRect::UPPER_CENTER) - { - offsetX += (graphics->getWidth() - getWidth()) / 2; - } - else if (position == ImageRect::UPPER_RIGHT) - { - offsetX += graphics->getWidth() - getWidth(); - } - else if (position == ImageRect::LEFT) - { - offsetY += (graphics->getHeight() - getHeight()) / 2; - } - else if (position == ImageRect::CENTER) - { - offsetX += (graphics->getWidth() - getWidth()) / 2; - offsetY += (graphics->getHeight() - getHeight()) / 2; - } - else if (position == ImageRect::RIGHT) - { - offsetX += graphics->getWidth() - getWidth(); - offsetY += (graphics->getHeight() - getHeight()) / 2; - } - else if (position == ImageRect::LOWER_LEFT) - { - offsetY += graphics->getHeight() - getHeight(); - } - else if (position == ImageRect::LOWER_CENTER) - { - offsetX += (graphics->getWidth() - getWidth()) / 2; - offsetY += graphics->getHeight() - getHeight(); - } - else if (position == ImageRect::LOWER_RIGHT) - { - offsetX += graphics->getWidth() - getWidth(); - offsetY += graphics->getHeight() - getHeight(); - } - - setPosition(offsetX, offsetY); -} - void Window::setMinWidth(int width) { mMinWinWidth = std::max(getSkin().getMinWidth(), width); @@ -599,41 +553,41 @@ void Window::setDefaultSize() } void Window::setDefaultSize(int defaultWidth, int defaultHeight, - ImageRect::ImagePosition position, + WindowAlignment alignment, int offsetX, int offsetY) { int x = 0; int y = 0; - switch (position) + switch (alignment) { - case ImageRect::UPPER_LEFT: + case WindowAlignment::TopLeft: break; - case ImageRect::UPPER_CENTER: + case WindowAlignment::Top: x = (graphics->getWidth() - defaultWidth) / 2; break; - case ImageRect::UPPER_RIGHT: + case WindowAlignment::TopRight: x = graphics->getWidth() - defaultWidth; break; - case ImageRect::LEFT: + case WindowAlignment::Left: y = (graphics->getHeight() - defaultHeight) / 2; break; - case ImageRect::CENTER: + case WindowAlignment::Center: x = (graphics->getWidth() - defaultWidth) / 2; y = (graphics->getHeight() - defaultHeight) / 2; break; - case ImageRect::RIGHT: + case WindowAlignment::Right: x = graphics->getWidth() - defaultWidth; y = (graphics->getHeight() - defaultHeight) / 2; break; - case ImageRect::LOWER_LEFT: + case WindowAlignment::BottomLeft: y = graphics->getHeight() - defaultHeight; break; - case ImageRect::LOWER_CENTER: + case WindowAlignment::Bottom: x = (graphics->getWidth() - defaultWidth) / 2; y = graphics->getHeight() - defaultHeight; break; - case ImageRect::LOWER_RIGHT: + case WindowAlignment::BottomRight: x = graphics->getWidth() - defaultWidth; y = graphics->getHeight() - defaultHeight; break; |