PixelLightAPI  .
AbstractButton.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: AbstractButton.h                               *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLGUI_ABSTRACTBUTTON_H__
00024 #define __PLGUI_ABSTRACTBUTTON_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
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 //[ Namespace                                             ]
00039 //[-------------------------------------------------------]
00040 namespace PLGui {
00041 
00042 
00043 //[-------------------------------------------------------]
00044 //[ Classes                                               ]
00045 //[-------------------------------------------------------]
00046 /**
00047 *  @brief
00048 *    Abstract base class for all kind of buttons
00049 */
00050 class AbstractButton : public Widget {
00051 
00052 
00053     //[-------------------------------------------------------]
00054     //[ Class definition                                      ]
00055     //[-------------------------------------------------------]
00056     pl_class(PLGUI_RTTI_EXPORT, AbstractButton, "PLGui", PLGui::Widget, "Abstract base class for all kind of buttons")
00057         // Attributes
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         // Signals
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         // Slots
00069         pl_slot_0(OnTimer,  "Timer callback",   "")
00070     pl_class_end
00071 
00072 
00073     //[-------------------------------------------------------]
00074     //[ Public functions                                      ]
00075     //[-------------------------------------------------------]
00076     public:
00077         /**
00078         *  @brief
00079         *    Constructor
00080         *
00081         *  @param[in] pParent
00082         *    Pointer to the parent widget
00083         */
00084         PLGUI_API AbstractButton(Widget *pParent = nullptr);
00085 
00086         /**
00087         *  @brief
00088         *    Destructor
00089         */
00090         PLGUI_API virtual ~AbstractButton();
00091 
00092         /**
00093         *  @brief
00094         *    Get widget state
00095         *
00096         *  @return
00097         *    Widget states as flags (see EWidgetState)
00098         */
00099         PLGUI_API virtual PLCore::uint32 GetWidgetState() const;
00100 
00101         /**
00102         *  @brief
00103         *    Get button text
00104         *
00105         *  @return
00106         *    Text that is displayed on the button
00107         */
00108         PLGUI_API PLCore::String GetText() const;
00109 
00110         /**
00111         *  @brief
00112         *    Set button text
00113         *
00114         *  @param[in] sText
00115         *    Text that is displayed on the button
00116         */
00117         PLGUI_API void SetText(const PLCore::String &sText);
00118 
00119         /**
00120         *  @brief
00121         *    Get image
00122         *
00123         *  @return
00124         *    Image that is displayed on the button
00125         */
00126         PLGUI_API const Image &GetImage() const;
00127 
00128         /**
00129         *  @brief
00130         *    Set image
00131         *
00132         *  @param[in] cImage
00133         *    Image that is displayed on the button
00134         */
00135         PLGUI_API void SetImage(const Image &cImage);
00136 
00137         /**
00138         *  @brief
00139         *    Get image filename
00140         *
00141         *  @return
00142         *    Image that is displayed on the button
00143         */
00144         PLGUI_API PLCore::String GetImageName() const;
00145 
00146         /**
00147         *  @brief
00148         *    Set image filename
00149         *
00150         *  @param[in] sImage
00151         *    Image that is displayed on the button
00152         */
00153         PLGUI_API void SetImageName(const PLCore::String &sImage);
00154 
00155         /**
00156         *  @brief
00157         *    Get image size
00158         *
00159         *  @return
00160         *    Size of image
00161         */
00162         PLGUI_API const PLMath::Vector2i &GetImageSize() const;
00163 
00164         /**
00165         *  @brief
00166         *    Set image size
00167         *
00168         *  @param[in] vSize
00169         *    Size of image
00170         */
00171         PLGUI_API void SetImageSize(const PLMath::Vector2i &vSize);
00172 
00173         /**
00174         *  @brief
00175         *    Get repeat-mode
00176         *
00177         *  @return
00178         *    'true' if repeat-mode is enabled, else 'false'
00179         */
00180         PLGUI_API bool GetRepeat() const;
00181 
00182         /**
00183         *  @brief
00184         *    Set repeat-mode
00185         *
00186         *  @param[in] bRepeat
00187         *    'true' if repeat-mode is enabled, else 'false'
00188         */
00189         PLGUI_API void SetRepeat(bool bRepeat);
00190 
00191         /**
00192         *  @brief
00193         *    Get repeat delay
00194         *
00195         *  @return
00196         *    Initial delay (in ms) before auto-repeat
00197         */
00198         PLGUI_API PLCore::uint64 GetRepeatDelay() const;
00199 
00200         /**
00201         *  @brief
00202         *    Set repeat delay
00203         *
00204         *  @param[in] nDelay
00205         *    Initial delay (in ms) before auto-repeat
00206         */
00207         PLGUI_API void SetRepeatDelay(PLCore::uint64 nDelay);
00208 
00209         /**
00210         *  @brief
00211         *    Get repeat interval
00212         *
00213         *  @return
00214         *    Interval (in ms) between auto-repeated clicks
00215         */
00216         PLGUI_API PLCore::uint64 GetRepeatInterval() const;
00217 
00218         /**
00219         *  @brief
00220         *    Set repeat interval
00221         *
00222         *  @param[in] nInterval
00223         *    Interval (in ms) between auto-repeated clicks
00224         */
00225         PLGUI_API void SetRepeatInterval(PLCore::uint64 nInterval);
00226 
00227         /**
00228         *  @brief
00229         *    Returns whether the button is currently pressed or not
00230         *
00231         *  @return
00232         *    'true' if the button is currently pressed, else 'false'
00233         */
00234         PLGUI_API bool IsPressed() const;
00235 
00236 
00237     //[-------------------------------------------------------]
00238     //[ Protected virtual AbstractButton functions            ]
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     //[ Protected virtual Widget functions                    ]
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     //[ Private functions                                     ]
00264     //[-------------------------------------------------------]
00265     private:
00266         /**
00267         *  @brief
00268         *    Press button down
00269         */
00270         void PressButton();
00271 
00272         /**
00273         *  @brief
00274         *    Release button
00275         *
00276         *  @param[in] bClick
00277         *    If 'true', the button will emit a click event
00278         */
00279         void ReleaseButton(bool bClick);
00280 
00281         /**
00282         *  @brief
00283         *    Called when the timer has fired
00284         */
00285         void OnTimer();
00286 
00287 
00288     //[-------------------------------------------------------]
00289     //[ Protected data                                        ]
00290     //[-------------------------------------------------------]
00291     protected:
00292         // Button options
00293         PLCore::String      m_sText;            /**< Text that is displayed on the button */
00294         Image               m_cImage;           /**< Image that is displayed on the button */
00295         PLMath::Vector2i    m_vImageSize;       /**< Size of image (usually 16x16) */
00296         bool                m_bRepeat;          /**< If the button is hold down, emit clicks repeatedly */
00297         PLCore::uint64      m_nRepeatDelay;     /**< Initial delay (in ms) for repeated clicks */
00298         PLCore::uint64      m_nRepeatInterval;  /**< Interval (in ms) between repeated clicks */
00299 
00300         // Button state
00301         bool                m_bPressed;         /**< Is the button currently pressed? */
00302         bool                m_bMouseIn;         /**< Is the mouse inside the button? */
00303         bool                m_bMousePressed;    /**< Is there currently a mouse button pressed? */
00304 
00305         // Tools
00306         Timer               m_cTimer;           /**< Timer for repeated clicks */
00307 
00308 
00309 };
00310 
00311 
00312 //[-------------------------------------------------------]
00313 //[ Namespace                                             ]
00314 //[-------------------------------------------------------]
00315 } // PLGui
00316 
00317 
00318 #endif // __PLGUI_ABSTRACTBUTTON_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:50
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported