11/*
22 * Resize handle for DPF
3- * Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
3+ * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
44 *
55 * Permission to use, copy, modify, and/or distribute this software for any purpose with
66 * or without fee is hereby granted, provided that the above copyright notice and this
@@ -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,12 +39,14 @@ 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 }
4547
46- /* * Set the handle size, minimum 16. */
48+ /* * Set the handle size, minimum 16.
49+ * Scale factor is automatically applied on top of this size as needed */
4750 void setHandleSize (const uint size)
4851 {
4952 handleSize = std::max (16u , size);
@@ -53,12 +56,14 @@ class ResizeHandle : public TopLevelWidget
5356protected:
5457 void onDisplay () override
5558 {
59+ // TODO implement gl3 stuff in DPF
60+ #ifndef DGL_USE_OPENGL3
5661 const GraphicsContext& context (getGraphicsContext ());
5762 const double lineWidth = 1.0 * getScaleFactor ();
5863
59- # ifdef DGL_OPENGL
64+ # if defined( DGL_OPENGL) && !defined(DGL_USE_OPENGL3)
6065 glMatrixMode (GL_MODELVIEW );
61- #endif
66+ #endif
6267
6368 // draw white lines, 1px wide
6469 Color (1 .0f , 1 .0f , 1 .0f ).setFor (context);
@@ -75,6 +80,7 @@ class ResizeHandle : public TopLevelWidget
7580 l1b.draw (context, lineWidth);
7681 l2b.draw (context, lineWidth);
7782 l3b.draw (context, lineWidth);
83+ #endif
7884 }
7985
8086 bool onMouse (const MouseEvent& ev) override
@@ -84,15 +90,16 @@ class ResizeHandle : public TopLevelWidget
8490
8591 if (ev.press && area.contains (ev.pos ))
8692 {
87- resizing = true ;
93+ isResizing = true ;
8894 resizingSize = Size<double >(getWidth (), getHeight ());
8995 lastResizePoint = ev.pos ;
9096 return true ;
9197 }
9298
93- if (resizing && ! ev.press )
99+ if (isResizing && ! ev.press )
94100 {
95- resizing = false ;
101+ isResizing = false ;
102+ recheckCursor (ev.pos );
96103 return true ;
97104 }
98105
@@ -101,18 +108,23 @@ class ResizeHandle : public TopLevelWidget
101108
102109 bool onMotion (const MotionEvent& ev) override
103110 {
104- if (! resizing)
111+ if (! isResizing)
112+ {
113+ recheckCursor (ev.pos );
105114 return false ;
115+ }
106116
107117 const Size<double > offset (ev.pos .getX () - lastResizePoint.getX (),
108118 ev.pos .getY () - lastResizePoint.getY ());
109119
110120 resizingSize += offset;
111121 lastResizePoint = ev.pos ;
112122
113- // TODO min width, min height
114- const uint minWidth = 16 ;
115- const uint minHeight = 16 ;
123+ // TODO keepAspectRatio
124+ bool keepAspectRatio;
125+ const Size<uint> minSize (getWindow ().getGeometryConstraints (keepAspectRatio));
126+ const uint minWidth = minSize.getWidth ();
127+ const uint minHeight = minSize.getHeight ();
116128
117129 if (resizingSize.getWidth () < minWidth)
118130 resizingSize.setWidth (minWidth);
@@ -139,10 +151,21 @@ class ResizeHandle : public TopLevelWidget
139151 uint handleSize;
140152
141153 // event handling state
142- bool resizing ;
154+ bool hasCursor, isResizing ;
143155 Point<double > lastResizePoint;
144156 Size<double > resizingSize;
145157
158+ void recheckCursor (const Point<double >& pos)
159+ {
160+ const bool shouldHaveCursor = area.contains (pos);
161+
162+ if (shouldHaveCursor == hasCursor)
163+ return ;
164+
165+ hasCursor = shouldHaveCursor;
166+ setCursor (shouldHaveCursor ? kMouseCursorDiagonal : kMouseCursorArrow );
167+ }
168+
146169 void resetArea ()
147170 {
148171 const double scaleFactor = getScaleFactor ();
0 commit comments