Jamba  3.1.0
TextButtonView.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/cbuttons.h>
22 
23 namespace pongasoft {
24 namespace VST {
25 namespace GUI {
26 namespace Views {
27 
28 using namespace VSTGUI;
29 using namespace Params;
30 
36 class TextButtonView : public CustomViewAdapter<CTextButton>
37 {
38 public:
39  using OnClickListener = std::function<void()>;
40 
41  // Constructor
42  explicit TextButtonView(const CRect &iSize) : CustomViewAdapter(iSize) {}
43 
44  // get/set titleTag to (optionally) tie the title of this text button to a (Jmb) parameter
45  virtual void setTitleTag(int32_t iValue);
46  int32_t getTitleTag() const { return fTitleTag; };
47 
48  // get/set disabled text color (color to use when button is disabled)
49  CColor const &getDisabledTextColor() const { return fDisabledTextColor; }
50  virtual void setDisabledTextColor(CColor const &iColor) { fDisabledTextColor = iColor; };
51 
52  // get/set disabled gradient (gradient to use when button is disabled)
53  GradientPtr getDisabledGradient() const { return fDisabledGradient; }
54  virtual void setDisabledGradient(GradientPtr iGradient) { fDisabledGradient = iGradient; };
55 
56  void setMouseEnabled(bool bEnable) override;
57 
58  // draw => overridden to handle disabled state
59  void draw(CDrawContext *context) override;
60 
61  // registerParameters
62  void registerParameters() override;
63 
64  // handles value change
65  void valueChanged() override;
66 
67  // call to programmatically click the button
68  virtual void click();
69 
70  // call to programmatically unClick the button
71  virtual void unClick();
72 
73  // callback when the button is clicked
74  virtual void onClick();
75 
76  // setOnClickListener
77  void setOnClickListener(OnClickListener iListener) { fOnClickListener = std::move(iListener); }
78 
79  CLASS_METHODS_NOCOPY(TextButtonView, CustomViewAdapter<CTextButton>)
80 
81 protected:
82  // (optionally) tie the title of this text button to a (Jmb) parameter
83  int32_t fTitleTag{-1};
84 
85  // Which color and gradient to use when disabled
88 
89  // the underlying jmb parameter of type UTF8String
91 
92  // the onclick listener
93  OnClickListener fOnClickListener{};
94 
95 public:
96  class Creator : public CustomViewCreator<TextButtonView, CustomViewAdapter<CTextButton>>
97  {
98  public:
99  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
100  CustomViewCreator(iViewName, iDisplayName, VSTGUI::UIViewCreator::kCTextButton)
101  {
102  registerTagAttribute("title-tag", &TextButtonView::getTitleTag, &TextButtonView::setTitleTag);
103  registerColorAttribute("disabled-text-color", &TextButtonView::getDisabledTextColor, &TextButtonView::setDisabledTextColor);
104  registerGradientAttribute("disabled-gradient", &TextButtonView::getDisabledGradient, &TextButtonView::setDisabledGradient);
105  }
106  };
107 };
108 
109 }
110 }
111 }
112 }
113 
GradientSPtr fDisabledGradient
Definition: TextButtonView.h:87
void setOnClickListener(OnClickListener iListener)
Definition: TextButtonView.h:77
Definition: CustomViewCreator.h:981
CColor const & getDisabledTextColor() const
Definition: TextButtonView.h:49
Definition: Clock.h:22
virtual void setTitleTag(int32_t iValue)
Definition: TextButtonView.cpp:51
Definition: TextButtonView.h:36
std::function< void()> OnClickListener
Definition: TextButtonView.h:39
SharedPointer< CGradient > GradientSPtr
Definition: Types.h:58
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: TextButtonView.h:99
CColor fDisabledTextColor
Definition: TextButtonView.h:86
Definition: Types.h:29
virtual void setDisabledGradient(GradientPtr iGradient)
Definition: TextButtonView.h:54
virtual void setDisabledTextColor(CColor const &iColor)
Definition: TextButtonView.h:50
TextButtonView(const CRect &iSize)
Definition: TextButtonView.h:42
GradientPtr getDisabledGradient() const
Definition: TextButtonView.h:53
int32_t getTitleTag() const
Definition: TextButtonView.h:46
CGradient * GradientPtr
Definition: Types.h:57