]>
git.saurik.com Git - wxWidgets.git/blob - samples/rotate/rotate.cpp
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"
24 #include "wx/numdlg.h"
26 class MyApp
: public wxApp
29 virtual bool OnInit();
31 const wxImage
& GetImage() const { return m_image
; }
38 class MyCanvas
: public wxScrolledWindow
41 MyCanvas(wxWindow
* parent
);
43 void OnMouseLeftUp (wxMouseEvent
& event
);
44 void OnMouseRightUp (wxMouseEvent
& event
);
51 class MyFrame
: public wxFrame
54 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
56 void OnQuit (wxCommandEvent
&);
57 void OnAngle(wxCommandEvent
&);
70 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
71 EVT_LEFT_UP (MyCanvas::OnMouseLeftUp
)
72 EVT_RIGHT_UP (MyCanvas::OnMouseRightUp
)
75 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
76 EVT_MENU (ID_Quit
, MyFrame::OnQuit
)
77 EVT_MENU (ID_Angle
, MyFrame::OnAngle
)
84 m_image
= wxImage(_T("kclub.bmp"), wxBITMAP_TYPE_BMP
);
86 // any unused colour will do
87 m_image
.SetMaskColour( 0, 255, 255 );
91 wxLogError(wxT("Can't load the test image, please copy it to the ")
92 wxT("program directory"));
96 MyFrame
*frame
= new MyFrame (_T("wxWidgets rotate sample"),
97 wxPoint(20,20), wxSize(600,450));
100 SetTopWindow (frame
);
104 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
105 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
111 wxMenu
*menuFile
= new wxMenu
;
112 menuFile
->Append (ID_Angle
, _T("Set &angle\tCtrl-A"));
113 menuFile
->AppendSeparator();
114 menuFile
->Append (ID_Quit
, _T("E&xit\tAlt-X"));
116 wxMenuBar
*menuBar
= new wxMenuBar
;
117 menuBar
->Append (menuFile
, _T("&File"));
119 SetMenuBar (menuBar
);
122 void MyFrame::OnAngle (wxCommandEvent
&)
124 long degrees
= (long)((180*m_angle
)/M_PI
);
125 degrees
= wxGetNumberFromUser(_T("Change the image rotation angle"),
126 _T("Angle in degrees:"),
127 _T("wxWidgets rotate sample"),
132 m_angle
= (degrees
* M_PI
) / 180.0;
135 void MyFrame::OnQuit (wxCommandEvent
&)
140 MyCanvas::MyCanvas(wxWindow
* parent
):
141 wxScrolledWindow(parent
, wxID_ANY
)
143 SetBackgroundColour (wxColour (0,80,60));
147 // Rotate with interpolation and with offset correction
148 void MyCanvas::OnMouseLeftUp (wxMouseEvent
& event
)
150 MyFrame
* frame
= (MyFrame
*) GetParent();
153 const wxImage
& img
= wxGetApp().GetImage();
154 wxImage img2
= img
.Rotate(frame
->m_angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), true, &offset
);
158 wxClientDC
dc (this);
159 dc
.DrawBitmap (bmp
, event
.m_x
+ offset
.x
, event
.m_y
+ offset
.y
, true);
162 // without interpolation, and without offset correction
163 void MyCanvas::OnMouseRightUp (wxMouseEvent
& event
)
165 MyFrame
* frame
= (MyFrame
*) GetParent();
167 const wxImage
& img
= wxGetApp().GetImage();
168 wxImage img2
= img
.Rotate(frame
->m_angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), false);
172 wxClientDC
dc (this);
173 dc
.DrawBitmap (bmp
, event
.m_x
, event
.m_y
, true);