| Mirage Source http://miragesource.net/forums/ |
|
| Exact Center? - BltPlayerName http://miragesource.net/forums/viewtopic.php?f=210&t=208 |
Page 1 of 1 |
| Author: | Leighland [ Fri Jun 30, 2006 11:03 pm ] |
| Post subject: | Exact Center? - BltPlayerName |
I have a small issue but it's driving me nuts lol. The names never seem to be centered over the player sprite. They're always a few pixels off.. and it doesn't look very nice to me. If anyone has managed to center the text exactly over the player sprite can you post your code please? :p |
|
| Author: | Misunderstood [ Fri Jun 30, 2006 11:10 pm ] |
| Post subject: | |
to get the text size of a string you can use this. Code: Public Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As textSize) As Long
Public Function getSize(ByVal DC As Long, ByVal Text As String) As textSize Dim lngReturn As Long Dim typSize As textSize lngReturn = GetTextExtentPoint32(DC, Text, Len(Text), typSize) getSize = typSize End Function Public Type textSize width As Long height As Long End Type |
|
| Author: | Leighland [ Fri Jun 30, 2006 11:15 pm ] |
| Post subject: | |
User defined type not defined, highlightes: Public Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As Point) As Long |
|
| Author: | Misunderstood [ Fri Jun 30, 2006 11:27 pm ] |
| Post subject: | |
whoops, change that to this Code: Public Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As textSize) As Long
|
|
| Author: | Leighland [ Fri Jun 30, 2006 11:35 pm ] |
| Post subject: | |
Okay, now how do I use it |
|
| Author: | Misunderstood [ Fri Jun 30, 2006 11:43 pm ] |
| Post subject: | |
in the blt name sub the x should be the getplayerx(index) * pic_x + 16 - (getSize(texthdc,getplayername(index)).width/2) |
|
| Author: | funkynut [ Sat Jul 01, 2006 1:32 am ] |
| Post subject: | |
There is a picbox function that will allow you to get the exact text width and height on any font All you do is set the picbox to the font you want, then you call the gettextwidth (or something) function. Dunno if its quicker then api |
|
| Author: | Robin [ Sat Jul 01, 2006 11:16 am ] |
| Post subject: | Re: Exact Center? - BltPlayerName |
Leighland wrote: I have a small issue but it's driving me nuts lol. The names never seem to be centered over the player sprite. They're always a few pixels off.. and it doesn't look very nice to me. If anyone has managed to center the text exactly over the player sprite can you post your code please? :p
I'm not 100% sure on this, but in the BltPlayerName sub, is there a ' * 6' or some other number. I think it works out the length of the word, then times it be the amount of pixels per letter. So just play around with that number (you can have decimals) ~Kite |
|
| Author: | Misunderstood [ Sat Jul 01, 2006 7:26 pm ] |
| Post subject: | |
well each letter is a different with, thats why this function is useful, it gets the exact width, ms uses 8*len, which is only an estimate. Also I posted a reply to funky before but I don't see it here...maybe I posted it in the wrong place xD. I think the picture box probably uses this API, so I doubt it would be faster. Course I don't really know... |
|
| Author: | Leighland [ Sun Jul 02, 2006 7:49 pm ] |
| Post subject: | |
Meh solved my problem lol. I set up an if statement to check wehther or not the length of the name was longer than 6 characters. If it is * by 5, else * by 6... works well for the most part |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|