Factored out GameWindow, added error alert dialogs, simplified stdbool.h

This commit is contained in:
Jon Thysell 2021-10-15 09:43:09 -07:00
parent b51cf36f80
commit 6184d31e6a
11 changed files with 97 additions and 33 deletions

View File

@ -16,7 +16,7 @@ extern const uint16_t PerfectScore;
typedef struct GameEngine
{
int8_t Level;
int8_t Level;
uint32_t Lights;
uint16_t Par;
uint16_t Moves;

29
src/GameWindow.c Normal file
View File

@ -0,0 +1,29 @@
// Copyright (c) Jon Thysell <http://jonthysell.com>
// Licensed under the MIT License.
#include "GameWindow.h"
void GameWindow_Init(GameWindow *gameWindow)
{
if (gameWindow->Window != nil)
{
ShowError("\pGameWindow already initialized!", false);
}
gameWindow->Window = GetNewWindow(kBaseResID, nil, kMoveToFront);
if (gameWindow->Window == nil)
{
ShowError("\pGameWindow resource WIND kBaseResID missing!", true);
}
CenterWindow(gameWindow->Window);
ShowWindow(gameWindow->Window);
SetPort(gameWindow->Window);
MoveTo(10, 20);
DrawString("\pHello MacLO");
}

16
src/GameWindow.h Normal file
View File

@ -0,0 +1,16 @@
// Copyright (c) Jon Thysell <http://jonthysell.com>
// Licensed under the MIT License.
#ifndef GAMEWINDOW_H
#define GAMEWINDOW_H
#include "MacCommon.h"
typedef struct GameWindow
{
WindowPtr Window;
} GameWindow;
void GameWindow_Init(GameWindow *gameWindow);
#endif

26
src/MacCommon.c Normal file
View File

@ -0,0 +1,26 @@
// Copyright (c) Jon Thysell <http://jonthysell.com>
// Licensed under the MIT License.
#include "MacCommon.h"
void CenterWindow(WindowPtr window)
{
}
Boolean IsCompactDisplay()
{
return screenBits.bounds.right == 512
&& screenBits.bounds.bottom == 342;
}
void ShowError(Str255 message, Boolean isFatal)
{
ParamText(message, kEmptyString, kEmptyString, kEmptyString);
StopAlert(kErrorAlertID, kNilFilterProc);
if (isFatal)
{
ExitToShell();
}
}

View File

@ -4,7 +4,16 @@
#ifndef MACCOMMON_H
#define MACCOMMON_H
#define kBaseResID 128
#define kMoveToFront (WindowPtr)-1L
#define kBaseResID 128
#define kMoveToFront (WindowPtr)-1L
#define kEmptyString "\p"
#define kNilFilterProc nil
#define kErrorAlertID kBaseResID
void CenterWindow(WindowPtr window);
Boolean IsCompactDisplay();
void ShowError(Str255 message, Boolean isFatal);
#endif

View File

@ -1,10 +1,12 @@
// Copyright (c) Jon Thysell <http://jonthysell.com>
// Licensed under the MIT License.
#include "MacCommon.h"
#include "GameWindow.h"
#include "MacLO.h"
void InitToolBox()
GameWindow gGameWindow;
void MacLO_InitToolBox()
{
InitGraf(&thePort);
InitFonts();
@ -16,26 +18,12 @@ void InitToolBox()
InitCursor();
}
void InitMainWindow()
void MacLO_InitWindows()
{
WindowPtr window;
window = GetNewWindow(kBaseResID, nil, kMoveToFront);
if (window == nil)
{
SysBeep(0);
ExitToShell();
}
ShowWindow(window);
SetPort(window);
MoveTo(30, 50);
DrawString("\pHello MacLO");
GameWindow_Init(&gGameWindow);
}
void ProcessEvents()
void MacLO_MainLoop()
{
while (!Button()) { }
}

View File

@ -4,8 +4,8 @@
#ifndef MACLO_H
#define MACLO_H
void InitToolBox();
void InitMainWindow();
void ProcessEvents();
void MacLO_InitToolBox();
void MacLO_InitWindows();
void MacLO_MainLoop();
#endif

Binary file not shown.

Binary file not shown.

View File

@ -5,7 +5,7 @@
void main(void)
{
InitToolBox();
InitMainWindow();
ProcessEvents();
MacLO_InitToolBox();
MacLO_InitWindows();
MacLO_MainLoop();
}

View File

@ -4,10 +4,6 @@
#ifndef STDBOOL_H
#define STDBOOL_H
#ifndef true
typedef char bool;
#define true 1
#define false 0
#endif
typedef Boolean bool;
#endif