summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-17 12:53:42 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-18 09:58:02 +0000
commitb6d579993a68cdf59c4d0759ad5e848005678d4b (patch)
tree3a0f83621280526332106d0770e63fb800011e8d /src/gui
parent77846cfb61a3e4793d3fae5c1cc23fb68851c9ac (diff)
downloadmana-b6d579993a68cdf59c4d0759ad5e848005678d4b.tar.gz
mana-b6d579993a68cdf59c4d0759ad5e848005678d4b.tar.bz2
mana-b6d579993a68cdf59c4d0759ad5e848005678d4b.tar.xz
mana-b6d579993a68cdf59c4d0759ad5e848005678d4b.zip
Added small grabbable margin to Shortcuts window
The Shortcuts window could no longer be moved since adding support for resizing windows at the top edge. Now there is again a bit of space where the window can be grabbed. Included some related cleanups.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/shortcutwindow.cpp40
-rw-r--r--src/gui/shortcutwindow.h11
-rw-r--r--src/gui/widgets/scrollarea.cpp1
-rw-r--r--src/gui/widgets/shortcutcontainer.h17
-rw-r--r--src/gui/widgets/window.cpp44
5 files changed, 32 insertions, 81 deletions
diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp
index e13dcd74..7d299d2c 100644
--- a/src/gui/shortcutwindow.cpp
+++ b/src/gui/shortcutwindow.cpp
@@ -27,42 +27,33 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/shortcutcontainer.h"
-static const int SCROLL_PADDING = 0;
-
-int ShortcutWindow::mBoxesWidth = 0;
+static constexpr int GRAB_MARGIN = 4;
ShortcutWindow::ShortcutWindow(const std::string &title,
ShortcutContainer *content)
{
setWindowName(title);
- // no title presented, title bar is padding so window can be moved.
- gcn::Window::setTitleBarHeight(gcn::Window::getPadding());
+ // no title presented, title bar gets some extra space so window can be moved.
+ setTitleBarHeight(getPadding() + GRAB_MARGIN);
setShowTitle(false);
setResizable(true);
setDefaultVisible(false);
setSaveVisible(true);
setupWindow->registerWindowForReset(this);
- mItems = content;
-
- const int border = SCROLL_PADDING * 2 + getPadding() * 2;
- setMinWidth(mItems->getBoxWidth() + border);
- setMinHeight(mItems->getBoxHeight() + border);
- setMaxWidth(mItems->getBoxWidth() * mItems->getMaxItems() + border);
- setMaxHeight(mItems->getBoxHeight() * mItems->getMaxItems() + border);
-
- setDefaultSize(mItems->getBoxWidth() + border, mItems->getBoxHeight() *
- mItems->getMaxItems() + border, ImageRect::LOWER_RIGHT,
- mBoxesWidth, 0);
+ const int border = getPadding() * 2;
+ setMinWidth(content->getBoxWidth() + border);
+ setMinHeight(content->getBoxHeight() + border + GRAB_MARGIN);
+ setMaxWidth(content->getBoxWidth() * content->getMaxItems() + border);
+ setMaxHeight(content->getBoxHeight() * content->getMaxItems() + border + GRAB_MARGIN);
- mBoxesWidth += mItems->getBoxWidth() + border;
+ setDefaultSize(getMinWidth(), getMaxHeight(), ImageRect::LOWER_RIGHT);
- mScrollArea = new ScrollArea(mItems);
- mScrollArea->setPosition(SCROLL_PADDING, SCROLL_PADDING);
- mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mScrollArea->setOpaque(false);
+ auto scrollArea = new ScrollArea(content);
+ scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ scrollArea->setOpaque(false);
- place(0, 0, mScrollArea, 5, 5).setPadding(0);
+ place(0, 0, scrollArea, 5, 5).setPadding(0);
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
@@ -70,8 +61,3 @@ ShortcutWindow::ShortcutWindow(const std::string &title,
loadWindowState();
}
-
-ShortcutWindow::~ShortcutWindow()
-{
- delete mItems;
-}
diff --git a/src/gui/shortcutwindow.h b/src/gui/shortcutwindow.h
index 6fdafcb8..7494dfed 100644
--- a/src/gui/shortcutwindow.h
+++ b/src/gui/shortcutwindow.h
@@ -24,7 +24,6 @@
#include "gui/widgets/window.h"
-class ScrollArea;
class ShortcutContainer;
/**
@@ -36,16 +35,6 @@ class ShortcutWindow : public Window
{
public:
ShortcutWindow(const std::string &title, ShortcutContainer *content);
-
- ~ShortcutWindow() override;
-
- private:
- ShortcutWindow();
- ShortcutContainer *mItems;
-
- ScrollArea *mScrollArea;
-
- static int mBoxesWidth;
};
extern ShortcutWindow *itemShortcutWindow;
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index e153ba65..8e16b5b3 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -50,7 +50,6 @@ ScrollArea::ScrollArea(gcn::Widget *widget):
ScrollArea::~ScrollArea()
{
- // Garbage collection
delete getContent();
instances--;
diff --git a/src/gui/widgets/shortcutcontainer.h b/src/gui/widgets/shortcutcontainer.h
index 449a06f3..cab20f27 100644
--- a/src/gui/widgets/shortcutcontainer.h
+++ b/src/gui/widgets/shortcutcontainer.h
@@ -40,8 +40,6 @@ class ShortcutContainer : public gcn::Widget,
public:
ShortcutContainer();
- ~ShortcutContainer() override {}
-
/**
* Draws the shortcuts
*/
@@ -53,21 +51,6 @@ class ShortcutContainer : public gcn::Widget,
*/
void widgetResized(const gcn::Event &event) override;
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(gcn::MouseEvent &event) override = 0;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(gcn::MouseEvent &event) override = 0;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(gcn::MouseEvent &event) override = 0;
-
int getMaxItems() const
{ return mMaxItems; }
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 6231bcbf..7e5c9ad9 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -604,44 +604,38 @@ void Window::setDefaultSize(int defaultWidth, int defaultHeight,
int x = 0;
int y = 0;
- if (position == ImageRect::UPPER_LEFT)
- {
- }
- else if (position == ImageRect::UPPER_CENTER)
+ switch (position)
{
+ case ImageRect::UPPER_LEFT:
+ break;
+ case ImageRect::UPPER_CENTER:
x = (graphics->getWidth() - defaultWidth) / 2;
- }
- else if (position == ImageRect::UPPER_RIGHT)
- {
+ break;
+ case ImageRect::UPPER_RIGHT:
x = graphics->getWidth() - defaultWidth;
- }
- else if (position == ImageRect::LEFT)
- {
+ break;
+ case ImageRect::LEFT:
y = (graphics->getHeight() - defaultHeight) / 2;
- }
- else if (position == ImageRect::CENTER)
- {
+ break;
+ case ImageRect::CENTER:
x = (graphics->getWidth() - defaultWidth) / 2;
y = (graphics->getHeight() - defaultHeight) / 2;
- }
- else if (position == ImageRect::RIGHT)
- {
+ break;
+ case ImageRect::RIGHT:
x = graphics->getWidth() - defaultWidth;
y = (graphics->getHeight() - defaultHeight) / 2;
- }
- else if (position == ImageRect::LOWER_LEFT)
- {
+ break;
+ case ImageRect::LOWER_LEFT:
y = graphics->getHeight() - defaultHeight;
- }
- else if (position == ImageRect::LOWER_CENTER)
- {
+ break;
+ case ImageRect::LOWER_CENTER:
x = (graphics->getWidth() - defaultWidth) / 2;
y = graphics->getHeight() - defaultHeight;
- }
- else if (position == ImageRect::LOWER_RIGHT)
- {
+ break;
+ case ImageRect::LOWER_RIGHT:
x = graphics->getWidth() - defaultWidth;
y = graphics->getHeight() - defaultHeight;
+ break;
}
mDefaultX = x - offsetX;