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