1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Animation sample
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
52 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
53 EVT_MENU(ID_PLAY
, MyFrame::OnPlay
)
54 EVT_MENU(wxID_STOP
, MyFrame::OnStop
)
55 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
56 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
58 EVT_MENU(wxID_OPEN
, MyFrame::OnOpen
)
59 #endif // wxUSE_FILEDLG
61 EVT_SIZE(MyFrame::OnSize
)
62 EVT_UPDATE_UI(wxID_ANY
, MyFrame::OnUpdateUI
)
65 // ===========================================================================
67 // ===========================================================================
69 // ---------------------------------------------------------------------------
71 // ---------------------------------------------------------------------------
73 // Initialise this in OnInit, not statically
76 // Create the main frame window
78 MyFrame
* frame
= new MyFrame((wxFrame
*)NULL
, wxID_ANY
, _T("Animation Demo"),
79 wxDefaultPosition
, wxSize(500, 400),
80 wxDEFAULT_FRAME_STYLE
);
83 frame
->SetIcon(wxICON(sample
));
86 wxMenu
*file_menu
= new wxMenu
;
89 file_menu
->Append(wxID_OPEN
, _T("&Open Animation...\tCtrl+O"), _T("Loads an animation"));
90 #endif // wxUSE_FILEDLG
91 file_menu
->Append(wxID_EXIT
);
93 wxMenu
*play_menu
= new wxMenu
;
94 play_menu
->Append(ID_PLAY
, _T("Play\tCtrl+P"), _T("Play the animation"));
95 play_menu
->Append(wxID_STOP
, _T("Stop\tCtrl+P"), _T("Stop the animation"));
97 wxMenu
*help_menu
= new wxMenu
;
98 help_menu
->Append(wxID_ABOUT
);
100 wxMenuBar
*menu_bar
= new wxMenuBar
;
102 menu_bar
->Append(file_menu
, _T("&File"));
103 menu_bar
->Append(play_menu
, _T("&Animation"));
104 menu_bar
->Append(help_menu
, _T("&Help"));
106 // Associate the menu bar with the frame
107 frame
->SetMenuBar(menu_bar
);
110 frame
->CreateStatusBar();
111 #endif // wxUSE_STATUSBAR
120 // ---------------------------------------------------------------------------
122 // ---------------------------------------------------------------------------
124 #include "wx/wfstream.h"
126 // Define my frame constructor
127 MyFrame::MyFrame(wxWindow
*parent
,
129 const wxString
& title
,
133 : wxFrame(parent
, id
, title
, pos
, size
,
134 style
| wxNO_FULL_REPAINT_ON_RESIZE
)
136 //m_canvas = new MyCanvas(this, wxPoint(0, 0), wxDefaultSize);
138 //wxSizer *sz = new wxBoxSizer(wxVERTICAL);
140 m_animationCtrl
= new wxAnimationCtrl(this, wxID_ANY
, wxNullAnimation
,
141 wxPoint(0,0),wxSize(100,100));
142 if (m_animationCtrl
->LoadFile(wxT("throbber.gif")))
143 m_animationCtrl
->Play();
145 //sz->Add(m_animationCtrl, 1, wxGROW);
154 void MyFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
156 if (!m_animationCtrl
->Play())
157 wxLogError(wxT("Invalid animation"));
160 void MyFrame::OnStop(wxCommandEvent
& WXUNUSED(event
))
162 m_animationCtrl
->Stop();
165 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
170 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
174 FIXME: on wxGTK at least using File->About command it shows
175 the message dialog but does not focus it
179 (void)wxMessageBox(_T("wxWidgets 2 Animation Demo\n")
180 _T("Author: Julian Smart (c) 2001\n"),
181 _T("About Animation Demo"));
185 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
187 wxFileDialog
dialog(this, _T("Please choose an animation"),
188 wxEmptyString
, wxEmptyString
, wxT("*.gif;*.ani"), wxFD_OPEN
);
189 if (dialog
.ShowModal() == wxID_OK
)
191 wxString
filename(dialog
.GetPath());
193 // enable one of the two chunk of codes to test different parts of wxAnimation/wxAnimationCtrl
195 if (m_animationCtrl
->LoadFile(filename
))
196 m_animationCtrl
->Play();
198 wxMessageBox(_T("Sorry, this animation is not a valid format for wxAnimation."));
202 if (!temp
.LoadFile(filename
))
204 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
208 m_animationCtrl
->SetAnimation(temp
);
209 m_animationCtrl
->Play();
211 wxFileInputStream
stream(filename
);
214 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
219 if (!temp
.Load(stream
))
221 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
225 m_animationCtrl
->SetAnimation(temp
);
226 m_animationCtrl
->Play();
231 #endif // wxUSE_FILEDLG
233 void MyFrame::OnUpdateUI(wxUpdateUIEvent
& WXUNUSED(event
) )
235 GetMenuBar()->FindItem(wxID_STOP
)->Enable(m_animationCtrl
->IsPlaying());
236 GetMenuBar()->FindItem(ID_PLAY
)->Enable(!m_animationCtrl
->IsPlaying());
239 // ---------------------------------------------------------------------------
241 // ---------------------------------------------------------------------------
243 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
244 //EVT_PAINT(MyCanvas::OnPaint)
247 // Define a constructor for my canvas
248 MyCanvas::MyCanvas(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
)
249 : wxScrolledWindow(parent
, wxID_ANY
, pos
, size
,
251 wxNO_FULL_REPAINT_ON_RESIZE
|
252 wxVSCROLL
| wxHSCROLL
)
254 SetBackgroundColour(wxColour(_T("YELLOW")));
257 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
259 //wxPaintDC dc(this);
261 //dc.DrawRotatedText(wxT("Background"),