2000-02-06 09:51:36 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-02-07 11:37:59 -05:00
|
|
|
// Name: rotate.cpp
|
2000-02-06 09:51:36 -05:00
|
|
|
// Purpose: Image rotation test
|
|
|
|
// Author: Carlos Moreno
|
|
|
|
// Modified by:
|
|
|
|
// Created: 6/2/2000
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2000
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2000-02-06 12:13:14 -05:00
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2000-02-06 09:51:36 -05:00
|
|
|
#include "wx/image.h"
|
|
|
|
|
2000-02-07 21:09:54 -05:00
|
|
|
/* GRG: This is not ANSI standard, define M_PI explicitly
|
2000-02-07 11:37:59 -05:00
|
|
|
#include <math.h> // M_PI
|
2000-02-07 21:09:54 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI 3.1415926535897932384626433832795
|
|
|
|
#endif
|
|
|
|
|
2000-02-07 11:37:59 -05:00
|
|
|
|
2000-02-06 09:51:36 -05:00
|
|
|
class MyApp: public wxApp
|
|
|
|
{
|
2000-02-07 11:37:59 -05:00
|
|
|
public:
|
2000-02-06 09:51:36 -05:00
|
|
|
virtual bool OnInit();
|
2000-02-07 11:37:59 -05:00
|
|
|
|
|
|
|
const wxImage& GetImage() const { return m_image; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxImage m_image;
|
2000-02-06 09:51:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class MyFrame: public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
|
|
|
|
|
|
|
void OnQuit (wxCommandEvent &);
|
2000-02-07 11:37:59 -05:00
|
|
|
void OnAngle(wxCommandEvent &);
|
2000-02-06 09:51:36 -05:00
|
|
|
void OnMouseLeftUp (wxMouseEvent & event);
|
|
|
|
void OnMouseRightUp (wxMouseEvent & event);
|
|
|
|
|
|
|
|
private:
|
2000-02-07 11:37:59 -05:00
|
|
|
double m_angle;
|
|
|
|
|
2000-02-06 09:51:36 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2000-02-07 11:37:59 -05:00
|
|
|
ID_Quit = 1,
|
|
|
|
ID_Angle
|
2000-02-06 09:51:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU (ID_Quit, MyFrame::OnQuit)
|
2000-02-07 11:37:59 -05:00
|
|
|
EVT_MENU (ID_Angle, MyFrame::OnAngle)
|
2000-02-06 09:51:36 -05:00
|
|
|
EVT_LEFT_UP (MyFrame::OnMouseLeftUp)
|
|
|
|
EVT_RIGHT_UP (MyFrame::OnMouseRightUp)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2000-02-07 11:37:59 -05:00
|
|
|
m_image = wxImage("kclub.bmp", wxBITMAP_TYPE_BMP);
|
2000-02-10 08:26:30 -05:00
|
|
|
|
|
|
|
// any unused colour will do
|
|
|
|
m_image.SetMaskColour( 0, 255, 255 );
|
|
|
|
|
2000-02-07 11:37:59 -05:00
|
|
|
if ( !m_image.Ok() )
|
|
|
|
{
|
|
|
|
wxLogError("Can't load the test image, please copy it to the "
|
|
|
|
"program directory");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame *frame = new MyFrame ("wxWindows rotate sample",
|
|
|
|
wxPoint(20,20), wxSize(600,450));
|
2000-02-06 09:51:36 -05:00
|
|
|
|
|
|
|
frame->SetBackgroundColour (wxColour (0,80,60));
|
2000-02-10 08:26:30 -05:00
|
|
|
frame->Clear();
|
2000-02-06 09:51:36 -05:00
|
|
|
frame->Show (TRUE);
|
|
|
|
SetTopWindow (frame);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|
|
|
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
|
|
|
|
{
|
2000-02-07 11:37:59 -05:00
|
|
|
m_angle = 0.1;
|
|
|
|
|
2000-02-06 09:51:36 -05:00
|
|
|
wxMenu *menuFile = new wxMenu;
|
2000-02-07 11:37:59 -05:00
|
|
|
menuFile->Append (ID_Angle, "Set &angle\tCtrl-A");
|
|
|
|
menuFile->AppendSeparator();
|
|
|
|
menuFile->Append (ID_Quit, "E&xit\tAlt-X");
|
2000-02-06 09:51:36 -05:00
|
|
|
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
menuBar->Append (menuFile, "&File");
|
|
|
|
|
|
|
|
SetMenuBar (menuBar);
|
|
|
|
}
|
|
|
|
|
2000-02-07 11:37:59 -05:00
|
|
|
void MyFrame::OnAngle (wxCommandEvent &)
|
|
|
|
{
|
|
|
|
long degrees = (long)((180*m_angle)/M_PI);
|
|
|
|
degrees = wxGetNumberFromUser("Change the image rotation angle",
|
|
|
|
"Angle in degrees:",
|
|
|
|
"wxWindows rotate sample",
|
|
|
|
degrees,
|
|
|
|
-180, +180,
|
|
|
|
this);
|
|
|
|
m_angle = (degrees * M_PI) / 180.0;
|
|
|
|
}
|
|
|
|
|
2000-02-06 09:51:36 -05:00
|
|
|
void MyFrame::OnQuit (wxCommandEvent &)
|
|
|
|
{
|
|
|
|
Close (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Rotate with interpolation and with offset correction
|
|
|
|
void MyFrame::OnMouseLeftUp (wxMouseEvent & event)
|
|
|
|
{
|
|
|
|
wxPoint offset;
|
2000-02-07 11:37:59 -05:00
|
|
|
const wxImage& img = wxGetApp().GetImage();
|
|
|
|
wxImage img2 = img.Rotate(m_angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), TRUE, &offset);
|
2000-02-06 09:51:36 -05:00
|
|
|
|
|
|
|
wxBitmap bmp = img2.ConvertToBitmap ();
|
|
|
|
|
|
|
|
wxClientDC dc (this);
|
2000-02-10 08:26:30 -05:00
|
|
|
dc.DrawBitmap (img2.ConvertToBitmap(), event.m_x + offset.x, event.m_y + offset.y, TRUE);
|
2000-02-06 09:51:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// without interpolation, and without offset correction
|
|
|
|
void MyFrame::OnMouseRightUp (wxMouseEvent & event)
|
|
|
|
{
|
2000-02-07 11:37:59 -05:00
|
|
|
const wxImage& img = wxGetApp().GetImage();
|
|
|
|
wxImage img2 = img.Rotate(m_angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), FALSE);
|
2000-02-06 09:51:36 -05:00
|
|
|
|
|
|
|
wxBitmap bmp = img2.ConvertToBitmap ();
|
|
|
|
|
|
|
|
wxClientDC dc (this);
|
2000-02-10 08:26:30 -05:00
|
|
|
dc.DrawBitmap (bmp, event.m_x, event.m_y, TRUE);
|
2000-02-06 09:51:36 -05:00
|
|
|
}
|