1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/animatecmn.cpp
3 // Purpose: wxAnimation and wxAnimationCtrl
4 // Author: Francesco Montorsi
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
24 #if wxUSE_ANIMATIONCTRL
26 #include "wx/animate.h"
27 #include "wx/bitmap.h"
31 #include "wx/dcmemory.h"
33 const char wxAnimationCtrlNameStr
[] = "animationctrl";
36 wxAnimation wxNullAnimation
;
38 IMPLEMENT_ABSTRACT_CLASS(wxAnimationBase
, wxObject
)
39 IMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase
, wxControl
)
42 // ----------------------------------------------------------------------------
43 // wxAnimationCtrlBase
44 // ----------------------------------------------------------------------------
46 void wxAnimationCtrlBase::UpdateStaticImage()
48 if (!m_bmpStaticReal
.IsOk() || !m_bmpStatic
.IsOk())
51 // if given bitmap is not of the right size, recreate m_bmpStaticReal accordingly
52 const wxSize
&sz
= GetClientSize();
53 if (sz
.GetWidth() != m_bmpStaticReal
.GetWidth() ||
54 sz
.GetHeight() != m_bmpStaticReal
.GetHeight())
56 if (!m_bmpStaticReal
.IsOk() ||
57 m_bmpStaticReal
.GetWidth() != sz
.GetWidth() ||
58 m_bmpStaticReal
.GetHeight() != sz
.GetHeight())
60 // need to (re)create m_bmpStaticReal
61 if (!m_bmpStaticReal
.Create(sz
.GetWidth(), sz
.GetHeight(),
62 m_bmpStatic
.GetDepth()))
64 wxLogDebug(wxT("Cannot create the static bitmap"));
65 m_bmpStatic
= wxNullBitmap
;
70 if (m_bmpStatic
.GetWidth() <= sz
.GetWidth() &&
71 m_bmpStatic
.GetHeight() <= sz
.GetHeight())
73 // clear the background of m_bmpStaticReal
74 wxBrush
brush(GetBackgroundColour());
76 dc
.SelectObject(m_bmpStaticReal
);
77 dc
.SetBackground(brush
);
80 // center the user-provided bitmap in m_bmpStaticReal
81 dc
.DrawBitmap(m_bmpStatic
,
82 (sz
.GetWidth()-m_bmpStatic
.GetWidth())/2,
83 (sz
.GetHeight()-m_bmpStatic
.GetHeight())/2,
84 true /* use mask */ );
88 // the user-provided bitmap is bigger than our control, strech it
89 wxImage
temp(m_bmpStatic
.ConvertToImage());
90 temp
.Rescale(sz
.GetWidth(), sz
.GetHeight(), wxIMAGE_QUALITY_HIGH
);
91 m_bmpStaticReal
= wxBitmap(temp
);
96 void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap
&bmp
)
99 m_bmpStaticReal
= bmp
;
101 // if not playing, update the control now
102 // NOTE: DisplayStaticImage() will call UpdateStaticImage automatically
104 DisplayStaticImage();
107 #endif // wxUSE_ANIMATIONCTRL