Jamba C++ API 8.0.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
21#include "CustomControlView.h"
22
24
25using namespace VSTGUI;
26using namespace Params;
27
54{
55public:
56 explicit ToggleButtonView(const CRect &iSize) : CustomDiscreteControlView(iSize)
57 {
58 // off color is grey
59 fBackColor = CColor{200, 200, 200};
60 }
61
62 // draw => does the actual drawing job
63 void draw(CDrawContext *iContext) override;
64
65 // input events (mouse/keyboard)
66 CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
67
68 CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
69
70 CMouseEventResult onMouseCancel() override;
71
72 int32_t onKeyDown(VstKeyCode &keyCode) override;
73
74 int32_t onKeyUp(VstKeyCode &keyCode) override;
75
76 // sizeToFit
77 bool sizeToFit() override;
78
83 int32 getOffStep() const { return fOffStep; }
84 void setOffStep(int32 iStep) { fOffStep = iStep; markDirty(); }
85
90 int32 getComputedOffStep() const { return std::max(Utils::ZERO_INT32, getOffStep()); }
91
96 int32 getOnStep() const { return fOnStep; }
97 void setOnStep(int32 iStep) { fOnStep = iStep; markDirty(); }
98
103 int32 getComputedOnStep() const;
104
106 bool isOff() const { return getControlValue() == getComputedOffStep(); }
107
116 bool isOn() const { return !isOff(); }
117
120
123
125 void setOnOrOff(bool iOnOrOff) { iOnOrOff ? setOn() : setOff(); }
126
132 int32 toggleControlValue();
133
139 int getFrames() const { return fFrames; }
140
141 void setFrames(int iFrames);
142
147 CColor const &getOnColor() const { return fOnColor; }
148
149 void setOnColor(CColor const &iColor) { fOnColor = iColor; }
150
152 bool getInverse() const { return fInverse; }
153
154 void setInverse(bool iInverse) { fInverse = iInverse; }
155
179 BitmapPtr getImage() const { return fImage; }
180
182 void setImage(BitmapPtr iImage) { fImage = iImage; }
183
184protected:
185 int32 fOffStep{-1};
186 int32 fOnStep{-1};
187
188 int fFrames{4};
189 CColor fOnColor{kRedCColor};
191 bool fInverse{false};
192
193 bool fPressed{false};
194
195public:
210};
211
212}
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:1330
void markDirty()
Marks this view dirty which will (at the appropriate time in the rendering lifecycle) trigger a call ...
Definition CustomView.h:177
CColor fBackColor
Definition CustomView.h:229
int32 getControlValue() const
Definition CustomControlView.h:196
virtual void setControlValue(int32 const &iControlValue)
Definition CustomControlView.h:205
void registerBitmapAttribute(std::string const &iName, BitmapAttribute::Getter iGetter, BitmapAttribute::Setter iSetter)
Definition CustomViewCreator.h:986
void registerBooleanAttribute(std::string const &iName, BooleanAttribute::Getter iGetter, BooleanAttribute::Setter iSetter)
Definition CustomViewCreator.h:1114
void registerColorAttribute(std::string const &iName, ColorAttribute::Getter iGetter, ColorAttribute::Setter iSetter)
Definition CustomViewCreator.h:966
void registerIntegerAttribute(std::string const &iName, IntegerAttribute< TInt >::Getter iGetter, IntegerAttribute< TInt >::Setter iSetter)
Definition CustomViewCreator.h:1074
void registerIntAttribute(std::string const &iName, IntegerAttribute< int32_t >::Getter iGetter, IntegerAttribute< int32_t >::Setter iSetter)
Definition CustomViewCreator.h:1084
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition ToggleButtonView.h:199
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:149
bool fPressed
Definition ToggleButtonView.h:193
bool getInverse() const
Inverses the meaning of "on" and "off" in regards to drawing the view/image.
Definition ToggleButtonView.h:152
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:122
void setOnStep(int32 iStep)
Definition ToggleButtonView.h:97
bool fInverse
Definition ToggleButtonView.h:191
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:96
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:182
int getFrames() const
The number of frames the image contains.
Definition ToggleButtonView.h:139
CMouseEventResult onMouseCancel() override
Definition ToggleButtonView.cpp:119
BitmapPtr getImage() const
The image to use to draw the button.
Definition ToggleButtonView.h:179
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:147
ToggleButtonView(const CRect &iSize)
Definition ToggleButtonView.h:56
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:83
int fFrames
Definition ToggleButtonView.h:188
BitmapSPtr fImage
Definition ToggleButtonView.h:190
int32_t onKeyDown(VstKeyCode &keyCode) override
Definition ToggleButtonView.cpp:129
void setOff()
Shortcut to set the toggle to its "off" state.
Definition ToggleButtonView.h:119
int32 toggleControlValue()
Toggles between on and off control value.
Definition ToggleButtonView.cpp:184
CColor fOnColor
Definition ToggleButtonView.h:189
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:106
int32 fOnStep
Definition ToggleButtonView.h:186
void setFrames(int iFrames)
Definition ToggleButtonView.cpp:28
void setInverse(bool iInverse)
Definition ToggleButtonView.h:154
void setOnOrOff(bool iOnOrOff)
Shortcut to set the toggle to the boolean state provided (true means "on", false means off).
Definition ToggleButtonView.h:125
void setOffStep(int32 iStep)
Definition ToggleButtonView.h:84
int32 getComputedOffStep() const
Actual value that the code should use for the underlying parameter.
Definition ToggleButtonView.h:90
int32 fOffStep
Definition ToggleButtonView.h:185
bool isOn() const
Returns true if the toggle is not in the "off" state.
Definition ToggleButtonView.h:116
int32_t onKeyUp(VstKeyCode &keyCode) override
Definition ToggleButtonView.cpp:143
constexpr auto ZERO_INT32
Definition Constants.h:25
Definition CustomController.h:26
CBitmap * BitmapPtr
Definition Types.h:48
SharedPointer< CBitmap > BitmapSPtr
Definition Types.h:49