]>
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
)
80 wxBitmap
bitmap( 100, 100 );
83 dc
.SelectObject( bitmap
);
84 dc
.SetBrush( wxBrush( "orange", wxSOLID
) );
85 dc
.SetPen( *wxWHITE_PEN
);
86 dc
.DrawRectangle( 0, 0, 100, 100 );
87 dc
.SelectObject( wxNullBitmap
);
89 wxImage
image( bitmap
);
90 image
.SaveFile( "../test.png", wxBITMAP_TYPE_PNG
);
92 image
.LoadFile( "../horse.png", wxBITMAP_TYPE_PNG
);
93 my_horse
= new wxBitmap( image
.ConvertToBitmap() );
95 image
.LoadFile( "../test.png", wxBITMAP_TYPE_PNG
);
96 my_square
= new wxBitmap( image
.ConvertToBitmap() );
99 MyCanvas::~MyCanvas(void)
105 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
107 wxPaintDC
dc( this );
110 dc
.DrawText( "Loaded image", 30, 100 );
111 if (my_square
->Ok()) dc
.DrawBitmap( *my_square
, 30, 120 );
113 dc
.DrawText( "Drawn directly", 150, 100 );
114 dc
.SetBrush( wxBrush( "orange", wxSOLID
) );
115 dc
.SetPen( *wxWHITE_PEN
);
116 dc
.DrawRectangle( 150, 120, 100, 100 );
118 if (my_horse
->Ok()) dc
.DrawBitmap( *my_horse
, 30, 240 );
123 const int ID_QUIT
= 108;
124 const int ID_ABOUT
= 109;
126 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
128 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
129 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
130 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
131 EVT_SIZE (MyFrame::OnSize
)
134 MyFrame::MyFrame(void) :
135 wxFrame( (wxFrame
*) NULL
, -1, "wxImage sample", wxPoint(20,20), wxSize(470,360) )
137 wxMenu
*file_menu
= new wxMenu();
138 file_menu
->Append( ID_ABOUT
, "About..");
139 file_menu
->Append( ID_QUIT
, "Exit");
141 wxMenuBar
*menu_bar
= new wxMenuBar();
142 menu_bar
->Append(file_menu
, "File");
143 menu_bar
->Show( TRUE
);
145 SetMenuBar( menu_bar
);
148 int widths
[] = { -1, 100 };
149 SetStatusWidths( 2, widths
);
151 m_canvas
= new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
152 m_canvas
->SetScrollbars( 10, 10, 50, 50 );
155 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
160 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
162 (void) wxMessageBox( "wxImage demo\nRobert Roebling (c) 1998", "About wxImage Demo", wxOK
);
165 void MyFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
168 GetClientSize( &w
, &h
);
169 m_canvas
->SetSize( w
, h
);
172 //-----------------------------------------------------------------------------
174 //-----------------------------------------------------------------------------
181 bool MyApp::OnInit(void)
183 wxImage::AddHandler( new wxPNGHandler
);
185 wxFrame
*frame
= new MyFrame();