iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestGradientControl.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 TestGradientControl(IRECT rect, int paramIdx = kNoParameter)
26 : IKnobControlBase(rect, paramIdx)
27 {
28 SetTooltip("TestGradientControl");
29 RandomiseGradient();
30 }
31
32 void Draw(IGraphics& g) override
33 {
34 g.DrawDottedRect(COLOR_BLACK, mRECT);
35
36 float cr = static_cast<float>(GetValue()) * (mRECT.H() / 2.f);
37 g.PathRoundRect(mRECT.GetPadded(-2.f), cr);
38 IFillOptions fillOptions;
39 IStrokeOptions strokeOptions;
40 fillOptions.mPreserve = true;
41 g.PathFill(mPattern, fillOptions);
42 g.PathStroke(IColor(255, 0, 0, 0), 3, strokeOptions);
43 }
44
45 void OnMouseDown(float x, float y, const IMouseMod& mod) override
46 {
47 RandomiseGradient();
48 SetDirty(false);
49 }
50
51 void OnResize() override
52 {
53 RandomiseGradient();
54 }
55
56private:
57
58 void RandomiseGradient()
59 {
60 //IPattern tmp(EPatternType::Linear);
61 //tmp.SetTransform(1.0/mRECT.W(), 0, 0, 1.0/mRECT.W(), 1.0/mRECT.W()*-mRECT.L, 1.0/mRECT.W()*-mRECT.T);
62 IPattern tmp(EPatternType::Solid);
63
64 if (std::rand() & 0x100)
65 tmp = IPattern::CreateRadialGradient(mRECT.MW(), mRECT.MH(), mRECT.MH());
66 else
67 tmp = IPattern::CreateLinearGradient(mRECT.L, mRECT.MH(), mRECT.L + mRECT.W() * 0.5f, mRECT.MH());
68
69 tmp.mExtend = (std::rand() & 0x10) ? ((std::rand() & 0x1000) ? EPatternExtend::None : EPatternExtend::Pad) : ((std::rand() & 0x1000) ? EPatternExtend::Repeat : EPatternExtend::Reflect);
70
71 tmp.AddStop(IColor::GetRandomColor(), 0.0f);
72 tmp.AddStop(IColor::GetRandomColor(), 0.1f);
73 tmp.AddStop(IColor::GetRandomColor(), 0.4f);
74 tmp.AddStop(IColor::GetRandomColor(), 0.6f);
75 tmp.AddStop(IColor::GetRandomColor(), 1.0f);
76
77 mPattern = tmp;
78 }
79
80 IPattern mPattern = IPattern(EPatternType::Linear);
81};
This file contains the base IControl implementation, along with some base classes for specific types ...
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
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 PathFill(const IPattern &pattern, const IFillOptions &options=IFillOptions(), const IBlend *pBlend=0)=0
Fill the current current path.
void PathRoundRect(const IRECT &bounds, float ctl, float ctr, float cbl, float cbr)
Add a rounded rectangle to the current path, with independent corner roundness.
Definition: IGraphics.cpp:2644
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
virtual void PathStroke(const IPattern &pattern, float thickness, const IStrokeOptions &options=IStrokeOptions(), const IBlend *pBlend=0)=0
Stroke the current current path.
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1368
Control to test drawing gradients with path based drawing backends.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Used to manage stroke behaviour for path based drawing back ends.
Used to manage color data, independent of draw class/platform.
static IColor GetRandomColor(bool randomAlpha=false)
Get a random IColor.
Used to manage fill behaviour.
Used to manage mouse modifiers i.e.
Used to store pattern information for gradients.
static IPattern CreateLinearGradient(float x1, float y1, float x2, float y2, const std::initializer_list< IColorStop > &stops={})
Create a linear gradient IPattern.
static IPattern CreateRadialGradient(float x1, float y1, float r, const std::initializer_list< IColorStop > &stops={})
Create a radial gradient IPattern.
Used to manage a rectangular area, independent of draw class/platform.
float MH() const
float W() const
float H() const
float MW() const
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.