2002-06-19 09:16:19 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: svgtest.cpp
|
|
|
|
// Purpose: SVG sample
|
|
|
|
// Author: Chris Elliott
|
|
|
|
// Modified by:
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2002-06-19 09:16:19 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// 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"
|
|
|
|
#include "wx/mdi.h"
|
|
|
|
#endif
|
|
|
|
|
2005-10-07 14:01:37 +00:00
|
|
|
#include "wx/toolbar.h"
|
2007-04-05 18:26:59 +00:00
|
|
|
#include "wx/dcsvg.h"
|
2009-03-14 01:01:12 +00:00
|
|
|
#include "wx/vector.h"
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
#include "bitmaps/new.xpm"
|
|
|
|
#include "bitmaps/save.xpm"
|
|
|
|
#include "bitmaps/help.xpm"
|
|
|
|
#include "SVGlogo24.xpm"
|
2005-05-31 13:44:45 +00:00
|
|
|
|
2012-03-04 00:28:58 +00:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2010-06-20 17:42:33 +00:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
2002-06-19 09:16:19 +00:00
|
|
|
class MyChild;
|
2009-03-14 01:01:12 +00:00
|
|
|
class MyCanvas;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// classes
|
|
|
|
// ---------------------------------------------------------------------------
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
public:
|
|
|
|
bool OnInit();
|
2002-06-19 09:16:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MyFrame : public wxMDIParentFrame
|
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
public:
|
|
|
|
MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
|
2002-06-19 09:16:19 +00:00
|
|
|
const wxPoint& pos, const wxSize& size, const long style);
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
void InitToolBar(wxToolBar* toolBar);
|
|
|
|
|
|
|
|
void OnSize(wxSizeEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
void OnNewWindow(wxCommandEvent& event);
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void FileSavePicture (wxCommandEvent& event);
|
2010-09-30 11:44:45 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
unsigned int GetCountOfChildren() const
|
|
|
|
{ return m_nWinCreated; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int m_nWinCreated;
|
2010-09-30 11:44:45 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2002-06-19 09:16:19 +00:00
|
|
|
};
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
class MyChild: public wxMDIChildFrame
|
2002-06-19 09:16:19 +00:00
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
public:
|
2010-09-30 11:44:45 +00:00
|
|
|
MyChild(wxMDIParentFrame *parent, const wxString& title,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
2009-03-14 01:01:12 +00:00
|
|
|
const long style = wxDEFAULT_FRAME_STYLE);
|
|
|
|
~MyChild();
|
|
|
|
|
|
|
|
void OnActivate(wxActivateEvent& event);
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
bool OnSave(wxString filename);
|
2010-09-30 11:44:45 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
MyFrame* GetFrame()
|
|
|
|
{ return m_frame; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
MyCanvas *m_canvas;
|
|
|
|
MyFrame *m_frame;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
2002-06-19 09:16:19 +00:00
|
|
|
};
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
class MyCanvas : public wxScrolledWindow
|
2002-06-19 09:16:19 +00:00
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
public:
|
|
|
|
MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size);
|
|
|
|
virtual void OnDraw(wxDC& dc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_index;
|
|
|
|
MyChild* m_child;
|
2010-09-30 11:44:45 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2002-06-19 09:16:19 +00:00
|
|
|
};
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2002-06-19 09:16:19 +00:00
|
|
|
// menu items ids
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MDI_QUIT = 100,
|
|
|
|
MDI_NEW_WINDOW,
|
|
|
|
MDI_SAVE,
|
|
|
|
MDI_REFRESH,
|
|
|
|
MDI_CHILD_QUIT,
|
|
|
|
MDI_ABOUT
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
|
2009-03-14 01:01:12 +00:00
|
|
|
EVT_MENU(MDI_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(MDI_NEW_WINDOW, MyFrame::OnNewWindow)
|
|
|
|
EVT_MENU(MDI_QUIT, MyFrame::OnQuit)
|
|
|
|
EVT_MENU (MDI_SAVE, MyFrame::FileSavePicture)
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
EVT_SIZE(MyFrame::OnSize)
|
2002-06-19 09:16:19 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// implementation
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2002-06-19 09:16:19 +00:00
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
// Create the main frame window
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
MyFrame* frame = new MyFrame((wxFrame *)NULL, -1, wxT("SVG Demo"),
|
|
|
|
wxDefaultPosition, wxSize(500, 400),
|
|
|
|
wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL);
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2004-07-19 15:14:07 +00:00
|
|
|
frame->Show(true);
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2005-08-23 16:02:51 +00:00
|
|
|
return true;
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define my frame constructor
|
|
|
|
MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
|
2009-03-14 01:01:12 +00:00
|
|
|
const wxPoint& pos, const wxSize& size, const long style)
|
2002-06-19 09:16:19 +00:00
|
|
|
: wxMDIParentFrame(parent, id, title, pos, size, style)
|
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
m_nWinCreated = 0;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2010-06-20 17:42:33 +00:00
|
|
|
SetIcon(wxICON(sample));
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
file_menu->Append(MDI_NEW_WINDOW, wxT("&New test\tCtrl+N"));
|
|
|
|
file_menu->Append(MDI_QUIT, wxT("&Exit\tAlt+X"));
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
wxMenu *help_menu = new wxMenu;
|
|
|
|
help_menu->Append(MDI_ABOUT, wxT("&About"));
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
menu_bar->Append(file_menu, wxT("&File"));
|
|
|
|
menu_bar->Append(help_menu, wxT("&Help"));
|
|
|
|
|
|
|
|
// Associate the menu bar with the frame
|
|
|
|
SetMenuBar(menu_bar);
|
|
|
|
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
CreateStatusBar();
|
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
|
|
|
|
CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL);
|
|
|
|
InitToolBar(GetToolBar());
|
|
|
|
}
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
(void)wxMessageBox(wxT("wxWidgets SVG sample\n")
|
|
|
|
wxT("Author: Chris Elliott (c) 2002-2009\n")
|
2010-09-30 11:44:45 +00:00
|
|
|
wxT("Usage: click File|New to show tests"),
|
2009-03-14 01:01:12 +00:00
|
|
|
wxT("About SVG Test"));
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
// Make another frame, containing a canvas
|
2009-03-14 01:01:12 +00:00
|
|
|
MyChild *subframe = new MyChild(this, wxT("SVG Frame"));
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
wxString title;
|
2009-03-14 01:01:12 +00:00
|
|
|
title.Printf(wxT("SVG Test Window %d"), m_nWinCreated );
|
2010-09-30 11:44:45 +00:00
|
|
|
|
2002-06-19 09:16:19 +00:00
|
|
|
// counts number of children previously, even if now closed
|
2009-03-14 01:01:12 +00:00
|
|
|
m_nWinCreated ++;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
// Give it a title and icon
|
|
|
|
subframe->SetTitle(title);
|
2010-06-20 17:42:33 +00:00
|
|
|
subframe->SetIcon(wxICON(sample));
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
|
|
|
|
file_menu->Append(MDI_NEW_WINDOW, wxT("&Another test\tCtrl+N"));
|
|
|
|
file_menu->Append(MDI_SAVE, wxT("&Save\tCtrl+S"), wxT("Save in SVG format"));
|
|
|
|
file_menu->Append(MDI_CHILD_QUIT, wxT("&Close child\tCtrl+F4"));
|
|
|
|
file_menu->Append(MDI_QUIT, wxT("&Exit\tAlt+X"));
|
|
|
|
|
|
|
|
wxMenu *help_menu = new wxMenu;
|
|
|
|
help_menu->Append(MDI_ABOUT, wxT("&About"));
|
|
|
|
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
|
|
|
|
|
|
|
menu_bar->Append(file_menu, wxT("&File"));
|
|
|
|
menu_bar->Append(help_menu, wxT("&Help"));
|
|
|
|
|
|
|
|
// Associate the menu bar with the frame
|
|
|
|
subframe->SetMenuBar(menu_bar);
|
|
|
|
|
2005-08-23 16:02:51 +00:00
|
|
|
subframe->Show(true);
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
2004-01-14 15:28:37 +00:00
|
|
|
void MyFrame::OnSize(wxSizeEvent& event)
|
2002-06-19 09:16:19 +00:00
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
GetClientSize(&w, &h);
|
|
|
|
|
|
|
|
GetClientWindow()->SetSize(0, 0, w, h);
|
2004-01-14 15:28:37 +00:00
|
|
|
event.Skip();
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::InitToolBar(wxToolBar* toolBar)
|
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
const int maxBitmaps = 3;
|
2002-06-19 09:16:19 +00:00
|
|
|
wxBitmap* bitmaps[maxBitmaps];
|
|
|
|
|
|
|
|
bitmaps[0] = new wxBitmap( new_xpm );
|
|
|
|
bitmaps[1] = new wxBitmap( save_xpm );
|
|
|
|
bitmaps[2] = new wxBitmap( help_xpm );
|
|
|
|
|
2008-07-05 18:23:01 +00:00
|
|
|
toolBar->AddTool(MDI_NEW_WINDOW, wxEmptyString, *(bitmaps[0]), wxS("New SVG test window"));
|
|
|
|
toolBar->AddTool(MDI_SAVE, wxEmptyString, *bitmaps[1], wxS("Save test in SVG format"));
|
2005-05-31 13:44:45 +00:00
|
|
|
toolBar->AddSeparator();
|
2008-07-05 18:23:01 +00:00
|
|
|
toolBar->AddTool(MDI_ABOUT, wxEmptyString, *bitmaps[2], wxS("Help"));
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
toolBar->Realize();
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < maxBitmaps; i++)
|
|
|
|
delete bitmaps[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::FileSavePicture (wxCommandEvent & WXUNUSED(event) )
|
|
|
|
{
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_FILEDLG
|
2009-03-14 01:01:12 +00:00
|
|
|
MyChild * pChild = (MyChild *)GetActiveChild();
|
2005-05-31 13:44:45 +00:00
|
|
|
if (pChild == NULL)
|
2002-06-19 09:16:19 +00:00
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
return;
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxFileDialog dialog(this, wxT("Save Picture as"), wxEmptyString, pChild->GetTitle(),
|
|
|
|
wxT("SVG vector picture files (*.svg)|*.svg"),
|
2006-05-28 23:32:12 +00:00
|
|
|
wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
if (!pChild->OnSave ( dialog.GetPath() ))
|
2002-06-19 09:16:19 +00:00
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
return;
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-14 01:01:12 +00:00
|
|
|
return;
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_FILEDLG
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyCanvas
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2002-06-19 09:16:19 +00:00
|
|
|
// Define a constructor for my canvas
|
2009-03-14 01:01:12 +00:00
|
|
|
MyCanvas::MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size)
|
|
|
|
: wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL)
|
2002-06-19 09:16:19 +00:00
|
|
|
{
|
2009-07-23 20:30:22 +00:00
|
|
|
SetBackgroundColour(wxColour(wxT("WHITE")));
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
m_child = parent;
|
|
|
|
m_index = m_child->GetFrame()->GetCountOfChildren() % 7;
|
|
|
|
}
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
// Define the repainting behaviour
|
|
|
|
void MyCanvas::OnDraw(wxDC& dc)
|
|
|
|
{
|
|
|
|
// vars to use ...
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
wxString s;
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
wxPen wP;
|
|
|
|
wxBrush wB;
|
2002-06-19 09:16:19 +00:00
|
|
|
wxPoint points[6];
|
|
|
|
wxColour wC;
|
2009-03-14 01:01:12 +00:00
|
|
|
wxFont wF;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
dc.SetFont(*wxSWISS_FONT);
|
|
|
|
dc.SetPen(*wxGREEN_PEN);
|
|
|
|
|
|
|
|
switch (m_index)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
// draw lines to make a cross
|
|
|
|
dc.DrawLine(0, 0, 200, 200);
|
|
|
|
dc.DrawLine(200, 0, 0, 200);
|
|
|
|
// draw point colored line and spline
|
2009-03-14 01:01:12 +00:00
|
|
|
wP = *wxCYAN_PEN;
|
2002-06-19 09:16:19 +00:00
|
|
|
wP.SetWidth(3);
|
|
|
|
dc.SetPen(wP);
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
dc.DrawPoint (25,15);
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.DrawLine(50, 30, 200, 30);
|
|
|
|
dc.DrawSpline(50, 200, 50, 100, 200, 10);
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
s = wxT("Green Cross, Cyan Line and spline");
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
break;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
case 1:
|
|
|
|
// draw standard shapes
|
|
|
|
dc.SetBrush(*wxCYAN_BRUSH);
|
|
|
|
dc.SetPen(*wxRED_PEN);
|
|
|
|
dc.DrawRectangle(10, 10, 100, 70);
|
2009-07-23 20:30:22 +00:00
|
|
|
wB = wxBrush (wxT("DARK ORCHID"), wxBRUSHSTYLE_TRANSPARENT);
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetBrush (wB);
|
|
|
|
dc.DrawRoundedRectangle(50, 50, 100, 70, 20);
|
2009-07-23 20:30:22 +00:00
|
|
|
dc.SetBrush (wxBrush(wxT("GOLDENROD")) );
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.DrawEllipse(100, 100, 100, 50);
|
|
|
|
|
|
|
|
points[0].x = 100; points[0].y = 200;
|
|
|
|
points[1].x = 70; points[1].y = 260;
|
|
|
|
points[2].x = 160; points[2].y = 230;
|
|
|
|
points[3].x = 40; points[3].y = 230;
|
|
|
|
points[4].x = 130; points[4].y = 260;
|
|
|
|
points[5].x = 100; points[5].y = 200;
|
|
|
|
|
|
|
|
dc.DrawPolygon(5, points);
|
|
|
|
dc.DrawLines (6, points, 160);
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars");
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
break;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
case 2:
|
|
|
|
// draw text in Arial or similar font
|
|
|
|
dc.DrawLine(50,25,50,35);
|
|
|
|
dc.DrawLine(45,30,55,30);
|
|
|
|
dc.DrawText(wxT("This is a Swiss-style string"), 50, 30);
|
2009-03-14 01:01:12 +00:00
|
|
|
wC = dc.GetTextForeground();
|
2009-07-23 20:30:22 +00:00
|
|
|
dc.SetTextForeground (wxT("FIREBRICK"));
|
2005-05-31 13:44:45 +00:00
|
|
|
|
2002-06-19 09:16:19 +00:00
|
|
|
// no effect in msw ??
|
2009-07-23 20:30:22 +00:00
|
|
|
dc.SetTextBackground (wxT("WHEAT"));
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.DrawText(wxT("This is a Red string"), 50, 200);
|
|
|
|
dc.DrawRotatedText(wxT("This is a 45 deg string"), 50, 200, 45);
|
|
|
|
dc.DrawRotatedText(wxT("This is a 90 deg string"), 50, 200, 90);
|
2005-08-23 16:02:51 +00:00
|
|
|
wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman"));
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetFont(wF);
|
2009-03-14 01:01:12 +00:00
|
|
|
dc.SetTextForeground (wC);
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.DrawText(wxT("This is a Times-style string"), 50, 60);
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
s = wxT("Swiss, Times text; red text, rotated and colored orange");
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
break;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
case 3 :
|
|
|
|
// four arcs start and end points, center
|
|
|
|
dc.SetBrush(*wxGREEN_BRUSH);
|
2003-09-15 12:28:11 +00:00
|
|
|
dc.DrawArc ( 200,300, 370,230, 300,300 );
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetBrush(*wxBLUE_BRUSH);
|
2003-09-15 12:28:11 +00:00
|
|
|
dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 );
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetDeviceOrigin(-10,-10);
|
2003-09-15 12:28:11 +00:00
|
|
|
dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 );
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetDeviceOrigin(0,0);
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
wP.SetColour (wxT("CADET BLUE"));
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetPen(wP);
|
2003-09-15 12:28:11 +00:00
|
|
|
dc.DrawArc ( 75,125, 110, 40, 75, 75 );
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
wP.SetColour (wxT("SALMON"));
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetPen(wP);
|
|
|
|
dc.SetBrush(*wxRED_BRUSH);
|
|
|
|
//top left corner, width and height, start and end angle
|
|
|
|
// 315 same center and x-radius as last pie-arc, half Y radius
|
2009-03-14 01:01:12 +00:00
|
|
|
dc.DrawEllipticArc(25,50,100,50,180.0,45.0);
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
wP = *wxCYAN_PEN;
|
2002-06-19 09:16:19 +00:00
|
|
|
wP.SetWidth(3);
|
|
|
|
dc.SetPen(wP);
|
|
|
|
//wxTRANSPARENT));
|
2009-07-23 20:30:22 +00:00
|
|
|
dc.SetBrush (wxBrush (wxT("SALMON")));
|
2009-03-14 01:01:12 +00:00
|
|
|
dc.DrawEllipticArc(300, 0,200,100, 0.0,145.0);
|
2002-06-19 09:16:19 +00:00
|
|
|
//same end point
|
2009-03-14 01:01:12 +00:00
|
|
|
dc.DrawEllipticArc(300, 50,200,100,90.0,145.0);
|
|
|
|
dc.DrawEllipticArc(300,100,200,100,90.0,345.0);
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
s = wxT("This is an arc test page");
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
break;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
case 4:
|
|
|
|
dc.DrawCheckMark ( 30,30,25,25);
|
2009-07-23 20:30:22 +00:00
|
|
|
dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT));
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.DrawCheckMark ( 80,50,75,75);
|
|
|
|
dc.DrawRectangle ( 80,50,75,75);
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
s = wxT("Two check marks");
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
break;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
case 5:
|
2005-08-23 16:02:51 +00:00
|
|
|
wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman"));
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetFont(wF);
|
|
|
|
dc.DrawLine(0, 0, 200, 200);
|
|
|
|
dc.DrawLine(200, 0, 0, 200);
|
|
|
|
dc.DrawText(wxT("This is an 18pt string"), 50, 60);
|
|
|
|
|
|
|
|
// rescale and draw in blue
|
2009-03-14 01:01:12 +00:00
|
|
|
wP = *wxCYAN_PEN;
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetPen(wP);
|
|
|
|
dc.SetUserScale (2.0,0.5);
|
|
|
|
dc.SetDeviceOrigin(200,0);
|
|
|
|
dc.DrawLine(0, 0, 200, 200);
|
|
|
|
dc.DrawLine(200, 0, 0, 200);
|
|
|
|
dc.DrawText(wxT("This is an 18pt string 2 x 0.5 UserScaled"), 50, 60);
|
|
|
|
dc.SetUserScale (2.0,2.0);
|
|
|
|
dc.SetDeviceOrigin(200,200);
|
|
|
|
dc.DrawText(wxT("This is an 18pt string 2 x 2 UserScaled"), 50, 60);
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
wP = *wxRED_PEN;
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.SetPen(wP);
|
|
|
|
dc.SetUserScale (1.0,1.0);
|
|
|
|
dc.SetDeviceOrigin(0,10);
|
2009-03-14 01:01:12 +00:00
|
|
|
dc.SetMapMode (wxMM_METRIC); //svg ignores this
|
2002-06-19 09:16:19 +00:00
|
|
|
dc.DrawLine(0, 0, 200, 200);
|
|
|
|
dc.DrawLine(200, 0, 0, 200);
|
2005-05-31 13:44:45 +00:00
|
|
|
dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60);
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
s = wxT("Scaling test page");
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
break;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
case 6:
|
2010-06-20 17:42:33 +00:00
|
|
|
dc.DrawIcon( wxICON(sample), 10, 10 );
|
2004-01-14 15:28:37 +00:00
|
|
|
dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15);
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
s = wxT("Icon and Bitmap ");
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2009-03-14 01:01:12 +00:00
|
|
|
break;
|
2002-06-19 09:16:19 +00:00
|
|
|
|
|
|
|
}
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
m_child->SetStatusText(s);
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyChild
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
// Note that MDI_NEW_WINDOW and MDI_ABOUT commands get passed
|
|
|
|
// to the parent window for processing, so no need to
|
|
|
|
// duplicate event handlers here.
|
|
|
|
BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
|
|
|
|
EVT_MENU(MDI_CHILD_QUIT, MyChild::OnQuit)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2002-06-19 09:16:19 +00:00
|
|
|
MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title,
|
2009-03-14 01:01:12 +00:00
|
|
|
const wxPoint& pos, const wxSize& size,
|
|
|
|
const long style)
|
|
|
|
: wxMDIChildFrame(parent, wxID_ANY, title, pos, size, style)
|
2002-06-19 09:16:19 +00:00
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
m_frame = (MyFrame *) parent;
|
2010-09-30 11:44:45 +00:00
|
|
|
|
2004-07-19 15:14:07 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
CreateStatusBar();
|
2005-05-31 13:44:45 +00:00
|
|
|
SetStatusText(title);
|
2004-07-19 15:14:07 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2002-06-19 09:16:19 +00:00
|
|
|
|
2009-03-14 01:01:12 +00:00
|
|
|
m_canvas = new MyCanvas(this, wxPoint(0, 0), GetClientSize());
|
2010-09-30 11:44:45 +00:00
|
|
|
|
2002-06-19 09:16:19 +00:00
|
|
|
// Give it scrollbars
|
|
|
|
m_canvas->SetScrollbars(20, 20, 50, 50);
|
|
|
|
}
|
|
|
|
|
|
|
|
MyChild::~MyChild()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-08-23 16:02:51 +00:00
|
|
|
Close(true);
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MyChild::OnSave(wxString filename)
|
|
|
|
{
|
2009-03-14 01:01:12 +00:00
|
|
|
wxSVGFileDC svgDC (filename, 600, 650);
|
2002-06-19 09:16:19 +00:00
|
|
|
m_canvas->OnDraw (svgDC);
|
2007-12-15 06:27:20 +00:00
|
|
|
return svgDC.IsOk();
|
2002-06-19 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnActivate(wxActivateEvent& event)
|
|
|
|
{
|
|
|
|
if ( event.GetActive() && m_canvas )
|
|
|
|
m_canvas->SetFocus();
|
|
|
|
}
|
|
|
|
|