00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __PLGUI_ABSTRACTBUTTON_H__
00024 #define __PLGUI_ABSTRACTBUTTON_H__
00025 #pragma once
00026
00027
00028
00029
00030
00031 #include <PLCore/String/String.h>
00032 #include "PLGui/Gui/Resources/Image.h"
00033 #include "PLGui/Gui/Resources/Timer.h"
00034 #include "PLGui/Widgets/Widget.h"
00035
00036
00037
00038
00039
00040 namespace PLGui {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 class AbstractButton : public Widget {
00051
00052
00053
00054
00055
00056 pl_class(PLGUI_RTTI_EXPORT, AbstractButton, "PLGui", PLGui::Widget, "Abstract base class for all kind of buttons")
00057
00058 pl_attribute(Text, PLCore::String, "", ReadWrite, GetSet, "Text that is displayed on the button", "")
00059 pl_attribute(ImageName, PLCore::String, "", ReadWrite, GetSet, "Image filename", "")
00060 pl_attribute(ImageSize, PLMath::Vector2i, PLMath::Vector2i(16, 16), ReadWrite, GetSet, "Image size", "")
00061 pl_attribute(Repeat, bool, false, ReadWrite, GetSet, "If the button is hold down, emit clicks repeatedly", "")
00062 pl_attribute(RepeatDelay, PLCore::uint64, 500, ReadWrite, GetSet, "Initial delay (in ms) for repeated clicks", "")
00063 pl_attribute(RepeatInterval, PLCore::uint64, 500, ReadWrite, GetSet, "Interval (in ms) between repeated clicks", "")
00064
00065 pl_signal_0(SignalPressed, "The button has been pressed down", "")
00066 pl_signal_0(SignalReleased, "The button has been released", "")
00067 pl_signal_0(SignalClicked, "The button has been clicked (pressed and released)", "")
00068
00069 pl_slot_0(OnTimer, "Timer callback", "")
00070 pl_class_end
00071
00072
00073
00074
00075
00076 public:
00077
00078
00079
00080
00081
00082
00083
00084 PLGUI_API AbstractButton(Widget *pParent = nullptr);
00085
00086
00087
00088
00089
00090 PLGUI_API virtual ~AbstractButton();
00091
00092
00093
00094
00095
00096
00097
00098
00099 PLGUI_API virtual PLCore::uint32 GetWidgetState() const;
00100
00101
00102
00103
00104
00105
00106
00107
00108 PLGUI_API PLCore::String GetText() const;
00109
00110
00111
00112
00113
00114
00115
00116
00117 PLGUI_API void SetText(const PLCore::String &sText);
00118
00119
00120
00121
00122
00123
00124
00125
00126 PLGUI_API const Image &GetImage() const;
00127
00128
00129
00130
00131
00132
00133
00134
00135 PLGUI_API void SetImage(const Image &cImage);
00136
00137
00138
00139
00140
00141
00142
00143
00144 PLGUI_API PLCore::String GetImageName() const;
00145
00146
00147
00148
00149
00150
00151
00152
00153 PLGUI_API void SetImageName(const PLCore::String &sImage);
00154
00155
00156
00157
00158
00159
00160
00161
00162 PLGUI_API const PLMath::Vector2i &GetImageSize() const;
00163
00164
00165
00166
00167
00168
00169
00170
00171 PLGUI_API void SetImageSize(const PLMath::Vector2i &vSize);
00172
00173
00174
00175
00176
00177
00178
00179
00180 PLGUI_API bool GetRepeat() const;
00181
00182
00183
00184
00185
00186
00187
00188
00189 PLGUI_API void SetRepeat(bool bRepeat);
00190
00191
00192
00193
00194
00195
00196
00197
00198 PLGUI_API PLCore::uint64 GetRepeatDelay() const;
00199
00200
00201
00202
00203
00204
00205
00206
00207 PLGUI_API void SetRepeatDelay(PLCore::uint64 nDelay);
00208
00209
00210
00211
00212
00213
00214
00215
00216 PLGUI_API PLCore::uint64 GetRepeatInterval() const;
00217
00218
00219
00220
00221
00222
00223
00224
00225 PLGUI_API void SetRepeatInterval(PLCore::uint64 nInterval);
00226
00227
00228
00229
00230
00231
00232
00233
00234 PLGUI_API bool IsPressed() const;
00235
00236
00237
00238
00239
00240 protected:
00241 PLGUI_API virtual void OnButtonPressed();
00242 PLGUI_API virtual void OnButtonReleased();
00243 PLGUI_API virtual void OnButtonClicked();
00244
00245
00246
00247
00248
00249 protected:
00250 PLGUI_API virtual void OnDisable() override;
00251 PLGUI_API virtual void OnGetFocus() override;
00252 PLGUI_API virtual void OnLooseFocus() override;
00253 PLGUI_API virtual void OnMouseEnter() override;
00254 PLGUI_API virtual void OnMouseLeave() override;
00255 PLGUI_API virtual void OnMouseMove(const PLMath::Vector2i &vPos) override;
00256 PLGUI_API virtual void OnMouseButtonDown(PLCore::uint32 nButton, const PLMath::Vector2i &vPos) override;
00257 PLGUI_API virtual void OnMouseButtonUp(PLCore::uint32 nButton, const PLMath::Vector2i &vPos) override;
00258 PLGUI_API virtual void OnKeyDown(PLCore::uint32 nKey, PLCore::uint32 nModifiers) override;
00259 PLGUI_API virtual void OnKeyUp(PLCore::uint32 nKey, PLCore::uint32 nModifiers) override;
00260
00261
00262
00263
00264
00265 private:
00266
00267
00268
00269
00270 void PressButton();
00271
00272
00273
00274
00275
00276
00277
00278
00279 void ReleaseButton(bool bClick);
00280
00281
00282
00283
00284
00285 void OnTimer();
00286
00287
00288
00289
00290
00291 protected:
00292
00293 PLCore::String m_sText;
00294 Image m_cImage;
00295 PLMath::Vector2i m_vImageSize;
00296 bool m_bRepeat;
00297 PLCore::uint64 m_nRepeatDelay;
00298 PLCore::uint64 m_nRepeatInterval;
00299
00300
00301 bool m_bPressed;
00302 bool m_bMouseIn;
00303 bool m_bMousePressed;
00304
00305
00306 Timer m_cTimer;
00307
00308
00309 };
00310
00311
00312
00313
00314
00315 }
00316
00317
00318 #endif // __PLGUI_ABSTRACTBUTTON_H__