]>
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"
21 class MyApp
: public wxApp
23 virtual bool OnInit();
27 class MyFrame
: public wxFrame
30 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
32 void OnQuit (wxCommandEvent
&);
33 void OnMouseLeftUp (wxMouseEvent
& event
);
34 void OnMouseRightUp (wxMouseEvent
& event
);
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
)
56 MyFrame
*frame
= new MyFrame ("wxWindows Skeleton", wxPoint(20,20), wxSize(600,450));
58 frame
->SetBackgroundColour (wxColour (0,80,60));
65 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
66 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
68 wxMenu
*menuFile
= new wxMenu
;
69 menuFile
->Append (ID_Quit
, "E&xit");
71 wxMenuBar
*menuBar
= new wxMenuBar
;
72 menuBar
->Append (menuFile
, "&File");
77 void MyFrame::OnQuit (wxCommandEvent
&)
83 // Rotate with interpolation and with offset correction
84 void MyFrame::OnMouseLeftUp (wxMouseEvent
& event
)
86 static double angle
= 0.1;
87 const double pi
= 3.14159265359;
89 wxImage
img ("kclub.bmp", wxBITMAP_TYPE_BMP
);
92 wxImage img2
= img
.Rotate(angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), TRUE
, &offset
);
95 wxBitmap bmp
= img2
.ConvertToBitmap ();
98 dc
.DrawBitmap (bmp
, event
.m_x
+ offset
.x
, event
.m_y
+ offset
.y
);
103 // without interpolation, and without offset correction
104 void MyFrame::OnMouseRightUp (wxMouseEvent
& event
)
106 static double angle
= 0.1;
107 const double pi
= 3.14159265359;
109 wxImage
img ("kclub.bmp", wxBITMAP_TYPE_BMP
);
111 wxImage img2
= img
.Rotate(angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), FALSE
);
114 wxBitmap bmp
= img2
.ConvertToBitmap ();
116 wxClientDC
dc (this);
117 dc
.DrawBitmap (bmp
, event
.m_x
, event
.m_y
);