iPlug2 - C++ Audio Plug-in Framework
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 {
24 public:
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);
64  IKnobControlBase::OnMouseUp(x, y, mod);
65  }
66 };
float MW() const
float MH() const
Used to manage a rectangular area, independent of draw class/platform.
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:2496
Used to manage mouse modifiers i.e.
void SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:210
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:2482
Used to manage color data, independent of draw class/platform.
This file contains the base IControl implementation, along with some base classes for specific types ...
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
float W() const
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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:2554
void Draw(IGraphics &g) override
Draw the control to the graphics context.
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1191
virtual void HideMouseCursor(bool hide=true, bool lock=true)=0
Call to hide/show the mouse cursor.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
double GetValue(int valIdx=0) const
Get the control&#39;s value.
Definition: IControl.cpp:151
IGraphics * GetUI()
Definition: IControl.h:452
Control to test drawing polygons.
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:808
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
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:797
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:2568