wxTimer for wxMGL
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12377 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: timer.h
|
// Name: timer.h
|
||||||
// Purpose:
|
// Purpose: wxTimer class
|
||||||
// Author: Vaclav Slavik
|
// Author: Vaclav Slavik
|
||||||
// Id: $Id$
|
// Id: $Id$
|
||||||
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
|
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
|
||||||
@@ -19,27 +19,35 @@
|
|||||||
// wxTimer
|
// wxTimer
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
//FIXME_MGL
|
class wxTimerDesc;
|
||||||
|
class wxTimerScheduler;
|
||||||
|
|
||||||
class WXDLLEXPORT wxTimer : public wxTimerBase
|
class WXDLLEXPORT wxTimer : public wxTimerBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxTimer() { Init(); }
|
wxTimer() { Init(); }
|
||||||
wxTimer(wxEvtHandler *owner, int id = -1) : wxTimerBase(owner, id)
|
wxTimer(wxEvtHandler *owner, int id = -1) : wxTimerBase(owner, id)
|
||||||
{ Init(); }
|
{ Init(); }
|
||||||
~wxTimer() {}
|
~wxTimer();
|
||||||
|
|
||||||
virtual bool Start( int millisecs = -1, bool oneShot = FALSE ) { return TRUE; }
|
virtual bool Start(int millisecs = -1, bool oneShot = FALSE);
|
||||||
virtual void Stop() {}
|
virtual void Stop();
|
||||||
|
|
||||||
virtual bool IsRunning() const { return m_tag != -1; }
|
virtual bool IsRunning() const;
|
||||||
|
|
||||||
|
// implementation
|
||||||
|
static void NotifyTimers();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Init() {}
|
void Init();
|
||||||
|
|
||||||
int m_tag;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
wxTimerDesc *m_desc;
|
||||||
|
|
||||||
|
static wxTimerScheduler *ms_scheduler;
|
||||||
|
static size_t ms_timersCnt;
|
||||||
|
|
||||||
DECLARE_ABSTRACT_CLASS(wxTimer)
|
DECLARE_ABSTRACT_CLASS(wxTimer)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __GTKTIMERH__
|
#endif // __WX_TIMER_H__
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "wx/dialog.h"
|
#include "wx/dialog.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
|
#include "wx/resource.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
|
@@ -29,8 +29,9 @@
|
|||||||
#endif //WX_PRECOMP
|
#endif //WX_PRECOMP
|
||||||
|
|
||||||
#include "wx/evtloop.h"
|
#include "wx/evtloop.h"
|
||||||
|
#include "wx/timer.h"
|
||||||
#include "wx/mgl/private.h"
|
#include "wx/mgl/private.h"
|
||||||
|
#include "pmapi.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxEventLoopImpl
|
// wxEventLoopImpl
|
||||||
@@ -77,7 +78,22 @@ void wxEventLoopImpl::Dispatch()
|
|||||||
|
|
||||||
MGL_wmUpdateDC(g_winMng);
|
MGL_wmUpdateDC(g_winMng);
|
||||||
|
|
||||||
EVT_halt(&evt, EVT_EVERYEVT);
|
// VS: The code bellow is equal to MGL's EVT_halt implementation, with
|
||||||
|
// two things added: sleeping (busy waiting is stupid, lets make CPU's
|
||||||
|
// life a bit easier) and timers updating
|
||||||
|
|
||||||
|
// EVT_halt(&evt, EVT_EVERYEVT);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
EVT_pollJoystick();
|
||||||
|
EVT_getNext(&evt, EVT_EVERYEVT);
|
||||||
|
#if wxUSE_TIMER
|
||||||
|
wxTimer::NotifyTimers();
|
||||||
|
#endif
|
||||||
|
PM_sleep(10);
|
||||||
|
} while (!(evt.what & EVT_EVERYEVT));
|
||||||
|
// end of EVT_halt
|
||||||
|
|
||||||
MGL_wmProcessEvent(g_winMng, &evt);
|
MGL_wmProcessEvent(g_winMng, &evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: gtk/timer.cpp
|
// Name: mgl/timer.cpp
|
||||||
// Purpose: wxTimer implementation
|
// Purpose: wxTimer implementation
|
||||||
// Author: Robert Roebling
|
// Author: Vaclav Slavik
|
||||||
// Id: $Id$
|
// Id: $Id$
|
||||||
// Copyright: (c) 1998 Robert Roebling
|
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -14,6 +14,97 @@
|
|||||||
|
|
||||||
#include "wx/timer.h"
|
#include "wx/timer.h"
|
||||||
|
|
||||||
|
#if wxUSE_TIMER
|
||||||
|
|
||||||
|
#include "wx/mgl/private.h"
|
||||||
|
|
||||||
|
extern "C" ulong _EVT_getTicks();
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// helper structures and wxTimerScheduler
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxTimerDesc
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxTimerDesc(wxTimer *t) : timer(t), running(FALSE), next(NULL), prev(NULL) {}
|
||||||
|
|
||||||
|
wxTimer *timer;
|
||||||
|
bool running;
|
||||||
|
wxTimerDesc *next, *prev;
|
||||||
|
unsigned long shotTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
class wxTimerScheduler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxTimerScheduler() : m_timers(NULL) {}
|
||||||
|
|
||||||
|
void QueueTimer(wxTimerDesc *desc, unsigned long when = 0);
|
||||||
|
void RemoveTimer(wxTimerDesc *desc);
|
||||||
|
void NotifyTimers();
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxTimerDesc *m_timers;
|
||||||
|
};
|
||||||
|
|
||||||
|
void wxTimerScheduler::QueueTimer(wxTimerDesc *desc, unsigned long when)
|
||||||
|
{
|
||||||
|
if ( when == 0 )
|
||||||
|
when = _EVT_getTicks() + desc->timer->GetInterval();
|
||||||
|
desc->shotTime = when;
|
||||||
|
desc->running = TRUE;
|
||||||
|
|
||||||
|
if ( m_timers )
|
||||||
|
{
|
||||||
|
wxTimerDesc *d = m_timers;
|
||||||
|
while ( d->next && d->next->shotTime < when ) d = d->next;
|
||||||
|
desc->next = d->next;
|
||||||
|
desc->prev = d;
|
||||||
|
if ( d->next )
|
||||||
|
d->next->prev = desc;
|
||||||
|
d->next = desc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_timers = desc;
|
||||||
|
desc->prev = desc->next = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTimerScheduler::RemoveTimer(wxTimerDesc *desc)
|
||||||
|
{
|
||||||
|
desc->running = FALSE;
|
||||||
|
if ( desc == m_timers )
|
||||||
|
m_timers = desc->next;
|
||||||
|
if ( desc->prev )
|
||||||
|
desc->prev->next = desc->next;
|
||||||
|
if ( desc->next )
|
||||||
|
desc->next->prev = desc->prev;
|
||||||
|
desc->prev = desc->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTimerScheduler::NotifyTimers()
|
||||||
|
{
|
||||||
|
if ( m_timers )
|
||||||
|
{
|
||||||
|
unsigned long now = _EVT_getTicks();
|
||||||
|
wxTimerDesc *desc;
|
||||||
|
|
||||||
|
while ( m_timers && m_timers->shotTime <= now )
|
||||||
|
{
|
||||||
|
desc = m_timers;
|
||||||
|
desc->timer->Notify();
|
||||||
|
RemoveTimer(desc);
|
||||||
|
if ( !desc->timer->IsOneShot() )
|
||||||
|
{
|
||||||
|
QueueTimer(desc, now + desc->timer->GetInterval());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxTimer
|
// wxTimer
|
||||||
@@ -21,4 +112,53 @@
|
|||||||
|
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
|
||||||
|
|
||||||
// FIXME_MGL
|
wxTimerScheduler *wxTimer::ms_scheduler = NULL;
|
||||||
|
size_t wxTimer::ms_timersCnt = 0;
|
||||||
|
|
||||||
|
void wxTimer::Init()
|
||||||
|
{
|
||||||
|
if ( ms_timersCnt++ == 0 )
|
||||||
|
ms_scheduler = new wxTimerScheduler;
|
||||||
|
m_desc = new wxTimerDesc(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxTimer::~wxTimer()
|
||||||
|
{
|
||||||
|
if ( IsRunning() )
|
||||||
|
Stop();
|
||||||
|
|
||||||
|
if ( --ms_timersCnt == 0 )
|
||||||
|
{
|
||||||
|
delete ms_scheduler;
|
||||||
|
ms_scheduler = NULL;
|
||||||
|
}
|
||||||
|
delete m_desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxTimer::IsRunning() const
|
||||||
|
{
|
||||||
|
return m_desc->running;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxTimer::Start(int millisecs, bool oneShot)
|
||||||
|
{
|
||||||
|
if ( !wxTimerBase::Start(millisecs, oneShot) )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
ms_scheduler->QueueTimer(m_desc);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTimer::Stop()
|
||||||
|
{
|
||||||
|
if ( !m_desc->running ) return;
|
||||||
|
|
||||||
|
ms_scheduler->RemoveTimer(m_desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*static*/ void wxTimer::NotifyTimers()
|
||||||
|
{
|
||||||
|
ms_scheduler->NotifyTimers();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //wxUSE_TIMER
|
||||||
|
Reference in New Issue
Block a user