PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Timer.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_TIMER_H__ 00024 #define __PLGUI_TIMER_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/Event.h> 00032 #include "PLGui/PLGui.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLGui { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 class Gui; 00045 class TimerThread; 00046 00047 00048 //[-------------------------------------------------------] 00049 //[ Classes ] 00050 //[-------------------------------------------------------] 00051 /** 00052 * @brief 00053 * Timer class 00054 */ 00055 class Timer { 00056 00057 00058 //[-------------------------------------------------------] 00059 //[ Friends ] 00060 //[-------------------------------------------------------] 00061 friend class Gui; 00062 friend class TimerThread; 00063 00064 00065 //[-------------------------------------------------------] 00066 //[ Public events ] 00067 //[-------------------------------------------------------] 00068 public: 00069 PLCore::Event<> EventStart; /**< The timer has been started */ 00070 PLCore::Event<> EventStop; /**< The timer has been stopped */ 00071 PLCore::Event<> EventFire; /**< The timer has fired */ 00072 00073 00074 //[-------------------------------------------------------] 00075 //[ Public functions ] 00076 //[-------------------------------------------------------] 00077 public: 00078 /** 00079 * @brief 00080 * Constructor 00081 * 00082 * @param[in] cGui 00083 * Owner GUI 00084 */ 00085 PLGUI_API Timer(Gui &cGui); 00086 00087 /** 00088 * @brief 00089 * Destructor 00090 */ 00091 PLGUI_API ~Timer(); 00092 00093 /** 00094 * @brief 00095 * Get owner GUI 00096 * 00097 * @return 00098 * Pointer to GUI object (never a null pointer) 00099 */ 00100 PLGUI_API Gui *GetGui() const; 00101 00102 /** 00103 * @brief 00104 * Get timer ID 00105 * 00106 * @return 00107 * Timer ID 00108 */ 00109 PLGUI_API PLCore::uint32 GetID() const; 00110 00111 /** 00112 * @brief 00113 * Set timer ID 00114 * 00115 * @param[in] nID 00116 * Timer ID 00117 */ 00118 PLGUI_API void SetID(PLCore::uint32 nID); 00119 00120 /** 00121 * @brief 00122 * Check if timer is active 00123 * 00124 * @return 00125 * 'true' if timer is currently active 00126 */ 00127 PLGUI_API bool IsActive() const; 00128 00129 /** 00130 * @brief 00131 * Check if timer fires only once 00132 * 00133 * @return 00134 * 'true' if once 00135 */ 00136 PLGUI_API bool IsOnce() const; 00137 00138 /** 00139 * @brief 00140 * Get timeout interval 00141 * 00142 * @return 00143 * Timeout interval in milliseconds 00144 */ 00145 PLGUI_API PLCore::uint64 GetTimeout() const; 00146 00147 /** 00148 * @brief 00149 * Start timer 00150 * 00151 * @param[in] nTimeout 00152 * Timeout in milliseconds after which the timer fires repeatedly 00153 * 00154 * @note 00155 * - If the timer is already running it's stopped and started again 00156 */ 00157 PLGUI_API void Start(PLCore::uint64 nTimeout); 00158 00159 /** 00160 * @brief 00161 * Start timer only once, not periodically 00162 * 00163 * @param[in] nTimeout 00164 * Timeout in milliseconds after which the timer fires 00165 * 00166 * @note 00167 * - If the timer is already running it's stopped and started again 00168 */ 00169 PLGUI_API void StartOnce(PLCore::uint64 nTimeout); 00170 00171 /** 00172 * @brief 00173 * Stop timer 00174 */ 00175 PLGUI_API void Stop(); 00176 00177 00178 //[-------------------------------------------------------] 00179 //[ Protected functions ] 00180 //[-------------------------------------------------------] 00181 protected: 00182 /** 00183 * @brief 00184 * Fire timer 00185 */ 00186 PLGUI_API void Fire(); 00187 00188 00189 //[-------------------------------------------------------] 00190 //[ Protected data ] 00191 //[-------------------------------------------------------] 00192 protected: 00193 Gui *m_pGui; /**< Pointer to owner GUI */ 00194 PLCore::uint32 m_nID; /**< Timer ID */ 00195 TimerThread *m_pThread; /**< Current timer thread */ 00196 bool m_bActive; /**< Timer is active? */ 00197 bool m_bOnce; /**< Timer is firing only once? */ 00198 PLCore::uint64 m_nTimeout; /**< Timeout value */ 00199 00200 00201 //[-------------------------------------------------------] 00202 //[ Private static data ] 00203 //[-------------------------------------------------------] 00204 private: 00205 static PLCore::uint32 m_nNextID; /**< ID counter */ 00206 00207 00208 }; 00209 00210 00211 //[-------------------------------------------------------] 00212 //[ Namespace ] 00213 //[-------------------------------------------------------] 00214 } // PLGui 00215 00216 00217 #endif // __PLGUI_TIMER_H__
|