PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: ScrollBar.h * 00003 * 00004 * Copyright (C) 2002-2012 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_SCROLLBAR_H__ 00024 #define __PLGUI_SCROLLBAR_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLMath/Vector2i.h> 00032 #include "PLGui/Gui/Resources/Timer.h" 00033 #include "PLGui/Widgets/Base/AbstractSlider.h" 00034 00035 00036 //[-------------------------------------------------------] 00037 //[ Namespace ] 00038 //[-------------------------------------------------------] 00039 namespace PLGui { 00040 00041 00042 //[-------------------------------------------------------] 00043 //[ Classes ] 00044 //[-------------------------------------------------------] 00045 /** 00046 * @brief 00047 * Scroll bar widget 00048 */ 00049 class ScrollBar : public AbstractSlider { 00050 00051 00052 //[-------------------------------------------------------] 00053 //[ Class definition ] 00054 //[-------------------------------------------------------] 00055 pl_class(PLGUI_RTTI_EXPORT, ScrollBar, "PLGui", PLGui::AbstractSlider, "Scroll bar widget") 00056 // Attributes 00057 pl_attribute(Orientation, pl_enum_type(EOrientation), Horizontal, ReadWrite, GetSet, "Scrollbar orientation", "") 00058 // Constructors 00059 pl_constructor_0(DefaultConstructor, "Default constructor", "") 00060 // Slots 00061 pl_slot_0(OnTimer, "Timer callback", "") 00062 pl_class_end 00063 00064 00065 //[-------------------------------------------------------] 00066 //[ Public functions ] 00067 //[-------------------------------------------------------] 00068 public: 00069 /** 00070 * @brief 00071 * Constructor 00072 * 00073 * @param[in] pParent 00074 * Pointer to the parent widget 00075 */ 00076 PLGUI_API ScrollBar(Widget *pParent = nullptr); 00077 00078 /** 00079 * @brief 00080 * Destructor 00081 */ 00082 PLGUI_API virtual ~ScrollBar(); 00083 00084 /** 00085 * @brief 00086 * Get orientation 00087 * 00088 * @return 00089 * Orientation 00090 */ 00091 PLGUI_API EOrientation GetOrientation() const; 00092 00093 /** 00094 * @brief 00095 * Set orientation 00096 * 00097 * @param[in] nOrientation 00098 * Orientation 00099 */ 00100 PLGUI_API void SetOrientation(EOrientation nOrientation); 00101 00102 00103 //[-------------------------------------------------------] 00104 //[ Protected virtual AbstractSlider functions ] 00105 //[-------------------------------------------------------] 00106 protected: 00107 PLGUI_API virtual void OnChangeValue(int nValue) override; 00108 00109 00110 //[-------------------------------------------------------] 00111 //[ Public virtual Widget functions ] 00112 //[-------------------------------------------------------] 00113 public: 00114 PLGUI_API virtual void OnDraw(Graphics &cGraphics) override; 00115 PLGUI_API virtual PLMath::Vector2i OnPreferredSize(const PLMath::Vector2i &vRefSize) const override; 00116 PLGUI_API virtual void OnDisable() override; 00117 PLGUI_API virtual void OnMouseLeave() override; 00118 PLGUI_API virtual void OnMouseMove(const PLMath::Vector2i &vPos) override; 00119 PLGUI_API virtual void OnMouseButtonDown(PLCore::uint32 nButton, const PLMath::Vector2i &vPos) override; 00120 PLGUI_API virtual void OnMouseButtonUp(PLCore::uint32 nButton, const PLMath::Vector2i &vPos) override; 00121 00122 00123 //[-------------------------------------------------------] 00124 //[ Protected functions ] 00125 //[-------------------------------------------------------] 00126 protected: 00127 /** 00128 * @brief 00129 * Calculate position of minus button 00130 */ 00131 void CalculateMinusButtonPos(); 00132 00133 /** 00134 * @brief 00135 * Calculate position of plus button 00136 */ 00137 void CalculatePlusButtonPos(); 00138 00139 /** 00140 * @brief 00141 * Calculate position of scrollbar handle 00142 */ 00143 void CalculateHandlePos(); 00144 00145 /** 00146 * @brief 00147 * Get widget state for the minus button 00148 * 00149 * @return 00150 * Widget state of minus button (combination of EWidgetState values) 00151 */ 00152 PLCore::uint32 GetMinusButtonState(); 00153 00154 /** 00155 * @brief 00156 * Get widget state for the plus button 00157 * 00158 * @return 00159 * Widget state of plus button (combination of EWidgetState values) 00160 */ 00161 PLCore::uint32 GetPlusButtonState(); 00162 00163 /** 00164 * @brief 00165 * Get widget state for the handle 00166 * 00167 * @return 00168 * Widget state of handle (combination of EWidgetState values) 00169 */ 00170 PLCore::uint32 GetHandleState(); 00171 00172 /** 00173 * @brief 00174 * Check if a button has been pressed 00175 * 00176 * @param[in] vPos 00177 * Mouse position 00178 * @param[in] bSlider 00179 * Allow selection of slider? 00180 */ 00181 void CheckButtons(const PLMath::Vector2i &vPos, bool bSlider); 00182 00183 /** 00184 * @brief 00185 * Called when the timer has fired 00186 */ 00187 void OnTimer(); 00188 00189 00190 //[-------------------------------------------------------] 00191 //[ Protected data types ] 00192 //[-------------------------------------------------------] 00193 protected: 00194 /** 00195 * @brief 00196 * Scroll bar button 00197 */ 00198 struct SScrollBarButton { 00199 PLMath::Vector2i vPos1; 00200 PLMath::Vector2i vPos2; 00201 bool bMouseOver; 00202 bool bPressed; 00203 }; 00204 00205 /** 00206 * @brief 00207 * Scroll bar slider 00208 */ 00209 struct SScrollBarSlider { 00210 PLMath::Vector2i vPos1; 00211 PLMath::Vector2i vPos2; 00212 bool bMouseOver; 00213 bool bPressed; 00214 int nMinPos; 00215 int nMaxPos; 00216 }; 00217 00218 00219 //[-------------------------------------------------------] 00220 //[ Protected data ] 00221 //[-------------------------------------------------------] 00222 protected: 00223 // Options 00224 EOrientation m_nOrientation; /**< Scrollbar orientation */ 00225 PLCore::uint64 m_nRepeatInterval; /**< Interval (in ms) between repeated clicks */ 00226 00227 // Internal data 00228 SScrollBarButton m_sButtonMinus; /**< Button 'minus' */ 00229 SScrollBarButton m_sButtonPlus; /**< Button 'plus' */ 00230 SScrollBarSlider m_sHandle; /**< Handle */ 00231 PLMath::Vector2i m_vMousePos; /**< Last mouse position */ 00232 Timer m_cTimer; /**< Timer for repeated clicks */ 00233 00234 00235 }; 00236 00237 00238 //[-------------------------------------------------------] 00239 //[ Namespace ] 00240 //[-------------------------------------------------------] 00241 } // PLGui 00242 00243 00244 #endif // __PLGUI_SCROLLBAR_H__
|