Jamba C++ API  4.4.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 
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 
139 protected:
140  int fFrames{4};
141  CColor fOnColor{kRedCColor};
142  BitmapSPtr fImage{nullptr};
143  bool fInverse{false};
144 
145  bool fPressed{false};
146 
147  int32 fStep{0};
148 
149 public:
150  class Creator : public CustomViewCreator<DiscreteButtonView, CustomDiscreteControlView>
151  {
152  public:
153  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
154  CustomViewCreator(iViewName, iDisplayName)
155  {
156  registerIntAttribute("frames", &DiscreteButtonView::getFrames, &DiscreteButtonView::setFrames);
157  registerColorAttribute("on-color", &DiscreteButtonView::getOnColor, &DiscreteButtonView::setOnColor);
158  registerBitmapAttribute("button-image", &DiscreteButtonView::getImage, &DiscreteButtonView::setImage);
159  registerBooleanAttribute("inverse", &DiscreteButtonView::getInverse, &DiscreteButtonView::setInverse);
160  registerIntegerAttribute<int32>("step", &DiscreteButtonView::getStep, &DiscreteButtonView::setStep);
161  }
162  };
163 };
164 
165 }
Inherit from this class to provide the factory for a custom view.
Definition: CustomViewCreator.h:1314
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:134
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
void setImage(BitmapPtr iImage)
Definition: DiscreteButtonView.h:135
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)
Attribute inverse
Definition: DiscreteButtonView.h:102
Specialization of TCustomControlView for discrete values.
Definition: CustomControlView.h:152
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: DiscreteButtonView.h:153
CBitmap * BitmapPtr
Definition: Types.h:49
bool isOff() const
Definition: DiscreteButtonView.h:77