Skip to content

Commit 9c6f11d

Browse files
author
tthomps
committed
Start implementing popup menus.
Start implementing a basic start menu.
1 parent 6113b2e commit 9c6f11d

File tree

11 files changed

+64
-6
lines changed

11 files changed

+64
-6
lines changed

MyOS_GUI_For_Windows/MyOS_GUI_For_Windows.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Control.h" />
154154
<ClInclude Include="..\MyOS_GUI_Shell\GUI_MessageBox.h" />
155155
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Object.h" />
156+
<ClInclude Include="..\MyOS_GUI_Shell\GUI_PopupMenu.h" />
156157
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Rect.h" />
157158
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Taskbar.h" />
158159
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Window.h" />
@@ -167,6 +168,7 @@
167168
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Kernel_Shell.cpp" />
168169
<ClCompile Include="..\MyOS_GUI_Shell\GUI_MessageBox.cpp" />
169170
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Object.cpp" />
171+
<ClCompile Include="..\MyOS_GUI_Shell\GUI_PopupMenu.cpp" />
170172
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Taskbar.cpp" />
171173
<ClCompile Include="..\MyOS_GUI_Shell\GUI_TerminalWindow.cpp" />
172174
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Window.cpp" />

MyOS_GUI_For_Windows/MyOS_GUI_For_Windows.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<ClInclude Include="..\MyOS_GUI_Shell\GUI_Taskbar.h">
4343
<Filter>Header Files</Filter>
4444
</ClInclude>
45+
<ClInclude Include="..\MyOS_GUI_Shell\GUI_PopupMenu.h">
46+
<Filter>Header Files</Filter>
47+
</ClInclude>
4548
</ItemGroup>
4649
<ItemGroup>
4750
<ClCompile Include="..\MyOS_GUI_Shell\MyOS_GUI_Shell.cpp">
@@ -80,5 +83,8 @@
8083
<ClCompile Include="..\MyOS_GUI_Shell\GUI_Kernel_Shell.cpp">
8184
<Filter>Source Files</Filter>
8285
</ClCompile>
86+
<ClCompile Include="..\MyOS_GUI_Shell\GUI_PopupMenu.cpp">
87+
<Filter>Source Files</Filter>
88+
</ClCompile>
8389
</ItemGroup>
8490
</Project>

MyOS_GUI_Shell/GUI_Object.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ void GUI_Object::DrawBox(SDL_Surface *pSurface, int x, int y, int width, int hei
7575
DrawVerticalLine(pSurface, x, y, y + height, lineColor);
7676
}
7777

78+
// Fill a surface with a color
79+
void GUI_Object::FillSurface(SDL_Surface * pSurface, SDL_Color color)
80+
{
81+
uint32_t col = SDL_MapRGB(pSurface->format, color.r, color.g, color.b);
82+
SDL_FillRect(pSurface, NULL, col);
83+
}
84+
7885
void GUI_Object::DrawSystemMenu(SDL_Surface *pSurface, char *windowName)
7986
{
8087
// Fill in a bar at the top

MyOS_GUI_Shell/GUI_Object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class GUI_Object
4646
void Draw3D_Box(SDL_Surface *pSurface, int x, int y, int width, int height);
4747
void Draw3D_InsetBox(SDL_Surface * pSurface, int x, int y, int width, int height);
4848
void DrawBox(SDL_Surface *pSurface, int x, int y, int width, int height, SDL_Color lineColor);
49+
void FillSurface(SDL_Surface *pSurface, SDL_Color color);
4950
};
5051

5152
#ifdef __cplusplus

MyOS_GUI_Shell/GUI_Taskbar.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "GUI_Taskbar.h"
77
#include "GUI_Button.h"
88

9+
void StartMenuHandler(int choice)
10+
{}
911

1012
GUI_Taskbar::GUI_Taskbar(uint32_t desktopWidth, uint32_t desktopHeight) :
1113
GUI_Window(desktopHeight - GUI_TASKBAR_HEIGHT, 0, desktopWidth, GUI_TASKBAR_HEIGHT, "Taskbar")
@@ -24,6 +26,10 @@ GUI_Taskbar::GUI_Taskbar(uint32_t desktopWidth, uint32_t desktopHeight) :
2426
pControls[0] = new GUI_Button("MyOS", GUI_TASKBAR_START_ID, this);
2527
pControls[0]->dimensions.left = GUI_TASKBAR_BUTTON_MARGINS;
2628

29+
// Create the start menu
30+
pStartMenu = new GUI_PopupMenu(this, StartMenuHandler, ABOVE_AND_RIGHT_OF_ORIGIN);
31+
pStartMenu->AddMenuItem("Run", 0);
32+
2733
windowButtons = 0;
2834
pActiveWindowButton = NULL;
2935
}
@@ -115,6 +121,8 @@ void GUI_Taskbar::ControlClicked(uint32_t controlID)
115121
{
116122
if (controlID != GUI_TASKBAR_START_ID)
117123
{
124+
pStartMenu->shown = false;
125+
118126
if (pActiveWindowButton)
119127
pActiveWindowButton->UnClick();
120128

@@ -129,6 +137,10 @@ void GUI_Taskbar::ControlClicked(uint32_t controlID)
129137
else
130138
{
131139
// start clicked
140+
if (!pStartMenu->shown)
141+
pStartMenu->ShowMenu({ GUI_TASKBAR_BUTTON_MARGINS, dimensions.top });
142+
else
143+
pStartMenu->shown = false;
132144
}
133145
}
134146

@@ -137,6 +149,13 @@ void GUI_Taskbar::OnDrag(int startRelX, int startRelY, int relX, int relY)
137149
// Don't allow the taskbar itself to be dragged
138150
}
139151

152+
void GUI_Taskbar::PaintToSurface(SDL_Surface * pTargetSurface)
153+
{
154+
GUI_Window::PaintToSurface(pTargetSurface);
155+
156+
pStartMenu->PaintToSurface(pTargetSurface);
157+
}
158+
140159
void GUI_Taskbar::RemoveWindow(uint32_t windowID)
141160
{
142161
// Find the control ID

MyOS_GUI_Shell/GUI_Taskbar.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "MyOS_GUI_Shell.h"
33
#include "GUI_Window.h"
44
#include "GUI_Button.h"
5+
#include "GUI_PopupMenu.h"
56

67
#define GUI_TASKBAR_HEIGHT 32
78
#define GUI_TASKBAR_BUTTON_MARGINS 4
@@ -33,12 +34,13 @@ class GUI_Taskbar :
3334
void ButtonsChanged();
3435
void ControlClicked(uint32_t controlID);
3536
void OnDrag(int startRelX, int startRelY, int relX, int relY);
37+
void PaintToSurface(SDL_Surface *pTargetSurface);
3638
void RemoveWindow(uint32_t windowID);
3739
void WindowActivated(uint32_t windowID);
3840

3941
protected:
4042
int windowButtons;
41-
4243
GUI_TaskbarButton *pActiveWindowButton;
44+
GUI_PopupMenu *pStartMenu;
4345
};
4446

MyOS_GUI_Shell/MyOS_GUI_Shell.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
<ClCompile Include="GUI_Kernel_Shell.cpp" />
279279
<ClCompile Include="GUI_MessageBox.cpp" />
280280
<ClCompile Include="GUI_Object.cpp" />
281+
<ClCompile Include="GUI_PopupMenu.cpp" />
281282
<ClCompile Include="GUI_Taskbar.cpp" />
282283
<ClCompile Include="GUI_TerminalWindow.cpp" />
283284
<ClCompile Include="GUI_Window.cpp" />
@@ -291,6 +292,7 @@
291292
<ClInclude Include="GUI_Kernel_Shell.h" />
292293
<ClInclude Include="GUI_MessageBox.h" />
293294
<ClInclude Include="GUI_Object.h" />
295+
<ClInclude Include="GUI_PopupMenu.h" />
294296
<ClInclude Include="GUI_Rect.h" />
295297
<ClInclude Include="GUI_Taskbar.h" />
296298
<ClInclude Include="GUI_TerminalWindow.h" />

MyOS_GUI_Shell/MyOS_GUI_Shell.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@
360360
<ClCompile Include="GUI_Kernel_Shell.cpp">
361361
<Filter>Source Files</Filter>
362362
</ClCompile>
363+
<ClCompile Include="GUI_PopupMenu.cpp">
364+
<Filter>Source Files</Filter>
365+
</ClCompile>
363366
</ItemGroup>
364367
<ItemGroup>
365368
<ClInclude Include="GUI_Object.h">
@@ -389,5 +392,8 @@
389392
<ClInclude Include="MyOS_GUI_Shell.h">
390393
<Filter>Header Files</Filter>
391394
</ClInclude>
395+
<ClInclude Include="GUI_PopupMenu.h">
396+
<Filter>Header Files</Filter>
397+
</ClInclude>
392398
</ItemGroup>
393399
</Project>

MyOS_GUI_Shell/SDL_picofont.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
File authors:
66
Fredrik Hultin
7+
With Modifications for MyOS by Trevor Thompson
78
89
License: GPLv2
910
*/
@@ -21,6 +22,17 @@ extern "C" {
2122
#include <SDL.h>
2223
#endif
2324

25+
26+
#define FNT_FONTHEIGHT 8
27+
#define FNT_FONTWIDTH 8
28+
29+
// put same space between rows to improve readability
30+
#define FNT_ROWSPACING 3
31+
32+
// put some margins around the borders
33+
#define FNT_LEFTRIGHTMARGIN 3
34+
#define FNT_TOPBOTTOMMARGIN 3
35+
2436
SDL_Surface* FNT_Render(const char* text, SDL_Color color);
2537
SDL_Surface* FNT_RenderMax(const char* text, unsigned int len, SDL_Color color);
2638

Release/MyOS_1.dll

0 Bytes
Binary file not shown.

SDL_TestApp1/SDL_TestApp1.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ int __cdecl main(int argc, char* argv[])
4040
"An SDL2 window", // window title
4141
SDL_WINDOWPOS_UNDEFINED, // initial x position
4242
SDL_WINDOWPOS_UNDEFINED, // initial y position
43-
800, // width, in pixels (ignored)
44-
600, // height, in pixels (ignored
45-
SDL_WINDOW_FULLSCREEN_DESKTOP // Make the window the same size as the desktop
43+
640, // width, in pixels (ignored)
44+
480, // height, in pixels (ignored
45+
0
46+
//SDL_WINDOW_FULLSCREEN_DESKTOP // Make the window the same size as the desktop
4647
);
4748

4849
// Check that the window was successfully created
@@ -63,7 +64,7 @@ int __cdecl main(int argc, char* argv[])
6364
// Update the surface
6465
SDL_UpdateWindowSurface(window);
6566

66-
SDL_Delay(500); // Pause execution for 500 milliseconds, for example
67+
SDL_Delay(100); // Pause execution for 500 milliseconds, for example
6768

6869
// Load BMP
6970
char *filename = "kghrwide.bmp";
@@ -85,7 +86,7 @@ int __cdecl main(int argc, char* argv[])
8586
// Update the surface
8687
SDL_UpdateWindowSurface(window);
8788

88-
SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example
89+
SDL_Delay(300); // Pause execution for 3000 milliseconds, for example
8990
}
9091

9192
// Close and destroy the window

0 commit comments

Comments
 (0)