wxAnimationCtrl cleanup

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett
2006-10-10 04:27:54 +00:00
parent 76319fbc38
commit c2f12218ce
8 changed files with 129 additions and 113 deletions

View File

@@ -34,8 +34,8 @@ It is only available if \texttt{wxUSE\_ANIMATIONCTRL} is set to $1$ (the default
\twocolwidtha{5cm}% \twocolwidtha{5cm}%
\begin{twocollist}\itemsep=0pt \begin{twocollist}\itemsep=0pt
\twocolitem{\windowstyle{wxAC\_DEFAULT\_STYLE}}{The default style: wxNO_BORDER.} \twocolitem{\windowstyle{wxAC\_DEFAULT\_STYLE}}{The default style: wxNO\_BORDER.}
\twocolitem{\windowstyle{wxAC\_NO_AUTORESIZE}}{By default, the control will adjust \twocolitem{\windowstyle{wxAC\_NO\_AUTORESIZE}}{By default, the control will adjust
its size to exactly fit to the size of the animation when \helpref{SetAnimation}{wxanimationctrlsetanimation} its size to exactly fit to the size of the animation when \helpref{SetAnimation}{wxanimationctrlsetanimation}
is called. If this style flag is given, the control will not change its size} is called. If this style flag is given, the control will not change its size}
\end{twocollist} \end{twocollist}

View File

@@ -68,7 +68,7 @@ data be deleted.
\membersection{wxAnimation::GetDelay}\label{wxanimationgetdelay} \membersection{wxAnimation::GetDelay}\label{wxanimationgetdelay}
\constfunc{int}{GetDelay}{\param{size_t }{i}} \constfunc{int}{GetDelay}{\param{size\_t }{i}}
Returns the delay for the i-th frame in milliseconds. Returns the delay for the i-th frame in milliseconds.
If {\tt -1} is returned the frame is to be displayed forever. If {\tt -1} is returned the frame is to be displayed forever.
@@ -76,14 +76,14 @@ If {\tt -1} is returned the frame is to be displayed forever.
\membersection{wxAnimation::GetFrameCount}\label{wxanimationgetframecount} \membersection{wxAnimation::GetFrameCount}\label{wxanimationgetframecount}
\constfunc{size_t}{GetFrameCount}{\void} \constfunc{size\_t}{GetFrameCount}{\void}
Returns the number of frames for this animation. Returns the number of frames for this animation.
\membersection{wxAnimation::GetFrame}\label{wxanimationgetframe} \membersection{wxAnimation::GetFrame}\label{wxanimationgetframe}
\constfunc{wxImage}{GetFrame}{\param{size_t }{i}} \constfunc{wxImage}{GetFrame}{\param{size\_t }{i}}
Returns the i-th frame as a \helpref{wxImage}{wximage}. Returns the i-th frame as a \helpref{wxImage}{wximage}.

View File

@@ -16,15 +16,9 @@
#if wxUSE_ANIMATIONCTRL #if wxUSE_ANIMATIONCTRL
#include <wx/defs.h> #include "wx/animdecod.h"
#include <wx/string.h> #include "wx/control.h"
#include <wx/gdicmn.h> #include "wx/timer.h"
#include <wx/list.h>
#include <wx/timer.h>
#include <wx/bitmap.h>
#include <wx/colour.h>
#include <wx/control.h>
#include <wx/animdecod.h>
class WXDLLIMPEXP_ADV wxAnimation; class WXDLLIMPEXP_ADV wxAnimation;

View File

@@ -14,9 +14,11 @@
#if wxUSE_STREAMS && wxUSE_GIF #if wxUSE_STREAMS && wxUSE_GIF
#include "wx/stream.h"
#include "wx/image.h"
#include "wx/colour.h" #include "wx/colour.h"
#include "wx/gdicmn.h"
class WXDLLIMPEXP_BASE wxInputStream;
class WXDLLIMPEXP_CORE wxImage;
/* /*

View File

@@ -12,23 +12,6 @@
#ifndef _WX_GENERIC_ANIMATEH__ #ifndef _WX_GENERIC_ANIMATEH__
#define _WX_GENERIC_ANIMATEH__ #define _WX_GENERIC_ANIMATEH__
#include <wx/defs.h>
#include <wx/string.h>
#include <wx/gdicmn.h>
#include <wx/list.h>
#include <wx/timer.h>
#include <wx/bitmap.h>
#include <wx/colour.h>
#include <wx/control.h>
#include <wx/animdecod.h>
class WXDLLIMPEXP_ADV wxAnimationBase;
class WXDLLIMPEXP_ADV wxAnimationPlayer;
class WXDLLEXPORT wxImage;
class WXDLLEXPORT wxGIFDecoder;
class WXDLLIMPEXP_ADV wxAnimation;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimation // wxAnimation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -38,17 +21,6 @@ WX_DECLARE_LIST(wxAnimationDecoder, wxAnimationDecoderList);
class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase
{ {
public: public:
wxAnimation(const wxAnimation &tocopy)
{ Ref(tocopy); }
wxAnimation() {}
~wxAnimation() { UnRef(); }
wxAnimation &operator= (const wxAnimation &tocopy)
{
Ref(tocopy);
return *this;
}
bool operator == (const wxAnimation& anim) const bool operator == (const wxAnimation& anim) const
{ return m_refData == anim.m_refData; } { return m_refData == anim.m_refData; }
bool operator != (const wxAnimation& anim) const bool operator != (const wxAnimation& anim) const
@@ -83,7 +55,6 @@ public:
static void CleanUpHandlers(); static void CleanUpHandlers();
static void InitStandardHandlers(); static void InitStandardHandlers();
protected:
DECLARE_DYNAMIC_CLASS(wxAnimation) DECLARE_DYNAMIC_CLASS(wxAnimation)
}; };
@@ -95,7 +66,7 @@ protected:
class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase
{ {
public: public:
wxAnimationCtrl() {} wxAnimationCtrl();
wxAnimationCtrl(wxWindow *parent, wxAnimationCtrl(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxAnimation& anim = wxNullAnimation, const wxAnimation& anim = wxNullAnimation,
@@ -182,6 +153,7 @@ protected:
// on the screen // on the screen
private: private:
typedef wxAnimationCtrlBase base_type;
DECLARE_DYNAMIC_CLASS(wxAnimationCtrl) DECLARE_DYNAMIC_CLASS(wxAnimationCtrl)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -12,8 +12,8 @@
#ifndef _WX_GTKANIMATEH__ #ifndef _WX_GTKANIMATEH__
#define _WX_GTKANIMATEH__ #define _WX_GTKANIMATEH__
#include "wx/defs.h" typedef struct _GdkPixbufAnimation GdkPixbufAnimation;
#include <gdk-pixbuf/gdk-pixbuf.h> typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimation // wxAnimation
@@ -27,19 +27,11 @@
class WXDLLEXPORT wxAnimation : public wxAnimationBase class WXDLLEXPORT wxAnimation : public wxAnimationBase
{ {
public: public:
wxAnimation(const wxAnimation &tocopy) wxAnimation(GdkPixbufAnimation *p = NULL) { m_pixbuf = p; }
{ m_pixbuf=tocopy.m_pixbuf; if (m_pixbuf) g_object_ref(m_pixbuf); } wxAnimation(const wxAnimation&);
wxAnimation(GdkPixbufAnimation *p = NULL) ~wxAnimation() { UnRef(); }
{ m_pixbuf=p; }
~wxAnimation()
{ UnRef(); }
wxAnimation &operator= (const wxAnimation &tocopy) wxAnimation& operator= (const wxAnimation&);
{
m_pixbuf=tocopy.m_pixbuf;
if (m_pixbuf) g_object_ref(m_pixbuf);
return *this;
}
bool operator == (const wxAnimation& anim) const bool operator == (const wxAnimation& anim) const
{ return m_pixbuf == anim.m_pixbuf; } { return m_pixbuf == anim.m_pixbuf; }
@@ -54,34 +46,24 @@ public:
virtual size_t GetFrameCount() const virtual size_t GetFrameCount() const
{ return 0; } { return 0; }
virtual wxImage GetFrame(size_t i) const virtual wxImage GetFrame(size_t i) const;
{ return wxNullImage; }
// we can retrieve the delay for a frame only after building // we can retrieve the delay for a frame only after building
// a GdkPixbufAnimationIter... // a GdkPixbufAnimationIter...
virtual int GetDelay(size_t i) const virtual int GetDelay(size_t i) const
{ return 0; } { return 0; }
virtual wxSize GetSize() const virtual wxSize GetSize() const;
{ return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf),
gdk_pixbuf_animation_get_height(m_pixbuf)); }
virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY); virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY);
virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY); virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY);
void UnRef() // Implementation
{
if (m_pixbuf)
g_object_unref(m_pixbuf);
m_pixbuf = NULL;
}
public: // used by GTK callbacks public: // used by GTK callbacks
GdkPixbufAnimation *GetPixbuf() const GdkPixbufAnimation *GetPixbuf() const
{ return m_pixbuf; } { return m_pixbuf; }
void SetPixbuf(GdkPixbufAnimation *p) void SetPixbuf(GdkPixbufAnimation* p);
{ m_pixbuf=p; if (m_pixbuf) g_object_ref(m_pixbuf); }
protected: protected:
GdkPixbufAnimation *m_pixbuf; GdkPixbufAnimation *m_pixbuf;
@@ -89,12 +71,14 @@ protected:
// used temporary by Load() // used temporary by Load()
//bool m_bLoadComplete; //bool m_bLoadComplete;
protected: private:
void UnRef();
typedef wxAnimationBase base_type;
DECLARE_DYNAMIC_CLASS(wxAnimation) DECLARE_DYNAMIC_CLASS(wxAnimation)
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimationCtrl // wxAnimationCtrl
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -105,7 +89,7 @@ protected:
class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase
{ {
public: public:
wxAnimationCtrl() {} wxAnimationCtrl();
wxAnimationCtrl(wxWindow *parent, wxAnimationCtrl(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxAnimation& anim = wxNullAnimation, const wxAnimation& anim = wxNullAnimation,
@@ -151,19 +135,8 @@ protected:
void FitToAnimation(); void FitToAnimation();
void ClearToBackgroundColour(); void ClearToBackgroundColour();
void ResetAnim() void ResetAnim();
{ void ResetIter();
if (m_anim)
g_object_unref(m_anim);
m_anim = NULL;
}
void ResetIter()
{
if (m_iter)
g_object_unref(m_iter);
m_iter = NULL;
}
protected: // internal vars protected: // internal vars
@@ -174,6 +147,7 @@ protected: // internal vars
bool m_bPlaying; bool m_bPlaying;
private: private:
typedef wxAnimationCtrlBase base_type;
DECLARE_DYNAMIC_CLASS(wxAnimationCtrl) DECLARE_DYNAMIC_CLASS(wxAnimationCtrl)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -15,28 +15,28 @@
#pragma hdrstop #pragma hdrstop
#endif //__BORLANDC__ #endif //__BORLANDC__
#if wxUSE_ANIMATIONCTRL #if wxUSE_ANIMATIONCTRL
#include "wx/log.h" #include "wx/animate.h"
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/image.h"
#include "wx/dcmemory.h"
#include "wx/dcclient.h"
#include "wx/module.h"
#endif
#include "wx/wfstream.h" #include "wx/wfstream.h"
#include "wx/image.h"
#include "wx/gifdecod.h" #include "wx/gifdecod.h"
#include "wx/anidecod.h" #include "wx/anidecod.h"
#include "wx/dcmemory.h"
#include "wx/dc.h"
#include "wx/dcclient.h"
#include "wx/animate.h"
#include "wx/animdecod.h"
#include "wx/listimpl.cpp"
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(wxAnimationDecoderList); WX_DEFINE_LIST(wxAnimationDecoderList);
wxAnimationDecoderList wxAnimation::sm_handlers; wxAnimationDecoderList wxAnimation::sm_handlers;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimation // wxAnimation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -244,8 +244,6 @@ public:
IMPLEMENT_DYNAMIC_CLASS(wxAnimationModule, wxModule) IMPLEMENT_DYNAMIC_CLASS(wxAnimationModule, wxModule)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimationCtrl // wxAnimationCtrl
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -257,6 +255,14 @@ BEGIN_EVENT_TABLE(wxAnimationCtrl, wxAnimationCtrlBase)
EVT_TIMER(wxID_ANY, wxAnimationCtrl::OnTimer) EVT_TIMER(wxID_ANY, wxAnimationCtrl::OnTimer)
END_EVENT_TABLE() END_EVENT_TABLE()
wxAnimationCtrl::wxAnimationCtrl()
{
m_currentFrame = 0;
m_looped = false;
m_isPlaying = false;
m_useWinBackgroundColour = false;
}
bool wxAnimationCtrl::Create(wxWindow *parent, wxWindowID id, bool wxAnimationCtrl::Create(wxWindow *parent, wxWindowID id,
const wxAnimation& animation, const wxPoint& pos, const wxAnimation& animation, const wxPoint& pos,
const wxSize& size, long style, const wxString& name) const wxSize& size, long style, const wxString& name)
@@ -268,7 +274,7 @@ bool wxAnimationCtrl::Create(wxWindow *parent, wxWindowID id,
m_useWinBackgroundColour = false; m_useWinBackgroundColour = false;
m_timer.SetOwner(this); m_timer.SetOwner(this);
if (!wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name)) if (!base_type::Create(parent, id, pos, size, style, wxDefaultValidator, name))
return false; return false;
// by default we get the same background colour of our parent // by default we get the same background colour of our parent

View File

@@ -9,20 +9,20 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#if wxUSE_ANIMATIONCTRL #if wxUSE_ANIMATIONCTRL
#include "wx/animate.h" #include "wx/animate.h"
#include "wx/log.h"
#ifndef WX_PRECOMP
#include "wx/image.h"
#include "wx/log.h"
#include "wx/stream.h"
#endif
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gtk/gtkimage.h>
// ============================================================================ // ============================================================================
@@ -51,6 +51,27 @@ void gdk_pixbuf_area_updated(GdkPixbufLoader *loader,
IMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase) IMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase)
wxAnimation::wxAnimation(const wxAnimation& that)
: base_type(that)
{
m_pixbuf = that.m_pixbuf;
if (m_pixbuf)
g_object_ref(m_pixbuf);
}
wxAnimation& wxAnimation::operator=(const wxAnimation& that)
{
if (this != &that)
{
base_type::operator=(that);
UnRef();
m_pixbuf = that.m_pixbuf;
if (m_pixbuf)
g_object_ref(m_pixbuf);
}
return *this;
}
bool wxAnimation::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type)) bool wxAnimation::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type))
{ {
UnRef(); UnRef();
@@ -75,6 +96,7 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type)
break; break;
default: default:
anim_type[0] = '\0';
break; break;
} }
@@ -100,7 +122,7 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type)
while (stream.IsOk()) while (stream.IsOk())
{ {
// read a chunk of data // read a chunk of data
stream.Read(buf, 2048); stream.Read(buf, sizeof(buf));
// fetch all data into the loader // fetch all data into the loader
if (!gdk_pixbuf_loader_write(loader, buf, stream.LastRead(), &error)) if (!gdk_pixbuf_loader_write(loader, buf, stream.LastRead(), &error))
@@ -123,6 +145,31 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type)
return true; return true;
} }
wxImage wxAnimation::GetFrame(size_t i) const
{
return wxNullImage;
}
wxSize wxAnimation::GetSize() const
{
return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf),
gdk_pixbuf_animation_get_height(m_pixbuf));
}
void wxAnimation::UnRef()
{
if (m_pixbuf)
g_object_unref(m_pixbuf);
m_pixbuf = NULL;
}
void wxAnimation::SetPixbuf(GdkPixbufAnimation* p)
{
UnRef();
m_pixbuf = p;
if (m_pixbuf)
g_object_ref(m_pixbuf);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxAnimationCtrl // wxAnimationCtrl
@@ -133,6 +180,13 @@ BEGIN_EVENT_TABLE(wxAnimationCtrl, wxAnimationCtrlBase)
EVT_TIMER(wxID_ANY, wxAnimationCtrl::OnTimer) EVT_TIMER(wxID_ANY, wxAnimationCtrl::OnTimer)
END_EVENT_TABLE() END_EVENT_TABLE()
wxAnimationCtrl::wxAnimationCtrl()
{
m_anim = NULL;
m_iter = NULL;
m_bPlaying = false;
}
bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id, bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id,
const wxAnimation& anim, const wxAnimation& anim,
const wxPoint& pos, const wxPoint& pos,
@@ -144,7 +198,7 @@ bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id,
m_acceptsFocus = true; m_acceptsFocus = true;
if (!PreCreation( parent, pos, size ) || if (!PreCreation( parent, pos, size ) ||
!wxControl::CreateBase(parent, id, pos, size, style & wxWINDOW_STYLE_MASK, !base_type::CreateBase(parent, id, pos, size, style & wxWINDOW_STYLE_MASK,
wxDefaultValidator, name)) wxDefaultValidator, name))
{ {
wxFAIL_MSG( wxT("wxAnimationCtrl creation failed") ); wxFAIL_MSG( wxT("wxAnimationCtrl creation failed") );
@@ -234,6 +288,20 @@ void wxAnimationCtrl::FitToAnimation()
SetSize(w, h); SetSize(w, h);
} }
void wxAnimationCtrl::ResetAnim()
{
if (m_anim)
g_object_unref(m_anim);
m_anim = NULL;
}
void wxAnimationCtrl::ResetIter()
{
if (m_iter)
g_object_unref(m_iter);
m_iter = NULL;
}
bool wxAnimationCtrl::Play() bool wxAnimationCtrl::Play()
{ {
if (m_anim == NULL) if (m_anim == NULL)