#include "wx/overlay.h"
#include "wx/graphics.h"
#include "wx/filename.h"
+#include "wx/metafile.h"
#define TEST_CAIRO_EVERYWHERE 0
#if wxUSE_GRAPHICS_CONTEXT
void OnGraphicContext(wxCommandEvent& event);
#endif
+ void OnCopy(wxCommandEvent& event);
+ void OnSave(wxCommandEvent& event);
void OnShow(wxCommandEvent &event);
void OnOption(wxCommandEvent &event);
#if wxUSE_GRAPHICS_CONTEXT
void UseGraphicContext(bool use) { m_useContext = use; Refresh(); }
#endif
+ template <typename T> void Draw(T& dc);
protected:
enum DrawMode
#if wxUSE_GRAPHICS_CONTEXT
File_GraphicContext,
#endif
+ File_Copy,
+ File_Save,
MenuOption_First,
// still continue, the sample can be used without images too if they're
// missing for whatever reason
}
+#if wxUSE_LIBPNG
+ wxImage::AddHandler( new wxPNGHandler );
+#endif
return true;
}
void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
{
wxPaintDC pdc(this);
+ Draw(pdc);
+}
+template <typename T>
+void MyCanvas::Draw(T& pdc)
+{
#if wxUSE_GRAPHICS_CONTEXT
#if TEST_CAIRO_EVERYWHERE
wxGCDC gdc;
#if wxUSE_GRAPHICS_CONTEXT
EVT_MENU (File_GraphicContext, MyFrame::OnGraphicContext)
#endif
+ EVT_MENU (File_Copy, MyFrame::OnCopy)
+ EVT_MENU (File_Save, MyFrame::OnSave)
EVT_MENU_RANGE(MenuShow_First, MenuShow_Last, MyFrame::OnShow)
#if wxUSE_GRAPHICS_CONTEXT
menuFile->Append(File_ShowAlpha, wxT("&Alpha screen\tF10"));
#endif
- menuFile->Append(File_ShowSplines, wxT("&Splines screen\tF11"));
+ menuFile->Append(File_ShowSplines, wxT("Spl&ines screen\tF11"));
menuFile->Append(File_ShowGradients, wxT("&Gradients screen\tF12"));
#if wxUSE_GRAPHICS_CONTEXT
menuFile->Append(File_ShowGraphics, wxT("&Graphics screen"));
menuFile->AppendCheckItem(File_GraphicContext, wxT("&Use GraphicContext\tCtrl-Y"), wxT("Use GraphicContext"));
#endif
menuFile->AppendSeparator();
+#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
+ menuFile->Append(File_Copy, wxT("Copy to clipboard"));
+#endif
+ menuFile->Append(File_Save, wxT("&Save...\tCtrl-S"), wxT("Save drawing to file"));
+ menuFile->AppendSeparator();
menuFile->Append(File_About, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
menuFile->AppendSeparator();
menuFile->Append(File_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
}
#endif
+void MyFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
+{
+#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
+ wxMetafileDC dc;
+ if (!dc.IsOk())
+ return;
+ m_canvas->Draw(dc);
+ wxMetafile *mf = dc.Close();
+ if (!mf)
+ return;
+ mf->SetClipboard();
+ delete mf;
+#endif
+}
+
+void MyFrame::OnSave(wxCommandEvent& WXUNUSED(event))
+{
+ wxFileDialog dlg(this, wxT("Save as bitmap"), wxT(""), wxT(""),
+#if wxUSE_LIBPNG
+ wxT("PNG image (*.png)|*.png;*.PNG|")
+#endif
+ wxT("Bitmap image (*.bmp)|*.bmp;*.BMP"),
+ wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
+ if (dlg.ShowModal() == wxID_OK)
+ {
+ wxBitmap bmp(500, 800);
+ wxMemoryDC mdc(bmp);
+ m_canvas->Draw(mdc);
+ bmp.ConvertToImage().SaveFile(dlg.GetPath());
+ }
+}
+
void MyFrame::OnShow(wxCommandEvent& event)
{
m_canvas->ToShow(event.GetId());