Jamba C++ API  5.0.0
StepPadView.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 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 
26 
27 using namespace VSTGUI;
28 
61 {
62 public:
65  enum class EPositiveDirection
66  {
67  kUp,
68  kDown,
69  kRight,
70  kLeft,
71  };
72 
73 public:
74  explicit StepPadView(const CRect &iSize) : CustomDiscreteControlView(iSize)
75  {
76  }
77 
78  // draw => does the actual drawing job
79  void draw(CDrawContext *iContext) override;
80 
81  // called to display the "held" pad state
82  virtual void drawHeldPad(CDrawContext *iContext);
83 
84  // called to display the "released" pad state
85  virtual void drawReleasedPad(CDrawContext *iContext);
86 
87  // input events (mouse/keyboard)
88  CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override;
89  CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override;
90  CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override;
91  CMouseEventResult onMouseCancel() override;
92 
93  // true if held
94  bool isHeld() const { return fHeld; }
95 
101  inline CColor const &getHeldColor() const { return fHeldColor; }
103  void setHeldColor(CColor const &iColor) { fHeldColor = iColor; }
104 
107  CColor const &getDisabledColor() const { return fDisabledColor; }
109  void setDisabledColor(CColor const &iColor) { fDisabledColor = iColor; }
110 
133  BitmapPtr getImage() const { return fImage; }
134 
136  void setImage(BitmapPtr iImage) { fImage = iImage; }
137 
142  bool getImageHasDisabledState() const { return fImageHasDisabledState; }
144  void setImageHasDisabledState(bool iValue) { fImageHasDisabledState = iValue; }
145 
148  int32 getStepIncrement() const { return fStepIncrement; }
150  void setStepIncrement(int32 iStepIncrement) { fStepIncrement = iStepIncrement; }
151 
156  int32 getShiftStepIncrement() const { return fShiftStepIncrement; }
157 
159  void setShiftStepIncrement(int32 iStepIncrement) { fShiftStepIncrement = iStepIncrement; }
160 
168  double getDragFactor() const { return fDragFactor; }
170  void setDragFactor(double iDragFactor) { fDragFactor = iDragFactor; }
171 
177  double getShiftDragFactor() const { return fShiftDragFactor; }
179  void setShiftDragFactor(double iShiftDragFactor) { fShiftDragFactor = iShiftDragFactor; }
180 
184  inline bool getWrap() const { return fWrap; }
186  void setWrap(bool iFlag) { fWrap = iFlag; }
187 
194  bool getInverse() const { return fInverse; }
196  void setInverse(bool iInverse) { fInverse = iInverse; }
197 
211  EPositiveDirection getDirection() const { return fDirection; }
213  void setDirection(EPositiveDirection iDirection) { fDirection = iDirection; }
214 
215 protected:
216  // registerParameters
217  void registerParameters() override;
218 
221  virtual CMouseEventResult setNextValue(CPoint &iWhere, const CButtonState &iButtons);
222 
223  // sizeToFit
224  bool sizeToFit() override;
225 
226 protected:
229  bool fHeld{false};
230 
231  int32 fStepIncrement{1};
232  int32 fShiftStepIncrement{1};
233  double fDragFactor{100.0};
234  double fShiftDragFactor{100.0};
235  bool fWrap{false};
236 
237  CColor fHeldColor{kRedCColor};
238  CColor fDisabledColor{kBlackCColor};
239  BitmapSPtr fImage{nullptr};
240  bool fInverse{false};
241  EPositiveDirection fDirection{EPositiveDirection::kUp};
242 
243  // whether the image has disabled state (3 frames) or not (2 frames)
244  bool fImageHasDisabledState{false};
245 
246  // the editor for handling parameter change
248  CPoint fMousePosition{};
249 
250 public:
251  class Creator : public CustomViewCreator<StepPadView, CustomDiscreteControlView>
252  {
253  public:
254  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
255  CustomViewCreator(iViewName, iDisplayName)
256  {
257  registerIntegerAttribute<int32>("step-increment", &StepPadView::getStepIncrement, &StepPadView::setStepIncrement);
258  registerIntegerAttribute<int32>("shift-step-increment", &StepPadView::getShiftStepIncrement, &StepPadView::setShiftStepIncrement);
259  registerDoubleAttribute("drag-factor", &StepPadView::getDragFactor, &StepPadView::setDragFactor);
260  registerDoubleAttribute("shift-drag-factor", &StepPadView::getShiftDragFactor, &StepPadView::setShiftDragFactor);
261  registerBooleanAttribute("wrap", &StepPadView::getWrap, &StepPadView::setWrap);
262  registerColorAttribute("held-color", &StepPadView::getHeldColor, &StepPadView::setHeldColor);
263  registerColorAttribute("disabled-color", &StepPadView::getDisabledColor, &StepPadView::setDisabledColor);
264  registerBitmapAttribute("pad-image", &StepPadView::getImage, &StepPadView::setImage);
265  registerBooleanAttribute("pad-image-has-disabled-state", &StepPadView::getImageHasDisabledState, &StepPadView::setImageHasDisabledState);
266  registerBooleanAttribute("inverse", &StepPadView::getInverse, &StepPadView::setInverse);
267  registerListAttribute<EPositiveDirection>("positive-direction",
269  {
270  {"up", EPositiveDirection::kUp},
271  {"down", EPositiveDirection::kDown},
272  {"right", EPositiveDirection::kRight},
273  {"left", EPositiveDirection::kLeft}
274  }
275  );
276  }
277  };
278 };
279 
280 }
Inherit from this class to provide the factory for a custom view.
Definition: CustomViewCreator.h:1314
int32 getStepIncrement() const
Value by which this pad will increment (positive) or decrement (negative) the parameter.
Definition: StepPadView.h:148
bool getWrap() const
Defines what happens when the value reaches its end of range after being incremented (resp.
Definition: StepPadView.h:184
double getShiftDragFactor() const
Defines how many pixels the mouse needs to move to go through the range of values when shift is being...
Definition: StepPadView.h:177
BitmapPtr getImage() const
The image to use to draw the pad.
Definition: StepPadView.h:133
A step pad lets you step through the values of a parameter by click dragging vertically or horizontal...
Definition: StepPadView.h:60
bool isHeld() const
Definition: StepPadView.h:94
CColor const & getDisabledColor() const
When no image is provided and the control is disabled, this color is used instead.
Definition: StepPadView.h:107
int32 getShiftStepIncrement() const
Value by which this pad will increment (positive) or decrement (negative) the parameter when the shif...
Definition: StepPadView.h:156
void setImageHasDisabledState(bool iValue)
Attribute button-image.
Definition: StepPadView.h:144
void setStepIncrement(int32 iStepIncrement)
Attribute step-increment.
Definition: StepPadView.h:150
CColor const & getHeldColor() const
When no image is provided, the "released" color is the back color.
Definition: StepPadView.h:101
bool getInverse() const
Inverses the meaning of "held" and "released" in regards to drawing the view/image.
Definition: StepPadView.h:194
void setHeldColor(CColor const &iColor)
attribute held-color
Definition: StepPadView.h:103
void setDisabledColor(CColor const &iColor)
attribute disabled-color
Definition: StepPadView.h:109
Definition: Types.h:29
void setDragFactor(double iDragFactor)
Attribute drag-factor.
Definition: StepPadView.h:170
SharedPointer< CBitmap > BitmapSPtr
Definition: Types.h:50
EPositiveDirection
Represents the direction the mouse needs to be moved to register a change.
Definition: StepPadView.h:65
StepPadView(const CRect &iSize)
Definition: StepPadView.h:74
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: StepPadView.h:254
Definition: CustomController.h:24
double getDragFactor() const
Defines how many pixels the mouse needs to move to go through the range of values.
Definition: StepPadView.h:168
void setWrap(bool iFlag)
Attribute wrap.
Definition: StepPadView.h:186
bool getImageHasDisabledState() const
Flag to determine whether the image contains a disabled state (3 frames) or not (2 frames)
Definition: StepPadView.h:142
void setShiftStepIncrement(int32 iStepIncrement)
Attribute shift-step-increment.
Definition: StepPadView.h:159
void setDirection(EPositiveDirection iDirection)
Attribute positive-direction.
Definition: StepPadView.h:213
EPositiveDirection getDirection() const
Defines the direction in which the mouse needs to be dragged in order to increase the value.
Definition: StepPadView.h:211
Specialization of TCustomControlView for discrete values.
Definition: CustomControlView.h:152
void setImage(BitmapPtr iImage)
Attribute pad-image.
Definition: StepPadView.h:136
void setInverse(bool iInverse)
Attribute inverse.
Definition: StepPadView.h:196
CBitmap * BitmapPtr
Definition: Types.h:49
void setShiftDragFactor(double iShiftDragFactor)
Attribute shift-drag-factor.
Definition: StepPadView.h:179
Represents an optional parameter (Jmb, Vst or no param at all).
Definition: GUIOptionalParam.h:48