]> git.saurik.com Git - wxWidgets.git/blob - samples/image/image.cpp
DnD fixes
[wxWidgets.git] / samples / image / image.cpp
1 /*
2 * Program: image
3 *
4 * Author: Robert Roebling
5 *
6 * Copyright: (C) 1998, Robert Roebling
7 *
8 */
9
10 #include "wx/wx.h"
11 #include "wx/image.h"
12
13 // derived classes
14
15 class MyFrame;
16 class MyApp;
17
18 // MyCanvas
19
20 class MyCanvas: public wxScrolledWindow
21 {
22 DECLARE_DYNAMIC_CLASS(MyCanvas)
23
24 public:
25
26 MyCanvas(void) {};
27 MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
28 ~MyCanvas(void);
29 void OnPaint( wxPaintEvent &event );
30
31 wxBitmap *my_horse;
32
33 DECLARE_EVENT_TABLE()
34 };
35
36 // MyFrame
37
38 class MyFrame: public wxFrame
39 {
40 DECLARE_DYNAMIC_CLASS(MyFrame)
41
42 public:
43
44 MyFrame(void);
45 void OnSize( wxSizeEvent &event );
46 void OnAbout( wxCommandEvent &event );
47 void OnQuit( wxCommandEvent &event );
48
49 MyCanvas *m_canvas;
50
51 DECLARE_EVENT_TABLE()
52 };
53
54 // MyApp
55
56 class MyApp: public wxApp
57 {
58 public:
59
60 MyApp(void);
61 virtual bool OnInit(void);
62 };
63
64 // main program
65
66 IMPLEMENT_APP(MyApp)
67
68 // MyCanvas
69
70 IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
71
72 BEGIN_EVENT_TABLE(MyCanvas,wxScrolledWindow)
73 EVT_PAINT (MyCanvas::OnPaint)
74 END_EVENT_TABLE()
75
76 MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, const wxSize &size )
77 : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
78 {
79 wxImage image;
80 image.LoadFile( "../horse.png", wxBITMAP_TYPE_PNG );
81 my_horse = new wxBitmap( image );
82
83 wxBitmap bitmap( 100, 100 );
84
85 wxMemoryDC dc;
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 );
91
92 image = bitmap.ConvertToImage();
93 image.SaveFile( "../test.png", wxBITMAP_TYPE_PNG );
94 }
95
96 MyCanvas::~MyCanvas(void)
97 {
98 delete my_horse;
99 }
100
101 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
102 {
103 wxPaintDC dc( this );
104 PrepareDC( dc );
105
106 dc.DrawBitmap( *my_horse, 30, 120 );
107 }
108
109 // MyFrame
110
111 const ID_QUIT = 108;
112 const ID_ABOUT = 109;
113
114 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
115
116 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
117 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
118 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
119 END_EVENT_TABLE()
120
121 MyFrame::MyFrame(void) :
122 wxFrame( (wxFrame *) NULL, -1, (char *) "Robert's Test application", wxPoint(20,20), wxSize(470,360) )
123 {
124 wxMenu *file_menu = new wxMenu();
125 file_menu->Append( ID_ABOUT, "About..");
126 file_menu->Append( ID_QUIT, "Exit");
127
128 wxMenuBar *menu_bar = new wxMenuBar();
129 menu_bar->Append(file_menu, "File");
130 menu_bar->Show( TRUE );
131
132 SetMenuBar( menu_bar );
133
134 m_canvas = new MyCanvas( this, -1, wxPoint(2,62), wxSize(300-4,120-4) );
135 m_canvas->SetScrollbars( 10, 10, 50, 50 );
136 }
137
138 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
139 {
140 Close( TRUE );
141 }
142
143 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
144 {
145 (void) wxMessageBox( "Image demo\nRobert Roebling (c) 1998", "About Image Demo", wxOK );
146 }
147
148 //-----------------------------------------------------------------------------
149 // MyApp
150 //-----------------------------------------------------------------------------
151
152 MyApp::MyApp(void) :
153 wxApp( )
154 {
155 }
156
157 bool MyApp::OnInit(void)
158 {
159 wxImage::AddHandler( new wxPNGHandler );
160
161 wxFrame *frame = new MyFrame();
162 frame->Show( TRUE );
163
164 return TRUE;
165 }
166
167
168
169
170