3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #define TAG_TUI_SCREENBUFFER 'SiuT'
23 #define TAG_TAG_TUI_PALETTE 'PiuT'
25 PVOID TextVideoBuffer
= NULL
;
29 * Prints formatted text to the screen
31 int TuiPrintf(const char *Format
, ...)
39 Length
= _vsnprintf(Buffer
, sizeof(Buffer
), Format
, ap
);
42 if (Length
== -1) Length
= sizeof(Buffer
);
44 for (i
= 0; i
< Length
; i
++)
46 MachConsPutChar(Buffer
[i
]);
52 BOOLEAN
TuiInitialize(VOID
)
54 MachVideoHideShowTextCursor(FALSE
);
55 MachVideoClearScreen(ATTR(COLOR_GRAY
, COLOR_BLACK
));
57 TextVideoBuffer
= VideoAllocateOffScreenBuffer();
58 if (TextVideoBuffer
== NULL
)
66 VOID
TuiUnInitialize(VOID
)
68 if (UiUseSpecialEffects
)
74 MachVideoSetDisplayMode(NULL
, FALSE
);
77 MachVideoClearScreen(ATTR(COLOR_GRAY
, COLOR_BLACK
));
78 MachVideoHideShowTextCursor(TRUE
);
81 VOID
TuiDrawBackdrop(VOID
)
84 // Fill in the background (excluding title box & status bar)
87 TUI_TITLE_BOX_CHAR_HEIGHT
,
91 ATTR(UiBackdropFgColor
, UiBackdropBgColor
));
99 TUI_TITLE_BOX_CHAR_HEIGHT
- 1,
104 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
111 GetFreeLoaderVersionString(),
112 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
120 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
124 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
129 TuiDrawText(UiScreenWidth
- 16, 3, /*"F1 for Help"*/"F8 for Options", ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
134 TuiDrawText((UiScreenWidth
- (ULONG
)strlen(UiTitleBoxTitleText
)) / 2,
137 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
140 // Update the date & time
144 VideoCopyOffScreenBufferToVRAM();
149 * This function assumes coordinates are zero-based
151 VOID
TuiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
153 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
156 // Clip the area to the screen
157 if ((Left
>= UiScreenWidth
) || (Top
>= UiScreenHeight
))
161 if (Right
>= UiScreenWidth
)
163 Right
= UiScreenWidth
- 1;
165 if (Bottom
>= UiScreenHeight
)
167 Bottom
= UiScreenHeight
- 1;
170 // Loop through each line and fill it in
171 for (i
=Top
; i
<=Bottom
; i
++)
173 // Loop through each character (column) in the line and fill it in
174 for (j
=Left
; j
<=Right
; j
++)
176 ScreenMemory
[((i
*2)*UiScreenWidth
)+(j
*2)] = (UCHAR
)FillChar
;
177 ScreenMemory
[((i
*2)*UiScreenWidth
)+(j
*2)+1] = Attr
;
184 * This function assumes coordinates are zero-based
186 VOID
TuiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
188 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
191 // Shade the bottom of the area
192 if (Bottom
< (UiScreenHeight
- 1))
194 if (UiScreenHeight
< 34)
203 for (; Idx
<=Right
; Idx
++)
205 ScreenMemory
[(((Bottom
+1)*2)*UiScreenWidth
)+(Idx
*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
209 // Shade the right of the area
210 if (Right
< (UiScreenWidth
- 1))
212 for (Idx
=Top
+1; Idx
<=Bottom
; Idx
++)
214 ScreenMemory
[((Idx
*2)*UiScreenWidth
)+((Right
+1)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
217 if (UiScreenHeight
< 34)
219 if ((Right
+ 1) < (UiScreenWidth
- 1))
221 for (Idx
=Top
+1; Idx
<=Bottom
; Idx
++)
223 ScreenMemory
[((Idx
*2)*UiScreenWidth
)+((Right
+2)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
228 // Shade the bottom right corner
229 if ((Right
< (UiScreenWidth
- 1)) && (Bottom
< (UiScreenHeight
- 1)))
231 ScreenMemory
[(((Bottom
+1)*2)*UiScreenWidth
)+((Right
+1)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
233 if (UiScreenHeight
< 34)
235 if (((Right
+ 1) < (UiScreenWidth
- 1)) && (Bottom
< (UiScreenHeight
- 1)))
237 ScreenMemory
[(((Bottom
+1)*2)*UiScreenWidth
)+((Right
+2)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
244 * This function assumes coordinates are zero-based
246 VOID
TuiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
248 UCHAR ULCorner
, URCorner
, LLCorner
, LRCorner
;
250 // Calculate the corner values
251 if (HorzStyle
== HORZ
)
253 if (VertStyle
== VERT
)
260 else // VertStyle == D_VERT
268 else // HorzStyle == D_HORZ
270 if (VertStyle
== VERT
)
277 else // VertStyle == D_VERT
286 // Fill in box background
289 TuiFillArea(Left
, Top
, Right
, Bottom
, ' ', Attr
);
293 TuiFillArea(Left
, Top
, Left
, Top
, ULCorner
, Attr
);
294 TuiFillArea(Right
, Top
, Right
, Top
, URCorner
, Attr
);
295 TuiFillArea(Left
, Bottom
, Left
, Bottom
, LLCorner
, Attr
);
296 TuiFillArea(Right
, Bottom
, Right
, Bottom
, LRCorner
, Attr
);
299 TuiFillArea(Left
, Top
+1, Left
, Bottom
-1, VertStyle
, Attr
);
301 TuiFillArea(Left
+1, Top
, Right
-1, Top
, HorzStyle
, Attr
);
302 // Fill in right line
303 TuiFillArea(Right
, Top
+1, Right
, Bottom
-1, VertStyle
, Attr
);
304 // Fill in bottom line
305 TuiFillArea(Left
+1, Bottom
, Right
-1, Bottom
, HorzStyle
, Attr
);
310 TuiDrawShadow(Left
, Top
, Right
, Bottom
);
316 * This function assumes coordinates are zero-based
318 VOID
TuiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
320 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
324 for (i
= X
, j
= 0; Text
[j
] && i
< UiScreenWidth
; i
++, j
++)
326 ScreenMemory
[((Y
*2)*UiScreenWidth
)+(i
*2)] = (UCHAR
)Text
[j
];
327 ScreenMemory
[((Y
*2)*UiScreenWidth
)+(i
*2)+1] = Attr
;
333 * This function assumes coordinates are zero-based.
334 * MaxNumChars is the maximum number of characters to display.
335 * If MaxNumChars == 0, then display the whole string.
337 VOID
TuiDrawText2(ULONG X
, ULONG Y
, ULONG MaxNumChars
, PCSTR Text
, UCHAR Attr
)
339 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
343 for (i
= X
, j
= 0; Text
[j
] && i
< UiScreenWidth
&& (MaxNumChars
> 0 ? j
< MaxNumChars
: TRUE
); i
++, j
++)
345 ScreenMemory
[((Y
*2)*UiScreenWidth
)+(i
*2)] = (UCHAR
)Text
[j
];
346 ScreenMemory
[((Y
*2)*UiScreenWidth
)+(i
*2)+1] = Attr
;
350 VOID
TuiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
355 ULONG LineBreakCount
;
364 TextLength
= strlen(TextString
);
366 // Count the new lines and the box width
370 for (Index
=0; Index
<TextLength
; Index
++)
372 if (TextString
[Index
] == '\n')
379 if ((Index
- LastIndex
) > BoxWidth
)
381 BoxWidth
= (ULONG
)(Index
- LastIndex
);
386 BoxHeight
= LineBreakCount
+ 1;
388 RealLeft
= (((Right
- Left
) - BoxWidth
) / 2) + Left
;
389 RealTop
= (((Bottom
- Top
) - BoxHeight
) / 2) + Top
;
392 for (Index
=0; Index
<TextLength
; Index
++)
394 if (TextString
[Index
] == '\n')
401 X
= (ULONG
)(RealLeft
+ LastIndex
);
404 Temp
[0] = TextString
[Index
];
406 TuiDrawText(X
, Y
, Temp
, Attr
);
411 VOID
TuiDrawStatusText(PCSTR StatusText
)
415 TuiDrawText(0, UiScreenHeight
-1, " ", ATTR(UiStatusBarFgColor
, UiStatusBarBgColor
));
416 TuiDrawText(1, UiScreenHeight
-1, StatusText
, ATTR(UiStatusBarFgColor
, UiStatusBarBgColor
));
418 for (i
=strlen(StatusText
)+1; i
<UiScreenWidth
; i
++)
420 TuiDrawText((ULONG
)i
, UiScreenHeight
-1, " ", ATTR(UiStatusBarFgColor
, UiStatusBarBgColor
));
423 VideoCopyOffScreenBufferToVRAM();
426 VOID
TuiUpdateDateTime(VOID
)
432 BOOLEAN PMHour
= FALSE
;
434 /* Don't draw the time if this has been disabled */
435 if (!UiDrawTime
) return;
437 TimeInfo
= ArcGetTime();
438 if (TimeInfo
->Year
< 1 || 9999 < TimeInfo
->Year
||
439 TimeInfo
->Month
< 1 || 12 < TimeInfo
->Month
||
440 TimeInfo
->Day
< 1 || 31 < TimeInfo
->Day
||
441 23 < TimeInfo
->Hour
||
442 59 < TimeInfo
->Minute
||
443 59 < TimeInfo
->Second
)
445 /* This happens on QEmu sometimes. We just skip updating */
448 // Get the month name
449 strcpy(DateString
, UiMonthNames
[TimeInfo
->Month
- 1]);
451 _itoa(TimeInfo
->Day
, TempString
, 10);
452 // Get the day postfix
453 if (1 == TimeInfo
->Day
|| 21 == TimeInfo
->Day
|| 31 == TimeInfo
->Day
)
455 strcat(TempString
, "st");
457 else if (2 == TimeInfo
->Day
|| 22 == TimeInfo
->Day
)
459 strcat(TempString
, "nd");
461 else if (3 == TimeInfo
->Day
|| 23 == TimeInfo
->Day
)
463 strcat(TempString
, "rd");
467 strcat(TempString
, "th");
470 // Add the day to the date
471 strcat(DateString
, TempString
);
472 strcat(DateString
, " ");
474 // Get the year and add it to the date
475 _itoa(TimeInfo
->Year
, TempString
, 10);
476 strcat(DateString
, TempString
);
479 TuiDrawText(UiScreenWidth
-(ULONG
)strlen(DateString
)-2, 1, DateString
, ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
481 // Get the hour and change from 24-hour mode to 12-hour
482 if (TimeInfo
->Hour
> 12)
484 TimeInfo
->Hour
-= 12;
487 if (TimeInfo
->Hour
== 0)
491 _itoa(TimeInfo
->Hour
, TempString
, 10);
492 strcpy(TimeString
, " ");
493 strcat(TimeString
, TempString
);
494 strcat(TimeString
, ":");
495 _itoa(TimeInfo
->Minute
, TempString
, 10);
496 if (TimeInfo
->Minute
< 10)
498 strcat(TimeString
, "0");
500 strcat(TimeString
, TempString
);
501 strcat(TimeString
, ":");
502 _itoa(TimeInfo
->Second
, TempString
, 10);
503 if (TimeInfo
->Second
< 10)
505 strcat(TimeString
, "0");
507 strcat(TimeString
, TempString
);
510 strcat(TimeString
, " PM");
514 strcat(TimeString
, " AM");
518 TuiDrawText(UiScreenWidth
-(ULONG
)strlen(TimeString
)-2, 2, TimeString
, ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
521 VOID
TuiSaveScreen(PUCHAR Buffer
)
523 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
526 for (i
=0; i
< (UiScreenWidth
* UiScreenHeight
* 2); i
++)
528 Buffer
[i
] = ScreenMemory
[i
];
532 VOID
TuiRestoreScreen(PUCHAR Buffer
)
534 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
537 for (i
=0; i
< (UiScreenWidth
* UiScreenHeight
* 2); i
++)
539 ScreenMemory
[i
] = Buffer
[i
];
543 VOID
TuiMessageBox(PCSTR MessageText
)
547 // Save the screen contents
548 ScreenBuffer
= FrLdrTempAlloc(UiScreenWidth
* UiScreenHeight
* 2,
549 TAG_TUI_SCREENBUFFER
);
550 TuiSaveScreen(ScreenBuffer
);
552 // Display the message box
553 TuiMessageBoxCritical(MessageText
);
555 // Restore the screen contents
556 TuiRestoreScreen(ScreenBuffer
);
557 FrLdrTempFree(ScreenBuffer
, TAG_TUI_SCREENBUFFER
);
560 VOID
TuiMessageBoxCritical(PCSTR MessageText
)
563 unsigned int height
= 1;
572 for (i
=0; i
<strlen(MessageText
); i
++)
574 if (MessageText
[i
] == '\n')
579 for (i
=0,j
=0,k
=0; i
<height
; i
++)
581 while ((MessageText
[j
] != '\n') && (MessageText
[j
] != 0))
594 // Calculate box area
595 x1
= (UiScreenWidth
- (width
+2))/2;
597 y1
= ((UiScreenHeight
- height
- 2)/2) + 1;
598 y2
= y1
+ height
+ 4;
601 TuiDrawBox(x1
, y1
, x2
, y2
, D_VERT
, D_HORZ
, TRUE
, TRUE
, ATTR(UiMessageBoxFgColor
, UiMessageBoxBgColor
));
604 for (i
=0,j
=0; i
<strlen(MessageText
)+1; i
++)
606 if ((MessageText
[i
] == '\n') || (MessageText
[i
] == 0))
610 UiDrawText(x1
+2, y1
+1+curline
, temp
, ATTR(UiMessageBoxFgColor
, UiMessageBoxBgColor
));
614 temp
[j
++] = MessageText
[i
];
618 strcpy(temp
, " OK ");
619 UiDrawText(x1
+((x2
-x1
)/2)-3, y2
-2, temp
, ATTR(COLOR_BLACK
, COLOR_GRAY
));
622 UiDrawStatusText("Press ENTER to continue");
624 VideoCopyOffScreenBufferToVRAM();
630 key
= MachConsGetCh();
631 if (key
== KEY_EXTENDED
)
632 key
= MachConsGetCh();
634 if ((key
== KEY_ENTER
) || (key
== KEY_SPACE
) || (key
== KEY_ESC
))
640 VideoCopyOffScreenBufferToVRAM();
646 VOID
TuiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
648 ULONG Left
, Top
, Right
, Bottom
;
649 ULONG Width
= 50; // Allow for 50 "bars"
652 Left
= (UiScreenWidth
- Width
- 4) / 2;
653 Right
= Left
+ Width
+ 3;
654 Top
= (UiScreenHeight
- Height
- 2) / 2;
656 Bottom
= Top
+ Height
+ 1;
658 TuiDrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
661 VOID
TuiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
664 ULONG ProgressBarWidth
= (Right
- Left
) - 3;
666 // First make sure the progress bar text fits
667 UiTruncateStringEllipsis(ProgressText
, ProgressBarWidth
- 4);
669 if (Position
> Range
)
675 TuiDrawBox(Left
, Top
, Right
, Bottom
, VERT
, HORZ
, TRUE
, TRUE
, ATTR(UiMenuFgColor
, UiMenuBgColor
));
678 // Draw the "Loading..." text
680 TuiDrawCenteredText(Left
+ 2, Top
+ 2, Right
- 2, Top
+ 2, ProgressText
, ATTR(UiTextColor
, UiMenuBgColor
));
682 // Draw the percent complete
683 for (i
=0; i
<(Position
*ProgressBarWidth
)/Range
; i
++)
685 TuiDrawText(Left
+2+i
, Top
+2, "\xDB", ATTR(UiTextColor
, UiMenuBgColor
));
689 for (; i
<ProgressBarWidth
; i
++)
691 TuiDrawText(Left
+2+i
, Top
+2, "\xB2", ATTR(UiTextColor
, UiMenuBgColor
));
695 VideoCopyOffScreenBufferToVRAM();
698 UCHAR
TuiTextToColor(PCSTR ColorText
)
700 if (_stricmp(ColorText
, "Black") == 0)
702 else if (_stricmp(ColorText
, "Blue") == 0)
704 else if (_stricmp(ColorText
, "Green") == 0)
706 else if (_stricmp(ColorText
, "Cyan") == 0)
708 else if (_stricmp(ColorText
, "Red") == 0)
710 else if (_stricmp(ColorText
, "Magenta") == 0)
711 return COLOR_MAGENTA
;
712 else if (_stricmp(ColorText
, "Brown") == 0)
714 else if (_stricmp(ColorText
, "Gray") == 0)
716 else if (_stricmp(ColorText
, "DarkGray") == 0)
717 return COLOR_DARKGRAY
;
718 else if (_stricmp(ColorText
, "LightBlue") == 0)
719 return COLOR_LIGHTBLUE
;
720 else if (_stricmp(ColorText
, "LightGreen") == 0)
721 return COLOR_LIGHTGREEN
;
722 else if (_stricmp(ColorText
, "LightCyan") == 0)
723 return COLOR_LIGHTCYAN
;
724 else if (_stricmp(ColorText
, "LightRed") == 0)
725 return COLOR_LIGHTRED
;
726 else if (_stricmp(ColorText
, "LightMagenta") == 0)
727 return COLOR_LIGHTMAGENTA
;
728 else if (_stricmp(ColorText
, "Yellow") == 0)
730 else if (_stricmp(ColorText
, "White") == 0)
736 UCHAR
TuiTextToFillStyle(PCSTR FillStyleText
)
738 if (_stricmp(FillStyleText
, "Light") == 0)
742 else if (_stricmp(FillStyleText
, "Medium") == 0)
746 else if (_stricmp(FillStyleText
, "Dark") == 0)
754 VOID
TuiFadeInBackdrop(VOID
)
756 PPALETTE_ENTRY TuiFadePalette
= NULL
;
758 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed())
760 TuiFadePalette
= (PPALETTE_ENTRY
)FrLdrTempAlloc(sizeof(PALETTE_ENTRY
) * 64,
761 TAG_TAG_TUI_PALETTE
);
763 if (TuiFadePalette
!= NULL
)
765 VideoSavePaletteState(TuiFadePalette
, 64);
766 VideoSetAllColorsToBlack(64);
770 // Draw the backdrop and title box
773 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed() && TuiFadePalette
!= NULL
)
775 VideoFadeIn(TuiFadePalette
, 64);
776 FrLdrTempFree(TuiFadePalette
, TAG_TAG_TUI_PALETTE
);
780 VOID
TuiFadeOut(VOID
)
782 PPALETTE_ENTRY TuiFadePalette
= NULL
;
784 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed())
786 TuiFadePalette
= (PPALETTE_ENTRY
)FrLdrTempAlloc(sizeof(PALETTE_ENTRY
) * 64,
787 TAG_TAG_TUI_PALETTE
);
789 if (TuiFadePalette
!= NULL
)
791 VideoSavePaletteState(TuiFadePalette
, 64);
795 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed() && TuiFadePalette
!= NULL
)
800 MachVideoSetDisplayMode(NULL
, FALSE
);
802 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed() && TuiFadePalette
!= NULL
)
804 VideoRestorePaletteState(TuiFadePalette
, 64);
805 FrLdrTempFree(TuiFadePalette
, TAG_TAG_TUI_PALETTE
);
810 BOOLEAN
TuiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
822 ULONG EditBoxStartX
, EditBoxEndX
;
824 ULONG EditBoxTextLength
, EditBoxTextPosition
;
825 INT EditBoxTextDisplayIndex
;
829 // Save the screen contents
830 ScreenBuffer
= FrLdrTempAlloc(UiScreenWidth
* UiScreenHeight
* 2,
831 TAG_TUI_SCREENBUFFER
);
832 TuiSaveScreen(ScreenBuffer
);
835 for (i
=0; i
<strlen(MessageText
); i
++)
837 if (MessageText
[i
] == '\n')
842 for (i
=0,j
=0,k
=0; i
<height
; i
++)
844 while ((MessageText
[j
] != '\n') && (MessageText
[j
] != 0))
857 // Calculate box area
858 x1
= (UiScreenWidth
- (width
+2))/2;
860 y1
= ((UiScreenHeight
- height
- 2)/2) + 1;
861 y2
= y1
+ height
+ 4;
864 TuiDrawBox(x1
, y1
, x2
, y2
, D_VERT
, D_HORZ
, TRUE
, TRUE
, ATTR(UiMessageBoxFgColor
, UiMessageBoxBgColor
));
867 for (i
=0,j
=0; i
<strlen(MessageText
)+1; i
++)
869 if ((MessageText
[i
] == '\n') || (MessageText
[i
] == 0))
873 UiDrawText(x1
+2, y1
+1+curline
, temp
, ATTR(UiMessageBoxFgColor
, UiMessageBoxBgColor
));
877 temp
[j
++] = MessageText
[i
];
880 EditBoxTextLength
= (ULONG
)strlen(EditTextBuffer
) + 1;
881 EditBoxTextLength
= min(EditBoxTextLength
, Length
);
882 EditBoxTextPosition
= 0;
883 EditBoxLine
= y2
- 2;
884 EditBoxStartX
= x1
+ 3;
885 EditBoxEndX
= x2
- 3;
887 // Draw the edit box background and the text
888 UiFillArea(EditBoxStartX
, EditBoxLine
, EditBoxEndX
, EditBoxLine
, ' ', ATTR(UiEditBoxTextColor
, UiEditBoxBgColor
));
889 UiDrawText2(EditBoxStartX
, EditBoxLine
, EditBoxEndX
- EditBoxStartX
+ 1, EditTextBuffer
, ATTR(UiEditBoxTextColor
, UiEditBoxBgColor
));
892 EditBoxCursorX
= EditBoxStartX
;
893 MachVideoSetTextCursorPosition(EditBoxCursorX
, EditBoxLine
);
894 MachVideoHideShowTextCursor(TRUE
);
897 UiDrawStatusText("Press ENTER to continue, or ESC to cancel");
899 VideoCopyOffScreenBufferToVRAM();
902 // Enter the text. Please keep in mind that the default input mode
903 // of the edit boxes is in insertion mode, that is, you can insert
904 // text without erasing the existing one.
911 key
= MachConsGetCh();
912 if (key
== KEY_EXTENDED
)
915 key
= MachConsGetCh();
918 if (key
== KEY_ENTER
)
923 else if (key
== KEY_ESC
)
928 else if (key
== KEY_BACKSPACE
) // Remove a character
930 if ( (EditBoxTextLength
> 0) && (EditBoxTextPosition
> 0) &&
931 (EditBoxTextPosition
<= EditBoxTextLength
) )
933 EditBoxTextPosition
--;
934 memmove(EditTextBuffer
+ EditBoxTextPosition
,
935 EditTextBuffer
+ EditBoxTextPosition
+ 1,
936 EditBoxTextLength
- EditBoxTextPosition
);
938 EditTextBuffer
[EditBoxTextLength
] = 0;
945 else if (Extended
&& key
== KEY_DELETE
) // Remove a character
947 if ( (EditBoxTextLength
> 0) &&
948 (EditBoxTextPosition
< EditBoxTextLength
) )
950 memmove(EditTextBuffer
+ EditBoxTextPosition
,
951 EditTextBuffer
+ EditBoxTextPosition
+ 1,
952 EditBoxTextLength
- EditBoxTextPosition
);
954 EditTextBuffer
[EditBoxTextLength
] = 0;
961 else if (Extended
&& key
== KEY_HOME
) // Go to the start of the buffer
963 EditBoxTextPosition
= 0;
965 else if (Extended
&& key
== KEY_END
) // Go to the end of the buffer
967 EditBoxTextPosition
= EditBoxTextLength
;
969 else if (Extended
&& key
== KEY_RIGHT
) // Go right
971 if (EditBoxTextPosition
< EditBoxTextLength
)
972 EditBoxTextPosition
++;
976 else if (Extended
&& key
== KEY_LEFT
) // Go left
978 if (EditBoxTextPosition
> 0)
979 EditBoxTextPosition
--;
983 else if (!Extended
) // Add this key to the buffer
985 if ( (EditBoxTextLength
< Length
- 1) &&
986 (EditBoxTextPosition
< Length
- 1) )
988 memmove(EditTextBuffer
+ EditBoxTextPosition
+ 1,
989 EditTextBuffer
+ EditBoxTextPosition
,
990 EditBoxTextLength
- EditBoxTextPosition
);
991 EditTextBuffer
[EditBoxTextPosition
] = key
;
992 EditBoxTextPosition
++;
994 EditTextBuffer
[EditBoxTextLength
] = 0;
1007 // Draw the edit box background
1008 UiFillArea(EditBoxStartX
, EditBoxLine
, EditBoxEndX
, EditBoxLine
, ' ', ATTR(UiEditBoxTextColor
, UiEditBoxBgColor
));
1011 if (EditBoxTextPosition
> (EditBoxEndX
- EditBoxStartX
))
1013 EditBoxTextDisplayIndex
= EditBoxTextPosition
- (EditBoxEndX
- EditBoxStartX
);
1014 EditBoxCursorX
= EditBoxEndX
;
1018 EditBoxTextDisplayIndex
= 0;
1019 EditBoxCursorX
= EditBoxStartX
+ EditBoxTextPosition
;
1021 UiDrawText2(EditBoxStartX
, EditBoxLine
, EditBoxEndX
- EditBoxStartX
+ 1, &EditTextBuffer
[EditBoxTextDisplayIndex
], ATTR(UiEditBoxTextColor
, UiEditBoxBgColor
));
1024 MachVideoSetTextCursorPosition(EditBoxCursorX
, EditBoxLine
);
1026 TuiUpdateDateTime();
1028 VideoCopyOffScreenBufferToVRAM();
1033 // Hide the cursor again
1034 MachVideoHideShowTextCursor(FALSE
);
1036 // Restore the screen contents
1037 TuiRestoreScreen(ScreenBuffer
);
1038 FrLdrTempFree(ScreenBuffer
, TAG_TUI_SCREENBUFFER
);
1043 const UIVTBL TuiVtbl
=
1053 TuiDrawCenteredText
,
1057 TuiMessageBoxCritical
,
1058 TuiDrawProgressBarCenter
,