]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/animate/anitest.cpp
warning fix
[wxWidgets.git] / contrib / samples / animate / anitest.cpp
CommitLineData
4638d697
JS
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
c54e5eb0 31#ifndef __WXMSW__
4638d697
JS
32 #include "mondrian.xpm"
33#endif
34
35#include "anitest.h"
36
37IMPLEMENT_APP(MyApp)
38
39// ---------------------------------------------------------------------------
40// global variables
41// ---------------------------------------------------------------------------
42
43// ---------------------------------------------------------------------------
44// event tables
45// ---------------------------------------------------------------------------
46
47BEGIN_EVENT_TABLE(MyFrame, wxFrame)
c54e5eb0
WS
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
4638d697
JS
53
54 EVT_SIZE(MyFrame::OnSize)
55END_EVENT_TABLE()
56
57// ===========================================================================
58// implementation
59// ===========================================================================
60
61// ---------------------------------------------------------------------------
62// MyApp
63// ---------------------------------------------------------------------------
64
65// Initialise this in OnInit, not statically
66bool MyApp::OnInit()
67{
68 // Create the main frame window
69
10217444 70 MyFrame* frame = new MyFrame((wxFrame *)NULL, -1, _T("Animation Demo"),
4638d697
JS
71 wxPoint(-1, -1), wxSize(500, 400),
72 wxDEFAULT_FRAME_STYLE);
73
74 // Give it an icon
75#ifdef __WXMSW__
ee0d4b46 76 frame->SetIcon(wxIcon(_T("mdi_icn")));
4638d697
JS
77#else
78 frame->SetIcon(wxIcon( mondrian_xpm ));
79#endif
80
81 // Make a menubar
82 wxMenu *file_menu = new wxMenu;
83
c54e5eb0
WS
84#if wxUSE_FILEDLG
85 file_menu->Append(wxID_OPEN, _T("&Open Animation...\tCtrl+O"), _T("Open a GIF animation"));
86#endif // wxUSE_FILEDLG
87 file_menu->Append(wxID_EXIT, _T("&Exit\tAlt+X"), _T("Quit the program"));
4638d697
JS
88
89 wxMenu *help_menu = new wxMenu;
c54e5eb0 90 help_menu->Append(wxID_ABOUT, _T("&About\tF1"));
4638d697
JS
91
92 wxMenuBar *menu_bar = new wxMenuBar;
93
10217444
VS
94 menu_bar->Append(file_menu, _T("&File"));
95 menu_bar->Append(help_menu, _T("&Help"));
4638d697
JS
96
97 // Associate the menu bar with the frame
98 frame->SetMenuBar(menu_bar);
99
d96cdd4a 100#if wxUSE_STATUSBAR
4638d697 101 frame->CreateStatusBar();
d96cdd4a 102#endif // wxUSE_STATUSBAR
4638d697 103
c54e5eb0 104 frame->Show(true);
4638d697
JS
105
106 SetTopWindow(frame);
107
c54e5eb0 108 return true;
4638d697
JS
109}
110
111// ---------------------------------------------------------------------------
112// MyFrame
113// ---------------------------------------------------------------------------
114
115// Define my frame constructor
116MyFrame::MyFrame(wxWindow *parent,
117 const wxWindowID id,
118 const wxString& title,
119 const wxPoint& pos,
120 const wxSize& size,
121 const long style)
122 : wxFrame(parent, id, title, pos, size,
123 style | wxNO_FULL_REPAINT_ON_RESIZE)
124{
125// m_animation = NULL;
c54e5eb0 126 m_canvas = new MyCanvas(this, wxPoint(0, 0), wxDefaultSize);
4638d697 127#if 0
c54e5eb0 128 m_player.SetDestroyAnimation(false);
4638d697
JS
129 m_player.SetWindow(m_canvas);
130 m_player.SetPosition(wxPoint(0, 0));
131#endif
132 m_animationCtrl = new wxGIFAnimationCtrl(m_canvas, -1, wxEmptyString,
133 wxPoint(0, 0), wxSize(200, 200));
134}
135
136MyFrame::~MyFrame()
137{
138// m_player.Stop();
139}
140
141void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
142{
143 Close();
144}
145
146void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
147{
be5a51fb 148 (void)wxMessageBox(_T("wxWidgets 2 Animation Demo\n")
10217444
VS
149 _T("Author: Julian Smart (c) 2001\n"),
150 _T("About Animation Demo"));
4638d697
JS
151}
152
c54e5eb0 153#if wxUSE_FILEDLG
ee0d4b46 154void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
4638d697 155{
10217444 156 wxFileDialog dialog(this, _T("Please choose an animated GIF"),
4638d697
JS
157 wxEmptyString, wxEmptyString, wxT("*.gif"), wxOPEN);
158 if (dialog.ShowModal() == wxID_OK)
159 {
160 wxString filename(dialog.GetPath());
161
162 m_animationCtrl->Stop();
163 if (m_animationCtrl->LoadFile(filename))
164 {
165 m_animationCtrl->Play();
166 }
167 else
168 {
10217444 169 wxMessageBox(_T("Sorry, this animation was not a valid animated GIF."));
4638d697
JS
170 }
171 }
172}
c54e5eb0 173#endif // wxUSE_FILEDLG
4638d697
JS
174
175
176// ---------------------------------------------------------------------------
177// MyCanvas
178// ---------------------------------------------------------------------------
179
180BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
181 EVT_PAINT(MyCanvas::OnPaint)
182END_EVENT_TABLE()
183
184// Define a constructor for my canvas
185MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
186 : wxScrolledWindow(parent, -1, pos, size,
187 wxSUNKEN_BORDER |
188 wxNO_FULL_REPAINT_ON_RESIZE |
189 wxVSCROLL | wxHSCROLL)
190{
ee0d4b46 191 SetBackgroundColour(wxColour(_T("YELLOW")));
4638d697
JS
192}
193
ee0d4b46 194void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
4638d697
JS
195{
196 wxPaintDC dc(this);
197#if 0
198 MyFrame* frame = (MyFrame*) GetParent();
199 if (frame->GetPlayer().IsPlaying())
200 {
201 frame->GetPlayer().Draw(dc);
202 }
203#endif
204}