Jamba  3.2.0
StepButtonView.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 
20 #include <vstgui4/vstgui/lib/controls/ccontrol.h>
21 #include <vstgui4/vstgui/lib/cdrawcontext.h>
23 #include "CustomControlView.h"
24 
25 namespace pongasoft {
26 namespace VST {
27 namespace GUI {
28 namespace Views {
29 
30 using namespace VSTGUI;
31 
45 {
46 public:
47  explicit StepButtonView(const CRect &iSize) : RawCustomControlView(iSize)
48  {
49  }
50 
51  // draw => does the actual drawing job
52  void draw(CDrawContext *iContext) override;
53 
54  // called to display the "held" button state
55  virtual void drawHeldButton(CDrawContext *iContext);
56 
57  // called to display the "released" button state
58  virtual void drawReleasedButton(CDrawContext *iContext);
59 
60  // input events (mouse/keyboard)
61  CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
62  CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
63  CMouseEventResult onMouseCancel() override;
64  int32_t onKeyDown(VstKeyCode &keyCode) override;
65  int32_t onKeyUp(VstKeyCode &keyCode) override;
66 
67  // true if held
68  bool isHeld() const { return fHeld; }
69 
70  // get/setHeldColor
71  inline CColor const &getHeldColor() const { return fHeldColor; }
72  void setHeldColor(CColor const &iColor) { fHeldColor = iColor; markDirty(); }
73 
74  // get/setReleasedColor
75  inline CColor const &getReleasedColor() const { return fReleasedColor; }
76  void setReleasedColor(CColor const &iColor) { fReleasedColor = iColor; markDirty(); }
77 
84  BitmapPtr getImage() const { return fImage; }
85 
89  void setImage(BitmapPtr iImage) { fImage = iImage; markDirty(); }
90 
95  double getStepIncrement() const { return fStepIncrement; }
96 
100  void setStepIncrement(double iStepIncrement) { fStepIncrement = iStepIncrement; fButtonPolygon = nullptr; }
101 
106  double getShiftStepIncrement() const { return fShiftStepIncrement; }
107 
111  void setShiftStepIncrement(double iStepIncrement) { fShiftStepIncrement = iStepIncrement; }
112 
114  inline bool getWrap() const { return fWrap; }
115  void setWrap(bool iFlag) { fWrap = iFlag; markDirty(); }
116 
117 protected:
118  // registerParameters
119  void registerParameters() override;
120 
127  virtual ParamValue computeNextValue(double iIncrement) const;
128 
132  virtual CDrawContext::PointList *getButtonPolygon();
133 
134  // setViewSize
135  void setViewSize(const CRect &rect, bool invalid) override;
136 
137 protected:
141  bool fHeld{false};
142 
143  double fStepIncrement{1.0};
144  double fShiftStepIncrement{0.0};
145  bool fWrap{false};
146  CColor fHeldColor{kRedCColor};
147  CColor fReleasedColor{kGreyCColor};
148  BitmapSPtr fImage{nullptr};
149  std::unique_ptr<CDrawContext::PointList> fButtonPolygon{};
150 
151 public:
152  class Creator : public CustomViewCreator<StepButtonView, RawCustomControlView>
153  {
154  public:
155  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
156  CustomViewCreator(iViewName, iDisplayName)
157  {
158  registerDoubleAttribute("step-increment", &StepButtonView::getStepIncrement, &StepButtonView::setStepIncrement);
159  registerDoubleAttribute("shift-step-increment", &StepButtonView::getShiftStepIncrement, &StepButtonView::setShiftStepIncrement);
160  registerBooleanAttribute("wrap", &StepButtonView::getWrap, &StepButtonView::setWrap);
161  registerColorAttribute("held-color", &StepButtonView::getHeldColor, &StepButtonView::setHeldColor);
162  registerColorAttribute("released-color", &StepButtonView::getReleasedColor, &StepButtonView::setReleasedColor);
163  registerBitmapAttribute("button-image", &StepButtonView::getImage, &StepButtonView::setImage);
164  }
165  };
166 };
167 
168 }
169 }
170 }
171 }
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: StepButtonView.h:155
Definition: CustomViewCreator.h:1049
void setStepIncrement(double iStepIncrement)
Definition: StepButtonView.h:100
BitmapPtr getImage() const
Definition: StepButtonView.h:84
SharedPointer< CBitmap > BitmapSPtr
Definition: Types.h:50
void setWrap(bool iFlag)
Definition: StepButtonView.h:115
Definition: Clock.h:22
CBitmap * BitmapPtr
Definition: Types.h:49
Definition: CustomControlView.h:63
StepButtonView(const CRect &iSize)
Definition: StepButtonView.h:47
bool getWrap() const
get/setWrap => whether the discrete value wraps around when it reaches max (or min)
Definition: StepButtonView.h:114
CColor const & getHeldColor() const
Definition: StepButtonView.h:71
void setReleasedColor(CColor const &iColor)
Definition: StepButtonView.h:76
void setShiftStepIncrement(double iStepIncrement)
Definition: StepButtonView.h:111
double getStepIncrement() const
Definition: StepButtonView.h:95
Definition: Types.h:29
bool isHeld() const
Definition: StepButtonView.h:68
void setImage(BitmapPtr iImage)
Definition: StepButtonView.h:89
double getShiftStepIncrement() const
Definition: StepButtonView.h:106
CColor const & getReleasedColor() const
Definition: StepButtonView.h:75
Definition: StepButtonView.h:44
void setHeldColor(CColor const &iColor)
Definition: StepButtonView.h:72