Search

Main Menu

Login
Username:

Password:

Remember me?
Anonymous

Lost Password?

Register now!

Samurize Forums -> Rotate Meter Controls


Pages: (2) 1 [2]   ( Go to first unread post ) Reply to this topicStart new topic

> Rotate Meter Controls, A function to rotate Meters in Editor
AdamC
Posted: Oct 12 2007, 07:58 AM
Quote Post
The Programming Frog
*****



Group: Admin
Joined: Sep 26 2003
Posts: 2,496
Offline



At the moment I've not got time to work on anything so nothing is happening. The code I worked on very did as I would of expected. If Loki can show me the code he used then that would be great and would probably be easier to put in (hopefully).
PMICQAOLYahooMSN
Top
loki
Posted: Nov 3 2007, 02:22 AM
Quote Post
Ninja
**



Group: Contributor
Joined: Sep 28 2003
Posts: 89
Offline



REEEALLY sorry about the delay in this :-(
I've been so swamped.
My transparency code is ugly, so I'll just paste the 2 main functions below.

The first function shows how to draw angled text on any canvas.
Note - the font MUST be true type (TTF). fixed width cannot be rendered in angles.
Th eimportant bit is "lfEscapement" - it's the angle
The second funciton is something I whipped up to calculate the rectangle of the rotated text.
You may/may not need it.

For angling the other way I simply reversed the bitmap hotrizontally/vertically first.

Once again, sorry for the delay. Let me know if you need the full code, or if something needs explaining.

CODE

procedure TRenderAngleTextThread.CanvasTextOutAngle(c: TCanvas; x,y: Integer; d: Word; s: string);
   var
       LogRec: TLOGFONT;     {* Storage area for font information *}
       OldFontHandle,        {* The old font handle *}
       NewFontHandle: HFONT; {* Temporary font handle *}
   begin
                 {* Get the current font information. We only want to modify the angle *}
       GetObject(c.Font.Handle, SizeOf(LogRec), Addr(LogRec));
                 {* Modify the angle. "The angle, in tenths of a degrees, between the base
       line of a character and the x-axis." (Windows API Help file.)*}
       LogRec.lfEscapement := d;
//  LogRec.lfOrientation := d;
                 {* Create a new font handle using the modified old font handle *}
       NewFontHandle := CreateFontIndirect(LogRec);
                 {* Save the old font handle! We have to put it back when we are done! *}
       OldFontHandle := SelectObject(c.Handle,NewFontHandle);
                 {* Finally. Output the text! *}
       c.Brush.Style := bsClear;
       c.TextOut(x,y,s);
                 {* Put the font back the way we found it! *}
       NewFontHandle := SelectObject(c.Handle,OldFontHandle);
                 {* Delete the temporary (NewFontHandle) that we created *}
       DeleteObject(NewFontHandle);
   end; {* CanvasTextOutAngle *}

procedure TRenderAngleTextThread.BitmapTextOutAngle(var bmp: TBitmap; angle: integer; s: string);
   var
       rect: trect;
       t_width, t_height: integer;
       coords: array[1..4] of tpoint; // top left, top right, bottom right, bottom left,
       startx, starty: integer;
       i: integer;
       radangle: extended;
       currentbrangle: extended;
       length3: extended;
       topleft: TPoint;
       bottomright: TPoint;
       shadowstartx, shadowstarty: extended;
       shadowangle: integer;
   begin
       t_width := bmp.Canvas.TextWidth(s);
       t_height := bmp.Canvas.TextHeight(s);

       radangle := degtorad(angle);
       length3 := sqrt( sqr(t_width) + sqr(t_height) );
       currentbrangle := 360 - radtodeg(arctan((abs(t_height) / abs(t_width))));
       coords[1].x := (round(0 * cos(radangle)));
       coords[1].y := 0 - round(0 * sin(radangle));
       coords[2].x := round(t_width * cos(radangle));
       coords[2].y := 0 - round(t_width * sin(radangle));
       
       coords[3].x := round(length3 * cos(degtorad(currentbrangle) + radangle));
       coords[3].y := 0 - round(length3 * sin(degtorad(currentbrangle) + radangle));
       
       coords[4].x := round(t_height * cos(degtorad(270) + radangle));
       coords[4].y := 0 - round(t_height * sin(degtorad(270) + radangle));
       
       topleft.x := 0;
       topleft.y := 0;
       bottomright.x := 0;
       bottomright.y := 0;
       for i := 1 to 4 do
       begin
           if coords[i].x < topleft.x then topleft.x := coords[i].x;
           if coords[i].y < topleft.y then topleft.y := coords[i].y;
           if coords[i].x > bottomright.x then bottomright.x := coords[i].x;
           if coords[i].y > bottomright.y then bottomright.y := coords[i].y;
       end;

       bmp.Width := (bottomright.x - topleft.x) + 1 + XOffset;
       bmp.Height := (bottomright.y - topleft.y) + 1 + YOffset;
       startx := (0 - topleft.x) + XOffset;
       starty := (0 - topleft.y) + YOffset;

       if DrawShadow then
       begin
// work out the position of the shadow (45 degree offset)
           shadowangle := angle + ShadowOffsetAngle;
           while (shadowangle > 359) do dec(shadowangle, 360);
           while (shadowangle < 0) do inc(shadowangle, 360);
           GetDestinationPoint(shadowangle, ShadowDistance, shadowstartx, shadowstarty);

           bmp.Canvas.Font.Color := ShadowColor;
           CanvasTextOutAngle(bmp.canvas, trunc(startx + shadowstartx), trunc(starty + shadowstarty), angle * 10, s);
           bmp.Canvas.Font.Color := text_fontcolor;

       end;
       CanvasTextOutAngle(bmp.canvas, startx, starty, angle * 10, s);
   end;


--------------------
}-=Loki=-{
PMEmail PosterICQAOLYahooMSN
Top
AdamC
Posted: Nov 3 2007, 04:00 PM
Quote Post
The Programming Frog
*****



Group: Admin
Joined: Sep 26 2003
Posts: 2,496
Offline



Thanks loki I'll look into using these, they do look familar to what I have but there might be something in there that I missed when I was doing the code.
PMICQAOLYahooMSN
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages: (2) 1 [2]  Reply to this topicStart new topic

 

Come On, Get Samurized!