1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/animatecmn.cpp
3 // Purpose: wxAnimation and wxAnimationCtrl
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 // ----------------------------------------------------------------------------
14 // ----------------------------------------------------------------------------
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_ANIMATIONCTRL
25 #include "wx/animate.h"
26 #include "wx/bitmap.h"
30 #include "wx/dcmemory.h"
32 const char wxAnimationCtrlNameStr
[] = "animationctrl";
35 wxAnimation wxNullAnimation
;
37 IMPLEMENT_ABSTRACT_CLASS(wxAnimationBase
, wxObject
)
38 IMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase
, wxControl
)
41 // ----------------------------------------------------------------------------
42 // wxAnimationCtrlBase
43 // ----------------------------------------------------------------------------
45 void wxAnimationCtrlBase::UpdateStaticImage()
47 if (!m_bmpStaticReal
.IsOk() || !m_bmpStatic
.IsOk())
50 // if given bitmap is not of the right size, recreate m_bmpStaticReal accordingly
51 const wxSize
&sz
= GetClientSize();
52 if (sz
.GetWidth() != m_bmpStaticReal
.GetWidth() ||
53 sz
.GetHeight() != m_bmpStaticReal
.GetHeight())
55 if (!m_bmpStaticReal
.IsOk() ||
56 m_bmpStaticReal
.GetWidth() != sz
.GetWidth() ||
57 m_bmpStaticReal
.GetHeight() != sz
.GetHeight())
59 // need to (re)create m_bmpStaticReal
60 if (!m_bmpStaticReal
.Create(sz
.GetWidth(), sz
.GetHeight(),
61 m_bmpStatic
.GetDepth()))
63 wxLogDebug(wxT("Cannot create the static bitmap"));
64 m_bmpStatic
= wxNullBitmap
;
69 if (m_bmpStatic
.GetWidth() <= sz
.GetWidth() &&
70 m_bmpStatic
.GetHeight() <= sz
.GetHeight())
72 // clear the background of m_bmpStaticReal
73 wxBrush
brush(GetBackgroundColour());
75 dc
.SelectObject(m_bmpStaticReal
);
76 dc
.SetBackground(brush
);
79 // center the user-provided bitmap in m_bmpStaticReal
80 dc
.DrawBitmap(m_bmpStatic
,
81 (sz
.GetWidth()-m_bmpStatic
.GetWidth())/2,
82 (sz
.GetHeight()-m_bmpStatic
.GetHeight())/2,
83 true /* use mask */ );
87 // the user-provided bitmap is bigger than our control, strech it
88 wxImage
temp(m_bmpStatic
.ConvertToImage());
89 temp
.Rescale(sz
.GetWidth(), sz
.GetHeight(), wxIMAGE_QUALITY_HIGH
);
90 m_bmpStaticReal
= wxBitmap(temp
);
95 void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap
&bmp
)
98 m_bmpStaticReal
= bmp
;
100 // if not playing, update the control now
101 // NOTE: DisplayStaticImage() will call UpdateStaticImage automatically
103 DisplayStaticImage();
106 #endif // wxUSE_ANIMATIONCTRL