]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/animate/anitest.cpp
distrib changes to enable graphics context and add gdiplus.dll
[wxWidgets.git] / contrib / samples / animate / anitest.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: anitest.cpp
3 // Purpose: Animation sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 02/07/2001
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/wx.h"
29 #endif
30
31 #ifndef __WXMSW__
32 #include "mondrian.xpm"
33 #endif
34
35 #include "anitest.h"
36
37 IMPLEMENT_APP(MyApp)
38
39 // ---------------------------------------------------------------------------
40 // global variables
41 // ---------------------------------------------------------------------------
42
43 // ---------------------------------------------------------------------------
44 // event tables
45 // ---------------------------------------------------------------------------
46
47 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
48 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
49 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
50 #if wxUSE_FILEDLG
51 EVT_MENU(wxID_OPEN, MyFrame::OnOpen)
52 #endif // wxUSE_FILEDLG
53
54 EVT_SIZE(MyFrame::OnSize)
55 END_EVENT_TABLE()
56
57 // ===========================================================================
58 // implementation
59 // ===========================================================================
60
61 // ---------------------------------------------------------------------------
62 // MyApp
63 // ---------------------------------------------------------------------------
64
65 // Initialise this in OnInit, not statically
66 bool MyApp::OnInit()
67 {
68 // Create the main frame window
69
70 MyFrame* frame = new MyFrame((wxFrame *)NULL, -1, _T("Animation Demo"),
71 wxPoint(-1, -1), wxSize(500, 400),
72 wxDEFAULT_FRAME_STYLE);
73
74 // Give it an icon
75 frame->SetIcon(wxICON(mondrian));
76
77 // Make a menubar
78 wxMenu *file_menu = new wxMenu;
79
80 #if wxUSE_FILEDLG
81 file_menu->Append(wxID_OPEN, _T("&Open Animation...\tCtrl+O"), _T("Open a GIF animation"));
82 #endif // wxUSE_FILEDLG
83 file_menu->Append(wxID_EXIT, _T("&Exit\tAlt+X"), _T("Quit the program"));
84
85 wxMenu *help_menu = new wxMenu;
86 help_menu->Append(wxID_ABOUT, _T("&About\tF1"));
87
88 wxMenuBar *menu_bar = new wxMenuBar;
89
90 menu_bar->Append(file_menu, _T("&File"));
91 menu_bar->Append(help_menu, _T("&Help"));
92
93 // Associate the menu bar with the frame
94 frame->SetMenuBar(menu_bar);
95
96 #if wxUSE_STATUSBAR
97 frame->CreateStatusBar();
98 #endif // wxUSE_STATUSBAR
99
100 frame->Show(true);
101
102 SetTopWindow(frame);
103
104 return true;
105 }
106
107 // ---------------------------------------------------------------------------
108 // MyFrame
109 // ---------------------------------------------------------------------------
110
111 // Define my frame constructor
112 MyFrame::MyFrame(wxWindow *parent,
113 const wxWindowID id,
114 const wxString& title,
115 const wxPoint& pos,
116 const wxSize& size,
117 const long style)
118 : wxFrame(parent, id, title, pos, size,
119 style | wxNO_FULL_REPAINT_ON_RESIZE)
120 {
121 // m_animation = NULL;
122 m_canvas = new MyCanvas(this, wxPoint(0, 0), wxDefaultSize);
123 #if 0
124 m_player.SetDestroyAnimation(false);
125 m_player.SetWindow(m_canvas);
126 m_player.SetPosition(wxPoint(0, 0));
127 #endif
128 m_animationCtrl = new wxGIFAnimationCtrl(m_canvas, -1, wxEmptyString,
129 wxPoint(0, 0), wxSize(200, 200));
130 }
131
132 MyFrame::~MyFrame()
133 {
134 // m_player.Stop();
135 }
136
137 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
138 {
139 Close();
140 }
141
142 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
143 {
144 (void)wxMessageBox(_T("wxWidgets 2 Animation Demo\n")
145 _T("Author: Julian Smart (c) 2001\n"),
146 _T("About Animation Demo"));
147 }
148
149 #if wxUSE_FILEDLG
150 void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
151 {
152 wxFileDialog dialog(this, _T("Please choose an animated GIF"),
153 wxEmptyString, wxEmptyString, wxT("*.gif"), wxFD_OPEN);
154 if (dialog.ShowModal() == wxID_OK)
155 {
156 wxString filename(dialog.GetPath());
157
158 m_animationCtrl->Stop();
159 if (m_animationCtrl->LoadFile(filename))
160 {
161 m_animationCtrl->Play();
162 }
163 else
164 {
165 wxMessageBox(_T("Sorry, this animation was not a valid animated GIF."));
166 }
167 }
168 }
169 #endif // wxUSE_FILEDLG
170
171
172 // ---------------------------------------------------------------------------
173 // MyCanvas
174 // ---------------------------------------------------------------------------
175
176 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
177 EVT_PAINT(MyCanvas::OnPaint)
178 END_EVENT_TABLE()
179
180 // Define a constructor for my canvas
181 MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
182 : wxScrolledWindow(parent, -1, pos, size,
183 wxSUNKEN_BORDER |
184 wxNO_FULL_REPAINT_ON_RESIZE |
185 wxVSCROLL | wxHSCROLL)
186 {
187 SetBackgroundColour(wxColour(_T("YELLOW")));
188 }
189
190 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
191 {
192 wxPaintDC dc(this);
193 #if 0
194 MyFrame* frame = (MyFrame*) GetParent();
195 if (frame->GetPlayer().IsPlaying())
196 {
197 frame->GetPlayer().Draw(dc);
198 }
199 #endif
200 }