1. modified Makefile to copy the .bmp
2. added "change angle" to the menu, abort (and not crash) if bitmap not found git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5888 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -17,5 +17,7 @@ PROGRAM=rotate
|
|||||||
|
|
||||||
OBJECTS=$(PROGRAM).o
|
OBJECTS=$(PROGRAM).o
|
||||||
|
|
||||||
|
DATAFILES=kclub.bmp
|
||||||
|
|
||||||
include ../../src/makeprog.env
|
include ../../src/makeprog.env
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: test.cpp
|
// Name: rotate.cpp
|
||||||
// Purpose: Image rotation test
|
// Purpose: Image rotation test
|
||||||
// Author: Carlos Moreno
|
// Author: Carlos Moreno
|
||||||
// Modified by:
|
// Modified by:
|
||||||
@@ -22,9 +22,17 @@
|
|||||||
|
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
|
||||||
|
#include <math.h> // M_PI
|
||||||
|
|
||||||
class MyApp: public wxApp
|
class MyApp: public wxApp
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
virtual bool OnInit();
|
virtual bool OnInit();
|
||||||
|
|
||||||
|
const wxImage& GetImage() const { return m_image; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxImage m_image;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -34,20 +42,25 @@ public:
|
|||||||
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||||
|
|
||||||
void OnQuit (wxCommandEvent &);
|
void OnQuit (wxCommandEvent &);
|
||||||
|
void OnAngle(wxCommandEvent &);
|
||||||
void OnMouseLeftUp (wxMouseEvent & event);
|
void OnMouseLeftUp (wxMouseEvent & event);
|
||||||
void OnMouseRightUp (wxMouseEvent & event);
|
void OnMouseRightUp (wxMouseEvent & event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
double m_angle;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ID_Quit = 1
|
ID_Quit = 1,
|
||||||
|
ID_Angle
|
||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
EVT_MENU (ID_Quit, MyFrame::OnQuit)
|
EVT_MENU (ID_Quit, MyFrame::OnQuit)
|
||||||
|
EVT_MENU (ID_Angle, MyFrame::OnAngle)
|
||||||
EVT_LEFT_UP (MyFrame::OnMouseLeftUp)
|
EVT_LEFT_UP (MyFrame::OnMouseLeftUp)
|
||||||
EVT_RIGHT_UP (MyFrame::OnMouseRightUp)
|
EVT_RIGHT_UP (MyFrame::OnMouseRightUp)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
@@ -57,7 +70,16 @@ IMPLEMENT_APP(MyApp)
|
|||||||
|
|
||||||
bool MyApp::OnInit()
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
MyFrame *frame = new MyFrame ("wxWindows Skeleton", wxPoint(20,20), wxSize(600,450));
|
m_image = wxImage("kclub.bmp", wxBITMAP_TYPE_BMP);
|
||||||
|
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));
|
||||||
|
|
||||||
frame->SetBackgroundColour (wxColour (0,80,60));
|
frame->SetBackgroundColour (wxColour (0,80,60));
|
||||||
|
|
||||||
@@ -69,8 +91,12 @@ bool MyApp::OnInit()
|
|||||||
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||||
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
|
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
|
||||||
{
|
{
|
||||||
|
m_angle = 0.1;
|
||||||
|
|
||||||
wxMenu *menuFile = new wxMenu;
|
wxMenu *menuFile = new wxMenu;
|
||||||
menuFile->Append (ID_Quit, "E&xit");
|
menuFile->Append (ID_Angle, "Set &angle\tCtrl-A");
|
||||||
|
menuFile->AppendSeparator();
|
||||||
|
menuFile->Append (ID_Quit, "E&xit\tAlt-X");
|
||||||
|
|
||||||
wxMenuBar *menuBar = new wxMenuBar;
|
wxMenuBar *menuBar = new wxMenuBar;
|
||||||
menuBar->Append (menuFile, "&File");
|
menuBar->Append (menuFile, "&File");
|
||||||
@@ -78,6 +104,18 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|||||||
SetMenuBar (menuBar);
|
SetMenuBar (menuBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
void MyFrame::OnQuit (wxCommandEvent &)
|
void MyFrame::OnQuit (wxCommandEvent &)
|
||||||
{
|
{
|
||||||
Close (TRUE);
|
Close (TRUE);
|
||||||
@@ -87,38 +125,24 @@ void MyFrame::OnQuit (wxCommandEvent &)
|
|||||||
// Rotate with interpolation and with offset correction
|
// Rotate with interpolation and with offset correction
|
||||||
void MyFrame::OnMouseLeftUp (wxMouseEvent & event)
|
void MyFrame::OnMouseLeftUp (wxMouseEvent & event)
|
||||||
{
|
{
|
||||||
static double angle = 0.1;
|
|
||||||
const double pi = 3.14159265359;
|
|
||||||
|
|
||||||
wxImage img ("kclub.bmp", wxBITMAP_TYPE_BMP);
|
|
||||||
|
|
||||||
wxPoint offset;
|
wxPoint offset;
|
||||||
wxImage img2 = img.Rotate(angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), TRUE, &offset);
|
const wxImage& img = wxGetApp().GetImage();
|
||||||
angle += 0.05;
|
wxImage img2 = img.Rotate(m_angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), TRUE, &offset);
|
||||||
|
|
||||||
wxBitmap bmp = img2.ConvertToBitmap ();
|
wxBitmap bmp = img2.ConvertToBitmap ();
|
||||||
|
|
||||||
wxClientDC dc (this);
|
wxClientDC dc (this);
|
||||||
dc.DrawBitmap (bmp, event.m_x + offset.x, event.m_y + offset.y);
|
dc.DrawBitmap (img2.ConvertToBitmap(), event.m_x + offset.x, event.m_y + offset.y);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// without interpolation, and without offset correction
|
// without interpolation, and without offset correction
|
||||||
void MyFrame::OnMouseRightUp (wxMouseEvent & event)
|
void MyFrame::OnMouseRightUp (wxMouseEvent & event)
|
||||||
{
|
{
|
||||||
static double angle = 0.1;
|
const wxImage& img = wxGetApp().GetImage();
|
||||||
const double pi = 3.14159265359;
|
wxImage img2 = img.Rotate(m_angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), FALSE);
|
||||||
|
|
||||||
wxImage img ("kclub.bmp", wxBITMAP_TYPE_BMP);
|
|
||||||
|
|
||||||
wxImage img2 = img.Rotate(angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), FALSE);
|
|
||||||
angle += 0.05;
|
|
||||||
|
|
||||||
wxBitmap bmp = img2.ConvertToBitmap ();
|
wxBitmap bmp = img2.ConvertToBitmap ();
|
||||||
|
|
||||||
wxClientDC dc (this);
|
wxClientDC dc (this);
|
||||||
dc.DrawBitmap (bmp, event.m_x, event.m_y);
|
dc.DrawBitmap (bmp, event.m_x, event.m_y);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user