View Full Version : drawing sentered text?!
Diaboli
24-01-2007, 09:50 PM
I dont know if there is something about this out on the forum. i looked for it, but didnt find anything useful.
I need to display text that is sentered. for instance captions on buttons and names of players (wich needs to be directly overhead)
I had some code for this a while ago, but i managed to delete it... :(
hoping for help! :D
P.S: And i use UnDelphiX and Delphi 2006.
If the text drawing routines use the top-left for position, then all you need to do is this.
Calculate where you want the centre of the text to be. For a button,
CentreX := Button.Left + (Button.Width / 2);
CentreY := Button.Top + (Button.Height / 2);
Calculate the width and height of the text. I don't know DelphiX, so I'm not sure what the functions would actually be.
TextWidth := GetTextWidth(MyString);
TextHeight := GetTextHeight(MyString);
Now calculate where to draw the text.
TextX := CentreX - (TextWidth / 2);
TextY := CentreY - (TextHeight / 2);
And draw it. Again, replace the function with what DelphiX actually uses.
DrawText(MyString, TextX, TextY);
Diaboli
25-01-2007, 07:32 AM
i cant see that UnDelphiX HAS a similar function as "GetTextWidth"..
anyone using UnDelphiX here that know this?
Set your canvas font size and name
then
DXDraw1.Surface.Canvas.TextOut(100-DXDraw1.Surface.Canvas.TextWidth('test'), 10, 'test');
Don't forget to release.
Diaboli
25-01-2007, 08:54 AM
Thanx lots! :D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.