]> git.saurik.com Git - wxWidgets.git/blame - samples/animate/anitest.cpp
Sizing fixes for generic control.
[wxWidgets.git] / samples / animate / anitest.cpp
CommitLineData
72045d57
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: anitest.cpp
3// Purpose: Animation sample
4// Author: Julian Smart
5// Modified by: Francesco Montorsi
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__
3652fd78 32 #include "sample.xpm"
72045d57
VZ
33#endif
34
68aef14d 35#include "wx/aboutdlg.h"
72045d57
VZ
36#include "anitest.h"
37
68aef14d
VZ
38#if !wxUSE_ANIMATIONCTRL
39 #error Cannot compile this sample if wxAnimationCtrl is not enabled
40#endif
41
42
72045d57
VZ
43IMPLEMENT_APP(MyApp)
44
45// ---------------------------------------------------------------------------
46// global variables
47// ---------------------------------------------------------------------------
48
49// ---------------------------------------------------------------------------
50// event tables
51// ---------------------------------------------------------------------------
52
53enum
54{
c3d6e0aa 55 ID_PLAY = 1
72045d57
VZ
56};
57
58BEGIN_EVENT_TABLE(MyFrame, wxFrame)
c3d6e0aa 59 EVT_MENU(ID_PLAY, MyFrame::OnPlay)
72045d57
VZ
60 EVT_MENU(wxID_STOP, MyFrame::OnStop)
61 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
62 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
63#if wxUSE_FILEDLG
64 EVT_MENU(wxID_OPEN, MyFrame::OnOpen)
65#endif // wxUSE_FILEDLG
66
67 EVT_SIZE(MyFrame::OnSize)
68 EVT_UPDATE_UI(wxID_ANY, MyFrame::OnUpdateUI)
69END_EVENT_TABLE()
70
71// ===========================================================================
72// implementation
73// ===========================================================================
74
75// ---------------------------------------------------------------------------
76// MyApp
77// ---------------------------------------------------------------------------
78
79// Initialise this in OnInit, not statically
80bool MyApp::OnInit()
81{
82 // Create the main frame window
83
3f4a2351
WS
84 MyFrame* frame = new MyFrame((wxFrame *)NULL, wxID_ANY, _T("Animation Demo"),
85 wxDefaultPosition, wxSize(500, 400),
86 wxDEFAULT_FRAME_STYLE);
72045d57
VZ
87
88 // Give it an icon
73565531 89 frame->SetIcon(wxICON(sample));
72045d57
VZ
90
91 // Make a menubar
92 wxMenu *file_menu = new wxMenu;
93
94#if wxUSE_FILEDLG
95 file_menu->Append(wxID_OPEN, _T("&Open Animation...\tCtrl+O"), _T("Loads an animation"));
96#endif // wxUSE_FILEDLG
97 file_menu->Append(wxID_EXIT);
98
99 wxMenu *play_menu = new wxMenu;
c3d6e0aa 100 play_menu->Append(ID_PLAY, _T("Play\tCtrl+P"), _T("Play the animation"));
72045d57
VZ
101 play_menu->Append(wxID_STOP, _T("Stop\tCtrl+P"), _T("Stop the animation"));
102
103 wxMenu *help_menu = new wxMenu;
104 help_menu->Append(wxID_ABOUT);
105
106 wxMenuBar *menu_bar = new wxMenuBar;
107
108 menu_bar->Append(file_menu, _T("&File"));
109 menu_bar->Append(play_menu, _T("&Animation"));
110 menu_bar->Append(help_menu, _T("&Help"));
111
112 // Associate the menu bar with the frame
113 frame->SetMenuBar(menu_bar);
114
115#if wxUSE_STATUSBAR
116 frame->CreateStatusBar();
117#endif // wxUSE_STATUSBAR
118
119 frame->Show(true);
120
121 SetTopWindow(frame);
122
123 return true;
124}
125
126// ---------------------------------------------------------------------------
127// MyFrame
128// ---------------------------------------------------------------------------
129
130#include "wx/wfstream.h"
131
132// Define my frame constructor
133MyFrame::MyFrame(wxWindow *parent,
134 const wxWindowID id,
135 const wxString& title,
136 const wxPoint& pos,
137 const wxSize& size,
138 const long style)
139 : wxFrame(parent, id, title, pos, size,
140 style | wxNO_FULL_REPAINT_ON_RESIZE)
141{
72045d57
VZ
142 m_animationCtrl = new wxAnimationCtrl(this, wxID_ANY, wxNullAnimation,
143 wxPoint(0,0),wxSize(100,100));
144 if (m_animationCtrl->LoadFile(wxT("throbber.gif")))
145 m_animationCtrl->Play();
72045d57
VZ
146}
147
148MyFrame::~MyFrame()
149{
150}
151
152void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
153{
154 if (!m_animationCtrl->Play())
155 wxLogError(wxT("Invalid animation"));
156}
157
158void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event))
159{
160 m_animationCtrl->Stop();
161}
162
163void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
164{
165 Close();
166}
167
168void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
169{
68aef14d
VZ
170 wxAboutDialogInfo info;
171 info.SetName(_("wxAnimationCtrl and wxAnimation sample"));
172 info.SetDescription(_("This sample program demonstrates the usage of wxAnimationCtrl"));
173 info.SetCopyright(_T("(C) 2006 Julian Smart"));
72045d57 174
68aef14d
VZ
175 info.AddDeveloper(_T("Julian Smart"));
176 info.AddDeveloper(_T("Guillermo Rodriguez Garcia"));
177 info.AddDeveloper(_T("Francesco Montorsi"));
72045d57 178
68aef14d 179 wxAboutBox(info);
72045d57
VZ
180}
181
182#if wxUSE_FILEDLG
183void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
184{
185 wxFileDialog dialog(this, _T("Please choose an animation"),
186 wxEmptyString, wxEmptyString, wxT("*.gif;*.ani"), wxFD_OPEN);
187 if (dialog.ShowModal() == wxID_OK)
188 {
189 wxString filename(dialog.GetPath());
190
191 // enable one of the two chunk of codes to test different parts of wxAnimation/wxAnimationCtrl
192#if 0
193 if (m_animationCtrl->LoadFile(filename))
194 m_animationCtrl->Play();
195 else
196 wxMessageBox(_T("Sorry, this animation is not a valid format for wxAnimation."));
197#else
198 #if 0
199 wxAnimation temp;
200 if (!temp.LoadFile(filename))
201 {
202 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
203 return;
204 }
205
206 m_animationCtrl->SetAnimation(temp);
207 m_animationCtrl->Play();
208 #else
209 wxFileInputStream stream(filename);
210 if (!stream.Ok())
211 {
212 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
213 return;
214 }
215
216 wxAnimation temp;
217 if (!temp.Load(stream))
218 {
219 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
220 return;
221 }
222
223 m_animationCtrl->SetAnimation(temp);
224 m_animationCtrl->Play();
225 #endif
226#endif
227 }
228}
229#endif // wxUSE_FILEDLG
230
231void MyFrame::OnUpdateUI(wxUpdateUIEvent& WXUNUSED(event) )
232{
233 GetMenuBar()->FindItem(wxID_STOP)->Enable(m_animationCtrl->IsPlaying());
c3d6e0aa 234 GetMenuBar()->FindItem(ID_PLAY)->Enable(!m_animationCtrl->IsPlaying());
72045d57
VZ
235}
236