Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: String & Pixels  (Read 4631 times)

0 Members and 1 Guest are viewing this topic.

MMR

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 349
  • http://mmrdeveloper.wordpress.com/
    • View Profile
    • TinyWME
String & Pixels
« on: July 03, 2005, 03:41:24 PM »

How can we know/calculate the size/length (in pixels) of a string using a determinate font?? e.g. to center a string (that changes it content) in the middle of the screen.

;)
Logged

Nihil

  • Supporter
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 528
  • Fear me! I'm evil!
    • View Profile
    • Order of Dagon
Re: String & Pixels
« Reply #1 on: July 03, 2005, 10:25:07 PM »

I guess you could use the Length-attribute of strings and multiply it with the width of the characters, but that would only work with bitmap-fonts, don't know how to get the size of TTFs.

McCoy

  • The cocido eater
  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 365
  • Spurrrrrrring
    • View Profile
    • Spur Games
Re: String & Pixels
« Reply #2 on: July 04, 2005, 12:10:54 AM »

Mhh... one thing that comes to my mind is to put the string inside a static control, then use the .SizeToFit() to automatically change its size to the string length. Then you just read the .width attribute of the static control, and voilá! :). And this way it will work with TTF and bitmap fonts.
Logged

Click here to sign my sig!

MMR

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 349
  • http://mmrdeveloper.wordpress.com/
    • View Profile
    • TinyWME
Re: String & Pixels
« Reply #3 on: July 04, 2005, 12:12:02 AM »

Good idea McCoy ;) thanks

I'm using TTF fonts
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: String & Pixels
« Reply #4 on: July 04, 2005, 09:16:29 AM »

Yes, SizeToFit() is the (only) way to go.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

MMR

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 349
  • http://mmrdeveloper.wordpress.com/
    • View Profile
    • TinyWME
Re: String & Pixels
« Reply #5 on: July 04, 2005, 12:58:30 PM »

Yep, it works fine. Just what I needed ;)
Logged

McCoy

  • The cocido eater
  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 365
  • Spurrrrrrring
    • View Profile
    • Spur Games
Re: String & Pixels
« Reply #6 on: July 04, 2005, 08:38:51 PM »

I'm not sure, but I think this method is used for the pointed object caption in the WME demo.
Logged

Click here to sign my sig!
 

Page created in 0.024 seconds with 18 queries.