mirror of
https://github.com/reactos/reactos.git
synced 2025-05-08 03:07:05 +00:00
[FREELDR:UI] Cleanup for the DrawText* functions.
- Remove duplicated code from directui.c and use the one from TUI instead, with the latter properly #ifdef'ed for _M_ARM. - Provide the minimal implementations for NoUiDrawText*(). - TuiDrawText() is just a particular case of TuiDrawText2(). - Isolate the TuiPrintf() and TuiDraw*Text*() functions as separate "Generic TUI utils". - Fix "TAG_TAG" typo in TAG_TAG_TUI_PALETTE. - Add SAL annotations.
This commit is contained in:
parent
06fc2e72a6
commit
f6a2438c1f
7 changed files with 317 additions and 247 deletions
|
@ -61,9 +61,34 @@ VOID UiDrawBackdrop(VOID); // Fills the en
|
||||||
VOID UiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */); // Fills the area specified with FillChar and Attr
|
VOID UiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */); // Fills the area specified with FillChar and Attr
|
||||||
VOID UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified
|
VOID UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified
|
||||||
VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); // Draws a box around the area specified
|
VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); // Draws a box around the area specified
|
||||||
VOID UiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified
|
|
||||||
VOID UiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified
|
/* Draws text at coordinates specified */
|
||||||
VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr); // Draws centered text at the coordinates specified and clips the edges
|
VOID
|
||||||
|
UiDrawText(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_ PCSTR Text,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
|
/* Draws text at coordinates specified */
|
||||||
|
VOID
|
||||||
|
UiDrawText2(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_opt_ ULONG MaxNumChars,
|
||||||
|
_In_reads_or_z_(MaxNumChars) PCSTR Text,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
|
/* Draws centered text at the coordinates specified and clips the edges */
|
||||||
|
VOID
|
||||||
|
UiDrawCenteredText(
|
||||||
|
_In_ ULONG Left,
|
||||||
|
_In_ ULONG Top,
|
||||||
|
_In_ ULONG Right,
|
||||||
|
_In_ ULONG Bottom,
|
||||||
|
_In_ PCSTR TextString,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
VOID UiDrawStatusText(PCSTR StatusText); // Draws text at the very bottom line on the screen
|
VOID UiDrawStatusText(PCSTR StatusText); // Draws text at the very bottom line on the screen
|
||||||
VOID UiUpdateDateTime(VOID); // Updates the date and time
|
VOID UiUpdateDateTime(VOID); // Updates the date and time
|
||||||
VOID UiInfoBox(PCSTR MessageText); // Displays a info box on the screen
|
VOID UiInfoBox(PCSTR MessageText); // Displays a info box on the screen
|
||||||
|
|
|
@ -21,9 +21,34 @@ VOID NoUiDrawBackdrop(VOID);
|
||||||
VOID NoUiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr);
|
VOID NoUiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr);
|
||||||
VOID NoUiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom);
|
VOID NoUiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom);
|
||||||
VOID NoUiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr);
|
VOID NoUiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr);
|
||||||
VOID NoUiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr);
|
|
||||||
VOID NoUiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr);
|
/* Draws text at coordinates specified */
|
||||||
VOID NoUiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr);
|
VOID
|
||||||
|
NoUiDrawText(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_ PCSTR Text,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
|
/* Draws text at coordinates specified */
|
||||||
|
VOID
|
||||||
|
NoUiDrawText2(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_opt_ ULONG MaxNumChars,
|
||||||
|
_In_reads_or_z_(MaxNumChars) PCSTR Text,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
|
/* Draws centered text at the coordinates specified and clips the edges */
|
||||||
|
VOID
|
||||||
|
NoUiDrawCenteredText(
|
||||||
|
_In_ ULONG Left,
|
||||||
|
_In_ ULONG Top,
|
||||||
|
_In_ ULONG Right,
|
||||||
|
_In_ ULONG Bottom,
|
||||||
|
_In_ PCSTR TextString,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
VOID NoUiDrawStatusText(PCSTR StatusText);
|
VOID NoUiDrawStatusText(PCSTR StatusText);
|
||||||
VOID NoUiUpdateDateTime(VOID);
|
VOID NoUiUpdateDateTime(VOID);
|
||||||
VOID NoUiMessageBox(PCSTR MessageText);
|
VOID NoUiMessageBox(PCSTR MessageText);
|
||||||
|
|
|
@ -19,6 +19,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/* GENERIC TUI UTILS *********************************************************/
|
||||||
|
|
||||||
|
INT
|
||||||
|
TuiPrintf(
|
||||||
|
_In_ PCSTR Format, ...);
|
||||||
|
|
||||||
|
|
||||||
#define TUI_TITLE_BOX_CHAR_HEIGHT 5
|
#define TUI_TITLE_BOX_CHAR_HEIGHT 5
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -26,6 +33,7 @@
|
||||||
// Textual User Interface Functions
|
// Textual User Interface Functions
|
||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
BOOLEAN TuiInitialize(VOID); // Initialize User-Interface
|
BOOLEAN TuiInitialize(VOID); // Initialize User-Interface
|
||||||
VOID TuiUnInitialize(VOID); // Un-initialize User-Interface
|
VOID TuiUnInitialize(VOID); // Un-initialize User-Interface
|
||||||
|
|
||||||
|
@ -33,9 +41,34 @@ VOID TuiDrawBackdrop(VOID); // Fills the e
|
||||||
VOID TuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */); // Fills the area specified with FillChar and Attr
|
VOID TuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */); // Fills the area specified with FillChar and Attr
|
||||||
VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified
|
VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified
|
||||||
VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); // Draws a box around the area specified
|
VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); // Draws a box around the area specified
|
||||||
VOID TuiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified
|
|
||||||
VOID TuiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified
|
/* Draws text at coordinates specified */
|
||||||
VOID TuiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr); // Draws centered text at the coordinates specified and clips the edges
|
VOID
|
||||||
|
TuiDrawText(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_ PCSTR Text,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
|
/* Draws text at coordinates specified */
|
||||||
|
VOID
|
||||||
|
TuiDrawText2(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_opt_ ULONG MaxNumChars,
|
||||||
|
_In_reads_or_z_(MaxNumChars) PCSTR Text,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
|
/* Draws centered text at the coordinates specified and clips the edges */
|
||||||
|
VOID
|
||||||
|
TuiDrawCenteredText(
|
||||||
|
_In_ ULONG Left,
|
||||||
|
_In_ ULONG Top,
|
||||||
|
_In_ ULONG Right,
|
||||||
|
_In_ ULONG Bottom,
|
||||||
|
_In_ PCSTR TextString,
|
||||||
|
_In_ UCHAR Attr);
|
||||||
|
|
||||||
VOID TuiDrawStatusText(PCSTR StatusText); // Draws text at the very bottom line on the screen
|
VOID TuiDrawStatusText(PCSTR StatusText); // Draws text at the very bottom line on the screen
|
||||||
VOID TuiUpdateDateTime(VOID); // Updates the date and time
|
VOID TuiUpdateDateTime(VOID); // Updates the date and time
|
||||||
VOID TuiSaveScreen(PUCHAR Buffer); // Saves the screen so that it can be restored later
|
VOID TuiSaveScreen(PUCHAR Buffer); // Saves the screen so that it can be restored later
|
||||||
|
@ -45,7 +78,6 @@ VOID TuiMessageBoxCritical(PCSTR MessageText); // Displays a m
|
||||||
VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText); // Draws the progress bar showing nPos percent filled
|
VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText); // Draws the progress bar showing nPos percent filled
|
||||||
VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText); // Draws the progress bar showing nPos percent filled
|
VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText); // Draws the progress bar showing nPos percent filled
|
||||||
BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length);
|
BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length);
|
||||||
int TuiPrintf(const char *format, ... );
|
|
||||||
UCHAR TuiTextToColor(PCSTR ColorText); // Converts the text color into it's equivalent color value
|
UCHAR TuiTextToColor(PCSTR ColorText); // Converts the text color into it's equivalent color value
|
||||||
UCHAR TuiTextToFillStyle(PCSTR FillStyleText); // Converts the text fill into it's equivalent fill value
|
UCHAR TuiTextToFillStyle(PCSTR FillStyleText); // Converts the text fill into it's equivalent fill value
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,13 @@
|
||||||
* PURPOSE: FreeLDR UI Routines
|
* PURPOSE: FreeLDR UI Routines
|
||||||
* PROGRAMMERS: ReactOS Portable Systems Group
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
||||||
*/
|
*/
|
||||||
#ifdef _M_ARM
|
|
||||||
|
|
||||||
/* INCLUDES *******************************************************************/
|
#ifdef _M_ARM
|
||||||
|
|
||||||
#include <freeldr.h>
|
#include <freeldr.h>
|
||||||
|
|
||||||
/* GLOBALS ********************************************************************/
|
/* GLOBALS ********************************************************************/
|
||||||
|
|
||||||
/* FUNCTIONS ******************************************************************/
|
|
||||||
|
|
||||||
ULONG UiScreenWidth;
|
ULONG UiScreenWidth;
|
||||||
ULONG UiScreenHeight;
|
ULONG UiScreenHeight;
|
||||||
UCHAR UiMenuFgColor = COLOR_GRAY;
|
UCHAR UiMenuFgColor = COLOR_GRAY;
|
||||||
|
@ -24,28 +21,7 @@ UCHAR UiSelectedTextColor = COLOR_BLACK;
|
||||||
UCHAR UiSelectedTextBgColor = COLOR_GRAY;
|
UCHAR UiSelectedTextBgColor = COLOR_GRAY;
|
||||||
CHAR UiTimeText[260] = "Seconds until highlighted choice will be started automatically: ";
|
CHAR UiTimeText[260] = "Seconds until highlighted choice will be started automatically: ";
|
||||||
|
|
||||||
INT
|
/* FUNCTIONS ******************************************************************/
|
||||||
TuiPrintf(const char *Format,
|
|
||||||
...)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int Length;
|
|
||||||
va_list ap;
|
|
||||||
CHAR Buffer[512];
|
|
||||||
|
|
||||||
va_start(ap, Format);
|
|
||||||
Length = _vsnprintf(Buffer, sizeof(Buffer), Format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (Length == -1) Length = sizeof(Buffer);
|
|
||||||
|
|
||||||
for (i = 0; i < Length; i++)
|
|
||||||
{
|
|
||||||
MachConsPutChar(Buffer[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
UiInitialize(IN BOOLEAN ShowUi)
|
UiInitialize(IN BOOLEAN ShowUi)
|
||||||
|
@ -76,106 +52,36 @@ UiDrawBackdrop(VOID)
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
UiDrawText(IN ULONG X,
|
UiDrawText(
|
||||||
IN ULONG Y,
|
_In_ ULONG X,
|
||||||
IN PCSTR Text,
|
_In_ ULONG Y,
|
||||||
IN UCHAR Attr)
|
_In_ PCSTR Text,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
ULONG i, j;
|
TuiDrawText2(X, Y, 0 /*(ULONG)strlen(Text)*/, Text, Attr);
|
||||||
|
|
||||||
/* Draw the text character by character, but don't exceed the width */
|
|
||||||
for (i = X, j = 0; Text[j] && i < UiScreenWidth; i++, j++)
|
|
||||||
{
|
|
||||||
/* Write the character */
|
|
||||||
MachVideoPutChar(Text[j], Attr, i, Y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
UiDrawText2(IN ULONG X,
|
UiDrawText2(
|
||||||
IN ULONG Y,
|
_In_ ULONG X,
|
||||||
IN ULONG MaxNumChars,
|
_In_ ULONG Y,
|
||||||
IN PCSTR Text,
|
_In_opt_ ULONG MaxNumChars,
|
||||||
IN UCHAR Attr)
|
_In_reads_or_z_(MaxNumChars) PCSTR Text,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
ULONG i, j;
|
TuiDrawText2(X, Y, MaxNumChars, Text, Attr);
|
||||||
|
|
||||||
/* Draw the text character by character, but don't exceed the width */
|
|
||||||
for (i = X, j = 0; Text[j] && i < UiScreenWidth && (MaxNumChars > 0 ? j < MaxNumChars : TRUE); i++, j++)
|
|
||||||
{
|
|
||||||
/* Write the character */
|
|
||||||
MachVideoPutChar(Text[j], Attr, i, Y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
UiDrawCenteredText(IN ULONG Left,
|
UiDrawCenteredText(
|
||||||
IN ULONG Top,
|
_In_ ULONG Left,
|
||||||
IN ULONG Right,
|
_In_ ULONG Top,
|
||||||
IN ULONG Bottom,
|
_In_ ULONG Right,
|
||||||
IN PCSTR TextString,
|
_In_ ULONG Bottom,
|
||||||
IN UCHAR Attr)
|
_In_ PCSTR TextString,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
ULONG TextLength, BoxWidth, BoxHeight, LineBreakCount, Index, LastIndex;
|
TuiDrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
|
||||||
ULONG RealLeft, RealTop, X, Y;
|
|
||||||
CHAR Temp[2];
|
|
||||||
|
|
||||||
/* Query text length */
|
|
||||||
TextLength = strlen(TextString);
|
|
||||||
|
|
||||||
/* Count the new lines and the box width */
|
|
||||||
LineBreakCount = 0;
|
|
||||||
BoxWidth = 0;
|
|
||||||
LastIndex = 0;
|
|
||||||
for (Index=0; Index < TextLength; Index++)
|
|
||||||
{
|
|
||||||
/* Scan for new lines */
|
|
||||||
if (TextString[Index] == '\n')
|
|
||||||
{
|
|
||||||
/* Remember the new line */
|
|
||||||
LastIndex = Index;
|
|
||||||
LineBreakCount++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Check for new larger box width */
|
|
||||||
if ((Index - LastIndex) > BoxWidth)
|
|
||||||
{
|
|
||||||
/* Update it */
|
|
||||||
BoxWidth = (Index - LastIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Base the box height on the number of lines */
|
|
||||||
BoxHeight = LineBreakCount + 1;
|
|
||||||
|
|
||||||
/* Create the centered coordinates */
|
|
||||||
RealLeft = (((Right - Left) - BoxWidth) / 2) + Left;
|
|
||||||
RealTop = (((Bottom - Top) - BoxHeight) / 2) + Top;
|
|
||||||
|
|
||||||
/* Now go for a second scan */
|
|
||||||
LastIndex = 0;
|
|
||||||
for (Index=0; Index < TextLength; Index++)
|
|
||||||
{
|
|
||||||
/* Look for new lines again */
|
|
||||||
if (TextString[Index] == '\n')
|
|
||||||
{
|
|
||||||
/* Update where the text should start */
|
|
||||||
RealTop++;
|
|
||||||
LastIndex = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* We've got a line of text to print, do it */
|
|
||||||
X = RealLeft + LastIndex;
|
|
||||||
Y = RealTop;
|
|
||||||
LastIndex++;
|
|
||||||
Temp[0] = TextString[Index];
|
|
||||||
Temp[1] = 0;
|
|
||||||
UiDrawText(X, Y, Temp, Attr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
@ -659,4 +565,4 @@ UiDisplayMenu(
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // _M_ARM
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* PURPOSE: No Text UI interface
|
* PURPOSE: No Text UI interface
|
||||||
* PROGRAMMERS: Hervé Poussineau
|
* PROGRAMMERS: Hervé Poussineau
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _M_ARM
|
#ifndef _M_ARM
|
||||||
#include <freeldr.h>
|
#include <freeldr.h>
|
||||||
|
|
||||||
|
@ -33,16 +34,39 @@ VOID NoUiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertSty
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID NoUiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr)
|
VOID
|
||||||
|
NoUiDrawText(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_ PCSTR Text,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
|
printf("%s\n", Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID NoUiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr)
|
VOID
|
||||||
|
NoUiDrawText2(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_opt_ ULONG MaxNumChars,
|
||||||
|
_In_reads_or_z_(MaxNumChars) PCSTR Text,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
|
if (MaxNumChars == 0)
|
||||||
|
MaxNumChars = (ULONG)strlen(Text);
|
||||||
|
printf("%*s\n", MaxNumChars, Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID NoUiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr)
|
VOID
|
||||||
|
NoUiDrawCenteredText(
|
||||||
|
_In_ ULONG Left,
|
||||||
|
_In_ ULONG Top,
|
||||||
|
_In_ ULONG Right,
|
||||||
|
_In_ ULONG Bottom,
|
||||||
|
_In_ PCSTR TextString,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
|
printf("%s\n", TextString);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID NoUiDrawStatusText(PCSTR StatusText)
|
VOID NoUiDrawStatusText(PCSTR StatusText)
|
||||||
|
@ -134,4 +158,5 @@ NoUiDisplayMenu(
|
||||||
VOID NoUiDrawMenu(PUI_MENU_INFO MenuInfo)
|
VOID NoUiDrawMenu(PUI_MENU_INFO MenuInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif // _M_ARM
|
||||||
|
|
|
@ -16,23 +16,25 @@
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
#ifndef _M_ARM
|
|
||||||
#include <freeldr.h>
|
#include <freeldr.h>
|
||||||
|
|
||||||
#define TAG_TUI_SCREENBUFFER 'SiuT'
|
#ifndef _M_ARM
|
||||||
#define TAG_TAG_TUI_PALETTE 'PiuT'
|
|
||||||
|
|
||||||
PVOID TextVideoBuffer = NULL;
|
PVOID TextVideoBuffer = NULL;
|
||||||
extern UCHAR MachDefaultTextColor;
|
#endif
|
||||||
|
|
||||||
|
/* GENERIC TUI UTILS *********************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TuiPrintf()
|
* TuiPrintf()
|
||||||
* Prints formatted text to the screen
|
* Prints formatted text to the screen.
|
||||||
*/
|
*/
|
||||||
int TuiPrintf(const char *Format, ...)
|
INT
|
||||||
|
TuiPrintf(
|
||||||
|
_In_ PCSTR Format, ...)
|
||||||
{
|
{
|
||||||
int i;
|
INT i;
|
||||||
int Length;
|
INT Length;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
CHAR Buffer[512];
|
CHAR Buffer[512];
|
||||||
|
|
||||||
|
@ -40,7 +42,8 @@ int TuiPrintf(const char *Format, ...)
|
||||||
Length = _vsnprintf(Buffer, sizeof(Buffer), Format, ap);
|
Length = _vsnprintf(Buffer, sizeof(Buffer), Format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (Length == -1) Length = sizeof(Buffer);
|
if (Length == -1)
|
||||||
|
Length = (INT)sizeof(Buffer);
|
||||||
|
|
||||||
for (i = 0; i < Length; i++)
|
for (i = 0; i < Length; i++)
|
||||||
{
|
{
|
||||||
|
@ -50,6 +53,138 @@ int TuiPrintf(const char *Format, ...)
|
||||||
return Length;
|
return Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DrawText()
|
||||||
|
* Displays a string on a single screen line.
|
||||||
|
* This function assumes coordinates are zero-based.
|
||||||
|
*/
|
||||||
|
VOID
|
||||||
|
TuiDrawText(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_ PCSTR Text,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
|
{
|
||||||
|
TuiDrawText2(X, Y, 0 /*(ULONG)strlen(Text)*/, Text, Attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DrawText2()
|
||||||
|
* Displays a string on a single screen line.
|
||||||
|
* This function assumes coordinates are zero-based.
|
||||||
|
* MaxNumChars is the maximum number of characters to display.
|
||||||
|
* If MaxNumChars == 0, then display the whole string.
|
||||||
|
*/
|
||||||
|
VOID
|
||||||
|
TuiDrawText2(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_opt_ ULONG MaxNumChars,
|
||||||
|
_In_reads_or_z_(MaxNumChars) PCSTR Text,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
|
{
|
||||||
|
#ifndef _M_ARM
|
||||||
|
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
|
||||||
|
#endif
|
||||||
|
ULONG i, j;
|
||||||
|
|
||||||
|
/* Draw the text, not exceeding the width */
|
||||||
|
for (i = X, j = 0; Text[j] && i < UiScreenWidth && (MaxNumChars > 0 ? j < MaxNumChars : TRUE); i++, j++)
|
||||||
|
{
|
||||||
|
#ifndef _M_ARM
|
||||||
|
ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)] = (UCHAR)Text[j];
|
||||||
|
ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)+1] = Attr;
|
||||||
|
#else
|
||||||
|
/* Write the character */
|
||||||
|
MachVideoPutChar(Text[j], Attr, i, Y);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
TuiDrawCenteredText(
|
||||||
|
_In_ ULONG Left,
|
||||||
|
_In_ ULONG Top,
|
||||||
|
_In_ ULONG Right,
|
||||||
|
_In_ ULONG Bottom,
|
||||||
|
_In_ PCSTR TextString,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
|
{
|
||||||
|
SIZE_T TextLength;
|
||||||
|
SIZE_T Index, LastIndex;
|
||||||
|
ULONG LineBreakCount;
|
||||||
|
ULONG BoxWidth, BoxHeight;
|
||||||
|
ULONG RealLeft, RealTop;
|
||||||
|
ULONG X, Y;
|
||||||
|
CHAR Temp[2];
|
||||||
|
|
||||||
|
/* Query text length */
|
||||||
|
TextLength = strlen(TextString);
|
||||||
|
|
||||||
|
/* Count the new lines and the box width */
|
||||||
|
LineBreakCount = 0;
|
||||||
|
BoxWidth = 0;
|
||||||
|
LastIndex = 0;
|
||||||
|
for (Index = 0; Index < TextLength; Index++)
|
||||||
|
{
|
||||||
|
/* Scan for new lines */
|
||||||
|
if (TextString[Index] == '\n')
|
||||||
|
{
|
||||||
|
/* Remember the new line */
|
||||||
|
LastIndex = Index;
|
||||||
|
LineBreakCount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Check for new larger box width */
|
||||||
|
if ((Index - LastIndex) > BoxWidth)
|
||||||
|
{
|
||||||
|
/* Update it */
|
||||||
|
BoxWidth = (ULONG)(Index - LastIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Base the box height on the number of lines */
|
||||||
|
BoxHeight = LineBreakCount + 1;
|
||||||
|
|
||||||
|
/* Create the centered coordinates */
|
||||||
|
RealLeft = (((Right - Left) - BoxWidth) / 2) + Left;
|
||||||
|
RealTop = (((Bottom - Top) - BoxHeight) / 2) + Top;
|
||||||
|
|
||||||
|
/* Now go for a second scan */
|
||||||
|
LastIndex = 0;
|
||||||
|
for (Index = 0; Index < TextLength; Index++)
|
||||||
|
{
|
||||||
|
/* Look for new lines again */
|
||||||
|
if (TextString[Index] == '\n')
|
||||||
|
{
|
||||||
|
/* Update where the text should start */
|
||||||
|
RealTop++;
|
||||||
|
LastIndex = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* We've got a line of text to print, do it */
|
||||||
|
X = (ULONG)(RealLeft + LastIndex);
|
||||||
|
Y = RealTop;
|
||||||
|
LastIndex++;
|
||||||
|
Temp[0] = TextString[Index];
|
||||||
|
Temp[1] = 0;
|
||||||
|
TuiDrawText(X, Y, Temp, Attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* FULL TUI THEME ************************************************************/
|
||||||
|
|
||||||
|
#ifndef _M_ARM
|
||||||
|
|
||||||
|
#define TAG_TUI_SCREENBUFFER 'SiuT'
|
||||||
|
#define TAG_TUI_PALETTE 'PiuT'
|
||||||
|
|
||||||
|
extern UCHAR MachDefaultTextColor;
|
||||||
|
|
||||||
BOOLEAN TuiInitialize(VOID)
|
BOOLEAN TuiInitialize(VOID)
|
||||||
{
|
{
|
||||||
MachVideoHideShowTextCursor(FALSE);
|
MachVideoHideShowTextCursor(FALSE);
|
||||||
|
@ -305,103 +440,6 @@ VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* DrawText()
|
|
||||||
* This function assumes coordinates are zero-based
|
|
||||||
*/
|
|
||||||
VOID TuiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr)
|
|
||||||
{
|
|
||||||
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
|
|
||||||
ULONG i, j;
|
|
||||||
|
|
||||||
// Draw the text
|
|
||||||
for (i = X, j = 0; Text[j] && i < UiScreenWidth; i++, j++)
|
|
||||||
{
|
|
||||||
ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)] = (UCHAR)Text[j];
|
|
||||||
ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)+1] = Attr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DrawText2()
|
|
||||||
* This function assumes coordinates are zero-based.
|
|
||||||
* MaxNumChars is the maximum number of characters to display.
|
|
||||||
* If MaxNumChars == 0, then display the whole string.
|
|
||||||
*/
|
|
||||||
VOID TuiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr)
|
|
||||||
{
|
|
||||||
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
|
|
||||||
ULONG i, j;
|
|
||||||
|
|
||||||
// Draw the text
|
|
||||||
for (i = X, j = 0; Text[j] && i < UiScreenWidth && (MaxNumChars > 0 ? j < MaxNumChars : TRUE); i++, j++)
|
|
||||||
{
|
|
||||||
ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)] = (UCHAR)Text[j];
|
|
||||||
ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)+1] = Attr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID TuiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr)
|
|
||||||
{
|
|
||||||
SIZE_T TextLength;
|
|
||||||
ULONG BoxWidth;
|
|
||||||
ULONG BoxHeight;
|
|
||||||
ULONG LineBreakCount;
|
|
||||||
SIZE_T Index;
|
|
||||||
SIZE_T LastIndex;
|
|
||||||
ULONG RealLeft;
|
|
||||||
ULONG RealTop;
|
|
||||||
ULONG X;
|
|
||||||
ULONG Y;
|
|
||||||
CHAR Temp[2];
|
|
||||||
|
|
||||||
TextLength = strlen(TextString);
|
|
||||||
|
|
||||||
// Count the new lines and the box width
|
|
||||||
LineBreakCount = 0;
|
|
||||||
BoxWidth = 0;
|
|
||||||
LastIndex = 0;
|
|
||||||
for (Index=0; Index<TextLength; Index++)
|
|
||||||
{
|
|
||||||
if (TextString[Index] == '\n')
|
|
||||||
{
|
|
||||||
LastIndex = Index;
|
|
||||||
LineBreakCount++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((Index - LastIndex) > BoxWidth)
|
|
||||||
{
|
|
||||||
BoxWidth = (ULONG)(Index - LastIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BoxHeight = LineBreakCount + 1;
|
|
||||||
|
|
||||||
RealLeft = (((Right - Left) - BoxWidth) / 2) + Left;
|
|
||||||
RealTop = (((Bottom - Top) - BoxHeight) / 2) + Top;
|
|
||||||
|
|
||||||
LastIndex = 0;
|
|
||||||
for (Index=0; Index<TextLength; Index++)
|
|
||||||
{
|
|
||||||
if (TextString[Index] == '\n')
|
|
||||||
{
|
|
||||||
RealTop++;
|
|
||||||
LastIndex = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
X = (ULONG)(RealLeft + LastIndex);
|
|
||||||
Y = RealTop;
|
|
||||||
LastIndex++;
|
|
||||||
Temp[0] = TextString[Index];
|
|
||||||
Temp[1] = 0;
|
|
||||||
TuiDrawText(X, Y, Temp, Attr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID TuiDrawStatusText(PCSTR StatusText)
|
VOID TuiDrawStatusText(PCSTR StatusText)
|
||||||
{
|
{
|
||||||
SIZE_T i;
|
SIZE_T i;
|
||||||
|
@ -755,7 +793,7 @@ VOID TuiFadeInBackdrop(VOID)
|
||||||
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed())
|
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed())
|
||||||
{
|
{
|
||||||
TuiFadePalette = (PPALETTE_ENTRY)FrLdrTempAlloc(sizeof(PALETTE_ENTRY) * 64,
|
TuiFadePalette = (PPALETTE_ENTRY)FrLdrTempAlloc(sizeof(PALETTE_ENTRY) * 64,
|
||||||
TAG_TAG_TUI_PALETTE);
|
TAG_TUI_PALETTE);
|
||||||
|
|
||||||
if (TuiFadePalette != NULL)
|
if (TuiFadePalette != NULL)
|
||||||
{
|
{
|
||||||
|
@ -770,7 +808,7 @@ VOID TuiFadeInBackdrop(VOID)
|
||||||
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL)
|
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL)
|
||||||
{
|
{
|
||||||
VideoFadeIn(TuiFadePalette, 64);
|
VideoFadeIn(TuiFadePalette, 64);
|
||||||
FrLdrTempFree(TuiFadePalette, TAG_TAG_TUI_PALETTE);
|
FrLdrTempFree(TuiFadePalette, TAG_TUI_PALETTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -781,7 +819,7 @@ VOID TuiFadeOut(VOID)
|
||||||
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed())
|
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed())
|
||||||
{
|
{
|
||||||
TuiFadePalette = (PPALETTE_ENTRY)FrLdrTempAlloc(sizeof(PALETTE_ENTRY) * 64,
|
TuiFadePalette = (PPALETTE_ENTRY)FrLdrTempAlloc(sizeof(PALETTE_ENTRY) * 64,
|
||||||
TAG_TAG_TUI_PALETTE);
|
TAG_TUI_PALETTE);
|
||||||
|
|
||||||
if (TuiFadePalette != NULL)
|
if (TuiFadePalette != NULL)
|
||||||
{
|
{
|
||||||
|
@ -799,7 +837,7 @@ VOID TuiFadeOut(VOID)
|
||||||
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL)
|
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL)
|
||||||
{
|
{
|
||||||
VideoRestorePaletteState(TuiFadePalette, 64);
|
VideoRestorePaletteState(TuiFadePalette, 64);
|
||||||
FrLdrTempFree(TuiFadePalette, TAG_TAG_TUI_PALETTE);
|
FrLdrTempFree(TuiFadePalette, TAG_TUI_PALETTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1062,4 +1100,5 @@ const UIVTBL TuiVtbl =
|
||||||
TuiDisplayMenu,
|
TuiDisplayMenu,
|
||||||
TuiDrawMenu,
|
TuiDrawMenu,
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
#endif // _M_ARM
|
||||||
|
|
|
@ -239,17 +239,35 @@ VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle
|
||||||
UiVtbl.DrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
|
UiVtbl.DrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID UiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr)
|
VOID
|
||||||
|
UiDrawText(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_ PCSTR Text,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
UiVtbl.DrawText(X, Y, Text, Attr);
|
UiVtbl.DrawText(X, Y, Text, Attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID UiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr)
|
VOID
|
||||||
|
UiDrawText2(
|
||||||
|
_In_ ULONG X,
|
||||||
|
_In_ ULONG Y,
|
||||||
|
_In_opt_ ULONG MaxNumChars,
|
||||||
|
_In_reads_or_z_(MaxNumChars) PCSTR Text,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
UiVtbl.DrawText2(X, Y, MaxNumChars, Text, Attr);
|
UiVtbl.DrawText2(X, Y, MaxNumChars, Text, Attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr)
|
VOID
|
||||||
|
UiDrawCenteredText(
|
||||||
|
_In_ ULONG Left,
|
||||||
|
_In_ ULONG Top,
|
||||||
|
_In_ ULONG Right,
|
||||||
|
_In_ ULONG Bottom,
|
||||||
|
_In_ PCSTR TextString,
|
||||||
|
_In_ UCHAR Attr)
|
||||||
{
|
{
|
||||||
UiVtbl.DrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
|
UiVtbl.DrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue