2 // control/visual/editbox.qc
8 void() Item_EditBox_Draw =
16 Raise_DataEvent( self._target, ITEM_DATALINK_GET );
18 if( self._state == ITEM_STATE_NORMAL ) {
19 Menu_DrawString( self.pos + self.origin, self._target.value, self.fontSize, self.color, self.alphas_x, self.drawFlags_x );
23 lCursor_x = self._cursorPos * self.fontSize_x;
24 lCursor_y = self.fontSize_y;
26 if( mod( Timer_Time * 1000, 1000 / ITEM_EDITBOX_CURSOR_FREQ ) > 500 / ITEM_EDITBOX_CURSOR_FREQ )
30 //lAlpha = 1.2 - fabs( 1 + floor( Timer_Time * ITEM_EDITBOX_CURSOR_FREQ / 2 ) * 2 - Timer_Time * ITEM_EDITBOX_CURSOR_FREQ );
32 if( self._state == ITEM_STATE_SELECTED ) {
33 lCursor_y = lCursor_y - self.sizeCursor_y;
34 Menu_DrawString( self.pos + self.origin, self._target.value, self.fontSize, self.colorSelected, self.alphas_y, self.drawFlags_y );
35 Menu_Fill( self.pos + self.origin + lCursor, self.sizeCursor, self.colorCursor, self.alphasCursor_x * lAlpha, self.drawFlagsCursor_x );
37 lCursor_y = lCursor_y - self.sizeCursorFlash_y;
38 Menu_DrawString( self.pos + self.origin, self._target.value, self.fontSize, self.colorPressed, self.alphas_z, self.drawFlags_z );
39 Menu_Fill( self.pos + self.origin + lCursor, self.sizeCursorFlash, self.colorCursorFlash, self.alphasCursor_y * lAlpha, self.drawFlagsCursor_y );
43 void() Item_EditBox_Update =
45 Item_DataUser_Update();
47 if( self._presstime + ITEM_EDITBOX_FLASHTIME > Timer_Time )
48 self._state = ITEM_STATE_PRESSED;
49 else if( Menu_ActiveItem == self )
50 self._state = ITEM_STATE_SELECTED;
52 self._state = ITEM_STATE_NORMAL;
57 // clamp the cursor position if necessary
58 Raise_DataEvent( self._target, ITEM_DATALINK_GET );
59 self._cursorPos = bound( 0, self._cursorPos, strlen( self._target.value ) );
61 // scroll the text if necessary
62 // save the scrolled position in origin
64 if( ( self._cursorPos + ITEM_EDITBOX_SCROLLDISTANCE > self.size_x / self.fontSize_x )
65 && ( self._target.maxValue - ITEM_EDITBOX_SCROLLDISTANCE > self.size_x / self.fontSize_x ) )
66 self.origin_x = self.fontSize_x * ( floor( self.size_x / self.fontSize_x ) - self._cursorPos - ITEM_EDITBOX_SCROLLDISTANCE );
71 void() _IEB_RemoveChar =
76 lValue = self._target.value;
77 // TODO: perhaps use strlen perhaps
78 // FIXME: FteQCC bug: lTemp = strcat( substring( lValue, 0, self._cursorPos ), substring( lValue, self._cursorPos + 1, 100000 ) );
79 lTemp = strcat( substring( lValue, 0, self._cursorPos ) );
80 lTemp = strcat( lTemp, substring( lValue, self._cursorPos + 1, 100000 ) );
81 String_EntitySet( self._target, value, lTemp );
82 Raise_DataEvent( self._target, ITEM_DATALINK_SET );
84 self._presstime = Timer_Time;
85 Sound_Play( self.soundKey );
88 void( float pAscii ) _IEB_InsertChar =
93 lValue = self._target.value;
94 lTemp = strcat( substring( lValue, 0, self._cursorPos ) , chr( pAscii ) );
95 lTemp = strcat( lTemp, substring( lValue, self._cursorPos, 100000 ) );
96 // FIXME: FTEQCC bug: lTemp = strcat( substring( lValue, 0, self._cursorPos ) , chr( pAscii ), substring( lValue, self._cursorPos, 100000 ) );
97 String_EntitySet( self._target, value, lTemp );
98 Raise_DataEvent( self._target, ITEM_DATALINK_SET );
100 self._cursorPos = self._cursorPos + 1;
102 self._presstime = Timer_Time;
103 Sound_Play( self.soundKey );
106 bool( float pKey, float pAscii ) Item_EditBox_Key =
110 else if( pKey == K_ENTER ) {
112 Sound_Play( self.soundKey );
114 } else if( pKey == K_LEFTARROW ) {
115 if( self._cursorPos )
116 self._cursorPos = self._cursorPos - 1;
117 Sound_Play( self.soundMove );
119 } else if( pKey == K_RIGHTARROW ) {
120 if( self._cursorPos < strlen( self._target.value ) )
121 self._cursorPos = self._cursorPos + 1;
122 Sound_Play( self.soundMove );
124 } else if( pKey == K_BACKSPACE ) {
125 if( self._cursorPos > 0 ) {
126 self._cursorPos = self._cursorPos - 1;
130 } else if( pKey == K_DEL ) {
131 if( self._cursorPos < strlen( self._target.value ) )
134 } else if( 30 <= pAscii && pAscii <= 126 ) {
135 _IEB_InsertChar( pAscii );
141 void( bool pSelect, bool pUser ) Item_EditBox_Select =
143 CtCall_Select( pSelect, pUser );
144 if( pSelect && pUser )
145 Sound_Play( self.soundSelected );
148 void() Item_EditBox_Destroy =
151 Item_DataUser_Destroy();
153 String_EntityFree( self, soundSelected );
154 String_EntityFree( self, soundKey );
155 String_EntityFree( self, soundMove );
158 void() Item_EditBox_Reinit =
164 void() Item_EditBox_Spawn =
166 Item_DataUser_Init();
168 String_EntityZone( self, soundSelected );
169 String_EntityZone( self, soundKey );
170 String_EntityZone( self, soundMove );
172 Sound_Precache( self.soundSelected );
173 Sound_Precache( self.soundKey );
174 Sound_Precache( self.soundMove );
176 if( self.size == '0 0 0' && self._target && self._target.maxValue >= 0 ) {
177 self.size_x = self.fontSize_x * self._target.maxValue + max( self.sizeCursor_x, self.sizeCursorFlash );
178 self.size_y = self.fontSize_y;
181 self._reinit = Item_EditBox_Reinit;
182 self._destroy = Item_EditBox_Destroy;
183 self._key = Item_EditBox_Key;
184 self._draw = Item_EditBox_Draw;
185 self._select = Item_EditBox_Select;
186 self._update = Item_EditBox_Update;