Creating custom textbox

Started by Construed, Mon 30/09/2013 19:45:54

Previous topic - Next topic

Construed

I've tried all venue's to make a way to type into one textbox at a time and it always types into both textboxes and if i make one text box visible then invisible it defeats my purpose..

It's a vital part of my project and any help would be greatly appreciated.


Thanks, Jar
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Khris

#1
You have to alternately enable one of them and disable the other.

Disable the 2nd one by calling TextBox2.Enabled = false; in game_start.

In on_key_press, add code like this:
Code: ags
  if (k == eKeyTab && gTheGUI.Visible) {
    // switch focus
    TextBox1.Enabled = !TextBox1.Enabled;
    TextBox2.Enabled = !TextBox2.Enabled;
  }


Edit:
Here's an alternative way using the on_event function, use this to focus input on a textbox by clicking it:
Code: ags
void on_event(EventType event, int data) {
  if (event == eEventGUIMouseUp) {
    GUI *theGUI = gBlack;         //  <------- insert your GUI's name here!
    // textbox clicking
    if (data == theGUI.ID) {
      GUIControl *gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
      if (gc == null) return;
      TextBox *tb = gc.AsTextBox;
      if (tb == null) return;
      int i;
      while (i < theGUI.ControlCount) {
        if (theGUI.Controls[i].AsTextBox != null)
          theGUI.Controls[i].Enabled = false;
        i++;
      }
      tb.Enabled = true;
    }
  }
}


Edit2: added missing null pointer check

Construed

Code: ags

   void on_event(EventType event, int data) {
      if (event == eEventGUIMouseUp) {
        GUI *theGUI = gBlack;         //  <------- insert your GUI's name here!
        // textbox clicking
        if (data == theGUI.ID) {
          GUIControl *gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
          TextBox *tb = gc.AsTextBox;
          if (tb == null) return;
          int i;
          while (i < theGUI.ControlCount) {
            if (theGUI.Controls[i].AsTextBox != null)
              theGUI.Controls[i].Enabled = false;
            i++;
          }
          tb.Enabled = true;
        }
      }
    }


A thousand thumbs up to you my good sir!!!!
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

SMF spam blocked by CleanTalk