 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
shahram Guest
|
Posted: Sun Apr 11, 2004 9:11 pm Post subject: Rotate a TShape |
|
|
Hi all,
How can I rotate a TShape component?
|
|
| Back to top |
|
 |
Rene Tschaggelar Guest
|
Posted: Sun Apr 11, 2004 9:41 pm Post subject: Re: Rotate a TShape |
|
|
shahram wrote:
| Quote: | Hi all,
How can I rotate a TShape component?
|
You can rotate anything by rotating the coordinates.
http://www.ibrtses.com/delphi/drot.html
Note that a rotation is always around the origin.
Meaning for a different rotation point you have to move
before and after rotation.
Rene
--
Ing.Buro R.Tschaggelar http://www.ibrtses.com
Your newsgroups @ http://www.talkto.net
|
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Sun Apr 11, 2004 10:58 pm Post subject: Re: Rotate a TShape |
|
|
There is no "native" Rotate command for VCL components.
When you want to add rotation, consider the following:
- If you're drawing lines, you can simply rotate the start and endpoint
mathematically, and draw the line with these new coordinates
- If you're rotating bitmapped graphics, you can do this most easily with 90
degree increments.
- Of course you can also rotate a bitmap freely, but then you must really
find the rotated position of each pixel and map them. This is a slow
process, and can be optimized in many ways. The resulting quality also
differs with speed (there's a tradeoff). EFG's site has example code for
rotating bitmaps, and the graphics32 package has excellent and fast code too
([url]www.g32.org)[/url].
If you're looking for a "ready-to-go" solution, you can use our DtpDocuments
component. It allows you to define your own TdtpShape descendant (drawing
basically anything you want, without worrying about rotation). The library
will then handle the rotation easily, and for any shape (either bitmap or
vector based). You can rotate by mouse or by code: e.g.
MyShape.DocRotate(10) will rotate the shape by 10 degrees around its center.
The component is not free, it costs Eur99 (for the DCU version) but could
potentially save you LOTS of time and hassle.
More info (and trial) here:
http://www.simdesign.nl/dtpdocuments.html
Kind regards,
Nils Haeck
www.simdesign.nl
"shahram" <shshafieha (AT) yahoo (DOT) com> wrote
| Quote: | Hi all,
How can I rotate a TShape component?
|
|
|
| Back to top |
|
 |
shahram Guest
|
Posted: Tue Apr 13, 2004 12:17 pm Post subject: Re: Rotate a TShape |
|
|
I do know mathematical subject, the things that I don't know is after change
the coordinates of the points how to redraw the shape
"Rene Tschaggelar" <ee123123wqe12 (AT) sd242323 (DOT) com> wrote
|
|
| Back to top |
|
 |
Gordon Whittam Guest
|
Posted: Tue Apr 13, 2004 1:56 pm Post subject: Re: Rotate a TShape |
|
|
In article <4079b48a$1 (AT) newsgroups (DOT) borland.com>, Shahram wrote:
| Quote: | Hi all,
How can I rotate a TShape component?
|
You could try something like this:
type
TMGC_RotateShape = class(TShape)
private
fAngle: extended;
procedure SetAngle(const Value: extended);
protected
procedure Paint;override;
public
constructor Create(aOwner: TComponent);override;
{in degrees}
property Angle: extended read fAngle write SetAngle;
end;
implementation
uses Math;
{$R *.DFM}
{ TMGC_RotateShape }
constructor TMGC_RotateShape.Create(aOwner: TComponent);
begin
fAngle:= 0;
inherited;
end;
procedure TMGC_RotateShape.Paint;
var
xForm,xFormOld: TXForm;
gMode: DWORD;
radA: extended;
OldOrg: TPoint;
begin
radA:= DegToRad(Angle);
{GM_ADVANCED requires W98 up}
gMode:= SetGraphicsMode(Canvas.Handle,GM_ADVANCED);
try
XForm.eM11 := Cos(radA);
XForm.eM12 := Sin(radA);
XForm.eM21 := - Sin(radA);
XForm.eM22 := Cos(radA);
{shifts the offset as it rotates so the rotation is around the
center. Set to zero to rotate around top left}
XForm.eDx := ((Width/2)-(Cos(radA)*(Width/2)))
+((Sin(radA)*(Height/2)));
XForm.eDy := ((Height/2)-(Sin(radA)*(Width/2)))
-((Cos(radA)*(Height/2)));
if GetWorldTransform(Canvas.Handle,xFormOld) then
try
SetWorldTransform(Canvas.Handle,XForm);
inherited;
finally
SetWorldTransform(Canvas.Handle,XFormOld);
end;
finally
SetGraphicsMode(Canvas.Handle,gMode);
end;
end;
procedure TMGC_RotateShape.SetAngle(const Value: extended);
begin
fAngle := Value;
Repaint;
end;
Should give you some ideas.
Gordon
|
|
| Back to top |
|
 |
shahram Guest
|
Posted: Wed Apr 14, 2004 9:03 am Post subject: Re: Rotate a TShape |
|
|
Thanks a lot
Shahram
"Gordon Whittam" <gordon (AT) mgcsoft (DOT) com> wrote
| Quote: | In article <4079b48a$1 (AT) newsgroups (DOT) borland.com>, Shahram wrote:
Hi all,
How can I rotate a TShape component?
You could try something like this:
type
TMGC_RotateShape = class(TShape)
private
fAngle: extended;
procedure SetAngle(const Value: extended);
protected
procedure Paint;override;
public
constructor Create(aOwner: TComponent);override;
{in degrees}
property Angle: extended read fAngle write SetAngle;
end;
implementation
uses Math;
{$R *.DFM}
{ TMGC_RotateShape }
constructor TMGC_RotateShape.Create(aOwner: TComponent);
begin
fAngle:= 0;
inherited;
end;
procedure TMGC_RotateShape.Paint;
var
xForm,xFormOld: TXForm;
gMode: DWORD;
radA: extended;
OldOrg: TPoint;
begin
radA:= DegToRad(Angle);
{GM_ADVANCED requires W98 up}
gMode:= SetGraphicsMode(Canvas.Handle,GM_ADVANCED);
try
XForm.eM11 := Cos(radA);
XForm.eM12 := Sin(radA);
XForm.eM21 := - Sin(radA);
XForm.eM22 := Cos(radA);
{shifts the offset as it rotates so the rotation is around the
center. Set to zero to rotate around top left}
XForm.eDx := ((Width/2)-(Cos(radA)*(Width/2)))
+((Sin(radA)*(Height/2)));
XForm.eDy := ((Height/2)-(Sin(radA)*(Width/2)))
-((Cos(radA)*(Height/2)));
if GetWorldTransform(Canvas.Handle,xFormOld) then
try
SetWorldTransform(Canvas.Handle,XForm);
inherited;
finally
SetWorldTransform(Canvas.Handle,XFormOld);
end;
finally
SetGraphicsMode(Canvas.Handle,gMode);
end;
end;
procedure TMGC_RotateShape.SetAngle(const Value: extended);
begin
fAngle := Value;
Repaint;
end;
Should give you some ideas.
Gordon
|
|
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Fri Apr 16, 2004 9:56 pm Post subject: Re: Rotate a TShape |
|
|
Please note that this does not work on Win95 and many Win98 systems. If you
want to support these operating systems, you cannot use "SetWorldTransform"
with other than scaling values (so no rotation).
Nils
"shahram" <shshafieha (AT) yahoo (DOT) com> wrote
| Quote: | Thanks a lot
Shahram
"Gordon Whittam" <gordon (AT) mgcsoft (DOT) com> wrote in message
news:VA.0000015c.0103a160 (AT) mgcsoft (DOT) com...
In article <4079b48a$1 (AT) newsgroups (DOT) borland.com>, Shahram wrote:
Hi all,
How can I rotate a TShape component?
You could try something like this:
type
TMGC_RotateShape = class(TShape)
private
fAngle: extended;
procedure SetAngle(const Value: extended);
protected
procedure Paint;override;
public
constructor Create(aOwner: TComponent);override;
{in degrees}
property Angle: extended read fAngle write SetAngle;
end;
implementation
uses Math;
{$R *.DFM}
{ TMGC_RotateShape }
constructor TMGC_RotateShape.Create(aOwner: TComponent);
begin
fAngle:= 0;
inherited;
end;
procedure TMGC_RotateShape.Paint;
var
xForm,xFormOld: TXForm;
gMode: DWORD;
radA: extended;
OldOrg: TPoint;
begin
radA:= DegToRad(Angle);
{GM_ADVANCED requires W98 up}
gMode:= SetGraphicsMode(Canvas.Handle,GM_ADVANCED);
try
XForm.eM11 := Cos(radA);
XForm.eM12 := Sin(radA);
XForm.eM21 := - Sin(radA);
XForm.eM22 := Cos(radA);
{shifts the offset as it rotates so the rotation is around the
center. Set to zero to rotate around top left}
XForm.eDx := ((Width/2)-(Cos(radA)*(Width/2)))
+((Sin(radA)*(Height/2)));
XForm.eDy := ((Height/2)-(Sin(radA)*(Width/2)))
-((Cos(radA)*(Height/2)));
if GetWorldTransform(Canvas.Handle,xFormOld) then
try
SetWorldTransform(Canvas.Handle,XForm);
inherited;
finally
SetWorldTransform(Canvas.Handle,XFormOld);
end;
finally
SetGraphicsMode(Canvas.Handle,gMode);
end;
end;
procedure TMGC_RotateShape.SetAngle(const Value: extended);
begin
fAngle := Value;
Repaint;
end;
Should give you some ideas.
Gordon
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|