Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
ToggleButtonView.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2019 pongasoft
3 *
4 * Licensed under the Apache License, Version 2.0 or the MIT license,
5 * at your option. You may not use this file except in compliance with
6 * one of these licenses. You may obtain copies of the licenses at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 * https://opensource.org/licenses/MIT
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 *
17 * @author Yan Pujante
18 */
19#pragma once
20
22#include "CustomControlView.h"
23
25
26using namespace VSTGUI;
27using namespace Params;
28
55{
56public:
57 explicit ToggleButtonView(const CRect &iSize) : CustomDiscreteControlView(iSize)
58 {
59 // off color is grey
60 fBackColor = CColor{200, 200, 200};
61 }
62
63 // draw => does the actual drawing job
64 void draw(CDrawContext *iContext) override;
65
66 // input events (mouse/keyboard)
67 CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
68
69 CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
70
71 CMouseEventResult onMouseCancel() override;
72
73 int32_t onKeyDown(VstKeyCode &keyCode) override;
74
75 int32_t onKeyUp(VstKeyCode &keyCode) override;
76
77 // sizeToFit
78 bool sizeToFit() override;
79
84 int32 getOffStep() const { return fOffStep; }
85 void setOffStep(int32 iStep) { fOffStep = iStep; markDirty(); }
86
91 int32 getComputedOffStep() const { return std::max(Utils::ZERO_INT32, getOffStep()); }
92
97 int32 getOnStep() const { return fOnStep; }
98 void setOnStep(int32 iStep) { fOnStep = iStep; markDirty(); }
99
104 int32 getComputedOnStep() const;
105
107 bool isOff() const { return getControlValue() == getComputedOffStep(); }
108
117 bool isOn() const { return !isOff(); }
118
121
124
126 inline void setOnOrOff(bool iOnOrOff) { iOnOrOff ? setOn() : setOff(); }
127
133 int32 toggleControlValue();
134
140 int getFrames() const { return fFrames; }
141
142 void setFrames(int iFrames);
143
148 CColor const &getOnColor() const { return fOnColor; }
149
150 void setOnColor(CColor const &iColor) { fOnColor = iColor; }
151
153 bool getInverse() const { return fInverse; }
154
155 void setInverse(bool iInverse) { fInverse = iInverse; }
156
180 BitmapPtr getImage() const { return fImage; }
181
183 void setImage(BitmapPtr iImage) { fImage = iImage; }
184
185protected:
186 int32 fOffStep{-1};
187 int32 fOnStep{-1};
188
189 int fFrames{4};
190 CColor fOnColor{kRedCColor};
192 bool fInverse{false};
193
194 bool fPressed{false};
195
196public:
211};
212
213}
CustomDiscreteControlView(const CRect &iSize)
Definition CustomControlView.h:157
CustomViewCreator(char const *iViewName=nullptr, char const *iDisplayName=nullptr, char const *iBaseViewName=VSTGUI::UIViewCreator::kCView)
Definition CustomViewCreator.h:1318
void markDirty()
Marks this view dirty which will (at the appropriate time in the rendering lifecycle) trigger a call ...
Definition CustomView.h:178
CColor fBackColor
Definition CustomView.h:230
int32 getControlValue() const
Definition CustomControlView.h:196
virtual void setControlValue(int32 const &iControlValue)
Definition CustomControlView.h:205
void registerColorAttribute(std::string const &iName, typename ColorAttribute::Getter iGetter, typename ColorAttribute::Setter iSetter)
Definition CustomViewCreator.h:952
void registerIntAttribute(std::string const &iName, typename IntegerAttribute< int32_t >::Getter iGetter, typename IntegerAttribute< int32_t >::Setter iSetter)
Definition CustomViewCreator.h:1070
void registerBitmapAttribute(std::string const &iName, typename BitmapAttribute::Getter iGetter, typename BitmapAttribute::Setter iSetter)
Definition CustomViewCreator.h:972
void registerIntegerAttribute(std::string const &iName, typename IntegerAttribute< TInt >::Getter iGetter, typename IntegerAttribute< TInt >::Setter iSetter)
Definition CustomViewCreator.h:1060
void registerBooleanAttribute(std::string const &iName, typename BooleanAttribute::Getter iGetter, typename BooleanAttribute::Setter iSetter)
Definition CustomViewCreator.h:1100
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition ToggleButtonView.h:200
int32 getComputedOnStep() const
Actual value that the code should use for the underlying parameter.
Definition ToggleButtonView.cpp:166
void setOnColor(CColor const &iColor)
Definition ToggleButtonView.h:150
bool fPressed
Definition ToggleButtonView.h:194
bool getInverse() const
Inverses the meaning of "on" and "off" in regards to drawing the view/image.
Definition ToggleButtonView.h:153
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
Definition ToggleButtonView.cpp:105
void setOn()
Shortcut to set the toggle to its "on" state.
Definition ToggleButtonView.h:123
void setOnStep(int32 iStep)
Definition ToggleButtonView.h:98
bool fInverse
Definition ToggleButtonView.h:192
int32 getOnStep() const
Maps to the "on" value unless it is set to its default (-1) value in which case it maps to getStepCou...
Definition ToggleButtonView.h:97
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
Definition ToggleButtonView.cpp:92
void draw(CDrawContext *iContext) override
Definition ToggleButtonView.cpp:41
bool sizeToFit() override
Definition ToggleButtonView.cpp:158
void setImage(BitmapPtr iImage)
Attribute button-image.
Definition ToggleButtonView.h:183
int getFrames() const
The number of frames the image contains.
Definition ToggleButtonView.h:140
CMouseEventResult onMouseCancel() override
Definition ToggleButtonView.cpp:119
BitmapPtr getImage() const
The image to use to draw the button.
Definition ToggleButtonView.h:180
CColor const & getOnColor() const
When no image is provided, back-color is used for the "off" state and on-color for the "on" state (dr...
Definition ToggleButtonView.h:148
ToggleButtonView(const CRect &iSize)
Definition ToggleButtonView.h:57
int32 getOffStep() const
Maps to the "off" value unless it is set to its default (-1) value in which case it maps to 0 (should...
Definition ToggleButtonView.h:84
int fFrames
Definition ToggleButtonView.h:189
BitmapSPtr fImage
Definition ToggleButtonView.h:191
int32_t onKeyDown(VstKeyCode &keyCode) override
Definition ToggleButtonView.cpp:129
void setOff()
Shortcut to set the toggle to its "off" state.
Definition ToggleButtonView.h:120
int32 toggleControlValue()
Toggles between on and off control value.
Definition ToggleButtonView.cpp:184
CColor fOnColor
Definition ToggleButtonView.h:190
bool isOff() const
Returns true if the toggle is in the "off" state (meaning the control value is equal to the off step)...
Definition ToggleButtonView.h:107
int32 fOnStep
Definition ToggleButtonView.h:187
void setFrames(int iFrames)
Definition ToggleButtonView.cpp:28
void setInverse(bool iInverse)
Definition ToggleButtonView.h:155
void setOnOrOff(bool iOnOrOff)
Shortcut to set the toggle to the boolean state provided (true means "on", false means off).
Definition ToggleButtonView.h:126
void setOffStep(int32 iStep)
Definition ToggleButtonView.h:85
int32 getComputedOffStep() const
Actual value that the code should use for the underlying parameter.
Definition ToggleButtonView.h:91
int32 fOffStep
Definition ToggleButtonView.h:186
bool isOn() const
Returns true if the toggle is not in the "off" state.
Definition ToggleButtonView.h:117
int32_t onKeyUp(VstKeyCode &keyCode) override
Definition ToggleButtonView.cpp:143
constexpr auto ZERO_INT32
Definition Constants.h:25
Definition CustomController.h:25
CBitmap * BitmapPtr
Definition Types.h:50
SharedPointer< CBitmap > BitmapSPtr
Definition Types.h:51