Skip to content

Commit 14f1257

Browse files
committed
Update resize handle
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 61293d0 commit 14f1257

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

plugins/ProM/ResizeHandle.hpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class ResizeHandle : public TopLevelWidget
2929
explicit ResizeHandle(Window& window)
3030
: TopLevelWidget(window),
3131
handleSize(16),
32-
resizing(false)
32+
hasCursor(false),
33+
isResizing(false)
3334
{
3435
resetArea();
3536
}
@@ -38,7 +39,8 @@ class ResizeHandle : public TopLevelWidget
3839
explicit ResizeHandle(TopLevelWidget* const tlw)
3940
: TopLevelWidget(tlw->getWindow()),
4041
handleSize(16),
41-
resizing(false)
42+
hasCursor(false),
43+
isResizing(false)
4244
{
4345
resetArea();
4446
}
@@ -56,12 +58,9 @@ class ResizeHandle : public TopLevelWidget
5658
const GraphicsContext& context(getGraphicsContext());
5759
const double lineWidth = 1.0 * getScaleFactor();
5860

59-
#ifdef DGL_OPENGL
60-
glUseProgram(0);
61-
# ifndef DGL_USE_OPENGL3
61+
#if defined(DGL_OPENGL) && !defined(DGL_USE_OPENGL3)
6262
glMatrixMode(GL_MODELVIEW);
63-
# endif
64-
#endif
63+
#endif
6564

6665
// draw white lines, 1px wide
6766
Color(1.0f, 1.0f, 1.0f).setFor(context);
@@ -87,15 +86,16 @@ class ResizeHandle : public TopLevelWidget
8786

8887
if (ev.press && area.contains(ev.pos))
8988
{
90-
resizing = true;
89+
isResizing = true;
9190
resizingSize = Size<double>(getWidth(), getHeight());
9291
lastResizePoint = ev.pos;
9392
return true;
9493
}
9594

96-
if (resizing && ! ev.press)
95+
if (isResizing && ! ev.press)
9796
{
98-
resizing = false;
97+
isResizing = false;
98+
recheckCursor(ev.pos);
9999
return true;
100100
}
101101

@@ -104,18 +104,23 @@ class ResizeHandle : public TopLevelWidget
104104

105105
bool onMotion(const MotionEvent& ev) override
106106
{
107-
if (! resizing)
107+
if (! isResizing)
108+
{
109+
recheckCursor(ev.pos);
108110
return false;
111+
}
109112

110113
const Size<double> offset(ev.pos.getX() - lastResizePoint.getX(),
111114
ev.pos.getY() - lastResizePoint.getY());
112115

113116
resizingSize += offset;
114117
lastResizePoint = ev.pos;
115118

116-
// TODO min width, min height
117-
const uint minWidth = 16;
118-
const uint minHeight = 16;
119+
// TODO keepAspectRatio
120+
bool keepAspectRatio;
121+
const Size<uint> minSize(getWindow().getGeometryConstraints(keepAspectRatio));
122+
const uint minWidth = minSize.getWidth();
123+
const uint minHeight = minSize.getHeight();
119124

120125
if (resizingSize.getWidth() < minWidth)
121126
resizingSize.setWidth(minWidth);
@@ -142,10 +147,21 @@ class ResizeHandle : public TopLevelWidget
142147
uint handleSize;
143148

144149
// event handling state
145-
bool resizing;
150+
bool hasCursor, isResizing;
146151
Point<double> lastResizePoint;
147152
Size<double> resizingSize;
148153

154+
void recheckCursor(const Point<double>& pos)
155+
{
156+
const bool shouldHaveCursor = area.contains(pos);
157+
158+
if (shouldHaveCursor == hasCursor)
159+
return;
160+
161+
hasCursor = shouldHaveCursor;
162+
setCursor(shouldHaveCursor ? kMouseCursorDiagonal : kMouseCursorArrow);
163+
}
164+
149165
void resetArea()
150166
{
151167
const double scaleFactor = getScaleFactor();

0 commit comments

Comments
 (0)