]> git.saurik.com Git - wxWidgets.git/blob - src/common/animatecmn.cpp
added missing wxUSE_RICHEDIT test
[wxWidgets.git] / src / common / animatecmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/animatecmn.cpp
3 // Purpose: wxAnimation and wxAnimationCtrl
4 // Author: Francesco Montorsi
5 // Modified By:
6 // Created: 24/09/2006
7 // Id: $Id$
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 // ----------------------------------------------------------------------------
14 // headers
15 // ----------------------------------------------------------------------------
16
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
19
20 #if wxUSE_ANIMATIONCTRL
21
22 #include "wx/animate.h"
23 #include "wx/bitmap.h"
24 #include "wx/log.h"
25 #include "wx/brush.h"
26 #include "wx/image.h"
27 #include "wx/dcmemory.h"
28
29 const wxChar wxAnimationCtrlNameStr[] = wxT("animationctrl");
30
31 // global object
32 wxAnimation wxNullAnimation;
33
34 IMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject)
35 IMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl)
36
37
38 // ----------------------------------------------------------------------------
39 // wxAnimationCtrlBase
40 // ----------------------------------------------------------------------------
41
42 void wxAnimationCtrlBase::UpdateStaticImage()
43 {
44 if (!m_bmpStaticReal.IsOk() || !m_bmpStatic.IsOk())
45 return;
46
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())
51 {
52 if (!m_bmpStaticReal.IsOk() ||
53 m_bmpStaticReal.GetWidth() != sz.GetWidth() ||
54 m_bmpStaticReal.GetHeight() != sz.GetHeight())
55 {
56 // need to (re)create m_bmpStaticReal
57 if (!m_bmpStaticReal.Create(sz.GetWidth(), sz.GetHeight(),
58 m_bmpStatic.GetDepth()))
59 {
60 wxLogDebug(wxT("Cannot create the static bitmap"));
61 m_bmpStatic = wxNullBitmap;
62 return;
63 }
64 }
65
66 if (m_bmpStatic.GetWidth() <= sz.GetWidth() &&
67 m_bmpStatic.GetHeight() <= sz.GetHeight())
68 {
69 // clear the background of m_bmpStaticReal
70 wxBrush brush(GetBackgroundColour());
71 wxMemoryDC dc;
72 dc.SelectObject(m_bmpStaticReal);
73 dc.SetBackground(brush);
74 dc.Clear();
75
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 */ );
81 }
82 else
83 {
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);
88 }
89 }
90 }
91
92 void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap &bmp)
93 {
94 m_bmpStatic = bmp;
95 m_bmpStaticReal = bmp;
96
97 // if not playing, update the control now
98 // NOTE: DisplayStaticImage() will call UpdateStaticImage automatically
99 if ( !IsPlaying() )
100 DisplayStaticImage();
101 }
102
103 #endif // wxUSE_ANIMATIONCTRL