Browse Source

Alternative approach to resize handle, using nanovg

master
falkTX 2 years ago
parent
commit
8a339464c8
2 changed files with 17 additions and 32 deletions
  1. +1
    -1
      dpf
  2. +16
    -31
      plugins/ProM/ResizeHandle.hpp

+ 1
- 1
dpf

@@ -1 +1 @@
Subproject commit ec2862546a3613190e5dadf939efb6e4deff41fe
Subproject commit b52112bf23ef7eb91883828b27f12bb15cb671ac

+ 16
- 31
plugins/ProM/ResizeHandle.hpp View File

@@ -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)
@@ -44,22 +43,19 @@ public:
}

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);
@@ -69,6 +65,14 @@ protected:
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)
@@ -155,7 +159,7 @@ private:
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,
@@ -187,25 +191,6 @@ private:
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)
};



Loading…
Cancel
Save