Set up resize cursor under resize handle (X11 only for now)

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2021-12-15 11:15:27 +00:00
parent b29c5ee81d
commit e226cbe101
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
2 changed files with 24 additions and 8 deletions

2
dpf

@ -1 +1 @@
Subproject commit ed6705a161e13565391e020389b6c1b7bd5ab742
Subproject commit 7357d71fa9ce01eab8707e775f862be7e3be0676

View file

@ -29,7 +29,8 @@ public:
explicit ResizeHandle(Window& window)
: TopLevelWidget(window),
handleSize(16),
resizing(false)
hasCursor(false),
isResizing(false)
{
resetArea();
}
@ -38,7 +39,7 @@ public:
explicit ResizeHandle(TopLevelWidget* const tlw)
: TopLevelWidget(tlw->getWindow()),
handleSize(16),
resizing(false)
isResizing(false)
{
resetArea();
}
@ -64,15 +65,16 @@ protected:
if (ev.press && area.contains(ev.pos))
{
resizing = true;
isResizing = true;
resizingSize = Size<double>(getWidth(), getHeight());
lastResizePoint = ev.pos;
return true;
}
if (resizing && ! ev.press)
if (isResizing && ! ev.press)
{
resizing = false;
isResizing = false;
recheckCursor(ev.pos);
return true;
}
@ -81,8 +83,11 @@ protected:
bool onMotion(const MotionEvent& ev) override
{
if (! resizing)
if (! isResizing)
{
recheckCursor(ev.pos);
return false;
}
const Size<double> offset(ev.pos.getX() - lastResizePoint.getX(),
ev.pos.getY() - lastResizePoint.getY());
@ -119,10 +124,21 @@ private:
uint handleSize;
// event handling state
bool resizing;
bool hasCursor, isResizing;
Point<double> lastResizePoint;
Size<double> resizingSize;
void recheckCursor(const Point<double>& pos)
{
const bool shouldSetCursor = area.contains(pos);
if (shouldSetCursor == hasCursor)
return;
hasCursor = shouldSetCursor;
setCursor(shouldSetCursor ? kMouseCursorDiagonal : kMouseCursorArrow);
}
void resetArea()
{
const double scaleFactor = getScaleFactor();