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 PVOID TextVideoBuffer
= NULL
;
26 * Prints formatted text to the screen
28 int TuiPrintf(const char *Format
, ...)
36 Length
= _vsnprintf(Buffer
, sizeof(Buffer
), Format
, ap
);
39 if (Length
== -1) Length
= sizeof(Buffer
);
41 for (i
= 0; i
< Length
; i
++)
43 MachConsPutChar(Buffer
[i
]);
49 BOOLEAN
TuiInitialize(VOID
)
51 MachVideoHideShowTextCursor(FALSE
);
52 MachVideoClearScreen(ATTR(COLOR_GRAY
, COLOR_BLACK
));
54 TextVideoBuffer
= VideoAllocateOffScreenBuffer();
55 if (TextVideoBuffer
== NULL
)
63 VOID
TuiUnInitialize(VOID
)
65 if (UiUseSpecialEffects
)
71 MachVideoSetDisplayMode(NULL
, FALSE
);
74 MachVideoClearScreen(ATTR(COLOR_GRAY
, COLOR_BLACK
));
75 MachVideoHideShowTextCursor(TRUE
);
78 VOID
TuiDrawBackdrop(VOID
)
81 // Fill in the background (excluding title box & status bar)
84 TUI_TITLE_BOX_CHAR_HEIGHT
,
88 ATTR(UiBackdropFgColor
, UiBackdropBgColor
));
96 TUI_TITLE_BOX_CHAR_HEIGHT
- 1,
101 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
108 GetFreeLoaderVersionString(),
109 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
117 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
121 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
126 TuiDrawText(UiScreenWidth
- 16, 3, /*"F1 for Help"*/"F8 for Options", ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
131 TuiDrawText((UiScreenWidth
- (ULONG
)strlen(UiTitleBoxTitleText
)) / 2,
134 ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
137 // Update the date & time
141 VideoCopyOffScreenBufferToVRAM();
146 * This function assumes coordinates are zero-based
148 VOID
TuiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
150 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
153 // Clip the area to the screen
154 if ((Left
>= UiScreenWidth
) || (Top
>= UiScreenHeight
))
158 if (Right
>= UiScreenWidth
)
160 Right
= UiScreenWidth
- 1;
162 if (Bottom
>= UiScreenHeight
)
164 Bottom
= UiScreenHeight
- 1;
167 // Loop through each line and fill it in
168 for (i
=Top
; i
<=Bottom
; i
++)
170 // Loop through each character (column) in the line and fill it in
171 for (j
=Left
; j
<=Right
; j
++)
173 ScreenMemory
[((i
*2)*UiScreenWidth
)+(j
*2)] = (UCHAR
)FillChar
;
174 ScreenMemory
[((i
*2)*UiScreenWidth
)+(j
*2)+1] = Attr
;
181 * This function assumes coordinates are zero-based
183 VOID
TuiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
185 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
188 // Shade the bottom of the area
189 if (Bottom
< (UiScreenHeight
- 1))
191 if (UiScreenHeight
< 34)
200 for (; Idx
<=Right
; Idx
++)
202 ScreenMemory
[(((Bottom
+1)*2)*UiScreenWidth
)+(Idx
*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
206 // Shade the right of the area
207 if (Right
< (UiScreenWidth
- 1))
209 for (Idx
=Top
+1; Idx
<=Bottom
; Idx
++)
211 ScreenMemory
[((Idx
*2)*UiScreenWidth
)+((Right
+1)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
214 if (UiScreenHeight
< 34)
216 if ((Right
+ 1) < (UiScreenWidth
- 1))
218 for (Idx
=Top
+1; Idx
<=Bottom
; Idx
++)
220 ScreenMemory
[((Idx
*2)*UiScreenWidth
)+((Right
+2)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
225 // Shade the bottom right corner
226 if ((Right
< (UiScreenWidth
- 1)) && (Bottom
< (UiScreenHeight
- 1)))
228 ScreenMemory
[(((Bottom
+1)*2)*UiScreenWidth
)+((Right
+1)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
230 if (UiScreenHeight
< 34)
232 if (((Right
+ 1) < (UiScreenWidth
- 1)) && (Bottom
< (UiScreenHeight
- 1)))
234 ScreenMemory
[(((Bottom
+1)*2)*UiScreenWidth
)+((Right
+2)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
241 * This function assumes coordinates are zero-based
243 VOID
TuiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
245 UCHAR ULCorner
, URCorner
, LLCorner
, LRCorner
;
247 // Calculate the corner values
248 if (HorzStyle
== HORZ
)
250 if (VertStyle
== VERT
)
257 else // VertStyle == D_VERT
265 else // HorzStyle == D_HORZ
267 if (VertStyle
== VERT
)
274 else // VertStyle == D_VERT
283 // Fill in box background
286 TuiFillArea(Left
, Top
, Right
, Bottom
, ' ', Attr
);
290 TuiFillArea(Left
, Top
, Left
, Top
, ULCorner
, Attr
);
291 TuiFillArea(Right
, Top
, Right
, Top
, URCorner
, Attr
);
292 TuiFillArea(Left
, Bottom
, Left
, Bottom
, LLCorner
, Attr
);
293 TuiFillArea(Right
, Bottom
, Right
, Bottom
, LRCorner
, Attr
);
296 TuiFillArea(Left
, Top
+1, Left
, Bottom
-1, VertStyle
, Attr
);
298 TuiFillArea(Left
+1, Top
, Right
-1, Top
, HorzStyle
, Attr
);
299 // Fill in right line
300 TuiFillArea(Right
, Top
+1, Right
, Bottom
-1, VertStyle
, Attr
);
301 // Fill in bottom line
302 TuiFillArea(Left
+1, Bottom
, Right
-1, Bottom
, HorzStyle
, Attr
);
307 TuiDrawShadow(Left
, Top
, Right
, Bottom
);
313 * This function assumes coordinates are zero-based
315 VOID
TuiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
317 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
321 for (i
= X
, j
= 0; Text
[j
] && i
< UiScreenWidth
; i
++, j
++)
323 ScreenMemory
[((Y
*2)*UiScreenWidth
)+(i
*2)] = (UCHAR
)Text
[j
];
324 ScreenMemory
[((Y
*2)*UiScreenWidth
)+(i
*2)+1] = Attr
;
330 * This function assumes coordinates are zero-based.
331 * MaxNumChars is the maximum number of characters to display.
332 * If MaxNumChars == 0, then display the whole string.
334 VOID
TuiDrawText2(ULONG X
, ULONG Y
, ULONG MaxNumChars
, PCSTR Text
, UCHAR Attr
)
336 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
340 for (i
= X
, j
= 0; Text
[j
] && i
< UiScreenWidth
&& (MaxNumChars
> 0 ? j
< MaxNumChars
: TRUE
); i
++, j
++)
342 ScreenMemory
[((Y
*2)*UiScreenWidth
)+(i
*2)] = (UCHAR
)Text
[j
];
343 ScreenMemory
[((Y
*2)*UiScreenWidth
)+(i
*2)+1] = Attr
;
347 VOID
TuiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
352 ULONG LineBreakCount
;
361 TextLength
= strlen(TextString
);
363 // Count the new lines and the box width
367 for (Index
=0; Index
<TextLength
; Index
++)
369 if (TextString
[Index
] == '\n')
376 if ((Index
- LastIndex
) > BoxWidth
)
378 BoxWidth
= (ULONG
)(Index
- LastIndex
);
383 BoxHeight
= LineBreakCount
+ 1;
385 RealLeft
= (((Right
- Left
) - BoxWidth
) / 2) + Left
;
386 RealTop
= (((Bottom
- Top
) - BoxHeight
) / 2) + Top
;
389 for (Index
=0; Index
<TextLength
; Index
++)
391 if (TextString
[Index
] == '\n')
398 X
= (ULONG
)(RealLeft
+ LastIndex
);
401 Temp
[0] = TextString
[Index
];
403 TuiDrawText(X
, Y
, Temp
, Attr
);
408 VOID
TuiDrawStatusText(PCSTR StatusText
)
412 TuiDrawText(0, UiScreenHeight
-1, " ", ATTR(UiStatusBarFgColor
, UiStatusBarBgColor
));
413 TuiDrawText(1, UiScreenHeight
-1, StatusText
, ATTR(UiStatusBarFgColor
, UiStatusBarBgColor
));
415 for (i
=strlen(StatusText
)+1; i
<UiScreenWidth
; i
++)
417 TuiDrawText((ULONG
)i
, UiScreenHeight
-1, " ", ATTR(UiStatusBarFgColor
, UiStatusBarBgColor
));
420 VideoCopyOffScreenBufferToVRAM();
423 VOID
TuiUpdateDateTime(VOID
)
429 BOOLEAN PMHour
= FALSE
;
431 /* Don't draw the time if this has been disabled */
432 if (!UiDrawTime
) return;
434 TimeInfo
= ArcGetTime();
435 if (TimeInfo
->Year
< 1 || 9999 < TimeInfo
->Year
||
436 TimeInfo
->Month
< 1 || 12 < TimeInfo
->Month
||
437 TimeInfo
->Day
< 1 || 31 < TimeInfo
->Day
||
438 23 < TimeInfo
->Hour
||
439 59 < TimeInfo
->Minute
||
440 59 < TimeInfo
->Second
)
442 /* This happens on QEmu sometimes. We just skip updating */
445 // Get the month name
446 strcpy(DateString
, UiMonthNames
[TimeInfo
->Month
- 1]);
448 _itoa(TimeInfo
->Day
, TempString
, 10);
449 // Get the day postfix
450 if (1 == TimeInfo
->Day
|| 21 == TimeInfo
->Day
|| 31 == TimeInfo
->Day
)
452 strcat(TempString
, "st");
454 else if (2 == TimeInfo
->Day
|| 22 == TimeInfo
->Day
)
456 strcat(TempString
, "nd");
458 else if (3 == TimeInfo
->Day
|| 23 == TimeInfo
->Day
)
460 strcat(TempString
, "rd");
464 strcat(TempString
, "th");
467 // Add the day to the date
468 strcat(DateString
, TempString
);
469 strcat(DateString
, " ");
471 // Get the year and add it to the date
472 _itoa(TimeInfo
->Year
, TempString
, 10);
473 strcat(DateString
, TempString
);
476 TuiDrawText(UiScreenWidth
-(ULONG
)strlen(DateString
)-2, 1, DateString
, ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
478 // Get the hour and change from 24-hour mode to 12-hour
479 if (TimeInfo
->Hour
> 12)
481 TimeInfo
->Hour
-= 12;
484 if (TimeInfo
->Hour
== 0)
488 _itoa(TimeInfo
->Hour
, TempString
, 10);
489 strcpy(TimeString
, " ");
490 strcat(TimeString
, TempString
);
491 strcat(TimeString
, ":");
492 _itoa(TimeInfo
->Minute
, TempString
, 10);
493 if (TimeInfo
->Minute
< 10)
495 strcat(TimeString
, "0");
497 strcat(TimeString
, TempString
);
498 strcat(TimeString
, ":");
499 _itoa(TimeInfo
->Second
, TempString
, 10);
500 if (TimeInfo
->Second
< 10)
502 strcat(TimeString
, "0");
504 strcat(TimeString
, TempString
);
507 strcat(TimeString
, " PM");
511 strcat(TimeString
, " AM");
515 TuiDrawText(UiScreenWidth
-(ULONG
)strlen(TimeString
)-2, 2, TimeString
, ATTR(UiTitleBoxFgColor
, UiTitleBoxBgColor
));
518 VOID
TuiSaveScreen(PUCHAR Buffer
)
520 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
523 for (i
=0; i
< (UiScreenWidth
* UiScreenHeight
* 2); i
++)
525 Buffer
[i
] = ScreenMemory
[i
];
529 VOID
TuiRestoreScreen(PUCHAR Buffer
)
531 PUCHAR ScreenMemory
= (PUCHAR
)TextVideoBuffer
;
534 for (i
=0; i
< (UiScreenWidth
* UiScreenHeight
* 2); i
++)
536 ScreenMemory
[i
] = Buffer
[i
];
540 VOID
TuiMessageBox(PCSTR MessageText
)
544 // Save the screen contents
545 ScreenBuffer
= MmHeapAlloc(UiScreenWidth
* UiScreenHeight
* 2);
546 TuiSaveScreen(ScreenBuffer
);
548 // Display the message box
549 TuiMessageBoxCritical(MessageText
);
551 // Restore the screen contents
552 TuiRestoreScreen(ScreenBuffer
);
553 MmHeapFree(ScreenBuffer
);
556 VOID
TuiMessageBoxCritical(PCSTR MessageText
)
559 unsigned int height
= 1;
568 for (i
=0; i
<strlen(MessageText
); i
++)
570 if (MessageText
[i
] == '\n')
575 for (i
=0,j
=0,k
=0; i
<height
; i
++)
577 while ((MessageText
[j
] != '\n') && (MessageText
[j
] != 0))
590 // Calculate box area
591 x1
= (UiScreenWidth
- (width
+2))/2;
593 y1
= ((UiScreenHeight
- height
- 2)/2) + 1;
594 y2
= y1
+ height
+ 4;
597 TuiDrawBox(x1
, y1
, x2
, y2
, D_VERT
, D_HORZ
, TRUE
, TRUE
, ATTR(UiMessageBoxFgColor
, UiMessageBoxBgColor
));
600 for (i
=0,j
=0; i
<strlen(MessageText
)+1; i
++)
602 if ((MessageText
[i
] == '\n') || (MessageText
[i
] == 0))
606 UiDrawText(x1
+2, y1
+1+curline
, temp
, ATTR(UiMessageBoxFgColor
, UiMessageBoxBgColor
));
610 temp
[j
++] = MessageText
[i
];
614 strcpy(temp
, " OK ");
615 UiDrawText(x1
+((x2
-x1
)/2)-3, y2
-2, temp
, ATTR(COLOR_BLACK
, COLOR_GRAY
));
618 UiDrawStatusText("Press ENTER to continue");
620 VideoCopyOffScreenBufferToVRAM();
626 key
= MachConsGetCh();
627 if(key
== KEY_EXTENDED
)
628 key
= MachConsGetCh();
632 else if(key
== KEY_SPACE
)
634 else if(key
== KEY_ESC
)
640 VideoCopyOffScreenBufferToVRAM();
647 VOID
TuiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
649 ULONG Left
, Top
, Right
, Bottom
;
650 ULONG Width
= 50; // Allow for 50 "bars"
653 Left
= (UiScreenWidth
- Width
- 4) / 2;
654 Right
= Left
+ Width
+ 3;
655 Top
= (UiScreenHeight
- Height
- 2) / 2;
657 Bottom
= Top
+ Height
+ 1;
659 TuiDrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
662 VOID
TuiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
665 ULONG ProgressBarWidth
= (Right
- Left
) - 3;
667 // First make sure the progress bar text fits
668 UiTruncateStringEllipsis(ProgressText
, ProgressBarWidth
- 4);
670 if (Position
> Range
)
676 TuiDrawBox(Left
, Top
, Right
, Bottom
, VERT
, HORZ
, TRUE
, TRUE
, ATTR(UiMenuFgColor
, UiMenuBgColor
));
679 // Draw the "Loading..." text
681 TuiDrawCenteredText(Left
+ 2, Top
+ 2, Right
- 2, Top
+ 2, ProgressText
, ATTR(UiTextColor
, UiMenuBgColor
));
683 // Draw the percent complete
684 for (i
=0; i
<(Position
*ProgressBarWidth
)/Range
; i
++)
686 TuiDrawText(Left
+2+i
, Top
+2, "\xDB", ATTR(UiTextColor
, UiMenuBgColor
));
690 for (; i
<ProgressBarWidth
; i
++)
692 TuiDrawText(Left
+2+i
, Top
+2, "\xB2", ATTR(UiTextColor
, UiMenuBgColor
));
696 VideoCopyOffScreenBufferToVRAM();
699 UCHAR
TuiTextToColor(PCSTR ColorText
)
701 if (_stricmp(ColorText
, "Black") == 0)
703 else if (_stricmp(ColorText
, "Blue") == 0)
705 else if (_stricmp(ColorText
, "Green") == 0)
707 else if (_stricmp(ColorText
, "Cyan") == 0)
709 else if (_stricmp(ColorText
, "Red") == 0)
711 else if (_stricmp(ColorText
, "Magenta") == 0)
712 return COLOR_MAGENTA
;
713 else if (_stricmp(ColorText
, "Brown") == 0)
715 else if (_stricmp(ColorText
, "Gray") == 0)
717 else if (_stricmp(ColorText
, "DarkGray") == 0)
718 return COLOR_DARKGRAY
;
719 else if (_stricmp(ColorText
, "LightBlue") == 0)
720 return COLOR_LIGHTBLUE
;
721 else if (_stricmp(ColorText
, "LightGreen") == 0)
722 return COLOR_LIGHTGREEN
;
723 else if (_stricmp(ColorText
, "LightCyan") == 0)
724 return COLOR_LIGHTCYAN
;
725 else if (_stricmp(ColorText
, "LightRed") == 0)
726 return COLOR_LIGHTRED
;
727 else if (_stricmp(ColorText
, "LightMagenta") == 0)
728 return COLOR_LIGHTMAGENTA
;
729 else if (_stricmp(ColorText
, "Yellow") == 0)
731 else if (_stricmp(ColorText
, "White") == 0)
737 UCHAR
TuiTextToFillStyle(PCSTR FillStyleText
)
739 if (_stricmp(FillStyleText
, "Light") == 0)
743 else if (_stricmp(FillStyleText
, "Medium") == 0)
747 else if (_stricmp(FillStyleText
, "Dark") == 0)
755 VOID
TuiFadeInBackdrop(VOID
)
757 PPALETTE_ENTRY TuiFadePalette
= NULL
;
759 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed())
761 TuiFadePalette
= (PPALETTE_ENTRY
)MmHeapAlloc(sizeof(PALETTE_ENTRY
) * 64);
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 MmHeapFree(TuiFadePalette
);
780 VOID
TuiFadeOut(VOID
)
782 PPALETTE_ENTRY TuiFadePalette
= NULL
;
784 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed())
786 TuiFadePalette
= (PPALETTE_ENTRY
)MmHeapAlloc(sizeof(PALETTE_ENTRY
) * 64);
788 if (TuiFadePalette
!= NULL
)
790 VideoSavePaletteState(TuiFadePalette
, 64);
794 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed() && TuiFadePalette
!= NULL
)
799 MachVideoSetDisplayMode(NULL
, FALSE
);
801 if (UiUseSpecialEffects
&& ! MachVideoIsPaletteFixed() && TuiFadePalette
!= NULL
)
803 VideoRestorePaletteState(TuiFadePalette
, 64);
804 MmHeapFree(TuiFadePalette
);
809 BOOLEAN
TuiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
821 ULONG EditBoxStartX
, EditBoxEndX
;
823 ULONG EditBoxTextLength
, EditBoxTextPosition
;
824 INT EditBoxTextDisplayIndex
;
828 // Save the screen contents
829 ScreenBuffer
= MmHeapAlloc(UiScreenWidth
* UiScreenHeight
* 2);
830 TuiSaveScreen(ScreenBuffer
);
833 for (i
=0; i
<strlen(MessageText
); i
++)
835 if (MessageText
[i
] == '\n')
840 for (i
=0,j
=0,k
=0; i
<height
; i
++)
842 while ((MessageText
[j
] != '\n') && (MessageText
[j
] != 0))
855 // Calculate box area
856 x1
= (UiScreenWidth
- (width
+2))/2;
858 y1
= ((UiScreenHeight
- height
- 2)/2) + 1;
859 y2
= y1
+ height
+ 4;
862 TuiDrawBox(x1
, y1
, x2
, y2
, D_VERT
, D_HORZ
, TRUE
, TRUE
, ATTR(UiMessageBoxFgColor
, UiMessageBoxBgColor
));
865 for (i
=0,j
=0; i
<strlen(MessageText
)+1; i
++)
867 if ((MessageText
[i
] == '\n') || (MessageText
[i
] == 0))
871 UiDrawText(x1
+2, y1
+1+curline
, temp
, ATTR(UiMessageBoxFgColor
, UiMessageBoxBgColor
));
875 temp
[j
++] = MessageText
[i
];
878 EditBoxTextLength
= 0;
879 EditBoxTextPosition
= 0;
880 EditBoxLine
= y2
- 2;
881 EditBoxStartX
= x1
+ 3;
882 EditBoxEndX
= x2
- 3;
883 UiFillArea(EditBoxStartX
, EditBoxLine
, EditBoxEndX
, EditBoxLine
, ' ', ATTR(UiEditBoxTextColor
, UiEditBoxBgColor
));
886 EditBoxCursorX
= EditBoxStartX
;
887 MachVideoSetTextCursorPosition(EditBoxCursorX
, EditBoxLine
);
888 MachVideoHideShowTextCursor(TRUE
);
891 UiDrawStatusText("Press ENTER to continue, or ESC to cancel");
893 VideoCopyOffScreenBufferToVRAM();
896 // Enter the text. Please keep in mind that the default input mode
897 // of the edit boxes is in insertion mode, that is, you can insert
898 // text without erasing the existing one.
905 key
= MachConsGetCh();
906 if(key
== KEY_EXTENDED
)
909 key
= MachConsGetCh();
917 else if(key
== KEY_ESC
)
922 else if (key
== KEY_BACKSPACE
) // Remove a character
924 if ( (EditBoxTextLength
> 0) && (EditBoxTextPosition
> 0) &&
925 (EditBoxTextPosition
<= EditBoxTextLength
) )
927 EditBoxTextPosition
--;
928 memmove(EditTextBuffer
+ EditBoxTextPosition
,
929 EditTextBuffer
+ EditBoxTextPosition
+ 1,
930 EditBoxTextLength
- EditBoxTextPosition
);
932 EditTextBuffer
[EditBoxTextLength
] = 0;
939 else if (Extended
&& key
== KEY_DELETE
) // Remove a character
941 if ( (EditBoxTextLength
> 0) &&
942 (EditBoxTextPosition
< EditBoxTextLength
) )
944 memmove(EditTextBuffer
+ EditBoxTextPosition
,
945 EditTextBuffer
+ EditBoxTextPosition
+ 1,
946 EditBoxTextLength
- EditBoxTextPosition
);
948 EditTextBuffer
[EditBoxTextLength
] = 0;
955 else if (key
== KEY_HOME
) // Go to the start of the buffer
957 EditBoxTextPosition
= 0;
959 else if (key
== KEY_END
) // Go to the end of the buffer
961 EditBoxTextPosition
= EditBoxTextLength
;
963 else if (key
== KEY_RIGHT
) // Go right
965 if (EditBoxTextPosition
< EditBoxTextLength
)
966 EditBoxTextPosition
++;
970 else if (key
== KEY_LEFT
) // Go left
972 if (EditBoxTextPosition
> 0)
973 EditBoxTextPosition
--;
977 else // Add this key to the buffer
979 if ( (EditBoxTextLength
< Length
- 1) &&
980 (EditBoxTextPosition
< Length
- 1) )
982 memmove(EditTextBuffer
+ EditBoxTextPosition
+ 1,
983 EditTextBuffer
+ EditBoxTextPosition
,
984 EditBoxTextLength
- EditBoxTextPosition
);
985 EditTextBuffer
[EditBoxTextPosition
] = key
;
986 EditBoxTextPosition
++;
988 EditTextBuffer
[EditBoxTextLength
] = 0;
997 // Draw the edit box background
998 UiFillArea(EditBoxStartX
, EditBoxLine
, EditBoxEndX
, EditBoxLine
, ' ', ATTR(UiEditBoxTextColor
, UiEditBoxBgColor
));
1001 if (EditBoxTextPosition
> (EditBoxEndX
- EditBoxStartX
))
1003 EditBoxTextDisplayIndex
= EditBoxTextPosition
- (EditBoxEndX
- EditBoxStartX
);
1004 EditBoxCursorX
= EditBoxEndX
;
1008 EditBoxTextDisplayIndex
= 0;
1009 EditBoxCursorX
= EditBoxStartX
+ EditBoxTextPosition
;
1011 UiDrawText2(EditBoxStartX
, EditBoxLine
, EditBoxEndX
- EditBoxStartX
+ 1, &EditTextBuffer
[EditBoxTextDisplayIndex
], ATTR(UiEditBoxTextColor
, UiEditBoxBgColor
));
1014 MachVideoSetTextCursorPosition(EditBoxCursorX
, EditBoxLine
);
1016 TuiUpdateDateTime();
1018 VideoCopyOffScreenBufferToVRAM();
1023 // Hide the cursor again
1024 MachVideoHideShowTextCursor(FALSE
);
1026 // Restore the screen contents
1027 TuiRestoreScreen(ScreenBuffer
);
1028 MmHeapFree(ScreenBuffer
);
1033 const UIVTBL TuiVtbl
=
1043 TuiDrawCenteredText
,
1047 TuiMessageBoxCritical
,
1048 TuiDrawProgressBarCenter
,