Mirage Source
Centering Player Name (100% accurate) - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49)
+---- Thread: Centering Player Name (100% accurate) (/showthread.php?tid=1663)



Centering Player Name (100% accurate) - seraphelic - 06-04-2008

Centering Player Name (100% accurate)
[Difficulty: 1/5] (Copy-Paste)

Basically this tut will show you how to use the call GetTextExtentPoint32 to find the width of the name and then how to encorporate it into the sub BltPlayerName.

ALL CLIENTSIDE:
In modDeclares, add this:
Code:
Public Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hDC As Long, ByVal lpszString As String, ByVal cbString As Integer, ByRef lpSize As Size) As Integer
*note ~ I set this to integer because I dont need to find the length of anything more than 255 chars

In modTypes, add this:
Code:
Type Size
cx As Long
cy As Long
End Type
This creates the type Size which GetExtentPoint32 needs to dump the text info

Now go to BltPlayerName and add these at top:
Code:
Dim textSize As Size
Dim textWidth As Integer

Under the color assigns, add this:
Code:
'measure width of name
    SelectObject TexthDC, GameFont
    GetTextExtentPoint32 TexthDC, GetPlayerName(Index), Len(GetPlayerName(Index)), textSize
    textWidth = textSize.cx
This gets the size info for your name and assigns the width to textWidth

Now replace:
Code:
TextX = GetPlayerX(Index) * PIC_X + Player(Index).XOffset + Int(PIC_X / 2) - ((Len(GetPlayerName(Index)) / 2) * 8)
With:
Code:
TextX = (GetPlayerX(Index) * PIC_X) + (Player(Index).XOffset) + (Int(PIC_X / 2)) - (Int(textWidth / 2))
This changes the old x coordinate assign to center the text with the new info.

And you're done! You can apply this to NPC names, the map name, and whatever else you want to center.


Re: Centering Player Name (95%+ accurate) - Stomach Pulser - 06-04-2008

screens pl0x!


Re: [WORKING] Centering Player Name (100% accurate) - seraphelic - 09-04-2008

*Bump and image of working example

[Image: centeredname.png]


Re: [WORKING] Centering Player Name (100% accurate) - Matt - 09-04-2008

Doesn't look centered to me..


Re: [WORKING] Centering Player Name (100% accurate) - Rian - 09-04-2008

It's not 100% centered, but at least you know it's always gonna be fairly consistent.


Re: [WORKING] Centering Player Name (100% accurate) - Robin - 09-04-2008

Not really. I've been using this function for a long time and it's very temperamental.


Re: [WORKING] Centering Player Name (100% accurate) - seraphelic - 09-04-2008

hey 32px on the left, 30 px on the right. but the sprite is 1 px to the right anyways (19px wide), that is centered to me ;P


Re: [WORKING] Centering Player Name (100% accurate) - Matt - 09-04-2008

seraphelic Wrote:hey 32px on the left, 30 px on the right. but the sprite is 1 px to the right anyways (19px wide), that is centered to me ;P

Regardless if it's center to you or not, it's not 100% centered.

Tongue

Which is what you claim with this. So, you're wrong. ^_^


Re: [WORKING] Centering Player Name (100% accurate) - Rian - 09-04-2008

You know, I could swear the tutorial used to say 95% accurate


Re: [WORKING] Centering Player Name (100% accurate) - seraphelic - 09-04-2008

thats because i was using a different method because i couldnt get GetTextExtentPoint32 to work. My source renders the map name and player name perfectly centered, ive tested 7pt, 8pt, 9pt, and 10pt with tahoma, verdana, and a couple others.


Re: [WORKING] Centering Player Name (100% accurate) - Aydan - 13-04-2008

works perfectly for me ^^

looks absolutely fantastic finally names will look correct to me.

A very nice tut mate well done :mrgreen: