Jamba C++ API  4.0.0
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 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 #pragma once
19 
21 #include "CustomControlView.h"
22 
24 
25 using namespace VSTGUI;
26 using namespace Params;
27 
49 {
50 public:
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 
101  void setInverse(bool iInverse) { fInverse = iInverse; }
102 
107  int32 getStep() const { return fStep; }
108  void setStep(int32 step);
109 
133  BitmapPtr getImage() const { return fImage; }
134  void setImage(BitmapPtr iImage) { fImage = iImage; }
135 
136  void registerParameters() override;
137 
138 protected:
139  int fFrames{4};
140  CColor fOnColor{kRedCColor};
141  BitmapSPtr fImage{nullptr};
142  bool fInverse{false};
143 
144  bool fPressed{false};
145 
146  int32 fStep{0};
147 
148 public:
149  class Creator : public CustomViewCreator<DiscreteButtonView, CustomDiscreteControlView>
150  {
151  public:
152  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
153  CustomViewCreator(iViewName, iDisplayName)
154  {
155  registerIntAttribute("frames", &DiscreteButtonView::getFrames, &DiscreteButtonView::setFrames);
156  registerColorAttribute("on-color", &DiscreteButtonView::getOnColor, &DiscreteButtonView::setOnColor);
157  registerBitmapAttribute("button-image", &DiscreteButtonView::getImage, &DiscreteButtonView::setImage);
158  registerBooleanAttribute("inverse", &DiscreteButtonView::getInverse, &DiscreteButtonView::setInverse);
159  registerIntegerAttribute<int32>("step", &DiscreteButtonView::getStep, &DiscreteButtonView::setStep);
160  }
161  };
162 };
163 
164 }
Inherit from this class to provide the factory for a custom view.
Definition: CustomViewCreator.h:1311
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
DiscreteButtonView(const CRect &iSize)
Definition: DiscreteButtonView.h:51
void setStep(int32 step)
Definition: DiscreteButtonView.cpp:166
int getFrames() const
The number of frames the image contains.
Definition: DiscreteButtonView.h:86
void setOnColor(CColor const &iColor)
Definition: DiscreteButtonView.h:96
void setFrames(int iFrames)
Definition: DiscreteButtonView.cpp:28
BitmapPtr getImage() const
The image for the button.
Definition: DiscreteButtonView.h:133
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:107
void setImage(BitmapPtr iImage)
Definition: DiscreteButtonView.h:134
A discrete button behaves like a toggle button except that it is on only if the control value (tied t...
Definition: DiscreteButtonView.h:48
bool getInverse() const
Inverses the meaning of "on" and "off" in regards to drawing the view/image.
Definition: DiscreteButtonView.h:99
Definition: Types.h:29
SharedPointer< CBitmap > BitmapSPtr
Definition: Types.h:50
Definition: CustomController.h:24
void setInverse(bool iInverse)
Definition: DiscreteButtonView.h:101
Specialization of TCustomControlView for discrete values.
Definition: CustomControlView.h:152
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: DiscreteButtonView.h:152
CBitmap * BitmapPtr
Definition: Types.h:49
bool isOff() const
Definition: DiscreteButtonView.h:77