iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestBezierControl.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
18#include "IControl.h"
19
23{
24public:
25 TestBezierControl(const IRECT& rect)
26 : IControl(rect)
27 {
28 SetTooltip("TestBezierControl");
29 mP1 = mRECT.GetFromTLHC(20, 20);
30 mP2 = mRECT.GetFromTRHC(20, 20);
31 mC1 = mRECT.GetFromBLHC(20, 20);
32 mC2 = mRECT.GetFromBRHC(20, 20);
33 }
34
35 void Draw(IGraphics& g) override
36 {
37 g.FillRect(COLOR_WHITE, mRECT);
38
39
40 g.FillRect(COLOR_BLACK, mP1.GetCentredInside(5.f));
41 g.FillRect(COLOR_BLACK, mP2.GetCentredInside(5.f));
42 g.FillRect(COLOR_RED, mC1.GetCentredInside(5.f));
43 g.FillRect(COLOR_RED, mC2.GetCentredInside(5.f));
44
45 g.PathMoveTo(mP1.MW(), mP1.MH());
46 g.PathCubicBezierTo(mC1.MW(), mC1.MH(), mC2.MW(), mC2.MH(), mP2.MW(), mP2.MH());
47
48 g.PathStroke(COLOR_BLUE, 2.f);
49
50 g.PathMoveTo(mP1.MW(), mP1.MH());
51 g.PathQuadraticBezierTo(mC1.MW(), mC1.MH(), mP2.MW(), mP2.MH());
52 g.PathStroke(COLOR_GREEN, 2.f);
53
54
55 if(mMouseOverRect)
56 g.DrawRect(COLOR_BLACK, mMouseOverRect->GetCentredInside(8.f));
57 }
58
59 void OnMouseDown(float x, float y, const IMouseMod& mod) override
60 {
61 OnMouseDrag(x, y, 0., 0., mod);
62 }
63
64 void OnMouseUp(float x, float y, const IMouseMod& mod) override
65 {
66 mMouseOverRect = nullptr;
67 }
68
69 void OnMouseDrag(float x, float y, float, float, const IMouseMod& mod) override
70 {
71 if(mMouseOverRect)
72 *mMouseOverRect = IRECT(x-2.5f, y-2.5f, x+2.5f, y+2.5f);
73 SetDirty(false);
74 }
75
76 void OnMouseOver(float x, float y, const IMouseMod& mod) override
77 {
78 if(mP1.Contains(x, y))
79 mMouseOverRect = &mP1;
80 else if(mP2.Contains(x, y))
81 mMouseOverRect = &mP2;
82 else if(mC1.Contains(x, y))
83 mMouseOverRect = &mC1;
84 else if(mC2.Contains(x, y))
85 mMouseOverRect = &mC2;
86 else
87 mMouseOverRect = nullptr;
88 SetDirty(false);
89 }
90
91private:
92 IRECT mP1, mP2;
93 IRECT mC1, mC2;
94 IRECT* mMouseOverRect = nullptr;
95};
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:198
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
Definition: IGraphics.cpp:2497
virtual void PathStroke(const IPattern &pattern, float thickness, const IStrokeOptions &options=IStrokeOptions(), const IBlend *pBlend=0)=0
Stroke the current current path.
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
Definition: IGraphics.cpp:2569
virtual void PathMoveTo(float x, float y)=0
Move the current point in the current path.
virtual void PathQuadraticBezierTo(float cx, float cy, float x2, float y2)=0
Add a quadratic bezier to the current path from the current point to the specified location.
virtual void PathCubicBezierTo(float c1x, float c1y, float c2x, float c2y, float x2, float y2)=0
Add a cubic bezier to the current path from the current point to the specified location.
Control to test drawing bezier curves.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnMouseOver(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouseover event on this control.
void OnMouseDrag(float x, float y, float, float, const IMouseMod &mod) override
Implement this method to respond to a mouse drag event on this control.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
IRECT GetFromTRHC(float w, float h) const
Get a subrect of this IRECT expanding from the top-right corner.
IRECT GetFromTLHC(float w, float h) const
Get a subrect of this IRECT expanding from the top-left corner.
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
float MH() const
IRECT GetFromBLHC(float w, float h) const
Get a subrect of this IRECT expanding from the bottom-left corner.
IRECT GetFromBRHC(float w, float h) const
Get a subrect of this IRECT expanding from the bottom-right corner.
float MW() const
bool Contains(const IRECT &rhs) const
Returns true if this IRECT completely contains rhs.