]> git.saurik.com Git - wxWidgets.git/blame - samples/rotate/rotate.cpp
Added RTLD_GLOBAL to dlopen() flags which is needed if libraries depend
[wxWidgets.git] / samples / rotate / rotate.cpp
CommitLineData
7a632f10 1/////////////////////////////////////////////////////////////////////////////
f5ac656c 2// Name: rotate.cpp
7a632f10
JS
3// Purpose: Image rotation test
4// Author: Carlos Moreno
5// Modified by:
6// Created: 6/2/2000
7// RCS-ID: $Id$
8// Copyright: (c) 2000
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
46132182
RR
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
7a632f10
JS
23#include "wx/image.h"
24
fa1993cc 25/* GRG: This is not ANSI standard, define M_PI explicitly
f5ac656c 26#include <math.h> // M_PI
fa1993cc
GRG
27*/
28
29#ifndef M_PI
30#define M_PI 3.1415926535897932384626433832795
31#endif
32
f5ac656c 33
7a632f10
JS
34class MyApp: public wxApp
35{
f5ac656c 36public:
7a632f10 37 virtual bool OnInit();
f5ac656c
VZ
38
39 const wxImage& GetImage() const { return m_image; }
40
41private:
42 wxImage m_image;
7a632f10
JS
43};
44
45
46class MyFrame: public wxFrame
47{
48public:
49 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
50
51 void OnQuit (wxCommandEvent &);
f5ac656c 52 void OnAngle(wxCommandEvent &);
7a632f10
JS
53 void OnMouseLeftUp (wxMouseEvent & event);
54 void OnMouseRightUp (wxMouseEvent & event);
55
56private:
f5ac656c
VZ
57 double m_angle;
58
7a632f10
JS
59 DECLARE_EVENT_TABLE()
60};
61
62enum
63{
f5ac656c
VZ
64 ID_Quit = 1,
65 ID_Angle
7a632f10
JS
66};
67
68BEGIN_EVENT_TABLE(MyFrame, wxFrame)
69 EVT_MENU (ID_Quit, MyFrame::OnQuit)
f5ac656c 70 EVT_MENU (ID_Angle, MyFrame::OnAngle)
7a632f10
JS
71 EVT_LEFT_UP (MyFrame::OnMouseLeftUp)
72 EVT_RIGHT_UP (MyFrame::OnMouseRightUp)
73END_EVENT_TABLE()
74
75IMPLEMENT_APP(MyApp)
76
77
78bool MyApp::OnInit()
79{
f5ac656c 80 m_image = wxImage("kclub.bmp", wxBITMAP_TYPE_BMP);
b2177839
GRG
81
82 // any unused colour will do
83 m_image.SetMaskColour( 0, 255, 255 );
84
f5ac656c
VZ
85 if ( !m_image.Ok() )
86 {
87 wxLogError("Can't load the test image, please copy it to the "
88 "program directory");
89 return FALSE;
90 }
91
92 MyFrame *frame = new MyFrame ("wxWindows rotate sample",
93 wxPoint(20,20), wxSize(600,450));
7a632f10
JS
94
95 frame->SetBackgroundColour (wxColour (0,80,60));
b2177839 96 frame->Clear();
7a632f10
JS
97 frame->Show (TRUE);
98 SetTopWindow (frame);
99 return TRUE;
100}
101
102MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
103 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
104{
f5ac656c
VZ
105 m_angle = 0.1;
106
7a632f10 107 wxMenu *menuFile = new wxMenu;
f5ac656c
VZ
108 menuFile->Append (ID_Angle, "Set &angle\tCtrl-A");
109 menuFile->AppendSeparator();
110 menuFile->Append (ID_Quit, "E&xit\tAlt-X");
7a632f10
JS
111
112 wxMenuBar *menuBar = new wxMenuBar;
113 menuBar->Append (menuFile, "&File");
114
115 SetMenuBar (menuBar);
116}
117
f5ac656c
VZ
118void MyFrame::OnAngle (wxCommandEvent &)
119{
120 long degrees = (long)((180*m_angle)/M_PI);
121 degrees = wxGetNumberFromUser("Change the image rotation angle",
122 "Angle in degrees:",
123 "wxWindows rotate sample",
124 degrees,
125 -180, +180,
126 this);
127 m_angle = (degrees * M_PI) / 180.0;
128}
129
7a632f10
JS
130void MyFrame::OnQuit (wxCommandEvent &)
131{
132 Close (TRUE);
133}
134
135
136// Rotate with interpolation and with offset correction
137void MyFrame::OnMouseLeftUp (wxMouseEvent & event)
138{
7a632f10 139 wxPoint offset;
f5ac656c
VZ
140 const wxImage& img = wxGetApp().GetImage();
141 wxImage img2 = img.Rotate(m_angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), TRUE, &offset);
7a632f10
JS
142
143 wxBitmap bmp = img2.ConvertToBitmap ();
144
145 wxClientDC dc (this);
b2177839 146 dc.DrawBitmap (img2.ConvertToBitmap(), event.m_x + offset.x, event.m_y + offset.y, TRUE);
7a632f10
JS
147}
148
149// without interpolation, and without offset correction
150void MyFrame::OnMouseRightUp (wxMouseEvent & event)
151{
f5ac656c
VZ
152 const wxImage& img = wxGetApp().GetImage();
153 wxImage img2 = img.Rotate(m_angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), FALSE);
7a632f10
JS
154
155 wxBitmap bmp = img2.ConvertToBitmap ();
156
157 wxClientDC dc (this);
b2177839 158 dc.DrawBitmap (bmp, event.m_x, event.m_y, TRUE);
7a632f10 159}