iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
ILEDControl.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
19#include "IControl.h"
20#include "Easing.h"
21
22BEGIN_IPLUG_NAMESPACE
23BEGIN_IGRAPHICS_NAMESPACE
24
27class ILEDControl : public IControl
28{
29public:
30 ILEDControl(const IRECT& bounds, float hue = 0.f)
31 : IControl(bounds)
32 , mHue(hue)
33 {
34 }
35
36 ILEDControl(const IRECT& bounds, const IColor& color)
37 : IControl(bounds)
38 {
39 float s,l,a;
40 color.GetHSLA(mHue, s, l, a);
41 }
42
43 void Draw(IGraphics& g) override
44 {
45 const float v = static_cast<float>(GetValue() * 0.65f);
46 const IColor c = IColor::FromHSLA(mHue, 1.f, v);
47 IRECT innerPart = mRECT.GetCentredInside(mRECT.W()/2.f);
48 IRECT flare = innerPart.GetScaledAboutCentre(1.f + v);
49 g.FillEllipse(c, innerPart, nullptr);
50 g.DrawEllipse(COLOR_BLACK, innerPart, nullptr, 1.f);
51 g.PathEllipse(flare);
52 IBlend b = {EBlend::Default, v};
53 g.PathFill(IPattern::CreateRadialGradient(mRECT.MW(), mRECT.MH(), mRECT.W()/2.f, {{c, 0.f}, {COLOR_TRANSPARENT, 1.f}}), {}, &b);
54 }
55
56 void TriggerWithDecay(int decayTimeMs)
57 {
58 SetAnimation([](IControl* pControl){
59 auto progress = pControl->GetAnimationProgress();
60
61 if(progress > 1.f) {
62 pControl->OnEndAnimation();
63 return;
64 }
65
66 pControl->SetValue(EaseCubicIn(1. -progress));
67
68 }, decayTimeMs);
69 }
70
71private:
72 float mHue = 0.f;
73};
74
75END_IGRAPHICS_NAMESPACE
76END_IPLUG_NAMESPACE
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
double GetAnimationProgress() const
Get the progress in a control's animation, in the range 0-1.
Definition: IControl.cpp:431
virtual void SetValue(double value, int valIdx=0)
Set one of the control's values.
Definition: IControl.cpp:147
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 FillEllipse(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill an ellipse within a rectangular region of the graphics context.
Definition: IGraphics.cpp:2613
virtual void DrawEllipse(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw an ellipse within a rectangular region of the graphics context.
Definition: IGraphics.cpp:2548
virtual void PathFill(const IPattern &pattern, const IFillOptions &options=IFillOptions(), const IBlend *pBlend=0)=0
Fill the current current path.
void PathEllipse(const IRECT &bounds)
Add an ellipse to the current path, specifying the rectangular region.
Definition: IGraphics.cpp:2683
Glowing LED control.
Definition: ILEDControl.h:28
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Definition: ILEDControl.h:43
Used to manage composite/blend operations, independent of draw class/platform.
Used to manage color data, independent of draw class/platform.
static IColor FromHSLA(float h, float s, float l, float a=1.f)
Create an IColor from Hue Saturation and Luminance values.
void GetHSLA(float &h, float &s, float &l, float &a) const
Get the Hue, Saturation and Luminance of the color.
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.
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
float MH() const
IRECT GetScaledAboutCentre(float scale) const
Get a copy of this IRECT where the width and height are multiplied by scale without changing the cent...
float W() const
float MW() const