Jamba C++ API 8.0.0
Loading...
Searching...
No Matches
MomentaryButtonView.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2020 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 <vstgui4/vstgui/lib/controls/ccontrol.h>
22#include "CustomControlView.h"
23
25
26using namespace VSTGUI;
27
56{
57public:
58 explicit MomentaryButtonView(const CRect &iSize) : CustomDiscreteControlView(iSize)
59 {
60 // off color is grey
61 fBackColor = CColor{200,200,200};
62 }
63
65 void draw(CDrawContext *iContext) override;
66
68 virtual void drawOn(CDrawContext *iContext);
69
71 virtual void drawOff(CDrawContext *iContext);
72
73 // input events (mouse/keyboard)
74 CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
75 CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
76 CMouseEventResult onMouseCancel() override;
77 int32_t onKeyDown(VstKeyCode &keyCode) override;
78 int32_t onKeyUp(VstKeyCode &keyCode) override;
79
80 // sizeToFit
81 bool sizeToFit() override;
82
87 int32 getOffStep() const { return fOffStep; }
88
90 void setOffStep(int32 iStep) { fOffStep = iStep; markDirty(); }
91
93 int32 getComputedOffStep() const { return std::max(Utils::ZERO_INT32, getOffStep()); }
94
99 int32 getOnStep() const { return fOnStep; }
100
102 void setOnStep(int32 iStep) { fOnStep = iStep; markDirty(); }
103
105 int32 getComputedOnStep() const;
106
107 // is on or off
108 bool isOff() const { return getControlValue() == getComputedOffStep(); }
109 bool isOn() const { return !isOff(); }
110
115 CColor const &getOnColor() const { return fOnColor; }
116
118 void setOnColor(CColor const &iColor) { fOnColor = iColor; }
119
122 CColor const &getDisabledColor() const { return fDisabledColor; }
123 void setDisabledColor(CColor const &iColor) { fDisabledColor = iColor; }
124
147 BitmapPtr getImage() const { return fImage; }
148
150 void setImage(BitmapPtr iImage) { fImage = iImage; }
151
157 void setImageHasDisabledState(bool iValue) { fImageHasDisabledState = iValue; }
158
160 bool getInverse() const { return fInverse; }
161 void setInverse(bool iInverse) { fInverse = iInverse; }
162
163 // true if held
164 bool isHeld() const { return fHeld; }
165
166protected:
167 int32 fOffStep{-1};
168 int32 fOnStep{-1};
169
172 bool fHeld{false};
173
174 CColor fOnColor{kRedCColor};
175 CColor fDisabledColor{kBlackCColor};
177 bool fInverse{false};
178
179 // whether the image has disabled state (3 frames) or not (2 frames)
181
182public:
198};
199
200}
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
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition MomentaryButtonView.h:186
int32 getComputedOnStep() const
Computes "on" step based on value of on-step attribute.
Definition MomentaryButtonView.cpp:193
bool getImageHasDisabledState() const
Flag to determine whether the image contains a disabled state (3 frames) or not (2 frames).
Definition MomentaryButtonView.h:156
void setOnColor(CColor const &iColor)
Attribute on-color (the "off" color is the back color...).
Definition MomentaryButtonView.h:118
bool getInverse() const
Inverses the meaning of "on" and "off" in regards to drawing the view/image.
Definition MomentaryButtonView.h:160
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
Definition MomentaryButtonView.cpp:129
void setOnStep(int32 iStep)
Attribute on-step.
Definition MomentaryButtonView.h:102
bool fInverse
Definition MomentaryButtonView.h:177
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 MomentaryButtonView.h:99
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
Definition MomentaryButtonView.cpp:115
void draw(CDrawContext *iContext) override
Calls drawOn() or drawOff() depending on the state (takes into account the inverse attribute).
Definition MomentaryButtonView.cpp:30
bool sizeToFit() override
Definition MomentaryButtonView.cpp:184
void setImage(BitmapPtr iImage)
Attribute button-image.
Definition MomentaryButtonView.h:150
bool fHeld
State of the button (true for held, false for released).
Definition MomentaryButtonView.h:172
CMouseEventResult onMouseCancel() override
Definition MomentaryButtonView.cpp:143
BitmapPtr getImage() const
The image to use to draw the button.
Definition MomentaryButtonView.h:147
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 MomentaryButtonView.h:115
CColor const & getDisabledColor() const
When no image is provided and the control is disabled, this color is used instead.
Definition MomentaryButtonView.h:122
void setDisabledColor(CColor const &iColor)
Definition MomentaryButtonView.h:123
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 MomentaryButtonView.h:87
BitmapSPtr fImage
Definition MomentaryButtonView.h:176
int32_t onKeyDown(VstKeyCode &keyCode) override
Definition MomentaryButtonView.cpp:154
bool fImageHasDisabledState
Definition MomentaryButtonView.h:180
CColor fOnColor
Definition MomentaryButtonView.h:174
bool isOff() const
Definition MomentaryButtonView.h:108
void setImageHasDisabledState(bool iValue)
Definition MomentaryButtonView.h:157
int32 fOnStep
Definition MomentaryButtonView.h:168
MomentaryButtonView(const CRect &iSize)
Definition MomentaryButtonView.h:58
virtual void drawOn(CDrawContext *iContext)
called to display the "on" state (can be overriden)
Definition MomentaryButtonView.cpp:49
bool isHeld() const
Definition MomentaryButtonView.h:164
void setInverse(bool iInverse)
Definition MomentaryButtonView.h:161
CColor fDisabledColor
Definition MomentaryButtonView.h:175
void setOffStep(int32 iStep)
Attribute off-step.
Definition MomentaryButtonView.h:90
int32 getComputedOffStep() const
Computes "off" step based on value of off-step attribute.
Definition MomentaryButtonView.h:93
int32 fOffStep
Definition MomentaryButtonView.h:167
bool isOn() const
Definition MomentaryButtonView.h:109
int32_t onKeyUp(VstKeyCode &keyCode) override
Definition MomentaryButtonView.cpp:169
virtual void drawOff(CDrawContext *iContext)
called to display the "off" state (can be overriden)
Definition MomentaryButtonView.cpp:81
int32 getControlValue() const
Definition CustomControlView.h:196
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
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