]>
git.saurik.com Git - wxWidgets.git/blob - samples/rotate/rotate.cpp
4b309651bdb2f8dc6b9018a5bef0a8c79f759426
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Image rotation test
4 // Author: Carlos Moreno
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
25 /* GRG: This is not ANSI standard, define M_PI explicitly
26 #include <math.h> // M_PI
30 #define M_PI 3.1415926535897932384626433832795
34 class MyApp
: public wxApp
37 virtual bool OnInit();
39 const wxImage
& GetImage() const { return m_image
; }
46 class MyFrame
: public wxFrame
49 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
51 void OnQuit (wxCommandEvent
&);
52 void OnAngle(wxCommandEvent
&);
53 void OnMouseLeftUp (wxMouseEvent
& event
);
54 void OnMouseRightUp (wxMouseEvent
& event
);
68 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
69 EVT_MENU (ID_Quit
, MyFrame::OnQuit
)
70 EVT_MENU (ID_Angle
, MyFrame::OnAngle
)
71 EVT_LEFT_UP (MyFrame::OnMouseLeftUp
)
72 EVT_RIGHT_UP (MyFrame::OnMouseRightUp
)
80 m_image
= wxImage("kclub.bmp", wxBITMAP_TYPE_BMP
);
83 wxLogError("Can't load the test image, please copy it to the "
88 MyFrame
*frame
= new MyFrame ("wxWindows rotate sample",
89 wxPoint(20,20), wxSize(600,450));
91 frame
->SetBackgroundColour (wxColour (0,80,60));
98 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
99 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
103 wxMenu
*menuFile
= new wxMenu
;
104 menuFile
->Append (ID_Angle
, "Set &angle\tCtrl-A");
105 menuFile
->AppendSeparator();
106 menuFile
->Append (ID_Quit
, "E&xit\tAlt-X");
108 wxMenuBar
*menuBar
= new wxMenuBar
;
109 menuBar
->Append (menuFile
, "&File");
111 SetMenuBar (menuBar
);
114 void MyFrame::OnAngle (wxCommandEvent
&)
116 long degrees
= (long)((180*m_angle
)/M_PI
);
117 degrees
= wxGetNumberFromUser("Change the image rotation angle",
119 "wxWindows rotate sample",
123 m_angle
= (degrees
* M_PI
) / 180.0;
126 void MyFrame::OnQuit (wxCommandEvent
&)
132 // Rotate with interpolation and with offset correction
133 void MyFrame::OnMouseLeftUp (wxMouseEvent
& event
)
136 const wxImage
& img
= wxGetApp().GetImage();
137 wxImage img2
= img
.Rotate(m_angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), TRUE
, &offset
);
139 wxBitmap bmp
= img2
.ConvertToBitmap ();
141 wxClientDC
dc (this);
142 dc
.DrawBitmap (img2
.ConvertToBitmap(), event
.m_x
+ offset
.x
, event
.m_y
+ offset
.y
);
145 // without interpolation, and without offset correction
146 void MyFrame::OnMouseRightUp (wxMouseEvent
& event
)
148 const wxImage
& img
= wxGetApp().GetImage();
149 wxImage img2
= img
.Rotate(m_angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), FALSE
);
151 wxBitmap bmp
= img2
.ConvertToBitmap ();
153 wxClientDC
dc (this);
154 dc
.DrawBitmap (bmp
, event
.m_x
, event
.m_y
);