iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestPolyControl.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 TestPolyControl(IRECT rect, int paramIdx = kNoParameter)
26 : IKnobControlBase(rect, paramIdx)
27 {
28 SetTooltip("TestPolyControl");
29 }
30
31 void Draw(IGraphics& g) override
32 {
33 const float value = (float) GetValue();
34 float xarray[32];
35 float yarray[32];
36 int npoints = 3 + (int) roundf((float) value * 29.f);
37 float angle = (-0.75f * (float) PI) + (float) value * (1.5f * (float) PI);
38 float incr = (2.f * (float) PI) / npoints;
39 float cr = (float) value * (mRECT.W() / 2.f);
40
41 g.FillRoundRect(COLOR_WHITE, mRECT.GetPadded(-2.f), cr);
42 g.DrawRoundRect(COLOR_BLACK, mRECT.GetPadded(-2.f), cr);
43
44 for (int i = 0; i < npoints; i++)
45 {
46 xarray[i] = mRECT.MW() + sinf(angle + (float) i * incr) * mRECT.W() * 0.45f;
47 yarray[i] = mRECT.MH() + cosf(angle + (float) i * incr) * mRECT.W() * 0.45f;
48 }
49
50 //IBlend blend { EBlend::Default, 0.5 };
51 g.FillConvexPolygon(IColor(120, 255, 127, 0), xarray, yarray, npoints);//, &blend);
52 g.DrawConvexPolygon(COLOR_BLACK, xarray, yarray, npoints);
53 }
54
55 void OnMouseDown(float x, float y, const IMouseMod& mod) override
56 {
59 }
60
61 void OnMouseUp(float x, float y, const IMouseMod& mod) override
62 {
63 GetUI()->HideMouseCursor(false);
65 }
66};
This file contains the base IControl implementation, along with some base classes for specific types ...
IGraphics * GetUI()
Definition: IControl.h:467
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
double GetValue(int valIdx=0) const
Get the control's value.
Definition: IControl.cpp:153
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void DrawConvexPolygon(const IColor &color, float *x, float *y, int nPoints, const IBlend *pBlend=0, float thickness=1.f)
Draw a convex polygon to the graphics context.
Definition: IGraphics.cpp:2518
virtual void DrawRoundRect(const IColor &color, const IRECT &bounds, float cornerRadius=5.f, const IBlend *pBlend=0, float thickness=1.f)
Draw a rounded rectangle to the graphics context.
Definition: IGraphics.cpp:2504
virtual void FillRoundRect(const IColor &color, const IRECT &bounds, float cornerRadius=5.f, const IBlend *pBlend=0)
Fill a rounded rectangle with a color.
Definition: IGraphics.cpp:2576
virtual void FillConvexPolygon(const IColor &color, float *x, float *y, int nPoints, const IBlend *pBlend=0)
Fill a convex polygon with a color.
Definition: IGraphics.cpp:2590
virtual void HideMouseCursor(bool hide=true, bool lock=true)=0
Call to hide/show the mouse cursor.
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1368
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
Definition: IControl.cpp:799
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
Definition: IControl.cpp:810
Control to test drawing polygons.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
Used to manage color data, independent of draw class/platform.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
float MH() const
float W() const
float MW() const
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.