Jamba C++ API 7.5.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>
23#include "CustomControlView.h"
24
26
27using namespace VSTGUI;
28
57{
58public:
59 explicit MomentaryButtonView(const CRect &iSize) : CustomDiscreteControlView(iSize)
60 {
61 // off color is grey
62 fBackColor = CColor{200,200,200};
63 }
64
66 void draw(CDrawContext *iContext) override;
67
69 virtual void drawOn(CDrawContext *iContext);
70
72 virtual void drawOff(CDrawContext *iContext);
73
74 // input events (mouse/keyboard)
75 CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
76 CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
77 CMouseEventResult onMouseCancel() override;
78 int32_t onKeyDown(VstKeyCode &keyCode) override;
79 int32_t onKeyUp(VstKeyCode &keyCode) override;
80
81 // sizeToFit
82 bool sizeToFit() override;
83
88 int32 getOffStep() const { return fOffStep; }
89
91 void setOffStep(int32 iStep) { fOffStep = iStep; markDirty(); }
92
94 int32 getComputedOffStep() const { return std::max(Utils::ZERO_INT32, getOffStep()); }
95
100 int32 getOnStep() const { return fOnStep; }
101
103 void setOnStep(int32 iStep) { fOnStep = iStep; markDirty(); }
104
106 int32 getComputedOnStep() const;
107
108 // is on or off
109 bool isOff() const { return getControlValue() == getComputedOffStep(); }
110 bool isOn() const { return !isOff(); }
111
116 CColor const &getOnColor() const { return fOnColor; }
117
119 void setOnColor(CColor const &iColor) { fOnColor = iColor; }
120
123 CColor const &getDisabledColor() const { return fDisabledColor; }
124 void setDisabledColor(CColor const &iColor) { fDisabledColor = iColor; }
125
148 BitmapPtr getImage() const { return fImage; }
149
151 void setImage(BitmapPtr iImage) { fImage = iImage; }
152
158 void setImageHasDisabledState(bool iValue) { fImageHasDisabledState = iValue; }
159
161 bool getInverse() const { return fInverse; }
162 void setInverse(bool iInverse) { fInverse = iInverse; }
163
164 // true if held
165 bool isHeld() const { return fHeld; }
166
167protected:
168 int32 fOffStep{-1};
169 int32 fOnStep{-1};
170
173 bool fHeld{false};
174
175 CColor fOnColor{kRedCColor};
176 CColor fDisabledColor{kBlackCColor};
178 bool fInverse{false};
179
180 // whether the image has disabled state (3 frames) or not (2 frames)
182
183public:
199};
200
201}
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
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition MomentaryButtonView.h:187
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:157
void setOnColor(CColor const &iColor)
Attribute on-color (the "off" color is the back color...).
Definition MomentaryButtonView.h:119
bool getInverse() const
Inverses the meaning of "on" and "off" in regards to drawing the view/image.
Definition MomentaryButtonView.h:161
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
Definition MomentaryButtonView.cpp:129
void setOnStep(int32 iStep)
Attribute on-step.
Definition MomentaryButtonView.h:103
bool fInverse
Definition MomentaryButtonView.h:178
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:100
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:151
bool fHeld
State of the button (true for held, false for released).
Definition MomentaryButtonView.h:173
CMouseEventResult onMouseCancel() override
Definition MomentaryButtonView.cpp:143
BitmapPtr getImage() const
The image to use to draw the button.
Definition MomentaryButtonView.h:148
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:116
CColor const & getDisabledColor() const
When no image is provided and the control is disabled, this color is used instead.
Definition MomentaryButtonView.h:123
void setDisabledColor(CColor const &iColor)
Definition MomentaryButtonView.h:124
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:88
BitmapSPtr fImage
Definition MomentaryButtonView.h:177
int32_t onKeyDown(VstKeyCode &keyCode) override
Definition MomentaryButtonView.cpp:154
bool fImageHasDisabledState
Definition MomentaryButtonView.h:181
CColor fOnColor
Definition MomentaryButtonView.h:175
bool isOff() const
Definition MomentaryButtonView.h:109
void setImageHasDisabledState(bool iValue)
Definition MomentaryButtonView.h:158
int32 fOnStep
Definition MomentaryButtonView.h:169
MomentaryButtonView(const CRect &iSize)
Definition MomentaryButtonView.h:59
virtual void drawOn(CDrawContext *iContext)
called to display the "on" state (can be overriden)
Definition MomentaryButtonView.cpp:49
bool isHeld() const
Definition MomentaryButtonView.h:165
void setInverse(bool iInverse)
Definition MomentaryButtonView.h:162
CColor fDisabledColor
Definition MomentaryButtonView.h:176
void setOffStep(int32 iStep)
Attribute off-step.
Definition MomentaryButtonView.h:91
int32 getComputedOffStep() const
Computes "off" step based on value of off-step attribute.
Definition MomentaryButtonView.h:94
int32 fOffStep
Definition MomentaryButtonView.h:168
bool isOn() const
Definition MomentaryButtonView.h:110
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 registerColorAttribute(std::string const &iName, typename ColorAttribute::Getter iGetter, typename ColorAttribute::Setter iSetter)
Definition CustomViewCreator.h:952
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
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