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 / Pixel length of strings

Author
Message
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 18th Nov 2004 03:12
I want to be able to get the length of a string in pixels, given the string and the text size. I have tried, but the problem is that all letters are not the same width, so I cannot get the right length. Has anybody created something so I can do this? It is for a name entering subroutine so that I can place a blinky cursor at the end of the name. I cannot add the cursor to the end of the string because the text is centered and otherwise it moves back and forth when the dash is replaced with a space... but I can always use a non blinking dash if no one can get this working.

Thanks

Xander Moser - Bolt Software - Firewall
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 18th Nov 2004 03:59


with some editing you should be able to get this working better
there is a way to get the length of text, but i really would recommend against trying to do it through the winapi.


Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 18th Nov 2004 04:19
Wow, you sure do have some confusing timer stuff in there...

Sadly, I don't think you quite understood me...I know how to do the input thing using the entry buffer, I have it all set up, it even writes the text to a texture for an object.

My problem is that when the text is centered I can't have a blinking cursor because then it offsets the text different than a space, as in the snippet below (your code, except I centered the text instead):



See what I mean?

Oh well, if what I want is not possible I will just skip the blinking cursor, not a problem.

Thanks anyway

Xander Moser - Bolt Software - Firewall
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 18th Nov 2004 04:24
the cursor is 1 pixel wide, just offset by a pixel... and make sure the cursor is always either | or " "


Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 18th Nov 2004 07:30
Just do something like;

Text x,y,mystr$
Text x + (Text Width(mystr$) / 2) + 1,y,"|"

Is that what you're after? As that will position the cursor at the end of the centred text.

Alternatively, the input routine that I mentioned a little while ago via email, if you like, I can have a shot at porting it to DBC ( Shouldn't be hard ) and you can give that a whirl?

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 18th Nov 2004 13:31
@ Jess: Actually, today, I redid the input routine using the entry buffer, it works perfectly and can even grab the images in mid typing. It's awesome. Thanks for suggesting it.

Well, I am just making the text flash instead, but the problem that I was having was the my text had to be centered, and the "|" or "_" was a different number of pixels than a " ". So, I had to find the perfect pixel length of the text to position the cursor after it, or else when the "_" is replaced with a " " the text gets offset a little more to the left or right because it is centered so it shakes as it changes.

Well, never mind. Thanks anyway.

Xander Moser - Bolt Software - Firewall
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 19th Nov 2004 07:19
Alrighty
Glad to help

Also, if you are having the problem with the text "shaking", as you are adding the extra character to the end of the string, why not simply paste the input string, then, seperatly paste the cursor string? (As I showed just above ).

That way, it will always keep the input string in the one spot, and you can also just past the cursor anywhere in the string ( if, for example, you want to use the Left and Right keys [as my input routine does] to edit the string ).

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 19th Nov 2004 11:23
Well, I was trying to do just what you suggested. The problem is that not every letter is the same length, pixel-wise. So it was impossible to find the correct position to place the cursor, unless I had the pixel width of each letter. Get it now?

Off topic: Next beta almost ready!

Xander Moser - Bolt Software - Firewall
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 19th Nov 2004 20:33 Edited at: 19th Nov 2004 20:34
Um... Call me stupid, but I still don't follow...

Here, I just smacked this together to show you what I mean, how the carret is just put at the end of the string...



Is that what you meant too? lol.
( I'm so lost right now )

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 19th Nov 2004 23:21
Um...I think you should call me stupid.

I was using the len() command to find the length of the string. I was too stupid to look in the manual for the text width() command, it is exactly what I was looking for.

I often tell people to look in the manuals for commands that they have really simple answers for. I think it is about time that I take my own advice...

Xander Moser - Bolt Software - Firewall
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 20th Nov 2004 11:23
lol.

Don't worry about it bro.
We all look past the simple commands sometimes, and get ourselves in a bit of a pickle

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!

Login to post a reply

Server time is: 2025-05-24 12:47:22
Your offset time is: 2025-05-24 12:47:22