Jamba  3.2.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 
23 namespace pongasoft {
24 namespace VST {
25 namespace GUI {
26 namespace Views {
27 
28 using namespace VSTGUI;
29 using namespace Params;
30 
39 {
40 public:
41  explicit DiscreteButtonView(const CRect &iSize) : RawCustomControlView(iSize)
42  {
43  // off color is grey
44  fBackColor = CColor{200, 200, 200};
45  }
46 
47  // draw => does the actual drawing job
48  void draw(CDrawContext *iContext) override;
49 
50  // input events (mouse/keyboard)
51  CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
52 
53  CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
54 
55  CMouseEventResult onMouseCancel() override;
56 
57  int32_t onKeyDown(VstKeyCode &keyCode) override;
58 
59  int32_t onKeyUp(VstKeyCode &keyCode) override;
60 
61  // sizeToFit
62  bool sizeToFit() override;
63 
64  // is on or off
65  bool isOn() const;
66 
67  bool isOff() const { return !isOn(); }
68 
69  void setOn();
70 
71  // get/set frames (should be either 2 or 4) 4 includes the pressed state
72  int getFrames() const { return fFrames; }
73 
74  void setFrames(int iFrames);
75 
76  // get/setOnColor (the off color is the back color...)
77  CColor const &getOnColor() const { return fOnColor; }
78 
79  void setOnColor(CColor const &iColor) { fOnColor = iColor; }
80 
81  // get/setInverse (toggles which image is on and which is off)
82  bool getInverse() const { return fInverse; }
83 
84  void setInverse(bool iInverse) { fInverse = iInverse; }
85 
86  int32 getStep() const { return fStep; }
87  void setStep(int32 step);
88 
101  BitmapPtr getImage() const { return fImage; }
102  void setImage(BitmapPtr iImage) { fImage = iImage; }
103 
104  void registerParameters() override;
105 
106 protected:
107  int fFrames{4};
108  CColor fOnColor{kRedCColor};
109  BitmapSPtr fImage{nullptr};
110  bool fInverse{false};
111 
112  bool fPressed{false};
113 
114  int32 fStep{0};
115 
116 public:
117  class Creator : public CustomViewCreator<DiscreteButtonView, RawCustomControlView>
118  {
119  public:
120  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
121  CustomViewCreator(iViewName, iDisplayName)
122  {
123  registerIntAttribute("frames", &DiscreteButtonView::getFrames, &DiscreteButtonView::setFrames);
124  registerColorAttribute("on-color", &DiscreteButtonView::getOnColor, &DiscreteButtonView::setOnColor);
125  registerBitmapAttribute("button-image", &DiscreteButtonView::getImage, &DiscreteButtonView::setImage);
126  registerBooleanAttribute("inverse", &DiscreteButtonView::getInverse, &DiscreteButtonView::setInverse);
127  registerIntegerAttribute<int32>("step", &DiscreteButtonView::getStep, &DiscreteButtonView::setStep);
128  }
129  };
130 };
131 
132 }
133 }
134 }
135 }
DiscreteButtonView(const CRect &iSize)
Definition: DiscreteButtonView.h:41
void setInverse(bool iInverse)
Definition: DiscreteButtonView.h:84
Definition: CustomViewCreator.h:1049
bool isOff() const
Definition: DiscreteButtonView.h:67
void setStep(int32 step)
Definition: DiscreteButtonView.cpp:170
void setOnColor(CColor const &iColor)
Definition: DiscreteButtonView.h:79
BitmapPtr getImage() const
Definition: DiscreteButtonView.h:101
SharedPointer< CBitmap > BitmapSPtr
Definition: Types.h:50
bool getInverse() const
Definition: DiscreteButtonView.h:82
Definition: Clock.h:22
CBitmap * BitmapPtr
Definition: Types.h:49
Definition: CustomControlView.h:63
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: DiscreteButtonView.h:120
int32 getStep() const
Definition: DiscreteButtonView.h:86
CColor const & getOnColor() const
Definition: DiscreteButtonView.h:77
void setFrames(int iFrames)
Definition: DiscreteButtonView.cpp:32
void setImage(BitmapPtr iImage)
Definition: DiscreteButtonView.h:102
Definition: DiscreteButtonView.h:38
Definition: Types.h:29
int getFrames() const
Definition: DiscreteButtonView.h:72