]>
git.saurik.com Git - wxWidgets.git/blob - samples/image/image.cpp
12ca058f16ae5a77d90fb96ef821ddbf968a6191
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 image
.SetRGB( 0, 0, 250, 0, 0 );
112 image
.SetRGB( 1, 0, 100, 100, 100 );
113 image
.SetRGB( 2, 0, 250, 250, 250 );
114 my_horse
= new wxBitmap( image
.ConvertToBitmap() );
116 image
.LoadFile( dir
+ wxString("test.png"), wxBITMAP_TYPE_PNG
);
117 my_square
= new wxBitmap( image
.ConvertToBitmap() );
120 MyCanvas::~MyCanvas(void)
126 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
128 wxPaintDC
dc( this );
131 dc
.DrawText( "Loaded image", 30, 100 );
132 if (my_square
->Ok()) dc
.DrawBitmap( *my_square
, 30, 120 );
134 dc
.DrawText( "Drawn directly", 150, 100 );
135 dc
.SetBrush( wxBrush( "orange", wxSOLID
) );
136 dc
.SetPen( *wxWHITE_PEN
);
137 dc
.DrawRectangle( 150, 120, 100, 100 );
139 if (my_horse
->Ok()) dc
.DrawBitmap( *my_horse
, 30, 240 );
144 const int ID_QUIT
= 108;
145 const int ID_ABOUT
= 109;
147 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
149 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
150 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
151 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
152 EVT_SIZE (MyFrame::OnSize
)
155 MyFrame::MyFrame(void) :
156 wxFrame( (wxFrame
*) NULL
, -1, "wxImage sample", wxPoint(20,20), wxSize(470,360) )
158 wxMenu
*file_menu
= new wxMenu();
159 file_menu
->Append( ID_ABOUT
, "About..");
160 file_menu
->Append( ID_QUIT
, "Exit");
162 wxMenuBar
*menu_bar
= new wxMenuBar();
163 menu_bar
->Append(file_menu
, "File");
165 SetMenuBar( menu_bar
);
168 int widths
[] = { -1, 100 };
169 SetStatusWidths( 2, widths
);
171 m_canvas
= new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
172 m_canvas
->SetScrollbars( 10, 10, 50, 50 );
175 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
180 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
182 (void) wxMessageBox( "wxImage demo\nRobert Roebling (c) 1998", "About wxImage Demo", wxOK
);
185 void MyFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
188 GetClientSize( &w
, &h
);
190 m_canvas
->SetSize( w
, h
);
193 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
202 bool MyApp::OnInit(void)
204 wxImage::AddHandler( new wxPNGHandler
);
206 wxFrame
*frame
= new MyFrame();