Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / text selection

Author
Message
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 6th Jan 2011 01:49
ok I change the text size and suddenly text height() and text width() don't work. i was able to make up for the height by just using text size(), but how can i make up for the width?

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Jan 2011 14:23
The default font uses a constant width for each character. So if you can figure out the width of 1 character then you can just multiple the length of the string by that size. If you're using a different font then you'd have to use the text width() command. I don't see why it wouldn't be working for you, do you get errors? What's the output from the function?

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 6th Jan 2011 18:48
you know the text size it stats with is 10 right? no matter what the text size changes too. the computer seems to think its still 10 and of course since i changed the size of the text. the actual text gets bigger or smaller, but the computer doesn't see to realize that.

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th Jan 2011 18:59
I seem to remember running into problems setting the font to a different size when using the default font. Try changing it to Arial or something like that.

It could also be that when you changed the font, you forgot to put the ",0" at the end. It didn't used to be required but now it is (I think it was after the most recent patch)

So it would have to be:
SET TEXT FONT "Arial",0

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Jan 2011 22:22
For DBC versions 1.20 >

Make sure you add the character set after choosing a font. The English character set is ,1

set text font "arial",1

Whenever you change the text size, it's best to call a sync. That "locks in" the size change right then and there.

A general font rule of thumb is you can retrieve the text height for a particular font by querying on gM:

value=text height("gM")

That should cover the the entire bounding area. That should also match the text size().

Enjoy your day.
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 7th Jan 2011 04:36
I got the font to change properly. I just put a ",1" at the end of the set text font command. I'll try the sync thing. its not the height i'm having problem with. its the width. when i used text width. its giving me false values. for the height, i'm just using the size and it seems to be working. i'll check it out. its only a minor bug in my program atm. something that can be fixed pretty easy

Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 12th Jan 2011 21:57
I had this problem a lot when I was working on textboxes!

DBC will change font or font size at any point and the text command will update immediately, but the commandsto return text width only apply to the combination that was set before the last sync command.

Text Width()/Text Height() seem to be tied in to Sync, so to make them return the right values you have to call sync immediately after defining your font and/or font size.

This isn't particularly good (calling a Sync in the middle of a loop) so workarounds include restricting yourself to a single Font/Font size combination or pre-rendering all letters as images and pasting them to screen instead of calling "text".

This last version is better because "Paste image" is much faster than "Text", and you already know the image width of each letter so you can write your own "Text Width" command - simply sum the widths of the images making up each letter in the string. This'll be much faster than the official text width command, as well!

I've not been around here for a while - but it's good to be back!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Jan 2011 18:25 Edited at: 14th Jan 2011 18:26
Quote: "you know the text size it stats with is 10 right? no matter what the text size changes too. the computer seems to think its still 10 and of course since i changed the size of the text. the actual text gets bigger or smaller, but the computer doesn't see to realize that."

Then simply multiply your text size by 1/10 of text width().

Does this function work? I just wrote it and haven't tested. Hope it helps.



Everything worthwhile requires effort.

Login to post a reply

Server time is: 2024-04-25 01:09:22
Your offset time is: 2024-04-25 01:09:22