1 #ifndef __TEXT_INPUT_H 2 #define __TEXT_INPUT_H 3 4 #include "Input.h" 5 6 #include <string_theory/string> 7 8 9 #define TEXT_CURSOR_BLINK_INTERVAL 500 10 11 //AUTHOR: Kris Morness 12 //Intended for inclusion with SGP. 13 14 //NEW CHANGES: January 16, 1998 15 //I have added the ability to stack the text input modes. So, if you have a particular 16 //screen that has fields, then somehow, hit a key to go into another mode with text input, 17 //it will automatically disable the current fields, as you go on to define new ones. Previously, 18 //you would have to make sure the mode was removed before initializing a new one. There were 19 //potential side effects of crashes, and unpredictable results, as the new fields would cook the 20 //existing ones. 21 //NOTE: You may have to modify you code now, so that you don't accidentally kill a text input mode 22 //when you don't one to begin with. (like removing an already deleted button). Also, remember that 23 //this works like a stack system and you can't flip through existing defined text input modes at will. 24 25 //NOTES ON LIMITATIONS: 26 // -max number of fields 255 (per level) 27 // -max num of chars in field 255 28 29 //The dosfilename inputtype is a perfect example of what is a exclusive handler. 30 //In this method, the input accepts only alphas and an underscore as the first character, 31 //then alphanumerics afterwards. For further support, chances are you'll want to treat it 32 //as an exclusive handler, and you'll have to process it in the filter input function. 33 enum InputType 34 { 35 INPUTTYPE_NUMERICSTRICT, 36 INPUTTYPE_FULL_TEXT, 37 INPUTTYPE_DOSFILENAME, 38 INPUTTYPE_COORDINATE, 39 INPUTTYPE_24HOURCLOCK 40 }; 41 42 //Simply initiates that you wish to begin inputting text. This should only apply to screen 43 //initializations that contain fields that edit text. It also verifies and clears any existing 44 //fields. Your input loop must contain the function HandleTextInput and processed if the gfTextInputMode 45 //flag is set else process your regular input handler. Note that this doesn't mean you are necessarily typing, 46 //just that there are text fields in your screen and may be inactive. The TAB key cycles through your text fields, 47 //and special fields can be defined which will call a void functionName( UINT16 usFieldNum ) 48 void InitTextInputMode(void); 49 50 //A hybrid version of InitTextInput() which uses a specific scheme. JA2's editor uses scheme 1, so 51 //feel free to add new color/font schemes. 52 enum{ 53 DEFAULT_SCHEME 54 }; 55 void InitTextInputModeWithScheme( UINT8 ubSchemeID ); 56 57 //Clears any existing fields, and ends text input mode. 58 void KillTextInputMode(void); 59 //Kills all levels of text input modes. When you init a second consecutive text input mode, without 60 //first removing them, the existing mode will be preserved. This function removes all of them in one 61 //call, though doing so "may" reflect poor coding style, though I haven't thought about any really 62 //just uses for it :( 63 void KillAllTextInputModes(void); 64 65 //Saves the current text input mode, then removes it and activates the previous text input mode, 66 //if applicable. The second function restores the settings. Doesn't currently support nested 67 //calls. 68 void SaveAndRemoveCurrentTextInputMode(void); 69 void RestoreSavedTextInputMode(void); 70 71 void SetTextInputCursor( UINT16 usNewCursor ); 72 73 //After calling InitTextInputMode, you want to define one or more text input fields. The order 74 //of calls to this function dictate the TAB order from traversing from one field to the next. This 75 //function adds mouse regions and processes them for you, as well as deleting them when you are done. 76 void AddTextInputField(INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT8 bPriority, const ST::string& str, size_t maxCodepoints, InputType usInputType); 77 78 //This allows you to insert special processing functions and modes that can't be determined here. An example 79 //would be a file dialog where there would be a file list. This file list would be accessed using the Win95 80 //convention by pressing TAB. In there, your key presses would be handled differently and by adding a userinput 81 //field, you can make this hook into your function to accomplish this. In a filedialog, alpha characters 82 //would be used to jump to the file starting with that letter, and setting the field in the text input 83 //field. Pressing TAB again would place you back in the text input field. All of that stuff would be handled 84 //externally, except for the TAB keys. 85 typedef void (*INPUT_CALLBACK)(UINT8,BOOLEAN); 86 void AddUserInputField( INPUT_CALLBACK userFunction ); 87 //INPUT_CALLBACK explanation: 88 //The function must use this signature: void FunctionName( UINT8 ubFieldID, BOOLEAN fEntering ); 89 //ubFieldID contains the fieldID of that field 90 //fEntering is true if you are entering the user field, false if exiting. 91 92 //This is a useful call made from an external user input field. Using the previous file dialog example, this 93 //call would be made when the user selected a different filename in the list via clicking or scrolling with 94 //the arrows, or even using alpha chars to jump to the appropriate filename. 95 void SetInputFieldString(UINT8 ubField, const ST::string& str); 96 97 //Allows external functions to access the strings within the fields at anytime. 98 ST::string GetStringFromField(UINT8 ubField); 99 100 //Utility functions for the INPUTTYPE_24HOURCLOCK input type. 101 UINT16 GetExclusive24HourTimeValueFromField( UINT8 ubField ); 102 void SetExclusive24HourTimeValue( UINT8 ubField, UINT16 usTime ); 103 104 /* Return the field's string as a number. Return -1 if blank or invalid. Only 105 * works for positive numbers. */ 106 INT32 GetNumericStrictValueFromField(UINT8 id); 107 108 //Converts a number to a numeric strict value. If the number is negative, the 109 //field will be blank. 110 void SetInputFieldStringWithNumericStrictValue( UINT8 ubField, INT32 iNumber ); 111 112 //Sets the active field to the specified ID number. 113 void SetActiveField( UINT8 ubField ); 114 void SelectNextField(void); 115 116 //Returns the active field ID number. It'll return -1 if no field is active. 117 INT16 GetActiveFieldID(void); 118 119 //These allow you to customize the general color scheme of your text input boxes. I am assuming that 120 //under no circumstances would a user want a different color for each field. It follows the Win95 convention 121 //that all text input boxes are exactly the same color scheme. However, these colors can be set at anytime, 122 //but will effect all of the colors. 123 void SetTextInputFont(SGPFont); 124 void Set16BPPTextFieldColor( UINT16 usTextFieldColor ); 125 void SetTextInputRegularColors( UINT8 ubForeColor, UINT8 ubShadowColor ); 126 void SetTextInputHilitedColors( UINT8 ubForeColor, UINT8 ubShadowColor, UINT8 ubBackColor ); 127 //optional color setups 128 void SetBevelColors( UINT16 usBrighterColor, UINT16 usDarkerColor ); 129 void SetCursorColor( UINT16 usCursorColor ); 130 131 //All CTRL and ALT keys combinations, F1-F12 keys, ENTER and ESC are ignored allowing 132 //processing to be done with your own input handler. Otherwise, the keyboard event 133 //is absorbed by this input handler, if used in the appropriate manner. 134 //This call must be added at the beginning of your input handler in this format: 135 //while( DequeueEvent(&Event) ) 136 //{ 137 // if( !HandleTextInput( &Event ) && (your conditions...ex: Event.usEvent == KEY_DOWN ) ) 138 // { 139 // switch( Event.usParam ) 140 // { 141 // //Normal key cases here. 142 // } 143 // } 144 //} 145 //It is only necessary for event loops that contain text input fields. 146 BOOLEAN HandleTextInput(InputAtom const*); 147 148 void RenderInactiveTextField( UINT8 ubID ); 149 void RenderAllTextFields(void); 150 151 void DisableTextField( UINT8 ubID ); 152 void EnableTextFields( UINT8 ubFirstID, UINT8 ubLastID ); 153 void DisableTextFields( UINT8 ubFirstID, UINT8 ubLastID ); 154 void EnableAllTextFields(void); 155 void DisableAllTextFields(void); 156 157 // 158 BOOLEAN EditingText(void); 159 BOOLEAN TextInputMode(void); 160 161 extern BOOLEAN gfNoScroll; 162 163 #endif 164