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"
31 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
32 #include "mondrian.xpm"
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
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
)
52 EVT_SIZE(MyFrame::OnSize
)
55 // ===========================================================================
57 // ===========================================================================
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 // Initialise this in OnInit, not statically
66 // Create the main frame window
68 MyFrame
* frame
= new MyFrame((wxFrame
*)NULL
, -1, _T("Animation Demo"),
69 wxPoint(-1, -1), wxSize(500, 400),
70 wxDEFAULT_FRAME_STYLE
);
74 frame
->SetIcon(wxIcon(_T("mdi_icn")));
76 frame
->SetIcon(wxIcon( mondrian_xpm
));
80 wxMenu
*file_menu
= new wxMenu
;
82 file_menu
->Append(ANITEST_OPEN
, _T("&Open Animation...\tCtrl+O"), _T("Open a GIF animation"));
83 file_menu
->Append(ANITEST_QUIT
, _T("&Exit\tAlt+X"), _T("Quit the program"));
85 wxMenu
*help_menu
= new wxMenu
;
86 help_menu
->Append(ANITEST_ABOUT
, _T("&About\tF1"));
88 wxMenuBar
*menu_bar
= new wxMenuBar
;
90 menu_bar
->Append(file_menu
, _T("&File"));
91 menu_bar
->Append(help_menu
, _T("&Help"));
93 // Associate the menu bar with the frame
94 frame
->SetMenuBar(menu_bar
);
97 frame
->CreateStatusBar();
98 #endif // wxUSE_STATUSBAR
107 // ---------------------------------------------------------------------------
109 // ---------------------------------------------------------------------------
111 // Define my frame constructor
112 MyFrame::MyFrame(wxWindow
*parent
,
114 const wxString
& title
,
118 : wxFrame(parent
, id
, title
, pos
, size
,
119 style
| wxNO_FULL_REPAINT_ON_RESIZE
)
121 // m_animation = NULL;
122 m_canvas
= new MyCanvas(this, wxPoint(0, 0), wxSize(-1, -1));
124 m_player
.SetDestroyAnimation(FALSE
);
125 m_player
.SetWindow(m_canvas
);
126 m_player
.SetPosition(wxPoint(0, 0));
128 m_animationCtrl
= new wxGIFAnimationCtrl(m_canvas
, -1, wxEmptyString
,
129 wxPoint(0, 0), wxSize(200, 200));
137 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
142 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
144 (void)wxMessageBox(_T("wxWidgets 2 Animation Demo\n")
145 _T("Author: Julian Smart (c) 2001\n"),
146 _T("About Animation Demo"));
149 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
151 wxFileDialog
dialog(this, _T("Please choose an animated GIF"),
152 wxEmptyString
, wxEmptyString
, wxT("*.gif"), wxOPEN
);
153 if (dialog
.ShowModal() == wxID_OK
)
155 wxString
filename(dialog
.GetPath());
157 m_animationCtrl
->Stop();
158 if (m_animationCtrl
->LoadFile(filename
))
160 m_animationCtrl
->Play();
164 wxMessageBox(_T("Sorry, this animation was not a valid animated GIF."));
170 // ---------------------------------------------------------------------------
172 // ---------------------------------------------------------------------------
174 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
175 EVT_PAINT(MyCanvas::OnPaint
)
178 // Define a constructor for my canvas
179 MyCanvas::MyCanvas(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
)
180 : wxScrolledWindow(parent
, -1, pos
, size
,
182 wxNO_FULL_REPAINT_ON_RESIZE
|
183 wxVSCROLL
| wxHSCROLL
)
185 SetBackgroundColour(wxColour(_T("YELLOW")));
188 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
192 MyFrame
* frame
= (MyFrame
*) GetParent();
193 if (frame
->GetPlayer().IsPlaying())
195 frame
->GetPlayer().Draw(dc
);