#include "wx/colordlg.h"
#include "wx/image.h"
+#include "wx/artprov.h"
// ----------------------------------------------------------------------------
// ressources
// ----------------------------------------------------------------------------
// the application icon
-#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
+#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
#include "mondrian.xpm"
#endif
// event handlers (these functions should _not_ be virtual)
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
+ void OnClip(wxCommandEvent& event);
void OnShow(wxCommandEvent &event);
void OnOption(wxCommandEvent &event);
void Show(ScreenToShow show) { m_show = show; Refresh(); }
+ // set or remove the clipping region
+ void Clip(bool clip) { m_clip = clip; Refresh(); }
+
protected:
void DrawTestLines( int x, int y, int width, wxDC &dc );
void DrawTestPoly(wxDC& dc);
ScreenToShow m_show;
wxBitmap m_smile_bmp;
wxIcon m_std_icon;
+ bool m_clip;
DECLARE_EVENT_TABLE()
};
File_ShowCircles,
MenuShow_Last = File_ShowCircles,
+ File_Clip,
+
MenuOption_First,
MapMode_Text = MenuOption_First,
LogicalOrigin_MoveUp,
LogicalOrigin_MoveLeft,
LogicalOrigin_MoveRight,
+ LogicalOrigin_Set,
+ LogicalOrigin_Restore,
Colour_TextForeground,
Colour_TextBackground,
m_owner = parent;
m_show = Show_Default;
m_smile_bmp = wxBitmap(smile_xpm);
- m_std_icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
+ m_std_icon = wxArtProvider::GetIcon(wxART_INFORMATION);
}
void MyCanvas::DrawTestBrushes(wxDC& dc)
{
// mark the origin
dc.DrawCircle(0, 0, 10);
-#if !(defined __WXGTK__) && !(defined __WXMOTIF__) && !(defined __WXMGL__)
- // not implemented in wxGTK or wxMOTIF :-(
- dc.FloodFill(0, 0, wxColour(255, 0, 0));
-#endif //
+
+ //flood fill using brush, starting at 1,1 and replacing whatever colour we find there
+ dc.SetBrush(wxBrush(wxColour(128,128,0), wxSOLID));
+ wxColour tmpColour ;
+ dc.GetPixel(1,1, &tmpColour);
+ dc.FloodFill(1,1, tmpColour, wxFLOOD_SURFACE);
dc.DrawCheckMark(5, 80, 15, 15);
dc.DrawCheckMark(25, 80, 30, 30);
memdc.SelectObject( wxNullBitmap );
dc.DrawBitmap( bitmap, 10, 170 );
- wxImage image( bitmap );
+ wxImage image = bitmap.ConvertToImage();
image.Rescale( 60,210 );
- bitmap = image.ConvertToBitmap();
+ bitmap = wxBitmap(image);
dc.DrawBitmap( bitmap, 50, 170 );
// test the rectangle outline drawing - there should be one pixel between
dc.DestroyClippingRegion();
wxRegion region(x + 110, y + 20, 100, 270);
+#if !defined(__WXMOTIF__) && !defined(__WXMAC__)
if ( !firstTime )
region.Offset(10, 10);
-
+#endif
dc.SetClippingRegion(region);
dc.SetBrush( *wxGREY_BRUSH );
}
}
+ if ( m_clip )
+ dc.SetClippingRegion(100, 100, 100, 100);
+
dc.Clear();
- if ( m_owner->m_textureBackground) {
+ if ( m_owner->m_textureBackground )
+ {
dc.SetPen(*wxMEDIUM_GREY_PEN);
- for (int i=0; i<200; i++)
+ for ( int i = 0; i < 200; i++ )
dc.DrawLine(0, i*10, i*10, 0);
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU (File_Quit, MyFrame::OnQuit)
EVT_MENU (File_About, MyFrame::OnAbout)
+ EVT_MENU (File_Clip, MyFrame::OnClip)
EVT_MENU_RANGE(MenuShow_First, MenuShow_Last, MyFrame::OnShow)
menuFile->Append(File_ShowRegions, "Re&gions screen\tF8");
menuFile->Append(File_ShowCircles, "&Circles screen\tF9");
menuFile->AppendSeparator();
+ menuFile->AppendCheckItem(File_Clip, "&Clip\tCtrl-C", "Clip/unclip drawing");
+ menuFile->AppendSeparator();
menuFile->Append(File_About, "&About...\tCtrl-A", "Show about dialog");
menuFile->AppendSeparator();
menuFile->Append(File_Quit, "E&xit\tAlt-X", "Quit this program");
menuMapMode->Append( MapMode_Metric, "&METRIC map mode" );
wxMenu *menuUserScale = new wxMenu;
- menuUserScale->Append( UserScale_StretchHoriz, "Stretch horizontally\tCtrl-H" );
- menuUserScale->Append( UserScale_ShrinkHoriz, "Shrink horizontally\tCtrl-G" );
- menuUserScale->Append( UserScale_StretchVertic, "Stretch vertically\tCtrl-V" );
- menuUserScale->Append( UserScale_ShrinkVertic, "Shrink vertically\tCtrl-W" );
+ menuUserScale->Append( UserScale_StretchHoriz, "Stretch &horizontally\tCtrl-H" );
+ menuUserScale->Append( UserScale_ShrinkHoriz, "Shrin&k horizontally\tCtrl-G" );
+ menuUserScale->Append( UserScale_StretchVertic, "Stretch &vertically\tCtrl-V" );
+ menuUserScale->Append( UserScale_ShrinkVertic, "&Shrink vertically\tCtrl-W" );
menuUserScale->AppendSeparator();
- menuUserScale->Append( UserScale_Restore, "Restore to normal\tCtrl-0" );
+ menuUserScale->Append( UserScale_Restore, "&Restore to normal\tCtrl-0" );
wxMenu *menuAxis = new wxMenu;
menuAxis->Append( AxisMirror_Horiz, "Mirror horizontally\tCtrl-M", "", TRUE );
menuLogical->Append( LogicalOrigin_MoveUp, "Move &up\tCtrl-U" );
menuLogical->Append( LogicalOrigin_MoveLeft, "Move &right\tCtrl-L" );
menuLogical->Append( LogicalOrigin_MoveRight, "Move &left\tCtrl-R" );
+ menuLogical->AppendSeparator();
+ menuLogical->Append( LogicalOrigin_Set, "Set to (&100, 100)\tShift-Ctrl-1" );
+ menuLogical->Append( LogicalOrigin_Restore, "&Restore to normal\tShift-Ctrl-0" );
wxMenu *menuColour = new wxMenu;
- menuColour->Append( Colour_TextForeground, "Text foreground..." );
- menuColour->Append( Colour_TextBackground, "Text background..." );
- menuColour->Append( Colour_Background, "Background colour..." );
- menuColour->Append( Colour_BackgroundMode, "Opaque/transparent\tCtrl-B", "", TRUE );
- menuColour->Append( Colour_TextureBackgound, "Draw textured background\tCtrl-T", "", TRUE);
+ menuColour->Append( Colour_TextForeground, "Text &foreground..." );
+ menuColour->Append( Colour_TextBackground, "Text &background..." );
+ menuColour->Append( Colour_Background, "Background &colour..." );
+ menuColour->Append( Colour_BackgroundMode, "&Opaque/transparent\tCtrl-B", "", TRUE );
+ menuColour->Append( Colour_TextureBackgound, "Draw textured back&ground\tCtrl-T", "", TRUE);
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&File");
- menuBar->Append(menuMapMode, "&MapMode");
- menuBar->Append(menuUserScale, "&UserScale");
+ menuBar->Append(menuMapMode, "&Mode");
+ menuBar->Append(menuUserScale, "&Scale");
menuBar->Append(menuAxis, "&Axis");
- menuBar->Append(menuLogical, "&LogicalOrigin");
+ menuBar->Append(menuLogical, "&Origin");
menuBar->Append(menuColour, "&Colours");
// ... and attach this menu bar to the frame
wxMessageBox(msg, "About Drawing", wxOK | wxICON_INFORMATION, this);
}
+void MyFrame::OnClip(wxCommandEvent& event)
+{
+ m_canvas->Clip(event.IsChecked());
+}
+
void MyFrame::OnShow(wxCommandEvent& event)
{
m_canvas->Show((ScreenToShow)(event.GetId() - MenuShow_First));
case LogicalOrigin_MoveRight:
m_xLogicalOrigin -= 10;
break;
+ case LogicalOrigin_Set:
+ m_xLogicalOrigin =
+ m_yLogicalOrigin = -100;
+ break;
+ case LogicalOrigin_Restore:
+ m_xLogicalOrigin =
+ m_yLogicalOrigin = 0;
+ break;
case UserScale_StretchHoriz:
m_xUserScale *= 1.10;
void MyFrame::PrepareDC(wxDC& dc)
{
- dc.SetMapMode( m_mapMode );
- dc.SetUserScale( m_xUserScale, m_yUserScale );
dc.SetLogicalOrigin( m_xLogicalOrigin, m_yLogicalOrigin );
dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed );
+ dc.SetUserScale( m_xUserScale, m_yUserScale );
+ dc.SetMapMode( m_mapMode );
}
wxColour MyFrame::SelectColour()