Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

RepeatTimer.h

Go to the documentation of this file.
00001 #ifndef OglGui_RepeatTimer_h
00002 #define OglGui_RepeatTimer_h
00003 
00004 #ifndef OGLWND_H
00005 #include "Link/OGL/OGLWnd.h"
00006 #endif
00007 
00008 /*
00009 #ifndef OglGui_time_included
00010 #include <time.h>
00011 #define OglGui_time_included
00012 #endif
00013 */
00014 
00015 namespace OglGui
00016 {
00017 
00018 class RepeatTimer
00019 {
00020 public:
00021         RepeatTimer(int msDelay = 400, int msInterval = 40)
00022         {
00023                 Init(msDelay, msInterval);
00024         }
00025 
00026     void SetRepeatDelays(int msDelay = 400, int msInterval = 40)
00027     {
00028         mRepeatDelay = msDelay;
00029         mRepeatInterval = msInterval;
00030     }
00031 
00032     void GetRepeatDelays(int *msDelay, int *msInterval) const
00033     {
00034         if (msDelay)
00035             *msDelay = mRepeatDelay;
00036         if (msInterval)
00037             *msInterval = mRepeatInterval;
00038     }
00039 
00040         void
00041         StartRepeatTime()
00042         {
00043         mRepeatLastTime = mRepeatStartTime = OglClock() * 1000;
00044                 mRepeatCount = 0;
00045         }
00046 
00047         bool RepeatTime()
00048         {
00049                 double  t = OglClock() * 1000;
00050                 if (mRepeatCount == 0)
00051                 {
00052                         if ((t - mRepeatStartTime) > mRepeatDelay)
00053                         {
00054                                 mRepeatLastTime = t;
00055                                 mRepeatCount = 1;
00056                                 return true;
00057                         }
00058                         return false;
00059                 }
00060                 else
00061                 {
00062             if (t - mRepeatLastTime > mRepeatInterval){
00063                 mRepeatCount++;
00064                 mRepeatLastTime = t;
00065                                 return true;
00066                         }
00067                         return false;
00068                 }
00069         }
00070 
00071     int GetRepeatCount() const
00072     {
00073         return mRepeatCount;
00074     }
00075 
00076 
00077 private:
00078 
00079         void
00080         Init(int msDelay, int msInterval)
00081         {
00082                 mRepeatDelay = msDelay;
00083                 mRepeatInterval = msInterval;
00084                 StartRepeatTime();
00085         }
00086 
00087         double  mRepeatStartTime;
00088         double  mRepeatLastTime;
00089         int             mRepeatDelay;
00090         int             mRepeatInterval;
00091         int             mRepeatCount;
00092 };
00093 
00094 } // namespace OglGui
00095 #endif

Generated on Fri Mar 19 09:31:37 2010 for ImpalaSrc by  doxygen 1.5.1