Forum > General

BGRAControls:TBGRAShape

(1/1)

morknot:
I would like to use BGRAShape to rotate a rectangle, keeping its original dimensions, using the Angle property.
 I have tried the following:

Set the original BGRAShape.Height to 50, Width to 100 and Angle to 45
Use a trackbar to increment the angle, Min 45 Max 90
In the trackbar onchange event try to adjust the BGRAShape dimensions with

BGRAShape1.Width:=Trunc(50*cos((Trackbar1.Position)*pi/180) + 100*sin(Trackbar1.Position*pi/180));

BGRAShape1.Height:= Trunc((50*sin(Trackbar1.Position)*pi/180) +(100*cos(Trackbar1.Position*pi/180)));

This does not maintain the original dimensions.

Is it possible to achieve what I want and if so is Angle related to the centre point of the shape or the X or Y axis? Is the formula I am using just plain wrong?

Grateful for any advice.
 

Handoko:
I've just tested BGRAShape. On design time, I cannot configure the correct values for a proportional rectangle (ratio 2:1) with 30 degree. BGRAShape has UseRatioXY but it also can't give the correct result. You can test it yourself. So that makes me think BGRAShape cannot do what you want to achieve. Perhaps it is a bug.

Well, if want you can use my code RectRotate.zip:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, Forms, Controls, Graphics, ComCtrls, StdCtrls, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)    PaintBox1: TPaintBox;    TrackBar1: TTrackBar;    procedure TrackBar1Change(Sender: TObject);  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.TrackBar1Change(Sender: TObject);const  ShapeWidth  = 100;  ShapeHeight = 50;  degtorad    = pi/180;var  Angle            : Integer;  X1, X2, Y1, Y2   : Integer;  CanvasX, CanvasY : Integer;begin  Angle := TrackBar1.Position;  X1      := Round(ShapeWidth*cos(Angle*degtorad) - ShapeHeight*sin(Angle*degtorad));  X2      := Round(ShapeWidth*cos(Angle*degtorad) + ShapeHeight*sin(Angle*degtorad));  Y1      := Round(ShapeWidth*sin(Angle*degtorad) + ShapeHeight*cos(Angle*degtorad));  Y2      := Round(ShapeWidth*sin(Angle*degtorad) - ShapeHeight*cos(Angle*degtorad));  CanvasX := PaintBox1.Width  div 2;  CanvasY := PaintBox1.Height div 2;  PaintBox1.Refresh;  PaintBox1.Canvas.Line(CanvasX+X1, CanvasY-Y1, CanvasX+X2, CanvasY-Y2);  PaintBox1.Canvas.Line(CanvasX+X2, CanvasY-Y2, CanvasX-X1, CanvasY+Y1);  PaintBox1.Canvas.Line(CanvasX-X1, CanvasY+Y1, CanvasX-X2, CanvasY+Y2);  PaintBox1.Canvas.Line(CanvasX-X2, CanvasY+Y2, CanvasX+X1, CanvasY-Y1);end; end.

morknot:
Thank you for your reply and code, Handoko. I think you are right that BGRAShape is not able to do what I want.

morknot:
I don't know if anyone is interested but a partial solution to rotating a constant sized shape is to use TuEKnob or TuEMultiturn.

Create a bitmap of the shape and size you want. Assign the bitmap to the Picture property of either of the above. Set the width and height of the knob or multiturn to the maximum dimension likely to be achieved by rotating the shape to take account of the changing width and height (e.g. the corners on a rectangle).

Rotate!

Navigation

[0] Message Index

Go to full version