| Mirage Source http://miragesource.net/forums/ |
|
| Get the REAL width of text http://miragesource.net/forums/viewtopic.php?f=210&t=1470 |
Page 1 of 1 |
| Author: | Robin [ Thu Mar 08, 2007 9:13 pm ] |
| Post subject: | Get the REAL width of text |
Perfect for those who can't seem to centralise names [cleared] I also found it useful when I made Nr completely in DX. Code: 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 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 Code: Public Type textSize
width As Long Height As Long End Type |
|
| Author: | GIAKEN [ Tue Jul 22, 2008 3:45 am ] |
| Post subject: | Re: Get the REAL width of text |
How do we use this? |
|
| Author: | Lea [ Tue Jul 22, 2008 3:49 am ] |
| Post subject: | Re: Get the REAL width of text |
Robin, is DC the destination DC? Like of the picture box? Dim t as textSize t = getTextSize(DC, "This is my string") Dim i as long i = t.width |
|
| Author: | GIAKEN [ Tue Jul 22, 2008 3:52 am ] |
| Post subject: | Re: Get the REAL width of text |
Nevermind I figured it out Code: TextX = ((GetPlayerX(Index) * PIC_X + Player(Index).XOffset) + 16) - (getSize(frmMirage.hdc, GetPlayerName(Index)).width / 2)
|
|
| Author: | GIAKEN [ Tue Jul 22, 2008 4:18 am ] |
| Post subject: | Re: Get the REAL width of text |
Alright I just did some tests. The actual width of the text (checked with Photoshop) is 48 pixels. getSize returns 43. Len(Text) * 8 returns 48, which is what was the system that was in place. |
|
| Author: | Robin [ Tue Jul 22, 2008 8:38 am ] |
| Post subject: | Re: Get the REAL width of text |
This is over a year old xD And I'm aware it doesn't centralise it perfectly, but it does it a lot better than len*x on different sized fonts. |
|
| Author: | GIAKEN [ Tue Jul 22, 2008 5:37 pm ] |
| Post subject: | Re: Get the REAL width of text |
I'm aware of the date This would only be useful on font that varies in size between letters. Also I noticed: When using frmMirage.hDC it was 43 and when I used frmMirage.picScreen.hDC it returned 32 (or some 30 number). |
|
| Author: | seraphelic [ Tue Jul 22, 2008 5:56 pm ] |
| Post subject: | Re: Get the REAL width of text |
I made a center text tutorial a while back using this method. http://web.miragesource.com/forums/viewtopic.php?f=75&t=3562&start=0&st=0&sk=t&sd=a |
|
| Author: | Robin [ Tue Jul 22, 2008 5:58 pm ] |
| Post subject: | Re: Get the REAL width of text |
I made mine in 2007, you made yours in 2008. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|