]>
git.saurik.com Git - wxWidgets.git/blob - samples/rotate/rotate.cpp
3319489b51b14cd085db7e847358bbf1aff9bc52
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 #include <math.h> // M_PI
27 class MyApp
: public wxApp
30 virtual bool OnInit();
32 const wxImage
& GetImage() const { return m_image
; }
39 class MyFrame
: public wxFrame
42 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
44 void OnQuit (wxCommandEvent
&);
45 void OnAngle(wxCommandEvent
&);
46 void OnMouseLeftUp (wxMouseEvent
& event
);
47 void OnMouseRightUp (wxMouseEvent
& event
);
61 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
62 EVT_MENU (ID_Quit
, MyFrame::OnQuit
)
63 EVT_MENU (ID_Angle
, MyFrame::OnAngle
)
64 EVT_LEFT_UP (MyFrame::OnMouseLeftUp
)
65 EVT_RIGHT_UP (MyFrame::OnMouseRightUp
)
73 m_image
= wxImage("kclub.bmp", wxBITMAP_TYPE_BMP
);
76 wxLogError("Can't load the test image, please copy it to the "
81 MyFrame
*frame
= new MyFrame ("wxWindows rotate sample",
82 wxPoint(20,20), wxSize(600,450));
84 frame
->SetBackgroundColour (wxColour (0,80,60));
91 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
92 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
96 wxMenu
*menuFile
= new wxMenu
;
97 menuFile
->Append (ID_Angle
, "Set &angle\tCtrl-A");
98 menuFile
->AppendSeparator();
99 menuFile
->Append (ID_Quit
, "E&xit\tAlt-X");
101 wxMenuBar
*menuBar
= new wxMenuBar
;
102 menuBar
->Append (menuFile
, "&File");
104 SetMenuBar (menuBar
);
107 void MyFrame::OnAngle (wxCommandEvent
&)
109 long degrees
= (long)((180*m_angle
)/M_PI
);
110 degrees
= wxGetNumberFromUser("Change the image rotation angle",
112 "wxWindows rotate sample",
116 m_angle
= (degrees
* M_PI
) / 180.0;
119 void MyFrame::OnQuit (wxCommandEvent
&)
125 // Rotate with interpolation and with offset correction
126 void MyFrame::OnMouseLeftUp (wxMouseEvent
& event
)
129 const wxImage
& img
= wxGetApp().GetImage();
130 wxImage img2
= img
.Rotate(m_angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), TRUE
, &offset
);
132 wxBitmap bmp
= img2
.ConvertToBitmap ();
134 wxClientDC
dc (this);
135 dc
.DrawBitmap (img2
.ConvertToBitmap(), event
.m_x
+ offset
.x
, event
.m_y
+ offset
.y
);
138 // without interpolation, and without offset correction
139 void MyFrame::OnMouseRightUp (wxMouseEvent
& event
)
141 const wxImage
& img
= wxGetApp().GetImage();
142 wxImage img2
= img
.Rotate(m_angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), FALSE
);
144 wxBitmap bmp
= img2
.ConvertToBitmap ();
146 wxClientDC
dc (this);
147 dc
.DrawBitmap (bmp
, event
.m_x
, event
.m_y
);