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"
20 #if wxUSE_ANIMATIONCTRL
22 #include "wx/animate.h"
23 #include "wx/bitmap.h"
27 #include "wx/dcmemory.h"
29 const wxChar wxAnimationCtrlNameStr
[] = wxT("animationctrl");
32 wxAnimation wxNullAnimation
;
34 IMPLEMENT_ABSTRACT_CLASS(wxAnimationBase
, wxObject
)
35 IMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase
, wxControl
)
38 // ----------------------------------------------------------------------------
39 // wxAnimationCtrlBase
40 // ----------------------------------------------------------------------------
42 void wxAnimationCtrlBase::UpdateStaticImage()
44 if (!m_bmpStaticReal
.IsOk() || !m_bmpStatic
.IsOk())
47 // if given bitmap is not of the right size, recreate m_bmpStaticReal accordingly
48 const wxSize
&sz
= GetClientSize();
49 if (sz
.GetWidth() != m_bmpStaticReal
.GetWidth() ||
50 sz
.GetHeight() != m_bmpStaticReal
.GetHeight())
52 if (!m_bmpStaticReal
.IsOk() ||
53 m_bmpStaticReal
.GetWidth() != sz
.GetWidth() ||
54 m_bmpStaticReal
.GetHeight() != sz
.GetHeight())
56 // need to (re)create m_bmpStaticReal
57 if (!m_bmpStaticReal
.Create(sz
.GetWidth(), sz
.GetHeight(),
58 m_bmpStatic
.GetDepth()))
60 wxLogDebug(wxT("Cannot create the static bitmap"));
61 m_bmpStatic
= wxNullBitmap
;
66 if (m_bmpStatic
.GetWidth() <= sz
.GetWidth() &&
67 m_bmpStatic
.GetHeight() <= sz
.GetHeight())
69 // clear the background of m_bmpStaticReal
70 wxBrush
brush(GetBackgroundColour());
72 dc
.SelectObject(m_bmpStaticReal
);
73 dc
.SetBackground(brush
);
76 // center the user-provided bitmap in m_bmpStaticReal
77 dc
.DrawBitmap(m_bmpStatic
,
78 (sz
.GetWidth()-m_bmpStatic
.GetWidth())/2,
79 (sz
.GetHeight()-m_bmpStatic
.GetHeight())/2,
80 true /* use mask */ );
84 // the user-provided bitmap is bigger than our control, strech it
85 wxImage
temp(m_bmpStatic
.ConvertToImage());
86 temp
.Rescale(sz
.GetWidth(), sz
.GetHeight(), wxIMAGE_QUALITY_HIGH
);
87 m_bmpStaticReal
= wxBitmap(temp
);
92 void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap
&bmp
)
95 m_bmpStaticReal
= bmp
;
97 // if not playing, update the control now
98 // NOTE: DisplayStaticImage() will call UpdateStaticImage automatically
100 DisplayStaticImage();
103 #endif // wxUSE_ANIMATIONCTRL