Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
DiscreteButtonView.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 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
50{
51public:
52 explicit DiscreteButtonView(const CRect &iSize) : CustomDiscreteControlView(iSize)
53 {
54 // off color is grey
55 fBackColor = CColor{200, 200, 200};
56 }
57
58 // draw => does the actual drawing job
59 void draw(CDrawContext *iContext) override;
60
61 // input events (mouse/keyboard)
62 CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
63
64 CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
65
66 CMouseEventResult onMouseCancel() override;
67
68 int32_t onKeyDown(VstKeyCode &keyCode) override;
69
70 int32_t onKeyUp(VstKeyCode &keyCode) override;
71
72 // sizeToFit
73 bool sizeToFit() override;
74
75 // is on or off
76 bool isOn() const;
77
78 bool isOff() const { return !isOn(); }
79
80 void setOn();
81
87 int getFrames() const { return fFrames; }
88
89 void setFrames(int iFrames);
90
95 CColor const &getOnColor() const { return fOnColor; }
96
97 void setOnColor(CColor const &iColor) { fOnColor = iColor; }
98
100 bool getInverse() const { return fInverse; }
101
103 void setInverse(bool iInverse) { fInverse = iInverse; }
104
109 int32 getStep() const { return fStep; }
110 void setStep(int32 step);
111
135 BitmapPtr getImage() const { return fImage; }
136 void setImage(BitmapPtr iImage) { fImage = iImage; }
137
138 void registerParameters() override;
139
140protected:
141 int fFrames{4};
142 CColor fOnColor{kRedCColor};
144 bool fInverse{false};
145
146 bool fPressed{false};
147
148 int32 fStep{0};
149
150public:
151 class Creator : public CustomViewCreator<DiscreteButtonView, CustomDiscreteControlView>
152 {
153 public:
163 };
164};
165
166}
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
CColor fBackColor
Definition CustomView.h:230
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition DiscreteButtonView.h:154
void setStep(int32 step)
Definition DiscreteButtonView.cpp:167
void setOnColor(CColor const &iColor)
Definition DiscreteButtonView.h:97
void registerParameters() override
Registers the optional parameter using getControlTag() as its id.
Definition DiscreteButtonView.cpp:198
bool fPressed
Definition DiscreteButtonView.h:146
DiscreteButtonView(const CRect &iSize)
Definition DiscreteButtonView.h:52
bool getInverse() const
Inverses the meaning of "on" and "off" in regards to drawing the view/image.
Definition DiscreteButtonView.h:100
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
Definition DiscreteButtonView.cpp:106
void setOn()
Definition DiscreteButtonView.cpp:187
bool fInverse
Definition DiscreteButtonView.h:144
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
Definition DiscreteButtonView.cpp:93
void draw(CDrawContext *iContext) override
Definition DiscreteButtonView.cpp:42
int32 fStep
Definition DiscreteButtonView.h:148
bool sizeToFit() override
Definition DiscreteButtonView.cpp:159
void setImage(BitmapPtr iImage)
Definition DiscreteButtonView.h:136
int getFrames() const
The number of frames the image contains.
Definition DiscreteButtonView.h:87
CMouseEventResult onMouseCancel() override
Definition DiscreteButtonView.cpp:120
BitmapPtr getImage() const
The image for the button.
Definition DiscreteButtonView.h:135
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 DiscreteButtonView.h:95
int fFrames
Definition DiscreteButtonView.h:141
BitmapSPtr fImage
Definition DiscreteButtonView.h:143
int32_t onKeyDown(VstKeyCode &keyCode) override
Definition DiscreteButtonView.cpp:130
CColor fOnColor
Definition DiscreteButtonView.h:142
bool isOff() const
Definition DiscreteButtonView.h:78
void setFrames(int iFrames)
Definition DiscreteButtonView.cpp:29
void setInverse(bool iInverse)
Attribute inverse.
Definition DiscreteButtonView.h:103
int32 getStep() const
The value used to check whether the button is "on" or "off" as well as the value to set the parameter...
Definition DiscreteButtonView.h:109
bool isOn() const
Definition DiscreteButtonView.cpp:176
int32_t onKeyUp(VstKeyCode &keyCode) override
Definition DiscreteButtonView.cpp:144
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
Definition CustomController.h:25
CBitmap * BitmapPtr
Definition Types.h:50
SharedPointer< CBitmap > BitmapSPtr
Definition Types.h:51