iPlug2 - C++ Audio Plug-in Framework
TestColorControl.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 
22 class TestColorControl : public IControl
23 {
24 public:
25  TestColorControl(const IRECT& rect)
26  : IControl(rect)
27  {
28  SetTooltip("TestColorControl");
29  }
30 
31  void OnResize() override
32  {
33  mPattern = IPattern::CreateLinearGradient(mRECT.L, mRECT.MH(), mRECT.R, mRECT.MH());
34  const int nstops = 7;
35 
36  for (int i=0; i<nstops; i++) {
37  float pos = (1.f/(float) nstops) * i;
38  mPattern.AddStop(IColor::FromHSLA(pos, 1., 0.5), pos);
39  }
40  }
41 
42  void Draw(IGraphics& g) override
43  {
44  g.DrawDottedRect(COLOR_BLACK, mRECT);
45 
46 #ifndef IGRAPHICS_NANOVG
47  g.PathRect(mRECT);
48  g.PathFill(mPattern);
49 #else
50  g.DrawText(mText, "UNSUPPORTED", mRECT);
51 #endif
52  }
53 
54 private:
55  IPattern mPattern = IPattern(EPatternType::Linear);
56 };
void PathRect(const IRECT &bounds)
Add a rectangle to the current path.
Definition: IGraphics.cpp:2613
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
float MH() const
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
Used to manage a rectangular area, independent of draw class/platform.
virtual void DrawDottedRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f, float dashLen=2.f)
Draw a dotted rectangle to the graphics context.
Definition: IGraphics.cpp:2517
void SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:210
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
Definition: IGraphics.cpp:631
This file contains the base IControl implementation, along with some base classes for specific types ...
float R
Right side of the rectangle (X + W)
Control to colors.
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
Definition: IControl.cpp:81
virtual void PathFill(const IPattern &pattern, const IFillOptions &options=IFillOptions(), const IBlend *pBlend=0)=0
Fill the current current path.
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
static IColor FromHSLA(float h, float s, float l, float a=1.f)
Create an IColor from Hue Saturation and Luminance values.
float L
Left side of the rectangle (X)
void AddStop(IColor color, float offset)
Add an IColorStop to the IPattern.
static IPattern CreateLinearGradient(float x1, float y1, float x2, float y2, const std::initializer_list< IColorStop > &stops={})
Create a linear gradient IPattern.
Used to store pattern information for gradients.