Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
TextButtonView.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2019 pongasoft
3 *
4 * Licensed under the Apache License, Version 2.0 or the MIT license,
5 * at your option. You may not use this file except in compliance with
6 * one of these licenses. You may obtain copies of the licenses at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 * https://opensource.org/licenses/MIT
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 *
17 * @author Yan Pujante
18 */
19#pragma once
20
21#include <vstgui4/vstgui/lib/controls/cbuttons.h>
23
25
26using namespace VSTGUI;
27using namespace Params;
28
48class TextButtonView : public CustomViewAdapter<CTextButton>
49{
50public:
51 using OnClickListener = std::function<void()>;
52
53 // Constructor
54 explicit TextButtonView(const CRect &iSize) : CustomViewAdapter(iSize) {}
55
57 virtual void setTitleTag(ParamID iValue);
58
62 ParamID getTitleTag() const { return fTitleTag; };
63
65 CColor const &getDisabledTextColor() const { return fDisabledTextColor; }
66
68 virtual void setDisabledTextColor(CColor const &iColor) { fDisabledTextColor = iColor; };
69
72
74 virtual void setDisabledGradient(GradientPtr iGradient) { fDisabledGradient = iGradient; };
75
76 void setMouseEnabled(bool bEnable) override;
77
78 // draw => overridden to handle disabled state
79 void draw(CDrawContext *context) override;
80
81 // registerParameters
82 void registerParameters() override;
83
84 // handles value change
85 void valueChanged() override;
86
87 // call to programmatically click the button
88 virtual void click();
89
90 // call to programmatically unClick the button
91 virtual void unClick();
92
93 // callback when the button is clicked
94 virtual void onClick();
95
96 // setOnClickListener
97 void setOnClickListener(OnClickListener iListener) { fOnClickListener = std::move(iListener); }
98
121 BitmapPtr getImage() const { return fImage; }
122 void setImage(BitmapPtr iImage) { fImage = iImage; }
123
129 void setImageHasDisabledState(bool iValue) { fImageHasDisabledState = iValue; }
130
139 int32 getPrecisionOverride() const { return fPrecisionOverride; }
140 void setPrecisionOverride(int32 iPrecisionOverride) { fPrecisionOverride = iPrecisionOverride; markDirty(); }
141
142protected:
146 virtual void drawButtonText(CDrawContext *context);
147
153 virtual void drawButtonImage(CDrawContext *context);
154
155protected:
156 // (optionally) tie the title of this text button to a (Jmb) parameter
158
159 // Which color and gradient to use when disabled
162
163 // the underlying parameter => use its string representation to display the text of the button
165
166 // the image to use (in place of text)
168
169 // whether the image has disabled state (3 frames) or not (2 frames)
171
172 // the onclick listener
174
175public:
176 class Creator : public CustomViewCreator<TextButtonView, CustomViewAdapter<CTextButton>>
177 {
178 public:
189 };
190};
191
192}
193
CustomViewAdapter(const CRect &iSize, Args &&...args)
Definition CustomView.h:344
CustomViewCreator(char const *iViewName=nullptr, char const *iDisplayName=nullptr, char const *iBaseViewName=VSTGUI::UIViewCreator::kCView)
Definition CustomViewCreator.h:1318
void registerColorAttribute(std::string const &iName, typename ColorAttribute::Getter iGetter, typename ColorAttribute::Setter iSetter)
Definition CustomViewCreator.h:952
void registerBitmapAttribute(std::string const &iName, typename BitmapAttribute::Getter iGetter, typename BitmapAttribute::Setter iSetter)
Definition CustomViewCreator.h:972
void registerIntegerAttribute(std::string const &iName, typename IntegerAttribute< TInt >::Getter iGetter, typename IntegerAttribute< TInt >::Setter iSetter)
Definition CustomViewCreator.h:1060
void registerGradientAttribute(std::string const &iName, typename GradientAttribute::Getter iGetter, typename GradientAttribute::Setter iSetter)
Definition CustomViewCreator.h:962
void registerBooleanAttribute(std::string const &iName, typename BooleanAttribute::Getter iGetter, typename BooleanAttribute::Setter iSetter)
Definition CustomViewCreator.h:1100
void registerTagAttribute(std::string const &iName, typename TagAttribute::Getter iGetter, typename TagAttribute::Setter iSetter)
Definition CustomViewCreator.h:1049
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition TextButtonView.h:179
virtual void setDisabledTextColor(CColor const &iColor)
Attribute disabled-text-color.
Definition TextButtonView.h:68
bool getImageHasDisabledState() const
Used when drawing the image.
Definition TextButtonView.h:128
void setPrecisionOverride(int32 iPrecisionOverride)
Definition TextButtonView.h:140
void registerParameters() override
Subclasses should override this method to register each parameter.
Definition TextButtonView.cpp:30
CColor const & getDisabledTextColor() const
Color used to draw the title when no image is provided and the button is disabled.
Definition TextButtonView.h:65
void setOnClickListener(OnClickListener iListener)
Definition TextButtonView.h:97
void valueChanged() override
Definition TextButtonView.cpp:49
ParamID fTitleTag
Definition TextButtonView.h:157
virtual void drawButtonText(CDrawContext *context)
Called when the button should be drawn entirely (background + text + icon).
Definition TextButtonView.cpp:82
virtual void unClick()
Definition TextButtonView.cpp:168
void setImage(BitmapPtr iImage)
Definition TextButtonView.h:122
virtual void onClick()
Definition TextButtonView.cpp:60
BitmapPtr getImage() const
The image for the button.
Definition TextButtonView.h:121
CColor fDisabledTextColor
Definition TextButtonView.h:160
int32 getPrecisionOverride() const
Allow to override the precision of the parameter.
Definition TextButtonView.h:139
void setMouseEnabled(bool bEnable) override
Definition TextButtonView.cpp:148
GradientSPtr fDisabledGradient
Definition TextButtonView.h:161
std::function< void()> OnClickListener
Definition TextButtonView.h:51
BitmapSPtr fImage
Definition TextButtonView.h:167
bool fImageHasDisabledState
Definition TextButtonView.h:170
virtual void setTitleTag(ParamID iValue)
Attribute title-tag.
Definition TextButtonView.cpp:41
int32 fPrecisionOverride
Definition TextButtonView.h:164
virtual void click()
Definition TextButtonView.cpp:160
virtual void drawButtonImage(CDrawContext *context)
Called when the button is simply rendered as an image.
Definition TextButtonView.cpp:124
virtual void setDisabledGradient(GradientPtr iGradient)
Attribute disabled-gradient.
Definition TextButtonView.h:74
OnClickListener fOnClickListener
Definition TextButtonView.h:173
void setImageHasDisabledState(bool iValue)
Definition TextButtonView.h:129
GradientPtr getDisabledGradient() const
Gradient used to draw the button when no image is provided and the button is disabled.
Definition TextButtonView.h:71
TextButtonView(const CRect &iSize)
Definition TextButtonView.h:54
void draw(CDrawContext *context) override
Definition TextButtonView.cpp:69
ParamID getTitleTag() const
Optional id of the parameter whose string representation (IGUIParameter::toUTF8String()) will be used...
Definition TextButtonView.h:62
Definition Types.h:30
Definition CustomController.h:25
CGradient * GradientPtr
Definition Types.h:58
CBitmap * BitmapPtr
Definition Types.h:50
SharedPointer< CGradient > GradientSPtr
Definition Types.h:59
SharedPointer< CBitmap > BitmapSPtr
Definition Types.h:51
constexpr ParamID UNDEFINED_PARAM_ID
Constant used throughout the code to test whether the ParamID represents a valid id or an undefined o...
Definition Types.h:48