]> git.saurik.com Git - wxWidgets.git/blob - samples/rotate/rotate.cpp
compilation fixes.
[wxWidgets.git] / samples / rotate / rotate.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: test.cpp
3 // Purpose: Image rotation test
4 // Author: Carlos Moreno
5 // Modified by:
6 // Created: 6/2/2000
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22
23 #include "wx/image.h"
24
25 class MyApp: public wxApp
26 {
27 virtual bool OnInit();
28 };
29
30
31 class MyFrame: public wxFrame
32 {
33 public:
34 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
35
36 void OnQuit (wxCommandEvent &);
37 void OnMouseLeftUp (wxMouseEvent & event);
38 void OnMouseRightUp (wxMouseEvent & event);
39
40 private:
41 DECLARE_EVENT_TABLE()
42 };
43
44 enum
45 {
46 ID_Quit = 1
47 };
48
49 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
50 EVT_MENU (ID_Quit, MyFrame::OnQuit)
51 EVT_LEFT_UP (MyFrame::OnMouseLeftUp)
52 EVT_RIGHT_UP (MyFrame::OnMouseRightUp)
53 END_EVENT_TABLE()
54
55 IMPLEMENT_APP(MyApp)
56
57
58 bool MyApp::OnInit()
59 {
60 MyFrame *frame = new MyFrame ("wxWindows Skeleton", wxPoint(20,20), wxSize(600,450));
61
62 frame->SetBackgroundColour (wxColour (0,80,60));
63
64 frame->Show (TRUE);
65 SetTopWindow (frame);
66 return TRUE;
67 }
68
69 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
70 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
71 {
72 wxMenu *menuFile = new wxMenu;
73 menuFile->Append (ID_Quit, "E&xit");
74
75 wxMenuBar *menuBar = new wxMenuBar;
76 menuBar->Append (menuFile, "&File");
77
78 SetMenuBar (menuBar);
79 }
80
81 void MyFrame::OnQuit (wxCommandEvent &)
82 {
83 Close (TRUE);
84 }
85
86
87 // Rotate with interpolation and with offset correction
88 void MyFrame::OnMouseLeftUp (wxMouseEvent & event)
89 {
90 static double angle = 0.1;
91 const double pi = 3.14159265359;
92
93 wxImage img ("kclub.bmp", wxBITMAP_TYPE_BMP);
94
95 wxPoint offset;
96 wxImage img2 = img.Rotate(angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), TRUE, &offset);
97 angle += 0.05;
98
99 wxBitmap bmp = img2.ConvertToBitmap ();
100
101 wxClientDC dc (this);
102 dc.DrawBitmap (bmp, event.m_x + offset.x, event.m_y + offset.y);
103
104 return;
105 }
106
107 // without interpolation, and without offset correction
108 void MyFrame::OnMouseRightUp (wxMouseEvent & event)
109 {
110 static double angle = 0.1;
111 const double pi = 3.14159265359;
112
113 wxImage img ("kclub.bmp", wxBITMAP_TYPE_BMP);
114
115 wxImage img2 = img.Rotate(angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), FALSE);
116 angle += 0.05;
117
118 wxBitmap bmp = img2.ConvertToBitmap ();
119
120 wxClientDC dc (this);
121 dc.DrawBitmap (bmp, event.m_x, event.m_y);
122
123 return;
124 }