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"
32 #include "mondrian.xpm"
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
52 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
53 EVT_MENU(wxID_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
, -1, _T("Animation Demo"),
79 wxPoint(-1, -1), wxSize(500, 400),
80 wxDEFAULT_FRAME_STYLE
);
84 frame
->SetIcon(wxIcon(_T("mdi_icn")));
86 frame
->SetIcon(wxIcon( mondrian_xpm
));
90 wxMenu
*file_menu
= new wxMenu
;
93 file_menu
->Append(wxID_OPEN
, _T("&Open Animation...\tCtrl+O"), _T("Loads an animation"));
94 #endif // wxUSE_FILEDLG
95 file_menu
->Append(wxID_EXIT
);
97 wxMenu
*play_menu
= new wxMenu
;
98 play_menu
->Append(wxID_PLAY
, _T("Play\tCtrl+P"), _T("Play the animation"));
99 play_menu
->Append(wxID_STOP
, _T("Stop\tCtrl+P"), _T("Stop the animation"));
101 wxMenu
*help_menu
= new wxMenu
;
102 help_menu
->Append(wxID_ABOUT
);
104 wxMenuBar
*menu_bar
= new wxMenuBar
;
106 menu_bar
->Append(file_menu
, _T("&File"));
107 menu_bar
->Append(play_menu
, _T("&Animation"));
108 menu_bar
->Append(help_menu
, _T("&Help"));
110 // Associate the menu bar with the frame
111 frame
->SetMenuBar(menu_bar
);
114 frame
->CreateStatusBar();
115 #endif // wxUSE_STATUSBAR
124 // ---------------------------------------------------------------------------
126 // ---------------------------------------------------------------------------
128 #include "wx/wfstream.h"
130 // Define my frame constructor
131 MyFrame::MyFrame(wxWindow
*parent
,
133 const wxString
& title
,
137 : wxFrame(parent
, id
, title
, pos
, size
,
138 style
| wxNO_FULL_REPAINT_ON_RESIZE
)
140 //m_canvas = new MyCanvas(this, wxPoint(0, 0), wxDefaultSize);
142 //wxSizer *sz = new wxBoxSizer(wxVERTICAL);
144 m_animationCtrl
= new wxAnimationCtrl(this, wxID_ANY
, wxNullAnimation
,
145 wxPoint(0,0),wxSize(100,100));
146 if (m_animationCtrl
->LoadFile(wxT("throbber.gif")))
147 m_animationCtrl
->Play();
149 //sz->Add(m_animationCtrl, 1, wxGROW);
158 void MyFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
160 if (!m_animationCtrl
->Play())
161 wxLogError(wxT("Invalid animation"));
164 void MyFrame::OnStop(wxCommandEvent
& WXUNUSED(event
))
166 m_animationCtrl
->Stop();
169 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
174 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
178 FIXME: on wxGTK at least using File->About command it shows
179 the message dialog but does not focus it
183 (void)wxMessageBox(_T("wxWidgets 2 Animation Demo\n")
184 _T("Author: Julian Smart (c) 2001\n"),
185 _T("About Animation Demo"));
189 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
191 wxFileDialog
dialog(this, _T("Please choose an animation"),
192 wxEmptyString
, wxEmptyString
, wxT("*.gif;*.ani"), wxFD_OPEN
);
193 if (dialog
.ShowModal() == wxID_OK
)
195 wxString
filename(dialog
.GetPath());
197 // enable one of the two chunk of codes to test different parts of wxAnimation/wxAnimationCtrl
199 if (m_animationCtrl
->LoadFile(filename
))
200 m_animationCtrl
->Play();
202 wxMessageBox(_T("Sorry, this animation is not a valid format for wxAnimation."));
206 if (!temp
.LoadFile(filename
))
208 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
212 m_animationCtrl
->SetAnimation(temp
);
213 m_animationCtrl
->Play();
215 wxFileInputStream
stream(filename
);
218 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
223 if (!temp
.Load(stream
))
225 wxLogError(wxT("Sorry, this animation is not a valid format for wxAnimation."));
229 m_animationCtrl
->SetAnimation(temp
);
230 m_animationCtrl
->Play();
235 #endif // wxUSE_FILEDLG
237 void MyFrame::OnUpdateUI(wxUpdateUIEvent
& WXUNUSED(event
) )
239 GetMenuBar()->FindItem(wxID_STOP
)->Enable(m_animationCtrl
->IsPlaying());
240 GetMenuBar()->FindItem(wxID_PLAY
)->Enable(!m_animationCtrl
->IsPlaying());
243 // ---------------------------------------------------------------------------
245 // ---------------------------------------------------------------------------
247 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
248 //EVT_PAINT(MyCanvas::OnPaint)
251 // Define a constructor for my canvas
252 MyCanvas::MyCanvas(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
)
253 : wxScrolledWindow(parent
, -1, pos
, size
,
255 wxNO_FULL_REPAINT_ON_RESIZE
|
256 wxVSCROLL
| wxHSCROLL
)
258 SetBackgroundColour(wxColour(_T("YELLOW")));
261 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
263 //wxPaintDC dc(this);
265 //dc.DrawRotatedText(wxT("Background"),