It’s possible to know the pixel lenght of a string ?
I.E.
I want draw at the end of text “foo iiii”.
I use the glRasterPos
to assign the start postion of the text.
Now I want to know the final postion, after the last “i” letter.
How I can do this?
I try with
len(“foo iii”)*LETTER_WIDTH, but the letter
don’t have the same width…I.E. the “i” is smaller pixel
size than “o”.
Ah…another little question: can you tell me the code for a composite event, like SHIFT+AKEY?
I try like this:
if (evt == AKEY and val):
if (evt == LEFTSHIFTKEY and val):
print "A"
else:
print "a"
I have the same problem in Blender, i tries to work around it by using the digitalreadout.tga. I used a plane with a fixed size (for example 1x1 units) and moved an empty each time a key was pressed. It more or less works except for the “.” character, etc…
i hope this helps a little and maybe someone else found a more elegant solution…
Yeah I ended up doin somethin like that. But its VERY tedious, and it only works properly for one particular font because the relative sizes of the characters can be different for different fonts. What bitmap font did you use to work those out?
Keys pressed with the shift key have a different ascii value to keys pressed without the shift key. for example Shift+A produces a capital A which has an ascii value of 65. but just pressing ‘a’ on its own will produce a small case ‘a’ which has a different ascii value (not sure what it is) Most programs test if the ‘a’ has been pressed on its own by determining if the ascii value of the key pressed is equal to the ascii value of little ‘a’. They test if the Shift+A has been pressed by determining if the ascii value of the key pressed is equal to the ascii value of capital ‘A’, 65. Thats the simplest way to do it, but it relies on CAPS LOCK being off.