]> git.saurik.com Git - wxWidgets.git/blob - samples/rotate/rotate.cpp
Added rotation to wxImage
[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 #include "wx/image.h"
20
21 class MyApp: public wxApp
22 {
23 virtual bool OnInit();
24 };
25
26
27 class MyFrame: public wxFrame
28 {
29 public:
30 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
31
32 void OnQuit (wxCommandEvent &);
33 void OnMouseLeftUp (wxMouseEvent & event);
34 void OnMouseRightUp (wxMouseEvent & event);
35
36 private:
37 DECLARE_EVENT_TABLE()
38 };
39
40 enum
41 {
42 ID_Quit = 1
43 };
44
45 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
46 EVT_MENU (ID_Quit, MyFrame::OnQuit)
47 EVT_LEFT_UP (MyFrame::OnMouseLeftUp)
48 EVT_RIGHT_UP (MyFrame::OnMouseRightUp)
49 END_EVENT_TABLE()
50
51 IMPLEMENT_APP(MyApp)
52
53
54 bool MyApp::OnInit()
55 {
56 MyFrame *frame = new MyFrame ("wxWindows Skeleton", wxPoint(20,20), wxSize(600,450));
57
58 frame->SetBackgroundColour (wxColour (0,80,60));
59
60 frame->Show (TRUE);
61 SetTopWindow (frame);
62 return TRUE;
63 }
64
65 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
66 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
67 {
68 wxMenu *menuFile = new wxMenu;
69 menuFile->Append (ID_Quit, "E&xit");
70
71 wxMenuBar *menuBar = new wxMenuBar;
72 menuBar->Append (menuFile, "&File");
73
74 SetMenuBar (menuBar);
75 }
76
77 void MyFrame::OnQuit (wxCommandEvent &)
78 {
79 Close (TRUE);
80 }
81
82
83 // Rotate with interpolation and with offset correction
84 void MyFrame::OnMouseLeftUp (wxMouseEvent & event)
85 {
86 static double angle = 0.1;
87 const double pi = 3.14159265359;
88
89 wxImage img ("kclub.bmp", wxBITMAP_TYPE_BMP);
90
91 wxPoint offset;
92 wxImage img2 = img.Rotate(angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), TRUE, &offset);
93 angle += 0.05;
94
95 wxBitmap bmp = img2.ConvertToBitmap ();
96
97 wxClientDC dc (this);
98 dc.DrawBitmap (bmp, event.m_x + offset.x, event.m_y + offset.y);
99
100 return;
101 }
102
103 // without interpolation, and without offset correction
104 void MyFrame::OnMouseRightUp (wxMouseEvent & event)
105 {
106 static double angle = 0.1;
107 const double pi = 3.14159265359;
108
109 wxImage img ("kclub.bmp", wxBITMAP_TYPE_BMP);
110
111 wxImage img2 = img.Rotate(angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), FALSE);
112 angle += 0.05;
113
114 wxBitmap bmp = img2.ConvertToBitmap ();
115
116 wxClientDC dc (this);
117 dc.DrawBitmap (bmp, event.m_x, event.m_y);
118
119 return;
120 }