]>
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
);
39 class MyFrame
: public wxFrame
41 DECLARE_DYNAMIC_CLASS(MyFrame
)
46 void OnSize( wxSizeEvent
&event
);
47 void OnAbout( wxCommandEvent
&event
);
48 void OnQuit( wxCommandEvent
&event
);
57 class MyApp
: public wxApp
62 virtual bool OnInit(void);
71 IMPLEMENT_DYNAMIC_CLASS(MyCanvas
, wxScrolledWindow
)
73 BEGIN_EVENT_TABLE(MyCanvas
,wxScrolledWindow
)
74 EVT_PAINT (MyCanvas::OnPaint
)
77 MyCanvas::MyCanvas( wxWindow
*parent
, const wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
78 : wxScrolledWindow( parent
, id
, pos
, size
, wxSUNKEN_BORDER
)
82 wxBitmap
bitmap( 100, 100 );
85 dc
.SelectObject( bitmap
);
86 dc
.SetBrush( wxBrush( "orange", wxSOLID
) );
87 dc
.SetPen( *wxWHITE_PEN
);
88 dc
.DrawRectangle( 0, 0, 100, 100 );
89 dc
.SelectObject( wxNullBitmap
);
91 image
= bitmap
.ConvertToImage();
92 image
.SaveFile( "../test.png", wxBITMAP_TYPE_PNG
);
94 image
.LoadFile( "../horse.png", wxBITMAP_TYPE_PNG
);
95 my_horse
= new wxBitmap( image
);
97 image
.LoadFile( "../test.png", wxBITMAP_TYPE_PNG
);
98 my_square
= new wxBitmap( image
);
101 MyCanvas::~MyCanvas(void)
107 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
109 wxPaintDC
dc( this );
112 dc
.DrawText( "Loaded image", 30, 100 );
113 if (my_square
->Ok()) dc
.DrawBitmap( *my_square
, 30, 120 );
115 dc
.DrawText( "Drawn directly", 150, 100 );
116 dc
.SetBrush( wxBrush( "orange", wxSOLID
) );
117 dc
.SetPen( *wxWHITE_PEN
);
118 dc
.DrawRectangle( 150, 120, 100, 100 );
120 if (my_horse
->Ok()) dc
.DrawBitmap( *my_horse
, 30, 240 );
126 const ID_ABOUT
= 109;
128 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
130 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
131 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
132 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
135 MyFrame::MyFrame(void) :
136 wxFrame( (wxFrame
*) NULL
, -1, "wxImage sample", wxPoint(20,20), wxSize(470,360) )
138 wxMenu
*file_menu
= new wxMenu();
139 file_menu
->Append( ID_ABOUT
, "About..");
140 file_menu
->Append( ID_QUIT
, "Exit");
142 wxMenuBar
*menu_bar
= new wxMenuBar();
143 menu_bar
->Append(file_menu
, "File");
144 menu_bar
->Show( TRUE
);
146 SetMenuBar( menu_bar
);
149 int widths
[] = { -1, 100 };
150 SetStatusWidths( 2, widths
);
152 m_canvas
= new MyCanvas( this, -1, wxPoint(2,62), wxSize(300-4,120-4) );
153 m_canvas
->SetScrollbars( 10, 10, 50, 50 );
156 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
161 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
163 (void) wxMessageBox( "wxImage demo\nRobert Roebling (c) 1998", "About wxImage Demo", wxOK
);
166 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
175 bool MyApp::OnInit(void)
177 wxImage::AddHandler( new wxPNGHandler
);
179 wxFrame
*frame
= new MyFrame();