]>
git.saurik.com Git - wxWidgets.git/blob - samples/image/image.cpp
3546f1f1e67ddb855ab9915f583301be3295a495
4 * Author: Robert Roebling
6 * Copyright: (C) 1998, Robert Roebling
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
30 class MyCanvas
: public wxScrolledWindow
32 DECLARE_DYNAMIC_CLASS(MyCanvas
)
37 MyCanvas( wxWindow
*parent
, wxWindowID
, const wxPoint
&pos
, const wxSize
&size
);
39 void OnPaint( wxPaintEvent
&event
);
49 class MyFrame
: public wxFrame
51 DECLARE_DYNAMIC_CLASS(MyFrame
)
56 void OnSize( wxSizeEvent
&event
);
57 void OnAbout( wxCommandEvent
&event
);
58 void OnQuit( wxCommandEvent
&event
);
67 class MyApp
: public wxApp
72 virtual bool OnInit(void);
81 IMPLEMENT_DYNAMIC_CLASS(MyCanvas
, wxScrolledWindow
)
83 BEGIN_EVENT_TABLE(MyCanvas
,wxScrolledWindow
)
84 EVT_PAINT (MyCanvas::OnPaint
)
87 MyCanvas::MyCanvas( wxWindow
*parent
, const wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
88 : wxScrolledWindow( parent
, id
, pos
, size
, wxSUNKEN_BORDER
)
90 SetBackgroundColour(* wxWHITE
);
92 wxBitmap
bitmap( 100, 100 );
95 dc
.SelectObject( bitmap
);
96 dc
.SetBrush( wxBrush( "orange", wxSOLID
) );
97 dc
.SetPen( *wxWHITE_PEN
);
98 dc
.DrawRectangle( 0, 0, 100, 100 );
99 dc
.SelectObject( wxNullBitmap
);
104 dir
= wxString("../");
107 wxImage
image( bitmap
);
108 image
.SaveFile( dir
+ wxString("test.png"), wxBITMAP_TYPE_PNG
);
110 image
.LoadFile( dir
+ wxString("horse.png"), wxBITMAP_TYPE_PNG
);
111 my_horse
= new wxBitmap( image
.ConvertToBitmap() );
113 image
.LoadFile( dir
+ wxString("test.png"), wxBITMAP_TYPE_PNG
);
114 my_square
= new wxBitmap( image
.ConvertToBitmap() );
117 MyCanvas::~MyCanvas(void)
123 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
125 wxPaintDC
dc( this );
128 dc
.DrawText( "Loaded image", 30, 100 );
129 if (my_square
->Ok()) dc
.DrawBitmap( *my_square
, 30, 120 );
131 dc
.DrawText( "Drawn directly", 150, 100 );
132 dc
.SetBrush( wxBrush( "orange", wxSOLID
) );
133 dc
.SetPen( *wxWHITE_PEN
);
134 dc
.DrawRectangle( 150, 120, 100, 100 );
136 if (my_horse
->Ok()) dc
.DrawBitmap( *my_horse
, 30, 240 );
141 const int ID_QUIT
= 108;
142 const int ID_ABOUT
= 109;
144 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
146 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
147 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
148 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
149 EVT_SIZE (MyFrame::OnSize
)
152 MyFrame::MyFrame(void) :
153 wxFrame( (wxFrame
*) NULL
, -1, "wxImage sample", wxPoint(20,20), wxSize(470,360) )
155 wxMenu
*file_menu
= new wxMenu();
156 file_menu
->Append( ID_ABOUT
, "About..");
157 file_menu
->Append( ID_QUIT
, "Exit");
159 wxMenuBar
*menu_bar
= new wxMenuBar();
160 menu_bar
->Append(file_menu
, "File");
162 SetMenuBar( menu_bar
);
165 int widths
[] = { -1, 100 };
166 SetStatusWidths( 2, widths
);
168 m_canvas
= new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
169 m_canvas
->SetScrollbars( 10, 10, 50, 50 );
172 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
177 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
179 (void) wxMessageBox( "wxImage demo\nRobert Roebling (c) 1998", "About wxImage Demo", wxOK
);
182 void MyFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
185 GetClientSize( &w
, &h
);
187 m_canvas
->SetSize( w
, h
);
190 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
199 bool MyApp::OnInit(void)
201 wxImage::AddHandler( new wxPNGHandler
);
203 wxFrame
*frame
= new MyFrame();