1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Animation sample
4 // Author: Julian Smart
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 // ---------------------------------------------------------------------------
47 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
48 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
49 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
51 EVT_MENU(wxID_OPEN
, MyFrame::OnOpen
)
52 #endif // wxUSE_FILEDLG
54 EVT_SIZE(MyFrame::OnSize
)
57 // ===========================================================================
59 // ===========================================================================
61 // ---------------------------------------------------------------------------
63 // ---------------------------------------------------------------------------
65 // Initialise this in OnInit, not statically
68 // Create the main frame window
70 MyFrame
* frame
= new MyFrame((wxFrame
*)NULL
, -1, _T("Animation Demo"),
71 wxPoint(-1, -1), wxSize(500, 400),
72 wxDEFAULT_FRAME_STYLE
);
76 frame
->SetIcon(wxIcon(_T("mdi_icn")));
78 frame
->SetIcon(wxIcon( mondrian_xpm
));
82 wxMenu
*file_menu
= new wxMenu
;
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"));
89 wxMenu
*help_menu
= new wxMenu
;
90 help_menu
->Append(wxID_ABOUT
, _T("&About\tF1"));
92 wxMenuBar
*menu_bar
= new wxMenuBar
;
94 menu_bar
->Append(file_menu
, _T("&File"));
95 menu_bar
->Append(help_menu
, _T("&Help"));
97 // Associate the menu bar with the frame
98 frame
->SetMenuBar(menu_bar
);
101 frame
->CreateStatusBar();
102 #endif // wxUSE_STATUSBAR
111 // ---------------------------------------------------------------------------
113 // ---------------------------------------------------------------------------
115 // Define my frame constructor
116 MyFrame::MyFrame(wxWindow
*parent
,
118 const wxString
& title
,
122 : wxFrame(parent
, id
, title
, pos
, size
,
123 style
| wxNO_FULL_REPAINT_ON_RESIZE
)
125 // m_animation = NULL;
126 m_canvas
= new MyCanvas(this, wxPoint(0, 0), wxDefaultSize
);
128 m_player
.SetDestroyAnimation(false);
129 m_player
.SetWindow(m_canvas
);
130 m_player
.SetPosition(wxPoint(0, 0));
132 m_animationCtrl
= new wxGIFAnimationCtrl(m_canvas
, -1, wxEmptyString
,
133 wxPoint(0, 0), wxSize(200, 200));
141 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
146 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
148 (void)wxMessageBox(_T("wxWidgets 2 Animation Demo\n")
149 _T("Author: Julian Smart (c) 2001\n"),
150 _T("About Animation Demo"));
154 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
156 wxFileDialog
dialog(this, _T("Please choose an animated GIF"),
157 wxEmptyString
, wxEmptyString
, wxT("*.gif"), wxFD_OPEN
);
158 if (dialog
.ShowModal() == wxID_OK
)
160 wxString
filename(dialog
.GetPath());
162 m_animationCtrl
->Stop();
163 if (m_animationCtrl
->LoadFile(filename
))
165 m_animationCtrl
->Play();
169 wxMessageBox(_T("Sorry, this animation was not a valid animated GIF."));
173 #endif // wxUSE_FILEDLG
176 // ---------------------------------------------------------------------------
178 // ---------------------------------------------------------------------------
180 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
181 EVT_PAINT(MyCanvas::OnPaint
)
184 // Define a constructor for my canvas
185 MyCanvas::MyCanvas(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
)
186 : wxScrolledWindow(parent
, -1, pos
, size
,
188 wxNO_FULL_REPAINT_ON_RESIZE
|
189 wxVSCROLL
| wxHSCROLL
)
191 SetBackgroundColour(wxColour(_T("YELLOW")));
194 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
198 MyFrame
* frame
= (MyFrame
*) GetParent();
199 if (frame
->GetPlayer().IsPlaying())
201 frame
->GetPlayer().Draw(dc
);