Jamba  3.2.0
ToggleButtonView.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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 
23 namespace pongasoft {
24 namespace VST {
25 namespace GUI {
26 namespace Views {
27 
28 using namespace VSTGUI;
29 using namespace Params;
30 
32 {
33 public:
34  explicit ToggleButtonView(const CRect &iSize) : TCustomControlView(iSize)
35  {
36  // off color is grey
37  fBackColor = CColor{200, 200, 200};
38  }
39 
40  // draw => does the actual drawing job
41  void draw(CDrawContext *iContext) override;
42 
43  // input events (mouse/keyboard)
44  CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
45 
46  CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
47 
48  CMouseEventResult onMouseCancel() override;
49 
50  int32_t onKeyDown(VstKeyCode &keyCode) override;
51 
52  int32_t onKeyUp(VstKeyCode &keyCode) override;
53 
54  // sizeToFit
55  bool sizeToFit() override;
56 
57  // is on or off
58  bool isOn() const { return getControlValue(); }
59 
60  bool isOff() const { return !isOn(); }
61 
62  // get/set frames (should be either 2 or 4) 4 includes the pressed state
63  int getFrames() const { return fFrames; }
64 
65  void setFrames(int iFrames);
66 
67  // get/setOnColor (the off color is the back color...)
68  CColor const &getOnColor() const { return fOnColor; }
69 
70  void setOnColor(CColor const &iColor) { fOnColor = iColor; }
71 
72  // get/setInverse (toggles which image is on and which is off)
73  bool getInverse() const { return fInverse; }
74 
75  void setInverse(bool iInverse) { fInverse = iInverse; }
76 
89  BitmapPtr getImage() const { return fImage; }
90  void setImage(BitmapPtr iImage) { fImage = iImage; }
91 
92 public:
93  CLASS_METHODS_NOCOPY(ToggleButtonView, TCustomControlView<bool>)
94 
95 protected:
96  int fFrames{4};
97  CColor fOnColor{kRedCColor};
98  BitmapSPtr fImage{nullptr};
99  bool fInverse{false};
100 
101  bool fPressed{false};
102 
103 public:
104  class Creator : public CustomViewCreator<ToggleButtonView, TCustomControlView<bool>>
105  {
106  public:
107  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
108  CustomViewCreator(iViewName, iDisplayName)
109  {
110  registerIntAttribute("frames", &ToggleButtonView::getFrames, &ToggleButtonView::setFrames);
111  registerColorAttribute("on-color", &ToggleButtonView::getOnColor, &ToggleButtonView::setOnColor);
112  registerBitmapAttribute("button-image", &ToggleButtonView::getImage, &ToggleButtonView::setImage);
113  registerBooleanAttribute("inverse", &ToggleButtonView::getInverse, &ToggleButtonView::setInverse);
114  }
115  };
116 };
117 
118 }
119 }
120 }
121 }
Definition: CustomViewCreator.h:1049
void setInverse(bool iInverse)
Definition: ToggleButtonView.h:75
SharedPointer< CBitmap > BitmapSPtr
Definition: Types.h:50
Definition: Clock.h:22
CBitmap * BitmapPtr
Definition: Types.h:49
CColor const & getOnColor() const
Definition: ToggleButtonView.h:68
Definition: CustomControlView.h:63
Definition: ToggleButtonView.h:31
int getFrames() const
Definition: ToggleButtonView.h:63
Definition: Types.h:29
void setImage(BitmapPtr iImage)
Definition: ToggleButtonView.h:90
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: ToggleButtonView.h:107
bool isOn() const
Definition: ToggleButtonView.h:58
bool getInverse() const
Definition: ToggleButtonView.h:73
void setFrames(int iFrames)
Definition: ToggleButtonView.cpp:30
bool isOff() const
Definition: ToggleButtonView.h:60
BitmapPtr getImage() const
Definition: ToggleButtonView.h:89
void setOnColor(CColor const &iColor)
Definition: ToggleButtonView.h:70
ToggleButtonView(const CRect &iSize)
Definition: ToggleButtonView.h:34