]> git.saurik.com Git - wxWidgets.git/blob - samples/image/image.cpp
final (?) changes to the generic tree ctrl -- seems to work ok
[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
84 MyCanvas::~MyCanvas(void)
85 {
86 delete my_horse;
87 }
88
89 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
90 {
91 wxPaintDC dc( this );
92 PrepareDC( dc );
93
94 dc.DrawBitmap( *my_horse, 30, 120 );
95 }
96
97 // MyFrame
98
99 const ID_QUIT = 108;
100 const ID_ABOUT = 109;
101
102 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
103
104 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
105 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
106 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
107 END_EVENT_TABLE()
108
109 MyFrame::MyFrame(void) :
110 wxFrame( (wxFrame *) NULL, -1, (char *) "Robert's Test application", wxPoint(20,20), wxSize(470,360) )
111 {
112 wxMenu *file_menu = new wxMenu();
113 file_menu->Append( ID_ABOUT, "About..");
114 file_menu->Append( ID_QUIT, "Exit");
115
116 wxMenuBar *menu_bar = new wxMenuBar();
117 menu_bar->Append(file_menu, "File");
118 menu_bar->Show( TRUE );
119
120 SetMenuBar( menu_bar );
121
122 m_canvas = new MyCanvas( this, -1, wxPoint(2,62), wxSize(300-4,120-4) );
123 m_canvas->SetScrollbars( 10, 10, 50, 50 );
124 }
125
126 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
127 {
128 Close( TRUE );
129 }
130
131 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
132 {
133 (void) wxMessageBox( "Image demo\nRobert Roebling (c) 1998", "About Image Demo", wxOK );
134 }
135
136 //-----------------------------------------------------------------------------
137 // MyApp
138 //-----------------------------------------------------------------------------
139
140 MyApp::MyApp(void) :
141 wxApp( )
142 {
143 }
144
145 bool MyApp::OnInit(void)
146 {
147 wxImage::AddHandler( new wxPNGHandler );
148
149 wxFrame *frame = new MyFrame();
150 frame->Show( TRUE );
151
152 return TRUE;
153 }
154
155
156
157
158