]>
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 class MyApp
: public wxApp
27 virtual bool OnInit();
31 class MyFrame
: public wxFrame
34 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
36 void OnQuit (wxCommandEvent
&);
37 void OnMouseLeftUp (wxMouseEvent
& event
);
38 void OnMouseRightUp (wxMouseEvent
& event
);
49 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
50 EVT_MENU (ID_Quit
, MyFrame::OnQuit
)
51 EVT_LEFT_UP (MyFrame::OnMouseLeftUp
)
52 EVT_RIGHT_UP (MyFrame::OnMouseRightUp
)
60 MyFrame
*frame
= new MyFrame ("wxWindows Skeleton", wxPoint(20,20), wxSize(600,450));
62 frame
->SetBackgroundColour (wxColour (0,80,60));
69 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
70 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
72 wxMenu
*menuFile
= new wxMenu
;
73 menuFile
->Append (ID_Quit
, "E&xit");
75 wxMenuBar
*menuBar
= new wxMenuBar
;
76 menuBar
->Append (menuFile
, "&File");
81 void MyFrame::OnQuit (wxCommandEvent
&)
87 // Rotate with interpolation and with offset correction
88 void MyFrame::OnMouseLeftUp (wxMouseEvent
& event
)
90 static double angle
= 0.1;
91 const double pi
= 3.14159265359;
93 wxImage
img ("kclub.bmp", wxBITMAP_TYPE_BMP
);
96 wxImage img2
= img
.Rotate(angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), TRUE
, &offset
);
99 wxBitmap bmp
= img2
.ConvertToBitmap ();
101 wxClientDC
dc (this);
102 dc
.DrawBitmap (bmp
, event
.m_x
+ offset
.x
, event
.m_y
+ offset
.y
);
107 // without interpolation, and without offset correction
108 void MyFrame::OnMouseRightUp (wxMouseEvent
& event
)
110 static double angle
= 0.1;
111 const double pi
= 3.14159265359;
113 wxImage
img ("kclub.bmp", wxBITMAP_TYPE_BMP
);
115 wxImage img2
= img
.Rotate(angle
, wxPoint(img
.GetWidth()/2, img
.GetHeight()/2), FALSE
);
118 wxBitmap bmp
= img2
.ConvertToBitmap ();
120 wxClientDC
dc (this);
121 dc
.DrawBitmap (bmp
, event
.m_x
, event
.m_y
);