MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / GUI_EditBox

Function GUI_EditBox

src/gui/editbox.c:52–183  ·  view source on GitHub ↗

* Show an EditBox and handles the input. * @param text The text to edit. Uses the pointer to make the modifications. * @param maxLength The maximum length of the text. * @param widgetID the widget in which the EditBox is displayed. * @param w The widget this editbox is attached to (for input events). * @param tickProc The function to call every tick, for animation etc. * @param paint Flag in

Source from the content-addressed store, hash-verified

50 * @return Key code / Button press code.
51 */
52uint16 GUI_EditBox(char *text, uint16 maxLength, uint16 widgetID, Widget *w, uint16 (*tickProc)(void), bool paint)
53{
54 Screen oldScreenID;
55 uint16 oldWidgetID;
56 uint16 positionX;
57 uint16 maxWidth;
58 uint16 textWidth;
59 uint16 textLength;
60 uint16 returnValue;
61 char *t;
62
63 /* Initialize */
64 {
65 Input_Flags_SetBits(INPUT_FLAG_NO_TRANSLATE);
66 Input_Flags_ClearBits(INPUT_FLAG_UNKNOWN_2000);
67
68 oldScreenID = GFX_Screen_SetActive(SCREEN_0);
69
70 oldWidgetID = Widget_SetCurrentWidget(widgetID);
71
72 returnValue = 0x0;
73 }
74
75 positionX = g_curWidgetXBase << 3;
76
77 textWidth = 0;
78 textLength = 0;
79 maxWidth = (g_curWidgetWidth << 3) - Font_GetCharWidth('W') - 1;
80 t = text;
81
82 /* Calculate the length and width of the current string */
83 for (; *t != '\0'; t++) {
84 textWidth += Font_GetCharWidth(*t);
85 textLength++;
86
87 if (textWidth >= maxWidth) break;
88 }
89 *t = '\0';
90
91 GUI_Mouse_Hide_Safe();
92
93 if (paint) Widget_PaintCurrentWidget();
94
95 GUI_DrawText_Wrapper(text, positionX, g_curWidgetYBase, g_curWidgetFGColourBlink, g_curWidgetFGColourNormal, 0);
96
97 GUI_EditBox_BlinkCursor(positionX + textWidth, false);
98
99 GUI_Mouse_Show_Safe();
100
101 for (;; sleepIdle()) {
102 uint16 keyWidth;
103 uint16 key;
104
105 if (tickProc != NULL) {
106 returnValue = tickProc();
107 if (returnValue != 0) break;
108 }
109

Callers 3

GUI_HallOfFame_ShowFunction · 0.85
GUI_Security_ShowFunction · 0.85

Calls 12

Input_Flags_SetBitsFunction · 0.85
Input_Flags_ClearBitsFunction · 0.85
GFX_Screen_SetActiveFunction · 0.85
Widget_SetCurrentWidgetFunction · 0.85
Font_GetCharWidthFunction · 0.85
GUI_Mouse_Hide_SafeFunction · 0.85
GUI_DrawText_WrapperFunction · 0.85
GUI_EditBox_BlinkCursorFunction · 0.85
GUI_Mouse_Show_SafeFunction · 0.85
GUI_Widget_HandleEventsFunction · 0.85

Tested by

no test coverage detected