Jamba  3.0.2
MomentaryButtonView.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 
20 #include <vstgui4/vstgui/lib/controls/ccontrol.h>
22 #include "CustomControlView.h"
23 
24 namespace pongasoft {
25 namespace VST {
26 namespace GUI {
27 namespace Views {
28 
29 using namespace VSTGUI;
30 
31 // TODO TODO TODO
32 /* at this time I am still getting unexplained behavior (if the mouse click/release is too fast)
33 2018-06-11 10:47:59.350 ( 177.197s) [ 1F4B2] MomentaryButton.cpp:60 0| MomentaryButton::onMouseDown
34 2018-06-11 10:47:59.356 ( 177.204s) [ 1F561] VAC6Processor.cpp:263 0| VAC6Processor::processParameters => kMaxLevelReset=1.000000
35 2018-06-11 10:47:59.397 ( 177.244s) [ 1F4B2] MomentaryButton.cpp:78 0| MomentaryButton::onMouseUp
36 2018-06-11 10:47:59.399 ( 177.246s) [ 1F561] VAC6Processor.cpp:263 0| VAC6Processor::processParameters => kMaxLevelReset=0.000000
37 2018-06-11 10:47:59.432 ( 177.280s) [ 1F4B2] VAC6Processor.cpp:307 0| VAC6Processor::getState => fSoftClippingLevel=0.170968
38 2018-06-11 10:47:59.432 ( 177.280s) [ 1F4B2] VAC6Controller.cpp:168 0| VAC6Controller::getState()
39 2018-06-11 10:47:59.433 ( 177.281s) [ 1F4B2] VAC6Processor.cpp:307 0| VAC6Processor::getState => fSoftClippingLevel=0.170968
40 2018-06-11 10:47:59.433 ( 177.281s) [ 1F4B2] VAC6Controller.cpp:168 0| VAC6Controller::getState()
41 2018-06-11 10:47:59.441 ( 177.289s) [ 1F561] VAC6Processor.cpp:263 0| VAC6Processor::processParameters => kMaxLevelReset=1.000000
42 
43  Update 2018/07/12 Cannot reproduce with Editor or Maschine 2... only happens in Reason so may just be an implementation
44  issue with VST plugins in Reason
45  */
46 
53 {
54 public:
55  explicit MomentaryButtonView(const CRect &iSize) : TCustomControlView(iSize)
56  {
57  // off color is grey
58  fBackColor = CColor{200,200,200};
59  }
60 
61  // draw => does the actual drawing job
62  void draw(CDrawContext *iContext) override;
63 
64  // called to display the "on" state
65  virtual void drawOn(CDrawContext *iContext);
66 
67  // called to display the "off" state
68  virtual void drawOff(CDrawContext *iContext);
69 
70  // input events (mouse/keyboard)
71  CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
72  CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
73  CMouseEventResult onMouseCancel() override;
74  int32_t onKeyDown(VstKeyCode &keyCode) override;
75  int32_t onKeyUp(VstKeyCode &keyCode) override;
76 
77  // sizeToFit
78  bool sizeToFit() override;
79 
80  // is on or off
81  bool isOn() const { return getControlValue(); }
82  bool isOff() const { return !isOn(); }
83 
84  // get/setOnColor (the off color is the back color...)
85  CColor const &getOnColor() const { return fOnColor; }
86  void setOnColor(CColor const &iColor) { fOnColor = iColor; }
87 
94  BitmapPtr getImage() const { return fImage; }
95  void setImage(BitmapPtr iImage) { fImage = iImage; }
96 
97 public:
98  CLASS_METHODS_NOCOPY(MomentaryButtonView, TCustomControlView<bool>)
99 
100 protected:
101  CColor fOnColor{kRedCColor};
102  BitmapSPtr fImage{nullptr};
103 
104 public:
105  class Creator : public CustomViewCreator<MomentaryButtonView, TCustomControlView<bool>>
106  {
107  public:
108  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
109  CustomViewCreator(iViewName, iDisplayName)
110  {
111  registerColorAttribute("on-color", &MomentaryButtonView::getOnColor, &MomentaryButtonView::setOnColor);
112  registerBitmapAttribute("button-image", &MomentaryButtonView::getImage, &MomentaryButtonView::setImage);
113  }
114  };
115 };
116 
117 }
118 }
119 }
120 }
Definition: CustomViewCreator.h:981
SharedPointer< CBitmap > BitmapSPtr
Definition: Types.h:36
Definition: Clock.h:22
CBitmap * BitmapPtr
Definition: Types.h:35
bool isOff() const
Definition: MomentaryButtonView.h:82
Definition: CustomControlView.h:63
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: MomentaryButtonView.h:108
BitmapPtr getImage() const
Definition: MomentaryButtonView.h:94
void setOnColor(CColor const &iColor)
Definition: MomentaryButtonView.h:86
CColor const & getOnColor() const
Definition: MomentaryButtonView.h:85
MomentaryButtonView(const CRect &iSize)
Definition: MomentaryButtonView.h:55
bool isOn() const
Definition: MomentaryButtonView.h:81
Definition: MomentaryButtonView.h:52
void setImage(BitmapPtr iImage)
Definition: MomentaryButtonView.h:95