X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1afdfc9debf357b7d53ce60c97bfa64c983cfa64..4b263e5ef358411a345dee9ffef3ba69c19be40e:/src/generic/animateg.cpp diff --git a/src/generic/animateg.cpp b/src/generic/animateg.cpp index 2794e1a08f..f267c21cdb 100644 --- a/src/generic/animateg.cpp +++ b/src/generic/animateg.cpp @@ -1,10 +1,9 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: animateg.cpp +// Name: src/generic/animateg.cpp // Purpose: wxAnimation and wxAnimationCtrl // Author: Julian Smart and Guillermo Rodriguez Garcia // Modified by: Francesco Montorsi // Created: 13/8/99 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -15,7 +14,7 @@ #pragma hdrstop #endif //__BORLANDC__ -#if wxUSE_ANIMATIONCTRL && (!defined(__WXGTK20__) || defined(__WXUNIVERSAL__)) +#if wxUSE_ANIMATIONCTRL #include "wx/animate.h" @@ -42,7 +41,7 @@ wxAnimationDecoderList wxAnimation::sm_handlers; // ---------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase) -#define M_ANIMDATA wx_static_cast(wxAnimationDecoder*, m_refData) +#define M_ANIMDATA static_cast(m_refData) wxSize wxAnimation::GetSize() const { @@ -51,14 +50,14 @@ wxSize wxAnimation::GetSize() const return M_ANIMDATA->GetAnimationSize(); } -size_t wxAnimation::GetFrameCount() const +unsigned int wxAnimation::GetFrameCount() const { wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); return M_ANIMDATA->GetFrameCount(); } -wxImage wxAnimation::GetFrame(size_t i) const +wxImage wxAnimation::GetFrame(unsigned int i) const { wxCHECK_MSG( IsOk(), wxNullImage, wxT("invalid animation") ); @@ -68,35 +67,35 @@ wxImage wxAnimation::GetFrame(size_t i) const return ret; } -int wxAnimation::GetDelay(size_t i) const +int wxAnimation::GetDelay(unsigned int i) const { wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); return M_ANIMDATA->GetDelay(i); } -wxPoint wxAnimation::GetFramePosition(size_t frame) const +wxPoint wxAnimation::GetFramePosition(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxDefaultPosition, wxT("invalid animation") ); return M_ANIMDATA->GetFramePosition(frame); } -wxSize wxAnimation::GetFrameSize(size_t frame) const +wxSize wxAnimation::GetFrameSize(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); return M_ANIMDATA->GetFrameSize(frame); } -wxAnimationDisposal wxAnimation::GetDisposalMethod(size_t frame) const +wxAnimationDisposal wxAnimation::GetDisposalMethod(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxANIM_UNSPECIFIED, wxT("invalid animation") ); return M_ANIMDATA->GetDisposalMethod(frame); } -wxColour wxAnimation::GetTransparentColour(size_t frame) const +wxColour wxAnimation::GetTransparentColour(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); @@ -138,7 +137,6 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type) m_refData = handler->Clone(); return M_ANIMDATA->Load(stream); } - } wxLogWarning( _("No handler found for animation type.") ); @@ -147,10 +145,6 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type) handler = FindHandler(type); - // do a copy of the handler from the static list which we will own - // as our reference data - m_refData = handler->Clone(); - if (handler == NULL) { wxLogWarning( _("No animation handler for type %ld defined."), type ); @@ -158,6 +152,11 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type) return false; } + + // do a copy of the handler from the static list which we will own + // as our reference data + m_refData = handler->Clone(); + if (stream.IsSeekable() && !M_ANIMDATA->CanRead(stream)) { wxLogError(_("Animation file is not of type %ld."), type); @@ -186,7 +185,7 @@ void wxAnimation::AddHandler( wxAnimationDecoder *handler ) // a good reason to add and remove duplicate handlers (and they // may) we should probably refcount the duplicates. - wxLogDebug( _T("Adding duplicate animation handler for '%d' type"), + wxLogDebug( wxT("Adding duplicate animation handler for '%d' type"), handler->GetType() ); delete handler; } @@ -202,7 +201,7 @@ void wxAnimation::InsertHandler( wxAnimationDecoder *handler ) else { // see AddHandler for additional comments. - wxLogDebug( _T("Inserting duplicate animation handler for '%d' type"), + wxLogDebug( wxT("Inserting duplicate animation handler for '%d' type"), handler->GetType() ); delete handler; } @@ -254,8 +253,8 @@ class wxAnimationModule: public wxModule DECLARE_DYNAMIC_CLASS(wxAnimationModule) public: wxAnimationModule() {} - bool OnInit() { wxAnimation::InitStandardHandlers(); return true; }; - void OnExit() { wxAnimation::CleanUpHandlers(); }; + bool OnInit() { wxAnimation::InitStandardHandlers(); return true; } + void OnExit() { wxAnimation::CleanUpHandlers(); } }; IMPLEMENT_DYNAMIC_CLASS(wxAnimationModule, wxModule) @@ -306,10 +305,17 @@ wxAnimationCtrl::~wxAnimationCtrl() } bool wxAnimationCtrl::LoadFile(const wxString& filename, wxAnimationType type) +{ + wxFileInputStream fis(filename); + if (!fis.IsOk()) + return false; + return Load(fis, type); +} + +bool wxAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type) { wxAnimation anim; - if (!anim.LoadFile(filename, type) || - !anim.IsOk()) + if ( !anim.Load(stream, type) || !anim.IsOk() ) return false; SetAnimation(anim); @@ -333,7 +339,7 @@ void wxAnimationCtrl::SetAnimation(const wxAnimation& animation) m_animation = animation; if (!m_animation.IsOk()) { - UpdateBackingStoreWithStaticImage(); + DisplayStaticImage(); return; } @@ -342,13 +348,11 @@ void wxAnimationCtrl::SetAnimation(const wxAnimation& animation) if (!this->HasFlag(wxAC_NO_AUTORESIZE)) FitToAnimation(); - UpdateBackingStoreWithStaticImage(); + DisplayStaticImage(); } void wxAnimationCtrl::SetInactiveBitmap(const wxBitmap &bmp) { - m_bmpStatic = bmp; - // if the bitmap has an associated mask, we need to set our background to // the colour of our parent otherwise when calling DrawCurrentFrame() // (which uses the bitmap's mask), our background colour would be used for @@ -357,9 +361,7 @@ void wxAnimationCtrl::SetInactiveBitmap(const wxBitmap &bmp) if ( bmp.GetMask() != NULL && GetParent() != NULL ) SetBackgroundColour(GetParent()->GetBackgroundColour()); - // if not playing, update the backing store now - if ( !IsPlaying() ) - UpdateBackingStoreWithStaticImage(); + wxAnimationCtrlBase::SetInactiveBitmap(bmp); } void wxAnimationCtrl::FitToAnimation() @@ -375,7 +377,7 @@ bool wxAnimationCtrl::SetBackgroundColour(const wxColour& colour) // if not playing, then this change must be seen immediately (unless // there's an inactive bitmap set which has higher priority than bg colour) if ( !IsPlaying() ) - UpdateBackingStoreWithStaticImage(); + DisplayStaticImage(); return true; } @@ -393,7 +395,7 @@ void wxAnimationCtrl::Stop() // reset frame counter m_currentFrame = 0; - UpdateBackingStoreWithStaticImage(); + DisplayStaticImage(); } bool wxAnimationCtrl::Play(bool looped) @@ -421,7 +423,7 @@ bool wxAnimationCtrl::Play(bool looped) int delay = m_animation.GetDelay(0); if (delay == 0) delay = 1; // 0 is invalid timeout for wxTimer. - m_timer.Start(delay); + m_timer.Start(delay, true); return true; } @@ -432,7 +434,7 @@ bool wxAnimationCtrl::Play(bool looped) // wxAnimationCtrl - rendering methods // ---------------------------------------------------------------------------- -bool wxAnimationCtrl::RebuildBackingStoreUpToFrame(size_t frame) +bool wxAnimationCtrl::RebuildBackingStoreUpToFrame(unsigned int frame) { // if we've not created the backing store yet or it's too // small, then recreate it @@ -455,7 +457,7 @@ bool wxAnimationCtrl::RebuildBackingStoreUpToFrame(size_t frame) DisposeToBackground(dc); // Draw all intermediate frames that haven't been removed from the animation - for (size_t i = 0; i < frame; i++) + for (unsigned int i = 0; i < frame; i++) { if (m_animation.GetDisposalMethod(i) == wxANIM_DONOTREMOVE || m_animation.GetDisposalMethod(i) == wxANIM_UNSPECIFIED) @@ -501,7 +503,7 @@ void wxAnimationCtrl::IncrementalUpdateBackingStore() case wxANIM_TOPREVIOUS: // this disposal should never be used too often. - // E.g. GIF specification explicitely say to keep the usage of this + // E.g. GIF specification explicitly say to keep the usage of this // disposal limited to the minimum. // In fact it may require a lot of time to restore if (m_currentFrame == 1) @@ -526,23 +528,26 @@ void wxAnimationCtrl::IncrementalUpdateBackingStore() dc.SelectObject(wxNullBitmap); } -void wxAnimationCtrl::UpdateBackingStoreWithStaticImage() +void wxAnimationCtrl::DisplayStaticImage() { wxASSERT(!IsPlaying()); - if (m_bmpStatic.IsOk()) + // m_bmpStaticReal will be updated only if necessary... + UpdateStaticImage(); + + if (m_bmpStaticReal.IsOk()) { // copy the inactive bitmap in the backing store // eventually using the mask if the static bitmap has one - if ( m_bmpStatic.GetMask() ) + if ( m_bmpStaticReal.GetMask() ) { wxMemoryDC temp; temp.SelectObject(m_backingStore); DisposeToBackground(temp); - temp.DrawBitmap(m_bmpStatic, 0, 0, true /* use mask */); + temp.DrawBitmap(m_bmpStaticReal, 0, 0, true /* use mask */); } else - m_backingStore = m_bmpStatic; + m_backingStore = m_bmpStaticReal; } else { @@ -558,7 +563,7 @@ void wxAnimationCtrl::UpdateBackingStoreWithStaticImage() Refresh(); } -void wxAnimationCtrl::DrawFrame(wxDC &dc, size_t frame) +void wxAnimationCtrl::DrawFrame(wxDC &dc, unsigned int frame) { // PERFORMANCE NOTE: // this draw stuff is not as fast as possible: the wxAnimationDecoder @@ -584,11 +589,12 @@ void wxAnimationCtrl::DisposeToBackground() // clear the backing store wxMemoryDC dc; dc.SelectObject(m_backingStore); - DisposeToBackground(dc); + if ( dc.IsOk() ) + DisposeToBackground(dc); } void wxAnimationCtrl::DisposeToBackground(wxDC& dc) -{ +{ wxColour col = IsUsingWindowBackgroundColour() ? GetBackgroundColour() : m_animation.GetBackgroundColour(); @@ -620,8 +626,8 @@ void wxAnimationCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) if ( m_backingStore.IsOk() ) { - // NOTE: we draw the bitmap explicitely ignoring the mask (if any); - // i.e. we don't want to combine the backing store with the + // NOTE: we draw the bitmap explicitly ignoring the mask (if any); + // i.e. we don't want to combine the backing store with the // possibly wrong preexisting contents of the window! dc.DrawBitmap(m_backingStore, 0, 0, false /* no mask */); } @@ -662,7 +668,7 @@ void wxAnimationCtrl::OnTimer(wxTimerEvent &WXUNUSED(event)) int delay = m_animation.GetDelay(m_currentFrame); if (delay == 0) delay = 1; // 0 is invalid timeout for wxTimer. - m_timer.Start(delay); + m_timer.Start(delay, true); } void wxAnimationCtrl::OnSize(wxSizeEvent &WXUNUSED(event)) @@ -674,9 +680,9 @@ void wxAnimationCtrl::OnSize(wxSizeEvent &WXUNUSED(event)) // when using them inside sizers. if (m_animation.IsOk()) { - // be careful to change the backing store *only* if we are - // playing the animation as otherwise we may be displaying - // the inactive bitmap and overwriting the backing store + // be careful to change the backing store *only* if we are + // playing the animation as otherwise we may be displaying + // the inactive bitmap and overwriting the backing store // with the last played frame is wrong in this case if (IsPlaying()) { @@ -686,5 +692,5 @@ void wxAnimationCtrl::OnSize(wxSizeEvent &WXUNUSED(event)) } } -#endif // wxUSE_ANIMATIONCTRL +#endif // wxUSE_ANIMATIONCTRL