Skip to content

Commit

Permalink
Alternative approach to resize handle, using nanovg
Browse files Browse the repository at this point in the history
  • Loading branch information
falkTX committed Oct 31, 2022
1 parent 6c954be commit 8a33946
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
47 changes: 16 additions & 31 deletions plugins/ProM/ResizeHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

#pragma once

#include "TopLevelWidget.hpp"
#include "Color.hpp"
#include "NanoVG.hpp"

START_NAMESPACE_DGL

/** Resize handle for DPF windows, will sit on bottom-right. */
class ResizeHandle : public TopLevelWidget
class ResizeHandle : public NanoTopLevelWidget
{
public:
/** Overloaded constructor, will fetch the window from an existing top-level widget. */
explicit ResizeHandle(TopLevelWidget* const tlw)
: TopLevelWidget(tlw->getWindow()),
: NanoTopLevelWidget(tlw->getWindow()),
handleSize(16),
hasCursor(false),
isResizing(false)
Expand All @@ -44,22 +43,19 @@ class ResizeHandle : public TopLevelWidget
}

protected:
void onDisplay() override
void onNanoDisplay() override
{
const GraphicsContext& context(getGraphicsContext());
const double lineWidth = 1.0 * getScaleFactor();

glMatrixMode(GL_MODELVIEW);
glLineWidth(lineWidth);
strokeWidth(lineWidth);

// draw white lines, 1px wide
glColor3f(1.0f, 1.0f, 1.0f);
strokeColor(Color(1.0f, 1.0f, 1.0f));
drawLine(l1);
drawLine(l2);
drawLine(l3);

// draw black lines, offset by 1px and 1px wide
glColor3f(0.0f, 0.0f, 0.0f);
strokeColor(Color(0.0f, 0.0f, 0.0f));
Line<double> l1b(l1), l2b(l2), l3b(l3);
l1b.moveBy(lineWidth, lineWidth);
l2b.moveBy(lineWidth, lineWidth);
Expand All @@ -69,6 +65,14 @@ class ResizeHandle : public TopLevelWidget
drawLine(l3b);
}

void drawLine(const Line<double>& line)
{
beginPath();
moveTo(line.getStartPos().getX(), line.getStartPos().getY());
lineTo(line.getEndPos().getX(), line.getEndPos().getY());
stroke();
}

bool onMouse(const MouseEvent& ev) override
{
if (ev.button != 1)
Expand Down Expand Up @@ -155,7 +159,7 @@ class ResizeHandle : public TopLevelWidget
void resetArea()
{
const double scaleFactor = getScaleFactor();
const uint margin = 0.0 * scaleFactor;
const uint margin = 2.0 * scaleFactor;
const uint size = handleSize * scaleFactor;

area = Rectangle<uint>(getWidth() - size - margin,
Expand Down Expand Up @@ -187,25 +191,6 @@ class ResizeHandle : public TopLevelWidget
l3.setEndPos(x + offset, y + linesize + offset);
}

void drawLine(const Line<double>& line)
{
drawLine(line.getStartPos(), line.getEndPos());
}

void drawLine(const Point<double>& posStart, const Point<double>& posEnd)
{
DISTRHO_SAFE_ASSERT_RETURN(posStart != posEnd,);

glBegin(GL_LINES);

{
glVertex2d(posStart.getX(), posStart.getY());
glVertex2d(posEnd.getX(), posEnd.getY());
}

glEnd();
}

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ResizeHandle)
};

Expand Down

0 comments on commit 8a33946

Please sign in to comment.