6 void InputBox_configureInputBox(entity me, string theText, float theCursorPos, float theFontSize, string gfx)
8 SUPER(InputBox).configureLabel(me, theText, theFontSize, 0.0);
10 me.cursorPos = theCursorPos;
12 void InputBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
14 SUPER(InputBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
15 if (me.enableClearButton)
17 me.cb_width = absSize.y / absSize.x;
18 me.cb_offset = bound(-1, me.cb_offset, 0) * me.cb_width; // bound to range -1, 0
19 me.keepspaceRight = me.keepspaceRight - me.cb_offset + me.cb_width;
23 void InputBox_setText(entity me, string txt)
26 SUPER(InputBox).setText(me, strzone(txt));
29 float over_ClearButton(entity me, vector pos)
31 if (pos.x >= 1 + me.cb_offset - me.cb_width)
32 if (pos.x < 1 + me.cb_offset)
34 if (pos.y < 1) return 1;
38 float InputBox_mouseMove(entity me, vector pos)
40 if (me.enableClearButton)
42 if (over_ClearButton(me, pos))
52 float InputBox_mouseDrag(entity me, vector pos)
57 me.dragScrollPos = pos;
58 p = me.scrollPos + pos.x - me.keepspaceLeft;
59 me.cursorPos = draw_TextLengthUpToWidth(me.text, p, 0, me.realFontSize);
60 me.lastChangeTime = time;
62 else if (me.enableClearButton)
64 if (over_ClearButton(me, pos))
74 METHOD(InputBox, mousePress, bool(InputBox this, vector pos))
76 if (this.enableClearButton)
77 if (over_ClearButton(this, pos))
82 this.dragScrollTimer = time;
84 return InputBox_mouseDrag(this, pos);
87 float InputBox_mouseRelease(entity me, vector pos)
90 if (over_ClearButton(me, pos))
92 m_play_click_sound(MENU_SOUND_CLEAR);
95 me.applyButton.disabled = false;
99 float r = InputBox_mouseDrag(me, pos);
100 // reset cb_pressed after mouseDrag, mouseDrag could set cb_pressed in this case:
101 // mouse press out of the clear button, drag and then mouse release over the clear button
107 void InputBox_enterText(entity me, string ch)
110 for (i = 0; i < strlen(ch); ++i)
111 if (strstrofs(me.forbiddenCharacters, substring(ch, i, 1), 0) > -1) return;
112 if (me.maxLength > 0)
114 if (strlen(ch) + strlen(me.text) > me.maxLength) return;
116 else if (me.maxLength < 0)
118 if (u8_strsize(ch) + u8_strsize(me.text) > -me.maxLength) return;
120 me.setText(me, strcat(substring(me.text, 0, me.cursorPos), ch, substring(me.text, me.cursorPos, strlen(me.text) - me.cursorPos)));
121 me.cursorPos += strlen(ch);
124 float InputBox_keyDown(entity me, float key, float ascii, float shift)
126 me.lastChangeTime = time;
127 me.dragScrollTimer = time;
128 if (ascii >= 32 && ascii != 127)
130 me.enterText(me, chr(ascii));
132 me.applyButton.disabled = false;
141 case K_KP_RIGHTARROW:
151 me.cursorPos = strlen(me.text);
154 if (me.cursorPos > 0)
157 me.setText(me, strcat(substring(me.text, 0, me.cursorPos), substring(me.text, me.cursorPos + 1, strlen(me.text) - me.cursorPos - 1)));
159 me.applyButton.disabled = false;
166 m_play_click_sound(MENU_SOUND_CLEAR);
170 me.setText(me, strcat(substring(me.text, 0, me.cursorPos), substring(me.text, me.cursorPos + 1, strlen(me.text) - me.cursorPos - 1)));
172 me.applyButton.disabled = false;
178 void InputBox_draw(entity me)
181 float cursorPosInWidths, totalSizeInWidths;
183 if (me.pressed) me.mouseDrag(me, me.dragScrollPos); // simulate mouseDrag event
185 if (me.recalcPos) me.recalcPositionWithText(me, me.text);
187 me.focusable = !me.disabled;
188 if (me.disabled) draw_alpha *= me.disabledAlpha;
192 if (me.focused && !me.disabled) draw_ButtonPicture('0 0 0', strcat(me.src, "_f"), '1 1 0', me.colorF, 1);
193 else draw_ButtonPicture('0 0 0', strcat(me.src, "_n"), '1 1 0', me.color, 1);
196 me.cursorPos = bound(0, me.cursorPos, strlen(me.text));
197 cursorPosInWidths = draw_TextWidth(substring(me.text, 0, me.cursorPos), 0, me.realFontSize);
198 totalSizeInWidths = draw_TextWidth(strcat(me.text, CURSOR), 0, me.realFontSize);
200 if (me.dragScrollTimer < time)
204 me.scrollPos = bound(cursorPosInWidths - (0.875 - me.keepspaceLeft - me.keepspaceRight), me.scrollPos, cursorPosInWidths - 0.125);
205 if (me.scrollPos != save) me.dragScrollTimer = time + 0.2;
207 me.scrollPos = min(me.scrollPos, totalSizeInWidths - (1 - me.keepspaceRight - me.keepspaceLeft));
208 me.scrollPos = max(0, me.scrollPos);
210 draw_SetClipRect(eX * me.keepspaceLeft, eX * (1 - me.keepspaceLeft - me.keepspaceRight) + eY);
211 if (me.editColorCodes)
216 float theAlpha; // float theVariableAlpha;
221 p = me.realOrigin - eX * me.scrollPos;
223 theAlpha = 1; // theVariableAlpha = 1; // changes when ^ax found
226 for (i = 0; i < n; ++i)
228 ch = substring(me.text, i, 1);
232 ch2 = substring(me.text, i + 1, 1);
233 w = draw_TextWidth(strcat(ch, ch2), 0, me.realFontSize);
236 draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5);
237 draw_Text(p + eX * 0.25 * w, "^", me.realFontSize, theColor, theAlpha, 0);
239 else if (ch2 == "0" || stof(ch2)) // digit?
243 case 0: theColor = '0 0 0';
246 case 1: theColor = '1 0 0';
249 case 2: theColor = '0 1 0';
252 case 3: theColor = '1 1 0';
255 case 4: theColor = '0 0 1';
258 case 5: theColor = '0 1 1';
261 case 6: theColor = '1 0 1';
264 case 7: theColor = '1 1 1';
267 case 8: theColor = '1 1 1';
270 case 9: theColor = '0.5 0.5 0.5';
274 draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5);
275 draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0);
277 else if (ch2 == "x") // ^x found
281 component = HEXDIGIT_TO_DEC(substring(me.text, i + 2, 1));
282 if (component >= 0) // ^xr found
284 theTempColor.x = component / 15;
286 component = HEXDIGIT_TO_DEC(substring(me.text, i + 3, 1));
287 if (component >= 0) // ^xrg found
289 theTempColor.y = component / 15;
291 component = HEXDIGIT_TO_DEC(substring(me.text, i + 4, 1));
292 if (component >= 0) // ^xrgb found
294 theTempColor.z = component / 15;
295 theColor = theTempColor;
296 w = draw_TextWidth(substring(me.text, i, 5), 0, me.realFontSize);
298 draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5);
299 draw_Text(p, substring(me.text, i, 5), me.realFontSize, theColor, 1, 0); // theVariableAlpha instead of 1 using alpha tags ^ax
305 w = draw_TextWidth(substring(me.text, i, 4), 0, me.realFontSize);
306 draw_Fill(p, eX * w + eY * me.realFontSize.y, eZ, 0.5);
307 draw_Text(p, substring(me.text, i, 4), me.realFontSize, '1 1 1', theAlpha, 0);
314 w = draw_TextWidth(substring(me.text, i, 3), 0, me.realFontSize);
315 draw_Fill(p, eX * w + eY * me.realFontSize.y, eY, 0.5);
316 draw_Text(p, substring(me.text, i, 3), me.realFontSize, '1 1 1', theAlpha, 0);
323 // w = draw_TextWidth(substring(me.text, i, 2), 0) * me.realFontSize_x;
324 draw_Fill(p, eX * w + eY * me.realFontSize.y, eX, 0.5);
325 draw_Text(p, substring(me.text, i, 2), me.realFontSize, '1 1 1', theAlpha, 0);
330 draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5);
331 draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0);
337 draw_Text(p, ch, me.realFontSize, theColor, theAlpha, 0); // TODO theVariableAlpha
338 p += eX * draw_TextWidth(ch, 0, me.realFontSize);
343 draw_Text(me.realOrigin - eX * me.scrollPos, me.text, me.realFontSize, '1 1 1', 1, 0);
346 if (!me.focused || (time - me.lastChangeTime) < floor(time - me.lastChangeTime) + 0.5) draw_Text(me.realOrigin + eX * (cursorPosInWidths - me.scrollPos), CURSOR, me.realFontSize, '1 1 1', 1, 0);
350 if (me.enableClearButton)
353 if (me.focused && me.cb_pressed) draw_Picture(eX * (1 + me.cb_offset - me.cb_width), strcat(me.cb_src, "_c"), eX * me.cb_width + eY, me.cb_colorC, 1);
354 else if (me.focused && me.cb_focused) draw_Picture(eX * (1 + me.cb_offset - me.cb_width), strcat(me.cb_src, "_f"), eX * me.cb_width + eY, me.cb_colorF, 1);
355 else draw_Picture(eX * (1 + me.cb_offset - me.cb_width), strcat(me.cb_src, "_n"), eX * me.cb_width + eY, me.cb_color, 1);
358 // skipping SUPER(InputBox).draw(me);
362 void InputBox_showNotify(entity me)
364 me.focusable = !me.disabled;