Added rotation to wxImage
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5872 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
21
samples/rotate/Makefile.in
Normal file
21
samples/rotate/Makefile.in
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# File: makefile.unx
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Julian Smart
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile for rotate example (UNIX).
|
||||
|
||||
top_srcdir = @top_srcdir@/..
|
||||
top_builddir = ../..
|
||||
program_dir = samples/rotate
|
||||
|
||||
PROGRAM=rotate
|
||||
|
||||
OBJECTS=$(PROGRAM).o
|
||||
|
||||
include ../../src/makeprog.env
|
||||
|
BIN
samples/rotate/kclub.bmp
Normal file
BIN
samples/rotate/kclub.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
16
samples/rotate/makefile.b32
Normal file
16
samples/rotate/makefile.b32
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# File: makefile.b32
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright:
|
||||
#
|
||||
# Makefile : Builds sample for 32-bit BC++
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
TARGET=rotate
|
||||
OBJECTS = $(TARGET).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.b32
|
||||
|
16
samples/rotate/makefile.g95
Normal file
16
samples/rotate/makefile.g95
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# File: makefile.g95
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart, 1999
|
||||
#
|
||||
# Makefile for wxWindows sample (Cygwin/Mingw32).
|
||||
|
||||
WXDIR = ../..
|
||||
|
||||
TARGET=rotate
|
||||
OBJECTS = $(TARGET).o
|
||||
|
||||
include $(WXDIR)/src/makeprog.g95
|
||||
|
35
samples/rotate/makefile.unx
Normal file
35
samples/rotate/makefile.unx
Normal file
@@ -0,0 +1,35 @@
|
||||
#
|
||||
# File: Makefile for samples
|
||||
# Author: Robert Roebling
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Robert Roebling
|
||||
#
|
||||
# This makefile requires a Unix version of wxWindows
|
||||
# to be installed on your system. This is most often
|
||||
# done typing "make install" when using the complete
|
||||
# sources of wxWindows or by installing the two
|
||||
# RPM packages wxGTK.XXX.rpm and wxGTK-devel.XXX.rpm
|
||||
# under Linux.
|
||||
#
|
||||
|
||||
CC = gcc
|
||||
|
||||
PROGRAM = rotate
|
||||
|
||||
OBJECTS = $(PROGRAM).o
|
||||
|
||||
# implementation
|
||||
|
||||
.SUFFIXES: .o .cpp
|
||||
|
||||
.cpp.o :
|
||||
$(CC) -c `wx-config --cflags` -o $@ $<
|
||||
|
||||
all: $(PROGRAM)
|
||||
|
||||
$(PROGRAM): $(OBJECTS)
|
||||
$(CC) -o $(PROGRAM) $(OBJECTS) `wx-config --libs`
|
||||
|
||||
clean:
|
||||
rm -f *.o $(PROGRAM)
|
18
samples/rotate/makefile.vc
Normal file
18
samples/rotate/makefile.vc
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# File: makefile.vc
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart
|
||||
#
|
||||
# Makefile : Builds sample (VC++, WIN32)
|
||||
# Use FINAL=1 argument to nmake to build final version with no debug info.
|
||||
|
||||
# Set WXDIR for your system
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
PROGRAM=rotate
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.vc
|
||||
|
15
samples/rotate/makefile.wat
Normal file
15
samples/rotate/makefile.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# Makefile for WATCOM
|
||||
#
|
||||
# Created by Julian Smart, January 1999
|
||||
#
|
||||
#
|
||||
|
||||
WXDIR = $(%WXWIN)
|
||||
|
||||
PROGRAM = rotate
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.wat
|
||||
|
||||
|
BIN
samples/rotate/mondrian.ico
Normal file
BIN
samples/rotate/mondrian.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
120
samples/rotate/rotate.cpp
Normal file
120
samples/rotate/rotate.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: test.cpp
|
||||
// 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
|
||||
|
||||
#include "wx/image.h"
|
||||
|
||||
class MyApp: public wxApp
|
||||
{
|
||||
virtual bool OnInit();
|
||||
};
|
||||
|
||||
|
||||
class MyFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||
|
||||
void OnQuit (wxCommandEvent &);
|
||||
void OnMouseLeftUp (wxMouseEvent & event);
|
||||
void OnMouseRightUp (wxMouseEvent & event);
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ID_Quit = 1
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU (ID_Quit, MyFrame::OnQuit)
|
||||
EVT_LEFT_UP (MyFrame::OnMouseLeftUp)
|
||||
EVT_RIGHT_UP (MyFrame::OnMouseRightUp)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
MyFrame *frame = new MyFrame ("wxWindows Skeleton", wxPoint(20,20), wxSize(600,450));
|
||||
|
||||
frame->SetBackgroundColour (wxColour (0,80,60));
|
||||
|
||||
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)
|
||||
{
|
||||
wxMenu *menuFile = new wxMenu;
|
||||
menuFile->Append (ID_Quit, "E&xit");
|
||||
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append (menuFile, "&File");
|
||||
|
||||
SetMenuBar (menuBar);
|
||||
}
|
||||
|
||||
void MyFrame::OnQuit (wxCommandEvent &)
|
||||
{
|
||||
Close (TRUE);
|
||||
}
|
||||
|
||||
|
||||
// Rotate with interpolation and with offset correction
|
||||
void MyFrame::OnMouseLeftUp (wxMouseEvent & event)
|
||||
{
|
||||
static double angle = 0.1;
|
||||
const double pi = 3.14159265359;
|
||||
|
||||
wxImage img ("kclub.bmp", wxBITMAP_TYPE_BMP);
|
||||
|
||||
wxPoint offset;
|
||||
wxImage img2 = img.Rotate(angle, wxPoint(img.GetWidth()/2, img.GetHeight()/2), TRUE, &offset);
|
||||
angle += 0.05;
|
||||
|
||||
wxBitmap bmp = img2.ConvertToBitmap ();
|
||||
|
||||
wxClientDC dc (this);
|
||||
dc.DrawBitmap (bmp, event.m_x + offset.x, event.m_y + offset.y);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// without interpolation, and without offset correction
|
||||
void MyFrame::OnMouseRightUp (wxMouseEvent & event)
|
||||
{
|
||||
static double angle = 0.1;
|
||||
const double pi = 3.14159265359;
|
||||
|
||||
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 ();
|
||||
|
||||
wxClientDC dc (this);
|
||||
dc.DrawBitmap (bmp, event.m_x, event.m_y);
|
||||
|
||||
return;
|
||||
}
|
3
samples/rotate/rotate.rc
Normal file
3
samples/rotate/rotate.rc
Normal file
@@ -0,0 +1,3 @@
|
||||
mondrian ICON "mondrian.ico"
|
||||
#include "wx/msw/wx.rc"
|
||||
|
Reference in New Issue
Block a user