PixelLightAPI  .
Slider.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Slider.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_SLIDER_H__
00024 #define __PLGUI_SLIDER_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLMath/Vector2i.h>
00032 #include "PLGui/Widgets/Base/AbstractSlider.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLGui {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    Slider widget
00047 */
00048 class Slider : public AbstractSlider {
00049 
00050 
00051     //[-------------------------------------------------------]
00052     //[ Class definition                                      ]
00053     //[-------------------------------------------------------]
00054     pl_class(PLGUI_RTTI_EXPORT, Slider, "PLGui", PLGui::AbstractSlider, "Slider widget")
00055         // Attributes
00056         pl_attribute(Orientation,   pl_enum_type(EOrientation), Horizontal, ReadWrite,  GetSet, "Slider orientation",   "")
00057         // Constructors
00058         pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00059     pl_class_end
00060 
00061 
00062     //[-------------------------------------------------------]
00063     //[ Public functions                                      ]
00064     //[-------------------------------------------------------]
00065     public:
00066         /**
00067         *  @brief
00068         *    Constructor
00069         *
00070         *  @param[in] pParent
00071         *    Pointer to the parent widget
00072         */
00073         PLGUI_API Slider(Widget *pParent = nullptr);
00074 
00075         /**
00076         *  @brief
00077         *    Destructor
00078         */
00079         PLGUI_API virtual ~Slider();
00080 
00081         /**
00082         *  @brief
00083         *    Get orientation
00084         *
00085         *  @return
00086         *    Orientation
00087         */
00088         PLGUI_API EOrientation GetOrientation() const;
00089 
00090         /**
00091         *  @brief
00092         *    Set orientation
00093         *
00094         *  @param[in] nOrientation
00095         *    Orientation
00096         */
00097         PLGUI_API void SetOrientation(EOrientation nOrientation);
00098 
00099 
00100     //[-------------------------------------------------------]
00101     //[ Protected virtual AbstractSlider functions            ]
00102     //[-------------------------------------------------------]
00103     protected:
00104         PLGUI_API virtual void OnChangeValue(int nValue) override;
00105 
00106 
00107     //[-------------------------------------------------------]
00108     //[ Public virtual Widget functions                       ]
00109     //[-------------------------------------------------------]
00110     public:
00111         PLGUI_API virtual void OnDraw(Graphics &cGraphics) override;
00112         PLGUI_API virtual PLMath::Vector2i OnPreferredSize(const PLMath::Vector2i &vRefSize) const override;
00113         PLGUI_API virtual void OnDisable() override;
00114         PLGUI_API virtual void OnMouseLeave() override;
00115         PLGUI_API virtual void OnMouseMove(const PLMath::Vector2i &vPos) override;
00116         PLGUI_API virtual void OnMouseButtonDown(PLCore::uint32 nButton, const PLMath::Vector2i &vPos) override;
00117         PLGUI_API virtual void OnMouseButtonUp(PLCore::uint32 nButton, const PLMath::Vector2i &vPos) override;
00118 
00119 
00120     //[-------------------------------------------------------]
00121     //[ Protected functions                                   ]
00122     //[-------------------------------------------------------]
00123     protected:
00124         /**
00125         *  @brief
00126         *    Calculate position of slider handle
00127         */
00128         void CalculateHandlePos();
00129 
00130         /**
00131         *  @brief
00132         *    Get widget state for the handle
00133         *
00134         *  @return
00135         *    Widget state of handle (combination of EWidgetState values)
00136         */
00137         PLCore::uint32 GetHandleState();
00138 
00139         /**
00140         *  @brief
00141         *    Check if a button has been pressed
00142         *
00143         *  @param[in] vPos
00144         *    Mouse position
00145         */
00146         void CheckButtons(const PLMath::Vector2i &vPos);
00147 
00148 
00149     //[-------------------------------------------------------]
00150     //[ Protected data types                                  ]
00151     //[-------------------------------------------------------]
00152     protected:
00153         /**
00154         *  @brief
00155         *    Slider handle
00156         */
00157         struct SSliderHandle {
00158             PLMath::Vector2i vPos1;
00159             PLMath::Vector2i vPos2;
00160             bool             bMouseOver;
00161             bool             bPressed;
00162             int              nMinPos;
00163             int              nMaxPos;
00164         };
00165 
00166 
00167     //[-------------------------------------------------------]
00168     //[ Protected data                                        ]
00169     //[-------------------------------------------------------]
00170     protected:
00171         // Options
00172         EOrientation        m_nOrientation;     /**< Scrollbar orientation */
00173 
00174         // Internal data
00175         SSliderHandle       m_sHandle;          /**< Handle */
00176         PLMath::Vector2i    m_vMousePos;        /**< Last mouse position */
00177 
00178 
00179 };
00180 
00181 
00182 //[-------------------------------------------------------]
00183 //[ Namespace                                             ]
00184 //[-------------------------------------------------------]
00185 } // PLGui
00186 
00187 
00188 #endif // __PLGUI_SLIDER_H__


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