Skip to content

Commit 2443779

Browse files
author
tthomps
committed
Add MessageBoxf() GUI function to display a message with formatted text.
Make a little more sense of files which rely on SDL_picofont.h vs picofont.h - These files and their slightly-different functions should be modified and merged in the future.
1 parent 541041f commit 2443779

File tree

11 files changed

+36
-38
lines changed

11 files changed

+36
-38
lines changed

MyOS_1/Graphics/Display_HAL.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "Display_HAL.h"
22
#include "../Drivers/Bochs_VGA.h"
3-
#include "picofont.h"
43
#include "../multiboot.h"
54
#include "../misc.h"
65
#include "Graphical_Terminal.h"

MyOS_1/Graphics/Graphical_Terminal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "../Terminal.h"
33
#include "../misc.h"
44
#include "../printf.h"
5+
#include "picofont.h"
56
#include "Bitmap.h"
67

78
// TODO: Support multiple graphical terminals

MyOS_1/Graphics/Graphical_Terminal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22
#include "Display_HAL.h"
3-
#include "picofont.h"
43

54
// TODO: Support higher resolutions
65
#define MAX_X_RES 800

MyOS_GUI_Shell/GUI_TerminalWindow.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ extern "C" {
99
#endif
1010

1111
#include <string.h>
12-
#include "../MyOS_1/Graphics/picofont.h"
1312

1413
GUI_TerminalWindow::GUI_TerminalWindow(const char *name)
1514
: GUI_Window(NewWindowPosition(GUI_TERMINAL_DEFAULT_WIDTH, GUI_TERMINAL_DEFAULT_HEIGHT), name)

MyOS_GUI_Shell/GUI_TerminalWindow.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,12 @@ extern "C" {
66

77
#include "GUI_Window.h"
88
#include "MyOS_GUI_Shell.h"
9-
#include "../MyOS_1/Graphics/picofont.h"
109

1110
#define GUI_TERMINAL_DEFAULT_BUFFER_SIZE 4096
1211
#define GUI_TERMINAL_DEFAULT_TEXT_COLOR {255, 255, 255, 255}
1312
#define GUI_TERMINAL_DEFAULT_BG_COLOR {40, 40, 40, 255}
1413

1514

16-
#ifndef FNT_FONTHEIGHT
17-
#define FNT_FONTHEIGHT 8
18-
#endif
19-
#ifndef FNT_FONTWIDTH
20-
#define FNT_FONTWIDTH 8
21-
#endif
22-
#ifndef FNT_ROWSPACING
23-
#define FNT_ROWSPACING 3
24-
#endif
25-
26-
#ifndef FNT_xy
27-
typedef struct
28-
{
29-
int x;
30-
int y;
31-
}FNT_xy;
32-
#endif
33-
34-
// put some margins around the borders
35-
#ifndef FNT_LEFTRIGHTMARGIN
36-
#define FNT_LEFTRIGHTMARGIN 3
37-
#define FNT_TOPBOTTOMMARGIN 3
38-
#endif
39-
4015
#define GUI_TERMINAL_DEFAULT_COLUMNS 80
4116
#define GUI_TERMINAL_DEFAULT_ROWS 60
4217
#define GUI_TERMINAL_DEFAULT_WIDTH ((GUI_TERMINAL_DEFAULT_COLUMNS + 1) * FNT_FONTWIDTH)
@@ -55,7 +30,7 @@ class GUI_TerminalWindow :
5530
void PutChar(char c);
5631
void PutEntryAt(char c, size_t x, size_t y);
5732

58-
// Font functions from picofont by
33+
// Font functions from picofont by Fredrik Hultin
5934
FNT_xy FNT_Generate(const char* text, unsigned int len, unsigned int w, uint32_t *pixels, FNT_xy position);
6035
void FNT_Render(const char* text, FNT_xy position);
6136
void FNT_RenderMax(const char* text, unsigned int len, FNT_xy position);

MyOS_GUI_Shell/GUI_Window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "GUI_Object.h"
33
#include "GUI_Rect.h"
44
#include "GUI_Control.h"
5+
#include "SDL_picofont.h"
56

67
#define MAX_WINDOW_NAME_LENGTH 64
78
#define SYSTEM_MENU_CLOSE_BUTTON_ID (uint32_t)-1

MyOS_GUI_Shell/MyOS_GUI_Shell.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extern "C" {
99
#ifndef WIN32
1010
#include "../MyOS_1/Console_VGA.h"
1111
#include "../MyOS_1/Interrupts/System_Calls.h"
12+
#include "../MyOS_1/printf.h"
1213
//#undef _MSVC_VER
1314
#undef _WIN32
1415
//#define HAVE_LIBC 0
@@ -322,6 +323,30 @@ void MessageBox(char *messageText, char *windowTitle)
322323
__halt();
323324
}
324325

326+
// Display MessageBox with printf-like ability
327+
// TODO: don't require any memory allocation so we can show out-of-memory errors
328+
void MessageBoxf(char *windowTitle, char *messageFormat, ...)
329+
{
330+
for (int i = 0; i < MAX_GUI_WINDOWS; ++i)
331+
{
332+
if (!windowList[i])
333+
{
334+
char buffer[128] = { 0 };
335+
va_list va;
336+
va_start(va, messageFormat);
337+
const int ret = vsnprintf(buffer, 128, messageFormat, va);
338+
va_end(va);
339+
340+
windowList[i] = new GUI_MessageBox(buffer, windowTitle);
341+
AddWindowToStack(windowList[i], &windowStack[i]);
342+
return;
343+
}
344+
}
345+
printf("No free spot for window\n");
346+
for (;;)
347+
__halt();
348+
}
349+
325350
// Called by windows when they want to be destroyed
326351
void Shell_Destroy_Window(GUI_Window *pWindow)
327352
{
@@ -531,6 +556,7 @@ int main(int argc, char* argv[])
531556
done = true;
532557
break;
533558
default:
559+
MessageBoxf("Key pressed", "Scan code: 0x%X - %c", event.key.keysym.scancode, event.key.keysym.sym);
534560
if (pStackTop)
535561
pStackTop->pWindow->SendChar(event.key.keysym.sym);
536562
break;

MyOS_GUI_Shell/MyOS_GUI_Shell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ GUI_Window *CreateTextWindow(uint32_t uniqueID, const char *windowName);
2222
GUI_Window *GetWindowFromID(uint32_t uniqueID);
2323
GUI_Rect NewWindowPosition(int x, int y);
2424
void MessageBox(char *messageText, char *windowTitle);
25+
void MessageBoxf(char *windowTitle, char *messageFormat, ...);
2526
void Shell_Destroy_Window(GUI_Window *pWindow);
2627

2728

MyOS_GUI_Shell/SDL_picofont.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ extern "C" {
3333
#define FNT_LEFTRIGHTMARGIN 3
3434
#define FNT_TOPBOTTOMMARGIN 3
3535

36+
typedef struct
37+
{
38+
int x;
39+
int y;
40+
}FNT_xy;
41+
3642
SDL_Surface* FNT_Render(const char* text, SDL_Color color);
3743
SDL_Surface* FNT_RenderMax(const char* text, unsigned int len, SDL_Color color);
3844

MyOS_GUI_Shell/spf.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ extern "C" {
1818

1919
//#include <string.h>
2020

21-
#define FNT_FONTHEIGHT 8
22-
#define FNT_FONTWIDTH 8
23-
24-
typedef struct
25-
{
26-
int x;
27-
int y;
28-
}FNT_xy;
29-
3021
FNT_xy FNT_Generate(const char* text, unsigned int len, unsigned int w, unsigned char* pixels)
3122
{
3223
unsigned int i, x, y, col, row, stop;

Release/MyOS_1.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)