]> git.saurik.com Git - wxWidgets.git/blob - src/common/animatecmn.cpp
adding implementation for osx
[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 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #if wxUSE_ANIMATIONCTRL
25
26 #include "wx/animate.h"
27 #include "wx/bitmap.h"
28 #include "wx/log.h"
29 #include "wx/brush.h"
30 #include "wx/image.h"
31 #include "wx/dcmemory.h"
32
33 const char wxAnimationCtrlNameStr[] = "animationctrl";
34
35 // global object
36 wxAnimation wxNullAnimation;
37
38 IMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject)
39 IMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl)
40
41
42 // ----------------------------------------------------------------------------
43 // wxAnimationCtrlBase
44 // ----------------------------------------------------------------------------
45
46 void wxAnimationCtrlBase::UpdateStaticImage()
47 {
48 if (!m_bmpStaticReal.IsOk() || !m_bmpStatic.IsOk())
49 return;
50
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())
55 {
56 if (!m_bmpStaticReal.IsOk() ||
57 m_bmpStaticReal.GetWidth() != sz.GetWidth() ||
58 m_bmpStaticReal.GetHeight() != sz.GetHeight())
59 {
60 // need to (re)create m_bmpStaticReal
61 if (!m_bmpStaticReal.Create(sz.GetWidth(), sz.GetHeight(),
62 m_bmpStatic.GetDepth()))
63 {
64 wxLogDebug(wxT("Cannot create the static bitmap"));
65 m_bmpStatic = wxNullBitmap;
66 return;
67 }
68 }
69
70 if (m_bmpStatic.GetWidth() <= sz.GetWidth() &&
71 m_bmpStatic.GetHeight() <= sz.GetHeight())
72 {
73 // clear the background of m_bmpStaticReal
74 wxBrush brush(GetBackgroundColour());
75 wxMemoryDC dc;
76 dc.SelectObject(m_bmpStaticReal);
77 dc.SetBackground(brush);
78 dc.Clear();
79
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 */ );
85 }
86 else
87 {
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);
92 }
93 }
94 }
95
96 void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap &bmp)
97 {
98 m_bmpStatic = bmp;
99 m_bmpStaticReal = bmp;
100
101 // if not playing, update the control now
102 // NOTE: DisplayStaticImage() will call UpdateStaticImage automatically
103 if ( !IsPlaying() )
104 DisplayStaticImage();
105 }
106
107 #endif // wxUSE_ANIMATIONCTRL