wg_timer.cpp

00001 // wg_timer.cpp
00002 //
00003 // CTimer class implementation
00004 //
00005 //
00006 // Copyright (c) 2002-2004 Rob Wiskow
00007 // rob-dev@boxedchaos.com
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022 //
00023 
00024 
00025 #include "wgui_include_config.h"
00026 #include "wg_timer.h"
00027 #include "wg_message_server.h"
00028 
00029 
00030 namespace wGui
00031 {
00032 
00033 Uint32 TimerCallback(Uint32 Interval, void* param)
00034 {
00035      return static_cast<CTimer*>(param)->TimerHit(Interval);
00036 }
00037 
00038 
00039 CTimer::CTimer(CMessageClient* pOwner) :
00040      m_TimerID(0),
00041      m_bAutoRestart(false),
00042      m_iCounter(0),
00043      m_pOwner(pOwner)
00044 { }
00045 
00046 
00047 CTimer::~CTimer(void)
00048 {
00049      StopTimer();
00050 }
00051 
00052 
00053 void CTimer::StartTimer(unsigned long int Interval, bool bAutoRestart)
00054 {
00055      m_bAutoRestart = bAutoRestart;
00056      if (m_TimerID != 0)
00057      {
00058           StopTimer();
00059      }
00060      m_TimerID = SDL_AddTimer(Interval, &TimerCallback, this);
00061 }
00062 
00063 
00064 void CTimer::StopTimer(void)
00065 {
00066      if (m_TimerID)
00067      {
00068           SDL_RemoveTimer(m_TimerID);
00069           m_TimerID = 0;
00070      }
00071 }
00072 
00073 
00074 Uint32 CTimer::TimerHit(Uint32 Interval)
00075 {
00076      m_iCounter++;
00077      CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_TIMER, m_pOwner, this, m_iCounter));
00078      if (!m_bAutoRestart)
00079      {
00080           StopTimer();
00081      }
00082 
00083      return Interval;
00084 }
00085 
00086 
00087 bool CTimer::HandleMessage(CMessage* /*pMessage*/)
00088 {
00089      bool bHandled = false;
00090 
00091      return bHandled;
00092 }
00093 
00094 }
00095 

Generated on Wed May 16 23:11:26 2007 for wGui by  doxygen 1.5.1