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") );
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") );
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 );
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);
// for preventing duplicate additions. If someone ever has
// a good reason to add and remove duplicate handlers (and they
// may) we should probably refcount the duplicates.
- // also an issue in InsertHandler below.
wxLogDebug( _T("Adding duplicate animation handler for '%d' type"),
handler->GetType() );
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)
const wxAnimation& animation, const wxPoint& pos,
const wxSize& size, long style, const wxString& name)
{
- m_animation = animation;
m_timer.SetOwner(this);
if (!base_type::Create(parent, id, pos, size, style, wxDefaultValidator, name))
// by default we get the same background colour of our parent
SetBackgroundColour(parent->GetBackgroundColour());
+
+ SetAnimation(animation);
+
return true;
}
if (IsPlaying())
Stop();
+ // set new animation even if it's wxNullAnimation
m_animation = animation;
+ if (!m_animation.IsOk())
+ {
+ DisplayStaticImage();
+ return;
+ }
if (m_animation.GetBackgroundColour() == wxNullColour)
SetUseWindowBackgroundColour();
if (!this->HasFlag(wxAC_NO_AUTORESIZE))
FitToAnimation();
- // reset frame counter
- m_currentFrame = 0;
-
- 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
+ // transparent areas - and that's not what we want (at least for
+ // consistency with the GTK version)
+ 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()
SetSize(m_animation.GetSize());
}
+bool wxAnimationCtrl::SetBackgroundColour(const wxColour& colour)
+{
+ if ( !wxWindow::SetBackgroundColour(colour) )
+ return false;
+
+ // 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() )
+ DisplayStaticImage();
+
+ return true;
+}
+
// ----------------------------------------------------------------------------
// wxAnimationCtrl - stop/play methods
m_timer.Stop();
m_isPlaying = false;
- UpdateBackingStoreWithStaticImage();
+ // reset frame counter
+ m_currentFrame = 0;
+
+ DisplayStaticImage();
}
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
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)
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
- m_backingStore = m_bmpStatic;
+ // eventually using the mask if the static bitmap has one
+ if ( m_bmpStaticReal.GetMask() )
+ {
+ wxMemoryDC temp;
+ temp.SelectObject(m_backingStore);
+ DisposeToBackground(temp);
+ temp.DrawBitmap(m_bmpStaticReal, 0, 0, true /* use mask */);
+ }
+ else
+ m_backingStore = m_bmpStaticReal;
}
else
{
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
// 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();
+
wxBrush brush(col);
dc.SetBackground(brush);
dc.Clear();
wxPaintDC dc(this);
if ( m_backingStore.IsOk() )
- DrawCurrentFrame(dc);
+ {
+ // NOTE: we draw the bitmap explicitely 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 */);
+ }
else
{
// m_animation is not valid and thus we don't have a valid backing store...
// with the last played frame is wrong in this case
if (IsPlaying())
{
- if (!RebuildBackingStoreUpToFrame(m_currentFrame))
- Stop(); // in case we are playing
+ if (!RebuildBackingStoreUpToFrame(m_currentFrame))
+ Stop(); // in case we are playing
}
}
}