]>
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"
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
);
82 // any unused colour will do
83 m_image
.SetMaskColour( 0, 255, 255 );
87 wxLogError("Can't load the test image, please copy it to the "
92 MyFrame
*frame
= new MyFrame ("wxWindows rotate sample",
93 wxPoint(20,20), wxSize(600,450));
95 frame
->SetBackgroundColour (wxColour (0,80,60));
102 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
103 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
107 wxMenu
*menuFile
= new wxMenu
;
108 menuFile
->Append (ID_Angle
, "Set &angle\tCtrl-A");
109 menuFile
->AppendSeparator();
110 menuFile
->Append (ID_Quit
, "E&xit\tAlt-X");
112 wxMenuBar
*menuBar
= new wxMenuBar
;
113 menuBar
->Append (menuFile
, "&File");
115 SetMenuBar (menuBar
);
118 void MyFrame::OnAngle (wxCommandEvent
&)
120 long degrees
= (long)((180*m_angle
)/M_PI
);
121 degrees
= wxGetNumberFromUser("Change the image rotation angle",
123 "wxWindows rotate sample",
127 m_angle
= (degrees
* M_PI
) / 180.0;
130 void MyFrame::OnQuit (wxCommandEvent
&)
136 // Rotate with interpolation and with offset correction
137 void MyFrame::OnMouseLeftUp (wxMouseEvent
& event
)
140 const wxImage
& img
= wxGetApp().GetImage();
141 wxImage img2
= img
.Rotate(m_angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), TRUE
, &offset
);
143 wxBitmap bmp
= img2
.ConvertToBitmap ();
145 wxClientDC
dc (this);
146 dc
.DrawBitmap (img2
.ConvertToBitmap(), event
.m_x
+ offset
.x
, event
.m_y
+ offset
.y
, TRUE
);
149 // without interpolation, and without offset correction
150 void MyFrame::OnMouseRightUp (wxMouseEvent
& event
)
152 const wxImage
& img
= wxGetApp().GetImage();
153 wxImage img2
= img
.Rotate(m_angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), FALSE
);
155 wxBitmap bmp
= img2
.ConvertToBitmap ();
157 wxClientDC
dc (this);
158 dc
.DrawBitmap (bmp
, event
.m_x
, event
.m_y
, TRUE
);