Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Multi-Purpose Textbox

Author
Message
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 4th Sep 2004 02:14
Hi!
Well heres another little function from me. A little one line text box, you call the function and it displays the text box - if you click the textbox you can edit the text with the keyboard, pressing return or clicking anywhere that isnt in the textbox will disable the editing until the box is clicked again.
You should be able to call the function multiple times for different textboxes for different inputs.

You can specify the x location, y location and the width (height is always calculated by the function itself depending on the height of the currently set font) you may also set the max characters for limiting input and you also must pass 2 additional vars, Txt which is the text to fill the textbox with (what your editing, it will be clear when you see the code) and also an ID which is what allows you to use multiple instances.

You only need to declare ONE variable your self, which is SelectedItem - this the function sets to let all the text boxes know which ID is selected. Make it global so all functions have access. I like to declare it as a Byte as i see no reason why I would need more than 255 textboxes and that keeps it small

Anyway, the function:



The ink statements are placed according to my game, you may need to add one to the top if you dont have a colour preset in your game loop and you will most probably wish to change the colours. You could even add "Col" and "SelectedCol" parameters to the function if you wish to be able to set the colour of the box when you call it.

Example of how to use the function streight from my game:

Thats it, that one call does it all PlayerName is simply a string type variable, the function returns the edited text as you can see, draws the box at x90, y65, w200, passes PlayerName as the var to edit, sets max chars to 32 and tells the box its id is 1.

Im sure the function can be optimised but its fine for my little menu system, i use it for profiles and setting up multiplayer games Maybe someone can find a use for it in their game ^^

Hope you like!

p4 2.4ghz, 768ddr ram, Geforce FX 5200
Innovate, redefine, recreate whats in your mind. It isnt fate, you decide, only you can cross that line.

Login to post a reply

Server time is: 2024-11-23 19:34:15
Your offset time is: 2024-11-23 19:34:15