-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSGainStatsView.h
109 lines (93 loc) · 5.22 KB
/
JSGainStatsView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//------------------------------------------------------------------------------------------------------------
// This file defines a custom view which doesn't inherit from any control from the vst sdk. It will display
// the stats in a little window. This class gives access to fParams and fState and shows how to create a
// "Creator" which allows the view to be accessible in the "editor" like all other VST SDK views with custom
// attributes. It also shows how to create a timer in the GUI layer.
//------------------------------------------------------------------------------------------------------------
#pragma once
#include <pongasoft/VST/GUI/Views/CustomView.h>
#include <pongasoft/VST/Timer.h>
#include "../JSGainPlugin.h"
namespace pongasoft::VST::JSGain::GUI {
using namespace pongasoft::VST::GUI::Views;
using namespace VSTGUI;
//------------------------------------------------------------------------------------------------------------
// By inheriting from PluginCustomView<JSGainGUIState>, this view will inherit the default behaviors of
// pongasoft::VST::GUI::Views::CustomView and add fState and fParams for dealing for parameters/state.
//------------------------------------------------------------------------------------------------------------
class JSGainStatsView : public StateAwareCustomView<JSGainGUIState>, public ITimerCallback
{
public:
// Constructor
explicit JSGainStatsView(const CRect &iSize) : StateAwareCustomView<JSGainGUIState>(iSize)
{}
//------------------------------------------------------------------------
// tied to custom attribute "text-color" (see Creator below)
//------------------------------------------------------------------------
const CColor &getTextColor() const { return fTextColor; }
void setTextColor(const CColor &iColor) { fTextColor = iColor; }
//------------------------------------------------------------------------
// tied to custom attribute "font" (see Creator below)
//------------------------------------------------------------------------
FontPtr getFont() const { return fFont; }
void setFont(FontPtr iFont) { fFont = iFont; }
//------------------------------------------------------------------------
// This is the method that registers the parameter with the framework: the
// place where fStatsParam is assigned and registered to be notified for
// changes.
//------------------------------------------------------------------------
void registerParameters() override;
//------------------------------------------------------------------------
// This view will handle its own drawing
//------------------------------------------------------------------------
void draw(CDrawContext *iContext) override;
//------------------------------------------------------------------------
// Callback (from ITimerCallback) when the timer fires
//------------------------------------------------------------------------
void onTimer(Timer *timer) override;
CLASS_METHODS_NOCOPY(JSGainStatsView, CustomView)
protected:
CColor fTextColor{};
FontSPtr fFont{nullptr};
//------------------------------------------------------------------------
// Using a Jmb param to get to the stats (see registerParameters)
// GUIJmbParam is a wrapper class (similar to the other ones) which gives
// access to the param and make it behave like the underlying type (Stats
// in this case).
//------------------------------------------------------------------------
GUIJmbParam<Stats> fStatsParam{};
//------------------------------------------------------------------------
// Using the Jamba AutoReleaseTimer class which takes care of releasing
// the timer automatically (RAII concept)
//------------------------------------------------------------------------
std::unique_ptr<AutoReleaseTimer> fTimer{};
public:
//------------------------------------------------------------------------
// The Creator class is what makes this new view accessible in the editor.
// It has 2 custom attributes (text-color and font).
// The 1st type in CustomViewCreator is this view
// The 2nd type is the parent view so that it automatically adds all the
// attributes of the parent view (like back-color, custom-view-tag,
// editor-mode).
// Check the .cpp to see where/how the creator is instantiated.
//------------------------------------------------------------------------
class Creator : public CustomViewCreator<JSGainStatsView, StateAwareCustomView<JSGainGUIState>>
{
public:
explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) noexcept :
CustomViewCreator(iViewName, iDisplayName)
{
//------------------------------------------------------------------------
// Each type of attribute has its own register<Type>Attribute method
// Note how you simply references the getter and setter in the call
//------------------------------------------------------------------------
registerColorAttribute("text-color",
&JSGainStatsView::getTextColor,
&JSGainStatsView::setTextColor);
registerFontAttribute("font",
&JSGainStatsView::getFont,
&JSGainStatsView::setFont);
}
};
};
}