Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentui.c
Go to the documentation of this file.
00001 /* 00002 * FreeLoader 00003 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 #ifndef _M_ARM 00020 #include <freeldr.h> 00021 00022 PVOID TextVideoBuffer = NULL; 00023 00024 /* 00025 * TuiPrintf() 00026 * Prints formatted text to the screen 00027 */ 00028 int TuiPrintf(const char *Format, ...) 00029 { 00030 int i; 00031 int Length; 00032 va_list ap; 00033 CHAR Buffer[512]; 00034 00035 va_start(ap, Format); 00036 Length = _vsnprintf(Buffer, sizeof(Buffer), Format, ap); 00037 va_end(ap); 00038 00039 if (Length == -1) Length = sizeof(Buffer); 00040 00041 for (i = 0; i < Length; i++) 00042 { 00043 MachConsPutChar(Buffer[i]); 00044 } 00045 00046 return Length; 00047 } 00048 00049 BOOLEAN TuiInitialize(VOID) 00050 { 00051 MachVideoClearScreen(ATTR(COLOR_WHITE, COLOR_BLACK)); 00052 MachVideoHideShowTextCursor(FALSE); 00053 00054 TextVideoBuffer = VideoAllocateOffScreenBuffer(); 00055 if (TextVideoBuffer == NULL) 00056 { 00057 return FALSE; 00058 } 00059 00060 return TRUE; 00061 } 00062 00063 VOID TuiUnInitialize(VOID) 00064 { 00065 if (UiUseSpecialEffects) 00066 { 00067 TuiFadeOut(); 00068 } 00069 else 00070 { 00071 MachVideoSetDisplayMode(NULL, FALSE); 00072 } 00073 00074 //VideoClearScreen(); 00075 MachVideoHideShowTextCursor(TRUE); 00076 } 00077 00078 VOID TuiDrawBackdrop(VOID) 00079 { 00080 // 00081 // Fill in the background (excluding title box & status bar) 00082 // 00083 TuiFillArea(0, 00084 TUI_TITLE_BOX_CHAR_HEIGHT, 00085 UiScreenWidth - 1, 00086 UiScreenHeight - 2, 00087 UiBackdropFillStyle, 00088 ATTR(UiBackdropFgColor, UiBackdropBgColor)); 00089 00090 // 00091 // Draw the title box 00092 // 00093 TuiDrawBox(0, 00094 0, 00095 UiScreenWidth - 1, 00096 TUI_TITLE_BOX_CHAR_HEIGHT - 1, 00097 D_VERT, 00098 D_HORZ, 00099 TRUE, 00100 FALSE, 00101 ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); 00102 00103 // 00104 // Draw version text 00105 // 00106 TuiDrawText(2, 00107 1, 00108 GetFreeLoaderVersionString(), 00109 ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); 00110 00111 // 00112 // Draw copyright 00113 // 00114 TuiDrawText(2, 00115 2, 00116 BY_AUTHOR, 00117 ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); 00118 TuiDrawText(2, 00119 3, 00120 AUTHOR_EMAIL, 00121 ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); 00122 00123 // 00124 // Draw help text 00125 // 00126 TuiDrawText(UiScreenWidth - 16, 3, /*"F1 for Help"*/"F8 for Options", ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); 00127 00128 // 00129 // Draw title text 00130 // 00131 TuiDrawText( (UiScreenWidth / 2) - ((ULONG)strlen(UiTitleBoxTitleText) / 2), 00132 2, 00133 UiTitleBoxTitleText, 00134 ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); 00135 00136 // 00137 // Draw status bar 00138 // 00139 TuiDrawStatusText("Welcome to FreeLoader!"); 00140 00141 // 00142 // Update the date & time 00143 // 00144 TuiUpdateDateTime(); 00145 00146 VideoCopyOffScreenBufferToVRAM(); 00147 } 00148 00149 /* 00150 * FillArea() 00151 * This function assumes coordinates are zero-based 00152 */ 00153 VOID TuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */) 00154 { 00155 PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer; 00156 ULONG i, j; 00157 00158 // Clip the area to the screen 00159 if ((Left >= UiScreenWidth) || (Top >= UiScreenHeight)) 00160 { 00161 return; 00162 } 00163 if (Right >= UiScreenWidth) 00164 { 00165 Right = UiScreenWidth - 1; 00166 } 00167 if (Bottom >= UiScreenHeight) 00168 { 00169 Bottom = UiScreenHeight - 1; 00170 } 00171 00172 // Loop through each line and fill it in 00173 for (i=Top; i<=Bottom; i++) 00174 { 00175 // Loop through each character (column) in the line and fill it in 00176 for (j=Left; j<=Right; j++) 00177 { 00178 ScreenMemory[((i*2)*UiScreenWidth)+(j*2)] = (UCHAR)FillChar; 00179 ScreenMemory[((i*2)*UiScreenWidth)+(j*2)+1] = Attr; 00180 } 00181 } 00182 } 00183 00184 /* 00185 * DrawShadow() 00186 * This function assumes coordinates are zero-based 00187 */ 00188 VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom) 00189 { 00190 PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer; 00191 ULONG Idx; 00192 00193 // Shade the bottom of the area 00194 if (Bottom < (UiScreenHeight - 1)) 00195 { 00196 if (UiScreenHeight < 34) 00197 { 00198 Idx=Left + 2; 00199 } 00200 else 00201 { 00202 Idx=Left + 1; 00203 } 00204 00205 for (; Idx<=Right; Idx++) 00206 { 00207 ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+(Idx*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK); 00208 } 00209 } 00210 00211 // Shade the right of the area 00212 if (Right < (UiScreenWidth - 1)) 00213 { 00214 for (Idx=Top+1; Idx<=Bottom; Idx++) 00215 { 00216 ScreenMemory[((Idx*2)*UiScreenWidth)+((Right+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK); 00217 } 00218 } 00219 if (UiScreenHeight < 34) 00220 { 00221 if ((Right + 1) < (UiScreenWidth - 1)) 00222 { 00223 for (Idx=Top+1; Idx<=Bottom; Idx++) 00224 { 00225 ScreenMemory[((Idx*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK); 00226 } 00227 } 00228 } 00229 00230 // Shade the bottom right corner 00231 if ((Right < (UiScreenWidth - 1)) && (Bottom < (UiScreenHeight - 1))) 00232 { 00233 ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+((Right+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK); 00234 } 00235 if (UiScreenHeight < 34) 00236 { 00237 if (((Right + 1) < (UiScreenWidth - 1)) && (Bottom < (UiScreenHeight - 1))) 00238 { 00239 ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK); 00240 } 00241 } 00242 } 00243 00244 /* 00245 * DrawBox() 00246 * This function assumes coordinates are zero-based 00247 */ 00248 VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr) 00249 { 00250 UCHAR ULCorner, URCorner, LLCorner, LRCorner; 00251 00252 // Calculate the corner values 00253 if (HorzStyle == HORZ) 00254 { 00255 if (VertStyle == VERT) 00256 { 00257 ULCorner = UL; 00258 URCorner = UR; 00259 LLCorner = LL; 00260 LRCorner = LR; 00261 } 00262 else // VertStyle == D_VERT 00263 { 00264 ULCorner = VD_UL; 00265 URCorner = VD_UR; 00266 LLCorner = VD_LL; 00267 LRCorner = VD_LR; 00268 } 00269 } 00270 else // HorzStyle == D_HORZ 00271 { 00272 if (VertStyle == VERT) 00273 { 00274 ULCorner = HD_UL; 00275 URCorner = HD_UR; 00276 LLCorner = HD_LL; 00277 LRCorner = HD_LR; 00278 } 00279 else // VertStyle == D_VERT 00280 { 00281 ULCorner = D_UL; 00282 URCorner = D_UR; 00283 LLCorner = D_LL; 00284 LRCorner = D_LR; 00285 } 00286 } 00287 00288 // Fill in box background 00289 if (Fill) 00290 { 00291 TuiFillArea(Left, Top, Right, Bottom, ' ', Attr); 00292 } 00293 00294 // Fill in corners 00295 TuiFillArea(Left, Top, Left, Top, ULCorner, Attr); 00296 TuiFillArea(Right, Top, Right, Top, URCorner, Attr); 00297 TuiFillArea(Left, Bottom, Left, Bottom, LLCorner, Attr); 00298 TuiFillArea(Right, Bottom, Right, Bottom, LRCorner, Attr); 00299 00300 // Fill in left line 00301 TuiFillArea(Left, Top+1, Left, Bottom-1, VertStyle, Attr); 00302 // Fill in top line 00303 TuiFillArea(Left+1, Top, Right-1, Top, HorzStyle, Attr); 00304 // Fill in right line 00305 TuiFillArea(Right, Top+1, Right, Bottom-1, VertStyle, Attr); 00306 // Fill in bottom line 00307 TuiFillArea(Left+1, Bottom, Right-1, Bottom, HorzStyle, Attr); 00308 00309 // Draw the shadow 00310 if (Shadow) 00311 { 00312 TuiDrawShadow(Left, Top, Right, Bottom); 00313 } 00314 } 00315 00316 /* 00317 * DrawText() 00318 * This function assumes coordinates are zero-based 00319 */ 00320 VOID TuiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr) 00321 { 00322 PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer; 00323 ULONG i, j; 00324 00325 // Draw the text 00326 for (i=X, j=0; Text[j] && i<UiScreenWidth; i++,j++) 00327 { 00328 ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)] = (UCHAR)Text[j]; 00329 ScreenMemory[((Y*2)*UiScreenWidth)+(i*2)+1] = Attr; 00330 } 00331 } 00332 00333 VOID TuiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr) 00334 { 00335 SIZE_T TextLength; 00336 ULONG BoxWidth; 00337 ULONG BoxHeight; 00338 ULONG LineBreakCount; 00339 SIZE_T Index; 00340 SIZE_T LastIndex; 00341 ULONG RealLeft; 00342 ULONG RealTop; 00343 ULONG X; 00344 ULONG Y; 00345 CHAR Temp[2]; 00346 00347 TextLength = strlen(TextString); 00348 00349 // Count the new lines and the box width 00350 LineBreakCount = 0; 00351 BoxWidth = 0; 00352 LastIndex = 0; 00353 for (Index=0; Index<TextLength; Index++) 00354 { 00355 if (TextString[Index] == '\n') 00356 { 00357 LastIndex = Index; 00358 LineBreakCount++; 00359 } 00360 else 00361 { 00362 if ((Index - LastIndex) > BoxWidth) 00363 { 00364 BoxWidth = (ULONG)(Index - LastIndex); 00365 } 00366 } 00367 } 00368 00369 BoxHeight = LineBreakCount + 1; 00370 00371 RealLeft = (((Right - Left) - BoxWidth) / 2) + Left; 00372 RealTop = (((Bottom - Top) - BoxHeight) / 2) + Top; 00373 00374 LastIndex = 0; 00375 for (Index=0; Index<TextLength; Index++) 00376 { 00377 if (TextString[Index] == '\n') 00378 { 00379 RealTop++; 00380 LastIndex = 0; 00381 } 00382 else 00383 { 00384 X = (ULONG)(RealLeft + LastIndex); 00385 Y = RealTop; 00386 LastIndex++; 00387 Temp[0] = TextString[Index]; 00388 Temp[1] = 0; 00389 TuiDrawText(X, Y, Temp, Attr); 00390 } 00391 } 00392 } 00393 00394 VOID TuiDrawStatusText(PCSTR StatusText) 00395 { 00396 SIZE_T i; 00397 00398 TuiDrawText(0, UiScreenHeight-1, " ", ATTR(UiStatusBarFgColor, UiStatusBarBgColor)); 00399 TuiDrawText(1, UiScreenHeight-1, StatusText, ATTR(UiStatusBarFgColor, UiStatusBarBgColor)); 00400 00401 for (i=strlen(StatusText)+1; i<UiScreenWidth; i++) 00402 { 00403 TuiDrawText((ULONG)i, UiScreenHeight-1, " ", ATTR(UiStatusBarFgColor, UiStatusBarBgColor)); 00404 } 00405 00406 VideoCopyOffScreenBufferToVRAM(); 00407 } 00408 00409 VOID TuiUpdateDateTime(VOID) 00410 { 00411 TIMEINFO* TimeInfo; 00412 char DateString[40]; 00413 CHAR TimeString[40]; 00414 CHAR TempString[20]; 00415 BOOLEAN PMHour = FALSE; 00416 00417 /* Don't draw the time if this has been disabled */ 00418 if (!UiDrawTime) return; 00419 00420 TimeInfo = ArcGetTime(); 00421 if (TimeInfo->Year < 1 || 9999 < TimeInfo->Year || 00422 TimeInfo->Month < 1 || 12 < TimeInfo->Month || 00423 TimeInfo->Day < 1 || 31 < TimeInfo->Day || 00424 23 < TimeInfo->Hour || 00425 59 < TimeInfo->Minute || 00426 59 < TimeInfo->Second) 00427 { 00428 /* This happens on QEmu sometimes. We just skip updating */ 00429 return; 00430 } 00431 // Get the month name 00432 strcpy(DateString, UiMonthNames[TimeInfo->Month - 1]); 00433 // Get the day 00434 _itoa(TimeInfo->Day, TempString, 10); 00435 // Get the day postfix 00436 if (1 == TimeInfo->Day || 21 == TimeInfo->Day || 31 == TimeInfo->Day) 00437 { 00438 strcat(TempString, "st"); 00439 } 00440 else if (2 == TimeInfo->Day || 22 == TimeInfo->Day) 00441 { 00442 strcat(TempString, "nd"); 00443 } 00444 else if (3 == TimeInfo->Day || 23 == TimeInfo->Day) 00445 { 00446 strcat(TempString, "rd"); 00447 } 00448 else 00449 { 00450 strcat(TempString, "th"); 00451 } 00452 00453 // Add the day to the date 00454 strcat(DateString, TempString); 00455 strcat(DateString, " "); 00456 00457 // Get the year and add it to the date 00458 _itoa(TimeInfo->Year, TempString, 10); 00459 strcat(DateString, TempString); 00460 00461 // Draw the date 00462 TuiDrawText(UiScreenWidth-(ULONG)strlen(DateString)-2, 1, DateString, ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); 00463 00464 // Get the hour and change from 24-hour mode to 12-hour 00465 if (TimeInfo->Hour > 12) 00466 { 00467 TimeInfo->Hour -= 12; 00468 PMHour = TRUE; 00469 } 00470 if (TimeInfo->Hour == 0) 00471 { 00472 TimeInfo->Hour = 12; 00473 } 00474 _itoa(TimeInfo->Hour, TempString, 10); 00475 strcpy(TimeString, " "); 00476 strcat(TimeString, TempString); 00477 strcat(TimeString, ":"); 00478 _itoa(TimeInfo->Minute, TempString, 10); 00479 if (TimeInfo->Minute < 10) 00480 { 00481 strcat(TimeString, "0"); 00482 } 00483 strcat(TimeString, TempString); 00484 strcat(TimeString, ":"); 00485 _itoa(TimeInfo->Second, TempString, 10); 00486 if (TimeInfo->Second < 10) 00487 { 00488 strcat(TimeString, "0"); 00489 } 00490 strcat(TimeString, TempString); 00491 if (PMHour) 00492 { 00493 strcat(TimeString, " PM"); 00494 } 00495 else 00496 { 00497 strcat(TimeString, " AM"); 00498 } 00499 00500 // Draw the time 00501 TuiDrawText(UiScreenWidth-(ULONG)strlen(TimeString)-2, 2, TimeString, ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); 00502 } 00503 00504 VOID TuiSaveScreen(PUCHAR Buffer) 00505 { 00506 PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer; 00507 ULONG i; 00508 00509 for (i=0; i < (UiScreenWidth * UiScreenHeight * 2); i++) 00510 { 00511 Buffer[i] = ScreenMemory[i]; 00512 } 00513 } 00514 00515 VOID TuiRestoreScreen(PUCHAR Buffer) 00516 { 00517 PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer; 00518 ULONG i; 00519 00520 for (i=0; i < (UiScreenWidth * UiScreenHeight * 2); i++) 00521 { 00522 ScreenMemory[i] = Buffer[i]; 00523 } 00524 } 00525 00526 VOID TuiMessageBox(PCSTR MessageText) 00527 { 00528 PVOID ScreenBuffer; 00529 00530 // Save the screen contents 00531 ScreenBuffer = MmHeapAlloc(UiScreenWidth * UiScreenHeight * 2); 00532 TuiSaveScreen(ScreenBuffer); 00533 00534 // Display the message box 00535 TuiMessageBoxCritical(MessageText); 00536 00537 // Restore the screen contents 00538 TuiRestoreScreen(ScreenBuffer); 00539 MmHeapFree(ScreenBuffer); 00540 } 00541 00542 VOID TuiMessageBoxCritical(PCSTR MessageText) 00543 { 00544 int width = 8; 00545 unsigned int height = 1; 00546 int curline = 0; 00547 int k; 00548 size_t i , j; 00549 int x1, x2, y1, y2; 00550 char temp[260]; 00551 char key; 00552 00553 // Find the height 00554 for (i=0; i<strlen(MessageText); i++) 00555 { 00556 if (MessageText[i] == '\n') 00557 height++; 00558 } 00559 00560 // Find the width 00561 for (i=0,j=0,k=0; i<height; i++) 00562 { 00563 while ((MessageText[j] != '\n') && (MessageText[j] != 0)) 00564 { 00565 j++; 00566 k++; 00567 } 00568 00569 if (k > width) 00570 width = k; 00571 00572 k = 0; 00573 j++; 00574 } 00575 00576 // Calculate box area 00577 x1 = (UiScreenWidth - (width+2))/2; 00578 x2 = x1 + width + 3; 00579 y1 = ((UiScreenHeight - height - 2)/2) + 1; 00580 y2 = y1 + height + 4; 00581 00582 // Draw the box 00583 TuiDrawBox(x1, y1, x2, y2, D_VERT, D_HORZ, TRUE, TRUE, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor)); 00584 00585 // Draw the text 00586 for (i=0,j=0; i<strlen(MessageText)+1; i++) 00587 { 00588 if ((MessageText[i] == '\n') || (MessageText[i] == 0)) 00589 { 00590 temp[j] = 0; 00591 j = 0; 00592 UiDrawText(x1+2, y1+1+curline, temp, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor)); 00593 curline++; 00594 } 00595 else 00596 temp[j++] = MessageText[i]; 00597 } 00598 00599 // Draw OK button 00600 strcpy(temp, " OK "); 00601 UiDrawText(x1+((x2-x1)/2)-3, y2-2, temp, ATTR(COLOR_BLACK, COLOR_GRAY)); 00602 00603 // Draw status text 00604 UiDrawStatusText("Press ENTER to continue"); 00605 00606 VideoCopyOffScreenBufferToVRAM(); 00607 00608 for (;;) 00609 { 00610 if (MachConsKbHit()) 00611 { 00612 key = MachConsGetCh(); 00613 if(key == KEY_EXTENDED) 00614 key = MachConsGetCh(); 00615 00616 if(key == KEY_ENTER) 00617 break; 00618 else if(key == KEY_SPACE) 00619 break; 00620 else if(key == KEY_ESC) 00621 break; 00622 } 00623 00624 TuiUpdateDateTime(); 00625 00626 VideoCopyOffScreenBufferToVRAM(); 00627 00628 MachHwIdle(); 00629 } 00630 00631 } 00632 00633 00634 VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText) 00635 { 00636 ULONG Left, Top, Right, Bottom; 00637 ULONG Width = 50; // Allow for 50 "bars" 00638 ULONG Height = 2; 00639 00640 Left = (UiScreenWidth - Width - 4) / 2; 00641 Right = Left + Width + 3; 00642 Top = (UiScreenHeight - Height - 2) / 2; 00643 Top += 2; 00644 Bottom = Top + Height + 1; 00645 00646 TuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText); 00647 } 00648 00649 VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText) 00650 { 00651 ULONG i; 00652 ULONG ProgressBarWidth = (Right - Left) - 3; 00653 00654 // First make sure the progress bar text fits 00655 UiTruncateStringEllipsis(ProgressText, ProgressBarWidth - 4); 00656 00657 if (Position > Range) 00658 { 00659 Position = Range; 00660 } 00661 00662 // Draw the box 00663 TuiDrawBox(Left, Top, Right, Bottom, VERT, HORZ, TRUE, TRUE, ATTR(UiMenuFgColor, UiMenuBgColor)); 00664 00665 // 00666 // Draw the "Loading..." text 00667 // 00668 TuiDrawCenteredText(Left + 2, Top + 2, Right - 2, Top + 2, ProgressText, ATTR(UiTextColor, UiMenuBgColor)); 00669 00670 // Draw the percent complete 00671 for (i=0; i<(Position*ProgressBarWidth)/Range; i++) 00672 { 00673 TuiDrawText(Left+2+i, Top+2, "\xDB", ATTR(UiTextColor, UiMenuBgColor)); 00674 } 00675 00676 // Draw the shadow 00677 for (; i<ProgressBarWidth; i++) 00678 { 00679 TuiDrawText(Left+2+i, Top+2, "\xB2", ATTR(UiTextColor, UiMenuBgColor)); 00680 } 00681 00682 TuiUpdateDateTime(); 00683 VideoCopyOffScreenBufferToVRAM(); 00684 } 00685 00686 UCHAR TuiTextToColor(PCSTR ColorText) 00687 { 00688 if (_stricmp(ColorText, "Black") == 0) 00689 return COLOR_BLACK; 00690 else if (_stricmp(ColorText, "Blue") == 0) 00691 return COLOR_BLUE; 00692 else if (_stricmp(ColorText, "Green") == 0) 00693 return COLOR_GREEN; 00694 else if (_stricmp(ColorText, "Cyan") == 0) 00695 return COLOR_CYAN; 00696 else if (_stricmp(ColorText, "Red") == 0) 00697 return COLOR_RED; 00698 else if (_stricmp(ColorText, "Magenta") == 0) 00699 return COLOR_MAGENTA; 00700 else if (_stricmp(ColorText, "Brown") == 0) 00701 return COLOR_BROWN; 00702 else if (_stricmp(ColorText, "Gray") == 0) 00703 return COLOR_GRAY; 00704 else if (_stricmp(ColorText, "DarkGray") == 0) 00705 return COLOR_DARKGRAY; 00706 else if (_stricmp(ColorText, "LightBlue") == 0) 00707 return COLOR_LIGHTBLUE; 00708 else if (_stricmp(ColorText, "LightGreen") == 0) 00709 return COLOR_LIGHTGREEN; 00710 else if (_stricmp(ColorText, "LightCyan") == 0) 00711 return COLOR_LIGHTCYAN; 00712 else if (_stricmp(ColorText, "LightRed") == 0) 00713 return COLOR_LIGHTRED; 00714 else if (_stricmp(ColorText, "LightMagenta") == 0) 00715 return COLOR_LIGHTMAGENTA; 00716 else if (_stricmp(ColorText, "Yellow") == 0) 00717 return COLOR_YELLOW; 00718 else if (_stricmp(ColorText, "White") == 0) 00719 return COLOR_WHITE; 00720 00721 return COLOR_BLACK; 00722 } 00723 00724 UCHAR TuiTextToFillStyle(PCSTR FillStyleText) 00725 { 00726 if (_stricmp(FillStyleText, "Light") == 0) 00727 { 00728 return LIGHT_FILL; 00729 } 00730 else if (_stricmp(FillStyleText, "Medium") == 0) 00731 { 00732 return MEDIUM_FILL; 00733 } 00734 else if (_stricmp(FillStyleText, "Dark") == 0) 00735 { 00736 return DARK_FILL; 00737 } 00738 00739 return LIGHT_FILL; 00740 } 00741 00742 VOID TuiFadeInBackdrop(VOID) 00743 { 00744 PPALETTE_ENTRY TuiFadePalette = NULL; 00745 00746 if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed()) 00747 { 00748 TuiFadePalette = (PPALETTE_ENTRY)MmHeapAlloc(sizeof(PALETTE_ENTRY) * 64); 00749 00750 if (TuiFadePalette != NULL) 00751 { 00752 VideoSavePaletteState(TuiFadePalette, 64); 00753 VideoSetAllColorsToBlack(64); 00754 } 00755 } 00756 00757 // Draw the backdrop and title box 00758 TuiDrawBackdrop(); 00759 00760 if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL) 00761 { 00762 VideoFadeIn(TuiFadePalette, 64); 00763 MmHeapFree(TuiFadePalette); 00764 } 00765 } 00766 00767 VOID TuiFadeOut(VOID) 00768 { 00769 PPALETTE_ENTRY TuiFadePalette = NULL; 00770 00771 if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed()) 00772 { 00773 TuiFadePalette = (PPALETTE_ENTRY)MmHeapAlloc(sizeof(PALETTE_ENTRY) * 64); 00774 00775 if (TuiFadePalette != NULL) 00776 { 00777 VideoSavePaletteState(TuiFadePalette, 64); 00778 } 00779 } 00780 00781 if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL) 00782 { 00783 VideoFadeOut(64); 00784 } 00785 00786 MachVideoSetDisplayMode(NULL, FALSE); 00787 00788 if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL) 00789 { 00790 VideoRestorePaletteState(TuiFadePalette, 64); 00791 MmHeapFree(TuiFadePalette); 00792 } 00793 00794 } 00795 00796 BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length) 00797 { 00798 int width = 8; 00799 unsigned int height = 1; 00800 int curline = 0; 00801 int k; 00802 size_t i , j; 00803 int x1, x2, y1, y2; 00804 char temp[260]; 00805 char key; 00806 int EditBoxLine; 00807 ULONG EditBoxStartX, EditBoxEndX; 00808 int EditBoxCursorX; 00809 unsigned int EditBoxTextCount; 00810 int EditBoxTextDisplayIndex; 00811 BOOLEAN ReturnCode; 00812 PVOID ScreenBuffer; 00813 00814 // Save the screen contents 00815 ScreenBuffer = MmHeapAlloc(UiScreenWidth * UiScreenHeight * 2); 00816 TuiSaveScreen(ScreenBuffer); 00817 00818 // Find the height 00819 for (i=0; i<strlen(MessageText); i++) 00820 { 00821 if (MessageText[i] == '\n') 00822 height++; 00823 } 00824 00825 // Find the width 00826 for (i=0,j=0,k=0; i<height; i++) 00827 { 00828 while ((MessageText[j] != '\n') && (MessageText[j] != 0)) 00829 { 00830 j++; 00831 k++; 00832 } 00833 00834 if (k > width) 00835 width = k; 00836 00837 k = 0; 00838 j++; 00839 } 00840 00841 // Calculate box area 00842 x1 = (UiScreenWidth - (width+2))/2; 00843 x2 = x1 + width + 3; 00844 y1 = ((UiScreenHeight - height - 2)/2) + 1; 00845 y2 = y1 + height + 4; 00846 00847 // Draw the box 00848 TuiDrawBox(x1, y1, x2, y2, D_VERT, D_HORZ, TRUE, TRUE, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor)); 00849 00850 // Draw the text 00851 for (i=0,j=0; i<strlen(MessageText)+1; i++) 00852 { 00853 if ((MessageText[i] == '\n') || (MessageText[i] == 0)) 00854 { 00855 temp[j] = 0; 00856 j = 0; 00857 UiDrawText(x1+2, y1+1+curline, temp, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor)); 00858 curline++; 00859 } 00860 else 00861 temp[j++] = MessageText[i]; 00862 } 00863 00864 EditBoxTextCount = 0; 00865 EditBoxLine = y2 - 2; 00866 EditBoxStartX = x1 + 3; 00867 EditBoxEndX = x2 - 3; 00868 UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor)); 00869 00870 // Show the cursor 00871 EditBoxCursorX = EditBoxStartX; 00872 MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine); 00873 MachVideoHideShowTextCursor(TRUE); 00874 00875 // Draw status text 00876 UiDrawStatusText("Press ENTER to continue, or ESC to cancel"); 00877 00878 VideoCopyOffScreenBufferToVRAM(); 00879 00880 for (;;) 00881 { 00882 if (MachConsKbHit()) 00883 { 00884 key = MachConsGetCh(); 00885 if(key == KEY_EXTENDED) 00886 { 00887 key = MachConsGetCh(); 00888 } 00889 00890 if(key == KEY_ENTER) 00891 { 00892 ReturnCode = TRUE; 00893 break; 00894 } 00895 else if(key == KEY_ESC) 00896 { 00897 ReturnCode = FALSE; 00898 break; 00899 } 00900 else if (key == KEY_BACKSPACE) // Remove a character 00901 { 00902 if (EditBoxTextCount) 00903 { 00904 EditBoxTextCount--; 00905 EditTextBuffer[EditBoxTextCount] = 0; 00906 } 00907 else 00908 { 00909 MachBeep(); 00910 } 00911 } 00912 else // Add this key to the buffer 00913 { 00914 if (EditBoxTextCount < Length - 1) 00915 { 00916 EditTextBuffer[EditBoxTextCount] = key; 00917 EditBoxTextCount++; 00918 EditTextBuffer[EditBoxTextCount] = 0; 00919 } 00920 else 00921 { 00922 MachBeep(); 00923 } 00924 } 00925 } 00926 00927 // Draw the edit box background 00928 UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor)); 00929 00930 // Fill the text in 00931 if (EditBoxTextCount > (EditBoxEndX - EditBoxStartX)) 00932 { 00933 EditBoxTextDisplayIndex = EditBoxTextCount - (EditBoxEndX - EditBoxStartX); 00934 EditBoxCursorX = EditBoxEndX; 00935 } 00936 else 00937 { 00938 EditBoxTextDisplayIndex = 0; 00939 EditBoxCursorX = EditBoxStartX + EditBoxTextCount; 00940 } 00941 UiDrawText(EditBoxStartX, EditBoxLine, &EditTextBuffer[EditBoxTextDisplayIndex], ATTR(UiEditBoxTextColor, UiEditBoxBgColor)); 00942 00943 // Move the cursor 00944 MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine); 00945 00946 TuiUpdateDateTime(); 00947 00948 VideoCopyOffScreenBufferToVRAM(); 00949 00950 MachHwIdle(); 00951 } 00952 00953 // Hide the cursor again 00954 MachVideoHideShowTextCursor(FALSE); 00955 00956 // Restore the screen contents 00957 TuiRestoreScreen(ScreenBuffer); 00958 MmHeapFree(ScreenBuffer); 00959 00960 return ReturnCode; 00961 } 00962 00963 const UIVTBL TuiVtbl = 00964 { 00965 TuiInitialize, 00966 TuiUnInitialize, 00967 TuiDrawBackdrop, 00968 TuiFillArea, 00969 TuiDrawShadow, 00970 TuiDrawBox, 00971 TuiDrawText, 00972 TuiDrawCenteredText, 00973 TuiDrawStatusText, 00974 TuiUpdateDateTime, 00975 TuiMessageBox, 00976 TuiMessageBoxCritical, 00977 TuiDrawProgressBarCenter, 00978 TuiDrawProgressBar, 00979 TuiEditBox, 00980 TuiTextToColor, 00981 TuiTextToFillStyle, 00982 TuiFadeInBackdrop, 00983 TuiFadeOut, 00984 TuiDisplayMenu, 00985 TuiDrawMenu, 00986 }; 00987 #endif Generated on Sun May 27 2012 04:19:18 for ReactOS by
1.7.6.1
|