Game Development Community

Cursor position problem with GUIMLTextEditCtrl

by DeadElvis · in Torque Game Engine · 01/09/2008 (9:54 am) · 4 replies

I posed this question here several months ago but did not get a response with a solution so I thought I would try again and try to explain the problem with more detail.

I am running TGE 1.5.2.

I need a multi line text area, several, in fact, on a GUI where users can enter and edit text that could be up to several paragraphs in length. This text must be gotten by script and stored in a DB. Text must also be fetched from the DB and populated in the MLTextEdit controls for editing.

If there is any other Torque control capable of doing this, please let me know.

ALL of this is working fine except for one annoying, irritating, and frustrating problem with the cursor in all these controls. The text cursor is always one character to the left the character that is the focus. Here are some behaviors I have noticed.

* when the control first gain focus via TAB or a mouseclick, the cursor appears at the very end of the text already populated in the control exactly where it should. Almost immediately, the cursor backs up one space and stays one character to the left as long as the control has focus. Pressing END does not correct this.

* clicking the mouse inside any text in the control places the cursor one character to the left of the character you clicked on

* Backspace deletes the char to the right of the curson rather than the left like you would expect.

* This behavior does NOT occur when using the GUITextEditCtrl, only the ML version.

I have searched the Torque site carefully and, while I did see this problem reported a couple of times, the solutions were changes to the engine code that, as far as I know, have already been implemented with the current TGE. Nevertheless, I double checked and made sure that my TGE engine code matched the resource suggestions. Is there any example that comes with TGE of a multi-line text edit control that works correctly?

I've goofed with the C++ code a bit trying to add one to the cursor position with mixed results. None of them less irritating than the original problem.

If anyone can point me in the right direction to fix this, I would greatly appreciate it.

#1
01/09/2008 (11:12 am)
Hi,

I had this problem too. Here's how I fixed it:
In guiMLTextCtrl, look for:
x += font->getStrNWidth(buff, mCursorPosition - awalk->textStart - 1);
inside GuiMLTextCtrl::getCursorPositionAndColor

and change to:
x += font->getStrNWidth(buff, mCursorPosition - awalk->textStart);
#2
01/09/2008 (11:53 am)
That's IT! Thanks so much, Igor, I am eternally grateful. Works wonderfully now.
#3
06/04/2009 (8:52 am)
For me the problem still occured in TGEA although the TGEA code is reading

x += font->getStrNWidth(buff, mCursorPosition - awalk->textStart); // -1

I then changed it to

x += font->getStrNWidth(buff, mCursorPosition - awalk->textStart+1); //-1

and now it also works for me. These off by one errors ...
#4
06/04/2009 (10:36 am)
i'm not totally sure about TGE 1.5, but in 1.3 & 1.4 i found that the GuiMLTextEditCtrl had several shortcomings which IMO precluded it from being published as an actual user-facing UI element.

* no undo.
* text could only be selected with mouse, not with arrow keys.
* poor cursor movement support (no ctrl-home, ctrl-end, to say nothing of shift-ctrl-home).
* non-blinking cursor.

these are addressed in this resource, as well as other improvements. it's a TGE 1.3 resource but can probably be adapted to 1.5 without too much trouble.