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