orxTextBox

edited March 2012 in Help request
How can i do that? I need to make a "Text Input", ideas? :)

Comments

  • edited March 2012
    Ah. :)

    That's probably of the most tricky thing to do with orx. Or at least annoying. :)

    I believe tdomhan wanted to write a tutorial on that, but apparently it's the only of his tutorial he never found the time to write. ^^

    You have two main options, I think. First one is to create your own text field component, listening to keyboard events (or polling them), handling focus on your component and displaying the text. That shouldn't be too bad actually, just annoying. :)

    The other option would be to use an external UI library and plug its render callbacks to orx (something like CeGUI or ImGUI (taken from RecastNavigation)).

    Not sure which one would best suits your need though, so it's up to you! :)
  • edited March 2012
    mmm ... I think I prefer the first option. I don't like CEGUI: P
    Well, the answers to these questions will help me a lot:
    1) How I can get the keys pressed without using the config.ini?
    2) How I can draw basic shapes with orx? as squares, lines, etc..

    Another question!
    And if I want my application is compatible with android? What considerations must I have? how I can use the user interface of android? (for elements like textbox, and others?)
  • edited March 2012
    luciano wrote:
    mmm ... I think I prefer the first option. I don't like CEGUI: P

    Someone mentioned on the forum, not so long ago, another open source library that looked really interesting but I can't seem to find it today. -_-
    Well, the answers to these questions will help me a lot:
    1) How I can get the keys pressed without using the config.ini?

    Look at the orxKeyboard module. :)
    2) How I can draw basic shapes with orx? as squares, lines, etc..

    I've added primitive drawing only a couple of weeks ago. Look at orxDisplay_Draw*(). They're slower than rendering objects though, as they can't benefit from batching.

    If you only want to draw boxes or lines, another alternative is to have objects whose graphic is using the "pixel" texture (it's an actual internal texture in orx) and scale them to your liking.
    Another question!
    And if I want my application is compatible with android? What considerations must I have? how I can use the user interface of android? (for elements like textbox, and others?)

    If you're happy with your own text field made in orx, no need to do any change I believe.
    If you want the actual Android controls/widgets, you'll have to use the Android API and add #ifdef __orxANDROID__ around.

    Faistoiplaisir or Lydesik could provide more info on that as they're the masters of the Android version. :)
  • edited March 2012
    I'm doing :) I'm doing differents ui elements, for now I could show a dialog, which in turn is a container, and I added a textbox to container...

    My problem is in textbox:

    I write with the keyboard 'hola' and the textbox's text is 'hhhhoooollllaaaa' :P
    void TextInput::UpdateInput()
    {
    	if(orxKeyboard_Hit())
    	{
    		std::string keyString;
    		orxKEYBOARD_KEY key = orxKeyboard_Read();
    
    		int pointer = -1;
    		if(key >= orxKEYBOARD_KEY_A && key <= orxKEYBOARD_KEY_Z)
    		{
    			if(orxKeyboard_IsKeyPressed(orxKEYBOARD_KEY_LSHIFT) ||
    				orxKeyboard_IsKeyPressed(orxKEYBOARD_KEY_RSHIFT)
    				)
    			{
    				pointer = 65;
    			}
    			else
    			{
    				pointer = 97;
    			}
    		}
    		else if(key >= orxKEYBOARD_KEY_NUMPAD_0 && key <= orxKEYBOARD_KEY_NUMPAD_9)
    		{
    			pointer = 48 - orxKEYBOARD_KEY_NUMPAD_0;
    		}					
    		else if(key >= orxKEYBOARD_KEY_0 && key <= orxKEYBOARD_KEY_9)
    		{
    			pointer = 48 - orxKEYBOARD_KEY_0;
    		}
    		else if(key == orxKEYBOARD_KEY_SPACE)
    		{
    			keyString += ' ';
    		}
    		else if(key == orxKEYBOARD_KEY_BACKSPACE)
    		{
    			pointer = -2;
    		}
    
    		if(pointer >= 0)
    		{
    			keyString = (char)(pointer + (int)key);
    			this->text += keyString; // in the future this will change
    			cursor ++;
    		}
    		else if(pointer == -2)
    		{
    			keyString.substr(0, --cursor); // in the future this will change
    		}
    	}
    }
    

    Solution founded: add a timer

    Dibujo.PNG
    Dibujo 30.1K
  • edited March 2012
    Ahah yes, one of the solution is to handle the repetition yourself as you found out.

    But you have at least another option which is to go through the input system. This has the advantage of handling the repetition for you, you can act upon key press and/or key release, and you can even trigger the inputs yourself to simulate someone typing (useful for tutorials, for example). :)

    PS: Nice buttons there, by the way! :)
  • edited March 2012
    Ahah yes, one of the solution is to handle the repetition yourself as you found out.
    
    But you have at least another option which is to go through the input system. This has the advantage of handling the repetition for you, you can act upon key press and/or key release, and you can even trigger the inputs yourself to simulate someone typing (useful for tutorials, for example).
    

    Yes, it's true :) i'll do by this way
    PS: Nice buttons there, by the way!
    

    Thank you! :) :)
  • edited March 2012
    Let me know if you have any problem with the input system. :)

    By the way, I think you meant to use the "quote" tag in your post, not the "code" one! ;)
  • edited August 2012
    Well, the new orxKeyboard_ReadKey() / orxKeyboard_ReadString() should fix the timing problem completely, if you ever need it. :)
Sign In or Register to comment.