3 * Copyright (C) 1999, 2000 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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 int nScreenWidth
= 80; // Screen Width
25 int nScreenHeight
= 25; // Screen Height
27 char cStatusBarFgColor
= COLOR_BLACK
; // Status bar foreground color
28 char cStatusBarBgColor
= COLOR_CYAN
; // Status bar background color
29 char cBackdropFgColor
= COLOR_WHITE
; // Backdrop foreground color
30 char cBackdropBgColor
= COLOR_BLUE
; // Backdrop background color
31 char cBackdropFillStyle
= MEDIUM_FILL
; // Backdrop fill style
32 char cTitleBoxFgColor
= COLOR_WHITE
; // Title box foreground color
33 char cTitleBoxBgColor
= COLOR_RED
; // Title box background color
34 char cMessageBoxFgColor
= COLOR_WHITE
; // Message box foreground color
35 char cMessageBoxBgColor
= COLOR_BLUE
; // Message box background color
36 char cMenuFgColor
= COLOR_WHITE
; // Menu foreground color
37 char cMenuBgColor
= COLOR_BLUE
; // Menu background color
38 char cTextColor
= COLOR_YELLOW
; // Normal text color
39 char cSelectedTextColor
= COLOR_BLACK
; // Selected text color
40 char cSelectedTextBgColor
= COLOR_GRAY
; // Selected text background color
41 char szTitleBoxTitleText
[260] = "Boot Menu"; // Title box's title text
43 char szMessageBoxLineText
[4000] = "";
45 void DrawBackdrop(void)
47 // Fill in the backdrop
48 FillArea(0, 0, nScreenWidth
-1, nScreenHeight
-1, cBackdropFillStyle
, ATTR(cBackdropFgColor
, cBackdropBgColor
));
51 DrawBox(1, 1, nScreenWidth
, 5, D_VERT
, D_HORZ
, TRUE
, FALSE
, ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
54 DrawText(3, 2, VERSION
, ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
56 DrawText(3, 3, "by Brian Palmer", ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
57 DrawText(3, 4, "<brianp@sginet.com>", ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
60 //DrawText(nScreenWidth-15, 4, /*"F1 for Help"*/"F8 for Options", ATTR(cTitleBoxFgColor, cTitleBoxBgColor));
63 DrawText((nScreenWidth
/2)-(strlen(szTitleBoxTitleText
)/2), 3, szTitleBoxTitleText
, ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
66 DrawText(nScreenWidth
-9, 2, "01/02/03", ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
68 DrawText(nScreenWidth
-9, 3, "10:12:34", ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
73 // Update the date & time
79 * This function assumes coordinates are zero-based
81 void FillArea(int nLeft
, int nTop
, int nRight
, int nBottom
, char cFillChar
, char cAttr
/* Color Attributes */)
83 char *screen
= (char *)SCREEN_MEM
;
86 for(i
=nTop
; i
<=nBottom
; i
++)
88 for(j
=nLeft
; j
<=nRight
; j
++)
90 screen
[((i
*2)*nScreenWidth
)+(j
*2)] = cFillChar
;
91 screen
[((i
*2)*nScreenWidth
)+(j
*2)+1] = cAttr
;
98 * This function assumes coordinates are zero-based
100 void DrawShadow(int nLeft
, int nTop
, int nRight
, int nBottom
)
102 char *screen
= (char *)SCREEN_MEM
;
105 // Shade the bottom of the area
106 if(nBottom
< (nScreenHeight
-1))
108 for(i
=nLeft
+2; i
<=nRight
; i
++)
109 screen
[(((nBottom
+1)*2)*nScreenWidth
)+(i
*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
112 // Shade the right of the area
113 if(nRight
< (nScreenWidth
-1))
115 for(i
=nTop
+1; i
<=nBottom
; i
++)
116 screen
[((i
*2)*nScreenWidth
)+((nRight
+1)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
118 if(nRight
+1 < (nScreenWidth
-1))
120 for(i
=nTop
+1; i
<=nBottom
; i
++)
121 screen
[((i
*2)*nScreenWidth
)+((nRight
+2)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
124 // Shade the bottom right corner
125 if((nRight
< (nScreenWidth
-1)) && (nBottom
< (nScreenHeight
-1)))
126 screen
[(((nBottom
+1)*2)*nScreenWidth
)+((nRight
+1)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
127 if((nRight
+1 < (nScreenWidth
-1)) && (nBottom
< (nScreenHeight
-1)))
128 screen
[(((nBottom
+1)*2)*nScreenWidth
)+((nRight
+2)*2)+1] = ATTR(COLOR_GRAY
, COLOR_BLACK
);
133 * This function assumes coordinates are one-based
135 void DrawBox(int nLeft
, int nTop
, int nRight
, int nBottom
, int nVertStyle
, int nHorzStyle
, int bFill
, int bShadow
, char cAttr
)
137 char cULCorner
, cURCorner
, cLLCorner
, cLRCorner
;
147 if(nHorzStyle
== HORZ
)
149 if(nVertStyle
== VERT
)
156 else // nVertStyle == D_VERT
164 else // nHorzStyle == D_HORZ
166 if(nVertStyle
== VERT
)
173 else // nVertStyle == D_VERT
182 // Fill in box background
184 FillArea(nLeft
, nTop
, nRight
, nBottom
, ' ', cAttr
);
187 FillArea(nLeft
, nTop
, nLeft
, nTop
, cULCorner
, cAttr
);
188 FillArea(nRight
, nTop
, nRight
, nTop
, cURCorner
, cAttr
);
189 FillArea(nLeft
, nBottom
, nLeft
, nBottom
, cLLCorner
, cAttr
);
190 FillArea(nRight
, nBottom
, nRight
, nBottom
, cLRCorner
, cAttr
);
193 FillArea(nLeft
, nTop
+1, nLeft
, nBottom
-1, cVert
, cAttr
);
195 FillArea(nLeft
+1, nTop
, nRight
-1, nTop
, cHorz
, cAttr
);
196 // Fill in right line
197 FillArea(nRight
, nTop
+1, nRight
, nBottom
-1, cVert
, cAttr
);
198 // Fill in bottom line
199 FillArea(nLeft
+1, nBottom
, nRight
-1, nBottom
, cHorz
, cAttr
);
202 DrawShadow(nLeft
, nTop
, nRight
, nBottom
);
207 * This function assumes coordinates are one-based
209 void DrawText(int nX
, int nY
, char *text
, char cAttr
)
211 char *screen
= (char *)SCREEN_MEM
;
218 for(i
=nX
, j
=0; text
[j
]; i
++,j
++)
220 screen
[((nY
*2)*nScreenWidth
)+(i
*2)] = text
[j
];
221 screen
[((nY
*2)*nScreenWidth
)+(i
*2)+1] = cAttr
;
225 void DrawStatusText(char *text
)
229 DrawText(1, nScreenHeight
, text
, ATTR(cStatusBarFgColor
, cStatusBarBgColor
));
231 for(i
=strlen(text
)+1; i
<=nScreenWidth
; i
++)
232 DrawText(i
, nScreenHeight
, " ", ATTR(cStatusBarFgColor
, cStatusBarBgColor
));
235 void UpdateDateTime(void)
240 int hour
, minute
, second
, bPM
=FALSE
;
245 strcpy(date
, "January ");
248 strcpy(date
, "February ");
251 strcpy(date
, "March ");
254 strcpy(date
, "April ");
257 strcpy(date
, "May ");
260 strcpy(date
, "June ");
263 strcpy(date
, "July ");
266 strcpy(date
, "August ");
269 strcpy(date
, "September ");
272 strcpy(date
, "October ");
275 strcpy(date
, "November ");
278 strcpy(date
, "December ");
281 itoa(getday(), temp
, 10);
282 if((getday() == 1) || (getday() == 21) || (getday() == 31))
284 else if((getday() == 2) || (getday() == 22))
286 else if((getday() == 3) || (getday() == 23))
293 itoa(getyear(), temp
, 10);
297 DrawText(nScreenWidth
-strlen(date
)-1, 2, date
, ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
307 minute
= getminute();
308 second
= getsecond();
309 itoa(hour
, temp
, 10);
313 itoa(minute
, temp
, 10);
318 itoa(second
, temp
, 10);
328 DrawText(nScreenWidth
-strlen(time
)-1, 3, time
, ATTR(cTitleBoxFgColor
, cTitleBoxBgColor
));
331 void SaveScreen(char *buffer
)
333 char *screen
= (char *)SCREEN_MEM
;
336 for(i
=0; i
< (nScreenWidth
* nScreenHeight
* 2); i
++)
337 buffer
[i
] = screen
[i
];
340 void RestoreScreen(char *buffer
)
342 char *screen
= (char *)SCREEN_MEM
;
345 for(i
=0; i
< (nScreenWidth
* nScreenHeight
* 2); i
++)
346 screen
[i
] = buffer
[i
];
349 void MessageBox(char *text
)
356 char savebuffer
[8000];
360 SaveScreen(savebuffer
);
361 strcat(szMessageBoxLineText
, text
);
364 for(i
=0; i
<strlen(szMessageBoxLineText
); i
++)
366 if(szMessageBoxLineText
[i
] == '\n')
371 for(i
=0,j
=0,k
=0; i
<height
; i
++)
373 while((szMessageBoxLineText
[j
] != '\n') && (szMessageBoxLineText
[j
] != 0))
386 // Calculate box area
387 x1
= (nScreenWidth
- (width
+2))/2;
389 y1
= ((nScreenHeight
- height
- 2)/2) + 1;
390 y2
= y1
+ height
+ 4;
393 DrawBox(x1
, y1
, x2
, y2
, D_VERT
, D_HORZ
, TRUE
, TRUE
, ATTR(cMessageBoxFgColor
, cMessageBoxBgColor
));
396 for(i
=0,j
=0; i
<strlen(szMessageBoxLineText
)+1; i
++)
398 if((szMessageBoxLineText
[i
] == '\n') || (szMessageBoxLineText
[i
] == 0))
402 DrawText(x1
+2, y1
+1+curline
, temp
, ATTR(cMessageBoxFgColor
, cMessageBoxBgColor
));
406 temp
[j
++] = szMessageBoxLineText
[i
];
410 strcpy(temp
, " OK ");
411 DrawText(x1
+((x2
-x1
)/2)-3, y2
-2, temp
, ATTR(COLOR_BLACK
, COLOR_GRAY
));
418 if(key
== KEY_EXTENDED
)
423 else if(key
== KEY_SPACE
)
430 RestoreScreen(savebuffer
);
432 strcpy(szMessageBoxLineText
, "");
435 void MessageLine(char *text
)
437 strcat(szMessageBoxLineText
, text
);
438 strcat(szMessageBoxLineText
, "\n");
441 BOOL
IsValidColor(char *color
)
443 if(stricmp(color
, "Black") == 0)
445 else if(stricmp(color
, "Blue") == 0)
447 else if(stricmp(color
, "Green") == 0)
449 else if(stricmp(color
, "Cyan") == 0)
451 else if(stricmp(color
, "Red") == 0)
453 else if(stricmp(color
, "Magenta") == 0)
455 else if(stricmp(color
, "Brown") == 0)
457 else if(stricmp(color
, "Gray") == 0)
459 else if(stricmp(color
, "DarkGray") == 0)
461 else if(stricmp(color
, "LightBlue") == 0)
463 else if(stricmp(color
, "LightGreen") == 0)
465 else if(stricmp(color
, "LightCyan") == 0)
467 else if(stricmp(color
, "LightRed") == 0)
469 else if(stricmp(color
, "LightMagenta") == 0)
471 else if(stricmp(color
, "Yellow") == 0)
473 else if(stricmp(color
, "White") == 0)
479 char TextToColor(char *color
)
481 if(stricmp(color
, "Black") == 0)
483 else if(stricmp(color
, "Blue") == 0)
485 else if(stricmp(color
, "Green") == 0)
487 else if(stricmp(color
, "Cyan") == 0)
489 else if(stricmp(color
, "Red") == 0)
491 else if(stricmp(color
, "Magenta") == 0)
492 return COLOR_MAGENTA
;
493 else if(stricmp(color
, "Brown") == 0)
495 else if(stricmp(color
, "Gray") == 0)
497 else if(stricmp(color
, "DarkGray") == 0)
498 return COLOR_DARKGRAY
;
499 else if(stricmp(color
, "LightBlue") == 0)
500 return COLOR_LIGHTBLUE
;
501 else if(stricmp(color
, "LightGreen") == 0)
502 return COLOR_LIGHTGREEN
;
503 else if(stricmp(color
, "LightCyan") == 0)
504 return COLOR_LIGHTCYAN
;
505 else if(stricmp(color
, "LightRed") == 0)
506 return COLOR_LIGHTRED
;
507 else if(stricmp(color
, "LightMagenta") == 0)
508 return COLOR_LIGHTMAGENTA
;
509 else if(stricmp(color
, "Yellow") == 0)
511 else if(stricmp(color
, "White") == 0)
517 BOOL
IsValidFillStyle(char *fill
)
519 if(stricmp(fill
, "Light") == 0)
521 else if(stricmp(fill
, "Medium") == 0)
523 else if(stricmp(fill
, "Dark") == 0)
529 char TextToFillStyle(char *fill
)
531 if(stricmp(fill
, "Light") == 0)
533 else if(stricmp(fill
, "Medium") == 0)
535 else if(stricmp(fill
, "Dark") == 0)
541 void DrawProgressBar(int nPos
)
543 int left
, top
, right
, bottom
;
544 int width
= 50; // Allow for 50 "bars"
551 left
= (nScreenWidth
- width
- 4) / 2;
552 right
= left
+ width
+ 3;
553 top
= (nScreenHeight
- height
- 2) / 2;
555 bottom
= top
+ height
+ 1;
558 DrawBox(left
, top
, right
, bottom
, VERT
, HORZ
, TRUE
, TRUE
, ATTR(cMenuFgColor
, cMenuBgColor
));
560 // Draw the "Loading..." text
561 DrawText(70/2, top
+1, "Loading...", ATTR(cTextColor
, cMenuBgColor
));
563 // Draw the percent complete
564 for(i
=0; i
<(nPos
/2); i
++)
565 DrawText(left
+2+i
, top
+2, "\xDB", ATTR(cTextColor
, cMenuBgColor
));
569 DrawText(left
+2+i
, top
+2, "\xB2", ATTR(cTextColor
, cMenuBgColor
));