iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
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
23{
24public:
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
54private:
55 IPattern mPattern = IPattern(EPatternType::Linear);
56};
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
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void PathFill(const IPattern &pattern, const IFillOptions &options=IFillOptions(), const IBlend *pBlend=0)=0
Fill the current current path.
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:670
void PathRect(const IRECT &bounds)
Add a rectangle to the current path.
Definition: IGraphics.cpp:2635
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:2539
Control to colors.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
void Draw(IGraphics &g) override
Draw the control to the graphics context.
static IColor FromHSLA(float h, float s, float l, float a=1.f)
Create an IColor from Hue Saturation and Luminance values.
Used to store pattern information for gradients.
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 manage a rectangular area, independent of draw class/platform.
float MH() const