Skip to content

Commit 0ac04b2

Browse files
author
tthomps
committed
Add GUI_TerminalWindow class.
1 parent 82e3236 commit 0ac04b2

13 files changed

+192
-36
lines changed

MyOS_GUI_For_Windows/MyOS_GUI_For_Windows.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
<ItemGroup>
152152
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Button.h" />
153153
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Control.h" />
154-
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Kernel_Messages.h" />
155154
<ClInclude Include="..\MyOS_GUI_Shell\GUI_MessageBox.h" />
156155
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Object.h" />
157156
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Rect.h" />
@@ -165,9 +164,11 @@
165164
<ClCompile Include="..\MyOS_GUI_Shell\font.c" />
166165
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Button.cpp" />
167166
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Control.cpp" />
167+
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Kernel_Shell.cpp" />
168168
<ClCompile Include="..\MyOS_GUI_Shell\GUI_MessageBox.cpp" />
169169
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Object.cpp" />
170170
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Taskbar.cpp" />
171+
<ClCompile Include="..\MyOS_GUI_Shell\GUI_TerminalWindow.cpp" />
171172
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Window.cpp" />
172173
<ClCompile Include="..\MyOS_GUI_Shell\MyOS_GUI_Shell.cpp" />
173174
<ClCompile Include="..\MyOS_GUI_Shell\spf.c" />

MyOS_GUI_For_Windows/MyOS_GUI_For_Windows.vcxproj.filters

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Taskbar.h">
4343
<Filter>Header Files</Filter>
4444
</ClInclude>
45-
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Kernel_Messages.h">
46-
<Filter>Source Files</Filter>
47-
</ClInclude>
4845
</ItemGroup>
4946
<ItemGroup>
5047
<ClCompile Include="..\MyOS_GUI_Shell\MyOS_GUI_Shell.cpp">
@@ -77,5 +74,11 @@
7774
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Taskbar.cpp">
7875
<Filter>Source Files</Filter>
7976
</ClCompile>
77+
<ClCompile Include="..\MyOS_GUI_Shell\GUI_TerminalWindow.cpp">
78+
<Filter>Source Files</Filter>
79+
</ClCompile>
80+
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Kernel_Shell.cpp">
81+
<Filter>Source Files</Filter>
82+
</ClCompile>
8083
</ItemGroup>
8184
</Project>

MyOS_GUI_Shell/GUI_Kernel_Shell.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifdef __cplusplus
2+
extern "C" {
3+
#endif /* __cplusplus */
4+
5+
#include "GUI_Kernel_Shell.h"
6+
#include "MyOS_GUI_Shell.h"
7+
#include "../MyOS_1/GUI_Messages.h"
8+
9+
extern int lastWindowID;
10+
11+
void GUI_Kernel_Callback(uint32_t PID, uint32_t messageType, void * pData)
12+
{
13+
switch (messageType)
14+
{
15+
case GUI_MSG_NEW_CONSOLE_APP:
16+
// Create a new window with the app name
17+
CreateTextWindow(PID,
18+
//lastWindowID++,
19+
((GUI_NEW_CONSOLE_APP_DATA *)pData)->appName);
20+
break;
21+
default:
22+
MessageBox("GUI_Kernel_Callback called with unrecognized messageType.", "ERROR");
23+
break;
24+
}
25+
}
26+
27+
#ifdef __cplusplus
28+
}
29+
#endif

MyOS_GUI_Shell/GUI_Kernel_Shell.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif /* __cplusplus */
6+
7+
#include <stdint.h>
8+
9+
// Used to define the interface between the Kernel and the GUI Shell (on the shell side)
10+
11+
// Called by the kernel to send messages to the GUI
12+
void GUI_Kernel_Callback(uint32_t PID, uint32_t messageType, void *pData);
13+
14+
#ifdef __cplusplus
15+
}
16+
#endif /* __cplusplus */

MyOS_GUI_Shell/GUI_TerminalWindow.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "GUI_TerminalWindow.h"
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif /* __cplusplus */
6+
7+
#ifdef __MYOS
8+
#include "../MyOS_1/Interrupts/System_Calls.h"
9+
#endif
10+
11+
GUI_TerminalWindow::GUI_TerminalWindow(const char *name)
12+
: GUI_Window(NewWindowPosition(GUI_TERMINAL_DEFAULT_WIDTH, GUI_TERMINAL_DEFAULT_HEIGHT), name)
13+
{
14+
// TODO: Check for out of memory error
15+
characterBuffer = new char(characterBufferSize);
16+
//(char*)malloc(characterBufferSize);
17+
18+
foregroundTextColor = GUI_TERMINAL_DEFAULT_TEXT_COLOR;
19+
backgroundColor = GUI_TERMINAL_DEFAULT_BG_COLOR;
20+
21+
DrawWindow();
22+
}
23+
24+
25+
GUI_TerminalWindow::~GUI_TerminalWindow()
26+
{
27+
//free(characterBuffer);
28+
delete characterBuffer;
29+
}
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif /* __cplusplus */

MyOS_GUI_Shell/GUI_TerminalWindow.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif /* __cplusplus */
6+
7+
#include "GUI_Window.h"
8+
#include "MyOS_GUI_Shell.h"
9+
10+
#define GUI_TERMINAL_DEFAULT_BUFFER_SIZE 4096
11+
#define GUI_TERMINAL_DEFAULT_TEXT_COLOR {255, 255, 255, 255}
12+
#define GUI_TERMINAL_DEFAULT_BG_COLOR {40, 40, 40, 255}
13+
14+
#define GUI_TERMINAL_DEFAULT_WIDTH 80 * 8
15+
#define GUI_TERMINAL_DEFAULT_HEIGHT 60 * 8
16+
17+
class GUI_TerminalWindow :
18+
public GUI_Window
19+
{
20+
public:
21+
GUI_TerminalWindow(const char *name);
22+
~GUI_TerminalWindow();
23+
24+
SDL_Color foregroundTextColor;
25+
uint32_t characterBufferSize;
26+
char *characterBuffer;
27+
};
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif

MyOS_GUI_Shell/GUI_Window.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ void GUI_Window::CreateSurface()
2727
return;
2828
// printf("Error! Couldn't create RGB surface for window!\n");
2929

30-
backgroundColor.r = backgroundColor.b = 205;
31-
backgroundColor.b = 205;
30+
backgroundColor = { 205, 205, 205, 255 };
31+
3232
DrawWindow();
3333
}
3434

@@ -102,7 +102,6 @@ void GUI_Window::SetBackgroundColor(SDL_Color color)
102102
void GUI_Window::DrawWindow()
103103
{
104104
// Draw the background
105-
//SDL_FillRect(pSurface, NULL, SDL_MapRGB(pSurface->format, backgroundColor.r, backgroundColor.g, backgroundColor.b));
106105
FillSurface(backgroundColor);
107106

108107
// Draw the system menu at the top

MyOS_GUI_Shell/GUI_Window.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ class GUI_Control;
1212
class GUI_Window : public GUI_Object
1313
{
1414
public:
15-
GUI_Window(GUI_Rect size, char *name)
15+
GUI_Window(GUI_Rect size, const char *name)
1616
{
1717
dimensions = size;
18-
SDL_strlcpy(windowName, name, MAX_WINDOW_NAME_LENGTH);
18+
SDL_strlcpy(windowName, name, MAX_WINDOW_NAME_LENGTH - 1);
1919
CreateSurface();
2020

2121
for (int i = 0; i < MAX_WINDOW_CONTROLS; ++i)
2222
pControls[i] = NULL;
23+
24+
pClickedControl = NULL;
2325
}
2426

25-
GUI_Window(int top, int left, int width, int height, char *name)
27+
GUI_Window(int top, int left, int width, int height, const char *name)
2628
{
2729
dimensions.top = top;
2830
dimensions.left = left;

MyOS_GUI_Shell/MyOS_GUI_Shell.cpp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extern "C" {
2929
#include "GUI_Window.h"
3030
#include "GUI_MessageBox.h"
3131
#include "GUI_Taskbar.h"
32+
#include "GUI_Kernel_Shell.h"
33+
#include "GUI_TerminalWindow.h"
3234

3335
#define MAX_GUI_WINDOWS 256 /*TEMP HACK*/
3436
GUI_Window *windowList[MAX_GUI_WINDOWS] = { NULL };
@@ -56,6 +58,7 @@ GUI_Taskbar *pTaskbar;
5658
#define DELETION_QUEUE_SIZE 16
5759
GUI_Window *pDeletionQueue[DELETION_QUEUE_SIZE]; // UGLY HACK
5860
int nextDeletionQueueIndex = 0;
61+
int lastWindowID = 1;
5962

6063
#define CURSOR_X 16
6164
#define CURSOR_Y 16
@@ -178,19 +181,21 @@ void AddWindowToStack(GUI_Window *window, GUI_WINDOW_STACK_ENTRY *pStackEntry)
178181
}
179182

180183
// This would probably be called with a process' PID
181-
GUI_Window *CreateTextWindow(uint32_t uniqueID)
184+
GUI_Window *CreateTextWindow(uint32_t uniqueID, const char *windowName)
182185
{
183186
// find the first unused entry in the windowList
184187
for (int i = 0; i < MAX_GUI_WINDOWS; ++i)
185188
{
186189
if (!windowList[i])
187190
{
188-
windowList[i] = new GUI_Window(nextX, nextY, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT, "New Window");
191+
windowList[i] = new GUI_TerminalWindow(windowName);
192+
//new GUI_Window(nextX, nextY, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT, windowName);
193+
189194
// TODO: Check for NULL
190195
windowIDs[i] = uniqueID;
191196

192197
// Advance position of next window
193-
nextX += WINDOW_X_INC;
198+
/*nextX += WINDOW_X_INC;
194199
nextX %= MAX_WINDOW_X;
195200
nextY += WINDOW_Y_INC;
196201
nextY %= MAX_WINDOW_Y;
@@ -209,7 +214,7 @@ GUI_Window *CreateTextWindow(uint32_t uniqueID)
209214
210215
bgRed %= 255;
211216
bgGreen %= 255;
212-
bgBlue %= 255;
217+
bgBlue %= 255;*/
213218

214219
AddWindowToStack(windowList[i], &windowStack[i]);
215220

@@ -223,6 +228,19 @@ GUI_Window *CreateTextWindow(uint32_t uniqueID)
223228
return NULL;
224229
}
225230

231+
GUI_Rect NewWindowPosition(int width, int height)
232+
{
233+
GUI_Rect windowPos = { nextY, nextX, width, height };
234+
235+
// Advance position of next window
236+
nextX += WINDOW_X_INC;
237+
nextX %= MAX_WINDOW_X;
238+
nextY += WINDOW_Y_INC;
239+
nextY %= MAX_WINDOW_Y;
240+
241+
return windowPos;
242+
}
243+
226244
// This is kind of hacky and maybe I'll find a better way in the future.
227245
// Windows can request their own removal, but if they're deleted at that point, execution will return to deleted code
228246
void DeleteAllWindowsInQueue()
@@ -254,7 +272,7 @@ void MessageBox(char *messageText, char *windowTitle)
254272
if (!windowList[i])
255273
{
256274
windowList[i] = new GUI_MessageBox(messageText, windowTitle);
257-
AddWindowToStack(windowList[i], &windowStack[i]);
275+
AddWindowToStack(windowList[i], &windowStack[i]);
258276
return;
259277
}
260278
}
@@ -349,7 +367,8 @@ int main(int argc, char* argv[])
349367
SDL_Delay(500); // Pause execution for 500 milliseconds, for example
350368
*/
351369
// Load BMP
352-
char *filename = "kghrwide.bmp";
370+
//char *filename = "kghrwide.bmp";
371+
char *filename = "kg2.bmp";
353372
#if __MYOS__
354373
filename = "kg2.bmp";
355374
#endif
@@ -373,8 +392,6 @@ int main(int argc, char* argv[])
373392

374393
SDL_Event event;
375394

376-
int lastWindowID = 1;
377-
378395
// Hide the mouse cursor
379396
SDL_ShowCursor(SDL_DISABLE);
380397

@@ -415,6 +432,13 @@ int main(int argc, char* argv[])
415432
// Create Taskbar
416433
pTaskbar = new GUI_Taskbar(screenSurface->w, screenSurface->h);
417434

435+
#ifdef __MYOS
436+
// Tell the kernel how to talk to us
437+
registerGuiCallback(GUI_Kernel_Callback);
438+
#endif
439+
440+
//GUI_Kernel_Callback(0, 0, NULL);
441+
418442
// Keep drawing everything
419443
while (!done)
420444
{
@@ -437,9 +461,9 @@ int main(int argc, char* argv[])
437461

438462
case SDL_KEYDOWN:
439463
//switch (event.key.keysym)
440-
CreateTextWindow(lastWindowID++);
464+
CreateTextWindow(lastWindowID++, "New Window");
441465

442-
MessageBox("Here's a test message", "Test Message");
466+
//MessageBox("Here's a test message", "Test Message");
443467
switch (event.key.keysym.sym)
444468
{
445469
case SDLK_n:
@@ -524,16 +548,16 @@ int main(int argc, char* argv[])
524548
}
525549

526550
// draw the "background"
527-
/*if (bitmapSurface)
551+
if (bitmapSurface)
528552
{
529553
// Blit bitmap to window
530554
SDL_BlitScaled(bitmapSurface, NULL, screenSurface, NULL);
531555

532556
//SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example
533-
}*/
557+
}
534558

535559
// Fill the background with black instead of an image for a little while
536-
SDL_FillRect(screenSurface, NULL, RGB_BLACK);
560+
//SDL_FillRect(screenSurface, NULL, RGB_BLACK);
537561

538562
// draw all of the windows
539563
// bigWindow.PaintToSurface(screenSurface);

MyOS_GUI_Shell/MyOS_GUI_Shell.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
#pragma once
22

3-
#include "GUI_Window.h"
4-
5-
63
#ifdef __cplusplus
74
extern "C" {
85
#endif /* __cplusplus */
96

10-
struct GUI_WINDOW_STACK_ENTRY;
11-
typedef struct GUI_WINDOW_STACK_ENTRY
12-
{
13-
GUI_Window *pWindow;
14-
GUI_WINDOW_STACK_ENTRY *pUnderneath;
15-
GUI_WINDOW_STACK_ENTRY *pAbove;
16-
} GUI_WINDOW_STACK_ENTRY;
7+
#include "GUI_Window.h"
8+
9+
struct GUI_WINDOW_STACK_ENTRY;
10+
typedef struct GUI_WINDOW_STACK_ENTRY
11+
{
12+
GUI_Window *pWindow;
13+
GUI_WINDOW_STACK_ENTRY *pUnderneath;
14+
GUI_WINDOW_STACK_ENTRY *pAbove;
15+
} GUI_WINDOW_STACK_ENTRY;
1716

18-
void BringWindowID_ToFront(uint32_t windowID);
19-
void BringWindowToFront(GUI_WINDOW_STACK_ENTRY *pEntry);
20-
void Shell_Destroy_Window(GUI_Window *pWindow);
17+
void BringWindowID_ToFront(uint32_t windowID);
18+
void BringWindowToFront(GUI_WINDOW_STACK_ENTRY *pEntry);
19+
GUI_Window *CreateTextWindow(uint32_t uniqueID, const char *windowName);
20+
GUI_Rect NewWindowPosition(int x, int y);
21+
void MessageBox(char *messageText, char *windowTitle);
22+
void Shell_Destroy_Window(GUI_Window *pWindow);
2123

2224

2325
#ifdef __cplusplus

0 commit comments

Comments
 (0)