2001-07-06 06:24:54 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: anitest.cpp
|
|
|
|
// Purpose: Animation sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 02/07/2001
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// declarations
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2005-08-23 12:02:51 -04:00
|
|
|
#ifndef __WXMSW__
|
2001-07-06 06:24:54 -04:00
|
|
|
#include "mondrian.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "anitest.h"
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// global variables
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2005-08-23 12:02:51 -04:00
|
|
|
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
|
|
|
#if wxUSE_FILEDLG
|
|
|
|
EVT_MENU(wxID_OPEN, MyFrame::OnOpen)
|
|
|
|
#endif // wxUSE_FILEDLG
|
2001-07-06 06:24:54 -04:00
|
|
|
|
|
|
|
EVT_SIZE(MyFrame::OnSize)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// implementation
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Initialise this in OnInit, not statically
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
// Create the main frame window
|
|
|
|
|
2003-07-08 15:12:02 -04:00
|
|
|
MyFrame* frame = new MyFrame((wxFrame *)NULL, -1, _T("Animation Demo"),
|
2001-07-06 06:24:54 -04:00
|
|
|
wxPoint(-1, -1), wxSize(500, 400),
|
|
|
|
wxDEFAULT_FRAME_STYLE);
|
|
|
|
|
|
|
|
// Give it an icon
|
|
|
|
#ifdef __WXMSW__
|
2003-09-11 05:34:43 -04:00
|
|
|
frame->SetIcon(wxIcon(_T("mdi_icn")));
|
2001-07-06 06:24:54 -04:00
|
|
|
#else
|
|
|
|
frame->SetIcon(wxIcon( mondrian_xpm ));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
|
2005-08-23 12:02:51 -04:00
|
|
|
#if wxUSE_FILEDLG
|
|
|
|
file_menu->Append(wxID_OPEN, _T("&Open Animation...\tCtrl+O"), _T("Open a GIF animation"));
|
|
|
|
#endif // wxUSE_FILEDLG
|
|
|
|
file_menu->Append(wxID_EXIT, _T("&Exit\tAlt+X"), _T("Quit the program"));
|
2001-07-06 06:24:54 -04:00
|
|
|
|
|
|
|
wxMenu *help_menu = new wxMenu;
|
2005-08-23 12:02:51 -04:00
|
|
|
help_menu->Append(wxID_ABOUT, _T("&About\tF1"));
|
2001-07-06 06:24:54 -04:00
|
|
|
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
|
|
|
|
2003-07-08 15:12:02 -04:00
|
|
|
menu_bar->Append(file_menu, _T("&File"));
|
|
|
|
menu_bar->Append(help_menu, _T("&Help"));
|
2001-07-06 06:24:54 -04:00
|
|
|
|
|
|
|
// Associate the menu bar with the frame
|
|
|
|
frame->SetMenuBar(menu_bar);
|
|
|
|
|
2004-07-19 11:14:07 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2001-07-06 06:24:54 -04:00
|
|
|
frame->CreateStatusBar();
|
2004-07-19 11:14:07 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2001-07-06 06:24:54 -04:00
|
|
|
|
2005-08-23 12:02:51 -04:00
|
|
|
frame->Show(true);
|
2001-07-06 06:24:54 -04:00
|
|
|
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
2005-08-23 12:02:51 -04:00
|
|
|
return true;
|
2001-07-06 06:24:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define my frame constructor
|
|
|
|
MyFrame::MyFrame(wxWindow *parent,
|
|
|
|
const wxWindowID id,
|
|
|
|
const wxString& title,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
const long style)
|
|
|
|
: wxFrame(parent, id, title, pos, size,
|
|
|
|
style | wxNO_FULL_REPAINT_ON_RESIZE)
|
|
|
|
{
|
|
|
|
// m_animation = NULL;
|
2005-08-23 12:02:51 -04:00
|
|
|
m_canvas = new MyCanvas(this, wxPoint(0, 0), wxDefaultSize);
|
2001-07-06 06:24:54 -04:00
|
|
|
#if 0
|
2005-08-23 12:02:51 -04:00
|
|
|
m_player.SetDestroyAnimation(false);
|
2001-07-06 06:24:54 -04:00
|
|
|
m_player.SetWindow(m_canvas);
|
|
|
|
m_player.SetPosition(wxPoint(0, 0));
|
|
|
|
#endif
|
|
|
|
m_animationCtrl = new wxGIFAnimationCtrl(m_canvas, -1, wxEmptyString,
|
|
|
|
wxPoint(0, 0), wxSize(200, 200));
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
// m_player.Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2004-05-25 07:20:37 -04:00
|
|
|
(void)wxMessageBox(_T("wxWidgets 2 Animation Demo\n")
|
2003-07-08 15:12:02 -04:00
|
|
|
_T("Author: Julian Smart (c) 2001\n"),
|
|
|
|
_T("About Animation Demo"));
|
2001-07-06 06:24:54 -04:00
|
|
|
}
|
|
|
|
|
2005-08-23 12:02:51 -04:00
|
|
|
#if wxUSE_FILEDLG
|
2003-09-11 05:34:43 -04:00
|
|
|
void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
|
2001-07-06 06:24:54 -04:00
|
|
|
{
|
2003-07-08 15:12:02 -04:00
|
|
|
wxFileDialog dialog(this, _T("Please choose an animated GIF"),
|
2001-07-06 06:24:54 -04:00
|
|
|
wxEmptyString, wxEmptyString, wxT("*.gif"), wxOPEN);
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxString filename(dialog.GetPath());
|
|
|
|
|
|
|
|
m_animationCtrl->Stop();
|
|
|
|
if (m_animationCtrl->LoadFile(filename))
|
|
|
|
{
|
|
|
|
m_animationCtrl->Play();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-08 15:12:02 -04:00
|
|
|
wxMessageBox(_T("Sorry, this animation was not a valid animated GIF."));
|
2001-07-06 06:24:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-23 12:02:51 -04:00
|
|
|
#endif // wxUSE_FILEDLG
|
2001-07-06 06:24:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyCanvas
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
|
|
EVT_PAINT(MyCanvas::OnPaint)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// Define a constructor for my canvas
|
|
|
|
MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
|
|
|
|
: wxScrolledWindow(parent, -1, pos, size,
|
|
|
|
wxSUNKEN_BORDER |
|
|
|
|
wxNO_FULL_REPAINT_ON_RESIZE |
|
|
|
|
wxVSCROLL | wxHSCROLL)
|
|
|
|
{
|
2003-09-11 05:34:43 -04:00
|
|
|
SetBackgroundColour(wxColour(_T("YELLOW")));
|
2001-07-06 06:24:54 -04:00
|
|
|
}
|
|
|
|
|
2003-09-11 05:34:43 -04:00
|
|
|
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
2001-07-06 06:24:54 -04:00
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
#if 0
|
|
|
|
MyFrame* frame = (MyFrame*) GetParent();
|
|
|
|
if (frame->GetPlayer().IsPlaying())
|
|
|
|
{
|
|
|
|
frame->GetPlayer().Draw(dc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|