Skip to content

Commit 3501164

Browse files
author
tthomps
committed
Include a message to send text to a windowed terminal application.
Update the printf_interrupt_handler() to send text to a windowed application if there's a GUI running. Resize a message box if the text won't fit. Add some graphics for minimize and maximize buttons to the system menu (they aren't active yet). Add Resize() function to GUI_Window. Create GetWindowFromID() to get a GUI_Window pointer from a PID.
1 parent 0ac04b2 commit 3501164

17 files changed

+338
-24
lines changed

MyOS_1/Build_Number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// Define a build number. This number will be incremented by a simple console program called by a post-build event
44
// It's put here in its own file to keep the other program from messing up the source
55
#define \
6-
BUILD_NUMBER 5746
6+
BUILD_NUMBER 5778

MyOS_1/GUI_Kernel.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
#include <stdarg.h>
12
#include "GUI_Kernel.h"
23
#include "GUI_Messages.h"
34
#include "Tasks/Context.h"
5+
#include "printf.h"
46

57
GUI_CALLBACK guiCallback = NULL;
68

9+
// Send a formatted text string to the console window for the currently running application
10+
int GUI_printf(const char *format, va_list va)
11+
{
12+
GUI_CONSOLE_PRINT_DATA param;
13+
char outString[MAX_GUI_CONSOLE_STRING_LENGTH];
14+
15+
int returnValue = vsnprintf(outString, MAX_GUI_CONSOLE_STRING_LENGTH, format, va);
16+
17+
param.textString = outString;
18+
19+
(*guiCallback)(tasks[currentTask].PID, GUI_MSG_CONSOLE_PRINT, &param);
20+
21+
return returnValue;
22+
}
23+
724
void GUI_CallbackAdded()
825
{
926
// Send a new window message to the GUI shell for each running application

MyOS_1/GUI_Kernel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ typedef void(*GUI_CALLBACK)(uint32_t PID, uint32_t messageType, void *pData);
88
extern GUI_CALLBACK guiCallback;
99

1010
// Called immediately after a callback has been registered, to transition running apps into windowed consoles
11-
void GUI_CallbackAdded();
11+
void GUI_CallbackAdded();
12+
13+
// Sends the formatted text string to the running GUI application
14+
int GUI_printf(const char *format, va_list va);

MyOS_1/GUI_Messages.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33

44
// MESSAGES
55
#define GUI_MSG_NEW_CONSOLE_APP 0x1000
6+
#define GUI_MSG_CONSOLE_PRINT 0x1001
67
// END OF MESSAGES
78

9+
#define MAX_GUI_CONSOLE_STRING_LENGTH 512
10+
811
// DATA TYPES USED BY MESSAGES
912

1013
// Data type used by GUI_MSG_NEW_CONSOLE_APP messages
1114
typedef struct GUI_NEW_CONSOLE_APP_DATA
1215
{
1316
const char *appName;
14-
1517
// TODO: We may as well send the terminal contents over in the same message
1618
} GUI_NEW_CONSOLE_APP_DATA;
19+
20+
// Data type used by GUI_MSG_CONSOLE_PRINT
21+
typedef struct GUI_CONSOLE_PRINT_DATA
22+
{
23+
const char *textString;
24+
} GUI_CONSOLE_PRINT_DATA;
1725
// END OF DATA TYPES

MyOS_1/Graphics/picofont.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#define FNT_ROWSPACING 3
2121

2222
// put some margins around the borders
23-
#define FNT_LEFTRIGHTMARGIN 3
24-
#define FNT_TOPBOTTOMMARGIN 3
23+
#define FNT_LEFTRIGHTMARGIN 3
24+
#define FNT_TOPBOTTOMMARGIN 3
2525

2626
typedef struct
2727
{

MyOS_1/Interrupts/Interrupts.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,11 @@ void _declspec(naked) printf_interrupt_handler(int eflags, int cs, const char *f
752752
terminal_writestring("printf interrupt handler fired.\n");
753753

754754
// Here's where printf actually happens
755-
vprintf_(fmt, va);
755+
if (guiCallback)
756+
GUI_printf(fmt, va);
757+
else
758+
vprintf_(fmt, va);
759+
756760

757761
_asm
758762
{

MyOS_GUI_Shell/GUI_Kernel_Shell.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@ extern int lastWindowID;
1010

1111
void GUI_Kernel_Callback(uint32_t PID, uint32_t messageType, void * pData)
1212
{
13+
GUI_Window *pWindow = NULL;
14+
1315
switch (messageType)
1416
{
1517
case GUI_MSG_NEW_CONSOLE_APP:
1618
// Create a new window with the app name
1719
CreateTextWindow(PID,
18-
//lastWindowID++,
19-
((GUI_NEW_CONSOLE_APP_DATA *)pData)->appName);
20+
((GUI_NEW_CONSOLE_APP_DATA *)pData)->appName);
21+
break;
22+
23+
case GUI_MSG_CONSOLE_PRINT:
24+
// Send the text to the window
25+
26+
// Find the window associated with the PID
27+
pWindow = GetWindowFromID(PID);
28+
if (!pWindow)
29+
{
30+
MessageBox("GUI_Kernel_Callback called with unrecognized PID!", "ERROR");
31+
return;
32+
}
33+
pWindow->SendWindowText( ((GUI_CONSOLE_PRINT_DATA *)pData)->textString );
2034
break;
35+
2136
default:
2237
MessageBox("GUI_Kernel_Callback called with unrecognized messageType.", "ERROR");
2338
break;

MyOS_GUI_Shell/GUI_MessageBox.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#include "GUI_MessageBox.h"
22
#include "GUI_Object.h"
33
#include "GUI_Button.h"
4+
#include "MyOS_GUI_Shell.h"
45

56
GUI_MessageBox::GUI_MessageBox(char * messageText, char * windowTitle)
6-
: GUI_Window(MESSAGE_BOX_X, MESSAGE_BOX_Y, MESSAGE_BOX_WIDTH, MESSAGE_BOX_HEIGHT, windowTitle)
7+
: GUI_Window( NewWindowPosition(MESSAGE_BOX_WIDTH, MESSAGE_BOX_HEIGHT), windowTitle)
78
{
89
// TODO: Use static memory so we can display out of memory messages
910
SDL_Surface *pFont = FNT_Render(messageText, SDL_BLACK);
10-
uint32_t messageMargin = 8;
11+
const int messageMargin = 8;
1112

13+
int minTextWidth = pFont->w + (messageMargin * 2);
14+
15+
// Resize the message box if the text won't fit
16+
if (dimensions.width < minTextWidth)
17+
Resize( { dimensions.top, dimensions.left, minTextWidth, dimensions.height } );
18+
1219
SDL_Rect destRect = { messageMargin,
1320
messageMargin + SYSTEM_MENU_HEIGHT,
14-
dimensions.width - (messageMargin * 2),
21+
minTextWidth,
1522
dimensions.height - (messageMargin * 2) };
1623

1724
SDL_BlitSurface(pFont, NULL, pSurface, &destRect);
@@ -20,3 +27,4 @@ GUI_MessageBox::GUI_MessageBox(char * messageText, char * windowTitle)
2027
// Create a button control for an "OK" button
2128
pControls[0] = new GUI_Button("OK", SYSTEM_MENU_CLOSE_BUTTON_ID, this);
2229
}
30+

MyOS_GUI_Shell/GUI_Object.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,44 @@ void GUI_Object::DrawSystemMenu(SDL_Surface *pSurface, char *windowName)
100100

101101
// Draw the system boxes
102102
int margin = 4;
103-
int boxHeight = SYSTEM_MENU_HEIGHT - margin;
103+
int boxHeight = SYSTEM_MENU_HEIGHT - margin + 1;
104104
int boxWidth = boxHeight;
105105
int boxTop = (margin / 2);
106-
int boxLeft = dimensions.width - boxWidth - margin;
106+
int boxLeft = dimensions.width - boxWidth - margin + 2;
107107
SDL_Rect boxRect = { boxLeft, boxTop, boxWidth, boxHeight };
108108
uint32_t red = SDL_MapRGB(pSurface->format, 255, 120, 120 );
109109
SDL_FillRect(pSurface, &boxRect, red);
110-
//DrawBox(pSurface, boxLeft, boxTop, boxWidth, boxHeight, black);
111110
Draw3D_Box(pSurface, boxLeft, boxTop, boxWidth, boxHeight);
112111

113112
pFont = FNT_Render("X", black);
114-
boxRect.x += 6;
113+
boxRect.x += 7;
114+
boxRect.y += 7;
115+
SDL_BlitSurface(pFont, NULL, pSurface, &boxRect);
116+
SDL_FreeSurface(pFont);
117+
118+
119+
boxLeft = boxLeft - boxWidth - 2;
120+
boxRect = { boxLeft, boxTop, boxWidth, boxHeight };
121+
SDL_FillRect(pSurface, &boxRect, SDL_MapRGB(pSurface->format, 205, 205, 205));
122+
Draw3D_Box(pSurface, boxLeft, boxTop, boxWidth, boxHeight);
123+
124+
pFont = FNT_Render("[", black);
125+
boxRect.x += 4;
126+
boxRect.y += 7;
127+
SDL_BlitSurface(pFont, NULL, pSurface, &boxRect);
128+
boxRect.x += 4;
129+
SDL_FreeSurface(pFont);
130+
pFont = FNT_Render("]", black);
131+
SDL_BlitSurface(pFont, NULL, pSurface, &boxRect);
132+
SDL_FreeSurface(pFont);
133+
134+
boxLeft = boxLeft - boxWidth - 2;
135+
boxRect = { boxLeft, boxTop, boxWidth, boxHeight };
136+
SDL_FillRect(pSurface, &boxRect, SDL_MapRGB(pSurface->format, 205, 205, 205));
137+
Draw3D_Box(pSurface, boxLeft, boxTop, boxWidth, boxHeight);
138+
139+
pFont = FNT_Render("_", black);
140+
boxRect.x += 7;
115141
boxRect.y += 7;
116142
SDL_BlitSurface(pFont, NULL, pSurface, &boxRect);
117143
SDL_FreeSurface(pFont);

MyOS_GUI_Shell/GUI_Object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extern "C" {
1717
#define SYSTEM_MENU_COLOR_G 160
1818
#define SYSTEM_MENU_COLOR_B 255
1919

20-
const SDL_Color SDL_BLACK = { 0, 0, 0, 255 };
20+
const SDL_Color SDL_BLACK = { 0, 0, 0, 255 };
21+
const SDL_Color SDL_DARKGRAY = { 40, 40, 40, 255 };
2122
const uint32_t RGB_BLACK = 0x000000;
2223
const SDL_Color SDL_WHITE = { 255, 255, 255, 255 };
2324
const SDL_Color SDL_DEFAULT_BUTTON_COLOR = { 200, 200, 200, 255 };

0 commit comments

Comments
 (0)