]>
Commit | Line | Data |
---|---|---|
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 | // Copyright: (c) Francesco Montorsi | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | ||
12 | // ---------------------------------------------------------------------------- | |
13 | // headers | |
14 | // ---------------------------------------------------------------------------- | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #if wxUSE_ANIMATIONCTRL | |
24 | ||
25 | #include "wx/animate.h" | |
26 | #include "wx/bitmap.h" | |
27 | #include "wx/log.h" | |
28 | #include "wx/brush.h" | |
29 | #include "wx/image.h" | |
30 | #include "wx/dcmemory.h" | |
31 | ||
32 | const char wxAnimationCtrlNameStr[] = "animationctrl"; | |
33 | ||
34 | // global object | |
35 | wxAnimation wxNullAnimation; | |
36 | ||
37 | IMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject) | |
38 | IMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl) | |
39 | ||
40 | ||
41 | // ---------------------------------------------------------------------------- | |
42 | // wxAnimationCtrlBase | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | void wxAnimationCtrlBase::UpdateStaticImage() | |
46 | { | |
47 | if (!m_bmpStaticReal.IsOk() || !m_bmpStatic.IsOk()) | |
48 | return; | |
49 | ||
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()) | |
54 | { | |
55 | if (!m_bmpStaticReal.IsOk() || | |
56 | m_bmpStaticReal.GetWidth() != sz.GetWidth() || | |
57 | m_bmpStaticReal.GetHeight() != sz.GetHeight()) | |
58 | { | |
59 | // need to (re)create m_bmpStaticReal | |
60 | if (!m_bmpStaticReal.Create(sz.GetWidth(), sz.GetHeight(), | |
61 | m_bmpStatic.GetDepth())) | |
62 | { | |
63 | wxLogDebug(wxT("Cannot create the static bitmap")); | |
64 | m_bmpStatic = wxNullBitmap; | |
65 | return; | |
66 | } | |
67 | } | |
68 | ||
69 | if (m_bmpStatic.GetWidth() <= sz.GetWidth() && | |
70 | m_bmpStatic.GetHeight() <= sz.GetHeight()) | |
71 | { | |
72 | // clear the background of m_bmpStaticReal | |
73 | wxBrush brush(GetBackgroundColour()); | |
74 | wxMemoryDC dc; | |
75 | dc.SelectObject(m_bmpStaticReal); | |
76 | dc.SetBackground(brush); | |
77 | dc.Clear(); | |
78 | ||
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 */ ); | |
84 | } | |
85 | else | |
86 | { | |
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); | |
91 | } | |
92 | } | |
93 | } | |
94 | ||
95 | void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap &bmp) | |
96 | { | |
97 | m_bmpStatic = bmp; | |
98 | m_bmpStaticReal = bmp; | |
99 | ||
100 | // if not playing, update the control now | |
101 | // NOTE: DisplayStaticImage() will call UpdateStaticImage automatically | |
102 | if ( !IsPlaying() ) | |
103 | DisplayStaticImage(); | |
104 | } | |
105 | ||
106 | #endif // wxUSE_ANIMATIONCTRL |