Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the REAL width of text
#1
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
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#2
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?
Reply
#3
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)
Reply
#4
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.
Reply
#5
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.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#6
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).
Reply
#7
I made a center text tutorial a while back using this method.
http://web.miragesource.com/forums/viewt...&sk=t&sd=a
Reply
#8
I made mine in 2007, you made yours in 2008.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)