- fix wxAnimationCtrl::SetBackgroundColour both for generic and native GTK

version
- fix wxAnimationCtrl::GetAnimation for GTK version (modifying correctly the
  constructor which takes a GdkPixbufAnimation)
- fix the generic wxAnimationCtrl::SetAnimation() when it's used with a
  wxNullAnimation.
- moves the frame counter reset in Stop() as it's more sensed to always have
  m_currentFrame cleared immediately when the animation has been stopped
- fix a problem with transparent bitmaps drawing in wxAnimationCtrl::OnPaint

(part of patch 1598005)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-11-17 18:14:42 +00:00
parent 70fc30ae82
commit 1afdfc9deb
4 changed files with 69 additions and 12 deletions

View File

@@ -107,6 +107,9 @@ public:
void SetInactiveBitmap(const wxBitmap &bmp); void SetInactiveBitmap(const wxBitmap &bmp);
// override base class method
virtual bool SetBackgroundColour(const wxColour& col);
public: // event handlers public: // event handlers
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);

View File

@@ -27,7 +27,7 @@ typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter;
class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase
{ {
public: public:
wxAnimation(GdkPixbufAnimation *p = NULL) { m_pixbuf = p; } wxAnimation(GdkPixbufAnimation *p = NULL);
wxAnimation(const wxAnimation&); wxAnimation(const wxAnimation&);
~wxAnimation() { UnRef(); } ~wxAnimation() { UnRef(); }

View File

@@ -185,7 +185,6 @@ void wxAnimation::AddHandler( wxAnimationDecoder *handler )
// for preventing duplicate additions. If someone ever has // for preventing duplicate additions. If someone ever has
// a good reason to add and remove duplicate handlers (and they // a good reason to add and remove duplicate handlers (and they
// may) we should probably refcount the duplicates. // may) we should probably refcount the duplicates.
// also an issue in InsertHandler below.
wxLogDebug( _T("Adding duplicate animation handler for '%d' type"), wxLogDebug( _T("Adding duplicate animation handler for '%d' type"),
handler->GetType() ); handler->GetType() );
@@ -330,16 +329,19 @@ void wxAnimationCtrl::SetAnimation(const wxAnimation& animation)
if (IsPlaying()) if (IsPlaying())
Stop(); Stop();
// set new animation even if it's wxNullAnimation
m_animation = animation; m_animation = animation;
if (!m_animation.IsOk())
{
UpdateBackingStoreWithStaticImage();
return;
}
if (m_animation.GetBackgroundColour() == wxNullColour) if (m_animation.GetBackgroundColour() == wxNullColour)
SetUseWindowBackgroundColour(); SetUseWindowBackgroundColour();
if (!this->HasFlag(wxAC_NO_AUTORESIZE)) if (!this->HasFlag(wxAC_NO_AUTORESIZE))
FitToAnimation(); FitToAnimation();
// reset frame counter
m_currentFrame = 0;
UpdateBackingStoreWithStaticImage(); UpdateBackingStoreWithStaticImage();
} }
@@ -347,8 +349,16 @@ void wxAnimationCtrl::SetInactiveBitmap(const wxBitmap &bmp)
{ {
m_bmpStatic = 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 not playing, update the backing store now
if (!IsPlaying()) if ( !IsPlaying() )
UpdateBackingStoreWithStaticImage(); UpdateBackingStoreWithStaticImage();
} }
@@ -357,6 +367,19 @@ void wxAnimationCtrl::FitToAnimation()
SetSize(m_animation.GetSize()); 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() )
UpdateBackingStoreWithStaticImage();
return true;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimationCtrl - stop/play methods // wxAnimationCtrl - stop/play methods
@@ -367,6 +390,9 @@ void wxAnimationCtrl::Stop()
m_timer.Stop(); m_timer.Stop();
m_isPlaying = false; m_isPlaying = false;
// reset frame counter
m_currentFrame = 0;
UpdateBackingStoreWithStaticImage(); UpdateBackingStoreWithStaticImage();
} }
@@ -507,6 +533,15 @@ void wxAnimationCtrl::UpdateBackingStoreWithStaticImage()
if (m_bmpStatic.IsOk()) if (m_bmpStatic.IsOk())
{ {
// copy the inactive bitmap in the backing store // copy the inactive bitmap in the backing store
// eventually using the mask if the static bitmap has one
if ( m_bmpStatic.GetMask() )
{
wxMemoryDC temp;
temp.SelectObject(m_backingStore);
DisposeToBackground(temp);
temp.DrawBitmap(m_bmpStatic, 0, 0, true /* use mask */);
}
else
m_backingStore = m_bmpStatic; m_backingStore = m_bmpStatic;
} }
else else
@@ -557,6 +592,7 @@ void wxAnimationCtrl::DisposeToBackground(wxDC& dc)
wxColour col = IsUsingWindowBackgroundColour() wxColour col = IsUsingWindowBackgroundColour()
? GetBackgroundColour() ? GetBackgroundColour()
: m_animation.GetBackgroundColour(); : m_animation.GetBackgroundColour();
wxBrush brush(col); wxBrush brush(col);
dc.SetBackground(brush); dc.SetBackground(brush);
dc.Clear(); dc.Clear();
@@ -583,7 +619,12 @@ void wxAnimationCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
wxPaintDC dc(this); wxPaintDC dc(this);
if ( m_backingStore.IsOk() ) 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 else
{ {
// m_animation is not valid and thus we don't have a valid backing store... // m_animation is not valid and thus we don't have a valid backing store...

View File

@@ -59,6 +59,13 @@ wxAnimation::wxAnimation(const wxAnimation& that)
g_object_ref(m_pixbuf); g_object_ref(m_pixbuf);
} }
wxAnimation::wxAnimation(GdkPixbufAnimation *p)
{
m_pixbuf = p;
if ( m_pixbuf )
g_object_ref(m_pixbuf);
}
wxAnimation& wxAnimation::operator=(const wxAnimation& that) wxAnimation& wxAnimation::operator=(const wxAnimation& that)
{ {
if (this != &that) if (this != &that)
@@ -408,7 +415,13 @@ bool wxAnimationCtrl::SetBackgroundColour( const wxColour &colour )
// Thus we clear the GtkImage contents to the background colour... // Thus we clear the GtkImage contents to the background colour...
if (!wxControl::SetBackgroundColour(colour)) if (!wxControl::SetBackgroundColour(colour))
return false; return false;
ClearToBackgroundColour();
// if not playing the change must take place immediately but
// remember that the inactive bitmap has higher priority over the background
// colour; DisplayStaticImage() will handle that
if ( !IsPlaying() )
DisplayStaticImage();
return true; return true;
} }