Skip to content

Commit

Permalink
Update resize handle
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Jan 9, 2022
1 parent 61293d0 commit 14f1257
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions plugins/ProM/ResizeHandle.hpp
Expand Up @@ -29,7 +29,8 @@ class ResizeHandle : public TopLevelWidget
explicit ResizeHandle(Window& window)
: TopLevelWidget(window),
handleSize(16),
resizing(false)
hasCursor(false),
isResizing(false)
{
resetArea();
}
Expand All @@ -38,7 +39,8 @@ class ResizeHandle : public TopLevelWidget
explicit ResizeHandle(TopLevelWidget* const tlw)
: TopLevelWidget(tlw->getWindow()),
handleSize(16),
resizing(false)
hasCursor(false),
isResizing(false)
{
resetArea();
}
Expand All @@ -56,12 +58,9 @@ class ResizeHandle : public TopLevelWidget
const GraphicsContext& context(getGraphicsContext());
const double lineWidth = 1.0 * getScaleFactor();

#ifdef DGL_OPENGL
glUseProgram(0);
# ifndef DGL_USE_OPENGL3
#if defined(DGL_OPENGL) && !defined(DGL_USE_OPENGL3)
glMatrixMode(GL_MODELVIEW);
# endif
#endif
#endif

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

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;
}

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

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());

resizingSize += offset;
lastResizePoint = ev.pos;

// TODO min width, min height
const uint minWidth = 16;
const uint minHeight = 16;
// TODO keepAspectRatio
bool keepAspectRatio;
const Size<uint> minSize(getWindow().getGeometryConstraints(keepAspectRatio));
const uint minWidth = minSize.getWidth();
const uint minHeight = minSize.getHeight();

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

// event handling state
bool resizing;
bool hasCursor, isResizing;
Point<double> lastResizePoint;
Size<double> resizingSize;

void recheckCursor(const Point<double>& pos)
{
const bool shouldHaveCursor = area.contains(pos);

if (shouldHaveCursor == hasCursor)
return;

hasCursor = shouldHaveCursor;
setCursor(shouldHaveCursor ? kMouseCursorDiagonal : kMouseCursorArrow);
}

void resetArea()
{
const double scaleFactor = getScaleFactor();
Expand Down

0 comments on commit 14f1257

Please sign in to comment.