Game Development Community

GuiTextEditCtrl cursor fix (plus some more)

by Daan Broekhof · in Torque Game Engine · 09/20/2004 (1:24 pm) · 8 replies

In my journey to better understand Torque, I tried to make a fix for a gui glitch: 'Cursor misplacement in GuiTextEditCtrl'
(you know when you get to the end of a single line text edit box the cursor suddenly is drawn through a character instead of before it)

While at it I also improved it a bit to get cursor scrolling a-la default edit boxes in windows, which includes:
- Maintaining the offset when editbox is not in focus
- Free cursor when textlength is greater then the editbox width
- Hopping ahead or back a length (atm 1/4 of the total editbox width) when the cursor exceeds the editbox boundaries

The current code had has some commented lines which I suspect was trying to do the same (the commented lines dated more then 2 years back and were prefixed with '//BH'), so I also removed those.
Added a mTextOffsetReset bool member which is set to true when the offset needs to be recalculated (on resize or first draw), previously mTextOffset.x was abused for this (setting it to '65535'.. :P)

It now also looks at the mProfile->mTextOffset for padding (all sides), instead of a hardcoded 3 pixel vertical padding.
(but defaulting to '3' for when mProfile->mTextOffset.x is 0, as not to break backward compatibility. A better fix would be to make mProfile->mTextOffset.x have 3 as default, but I want to keep the scope of my changes small, your judgement on weither to change this too? )

Another lil addition is making the password mask character modifiable. (instead of a hardcoded '*', defaults now to '*')

I tested this quite a bit with all text alignments, but as this is my first largish hack into the source, please review it carefully..

(and I'd love a preview post feature ;))

[code coming next post(s)..]

#1
09/20/2004 (1:41 pm)
Njar.. posting more then 4k of code is nasty... do I have permission to put the changes in a seperate html file, and link that one here?
(its 7k in all, written out, only containing changes and the guiTextEditCtrl::DrawText function as it was changed for 80% )
#2
09/20/2004 (1:48 pm)
Post it in the resource section
#3
09/20/2004 (1:56 pm)
Ah ofcourse.. here is the resource (not approved yet)
#4
09/27/2004 (8:30 am)
One week later.. hmm they should enable some associates to approve resources to remove this bottleneck..
#5
09/27/2004 (8:49 am)
Good stuff. You should see about making a patch and getting it added to HEAD.
#6
09/27/2004 (9:25 am)
Added diffs vs current HEAD to the resource.
#7
09/27/2004 (10:10 am)
Works like a charm. This was one thing that nagged me. Well done, thank you for sharing
#8
08/04/2005 (10:07 pm)
Issue #95 closed. Nice code.