]>
git.saurik.com Git - wxWidgets.git/blob - samples/image/image.cpp
4 * Author: Robert Roebling
6 * Copyright: (C) 1998, Robert Roebling
20 class MyCanvas
: public wxScrolledWindow
22 DECLARE_DYNAMIC_CLASS(MyCanvas
)
27 MyCanvas( wxWindow
*parent
, wxWindowID
, const wxPoint
&pos
, const wxSize
&size
);
29 void OnPaint( wxPaintEvent
&event
);
38 class MyFrame
: public wxFrame
40 DECLARE_DYNAMIC_CLASS(MyFrame
)
45 void OnSize( wxSizeEvent
&event
);
46 void OnAbout( wxCommandEvent
&event
);
47 void OnQuit( wxCommandEvent
&event
);
56 class MyApp
: public wxApp
61 virtual bool OnInit(void);
70 IMPLEMENT_DYNAMIC_CLASS(MyCanvas
, wxScrolledWindow
)
72 BEGIN_EVENT_TABLE(MyCanvas
,wxScrolledWindow
)
73 EVT_PAINT (MyCanvas::OnPaint
)
76 MyCanvas::MyCanvas( wxWindow
*parent
, const wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
77 : wxScrolledWindow( parent
, id
, pos
, size
, wxSUNKEN_BORDER
)
80 image
.LoadFile( "../horse.png", wxBITMAP_TYPE_PNG
);
81 my_horse
= new wxBitmap( image
);
83 wxBitmap
bitmap( 100, 100 );
86 dc
.SelectObject( bitmap
);
87 dc
.SetBrush( wxRED_BRUSH
);
88 dc
.SetPen( wxWHITE_PEN
);
89 dc
.DrawRectangle( 0, 0, 100, 100 );
90 dc
.SelectObject( wxNullBitmap
);
92 image
= bitmap
.ConvertToImage();
93 image
.SaveFile( "../test.png", wxBITMAP_TYPE_PNG
);
96 MyCanvas::~MyCanvas(void)
101 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
103 wxPaintDC
dc( this );
106 dc
.DrawBitmap( *my_horse
, 30, 120 );
112 const ID_ABOUT
= 109;
114 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
116 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
117 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
118 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
121 MyFrame::MyFrame(void) :
122 wxFrame( (wxFrame
*) NULL
, -1, (char *) "Robert's Test application", wxPoint(20,20), wxSize(470,360) )
124 wxMenu
*file_menu
= new wxMenu();
125 file_menu
->Append( ID_ABOUT
, "About..");
126 file_menu
->Append( ID_QUIT
, "Exit");
128 wxMenuBar
*menu_bar
= new wxMenuBar();
129 menu_bar
->Append(file_menu
, "File");
130 menu_bar
->Show( TRUE
);
132 SetMenuBar( menu_bar
);
134 m_canvas
= new MyCanvas( this, -1, wxPoint(2,62), wxSize(300-4,120-4) );
135 m_canvas
->SetScrollbars( 10, 10, 50, 50 );
138 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
143 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
145 (void) wxMessageBox( "Image demo\nRobert Roebling (c) 1998", "About Image Demo", wxOK
);
148 //-----------------------------------------------------------------------------
150 //-----------------------------------------------------------------------------
157 bool MyApp::OnInit(void)
159 wxImage::AddHandler( new wxPNGHandler
);
161 wxFrame
*frame
= new MyFrame();