Mirage Engine
Get the REAL width of text - Printable Version

+- Mirage Engine (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: Get the REAL width of text (/showthread.php?tid=806)



Get the REAL width of text - Robin - 08-03-2007

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



Re: Get the REAL width of text - GIAKEN - 22-07-2008

How do we use this? :? It doesn't make sense...I'm wanting a function that returns the width of the text in pixels? Why do we need the array there?


Re: Get the REAL width of text - GIAKEN - 22-07-2008

Nevermind I figured it out Big Grin I was about to delete my post. Anyways, it doesn't appear to truely center text Sad

Code:
TextX = ((GetPlayerX(Index) * PIC_X + Player(Index).XOffset) + 16) - (getSize(frmMirage.hdc, GetPlayerName(Index)).width / 2)



Re: Get the REAL width of text - GIAKEN - 22-07-2008

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.


Re: Get the REAL width of text - Robin - 22-07-2008

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.


Re: Get the REAL width of text - GIAKEN - 22-07-2008

I'm aware of the date Wink

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).


Re: Get the REAL width of text - seraphelic - 22-07-2008

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


Re: Get the REAL width of text - Robin - 22-07-2008

I made mine in 2007, you made yours in 2008.