Add some initial widget functionality (prefs partly working)

This commit is contained in:
elasota
2020-01-01 20:24:46 -05:00
parent d9b5dd20d6
commit 5fe6218c28
85 changed files with 2131 additions and 1074 deletions

View File

@@ -1,17 +1,14 @@
#pragma once #pragma once
#ifndef __PL_COREDEFS_H__
#define __PL_COREDEFS_H__
#if __cplusplus >= 199711L #if __cplusplus >= 199711L
#define PL_IS_CPP11 1 #define GP_IS_CPP11 1
#else #else
#define PL_IS_CPP11 0 #define GP_IS_CPP11 0
#endif #endif
#if PL_IS_CPP11 #if GP_IS_CPP11
#define PL_DELETED = delete #define GP_DELETED = delete
#define PL_STATIC_ASSERT(n) static_assert((n), "Static assert failed: " #n) #define GP_STATIC_ASSERT(n) static_assert((n), "Static assert failed: " #n)
#else #else
#ifndef nullptr #ifndef nullptr
#define nullptr 0 #define nullptr 0
@@ -25,23 +22,23 @@
#define final #define final
#endif #endif
#define PL_DELETED #define GP_DELETED
template<bool TCondition> template<bool TCondition>
struct __PL_StaticAssertHelper struct __GpStaticAssertHelper
{ {
}; };
template<> template<>
struct __PL_StaticAssertHelper<true> struct __GpStaticAssertHelper<true>
{ {
int staticAssertFailed; int staticAssertFailed;
}; };
#define PL_STATIC_ASSERT(n) ((void)(&static_cast<const __PL_StaticAssertHelper<(n)>*>(nullptr)->staticAssertFailed)) #define GP_STATIC_ASSERT(n) ((void)(&static_cast<const __GpStaticAssertHelper<(n)>*>(nullptr)->staticAssertFailed))
#endif #endif
static const size_t PL_SYSTEM_MEMORY_ALIGNMENT = 16; static const size_t GP_SYSTEM_MEMORY_ALIGNMENT = 16;
#endif #define GP_DEBUG_CONFIG 1

View File

@@ -46,9 +46,6 @@ void DoAbout (void)
VersRecHndl version; VersRecHndl version;
ControlHandle itemHandle; ControlHandle itemHandle;
short itemType, hit, wasResFile; short itemType, hit, wasResFile;
ModalFilterUPP aboutFilterUPP;
aboutFilterUPP = NewModalFilterUPP(AboutFilter);
wasResFile = CurResFile(); wasResFile = CurResFile();
UseResFile(thisMac.thisResFile); UseResFile(thisMac.thisResFile);
@@ -84,14 +81,13 @@ void DoAbout (void)
do // Loop until user wants to exit do // Loop until user wants to exit
{ {
ModalDialog(aboutFilterUPP, &hit); ModalDialog(AboutFilter, &hit);
} }
while ((hit != kOkayButton) && (okayButtScanlineMask != nil)); while ((hit != kOkayButton) && (okayButtScanlineMask != nil));
if (okayButtScanlineMask != nil) if (okayButtScanlineMask != nil)
okayButtScanlineMask->Destroy(); // Clean up! okayButtScanlineMask->Destroy(); // Clean up!
DisposeDialog(aboutDialog); DisposeDialog(aboutDialog);
DisposeModalFilterUPP(aboutFilterUPP);
UseResFile(wasResFile); UseResFile(wasResFile);
} }

View File

@@ -217,7 +217,7 @@ void DisplayStarsRemaining (void)
else else
{ {
LoadScaledGraphic(surface, kStarsRemainingPICT, &bounds); LoadScaledGraphic(surface, kStarsRemainingPICT, &bounds);
const Point textPoint = Point::Create(bounds.left + 102 - (StringWidth(theStr) / 2), bounds.top + 23); const Point textPoint = Point::Create(bounds.left + 102 - (surface->MeasureString(theStr) / 2), bounds.top + 23);
ColorText(surface, textPoint, theStr, 4L); ColorText(surface, textPoint, theStr, 4L);
} }

View File

@@ -7,10 +7,10 @@
#include "DialogManager.h" #include "DialogManager.h"
#include "PLArrayView.h" #include "PLArrayView.h"
#include "PLControlDefinitions.h" #include "PLControlDefinitions.h"
#include "PLLowMem.h"
#include "PLNumberFormatting.h" #include "PLNumberFormatting.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "PLStandardColors.h" #include "PLStandardColors.h"
#include "PLWidgets.h"
#include "QDStandardPalette.h" #include "QDStandardPalette.h"
#include "DialogUtils.h" #include "DialogUtils.h"
#include "Externs.h" #include "Externs.h"
@@ -33,7 +33,7 @@ void BringUpDialog (Dialog **theDialog, short dialogID)
// CenterDialog(dialogID); // CenterDialog(dialogID);
if (*theDialog == nil) if (*theDialog == nil)
RedAlert(kErrDialogDidntLoad); RedAlert(kErrDialogDidntLoad);
SetPort((GrafPtr)*theDialog); SetGraphicsPort(&(*theDialog)->GetWindow()->m_graf);
ShowWindow((*theDialog)->GetWindow()); ShowWindow((*theDialog)->GetWindow());
DrawDefaultButton(*theDialog); DrawDefaultButton(*theDialog);
} }
@@ -343,10 +343,11 @@ void FlashDialogButton (Dialog *theDialog, short itemNumber)
UInt32 dummyLong; UInt32 dummyLong;
short itemType; short itemType;
GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemRect); PortabilityLayer::Widget *widget = theDialog->GetItems()[itemNumber - 1].GetWidget();
HiliteControl(itemHandle, kControlButtonPart);
widget->SetHighlightStyle(kControlButtonPart);
Delay(8, &dummyLong); Delay(8, &dummyLong);
HiliteControl(itemHandle, 0); widget->SetHighlightStyle(0);
} }
//-------------------------------------------------------------- DrawDefaultButton //-------------------------------------------------------------- DrawDefaultButton
@@ -355,10 +356,9 @@ void FlashDialogButton (Dialog *theDialog, short itemNumber)
void DrawDefaultButton (Dialog *theDialog) void DrawDefaultButton (Dialog *theDialog)
{ {
DialogItem *firstItem = *theDialog->GetItems().begin(); const PortabilityLayer::DialogItem &firstItem = *theDialog->GetItems().begin();
Rect itemRect = firstItem->GetRect(); Rect itemRect = firstItem.GetWidget()->GetRect();
DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface();
DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface();
InsetRect(&itemRect, -4, -4); InsetRect(&itemRect, -4, -4);
@@ -369,7 +369,7 @@ void DrawDefaultButton (Dialog *theDialog)
for (int yOffset = 0; yOffset < 3; yOffset++) for (int yOffset = 0; yOffset < 3; yOffset++)
{ {
const Rect offsetRect = itemRect + Point::Create(xOffset, yOffset); const Rect offsetRect = itemRect + Point::Create(xOffset, yOffset);
surface->FrameRoundRect(itemRect, 8, 8); surface->FrameRoundRect(offsetRect, 8, 8);
} }
} }
@@ -437,12 +437,7 @@ void GetDialogItemValue (Dialog *theDialog, short item, short *theState)
void SetDialogItemValue (Dialog *theDialog, short item, short theState) void SetDialogItemValue (Dialog *theDialog, short item, short theState)
{ {
Rect itemRect; theDialog->GetItems()[item - 1].GetWidget()->SetState(theState);
ControlHandle itemHandle;
short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
SetControlValue(itemHandle, theState);
} }
//-------------------------------------------------------------- ToggleDialogItemValue //-------------------------------------------------------------- ToggleDialogItemValue
@@ -500,7 +495,7 @@ void GetDialogNumFromStr (Dialog *theDialog, short item, long *theNumber)
void GetDialogItemRect (Dialog *theDialog, short item, Rect *theRect) void GetDialogItemRect (Dialog *theDialog, short item, Rect *theRect)
{ {
*theRect = theDialog->GetItems()[item - 1]->GetRect(); *theRect = theDialog->GetItems()[item - 1].GetWidget()->GetRect();
} }
//-------------------------------------------------------------- SetDialogItemRect //-------------------------------------------------------------- SetDialogItemRect
@@ -539,18 +534,10 @@ void OffsetDialogItemRect (Dialog *theDialog, short item, short h, short v)
void SelectFromRadioGroup (Dialog *dial, short which, short first, short last) void SelectFromRadioGroup (Dialog *dial, short which, short first, short last)
{ {
Rect iRect; for (int i = first; i <= last; i++)
ControlHandle iHandle; dial->GetItems()[i - 1].GetWidget()->SetState(0);
short iType, i;
for (i = first; i <= last; i++) dial->GetItems()[which - 1].GetWidget()->SetState(1);
{
GetDialogItem(dial, i, &iType, &iHandle, &iRect);
SetControlValue(iHandle, (short)false);
}
GetDialogItem(dial, which, &iType, &iHandle, &iRect);
SetControlValue(iHandle, (short)true);
} }
//-------------------------------------------------------------- AddMenuToPopUp //-------------------------------------------------------------- AddMenuToPopUp
@@ -615,8 +602,7 @@ void MyDisableControl (Dialog *theDialog, short whichItem)
ControlHandle iHandle; ControlHandle iHandle;
short iType; short iType;
GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect); theDialog->GetItems()[whichItem - 1].GetWidget()->SetEnabled(false);
HiliteControl(iHandle, kInactive);
} }
//-------------------------------------------------------------- DrawDialogUserText //-------------------------------------------------------------- DrawDialogUserText
@@ -626,22 +612,20 @@ void MyDisableControl (Dialog *theDialog, short whichItem)
void DrawDialogUserText (Dialog *dial, short item, StringPtr text, Boolean invert) void DrawDialogUserText (Dialog *dial, short item, StringPtr text, Boolean invert)
{ {
Rect iRect;
ControlHandle iHandle; ControlHandle iHandle;
Str255 newString, stringCopy; Str255 stringCopy;
short iType, textLong, i, inset; short iType, i, inset;
DrawSurface *surface = dial->GetWindow()->GetDrawSurface(); DrawSurface *surface = dial->GetWindow()->GetDrawSurface();
surface->SetApplicationFont(9, PortabilityLayer::FontFamilyFlag_None); surface->SetApplicationFont(9, PortabilityLayer::FontFamilyFlag_None);
PasStringCopy(text, stringCopy); PasStringCopy(text, stringCopy);
GetDialogItem(dial, item, &iType, &iHandle, &iRect);
if ((StringWidth(stringCopy) + 2) > (iRect.right - iRect.left)) Rect iRect = dial->GetItems()[item - 1].GetWidget()->GetRect();
CollapseStringToWidth(stringCopy, iRect.right - iRect.left - 2);
textLong = stringCopy[0]; if ((surface->MeasureString(stringCopy) + 2) > (iRect.right - iRect.left))
for (i = 0; i < textLong; i++) CollapseStringToWidth(surface, stringCopy, iRect.right - iRect.left - 2);
newString[i] = stringCopy[i + 1];
OffsetRect(&iRect, 0, 1); OffsetRect(&iRect, 0, 1);
@@ -651,11 +635,19 @@ void DrawDialogUserText (Dialog *dial, short item, StringPtr text, Boolean inver
OffsetRect(&iRect, 0, -1); OffsetRect(&iRect, 0, -1);
inset = ((iRect.right - iRect.left) - (StringWidth(stringCopy) + 2)) / 2; short strWidth = surface->MeasureString(stringCopy);
inset = ((iRect.right - iRect.left) - (strWidth + 2)) / 2;
iRect.left += inset; iRect.left += inset;
iRect.right -= inset; iRect.right -= inset;
TETextBox(newString, textLong, &iRect, teCenter); // Draw centered
PL_NotYetImplemented_TODO("Clip to iRect");
const int32_t ascender = surface->MeasureFontAscender();
const Point centeredDrawPoint = Point::Create((iRect.left + iRect.right - strWidth) / 2, (iRect.top + iRect.bottom + ascender) / 2);
surface->DrawString(centeredDrawPoint, stringCopy);
if (invert) if (invert)
{ {
OffsetRect(&iRect, 0, 1); OffsetRect(&iRect, 0, 1);
@@ -680,8 +672,8 @@ void DrawDialogUserText2 (Dialog *dial, short item, StringPtr text)
PasStringCopy(text, stringCopy); PasStringCopy(text, stringCopy);
GetDialogItem(dial, item, &iType, &iHandle, &iRect); GetDialogItem(dial, item, &iType, &iHandle, &iRect);
if ((StringWidth(stringCopy) + 2) > (iRect.right - iRect.left)) if ((surface->MeasureString(stringCopy) + 2) > (iRect.right - iRect.left))
CollapseStringToWidth(stringCopy, iRect.right - iRect.left - 2); CollapseStringToWidth(surface, stringCopy, iRect.right - iRect.left - 2);
surface->SetForeColor(StdColors::Black()); surface->SetForeColor(StdColors::Black());
surface->DrawString(Point::Create(iRect.left, iRect.bottom), stringCopy); surface->DrawString(Point::Create(iRect.left, iRect.bottom), stringCopy);
@@ -723,12 +715,8 @@ void FrameDialogItem (Dialog *theDialog, short item)
void FrameDialogItemC (Dialog *theDialog, short item, long color) void FrameDialogItemC (Dialog *theDialog, short item, long color)
{ {
Rect itemRect;
ControlHandle itemHandle;
short itemType;
DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface(); DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface();
const Rect itemRect = theDialog->GetItems()[item - 1].GetWidget()->GetRect();
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]); surface->SetForeColor(PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]);

View File

@@ -183,7 +183,7 @@ void PasStringConcat (StringPtr, const PLPasStr &);
void GetLineOfText (StringPtr, short, StringPtr); void GetLineOfText (StringPtr, short, StringPtr);
void WrapText (StringPtr, short); void WrapText (StringPtr, short);
void GetFirstWordOfString (StringPtr, StringPtr); void GetFirstWordOfString (StringPtr, StringPtr);
void CollapseStringToWidth (StringPtr, short); void CollapseStringToWidth (DrawSurface *, StringPtr, short);
void GetChooserName (StringPtr); void GetChooserName (StringPtr);
StringPtr GetLocalizedString (short, StringPtr); StringPtr GetLocalizedString (short, StringPtr);
@@ -198,7 +198,7 @@ void RedAlert (short);
void LoadGraphic (DrawSurface *, short); void LoadGraphic (DrawSurface *, short);
void LoadScaledGraphic (DrawSurface *, short, Rect *); void LoadScaledGraphic (DrawSurface *, short, Rect *);
void LargeIconPlot (Rect *, short); void LargeIconPlot (Rect *, short);
void DrawCIcon (short, short, short); void DrawCIcon (DrawSurface *surface, short, short, short);
char KeyMapOffsetFromRawKey (char); char KeyMapOffsetFromRawKey (char);
long LongSquareRoot (long); long LongSquareRoot (long);
Boolean WaitForInputEvent (short); Boolean WaitForInputEvent (short);

View File

@@ -141,11 +141,11 @@ void DrawHighScores (DrawSurface *surface)
PasStringConcat(tempStr, thisHouseName); PasStringConcat(tempStr, thisHouseName);
PasStringConcat(tempStr, PSTR(" <20>")); PasStringConcat(tempStr, PSTR(" <20>"));
const Point scoreShadowPoint = Point::Create(scoreLeft + ((kScoreWide - StringWidth(tempStr)) / 2) - 1, dropIt - 66); const Point scoreShadowPoint = Point::Create(scoreLeft + ((kScoreWide - surface->MeasureString(tempStr)) / 2) - 1, dropIt - 66);
surface->SetForeColor(blackColor); surface->SetForeColor(blackColor);
surface->DrawString(scoreShadowPoint, tempStr); surface->DrawString(scoreShadowPoint, tempStr);
const Point scoreTextPoint = Point::Create(scoreLeft + ((kScoreWide - StringWidth(tempStr)) / 2), dropIt - 65); const Point scoreTextPoint = Point::Create(scoreLeft + ((kScoreWide - surface->MeasureString(tempStr)) / 2), dropIt - 65);
surface->SetForeColor(cyanColor); surface->SetForeColor(cyanColor);
surface->DrawString(scoreTextPoint, tempStr); surface->DrawString(scoreTextPoint, tempStr);
@@ -154,7 +154,7 @@ void DrawHighScores (DrawSurface *surface)
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
// message for score #1 // message for score #1
PasStringCopy(thisHousePtr->highScores.banner, tempStr); PasStringCopy(thisHousePtr->highScores.banner, tempStr);
bannerWidth = StringWidth(tempStr); bannerWidth = surface->MeasureString(tempStr);
surface->SetForeColor(blackColor); surface->SetForeColor(blackColor);
const Point topScoreShadowPoint = Point::Create(scoreLeft + (kScoreWide - bannerWidth) / 2, dropIt - kKimsLifted); const Point topScoreShadowPoint = Point::Create(scoreLeft + (kScoreWide - bannerWidth) / 2, dropIt - kKimsLifted);
surface->DrawString(topScoreShadowPoint, tempStr); surface->DrawString(topScoreShadowPoint, tempStr);
@@ -490,9 +490,6 @@ void GetHighScoreName (short place)
Str255 scoreStr, placeStr, tempStr; Str255 scoreStr, placeStr, tempStr;
short item; short item;
Boolean leaving; Boolean leaving;
ModalFilterUPP nameFilterUPP;
nameFilterUPP = NewModalFilterUPP(NameFilter);
InitCursor(); InitCursor();
NumToString(theScore, scoreStr); NumToString(theScore, scoreStr);
@@ -507,7 +504,7 @@ void GetHighScoreName (short place)
while (!leaving) while (!leaving)
{ {
ModalDialog(nameFilterUPP, &item); ModalDialog(NameFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -518,7 +515,6 @@ void GetHighScoreName (short place)
} }
DisposeDialog(theDial); DisposeDialog(theDial);
DisposeModalFilterUPP(nameFilterUPP);
} }
//-------------------------------------------------------------- UpdateBannerDialog //-------------------------------------------------------------- UpdateBannerDialog
@@ -599,9 +595,6 @@ void GetHighScoreBanner (void)
Str255 tempStr; Str255 tempStr;
short item; short item;
Boolean leaving; Boolean leaving;
ModalFilterUPP bannerFilterUPP;
bannerFilterUPP = NewModalFilterUPP(BannerFilter);
PlayPrioritySound(kEnergizeSound, kEnergizePriority); PlayPrioritySound(kEnergizeSound, kEnergizePriority);
BringUpDialog(&theDial, kHighBannerDialogID); BringUpDialog(&theDial, kHighBannerDialogID);
@@ -611,7 +604,7 @@ void GetHighScoreBanner (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(bannerFilterUPP, &item); ModalDialog(BannerFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -620,9 +613,6 @@ void GetHighScoreBanner (void)
leaving = true; leaving = true;
} }
} }
DisposeDialog(theDial);
DisposeModalFilterUPP(bannerFilterUPP);
} }
//-------------------------------------------------------------- OpenHighScoresFile //-------------------------------------------------------------- OpenHighScoresFile

View File

@@ -623,7 +623,7 @@ Boolean GoToFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateGoToDialog(dial); UpdateGoToDialog(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -651,9 +651,7 @@ Boolean GoToFilter (Dialog *dial, EventRecord *event, short *item)
long tempLong; long tempLong;
short item, roomToGoTo; short item, roomToGoTo;
Boolean leaving, canceled; Boolean leaving, canceled;
ModalFilterUPP goToFilterUPP;
goToFilterUPP = NewModalFilterUPP(GoToFilter);
BringUpDialog(&theDialog, kGoToDialogID); BringUpDialog(&theDialog, kGoToDialogID);
if (GetFirstRoomNumber() == thisRoomNumber) if (GetFirstRoomNumber() == thisRoomNumber)
@@ -670,7 +668,7 @@ Boolean GoToFilter (Dialog *dial, EventRecord *event, short *item)
while (!leaving) while (!leaving)
{ {
ModalDialog(goToFilterUPP, &item); ModalDialog(GoToFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -700,7 +698,6 @@ Boolean GoToFilter (Dialog *dial, EventRecord *event, short *item)
} }
DisposeDialog(theDialog); DisposeDialog(theDialog);
DisposeModalFilterUPP(goToFilterUPP);
if (!canceled) if (!canceled)
{ {

View File

@@ -612,7 +612,7 @@ Boolean ReadHouse (void)
short whichRoom; short whichRoom;
// There should be no padding remaining the house type // There should be no padding remaining the house type
PL_STATIC_ASSERT(sizeof(houseType) - sizeof(roomType) == houseType::kBinaryDataSize + 2); GP_STATIC_ASSERT(sizeof(houseType) - sizeof(roomType) == houseType::kBinaryDataSize + 2);
if (!houseOpen) if (!houseOpen)
{ {

View File

@@ -166,7 +166,7 @@ Boolean HouseFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateHouseInfoDialog(dial); UpdateHouseInfoDialog(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -208,9 +208,7 @@ void DoHouseInfo (void)
short item, numRooms, version; short item, numRooms, version;
char wasState; char wasState;
Boolean leaving; Boolean leaving;
ModalFilterUPP houseFilterUPP;
houseFilterUPP = NewModalFilterUPP(HouseFilter);
tempPhoneBit = phoneBitSet; tempPhoneBit = phoneBitSet;
numRooms = RealRoomNumberCount(); numRooms = RealRoomNumberCount();
@@ -246,7 +244,7 @@ void DoHouseInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(houseFilterUPP, &item); ModalDialog(HouseFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -290,7 +288,6 @@ void DoHouseInfo (void)
} }
InitCursor(); InitCursor();
DisposeDialog(houseInfoDialog); DisposeDialog(houseInfoDialog);
DisposeModalFilterUPP(houseFilterUPP);
} }
//-------------------------------------------------------------- WarnLockingHouse //-------------------------------------------------------------- WarnLockingHouse

View File

@@ -690,7 +690,7 @@ Boolean ResumeFilter (Dialog *dial, EventRecord *event, short *item)
case updateEvt: case updateEvt:
if ((WindowPtr)event->message == dial->GetWindow()) if ((WindowPtr)event->message == dial->GetWindow())
{ {
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateResumeDialog(dial); UpdateResumeDialog(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -719,9 +719,6 @@ short QueryResumeGame (void)
short hitWhat, hadGliders; short hitWhat, hadGliders;
char wasState; char wasState;
Boolean leaving; Boolean leaving;
ModalFilterUPP resumeFilterUPP;
resumeFilterUPP = NewModalFilterUPP(ResumeFilter);
// get score & num. gliders // get score & num. gliders
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
@@ -746,14 +743,13 @@ short QueryResumeGame (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(resumeFilterUPP, &hitWhat); ModalDialog(ResumeFilter, &hitWhat);
if ((hitWhat == kSheWantsNewGame) || (hitWhat == kSheWantsResumeGame)) if ((hitWhat == kSheWantsNewGame) || (hitWhat == kSheWantsResumeGame))
{ {
leaving = true; leaving = true;
} }
} }
DisposeDialog(theDial); DisposeDialog(theDial);
DisposeModalFilterUPP(resumeFilterUPP);
return (hitWhat); return (hitWhat);
} }

View File

@@ -1067,7 +1067,7 @@ void DrawCalendar (Rect *theRect)
GetTime(&timeRec); GetTime(&timeRec);
GetIndString(monthStr, kMonthStringID, timeRec.month); GetIndString(monthStr, kMonthStringID, timeRec.month);
const Point textPos = Point::Create(theRect->left + ((64 - StringWidth(monthStr)) / 2), theRect->top + 55); const Point textPos = Point::Create(theRect->left + ((64 - backSrcMap->MeasureString(monthStr)) / 2), theRect->top + 55);
ColorText(backSrcMap, textPos, monthStr, kDarkFleshColor); ColorText(backSrcMap, textPos, monthStr, kDarkFleshColor);
} }

View File

@@ -386,7 +386,7 @@ Boolean BlowerFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateBlowerInfo(dial); UpdateBlowerInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -421,7 +421,7 @@ Boolean FurnitureFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateFurnitureInfo(dial); UpdateFurnitureInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -456,7 +456,7 @@ Boolean CustPictFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateCustPictInfo(dial); UpdateCustPictInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -497,7 +497,7 @@ Boolean SwitchFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateSwitchInfo(dial); UpdateSwitchInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -543,7 +543,7 @@ Boolean TriggerFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateTriggerInfo(dial); UpdateTriggerInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -592,7 +592,7 @@ Boolean LightFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateLightInfo(dial); UpdateLightInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -646,7 +646,7 @@ Boolean ApplianceFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateApplianceInfo(dial); UpdateApplianceInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -695,7 +695,7 @@ Boolean MicrowaveFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateMicrowaveInfo(dial); UpdateMicrowaveInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -736,7 +736,7 @@ Boolean GreaseFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateGreaseInfo(dial); UpdateGreaseInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -771,7 +771,7 @@ Boolean InvisBonusFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateInvisBonusInfo(dial); UpdateInvisBonusInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -812,7 +812,7 @@ Boolean TransFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateTransInfo(dial); UpdateTransInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -866,7 +866,7 @@ Boolean EnemyFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateEnemyInfo(dial); UpdateEnemyInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -915,7 +915,7 @@ Boolean FlowerFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateFlowerInfo(dial); UpdateFlowerInfo(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -936,9 +936,6 @@ void DoBlowerObjectInfo (short what)
Str255 numberStr, kindStr, distStr; Str255 numberStr, kindStr, distStr;
short item, initial; short item, initial;
Boolean leaving, doReturn, leftFacing; Boolean leaving, doReturn, leftFacing;
ModalFilterUPP blowerFilterUPP;
blowerFilterUPP = NewModalFilterUPP(BlowerFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -995,7 +992,7 @@ void DoBlowerObjectInfo (short what)
while (!leaving) while (!leaving)
{ {
ModalDialog(blowerFilterUPP, &item); ModalDialog(BlowerFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -1092,7 +1089,6 @@ void DoBlowerObjectInfo (short what)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(blowerFilterUPP);
if (doReturn) if (doReturn)
{ {
@@ -1109,9 +1105,6 @@ void DoFurnitureObjectInfo (void)
Str255 numberStr, kindStr; Str255 numberStr, kindStr;
short item; short item;
Boolean leaving, doReturn; Boolean leaving, doReturn;
ModalFilterUPP furnitureFilterUPP;
furnitureFilterUPP = NewModalFilterUPP(FurnitureFilter);
if (objActive == kInitialGliderSelected) if (objActive == kInitialGliderSelected)
{ {
@@ -1145,7 +1138,7 @@ void DoFurnitureObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(furnitureFilterUPP, &item); ModalDialog(FurnitureFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
leaving = true; leaving = true;
@@ -1157,7 +1150,6 @@ void DoFurnitureObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(furnitureFilterUPP);
if (doReturn) if (doReturn)
{ {
@@ -1175,9 +1167,6 @@ void DoCustPictObjectInfo (void)
long wasPict; long wasPict;
short item; short item;
Boolean leaving; Boolean leaving;
ModalFilterUPP custPictFilterUPP;
custPictFilterUPP = NewModalFilterUPP(CustPictFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -1202,7 +1191,7 @@ void DoCustPictObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(custPictFilterUPP, &item); ModalDialog(CustPictFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -1260,7 +1249,6 @@ void DoCustPictObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(custPictFilterUPP);
} }
//-------------------------------------------------------------- DoSwitchObjectInfo //-------------------------------------------------------------- DoSwitchObjectInfo
@@ -1271,9 +1259,6 @@ void DoSwitchObjectInfo (void)
Str255 numberStr, kindStr, roomStr, tempStr, objStr; Str255 numberStr, kindStr, roomStr, tempStr, objStr;
short item, floor, suite; short item, floor, suite;
Boolean leaving, doLink, doGoTo, doReturn; Boolean leaving, doLink, doGoTo, doReturn;
ModalFilterUPP switchFilterUPP;
switchFilterUPP = NewModalFilterUPP(SwitchFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -1310,7 +1295,7 @@ void DoSwitchObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(switchFilterUPP, &item); ModalDialog(SwitchFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -1363,7 +1348,6 @@ void DoSwitchObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(switchFilterUPP);
if (doLink) if (doLink)
{ {
@@ -1394,9 +1378,6 @@ void DoTriggerObjectInfo (void)
long delayIs; long delayIs;
short item, floor, suite; short item, floor, suite;
Boolean leaving, doLink, doGoTo, doReturn; Boolean leaving, doLink, doGoTo, doReturn;
ModalFilterUPP triggerFilterUPP;
triggerFilterUPP = NewModalFilterUPP(TriggerFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -1437,7 +1418,7 @@ void DoTriggerObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(triggerFilterUPP, &item); ModalDialog(TriggerFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -1519,7 +1500,6 @@ void DoTriggerObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(triggerFilterUPP);
if (doLink) if (doLink)
{ {
@@ -1549,9 +1529,6 @@ void DoLightObjectInfo (void)
Str255 numberStr, kindStr; Str255 numberStr, kindStr;
short item, initial; short item, initial;
Boolean leaving, doReturn; Boolean leaving, doReturn;
ModalFilterUPP lightFilterUPP;
lightFilterUPP = NewModalFilterUPP(LightFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -1578,7 +1555,7 @@ void DoLightObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(lightFilterUPP, &item); ModalDialog(LightFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -1618,7 +1595,6 @@ void DoLightObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(lightFilterUPP);
if (doReturn) if (doReturn)
{ {
@@ -1636,9 +1612,6 @@ void DoApplianceObjectInfo (short what)
long delay; long delay;
short item, initial; short item, initial;
Boolean leaving, doReturn; Boolean leaving, doReturn;
ModalFilterUPP applianceFilterUPP;
applianceFilterUPP = NewModalFilterUPP(ApplianceFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -1670,7 +1643,7 @@ void DoApplianceObjectInfo (short what)
while (!leaving) while (!leaving)
{ {
ModalDialog(applianceFilterUPP, &item); ModalDialog(ApplianceFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -1734,7 +1707,6 @@ void DoApplianceObjectInfo (short what)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(applianceFilterUPP);
if (doReturn) if (doReturn)
{ {
@@ -1751,9 +1723,6 @@ void DoMicrowaveObjectInfo (void)
Str255 numberStr, kindStr; Str255 numberStr, kindStr;
short item, initial, kills; short item, initial, kills;
Boolean leaving, doReturn; Boolean leaving, doReturn;
ModalFilterUPP microwaveFilterUPP;
microwaveFilterUPP = NewModalFilterUPP(MicrowaveFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -1788,7 +1757,7 @@ void DoMicrowaveObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(microwaveFilterUPP, &item); ModalDialog(MicrowaveFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -1858,7 +1827,6 @@ void DoMicrowaveObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(microwaveFilterUPP);
if (doReturn) if (doReturn)
{ {
@@ -1875,9 +1843,6 @@ void DoGreaseObjectInfo (void)
Str255 numberStr, kindStr; Str255 numberStr, kindStr;
short item; short item;
Boolean leaving, wasSpilled, doReturn; Boolean leaving, wasSpilled, doReturn;
ModalFilterUPP greaseFilterUPP;
greaseFilterUPP = NewModalFilterUPP(GreaseFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -1895,7 +1860,7 @@ void DoGreaseObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(greaseFilterUPP, &item); ModalDialog(GreaseFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -1932,7 +1897,6 @@ void DoGreaseObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(greaseFilterUPP);
if (doReturn) if (doReturn)
{ {
@@ -1949,9 +1913,6 @@ void DoInvisBonusObjectInfo (void)
Str255 numberStr, kindStr; Str255 numberStr, kindStr;
short item; short item;
Boolean leaving, doReturn; Boolean leaving, doReturn;
ModalFilterUPP invisBonusFilterUPP;
invisBonusFilterUPP = NewModalFilterUPP(InvisBonusFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -1982,7 +1943,7 @@ void DoInvisBonusObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(invisBonusFilterUPP, &item); ModalDialog(InvisBonusFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -2045,7 +2006,6 @@ void DoInvisBonusObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(invisBonusFilterUPP);
if (doReturn) if (doReturn)
{ {
@@ -2062,9 +2022,6 @@ void DoTransObjectInfo (short what)
Str255 numberStr, kindStr, roomStr, tempStr, objStr; Str255 numberStr, kindStr, roomStr, tempStr, objStr;
short item, floor, suite; short item, floor, suite;
Boolean leaving, doLink, doGoTo, doReturn, wasState; Boolean leaving, doLink, doGoTo, doReturn, wasState;
ModalFilterUPP transFilterUPP;
transFilterUPP = NewModalFilterUPP(TransFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -2108,7 +2065,7 @@ void DoTransObjectInfo (short what)
while (!leaving) while (!leaving)
{ {
ModalDialog(transFilterUPP, &item); ModalDialog(TransFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -2155,7 +2112,6 @@ void DoTransObjectInfo (short what)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(transFilterUPP);
if (doLink) if (doLink)
{ {
@@ -2186,9 +2142,6 @@ void DoEnemyObjectInfo (short what)
long delay; long delay;
short item, initial; short item, initial;
Boolean leaving, doReturn; Boolean leaving, doReturn;
ModalFilterUPP enemyFilterUPP;
enemyFilterUPP = NewModalFilterUPP(EnemyFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -2220,7 +2173,7 @@ void DoEnemyObjectInfo (short what)
while (!leaving) while (!leaving)
{ {
ModalDialog(enemyFilterUPP, &item); ModalDialog(EnemyFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -2278,7 +2231,6 @@ void DoEnemyObjectInfo (short what)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(enemyFilterUPP);
if (doReturn) if (doReturn)
{ {
@@ -2295,9 +2247,6 @@ void DoFlowerObjectInfo (void)
Str255 numberStr, kindStr; Str255 numberStr, kindStr;
short item, flower; short item, flower;
Boolean leaving, doReturn; Boolean leaving, doReturn;
ModalFilterUPP flowerFilterUPP;
flowerFilterUPP = NewModalFilterUPP(FlowerFilter);
NumToString(objActive + 1, numberStr); NumToString(objActive + 1, numberStr);
GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what); GetIndString(kindStr, kObjectNameStrings, thisRoom->objects[objActive].what);
@@ -2316,7 +2265,7 @@ void DoFlowerObjectInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(flowerFilterUPP, &item); ModalDialog(FlowerFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -2377,7 +2326,6 @@ void DoFlowerObjectInfo (void)
} }
DisposeDialog(infoDial); DisposeDialog(infoDial);
DisposeModalFilterUPP(flowerFilterUPP);
if (doReturn) if (doReturn)
{ {

View File

@@ -406,7 +406,7 @@ Boolean RoomFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateRoomInfoDialog(dial); UpdateRoomInfoDialog(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -434,11 +434,8 @@ void DoRoomInfo (void)
short item, i, newBack; short item, i, newBack;
char wasState; char wasState;
Boolean leaving, wasFirstRoom, forceDraw; Boolean leaving, wasFirstRoom, forceDraw;
ModalFilterUPP roomFilterUPP;
PLError_t theErr; PLError_t theErr;
roomFilterUPP = NewModalFilterUPP(RoomFilter);
tileOver = -1; tileOver = -1;
cursorIs = kArrowCursor; cursorIs = kArrowCursor;
tempBack = thisRoom->background; tempBack = thisRoom->background;
@@ -503,7 +500,7 @@ void DoRoomInfo (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(roomFilterUPP, &item); ModalDialog(RoomFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -598,7 +595,6 @@ void DoRoomInfo (void)
InitCursor(); InitCursor();
DisposeDialog(roomInfoDialog); DisposeDialog(roomInfoDialog);
DisposeModalFilterUPP(roomFilterUPP);
// KillOffScreenPixMap(tileSrcMap); // KillOffScreenPixMap(tileSrcMap);
DisposeGWorld(tileSrcMap); DisposeGWorld(tileSrcMap);
@@ -727,7 +723,7 @@ Boolean OriginalArtFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateOriginalArt(dial); UpdateOriginalArt(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -750,9 +746,6 @@ short ChooseOriginalArt (short was)
long longID; long longID;
short item, newPictID, tempShort, wasPictID; short item, newPictID, tempShort, wasPictID;
Boolean leaving; Boolean leaving;
ModalFilterUPP originalArtFilterUPP;
originalArtFilterUPP = NewModalFilterUPP(OriginalArtFilter);
if (was < kUserBackground) if (was < kUserBackground)
was = kUserBackground; was = kUserBackground;
@@ -790,7 +783,7 @@ short ChooseOriginalArt (short was)
while (!leaving) while (!leaving)
{ {
ModalDialog(originalArtFilterUPP, &item); ModalDialog(OriginalArtFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -855,7 +848,6 @@ short ChooseOriginalArt (short was)
} }
DisposeDialog(theDialog); DisposeDialog(theDialog);
DisposeModalFilterUPP(originalArtFilterUPP);
return (newPictID); return (newPictID);
} }

View File

@@ -157,7 +157,7 @@ void PageUpHouses (Dialog *theDial)
{ {
GetDialogItemRect(theDial, kScrollUpItem, &tempRect); GetDialogItemRect(theDial, kScrollUpItem, &tempRect);
HideDialogItem(theDial, kScrollUpItem); HideDialogItem(theDial, kScrollUpItem);
DrawCIcon(kGrayedOutUpArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutUpArrow, tempRect.left, tempRect.top);
} }
QSetRect(&tempRect, 8, 39, 421, 223); QSetRect(&tempRect, 8, 39, 421, 223);
@@ -191,7 +191,7 @@ void PageDownHouses (Dialog *theDial)
{ {
GetDialogItemRect(theDial, kScrollDownItem, &tempRect); GetDialogItemRect(theDial, kScrollDownItem, &tempRect);
HideDialogItem(theDial, kScrollDownItem); HideDialogItem(theDial, kScrollDownItem);
DrawCIcon(kGrayedOutDownArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top);
} }
QSetRect(&tempRect, 8, 39, 421, 223); QSetRect(&tempRect, 8, 39, 421, 223);
@@ -367,20 +367,20 @@ void DoLoadHouse (void)
Dialog *theDial; Dialog *theDial;
short i, item, wasIndex, screenCount; short i, item, wasIndex, screenCount;
Boolean leaving, whoCares; Boolean leaving, whoCares;
ModalFilterUPP loadFilterUPP;
loadFilterUPP = NewModalFilterUPP(LoadFilter);
BringUpDialog(&theDial, kLoadHouseDialogID); BringUpDialog(&theDial, kLoadHouseDialogID);
DrawSurface *surface = theDial->GetWindow()->GetDrawSurface();
if (housesFound <= kDispFiles) if (housesFound <= kDispFiles)
{ {
GetDialogItemRect(theDial, kScrollUpItem, &tempRect); GetDialogItemRect(theDial, kScrollUpItem, &tempRect);
HideDialogItem(theDial, kScrollUpItem); HideDialogItem(theDial, kScrollUpItem);
DrawCIcon(kGrayedOutUpArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutUpArrow, tempRect.left, tempRect.top);
GetDialogItemRect(theDial, kScrollDownItem, &tempRect); GetDialogItemRect(theDial, kScrollDownItem, &tempRect);
HideDialogItem(theDial, kScrollDownItem); HideDialogItem(theDial, kScrollDownItem);
DrawCIcon(kGrayedOutDownArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top);
} }
else else
{ {
@@ -388,13 +388,13 @@ void DoLoadHouse (void)
{ {
GetDialogItemRect(theDial, kScrollUpItem, &tempRect); GetDialogItemRect(theDial, kScrollUpItem, &tempRect);
HideDialogItem(theDial, kScrollUpItem); HideDialogItem(theDial, kScrollUpItem);
DrawCIcon(kGrayedOutUpArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutUpArrow, tempRect.left, tempRect.top);
} }
else if (thisHouseIndex > (housesFound - kDispFiles)) else if (thisHouseIndex > (housesFound - kDispFiles))
{ {
GetDialogItemRect(theDial, kScrollDownItem, &tempRect); GetDialogItemRect(theDial, kScrollDownItem, &tempRect);
HideDialogItem(theDial, kScrollDownItem); HideDialogItem(theDial, kScrollDownItem);
DrawCIcon(kGrayedOutDownArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top);
} }
} }
wasIndex = thisHouseIndex; wasIndex = thisHouseIndex;
@@ -415,7 +415,7 @@ void DoLoadHouse (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(loadFilterUPP, &item); ModalDialog(LoadFilter, &item);
if (item == kOkayButton) if (item == kOkayButton)
{ {
@@ -516,7 +516,6 @@ void DoLoadHouse (void)
} }
DisposeDialog(theDial); DisposeDialog(theDial);
DisposeModalFilterUPP(loadFilterUPP);
} }
#endif #endif

View File

@@ -9,6 +9,7 @@
#include "PLSound.h" #include "PLSound.h"
#include "PLStandardColors.h" #include "PLStandardColors.h"
#include "PLTextUtils.h" #include "PLTextUtils.h"
#include "PLTimeTaggedVOSEvent.h"
#include "DialogManager.h" #include "DialogManager.h"
#include "DialogUtils.h" #include "DialogUtils.h"
#include "Externs.h" #include "Externs.h"
@@ -79,7 +80,7 @@ void DisplayUpdate (Dialog *);
Boolean DisplayFilter (Dialog *, EventRecord *, short *); Boolean DisplayFilter (Dialog *, EventRecord *, short *);
void DoDisplayPrefs (void); void DoDisplayPrefs (void);
void SetAllDefaults (void); void SetAllDefaults (void);
void FlashSettingsButton (short); void FlashSettingsButton (DrawSurface *, short);
void UpdateSettingsMain (Dialog *); void UpdateSettingsMain (Dialog *);
Boolean PrefsFilter (Dialog *, EventRecord *, short *); Boolean PrefsFilter (Dialog *, EventRecord *, short *);
void BitchAboutChanges (void); void BitchAboutChanges (void);
@@ -204,7 +205,7 @@ Boolean BrainsFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateSettingsBrains(dial); UpdateSettingsBrains(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -225,9 +226,6 @@ void DoBrainsPrefs (void)
long tempLong; long tempLong;
short itemHit, wasMaxFiles; short itemHit, wasMaxFiles;
Boolean leaving; Boolean leaving;
ModalFilterUPP brainsFilterUPP;
brainsFilterUPP = NewModalFilterUPP(BrainsFilter);
BringUpDialog(&prefDlg, kBrainsPrefsDialID); BringUpDialog(&prefDlg, kBrainsPrefsDialID);
leaving = false; leaving = false;
@@ -251,7 +249,7 @@ void DoBrainsPrefs (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(brainsFilterUPP, &itemHit); ModalDialog(BrainsFilter, &itemHit);
switch (itemHit) switch (itemHit)
{ {
case kOkayButton: case kOkayButton:
@@ -320,7 +318,6 @@ void DoBrainsPrefs (void)
} }
DisposeDialog(prefDlg); DisposeDialog(prefDlg);
DisposeModalFilterUPP(brainsFilterUPP);
} }
//-------------------------------------------------------------- SetControlsToDefaults //-------------------------------------------------------------- SetControlsToDefaults
@@ -491,7 +488,7 @@ Boolean ControlFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateSettingsControl(dial); UpdateSettingsControl(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -511,9 +508,6 @@ void DoControlPrefs (void)
Dialog *prefDlg; Dialog *prefDlg;
short i, itemHit; short i, itemHit;
Boolean leaving; Boolean leaving;
ModalFilterUPP controlFilterUPP;
controlFilterUPP = NewModalFilterUPP(ControlFilter);
// CenterDialog(kControlPrefsDialID); // CenterDialog(kControlPrefsDialID);
prefDlg = PortabilityLayer::DialogManager::GetInstance()->LoadDialog(kControlPrefsDialID, kPutInFront); prefDlg = PortabilityLayer::DialogManager::GetInstance()->LoadDialog(kControlPrefsDialID, kPutInFront);
@@ -551,7 +545,7 @@ void DoControlPrefs (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(controlFilterUPP, &itemHit); ModalDialog(ControlFilter, &itemHit);
switch (itemHit) switch (itemHit)
{ {
case kOkayButton: case kOkayButton:
@@ -609,7 +603,6 @@ void DoControlPrefs (void)
} }
DisposeDialog(prefDlg); DisposeDialog(prefDlg);
DisposeModalFilterUPP(controlFilterUPP);
} }
//-------------------------------------------------------------- SoundDefaults //-------------------------------------------------------------- SoundDefaults
@@ -754,7 +747,7 @@ Boolean SoundFilter (Dialog *dial, EventRecord *event, short *item)
break; break;
case updateEvt: case updateEvt:
SetPort((GrafPtr)dial); SetPortDialogPort(dial);
UpdateSettingsSound(dial); UpdateSettingsSound(dial);
EndUpdate(dial->GetWindow()); EndUpdate(dial->GetWindow());
event->what = nullEvent; event->what = nullEvent;
@@ -777,12 +770,11 @@ void DoSoundPrefs (void)
PLError_t theErr; PLError_t theErr;
short itemHit; short itemHit;
Boolean leaving; Boolean leaving;
ModalFilterUPP soundFilterUPP;
soundFilterUPP = NewModalFilterUPP(SoundFilter);
BringUpDialog(&prefDlg, kSoundPrefsDialID); BringUpDialog(&prefDlg, kSoundPrefsDialID);
DrawSurface *surface = prefDlg->GetWindow()->GetDrawSurface();
UnivGetSoundVolume(&wasLoudness, thisMac.hasSM3); UnivGetSoundVolume(&wasLoudness, thisMac.hasSM3);
wasIdle = isPlayMusicIdle; wasIdle = isPlayMusicIdle;
@@ -793,7 +785,7 @@ void DoSoundPrefs (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(soundFilterUPP, &itemHit); ModalDialog(SoundFilter, &itemHit);
switch (itemHit) switch (itemHit)
{ {
case kOkayButton: case kOkayButton:
@@ -832,7 +824,7 @@ void DoSoundPrefs (void)
if (tempVolume > 0) if (tempVolume > 0)
{ {
GetDialogItemRect(prefDlg, kSofterItem, &tempRect); GetDialogItemRect(prefDlg, kSofterItem, &tempRect);
DrawCIcon(1034, tempRect.left, tempRect.top); DrawCIcon(surface, 1034, tempRect.left, tempRect.top);
tempVolume--; tempVolume--;
SetDialogNumToStr(prefDlg, kVolNumberItem, (long)tempVolume); SetDialogNumToStr(prefDlg, kVolNumberItem, (long)tempVolume);
UnivSetSoundVolume(tempVolume, thisMac.hasSM3); UnivSetSoundVolume(tempVolume, thisMac.hasSM3);
@@ -847,7 +839,7 @@ void DoSoundPrefs (void)
if (tempVolume < 7) if (tempVolume < 7)
{ {
GetDialogItemRect(prefDlg, kLouderItem, &tempRect); GetDialogItemRect(prefDlg, kLouderItem, &tempRect);
DrawCIcon(1033, tempRect.left, tempRect.top); DrawCIcon(surface, 1033, tempRect.left, tempRect.top);
tempVolume++; tempVolume++;
if (tempVolume == 7) if (tempVolume == 7)
SetDialogNumToStr(prefDlg, kVolNumberItem, 11L); SetDialogNumToStr(prefDlg, kVolNumberItem, 11L);
@@ -892,7 +884,6 @@ void DoSoundPrefs (void)
} }
DisposeDialog(prefDlg); DisposeDialog(prefDlg);
DisposeModalFilterUPP(soundFilterUPP);
} }
//-------------------------------------------------------------- DisplayDefaults //-------------------------------------------------------------- DisplayDefaults
@@ -943,7 +934,6 @@ void FrameDisplayIcon (Dialog *theDialog)
void DisplayUpdate (Dialog *theDialog) void DisplayUpdate (Dialog *theDialog)
{ {
DrawDialog(theDialog);
DrawDefaultButton(theDialog); DrawDefaultButton(theDialog);
SetDialogItemValue(theDialog, kDoColorFadeItem, (short)wasFade); SetDialogItemValue(theDialog, kDoColorFadeItem, (short)wasFade);
@@ -962,155 +952,114 @@ void DisplayUpdate (Dialog *theDialog)
//-------------------------------------------------------------- DisplayFilter //-------------------------------------------------------------- DisplayFilter
Boolean DisplayFilter (Dialog *dial, EventRecord *event, short *item) int16_t DisplayFilter(Dialog *dial, const TimeTaggedVOSEvent &evt)
{ {
switch (event->what) if (evt.IsKeyDownEvent())
{ {
case keyDown: switch (PackVOSKeyCode(evt.m_vosEvent.m_event.m_keyboardInputEvent))
switch (event->message)
{ {
case PL_KEY_SPECIAL(kEnter): case PL_KEY_SPECIAL(kEnter):
case PL_KEY_NUMPAD_SPECIAL(kEnter): case PL_KEY_NUMPAD_SPECIAL(kEnter):
FlashDialogButton(dial, kOkayButton); FlashDialogButton(dial, kOkayButton);
*item = kOkayButton; return kOkayButton;
return(true);
break;
case PL_KEY_SPECIAL(kEscape): case PL_KEY_SPECIAL(kEscape):
FlashDialogButton(dial, kCancelButton); FlashDialogButton(dial, kCancelButton);
*item = kCancelButton; return kCancelButton;
return(true);
break;
case PL_KEY_SPECIAL(kLeftArrow): case PL_KEY_SPECIAL(kLeftArrow):
switch (numNeighbors) switch (numNeighbors)
{ {
case 1: case 1:
*item = kDisplay9Item; return kDisplay9Item;
break;
case 3: case 3:
*item = kDisplay1Item; return kDisplay1Item;
break;
case 9: case 9:
*item = kDisplay3Item; return kDisplay3Item;
break;
}
return(true);
break;
case PL_KEY_SPECIAL(kRightArrow):
switch (numNeighbors)
{
case 1:
*item = kDisplay3Item;
break;
case 3:
*item = kDisplay9Item;
break;
case 9:
*item = kDisplay1Item;
break;
}
return(true);
break;
case PL_KEY_SPECIAL(kUpArrow):
switch (wasDepthPref)
{
case kSwitchIfNeeded:
*item = k16Depth;
break;
case kSwitchTo256Colors:
*item = kCurrentDepth;
break;
case kSwitchTo16Grays:
*item = k256Depth;
break;
}
return(true);
break;
case PL_KEY_SPECIAL(kDownArrow):
switch (wasDepthPref)
{
case kSwitchIfNeeded:
*item = k256Depth;
break;
case kSwitchTo256Colors:
*item = k16Depth;
break;
case kSwitchTo16Grays:
*item = kCurrentDepth;
break;
}
return(true);
break;
case PL_KEY_ASCII('1'):
*item = kDisplay1Item;
return(true);
break;
case PL_KEY_ASCII('3'):
*item = kDisplay3Item;
return(true);
break;
case PL_KEY_ASCII('9'):
*item = kDisplay9Item;
return(true);
break;
case PL_KEY_ASCII('B'):
*item = kDoColorFadeItem;
return(true);
break;
case PL_KEY_ASCII('D'):
*item = kDispDefault;
FlashDialogButton(dial, kDispDefault);
return(true);
break;
case PL_KEY_ASCII('R'):
*item = kUseScreen2Item;
FlashDialogButton(dial, kUseQDItem);
return(true);
break;
case PL_KEY_ASCII('U'):
*item = kUseQDItem;
return(true);
break;
default: default:
return(false); return -1;
} }
break; break;
case mouseDown: case PL_KEY_SPECIAL(kRightArrow):
return(false); switch (numNeighbors)
break; {
case 1:
return kDisplay3Item;
case updateEvt: case 3:
SetPort((GrafPtr)dial); return kDisplay9Item;
DisplayUpdate(dial);
EndUpdate(dial->GetWindow()); case 9:
event->what = nullEvent; return kDisplay1Item;
return(false);
break; default:
return -1;
}
break;
case PL_KEY_SPECIAL(kUpArrow):
switch (wasDepthPref)
{
case kSwitchIfNeeded:
return k16Depth;
case kSwitchTo256Colors:
return kCurrentDepth;
case kSwitchTo16Grays:
return k256Depth;
default:
return -1;
}
break;
case PL_KEY_SPECIAL(kDownArrow):
switch (wasDepthPref)
{
case kSwitchIfNeeded:
return k256Depth;
case kSwitchTo256Colors:
return k16Depth;
case kSwitchTo16Grays:
return kCurrentDepth;
}
break;
case PL_KEY_ASCII('1'):
return kDisplay1Item;
case PL_KEY_ASCII('3'):
return kDisplay3Item;
case PL_KEY_ASCII('9'):
return kDisplay9Item;
case PL_KEY_ASCII('B'):
return kDoColorFadeItem;
case PL_KEY_ASCII('D'):
FlashDialogButton(dial, kDispDefault);
return kDispDefault;
case PL_KEY_ASCII('R'):
PL_NotYetImplemented_TODO("FixMe"); // GP: This looks like a bug
FlashDialogButton(dial, kUseQDItem);
return kUseScreen2Item;
case PL_KEY_ASCII('U'):
return kUseQDItem;
default: default:
return(false); return(false);
break; }
} }
} }
@@ -1119,13 +1068,13 @@ Boolean DisplayFilter (Dialog *dial, EventRecord *event, short *item)
void DoDisplayPrefs (void) void DoDisplayPrefs (void)
{ {
Dialog *prefDlg; Dialog *prefDlg;
short itemHit, wasNeighbors; short wasNeighbors;
Boolean leaving; Boolean leaving;
ModalFilterUPP displayFilterUPP;
displayFilterUPP = NewModalFilterUPP(DisplayFilter);
BringUpDialog(&prefDlg, kDisplayPrefsDialID); BringUpDialog(&prefDlg, kDisplayPrefsDialID);
DisplayUpdate(prefDlg);
if (!thisMac.can8Bit) if (!thisMac.can8Bit)
{ {
MyDisableControl(prefDlg, kDoColorFadeItem); MyDisableControl(prefDlg, kDoColorFadeItem);
@@ -1143,7 +1092,7 @@ void DoDisplayPrefs (void)
while (!leaving) while (!leaving)
{ {
ModalDialog(displayFilterUPP, &itemHit); int16_t itemHit = prefDlg->ExecuteModal(DisplayFilter);
switch (itemHit) switch (itemHit)
{ {
case kOkayButton: case kOkayButton:
@@ -1225,8 +1174,7 @@ void DoDisplayPrefs (void)
} }
} }
DisposeDialog(prefDlg); prefDlg->Destroy();
DisposeModalFilterUPP(displayFilterUPP);
} }
//-------------------------------------------------------------- SetAllDefaults //-------------------------------------------------------------- SetAllDefaults
@@ -1282,17 +1230,17 @@ void SetAllDefaults (void)
//-------------------------------------------------------------- FlashSettingsButton //-------------------------------------------------------------- FlashSettingsButton
void FlashSettingsButton (short who) void FlashSettingsButton (DrawSurface *surface, short who)
{ {
#define kNormalSettingsIcon 1010 #define kNormalSettingsIcon 1010
#define kInvertedSettingsIcon 1014 #define kInvertedSettingsIcon 1014
short theID; short theID;
theID = kInvertedSettingsIcon + who; theID = kInvertedSettingsIcon + who;
DrawCIcon (theID, prefButton[who].left + 4, prefButton[who].top + 4); DrawCIcon (surface, theID, prefButton[who].left + 4, prefButton[who].top + 4);
DelayTicks(8); DelayTicks(8);
theID = kNormalSettingsIcon + who; theID = kNormalSettingsIcon + who;
DrawCIcon (theID, prefButton[who].left + 4, prefButton[who].top + 4); DrawCIcon (surface, theID, prefButton[who].left + 4, prefButton[who].top + 4);
} }
//-------------------------------------------------------------- UpdateSettingsMain //-------------------------------------------------------------- UpdateSettingsMain
@@ -1302,8 +1250,6 @@ void UpdateSettingsMain (Dialog *theDialog)
Str255 theStr; Str255 theStr;
DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface(); DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface();
DrawDialog(theDialog);
DrawDefaultButton(theDialog); DrawDefaultButton(theDialog);
GetIndString(theStr, 129, 1); GetIndString(theStr, 129, 1);
@@ -1323,86 +1269,56 @@ void UpdateSettingsMain (Dialog *theDialog)
//-------------------------------------------------------------- PrefsFilter //-------------------------------------------------------------- PrefsFilter
Boolean PrefsFilter (Dialog *dial, EventRecord *event, short *item) int16_t PrefsFilter (Dialog *dial, const TimeTaggedVOSEvent &evt)
{ {
Point testPt;
short i; short i;
Boolean foundHit; Boolean foundHit;
switch (event->what) if (evt.IsKeyDownEvent())
{ {
case keyDown: intptr_t packedKey = PackVOSKeyCode(evt.m_vosEvent.m_event.m_keyboardInputEvent);
switch (event->message)
switch (packedKey)
{ {
case PL_KEY_SPECIAL(kEnter): case PL_KEY_SPECIAL(kEnter):
case PL_KEY_NUMPAD_SPECIAL(kEnter): case PL_KEY_NUMPAD_SPECIAL(kEnter):
FlashDialogButton(dial, kOkayButton); FlashDialogButton(dial, kOkayButton);
*item = kOkayButton; return kOkayButton;
return(true);
break;
case PL_KEY_ASCII('B'): case PL_KEY_ASCII('B'):
*item = kBrainsButton; return kBrainsButton;
return(true);
break;
case PL_KEY_ASCII('C'): case PL_KEY_ASCII('C'):
*item = kControlsButton; return kControlsButton;
return(true);
break;
case PL_KEY_ASCII('d'): case PL_KEY_ASCII('d'):
*item = kDisplayButton; return kDisplayButton;
return(true);
break;
case PL_KEY_ASCII('S'): case PL_KEY_ASCII('S'):
*item = kSoundButton; return kSoundButton;
return(true);
break;
default:
return(false);
}
break;
case mouseDown:
testPt = event->where;
GlobalToLocal(&testPt);
foundHit = false;
for (i = 0; i < 4; i++)
{
if (PtInRect(testPt, &prefButton[i]))
{
*item = kDisplayButton + i;
foundHit = true;
}
}
return(foundHit);
break;
case updateEvt:
if ((WindowPtr)event->message == (WindowPtr)mainWindow)
{
SetPortWindowPort(mainWindow);
UpdateMainWindow();
EndUpdate(mainWindow);
SetPort((GrafPtr)dial);
}
else if ((WindowPtr)event->message == dial->GetWindow())
{
SetPortDialogPort(dial);
UpdateSettingsMain(dial);
EndUpdate(dial->GetWindow());
}
event->what = nullEvent;
return(false);
break;
default: default:
return(false); return -1;
break; }
} }
else if (evt.IsLMouseDownEvent())
{
const Window *window = dial->GetWindow();
const GpMouseInputEvent &mouseEvent = evt.m_vosEvent.m_event.m_mouseInputEvent;
const Point testPt = Point::Create(mouseEvent.m_x - window->m_wmX, mouseEvent.m_y - window->m_wmY);
int16_t hitCode = -1;
for (i = 0; i < 4; i++)
{
if (prefButton[i].Contains(testPt))
hitCode = kDisplayButton + i;
}
return hitCode;
}
return -1;
} }
//-------------------------------------------------------------- DoSettingsMain //-------------------------------------------------------------- DoSettingsMain
@@ -1411,14 +1327,13 @@ void DoSettingsMain (void)
{ {
#define kAllDefaultsButton 11 #define kAllDefaultsButton 11
Dialog *prefDlg; Dialog *prefDlg;
short itemHit; int16_t itemHit;
Boolean leaving; Boolean leaving;
ModalFilterUPP prefsFilterUPP;
prefsFilterUPP = NewModalFilterUPP(PrefsFilter);
BringUpDialog(&prefDlg, kMainPrefsDialID); BringUpDialog(&prefDlg, kMainPrefsDialID);
DrawSurface *surface = prefDlg->GetWindow()->GetDrawSurface();
GetDialogItemRect(prefDlg, kDisplayButton, &prefButton[0]); GetDialogItemRect(prefDlg, kDisplayButton, &prefButton[0]);
InsetRect(&prefButton[0], -4, -4); InsetRect(&prefButton[0], -4, -4);
GetDialogItemRect(prefDlg, 4, &prefButton[1]); GetDialogItemRect(prefDlg, 4, &prefButton[1]);
@@ -1428,35 +1343,38 @@ void DoSettingsMain (void)
GetDialogItemRect(prefDlg, 6, &prefButton[3]); GetDialogItemRect(prefDlg, 6, &prefButton[3]);
InsetRect(&prefButton[3], -4, -4); InsetRect(&prefButton[3], -4, -4);
UpdateSettingsMain(prefDlg);
leaving = false; leaving = false;
nextRestartChange = false; nextRestartChange = false;
while (!leaving) while (!leaving)
{ {
ModalDialog(prefsFilterUPP, &itemHit); int16_t selectedItem = prefDlg->ExecuteModal(PrefsFilter);
switch (itemHit)
switch (selectedItem)
{ {
case kOkayButton: case kOkayButton:
leaving = true; leaving = true;
break; break;
case kDisplayButton: case kDisplayButton:
FlashSettingsButton(0); FlashSettingsButton(surface, 0);
DoDisplayPrefs(); DoDisplayPrefs();
SetPort((GrafPtr)prefDlg); SetGraphicsPort(&prefDlg->GetWindow()->m_graf);
break; break;
case kSoundButton: case kSoundButton:
FlashSettingsButton(1); FlashSettingsButton(surface, 1);
DoSoundPrefs(); DoSoundPrefs();
SetPort((GrafPtr)prefDlg); SetGraphicsPort(&prefDlg->GetWindow()->m_graf);
FlushEvents(everyEvent, 0); FlushEvents(everyEvent, 0);
break; break;
case kControlsButton: case kControlsButton:
FlashSettingsButton(2); FlashSettingsButton(surface, 2);
DoControlPrefs(); DoControlPrefs();
SetPort((GrafPtr)prefDlg); SetGraphicsPort(&prefDlg->GetWindow()->m_graf);
break; break;
case kBrainsButton: case kBrainsButton:
@@ -1466,9 +1384,9 @@ void DoSettingsMain (void)
changeLockStateOfHouse = true; changeLockStateOfHouse = true;
saveHouseLocked = false; saveHouseLocked = false;
} }
FlashSettingsButton(3); FlashSettingsButton(surface, 3);
DoBrainsPrefs(); DoBrainsPrefs();
SetPort((GrafPtr)prefDlg); SetGraphicsPort(&prefDlg->GetWindow()->m_graf);
break; break;
case kAllDefaultsButton: case kAllDefaultsButton:
@@ -1478,7 +1396,6 @@ void DoSettingsMain (void)
} }
DisposeDialog(prefDlg); DisposeDialog(prefDlg);
DisposeModalFilterUPP(prefsFilterUPP);
if (nextRestartChange) if (nextRestartChange)
BitchAboutChanges(); BitchAboutChanges();

View File

@@ -275,17 +275,17 @@ void GetFirstWordOfString (StringPtr stringIn, StringPtr stringOut)
// font. If the text would exceed our width limit, characters<72> // font. If the text would exceed our width limit, characters<72>
// are dropped off the end of the string and "<22>" appended. // are dropped off the end of the string and "<22>" appended.
void CollapseStringToWidth (StringPtr theStr, short wide) void CollapseStringToWidth (DrawSurface *surface, StringPtr theStr, short wide)
{ {
short dotsWide; short dotsWide;
Boolean tooWide; Boolean tooWide;
dotsWide = StringWidth(PSTR("<EFBFBD>")); dotsWide = surface->MeasureString(PSTR("<EFBFBD>"));
tooWide = StringWidth(theStr) > wide; tooWide = surface->MeasureString(theStr) > wide;
while (tooWide) while (tooWide)
{ {
theStr[0]--; theStr[0]--;
tooWide = ((StringWidth(theStr) + dotsWide) > wide); tooWide = ((surface->MeasureString(theStr) + dotsWide) > wide);
if (!tooWide) if (!tooWide)
PasStringConcat(theStr, PSTR("<EFBFBD>")); PasStringConcat(theStr, PSTR("<EFBFBD>"));
} }

View File

@@ -265,7 +265,7 @@ void CreatePointers (void)
RedAlert(kErrNoMemory); RedAlert(kErrNoMemory);
else else
{ {
PL_STATIC_ASSERT(sizeof(demoType) == 6); GP_STATIC_ASSERT(sizeof(demoType) == 6);
BlockMove(*tempHandle, demoData, kDemoLength); BlockMove(*tempHandle, demoData, kDemoLength);
tempHandle.Dispose(); tempHandle.Dispose();

View File

@@ -54,7 +54,7 @@ void CreateToolsOffscreen (void);
void KillToolsOffscreen (void); void KillToolsOffscreen (void);
void FrameSelectedTool (DrawSurface *); void FrameSelectedTool (DrawSurface *);
void DrawToolName (DrawSurface *); void DrawToolName (DrawSurface *);
void DrawToolTiles (void); void DrawToolTiles (DrawSurface *);
void SwitchToolModes (short); void SwitchToolModes (short);
@@ -161,12 +161,12 @@ void DrawToolName (DrawSurface *surface)
//-------------------------------------------------------------- DrawToolTiles //-------------------------------------------------------------- DrawToolTiles
#ifndef COMPILEDEMO #ifndef COMPILEDEMO
void DrawToolTiles (void) void DrawToolTiles (DrawSurface *surface)
{ {
Rect srcRect, destRect; Rect srcRect, destRect;
short i; short i;
DrawCIcon(2000, toolRects[0].left, toolRects[0].top); // Selection Tool DrawCIcon(surface, 2000, toolRects[0].left, toolRects[0].top); // Selection Tool
for (i = 0; i < 15; i++) // Other tools for (i = 0; i < 15; i++) // Other tools
{ {
@@ -271,7 +271,7 @@ void UpdateToolsWindow (void)
surface->DrawLine(Point::Create(4, 25), Point::Create(112, 25)); surface->DrawLine(Point::Create(4, 25), Point::Create(112, 25));
surface->SetForeColor(StdColors::Black()); surface->SetForeColor(StdColors::Black());
DrawToolTiles(); DrawToolTiles(surface);
FrameSelectedTool(surface); FrameSelectedTool(surface);
DrawToolName(surface); DrawToolName(surface);
#endif #endif

View File

@@ -11,7 +11,9 @@
#include "PLResources.h" #include "PLResources.h"
#include "PLSound.h" #include "PLSound.h"
#include "PLTimeTaggedVOSEvent.h" #include "PLTimeTaggedVOSEvent.h"
#include "QDPixMap.h"
#include "Externs.h" #include "Externs.h"
#include "IconLoader.h"
#include "Utilities.h" #include "Utilities.h"
@@ -326,18 +328,25 @@ void LargeIconPlot (Rect *theRect, short theID)
// Draws a standard color icon (32 x 32) - resource is a 'CICN'. // Draws a standard color icon (32 x 32) - resource is a 'CICN'.
void DrawCIcon (short theID, short h, short v) void DrawCIcon (DrawSurface *surface, short theID, short h, short v)
{ {
CIconHandle theIcon; THandle<PortabilityLayer::PixMapImpl> colorImage;
Rect theRect; THandle<PortabilityLayer::PixMapImpl> bwImage;
THandle<PortabilityLayer::PixMapImpl> maskImage;
theIcon = GetCIcon(theID); if (PortabilityLayer::IconLoader::GetInstance()->LoadColorIcon(theID, colorImage, bwImage, maskImage))
if (theIcon != nil)
{ {
Rect theRect;
SetRect(&theRect, 0, 0, 32, 32); SetRect(&theRect, 0, 0, 32, 32);
OffsetRect(&theRect, h, v); OffsetRect(&theRect, h, v);
PlotCIcon(&theRect, theIcon);
DisposeCIcon(theIcon); CopyMask(*colorImage, *maskImage, *surface->m_port.GetPixMap(), &(*colorImage)->m_rect, &(*maskImage)->m_rect, &theRect);
surface->m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
bwImage.Dispose();
colorImage.Dispose();
maskImage.Dispose();
} }
} }

View File

@@ -40,6 +40,7 @@ class GpFont_FreeType2 final : public PortabilityLayer::HostFont
public: public:
void Destroy() override; void Destroy() override;
GpFontRenderedGlyph_FreeType2 *Render(uint32_t unicodeCodePoint, unsigned int size) override; GpFontRenderedGlyph_FreeType2 *Render(uint32_t unicodeCodePoint, unsigned int size) override;
bool GetLineSpacing(unsigned int size, int32_t &outSpacing) override;
static GpFont_FreeType2 *Create(const FT_StreamRec_ &streamRec, PortabilityLayer::IOStream *stream); static GpFont_FreeType2 *Create(const FT_StreamRec_ &streamRec, PortabilityLayer::IOStream *stream);
@@ -73,8 +74,8 @@ void GpFontRenderedGlyph_FreeType2::Destroy()
GpFontRenderedGlyph_FreeType2 *GpFontRenderedGlyph_FreeType2::Create(size_t dataSize, const PortabilityLayer::RenderedGlyphMetrics &metrics) GpFontRenderedGlyph_FreeType2 *GpFontRenderedGlyph_FreeType2::Create(size_t dataSize, const PortabilityLayer::RenderedGlyphMetrics &metrics)
{ {
size_t alignedPrefixSize = (sizeof(GpFontRenderedGlyph_FreeType2) + PL_SYSTEM_MEMORY_ALIGNMENT - 1); size_t alignedPrefixSize = (sizeof(GpFontRenderedGlyph_FreeType2) + GP_SYSTEM_MEMORY_ALIGNMENT - 1);
alignedPrefixSize -= alignedPrefixSize % PL_SYSTEM_MEMORY_ALIGNMENT; alignedPrefixSize -= alignedPrefixSize % GP_SYSTEM_MEMORY_ALIGNMENT;
void *storage = malloc(alignedPrefixSize + dataSize); void *storage = malloc(alignedPrefixSize + dataSize);
if (!storage) if (!storage)
@@ -141,8 +142,8 @@ GpFontRenderedGlyph_FreeType2 *GpFont_FreeType2::Render(uint32_t unicodeCodePoin
const size_t numRowsRequired = glyph->bitmap.rows; const size_t numRowsRequired = glyph->bitmap.rows;
size_t pitchRequired = (glyph->bitmap.width + 7) / 8; size_t pitchRequired = (glyph->bitmap.width + 7) / 8;
pitchRequired = pitchRequired + (PL_SYSTEM_MEMORY_ALIGNMENT - 1); pitchRequired = pitchRequired + (GP_SYSTEM_MEMORY_ALIGNMENT - 1);
pitchRequired -= pitchRequired % PL_SYSTEM_MEMORY_ALIGNMENT; pitchRequired -= pitchRequired % GP_SYSTEM_MEMORY_ALIGNMENT;
const size_t glyphDataSize = numRowsRequired * pitchRequired; const size_t glyphDataSize = numRowsRequired * pitchRequired;
@@ -181,6 +182,21 @@ GpFontRenderedGlyph_FreeType2 *GpFont_FreeType2::Render(uint32_t unicodeCodePoin
return renderedGlyph; return renderedGlyph;
} }
bool GpFont_FreeType2::GetLineSpacing(unsigned int size, int32_t &outSpacing)
{
if (m_currentSize != size)
{
if (FT_Set_Pixel_Sizes(m_face, 0, size) != 0)
return false;
m_currentSize = size;
}
outSpacing = m_face->size->metrics.height / 64;
return true;
}
GpFont_FreeType2 *GpFont_FreeType2::Create(const FT_StreamRec_ &streamRec, PortabilityLayer::IOStream *stream) GpFont_FreeType2 *GpFont_FreeType2::Create(const FT_StreamRec_ &streamRec, PortabilityLayer::IOStream *stream)
{ {
void *storage = malloc(sizeof(GpFont_FreeType2)); void *storage = malloc(sizeof(GpFont_FreeType2));

View File

@@ -42,8 +42,8 @@ GpMemoryBuffer::~GpMemoryBuffer()
size_t GpMemoryBuffer::AlignedSize() size_t GpMemoryBuffer::AlignedSize()
{ {
const size_t paddedSize = (sizeof(GpMemoryBuffer) + PL_SYSTEM_MEMORY_ALIGNMENT - 1); const size_t paddedSize = (sizeof(GpMemoryBuffer) + GP_SYSTEM_MEMORY_ALIGNMENT - 1);
const size_t sz = paddedSize - paddedSize % PL_SYSTEM_MEMORY_ALIGNMENT; const size_t sz = paddedSize - paddedSize % GP_SYSTEM_MEMORY_ALIGNMENT;
return sz; return sz;
} }

View File

@@ -313,7 +313,7 @@ void AuditPackBitsRectOld(MemReaderStream &stream, int pictVersion, bool isPacke
// If pack type == 3, 16-bit RLE // If pack type == 3, 16-bit RLE
// If pack type == 4, 8-bit planar component RLE // If pack type == 4, 8-bit planar component RLE
PL_STATIC_ASSERT(sizeof(BEPixMap) == 44); GP_STATIC_ASSERT(sizeof(BEPixMap) == 44);
BEPixMap pixMap; BEPixMap pixMap;
stream.Read(&pixMap, sizeof(BEPixMap)); stream.Read(&pixMap, sizeof(BEPixMap));
@@ -663,7 +663,7 @@ void AuditPackBitsRect(MemReaderStream &stream, int pictVersion, bool isPackedFl
// If pack type == 3, 16-bit RLE // If pack type == 3, 16-bit RLE
// If pack type == 4, 8-bit planar component RLE // If pack type == 4, 8-bit planar component RLE
PL_STATIC_ASSERT(sizeof(BEPixMap) == 44); GP_STATIC_ASSERT(sizeof(BEPixMap) == 44);
stream.Read(&pixMapBE, sizeof(BEPixMap)); stream.Read(&pixMapBE, sizeof(BEPixMap));

View File

@@ -8,7 +8,7 @@ namespace PortabilityLayer
template<class TNumberType, class TUnsignedType> template<class TNumberType, class TUnsignedType>
void SwapArbitrary(TNumberType &v) void SwapArbitrary(TNumberType &v)
{ {
PL_STATIC_ASSERT(sizeof(TNumberType) == sizeof(TUnsignedType)); GP_STATIC_ASSERT(sizeof(TNumberType) == sizeof(TUnsignedType));
uint8_t bytes[sizeof(TNumberType)]; uint8_t bytes[sizeof(TNumberType)];
for (size_t i = 0; i < sizeof(TNumberType); i++) for (size_t i = 0; i < sizeof(TNumberType); i++)

View File

@@ -30,7 +30,7 @@ namespace PortabilityLayer
void Close() override; void Close() override;
private: private:
CFileStream(const CFileStream &other) PL_DELETED; CFileStream(const CFileStream &other) GP_DELETED;
FILE *m_file; FILE *m_file;
bool m_readOnly; bool m_readOnly;

View File

@@ -1,9 +1,19 @@
#include "DialogManager.h" #include "DialogManager.h"
#include "HostDisplayDriver.h"
#include "IconLoader.h"
#include "ResourceManager.h" #include "ResourceManager.h"
#include "PLArrayView.h" #include "PLArrayView.h"
#include "PLDialogs.h"
#include "PLBigEndian.h" #include "PLBigEndian.h"
#include "PLButtonWidget.h"
#include "PLDialogs.h"
#include "PLIconWidget.h"
#include "PLInvisibleWidget.h"
#include "PLLabelWidget.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "PLSysCalls.h"
#include "PLTimeTaggedVOSEvent.h"
#include "PLWidgets.h"
#include "QDPixMap.h"
#include "ResTypeID.h" #include "ResTypeID.h"
#include "SharedTypes.h" #include "SharedTypes.h"
#include "WindowDef.h" #include "WindowDef.h"
@@ -14,6 +24,9 @@
namespace PortabilityLayer namespace PortabilityLayer
{ {
class DialogImpl;
class Widget;
namespace SerializedDialogItemTypeCodes namespace SerializedDialogItemTypeCodes
{ {
enum SerializedDialogItemTypeCode enum SerializedDialogItemTypeCode
@@ -32,6 +45,7 @@ namespace PortabilityLayer
typedef SerializedDialogItemTypeCodes::SerializedDialogItemTypeCode SerializedDialogItemTypeCode_t; typedef SerializedDialogItemTypeCodes::SerializedDialogItemTypeCode SerializedDialogItemTypeCode_t;
struct DialogTemplateItem struct DialogTemplateItem
{ {
Rect m_rect; Rect m_rect;
@@ -41,79 +55,6 @@ namespace PortabilityLayer
Str255 m_name; Str255 m_name;
}; };
class DialogItemImpl : public DialogItem
{
public:
DialogItemImpl(const DialogTemplateItem &templateItem);
virtual ~DialogItemImpl();
Rect GetRect() const override;
virtual bool Init() = 0;
virtual void Destroy() = 0;
protected:
Rect m_rect;
int16_t m_id;
bool m_enabled;
PascalStr<255> m_name;
};
template<class T>
class DialogItemSpec : public DialogItemImpl
{
public:
DialogItemSpec(const DialogTemplateItem &tmpl)
: DialogItemImpl(tmpl)
{
}
void Destroy() override
{
static_cast<T*>(this)->~T();
free(static_cast<T*>(this));
}
static DialogItemSpec *Create(const DialogTemplateItem &tmpl)
{
void *storage = malloc(sizeof(T));
if (!storage)
return nullptr;
T *item = new (storage) T(tmpl);
DialogItemImpl *dItem = static_cast<DialogItemImpl*>(item);
if (!dItem->Init())
{
dItem->Destroy();
return nullptr;
}
return item;
}
};
class DialogItem_EditBox final : public DialogItemSpec<DialogItem_EditBox>
{
public:
explicit DialogItem_EditBox(const DialogTemplateItem &tmpl);
bool Init() override;
};
class DialogItem_Label final : public DialogItemSpec<DialogItem_Label>
{
public:
explicit DialogItem_Label(const DialogTemplateItem &tmpl);
bool Init() override;
};
class DialogItem_Unknown final : public DialogItemSpec<DialogItem_Unknown>
{
public:
explicit DialogItem_Unknown(const DialogTemplateItem &tmpl);
bool Init() override;
};
class DialogTemplate final class DialogTemplate final
{ {
public: public:
@@ -132,68 +73,45 @@ namespace PortabilityLayer
{ {
public: public:
void Destroy() override; void Destroy() override;
Window *GetWindow() const override; Window *GetWindow() const override;
ArrayView<DialogItem*const> GetItems() const override; ArrayView<const DialogItem> GetItems() const override;
int16_t ExecuteModal(DialogFilterFunc_t filterFunc) override;
bool Populate(DialogTemplate *tmpl); bool Populate(DialogTemplate *tmpl);
void DrawControls();
Point MouseToDialog(const GpMouseInputEvent &evt);
static DialogImpl *Create(Window *window, size_t numItems); static DialogImpl *Create(Window *window, size_t numItems);
private: private:
explicit DialogImpl(Window *window, DialogItem **items, size_t numItems); explicit DialogImpl(Window *window, DialogItem *items, size_t numItems);
~DialogImpl(); ~DialogImpl();
Window *m_window; Window *m_window;
DialogItem **m_items; DialogItem *m_items;
size_t m_numItems; size_t m_numItems;
size_t m_maxItems;
}; };
DialogItemImpl::DialogItemImpl(const DialogTemplateItem &templateItem) DialogItem::DialogItem(Widget *widget)
: m_enabled(templateItem.m_enabled) : m_widget(widget)
, m_id(templateItem.m_id)
, m_name(PLPasStr(templateItem.m_name))
, m_rect(templateItem.m_rect)
{ {
} }
DialogItemImpl::~DialogItemImpl() DialogItem::~DialogItem()
{ {
if (m_widget)
m_widget->Destroy();
} }
Rect DialogItemImpl::GetRect() const Widget *DialogItem::GetWidget() const
{ {
return m_rect; return m_widget;
}
DialogItem_EditBox::DialogItem_EditBox(const DialogTemplateItem &tmpl)
: DialogItemSpec<DialogItem_EditBox>(tmpl)
{
}
bool DialogItem_EditBox::Init()
{
return true;
}
DialogItem_Label::DialogItem_Label(const DialogTemplateItem &tmpl)
: DialogItemSpec<DialogItem_Label>(tmpl)
{
}
bool DialogItem_Label::Init()
{
return true;
}
DialogItem_Unknown::DialogItem_Unknown(const DialogTemplateItem &tmpl)
: DialogItemSpec<DialogItem_Unknown>(tmpl)
{
}
bool DialogItem_Unknown::Init()
{
return true;
} }
DialogTemplate::DialogTemplate(DialogTemplateItem *itemStorage, size_t numItems) DialogTemplate::DialogTemplate(DialogTemplateItem *itemStorage, size_t numItems)
@@ -268,14 +186,68 @@ namespace PortabilityLayer
return m_window; return m_window;
} }
ArrayView<DialogItem*const> DialogImpl::GetItems() const ArrayView<const DialogItem> DialogImpl::GetItems() const
{ {
ArrayView<DialogItem*const> iter(m_items, m_numItems); return ArrayView<const DialogItem>(m_items, m_numItems);
return ArrayView<DialogItem*const>(m_items, m_numItems); }
int16_t DialogImpl::ExecuteModal(DialogFilterFunc_t filterFunc)
{
Window *window = this->GetWindow();
Widget *capturingWidget = nullptr;
size_t capturingWidgetIndex = 0;
for (;;)
{
TimeTaggedVOSEvent evt;
if (WaitForEvent(&evt, 1))
{
const int16_t selection = filterFunc(this, evt);
if (selection >= 0)
return selection;
if (capturingWidget != nullptr)
{
const WidgetHandleState_t state = capturingWidget->ProcessEvent(evt);
if (state != WidgetHandleStates::kDigested)
capturingWidget = nullptr;
if (state == WidgetHandleStates::kActivated)
return static_cast<int16_t>(capturingWidgetIndex + 1);
}
else
{
const size_t numItems = this->m_numItems;
for (size_t i = 0; i < numItems; i++)
{
Widget *widget = this->m_items[i].GetWidget();
const WidgetHandleState_t state = widget->ProcessEvent(evt);
if (state == WidgetHandleStates::kActivated)
return static_cast<int16_t>(i + 1);
if (state == WidgetHandleStates::kCaptured)
{
capturingWidget = widget;
capturingWidgetIndex = i;
break;
}
if (state == WidgetHandleStates::kDigested)
break;
}
}
}
}
} }
bool DialogImpl::Populate(DialogTemplate *tmpl) bool DialogImpl::Populate(DialogTemplate *tmpl)
{ {
Window *window = this->GetWindow();
ArrayView<const DialogTemplateItem> templateItems = tmpl->GetItems(); ArrayView<const DialogTemplateItem> templateItems = tmpl->GetItems();
const size_t numItems = templateItems.Count(); const size_t numItems = templateItems.Count();
@@ -284,61 +256,94 @@ namespace PortabilityLayer
{ {
const DialogTemplateItem &templateItem = templateItems[i]; const DialogTemplateItem &templateItem = templateItems[i];
DialogItem *ditem = nullptr; Widget *widget = nullptr;
WidgetBasicState basicState;
basicState.m_enabled = templateItem.m_enabled;
basicState.m_resID = templateItem.m_id;
basicState.m_text = PascalStr<255>(PLPasStr(templateItem.m_name));
basicState.m_rect = templateItem.m_rect;
basicState.m_window = window;
switch (templateItem.m_serializedType) switch (templateItem.m_serializedType)
{ {
case SerializedDialogItemTypeCodes::kButton:
widget = ButtonWidget::Create(basicState);
break;
case SerializedDialogItemTypeCodes::kLabel: case SerializedDialogItemTypeCodes::kLabel:
ditem = DialogItem_Label::Create(templateItem); widget = LabelWidget::Create(basicState);
break; break;
case SerializedDialogItemTypeCodes::kIcon:
widget = IconWidget::Create(basicState);
break;
case SerializedDialogItemTypeCodes::kCheckBox:
case SerializedDialogItemTypeCodes::kRadioButton:
case SerializedDialogItemTypeCodes::kEditBox: case SerializedDialogItemTypeCodes::kEditBox:
ditem = DialogItem_EditBox::Create(templateItem); case SerializedDialogItemTypeCodes::kImage:
break;
default: default:
ditem = DialogItem_Unknown::Create(templateItem); widget = InvisibleWidget::Create(basicState);
break; break;
} }
if (!ditem) if (!widget)
return false; return false;
m_items[i] = ditem; new (&m_items[m_numItems++]) DialogItem(widget);
} }
return true; return true;
} }
void DialogImpl::DrawControls()
{
DrawSurface *surface = m_window->GetDrawSurface();
for (ArrayViewIterator<const DialogItem> it = GetItems().begin(), itEnd = GetItems().end(); it != itEnd; ++it)
{
const DialogItem &item = *it;
item.GetWidget()->DrawControl(surface);
}
}
Point DialogImpl::MouseToDialog(const GpMouseInputEvent &evt)
{
const Window *window = m_window;
const int32_t x = evt.m_x - window->m_wmX;
const int32_t y = evt.m_y - window->m_wmY;
return Point::Create(x, y);
}
DialogImpl *DialogImpl::Create(Window *window, size_t numItems) DialogImpl *DialogImpl::Create(Window *window, size_t numItems)
{ {
size_t alignedSize = sizeof(DialogImpl) + PL_SYSTEM_MEMORY_ALIGNMENT + 1; size_t alignedSize = sizeof(DialogImpl) + GP_SYSTEM_MEMORY_ALIGNMENT + 1;
alignedSize -= alignedSize % PL_SYSTEM_MEMORY_ALIGNMENT; alignedSize -= alignedSize % GP_SYSTEM_MEMORY_ALIGNMENT;
const size_t itemsSize = sizeof(DialogItemImpl) * numItems; const size_t itemsSize = sizeof(DialogItem) * numItems;
void *storage = malloc(alignedSize + itemsSize); void *storage = malloc(alignedSize + itemsSize);
if (!storage) if (!storage)
return nullptr; return nullptr;
DialogItem **itemsList = reinterpret_cast<DialogItem **>(static_cast<uint8_t*>(storage) + alignedSize); DialogItem *itemsList = reinterpret_cast<DialogItem *>(static_cast<uint8_t*>(storage) + alignedSize);
for (size_t i = 0; i < numItems; i++)
itemsList[i] = nullptr;
return new (storage) DialogImpl(window, itemsList, numItems); return new (storage) DialogImpl(window, itemsList, numItems);
} }
DialogImpl::DialogImpl(Window *window, DialogItem **itemsList, size_t numItems) DialogImpl::DialogImpl(Window *window, DialogItem *itemsList, size_t numItems)
: m_window(window) : m_window(window)
, m_items(itemsList) , m_items(itemsList)
, m_numItems(numItems) , m_numItems(0)
, m_maxItems(numItems)
{ {
} }
DialogImpl::~DialogImpl() DialogImpl::~DialogImpl()
{ {
for (size_t i = 0; i < m_numItems; i++) while (m_numItems > 0)
{ {
if (DialogItem *item = m_items[i]) m_numItems--;
static_cast<DialogItemImpl*>(item)->Destroy(); m_items[m_numItems].~DialogItem();
} }
} }
@@ -415,6 +420,34 @@ namespace PortabilityLayer
wm->PutWindowBehind(window, behindWindow); wm->PutWindowBehind(window, behindWindow);
unsigned int displayWidth, displayHeight;
PortabilityLayer::HostDisplayDriver::GetInstance()->GetDisplayResolution(&displayWidth, &displayHeight, nullptr);
const unsigned int halfDisplayHeight = displayHeight / 2;
const unsigned int quarterDisplayWidth = displayHeight / 4;
const unsigned int halfDisplayWidth = displayWidth;
const uint16_t dialogWidth = rect.Width();
const uint16_t dialogHeight = rect.Height();
window->m_wmX = (static_cast<int32_t>(displayWidth) - static_cast<int32_t>(dialogWidth)) / 2;
// We center dialogs vertically in one of 3 ways in this priority:
// - Centered at 1/3 until the top edge is at the 1/4 mark
// - Top edge aligned to 1/4 mark until bottom edge is at 3/4 mark
// - Centered on screen
//if (displayHeight / 3 - dialogHeight / 2 >= displayHeight / 4)
if (displayHeight * 4 - dialogHeight * 6 >= displayHeight * 3)
{
//window->m_wmY = displayHeight / 3 - dialogHeight / 2;
window->m_wmY = (static_cast<int32_t>(displayHeight * 2) - static_cast<int32_t>(dialogHeight * 3)) / 6;
}
else if (dialogHeight * 2 <= displayHeight)
window->m_wmY = displayHeight / 4;
else
window->m_wmY = (static_cast<int32_t>(displayHeight) - static_cast<int32_t>(dialogHeight)) / 2;
DialogImpl *dialog = DialogImpl::Create(window, numItems); DialogImpl *dialog = DialogImpl::Create(window, numItems);
if (!dialog) if (!dialog)
@@ -433,6 +466,8 @@ namespace PortabilityLayer
return nullptr; return nullptr;
} }
dialog->DrawControls();
return dialog; return dialog;
} }
@@ -445,12 +480,17 @@ namespace PortabilityLayer
if (!dtemplateH) if (!dtemplateH)
return nullptr; return nullptr;
uint16_t numItems; int16_t numItemsMinusOne;
memcpy(&numItems, *dtemplateH, 2); memcpy(&numItemsMinusOne, *dtemplateH, 2);
ByteSwap::BigUInt16(numItems); ByteSwap::BigInt16(numItemsMinusOne);
size_t dtlAlignedSize = sizeof(DialogTemplate) + PL_SYSTEM_MEMORY_ALIGNMENT - 1; if (numItemsMinusOne < -1)
dtlAlignedSize -= dtlAlignedSize % PL_SYSTEM_MEMORY_ALIGNMENT; return nullptr;
uint16_t numItems = static_cast<uint16_t>(numItemsMinusOne + 1);
size_t dtlAlignedSize = sizeof(DialogTemplate) + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
dtlAlignedSize -= dtlAlignedSize % GP_SYSTEM_MEMORY_ALIGNMENT;
const size_t dtlItemSize = sizeof(DialogTemplateItem) * numItems; const size_t dtlItemSize = sizeof(DialogTemplateItem) * numItems;

View File

@@ -4,9 +4,12 @@
struct Dialog; struct Dialog;
struct Window; struct Window;
struct TimeTaggedVOSEvent;
namespace PortabilityLayer namespace PortabilityLayer
{ {
class Widget;
class DialogManager class DialogManager
{ {
public: public:
@@ -14,4 +17,16 @@ namespace PortabilityLayer
static DialogManager *GetInstance(); static DialogManager *GetInstance();
}; };
class DialogItem
{
public:
explicit DialogItem(Widget *widget);
~DialogItem();
Widget *GetWidget() const;
private:
Widget *m_widget;
};
} }

View File

@@ -30,7 +30,7 @@ namespace PortabilityLayer
bool m_paletteIsDirty; bool m_paletteIsDirty;
PortabilityLayer::RGBAColor *m_palette; PortabilityLayer::RGBAColor *m_palette;
uint8_t m_paletteStorage[256 * sizeof(PortabilityLayer::RGBAColor) + PL_SYSTEM_MEMORY_ALIGNMENT]; uint8_t m_paletteStorage[256 * sizeof(PortabilityLayer::RGBAColor) + GP_SYSTEM_MEMORY_ALIGNMENT];
static DisplayDeviceManagerImpl ms_instance; static DisplayDeviceManagerImpl ms_instance;
}; };
@@ -41,7 +41,7 @@ namespace PortabilityLayer
, m_pixelFormat(GpPixelFormats::k8BitStandard) , m_pixelFormat(GpPixelFormats::k8BitStandard)
{ {
uint8_t *paletteStorage = m_paletteStorage; uint8_t *paletteStorage = m_paletteStorage;
while (reinterpret_cast<intptr_t>(paletteStorage) % PL_SYSTEM_MEMORY_ALIGNMENT != 0) while (reinterpret_cast<intptr_t>(paletteStorage) % GP_SYSTEM_MEMORY_ALIGNMENT != 0)
paletteStorage++; paletteStorage++;
m_palette = reinterpret_cast<PortabilityLayer::RGBAColor*>(paletteStorage); m_palette = reinterpret_cast<PortabilityLayer::RGBAColor*>(paletteStorage);

View File

@@ -7,6 +7,7 @@
#include "MacRoman.h" #include "MacRoman.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "RenderedFont.h" #include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "RenderedGlyphMetrics.h" #include "RenderedGlyphMetrics.h"
#include <assert.h> #include <assert.h>
@@ -19,12 +20,14 @@ namespace PortabilityLayer
class RenderedFontImpl final : public RenderedFont class RenderedFontImpl final : public RenderedFont
{ {
public: public:
bool GetGlyph(unsigned int character, const RenderedGlyphMetrics **outMetricsPtr, const void **outData) const override; bool GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const override;
const RenderedFontMetrics &GetMetrics() const override;
size_t MeasureString(const uint8_t *chars, size_t len) const override; size_t MeasureString(const uint8_t *chars, size_t len) const override;
void Destroy() override; void Destroy() override;
void SetCharData(unsigned int charID, const void *data, size_t dataOffset, const RenderedGlyphMetrics &metrics); void SetCharData(unsigned int charID, const void *data, size_t dataOffset, const RenderedGlyphMetrics &metrics);
void SetFontMetrics(const RenderedFontMetrics &metrics);
static RenderedFontImpl *Create(size_t glyphDataSize); static RenderedFontImpl *Create(size_t glyphDataSize);
@@ -33,7 +36,9 @@ namespace PortabilityLayer
~RenderedFontImpl(); ~RenderedFontImpl();
size_t m_dataOffsets[256]; size_t m_dataOffsets[256];
RenderedGlyphMetrics m_metrics[256]; RenderedGlyphMetrics m_glyphMetrics[256];
RenderedFontMetrics m_fontMetrics;
void *m_data; void *m_data;
}; };
@@ -49,25 +54,31 @@ namespace PortabilityLayer
static FontRendererImpl ms_instance; static FontRendererImpl ms_instance;
}; };
bool RenderedFontImpl::GetGlyph(unsigned int character, const RenderedGlyphMetrics **outMetricsPtr, const void **outData) const bool RenderedFontImpl::GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const
{ {
const size_t dataOffset = m_dataOffsets[character]; const size_t dataOffset = m_dataOffsets[character];
if (!dataOffset) if (!dataOffset)
return false; return false;
*outMetricsPtr = m_metrics + character; outMetricsPtr = m_glyphMetrics + character;
*outData = static_cast<const uint8_t*>(m_data) + dataOffset; outData = static_cast<const uint8_t*>(m_data) + dataOffset;
return true; return true;
} }
const RenderedFontMetrics &RenderedFontImpl::GetMetrics() const
{
return m_fontMetrics;
}
size_t RenderedFontImpl::MeasureString(const uint8_t *chars, size_t len) const size_t RenderedFontImpl::MeasureString(const uint8_t *chars, size_t len) const
{ {
size_t measure = 0; size_t measure = 0;
for (size_t i = 0; i < len; i++) for (size_t i = 0; i < len; i++)
{ {
const RenderedGlyphMetrics &metrics = m_metrics[chars[i]]; const RenderedGlyphMetrics &metrics = m_glyphMetrics[chars[i]];
measure += metrics.m_advanceX; measure += metrics.m_advanceX;
} }
@@ -83,14 +94,19 @@ namespace PortabilityLayer
void RenderedFontImpl::SetCharData(unsigned int charID, const void *data, size_t dataOffset, const RenderedGlyphMetrics &metrics) void RenderedFontImpl::SetCharData(unsigned int charID, const void *data, size_t dataOffset, const RenderedGlyphMetrics &metrics)
{ {
m_dataOffsets[charID] = dataOffset; m_dataOffsets[charID] = dataOffset;
m_metrics[charID] = metrics; m_glyphMetrics[charID] = metrics;
memcpy(static_cast<uint8_t*>(m_data) + dataOffset, data, metrics.m_glyphDataPitch * metrics.m_glyphHeight); memcpy(static_cast<uint8_t*>(m_data) + dataOffset, data, metrics.m_glyphDataPitch * metrics.m_glyphHeight);
} }
void RenderedFontImpl::SetFontMetrics(const RenderedFontMetrics &metrics)
{
m_fontMetrics = metrics;
}
RenderedFontImpl *RenderedFontImpl::Create(size_t glyphDataSize) RenderedFontImpl *RenderedFontImpl::Create(size_t glyphDataSize)
{ {
size_t alignedPrefixSize = sizeof(RenderedFontImpl) + PL_SYSTEM_MEMORY_ALIGNMENT - 1; size_t alignedPrefixSize = sizeof(RenderedFontImpl) + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
alignedPrefixSize -= alignedPrefixSize % PL_SYSTEM_MEMORY_ALIGNMENT; alignedPrefixSize -= alignedPrefixSize % GP_SYSTEM_MEMORY_ALIGNMENT;
if (SIZE_MAX - alignedPrefixSize < glyphDataSize) if (SIZE_MAX - alignedPrefixSize < glyphDataSize)
return nullptr; return nullptr;
@@ -109,7 +125,8 @@ namespace PortabilityLayer
RenderedFontImpl::RenderedFontImpl(void *data) RenderedFontImpl::RenderedFontImpl(void *data)
: m_data(data) : m_data(data)
{ {
memset(m_metrics, 0, sizeof(m_metrics)); memset(m_glyphMetrics, 0, sizeof(m_glyphMetrics));
memset(&m_fontMetrics, 0, sizeof(m_fontMetrics));
memset(m_dataOffsets, 0, sizeof(m_dataOffsets)); memset(m_dataOffsets, 0, sizeof(m_dataOffsets));
} }
@@ -124,6 +141,10 @@ namespace PortabilityLayer
if (size < 1) if (size < 1)
return nullptr; return nullptr;
int32_t lineSpacing;
if (!font->GetLineSpacing(size, lineSpacing))
return nullptr;
HostFontRenderedGlyph *glyphs[numCharacters]; HostFontRenderedGlyph *glyphs[numCharacters];
for (unsigned int i = 0; i < numCharacters; i++) for (unsigned int i = 0; i < numCharacters; i++)
@@ -138,7 +159,7 @@ namespace PortabilityLayer
glyphs[i] = font->Render(unicodeCodePoint, size); glyphs[i] = font->Render(unicodeCodePoint, size);
} }
size_t glyphDataSize = PL_SYSTEM_MEMORY_ALIGNMENT; // So we can use 0 to mean no data size_t glyphDataSize = GP_SYSTEM_MEMORY_ALIGNMENT; // So we can use 0 to mean no data
size_t numUsedGlyphs = 0; size_t numUsedGlyphs = 0;
for (unsigned int i = 0; i < numCharacters; i++) for (unsigned int i = 0; i < numCharacters; i++)
{ {
@@ -152,7 +173,7 @@ namespace PortabilityLayer
RenderedFontImpl *rfont = RenderedFontImpl::Create(glyphDataSize); RenderedFontImpl *rfont = RenderedFontImpl::Create(glyphDataSize);
if (rfont) if (rfont)
{ {
size_t fillOffset = PL_SYSTEM_MEMORY_ALIGNMENT; size_t fillOffset = GP_SYSTEM_MEMORY_ALIGNMENT;
size_t numUsedGlyphs = 0; size_t numUsedGlyphs = 0;
for (unsigned int i = 0; i < numCharacters; i++) for (unsigned int i = 0; i < numCharacters; i++)
@@ -190,6 +211,41 @@ namespace PortabilityLayer
} }
} }
// Compute metrics
RenderedFontMetrics fontMetrics;
fontMetrics.m_linegap = lineSpacing;
fontMetrics.m_ascent = 0;
fontMetrics.m_descent = 0;
bool measuredAnyGlyphs = false;
for (char capChar = 'A'; capChar <= 'Z'; capChar++)
{
const RenderedGlyphMetrics *glyphMetrics;
const void *glyphData;
if (rfont->GetGlyph(static_cast<unsigned int>(capChar), glyphMetrics, glyphData) && glyphMetrics != nullptr)
{
const int32_t ascent = glyphMetrics->m_bearingY;
const int32_t descent = static_cast<int32_t>(glyphMetrics->m_glyphHeight) - ascent;
if (!measuredAnyGlyphs)
{
fontMetrics.m_ascent = ascent;
fontMetrics.m_descent = descent;
measuredAnyGlyphs = true;
}
else
{
if (ascent > fontMetrics.m_ascent)
fontMetrics.m_ascent = ascent;
if (descent > fontMetrics.m_descent)
fontMetrics.m_descent = descent;
}
}
}
rfont->SetFontMetrics(fontMetrics);
for (unsigned int i = 0; i < numCharacters; i++) for (unsigned int i = 0; i < numCharacters; i++)
{ {
if (glyphs[i]) if (glyphs[i])

View File

@@ -5,11 +5,13 @@
namespace PortabilityLayer namespace PortabilityLayer
{ {
class HostFontRenderedGlyph; class HostFontRenderedGlyph;
struct RenderedFontMetrics;
class HostFont class HostFont
{ {
public: public:
virtual void Destroy() = 0; virtual void Destroy() = 0;
virtual HostFontRenderedGlyph *Render(uint32_t unicodeCodePoint, unsigned int size) = 0; virtual HostFontRenderedGlyph *Render(uint32_t unicodeCodePoint, unsigned int size) = 0;
virtual bool GetLineSpacing(unsigned int size, int32_t &outSpacing) = 0;
}; };
} }

View File

@@ -0,0 +1,258 @@
#include "IconLoader.h"
#include "PLCore.h"
#include "PLCTabReducer.h"
#include "ResourceManager.h"
#include "QDStandardPalette.h"
#include "QDPixMap.h"
#include "SharedTypes.h"
// Color icons (cicn) format:
// ColorIconSerializedData (82 bytes)
// Mask bits
// B&W bits
// BEColorTableHeader (8 bytes)
// BEColorTableItem (8 bytes)
// Color bits
// ICON format is just a 32x32 bitfield
struct IconImagePrefix
{
BEUInt32_t m_unknown; // Seems to always be zero
BEUInt16_t m_pitch; // +0x8000 for color
};
struct ColorIconSerializedData
{
IconImagePrefix m_colorPrefix;
BEPixMap m_colorPixMap;
IconImagePrefix m_maskPrefix;
BEBitMap m_maskBitMap;
IconImagePrefix m_bwPrefix;
BEBitMap m_bwBitMap;
uint8_t m_unused[4];
};
namespace PortabilityLayer
{
class IconLoaderImpl final : public IconLoader
{
public:
bool LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage) override;
THandle<PixMapImpl> LoadBWIcon(const int16_t id) override;
static IconLoaderImpl *GetInstance();
private:
static bool ParseColorImage(const IconImagePrefix &prefix, const BEPixMap &pixMapHeader, THandle<PixMapImpl> &outHandle, const uint8_t *&dataPtr);
static bool ParseBWImage(const IconImagePrefix &prefix, const BEBitMap &bitMapHeader, THandle<PixMapImpl> &outHandle, const uint8_t *&dataPtr);
static IconLoaderImpl ms_instance;
};
bool IconLoaderImpl::LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage)
{
THandle<const uint8_t> data = PortabilityLayer::ResourceManager::GetInstance()->GetResource('cicn', id).StaticCast<const uint8_t>();
if (!data)
return false;
GP_STATIC_ASSERT(sizeof(ColorIconSerializedData) == 82);
ColorIconSerializedData header;
memcpy(&header, *data, sizeof(header));
const uint8_t *dataPtr = (*data) + sizeof(header);
THandle<PixMapImpl> maskImage;
if (!ParseBWImage(header.m_maskPrefix, header.m_maskBitMap, maskImage, dataPtr))
{
data.Dispose();
return false;
}
THandle<PixMapImpl> bwImage;
if (!ParseBWImage(header.m_bwPrefix, header.m_bwBitMap, bwImage, dataPtr))
{
PixMapImpl::Destroy(maskImage);
data.Dispose();
return false;
}
THandle<PixMapImpl> colorImage;
if (!ParseColorImage(header.m_colorPrefix, header.m_colorPixMap, colorImage, dataPtr))
{
PixMapImpl::Destroy(bwImage);
PixMapImpl::Destroy(maskImage);
data.Dispose();
return false;
}
outColorImage = colorImage;
outBWImage = bwImage;
outMaskImage = maskImage;
return true;
}
bool IconLoaderImpl::ParseColorImage(const IconImagePrefix &prefix, const BEPixMap &pixMapHeader, THandle<PixMapImpl> &outHandle, const uint8_t *&dataPtr)
{
if (pixMapHeader.m_componentCount != 1 || pixMapHeader.m_packType != 0)
{
PL_NotYetImplemented();
return false;
}
const uint8_t *inData = dataPtr;
BEColorTableHeader colorTableHeader;
memcpy(&colorTableHeader, inData, sizeof(BEColorTableHeader));
inData += sizeof(BEColorTableHeader);
const size_t numItems = static_cast<uint16_t>(colorTableHeader.m_numItemsMinusOne) + 1;
if (numItems > 256)
return false;
uint8_t remapping[256];
for (int i = 0; i < 256; i++)
remapping[i] = 0;
for (size_t i = 0; i < numItems; i++)
{
BEColorTableItem ctabItem;
memcpy(&ctabItem, inData, sizeof(BEColorTableItem));
inData += sizeof(BEColorTableItem);
const uint16_t index = ctabItem.m_index;
if (index >= 256)
return false;
const PortabilityLayer::RGBAColor remappedColor = CTabReducer::DecodeClutItem(ctabItem);
remapping[index] = StandardPalette::GetInstance()->MapColorLUT(remappedColor);
}
const Rect rect = pixMapHeader.m_bounds.ToRect();
if (!rect.IsValid())
return false;
THandle<PixMapImpl> pixMap = PixMapImpl::Create(rect, GpPixelFormats::k8BitStandard);
if (!pixMap)
return false;
const size_t width = rect.Width();
const size_t height = rect.Height();
const size_t inPitch = (prefix.m_pitch & 0x7fff);
uint8_t *outData = static_cast<uint8_t*>((*pixMap)->GetPixelData());
const size_t outPitch = (*pixMap)->GetPitch();
for (size_t row = 0; row < height; row++)
{
if (numItems > 16)
{
// 8bpp
for (size_t col = 0; col < width; col++)
{
const unsigned int index = inData[col];
outData[col] = remapping[index];
}
}
else if (numItems > 4)
{
// 4bpp
for (size_t col = 0; col < width; col++)
{
const unsigned int index = (inData[col / 2] >> (4 - ((col & 1) * 4))) & 0x0f;
outData[col] = remapping[index];
}
}
else if (numItems > 2)
{
// 2bpp
for (size_t col = 0; col < width; col++)
{
const unsigned int index = (inData[col / 4] >> (6 - ((col & 3) * 2))) & 0x03;
outData[col] = remapping[index];
}
}
else
{
// 1bpp
for (size_t col = 0; col < width; col++)
{
const unsigned int index = (inData[col / 4] >> (7 - (col & 7))) & 0x01;
outData[col] = remapping[index];
}
}
inData += inPitch;
outData += outPitch;
}
outHandle = pixMap;
dataPtr = inData;
return true;
}
bool IconLoaderImpl::ParseBWImage(const IconImagePrefix &prefix, const BEBitMap &bitMapHeader, THandle<PixMapImpl> &outHandle, const uint8_t *&dataPtr)
{
const Rect rect = bitMapHeader.m_bounds.ToRect();
if (!rect.IsValid())
return false;
THandle<PixMapImpl> pixMap = PixMapImpl::Create(rect, GpPixelFormats::kBW1);
if (!pixMap)
return THandle<PixMapImpl>();
const size_t inPitch = prefix.m_pitch;
const size_t height = rect.Height();
const size_t width = rect.Width();
const uint8_t *inData = dataPtr;
uint8_t *outData = static_cast<uint8_t*>((*pixMap)->GetPixelData());
const size_t outPitch = (*pixMap)->GetPitch();
for (size_t row = 0; row < height; row++)
{
for (size_t col = 0; col < width; col++)
{
if (inData[col / 8] & (0x80 >> (col & 7)))
outData[col] = 0xff;
else
outData[col] = 0x00;
}
inData += inPitch;
outData += outPitch;
}
dataPtr = inData;
outHandle = pixMap;
return true;
}
THandle<PixMapImpl> IconLoaderImpl::LoadBWIcon(const int16_t id)
{
PL_NotYetImplemented();
return THandle<PixMapImpl>();
}
IconLoaderImpl *IconLoaderImpl::GetInstance()
{
return &ms_instance;
}
IconLoaderImpl IconLoaderImpl::ms_instance;
IconLoader *IconLoader::GetInstance()
{
return IconLoaderImpl::GetInstance();
}
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include <stdint.h>
template<class T>
class THandle;
namespace PortabilityLayer
{
class PixMapImpl;
class SimpleImage;
class IconLoader
{
public:
virtual bool LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage) = 0;
virtual THandle<PixMapImpl> LoadBWIcon(const int16_t id) = 0;
static IconLoader *GetInstance();
};
}

View File

@@ -4,8 +4,8 @@ namespace PortabilityLayer
{ {
size_t MMBlock::AlignedSize() size_t MMBlock::AlignedSize()
{ {
const size_t paddedSize = sizeof(MMBlock) + PL_SYSTEM_MEMORY_ALIGNMENT - 1; const size_t paddedSize = sizeof(MMBlock) + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
const size_t paddedSizeTruncated = paddedSize - (paddedSize % PL_SYSTEM_MEMORY_ALIGNMENT); const size_t paddedSizeTruncated = paddedSize - (paddedSize % GP_SYSTEM_MEMORY_ALIGNMENT);
return paddedSizeTruncated; return paddedSizeTruncated;
} }

View File

@@ -11,7 +11,7 @@ namespace PortabilityLayer
{ {
struct MMBlock struct MMBlock
{ {
SmallestUInt<PL_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t m_offsetFromAllocLocation; SmallestUInt<GP_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t m_offsetFromAllocLocation;
static size_t AlignedSize(); static size_t AlignedSize();
}; };

View File

@@ -22,7 +22,7 @@ namespace PortabilityLayer
size_t m_size; size_t m_size;
private: private:
MMHandleBlock() PL_DELETED; MMHandleBlock() GP_DELETED;
}; };
} }

View File

@@ -26,7 +26,7 @@ namespace PortabilityLayer
void Close() override; void Close() override;
private: private:
MemReaderStream() PL_DELETED; MemReaderStream() GP_DELETED;
const uint8_t *m_bytes; const uint8_t *m_bytes;
size_t m_size; size_t m_size;

View File

@@ -51,7 +51,7 @@ namespace PortabilityLayer
const size_t oldBufOffsetFromAlignLoc = oldBufMMBlock->m_offsetFromAllocLocation; const size_t oldBufOffsetFromAlignLoc = oldBufMMBlock->m_offsetFromAllocLocation;
uint8_t *oldBufBase = oldBufBytes - MMBlock::AlignedSize() - oldBufOffsetFromAlignLoc; uint8_t *oldBufBase = oldBufBytes - MMBlock::AlignedSize() - oldBufOffsetFromAlignLoc;
const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + PL_SYSTEM_MEMORY_ALIGNMENT - 1; const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - newSize < mmBlockSizeWithMaxPadding) if (SIZE_MAX - newSize < mmBlockSizeWithMaxPadding)
return nullptr; return nullptr;
@@ -60,17 +60,17 @@ namespace PortabilityLayer
if (!newBuffer) if (!newBuffer)
return nullptr; return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(newBuffer) & static_cast<intptr_t>(PL_SYSTEM_MEMORY_ALIGNMENT - 1); const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(newBuffer) & static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0; intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0) if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(PL_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint; alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
// Check if the alignment changed, if so relocate // Check if the alignment changed, if so relocate
if (static_cast<size_t>(alignPadding) != oldBufOffsetFromAlignLoc) if (static_cast<size_t>(alignPadding) != oldBufOffsetFromAlignLoc)
memmove(newBuffer + alignPadding, newBuffer + oldBufOffsetFromAlignLoc, MMBlock::AlignedSize() + newSize); memmove(newBuffer + alignPadding, newBuffer + oldBufOffsetFromAlignLoc, MMBlock::AlignedSize() + newSize);
MMBlock *newMMBlock = reinterpret_cast<MMBlock*>(newBuffer + alignPadding); MMBlock *newMMBlock = reinterpret_cast<MMBlock*>(newBuffer + alignPadding);
newMMBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<PL_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding); newMMBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<GP_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding);
return newBuffer + alignPadding + MMBlock::AlignedSize(); return newBuffer + alignPadding + MMBlock::AlignedSize();
} }
@@ -80,7 +80,7 @@ namespace PortabilityLayer
if (size == 0) if (size == 0)
return nullptr; return nullptr;
const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + PL_SYSTEM_MEMORY_ALIGNMENT - 1; const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - size < mmBlockSizeWithMaxPadding) if (SIZE_MAX - size < mmBlockSizeWithMaxPadding)
return nullptr; return nullptr;
@@ -88,13 +88,13 @@ namespace PortabilityLayer
if (!buffer) if (!buffer)
return nullptr; return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(buffer) & static_cast<intptr_t>(PL_SYSTEM_MEMORY_ALIGNMENT - 1); const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(buffer) & static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0; intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0) if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(PL_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint; alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
MMBlock *mmBlock = reinterpret_cast<MMBlock*>(buffer + alignPadding); MMBlock *mmBlock = reinterpret_cast<MMBlock*>(buffer + alignPadding);
mmBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<PL_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding); mmBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<GP_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding);
return buffer + alignPadding + MMBlock::AlignedSize(); return buffer + alignPadding + MMBlock::AlignedSize();
} }

View File

@@ -23,8 +23,13 @@ private:
size_t m_count; size_t m_count;
}; };
#include "CoreDefs.h"
#include "PLArrayViewIterator.h" #include "PLArrayViewIterator.h"
#if GP_DEBUG_CONFIG
#include <assert.h>
#endif
template<class T> template<class T>
inline ArrayView<T>::ArrayView(const T *items, size_t count) inline ArrayView<T>::ArrayView(const T *items, size_t count)
: m_items(items) : m_items(items)
@@ -48,17 +53,29 @@ inline size_t ArrayView<T>::Count() const
template<class T> template<class T>
const T &ArrayView<T>::operator[](size_t index) const const T &ArrayView<T>::operator[](size_t index) const
{ {
#if GP_DEBUG_CONFIG
assert(index < m_count);
#endif
return m_items[index]; return m_items[index];
} }
template<class T> template<class T>
inline ArrayViewIterator<T> ArrayView<T>::begin() const inline ArrayViewIterator<T> ArrayView<T>::begin() const
{ {
#if GP_DEBUG_CONFIG
return ArrayViewIterator<T>(m_items, m_count, 0);
#else
return ArrayViewIterator<T>(m_items); return ArrayViewIterator<T>(m_items);
#endif
} }
template<class T> template<class T>
inline ArrayViewIterator<T> ArrayView<T>::end() const inline ArrayViewIterator<T> ArrayView<T>::end() const
{ {
#if GP_DEBUG_CONFIG
return ArrayViewIterator<T>(m_items, m_count, m_count);
#else
return ArrayViewIterator<T>(m_items + m_count); return ArrayViewIterator<T>(m_items + m_count);
#endif
} }

View File

@@ -1,12 +1,18 @@
#pragma once #pragma once
#include "CoreDefs.h"
#include <stdint.h> #include <stdint.h>
template<class T> template<class T>
class ArrayViewIterator class ArrayViewIterator
{ {
public: public:
#if GP_DEBUG_CONFIG
ArrayViewIterator(T *items, size_t count, size_t index);
#else
ArrayViewIterator(T *item); ArrayViewIterator(T *item);
#endif
ArrayViewIterator(const ArrayViewIterator<T> &other); ArrayViewIterator(const ArrayViewIterator<T> &other);
ArrayViewIterator<T> operator++(int); ArrayViewIterator<T> operator++(int);
@@ -24,9 +30,88 @@ public:
operator T*() const; operator T*() const;
private: private:
#if GP_DEBUG_CONFIG
T *m_items;
size_t m_count;
size_t m_index;
#else
T *m_iter; T *m_iter;
#endif
}; };
#if GP_DEBUG_CONFIG
#include <assert.h>
template<class T>
inline ArrayViewIterator<T>::ArrayViewIterator(T *items, size_t count, size_t index)
: m_items(items)
, m_count(count)
, m_index(index)
{
}
template<class T>
inline ArrayViewIterator<T>::ArrayViewIterator(const ArrayViewIterator<T> &other)
: m_items(other.m_items)
, m_count(other.m_count)
, m_index(other.m_index)
{
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator+=(ptrdiff_t delta)
{
if (delta < 0)
{
assert(-static_cast<ptrdiff_t>(m_index) >= delta);
}
else
{
assert(static_cast<ptrdiff_t>(m_count) >= delta && static_cast<ptrdiff_t>(m_count - m_index) >= delta);
}
m_index = static_cast<size_t>(static_cast<ptrdiff_t>(m_index) + delta);
return *this;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator-=(ptrdiff_t delta)
{
if (delta >= 0)
{
assert(static_cast<ptrdiff_t>(m_index) >= delta);
}
else
{
assert(-static_cast<ptrdiff_t>(m_count) <= delta && -static_cast<ptrdiff_t>(m_count - m_index) <= delta);
}
m_index = static_cast<size_t>(static_cast<ptrdiff_t>(m_index) - delta);
return *this;
}
template<class T>
inline bool ArrayViewIterator<T>::operator==(const ArrayViewIterator<T> &other) const
{
return m_index == other.m_index && m_items == other.m_items;
}
template<class T>
inline bool ArrayViewIterator<T>::operator!=(const ArrayViewIterator<T> &other) const
{
return m_index != other.m_index || m_items != other.m_items;
}
template<class T>
inline ArrayViewIterator<T>::operator T*() const
{
assert(m_index < m_count);
return m_items + m_index;
}
#else
template<class T> template<class T>
inline ArrayViewIterator<T>::ArrayViewIterator(T *item) inline ArrayViewIterator<T>::ArrayViewIterator(T *item)
: m_iter(item) : m_iter(item)
@@ -39,36 +124,6 @@ inline ArrayViewIterator<T>::ArrayViewIterator(const ArrayViewIterator<T> &other
{ {
} }
template<class T>
inline ArrayViewIterator<T> ArrayViewIterator<T>::operator++(int)
{
ArrayViewIterator<T> copy = *this;
m_iter++;
return copy;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator++()
{
m_iter++;
return *this;
}
template<class T>
inline ArrayViewIterator<T> ArrayViewIterator<T>::operator--(int)
{
ArrayViewIterator<T> copy = *this;
m_iter--;
return copy;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator--()
{
m_iter--;
return *this;
}
template<class T> template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator+=(ptrdiff_t delta) inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator+=(ptrdiff_t delta)
{ {
@@ -92,7 +147,7 @@ inline bool ArrayViewIterator<T>::operator==(const ArrayViewIterator<T> &other)
template<class T> template<class T>
inline bool ArrayViewIterator<T>::operator!=(const ArrayViewIterator<T> &other) const inline bool ArrayViewIterator<T>::operator!=(const ArrayViewIterator<T> &other) const
{ {
return m_iter == other.m_iter; return m_iter != other.m_iter;
} }
template<class T> template<class T>
@@ -100,3 +155,36 @@ inline ArrayViewIterator<T>::operator T*() const
{ {
return m_iter; return m_iter;
} }
#endif
template<class T>
inline ArrayViewIterator<T> ArrayViewIterator<T>::operator++(int)
{
ArrayViewIterator<T> copy = *this;
++(*this);
return copy;
}
template<class T>
inline ArrayViewIterator<T> ArrayViewIterator<T>::operator--(int)
{
ArrayViewIterator<T> copy = *this;
--(*this);
return copy;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator++()
{
(*this) += 1;
return *this;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator--()
{
(*this) -= 1;
return *this;
}

View File

@@ -0,0 +1,54 @@
#include "PLButtonWidget.h"
#include "PLCore.h"
#include "PLTimeTaggedVOSEvent.h"
namespace PortabilityLayer
{
ButtonWidget::ButtonWidget(const WidgetBasicState &state)
: WidgetSpec<ButtonWidget>(state)
, m_haveMouseDown(false)
{
}
WidgetHandleState_t ButtonWidget::ProcessEvent(Window *window, const TimeTaggedVOSEvent &evt)
{
if (m_haveMouseDown)
{
if (evt.IsLMouseUpEvent())
{
m_haveMouseDown = false;
const Point pt = window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent);
if (m_rect.Contains(pt))
return WidgetHandleStates::kActivated;
else
return WidgetHandleStates::kIgnored;
}
return WidgetHandleStates::kCaptured;
}
else
{
if (evt.IsLMouseDownEvent())
{
const Point pt = window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent);
if (m_rect.Contains(pt))
{
m_haveMouseDown = true;
return WidgetHandleStates::kCaptured;
}
else
return WidgetHandleStates::kIgnored;
}
}
return WidgetHandleStates::kIgnored;
}
bool ButtonWidget::Init(const WidgetBasicState &state)
{
(void)state;
return true;
}
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "PascalStr.h"
#include "PLWidgets.h"
namespace PortabilityLayer
{
class ButtonWidget final : public WidgetSpec<ButtonWidget>
{
public:
explicit ButtonWidget(const WidgetBasicState &state);
bool Init(const WidgetBasicState &state) override;
WidgetHandleState_t ProcessEvent(Window *window, const TimeTaggedVOSEvent &evt);
private:
bool m_haveMouseDown;
PascalStr<255> m_text;
};
}

View File

@@ -0,0 +1,28 @@
#include "PLCTabReducer.h"
#include "RGBAColor.h"
#include "SharedTypes.h"
namespace PortabilityLayer
{
uint8_t CTabReducer::DecodeClutItemChannel(const uint8_t *color16)
{
const int colorHigh = color16[0];
const int colorLow = color16[1];
const int lowDelta = colorLow - colorHigh;
if (lowDelta < -128)
return static_cast<uint8_t>(colorHigh - 1);
else if (lowDelta > 128)
return static_cast<uint8_t>(colorHigh + 1);
return static_cast<uint8_t>(colorHigh);
}
RGBAColor CTabReducer::DecodeClutItem(const BEColorTableItem &clutItem)
{
const uint8_t r = DecodeClutItemChannel(clutItem.m_red);
const uint8_t g = DecodeClutItemChannel(clutItem.m_green);
const uint8_t b = DecodeClutItemChannel(clutItem.m_blue);
return RGBAColor::Create(r, g, b, 255);
}
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include <stdint.h>
struct BEColorTableItem;
namespace PortabilityLayer
{
struct RGBAColor;
class CTabReducer
{
public:
static uint8_t DecodeClutItemChannel(const uint8_t *color16);
static RGBAColor DecodeClutItem(const BEColorTableItem &clutItem);
};
}

View File

@@ -33,6 +33,7 @@
#include "PLBigEndian.h" #include "PLBigEndian.h"
#include "PLEventQueue.h" #include "PLEventQueue.h"
#include "PLKeyEncoding.h" #include "PLKeyEncoding.h"
#include "PLSysCalls.h"
#include "PLTimeTaggedVOSEvent.h" #include "PLTimeTaggedVOSEvent.h"
#include "QDManager.h" #include "QDManager.h"
#include "Vec2i.h" #include "Vec2i.h"
@@ -65,113 +66,6 @@ static bool ConvertFilenameToSafePStr(const char *str, uint8_t *pstr)
return true; return true;
} }
static void TranslateMouseInputEvent(const GpVOSEvent &vosEventBase, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
const GpMouseInputEvent &vosEvent = vosEventBase.m_event.m_mouseInputEvent;
bool requeue = false;
if (vosEvent.m_button == GpMouseButtons::kLeft)
{
if (vosEvent.m_eventType == GpMouseEventTypes::kDown)
requeue = true;
else if (vosEvent.m_eventType == GpMouseEventTypes::kUp)
requeue = true;
}
else if (vosEvent.m_eventType == GpMouseEventTypes::kMove)
requeue = true;
if (requeue)
{
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
*evt = TimeTaggedVOSEvent::Create(vosEventBase, timestamp);
}
}
static void TranslateGamepadInputEvent(const GpGamepadInputEvent &vosEvent, PortabilityLayer::EventQueue *queue)
{
PortabilityLayer::InputManager *inputManager = PortabilityLayer::InputManager::GetInstance();
inputManager->ApplyGamepadEvent(vosEvent);
PL_DEAD(queue);
}
static void TranslateKeyboardInputEvent(const GpVOSEvent &vosEventBase, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
const GpKeyboardInputEvent &vosEvent = vosEventBase.m_event.m_keyboardInputEvent;
PL_STATIC_ASSERT((1 << PL_INPUT_PLAYER_INDEX_BITS) >= PL_INPUT_MAX_PLAYERS);
PL_STATIC_ASSERT((1 << PL_INPUT_TYPE_CODE_BITS) >= KeyEventType_Count);
PortabilityLayer::InputManager *inputManager = PortabilityLayer::InputManager::GetInstance();
if (vosEvent.m_eventType == GpKeyboardInputEventTypes::kUp || vosEvent.m_eventType == GpKeyboardInputEventTypes::kDown)
inputManager->ApplyKeyboardEvent(vosEvent);
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
*evt = TimeTaggedVOSEvent::Create(vosEventBase, timestamp);
}
intptr_t PackVOSKeyCode(const GpKeyboardInputEvent &vosEvent)
{
switch (vosEvent.m_keyIDSubset)
{
case GpKeyIDSubsets::kASCII:
return PL_KEY_ASCII(vosEvent.m_key.m_asciiChar);
case GpKeyIDSubsets::kFKey:
return PL_KEY_FKEY(vosEvent.m_key.m_fKey);
case GpKeyIDSubsets::kNumPadNumber:
return PL_KEY_NUMPAD_NUMBER(vosEvent.m_key.m_numPadNumber);
case GpKeyIDSubsets::kSpecial:
return PL_KEY_SPECIAL_ENCODE(vosEvent.m_key.m_specialKey);
break;
case GpKeyIDSubsets::kNumPadSpecial:
return PL_KEY_NUMPAD_SPECIAL_ENCODE(vosEvent.m_key.m_numPadSpecialKey);
break;
case GpKeyIDSubsets::kUnicode:
for (int i = 128; i < 256; i++)
{
if (PortabilityLayer::MacRoman::g_toUnicode[i] == vosEvent.m_key.m_unicodeChar)
return PL_KEY_MACROMAN(i);
}
break;
case GpKeyIDSubsets::kGamepadButton:
return PL_KEY_GAMEPAD_BUTTON_ENCODE(vosEvent.m_key.m_gamepadKey.m_button, vosEvent.m_key.m_gamepadKey.m_player);
default:
return 0;
}
return 0;
}
static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
switch (vosEvent->m_eventType)
{
case GpVOSEventTypes::kMouseInput:
TranslateMouseInputEvent(*vosEvent, timestamp, queue);
break;
case GpVOSEventTypes::kKeyboardInput:
TranslateKeyboardInputEvent(*vosEvent, timestamp, queue);
break;
case GpVOSEventTypes::kGamepadInput:
TranslateGamepadInputEvent(vosEvent->m_event.m_gamepadInputEvent, queue);
break;
}
}
static void ImportVOSEvents(uint32_t timestamp)
{
PortabilityLayer::EventQueue *plQueue = PortabilityLayer::EventQueue::GetInstance();
PortabilityLayer::HostVOSEventQueue *evtQueue = PortabilityLayer::HostVOSEventQueue::GetInstance();
while (const GpVOSEvent *evt = evtQueue->GetNext())
{
TranslateVOSEvent(evt, timestamp, plQueue);
evtQueue->DischargeOne();
}
}
void InitCursor() void InitCursor()
{ {
PortabilityLayer::HostDisplayDriver::GetInstance()->SetStandardCursor(EGpStandardCursors::kArrow); PortabilityLayer::HostDisplayDriver::GetInstance()->SetStandardCursor(EGpStandardCursors::kArrow);
@@ -244,15 +138,7 @@ void DisposeCCursor(CCrsrHandle handle)
void Delay(int ticks, UInt32 *endTickCount) void Delay(int ticks, UInt32 *endTickCount)
{ {
if (ticks > 0) PLSysCalls::Sleep(ticks);
{
PortabilityLayer::HostSuspendCallArgument args[1];
args[0].m_uint = static_cast<uint32_t>(ticks);
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_Delay, args, nullptr);
ImportVOSEvents(PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount());
}
if (endTickCount) if (endTickCount)
*endTickCount = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount(); *endTickCount = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount();
@@ -718,30 +604,6 @@ void DisposeDirectoryFiles(DirectoryFileListEntry *firstDFL)
} }
} }
short StringWidth(const PLPasStr &str)
{
const PortabilityLayer::QDState *qdState = PortabilityLayer::QDManager::GetInstance()->GetState();
PortabilityLayer::FontManager *fontManager = PortabilityLayer::FontManager::GetInstance();
PortabilityLayer::FontFamily *fontFamily = qdState->m_fontFamily;
if (!fontFamily)
return 0;
const int variationFlags = qdState->m_fontVariationFlags;
const int fontSize = qdState->m_fontSize;
PortabilityLayer::RenderedFont *rfont = fontManager->GetRenderedFontFromFamily(fontFamily, fontSize, variationFlags);
if (!rfont)
return 0;
const size_t width = rfont->MeasureString(str.UChars(), str.Length());
if (width > SHRT_MAX)
return SHRT_MAX;
return static_cast<short>(width);
}
void GetMouse(Point *point) void GetMouse(Point *point)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented();
@@ -965,3 +827,8 @@ DrawSurface *Window::GetDrawSurface() const
{ {
return const_cast<DrawSurface*>(&m_graf); return const_cast<DrawSurface*>(&m_graf);
} }
Point Window::MouseToLocal(const GpMouseInputEvent &evt) const
{
return Point::Create(evt.m_x - m_wmX, evt.m_y - m_wmY);
}

View File

@@ -15,6 +15,7 @@
struct IGpColorCursor; struct IGpColorCursor;
struct GpVOSEvent; struct GpVOSEvent;
struct GpMouseInputEvent;
struct TimeTaggedVOSEvent; struct TimeTaggedVOSEvent;
namespace PortabilityLayer namespace PortabilityLayer
@@ -104,6 +105,9 @@ struct Window
DrawSurface *GetDrawSurface() const; DrawSurface *GetDrawSurface() const;
// Convenience method to convert a mouse event to local point
Point MouseToLocal(const GpMouseInputEvent &evt) const;
DrawSurface m_graf; // Must be the first item DrawSurface m_graf; // Must be the first item
// The port is always at 0,0 // The port is always at 0,0
@@ -308,8 +312,6 @@ PLError_t PBGetCatInfo(CInfoPBPtr paramBlock, Boolean async);
DirectoryFileListEntry *GetDirectoryFiles(PortabilityLayer::VirtualDirectory_t dirID); DirectoryFileListEntry *GetDirectoryFiles(PortabilityLayer::VirtualDirectory_t dirID);
void DisposeDirectoryFiles(DirectoryFileListEntry *firstDFL); void DisposeDirectoryFiles(DirectoryFileListEntry *firstDFL);
short StringWidth(const PLPasStr &str);
void GetMouse(Point *point); void GetMouse(Point *point);
Boolean Button(); // Returns true if there's a mouse down event in the queue Boolean Button(); // Returns true if there's a mouse down event in the queue
Boolean StillDown(); Boolean StillDown();

View File

@@ -71,8 +71,3 @@ void HideDialogItem(Dialog *dialog, int item)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented();
} }
void TETextBox(const PLPasStr &str, short len, const Rect *rect, TEMode teMode)
{
PL_NotYetImplemented();
}

View File

@@ -1,30 +1,29 @@
#pragma once #pragma once
#ifndef __PL_DIALOGS_H__
#define __PL_DIALOGS_H__
#include "PLCore.h" #include "PLCore.h"
namespace PortabilityLayer
{
class DialogItem;
}
template<class T> template<class T>
class ArrayView; class ArrayView;
class PLPasStr; class PLPasStr;
struct Control; struct Control;
struct Dialog;
struct DialogItem typedef int16_t(*DialogFilterFunc_t)(Dialog *dialog, const TimeTaggedVOSEvent &evt);
{
virtual Rect GetRect() const = 0;
};
struct Dialog struct Dialog
{ {
virtual void Destroy() = 0; virtual void Destroy() = 0;
virtual Window *GetWindow() const = 0;
virtual ArrayView<DialogItem*const> GetItems() const = 0;
};
enum TEMode virtual Window *GetWindow() const = 0;
{ virtual ArrayView<const PortabilityLayer::DialogItem> GetItems() const = 0;
teCenter
virtual int16_t ExecuteModal(DialogFilterFunc_t filterFunc) = 0;
}; };
typedef Boolean(*ModalFilterUPP)(Dialog *dial, EventRecord *event, short *item); typedef Boolean(*ModalFilterUPP)(Dialog *dial, EventRecord *event, short *item);
@@ -40,16 +39,9 @@ void SetDialogItemText(THandle<Control> handle, const PLPasStr &str);
void SelectDialogItemText(Dialog *dialog, int item, int firstSelChar, int lastSelCharExclusive); void SelectDialogItemText(Dialog *dialog, int item, int firstSelChar, int lastSelCharExclusive);
ModalFilterUPP NewModalFilterUPP(ModalFilterUPP func);
void ModalDialog(ModalFilterUPP filter, short *item); void ModalDialog(ModalFilterUPP filter, short *item);
void DisposeDialog(Dialog *dialog); void DisposeDialog(Dialog *dialog);
void DisposeModalFilterUPP(ModalFilterUPP upp);
void ShowDialogItem(Dialog *dialog, int item); void ShowDialogItem(Dialog *dialog, int item);
void HideDialogItem(Dialog *dialog, int item); void HideDialogItem(Dialog *dialog, int item);
void TETextBox(const PLPasStr &str, short len, const Rect *rect, TEMode teMode);
#endif

View File

@@ -6,4 +6,6 @@ void THandleBase::Dispose()
{ {
if (m_hdl) if (m_hdl)
PortabilityLayer::MemoryManager::GetInstance()->ReleaseHandle(m_hdl); PortabilityLayer::MemoryManager::GetInstance()->ReleaseHandle(m_hdl);
m_hdl = nullptr;
} }

View File

@@ -28,7 +28,8 @@ public:
explicit THandle(PortabilityLayer::MMHandleBlock *hdl); explicit THandle(PortabilityLayer::MMHandleBlock *hdl);
THandle(const THandle<T> &other); THandle(const THandle<T> &other);
operator T **() const; operator T *const*() const;
operator T **();
template<class TOther> template<class TOther>
THandle<TOther> StaticCast() const; THandle<TOther> StaticCast() const;
@@ -36,11 +37,16 @@ public:
template<class TOther> template<class TOther>
THandle<TOther> ReinterpretCast() const; THandle<TOther> ReinterpretCast() const;
template<class TOther>
THandle<TOther> ImplicitCast() const;
bool operator==(const THandle<T> &other) const; bool operator==(const THandle<T> &other) const;
bool operator!=(const THandle<T> &other) const; bool operator!=(const THandle<T> &other) const;
bool operator==(T** other) const; bool operator==(T** other) const;
bool operator!=(T** other) const; bool operator!=(T** other) const;
static THandle<T> NullPtr();
}; };
typedef THandle<void> Handle; typedef THandle<void> Handle;
@@ -87,33 +93,47 @@ inline THandle<T>::THandle(const THandle<T> &other)
} }
template<class T> template<class T>
bool THandle<T>::operator==(const THandle<T> &other) const inline bool THandle<T>::operator==(const THandle<T> &other) const
{ {
return m_hdl == other.m_hdl; return m_hdl == other.m_hdl;
} }
template<class T> template<class T>
bool THandle<T>::operator!=(const THandle<T> &other) const inline bool THandle<T>::operator!=(const THandle<T> &other) const
{ {
return m_hdl != other.m_hdl; return m_hdl != other.m_hdl;
} }
template<class T> template<class T>
bool THandle<T>::operator==(T** other) const inline bool THandle<T>::operator==(T** other) const
{ {
return static_cast<void*>(&m_hdl->m_contents) == static_cast<void*>(other); return static_cast<void*>(&m_hdl->m_contents) == static_cast<void*>(other);
} }
template<class T> template<class T>
bool THandle<T>::operator!=(T** other) const inline bool THandle<T>::operator!=(T** other) const
{ {
return static_cast<void*>(&m_hdl->m_contents) != static_cast<void*>(other); return static_cast<void*>(&m_hdl->m_contents) != static_cast<void*>(other);
} }
template<class T> template<class T>
inline THandle<T>::operator T**() const THandle<T> THandle<T>::NullPtr()
{ {
return reinterpret_cast<T**>(&m_hdl->m_contents); return THandle<T>(static_cast<PortabilityLayer::MMHandleBlock *>(nullptr));
}
template<class T>
inline THandle<T>::operator T*const*() const
{
// Should use const_cast here but then I'd have to strip qualifiers, blah, do the lazy thing
return (T*const*)(&m_hdl->m_contents);
}
template<class T>
inline THandle<T>::operator T**()
{
// Should use const_cast here but then I'd have to strip qualifiers, blah, do the lazy thing
return (T**)(&m_hdl->m_contents);
} }
template<class T> template<class T>
@@ -131,3 +151,13 @@ THandle<TOther> THandle<T>::ReinterpretCast() const
(void)(reinterpret_cast<TOther*>(static_cast<T*>(nullptr))); (void)(reinterpret_cast<TOther*>(static_cast<T*>(nullptr)));
return THandle<TOther>(m_hdl); return THandle<TOther>(m_hdl);
} }
template<class T>
template<class TOther>
THandle<TOther> THandle<T>::ImplicitCast() const
{
const TOther *target = static_cast<const T*>(nullptr);
(void)target;
return THandle<TOther>(m_hdl);
}

View File

@@ -0,0 +1,49 @@
#include "PLIconWidget.h"
#include "IconLoader.h"
#include "QDPixMap.h"
#include <assert.h>
namespace PortabilityLayer
{
IconWidget::IconWidget(const WidgetBasicState &state)
: WidgetSpec<IconWidget>(state)
{
}
IconWidget::~IconWidget()
{
if (m_iconImage)
PixMapImpl::Destroy(m_iconImage);
if (m_iconMask)
PixMapImpl::Destroy(m_iconMask);
}
bool IconWidget::Init(const WidgetBasicState &state)
{
PL_DEAD(str);
THandle<PixMapImpl> colorImage;
THandle<PixMapImpl> bwImage;
THandle<PixMapImpl> maskImage;
if (!PortabilityLayer::IconLoader::GetInstance()->LoadColorIcon(state.m_resID, colorImage, bwImage, maskImage))
return false;
PixMapImpl::Destroy(bwImage);
m_iconImage = colorImage;
m_iconMask = maskImage;
assert(m_iconImage != nullptr);
assert(m_iconMask != nullptr);
return true;
}
void IconWidget::DrawControl(DrawSurface *surface)
{
CopyMask(*m_iconImage, *m_iconMask, *surface->m_port.GetPixMap(), &(*m_iconImage)->m_rect, &(*m_iconMask)->m_rect, &m_rect);
surface->m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include "PLWidgets.h"
#include "PLHandle.h"
namespace PortabilityLayer
{
class PixMapImpl;
class IconWidget final : public WidgetSpec<IconWidget>
{
public:
IconWidget(const WidgetBasicState &state);
~IconWidget() override;
bool Init(const WidgetBasicState &state) override;
void DrawControl(DrawSurface *surface) override;
private:
THandle<PixMapImpl> m_iconImage;
THandle<PixMapImpl> m_iconMask;
};
}

View File

@@ -0,0 +1,20 @@
#include "PLInvisibleWidget.h"
namespace PortabilityLayer
{
InvisibleWidget::InvisibleWidget(const WidgetBasicState &state)
: WidgetSpec<InvisibleWidget>(state)
{
}
InvisibleWidget::~InvisibleWidget()
{
}
bool InvisibleWidget::Init(const WidgetBasicState &state)
{
(void)state;
return true;
}
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "PLWidgets.h"
namespace PortabilityLayer
{
class InvisibleWidget final : public WidgetSpec<InvisibleWidget>
{
public:
InvisibleWidget(const WidgetBasicState &state);
~InvisibleWidget();
bool Init(const WidgetBasicState &state) override;
};
}

View File

@@ -0,0 +1,32 @@
#include "PLLabelWidget.h"
#include "PLQDraw.h"
#include "FontFamily.h"
#include "PLStandardColors.h"
#include <algorithm>
namespace PortabilityLayer
{
LabelWidget::LabelWidget(const WidgetBasicState &state)
: WidgetSpec<LabelWidget>(state)
, m_text(state.m_text)
{
}
bool LabelWidget::Init(const WidgetBasicState &state)
{
(void)state;
return true;
}
void LabelWidget::DrawControl(DrawSurface *surface)
{
surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold);
surface->SetForeColor(StdColors::Black());
const Point topLeftCorner = Point::Create(m_rect.left, m_rect.top);
const Point textStartPoint = topLeftCorner + Point::Create(0, surface->MeasureFontAscender());
surface->DrawString(textStartPoint, m_text.ToShortStr());
}
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include "PascalStr.h"
#include "PLWidgets.h"
namespace PortabilityLayer
{
class LabelWidget final : public WidgetSpec<LabelWidget>
{
public:
LabelWidget(const WidgetBasicState &state);
bool Init(const WidgetBasicState &state) override;
void DrawControl(DrawSurface *surface) override;
private:
PascalStr<255> m_text;
};
}

View File

@@ -1 +0,0 @@
#pragma once

View File

@@ -11,6 +11,7 @@
#include "HostFontHandler.h" #include "HostFontHandler.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "RenderedFont.h" #include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "RenderedGlyphMetrics.h" #include "RenderedGlyphMetrics.h"
#include "Rect2i.h" #include "Rect2i.h"
#include "ResourceManager.h" #include "ResourceManager.h"
@@ -274,23 +275,6 @@ PLError_t PlotIconSuite(Rect *rect, Handle iconSuite)
return PLErrors::kNone; return PLErrors::kNone;
} }
CIconHandle GetCIcon(short resID)
{
PL_NotYetImplemented();
return nullptr;
}
PLError_t PlotCIcon(Rect *rect, CIconHandle icon)
{
PL_NotYetImplemented();
return PLErrors::kNone;
}
void DisposeCIcon(CIconHandle icon)
{
PL_NotYetImplemented();
}
void SetRect(Rect *rect, short left, short top, short right, short bottom) void SetRect(Rect *rect, short left, short top, short right, short bottom)
{ {
rect->left = left; rect->left = left;
@@ -523,7 +507,7 @@ static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const
const PortabilityLayer::RenderedGlyphMetrics *metrics; const PortabilityLayer::RenderedGlyphMetrics *metrics;
const void *data; const void *data;
if (!rfont->GetGlyph(character, &metrics, &data)) if (!rfont->GetGlyph(character, metrics, data))
return; return;
const Point originalPoint = penPos; const Point originalPoint = penPos;
@@ -608,10 +592,59 @@ void DrawSurface::DrawString(const Point &point, const PLPasStr &str)
if (!rect.IsValid()) if (!rect.IsValid())
return; // ??? return; // ???
Point paraStartPos = penPos;
for (size_t i = 0; i < len; i++) for (size_t i = 0; i < len; i++)
DrawGlyph(qdState, pixMap, rect, penPos, rfont, chars[i]); {
if (chars[i] == static_cast<uint8_t>('\r'))
{
paraStartPos.v += rfont->GetMetrics().m_linegap;
penPos = paraStartPos;
}
else
DrawGlyph(qdState, pixMap, rect, penPos, rfont, chars[i]);
}
} }
size_t DrawSurface::MeasureString(const PLPasStr &str)
{
const PortabilityLayer::QDState *qdState = m_port.GetState();
PortabilityLayer::FontManager *fontManager = PortabilityLayer::FontManager::GetInstance();
PortabilityLayer::FontFamily *fontFamily = qdState->m_fontFamily;
if (!fontFamily)
return 0;
const int variationFlags = qdState->m_fontVariationFlags;
const int fontSize = qdState->m_fontSize;
PortabilityLayer::RenderedFont *rfont = fontManager->GetRenderedFontFromFamily(fontFamily, fontSize, variationFlags);
if (!rfont)
return 0;
return rfont->MeasureString(str.UChars(), str.Length());
}
int32_t DrawSurface::MeasureFontAscender()
{
const PortabilityLayer::QDState *qdState = m_port.GetState();
PortabilityLayer::FontManager *fontManager = PortabilityLayer::FontManager::GetInstance();
PortabilityLayer::FontFamily *fontFamily = qdState->m_fontFamily;
if (!fontFamily)
return 0;
const int variationFlags = qdState->m_fontVariationFlags;
const int fontSize = qdState->m_fontSize;
PortabilityLayer::RenderedFont *rfont = fontManager->GetRenderedFontFromFamily(fontFamily, fontSize, variationFlags);
if (!rfont)
return 0;
return rfont->GetMetrics().m_ascent;
}
void DrawSurface::DrawPicture(THandle<Picture> pictHdl, const Rect &bounds) void DrawSurface::DrawPicture(THandle<Picture> pictHdl, const Rect &bounds)
{ {
@@ -1056,11 +1089,6 @@ const PortabilityLayer::RGBAColor &DrawSurface::GetBackColor() const
return m_port.GetState()->GetBackColor(); return m_port.GetState()->GetBackColor();
} }
void FrameRoundRect(const Rect *rect, int w, int h)
{
PL_NotYetImplemented_TODO("Ovals");
}
void PenInvertMode(bool invertMode) void PenInvertMode(bool invertMode)
{ {
PortabilityLayer::QDState *qdState = PortabilityLayer::QDManager::GetInstance()->GetState(); PortabilityLayer::QDState *qdState = PortabilityLayer::QDManager::GetInstance()->GetState();

View File

@@ -102,10 +102,6 @@ void EndUpdate(WindowPtr graf);
PLError_t GetIconSuite(Handle *suite, short resID, IconSuiteFlags flags); PLError_t GetIconSuite(Handle *suite, short resID, IconSuiteFlags flags);
PLError_t PlotIconSuite(Rect *rect, Handle iconSuite); PLError_t PlotIconSuite(Rect *rect, Handle iconSuite);
CIconHandle GetCIcon(short resID);
PLError_t PlotCIcon(Rect *rect, CIconHandle icon);
void DisposeCIcon(CIconHandle icon);
void SetRect(Rect *rect, short left, short top, short right, short bottom); void SetRect(Rect *rect, short left, short top, short right, short bottom);
int TextWidth(const PLPasStr &str, int firstChar1Based, int length); int TextWidth(const PLPasStr &str, int firstChar1Based, int length);
@@ -113,13 +109,10 @@ void SetOrigin(int x, int y);
void ForeColor(SystemColorID color); void ForeColor(SystemColorID color);
void BackColor(SystemColorID color); void BackColor(SystemColorID color);
void GetForeColor(RGBColor *color); void GetForeColor(RGBColor *color);
void PaintOval(const Rect *rect);
void ClipRect(const Rect *rect); void ClipRect(const Rect *rect);
void GetClip(Rect *rect); void GetClip(Rect *rect);
void FrameOval(const Rect *rect);
void FrameRoundRect(const Rect *rect, int w, int h);
void PenInvertMode(bool invertMode); void PenInvertMode(bool invertMode);
void PenMask(bool maskMode); void PenMask(bool maskMode);
void PenPat(const Pattern *pattern); void PenPat(const Pattern *pattern);

View File

@@ -208,7 +208,7 @@ namespace PortabilityLayer
BufferHeader bufferHeader; BufferHeader bufferHeader;
PL_STATIC_ASSERT(sizeof(BufferHeader) >= 22); GP_STATIC_ASSERT(sizeof(BufferHeader) >= 22);
memcpy(&bufferHeader, dataPointer, 22); memcpy(&bufferHeader, dataPointer, 22);

View File

@@ -0,0 +1,135 @@
#include "PLCore.h"
#include "PLEventQueue.h"
#include "PLKeyEncoding.h"
#include "PLSysCalls.h"
#include "PLTimeTaggedVOSEvent.h"
#include "DisplayDeviceManager.h"
#include "GpVOSEvent.h"
#include "InputManager.h"
#include "HostSuspendCallArgument.h"
#include "HostSuspendHook.h"
#include "HostVOSEventQueue.h"
#include "MacRoman.h"
static void TranslateMouseInputEvent(const GpVOSEvent &vosEventBase, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
const GpMouseInputEvent &vosEvent = vosEventBase.m_event.m_mouseInputEvent;
bool requeue = false;
if (vosEvent.m_button == GpMouseButtons::kLeft)
{
if (vosEvent.m_eventType == GpMouseEventTypes::kDown)
requeue = true;
else if (vosEvent.m_eventType == GpMouseEventTypes::kUp)
requeue = true;
}
else if (vosEvent.m_eventType == GpMouseEventTypes::kMove)
requeue = true;
if (requeue)
{
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
*evt = TimeTaggedVOSEvent::Create(vosEventBase, timestamp);
}
}
static void TranslateGamepadInputEvent(const GpGamepadInputEvent &vosEvent, PortabilityLayer::EventQueue *queue)
{
PortabilityLayer::InputManager *inputManager = PortabilityLayer::InputManager::GetInstance();
inputManager->ApplyGamepadEvent(vosEvent);
PL_DEAD(queue);
}
static void TranslateKeyboardInputEvent(const GpVOSEvent &vosEventBase, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
const GpKeyboardInputEvent &vosEvent = vosEventBase.m_event.m_keyboardInputEvent;
GP_STATIC_ASSERT((1 << PL_INPUT_PLAYER_INDEX_BITS) >= PL_INPUT_MAX_PLAYERS);
GP_STATIC_ASSERT((1 << PL_INPUT_TYPE_CODE_BITS) >= KeyEventType_Count);
PortabilityLayer::InputManager *inputManager = PortabilityLayer::InputManager::GetInstance();
if (vosEvent.m_eventType == GpKeyboardInputEventTypes::kUp || vosEvent.m_eventType == GpKeyboardInputEventTypes::kDown)
inputManager->ApplyKeyboardEvent(vosEvent);
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
*evt = TimeTaggedVOSEvent::Create(vosEventBase, timestamp);
}
intptr_t PackVOSKeyCode(const GpKeyboardInputEvent &vosEvent)
{
switch (vosEvent.m_keyIDSubset)
{
case GpKeyIDSubsets::kASCII:
return PL_KEY_ASCII(vosEvent.m_key.m_asciiChar);
case GpKeyIDSubsets::kFKey:
return PL_KEY_FKEY(vosEvent.m_key.m_fKey);
case GpKeyIDSubsets::kNumPadNumber:
return PL_KEY_NUMPAD_NUMBER(vosEvent.m_key.m_numPadNumber);
case GpKeyIDSubsets::kSpecial:
return PL_KEY_SPECIAL_ENCODE(vosEvent.m_key.m_specialKey);
break;
case GpKeyIDSubsets::kNumPadSpecial:
return PL_KEY_NUMPAD_SPECIAL_ENCODE(vosEvent.m_key.m_numPadSpecialKey);
break;
case GpKeyIDSubsets::kUnicode:
for (int i = 128; i < 256; i++)
{
if (PortabilityLayer::MacRoman::g_toUnicode[i] == vosEvent.m_key.m_unicodeChar)
return PL_KEY_MACROMAN(i);
}
break;
case GpKeyIDSubsets::kGamepadButton:
return PL_KEY_GAMEPAD_BUTTON_ENCODE(vosEvent.m_key.m_gamepadKey.m_button, vosEvent.m_key.m_gamepadKey.m_player);
default:
return 0;
}
return 0;
}
static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
switch (vosEvent->m_eventType)
{
case GpVOSEventTypes::kMouseInput:
TranslateMouseInputEvent(*vosEvent, timestamp, queue);
break;
case GpVOSEventTypes::kKeyboardInput:
TranslateKeyboardInputEvent(*vosEvent, timestamp, queue);
break;
case GpVOSEventTypes::kGamepadInput:
TranslateGamepadInputEvent(vosEvent->m_event.m_gamepadInputEvent, queue);
break;
}
}
static void ImportVOSEvents(uint32_t timestamp)
{
PortabilityLayer::EventQueue *plQueue = PortabilityLayer::EventQueue::GetInstance();
PortabilityLayer::HostVOSEventQueue *evtQueue = PortabilityLayer::HostVOSEventQueue::GetInstance();
while (const GpVOSEvent *evt = evtQueue->GetNext())
{
TranslateVOSEvent(evt, timestamp, plQueue);
evtQueue->DischargeOne();
}
}
namespace PLSysCalls
{
void Sleep(uint32_t ticks)
{
if (ticks > 0)
{
PortabilityLayer::HostSuspendCallArgument args[1];
args[0].m_uint = static_cast<uint32_t>(ticks);
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_Delay, args, nullptr);
ImportVOSEvents(PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount());
}
}
}

View File

@@ -0,0 +1,8 @@
#pragma once
#include <stdint.h>
namespace PLSysCalls
{
void Sleep(uint32_t ticks);
}

View File

@@ -20,3 +20,13 @@ bool TimeTaggedVOSEvent::IsLMouseDownEvent() const
return mouseEvent.m_eventType == GpMouseEventTypes::kDown && mouseEvent.m_button == GpMouseButtons::kLeft; return mouseEvent.m_eventType == GpMouseEventTypes::kDown && mouseEvent.m_button == GpMouseButtons::kLeft;
} }
bool TimeTaggedVOSEvent::IsLMouseUpEvent() const
{
if (m_vosEvent.m_eventType != GpVOSEventTypes::kMouseInput)
return false;
const GpMouseInputEvent &mouseEvent = m_vosEvent.m_event.m_mouseInputEvent;
return mouseEvent.m_eventType == GpMouseEventTypes::kUp && mouseEvent.m_button == GpMouseButtons::kLeft;
}

View File

@@ -12,6 +12,7 @@ struct TimeTaggedVOSEvent
// Helpers for common cases // Helpers for common cases
bool IsKeyDownEvent() const; bool IsKeyDownEvent() const;
bool IsLMouseDownEvent() const; bool IsLMouseDownEvent() const;
bool IsLMouseUpEvent() const;
}; };
inline TimeTaggedVOSEvent TimeTaggedVOSEvent::Create(const GpVOSEvent &vosEvent, uint32_t timestamp) inline TimeTaggedVOSEvent TimeTaggedVOSEvent::Create(const GpVOSEvent &vosEvent, uint32_t timestamp)

View File

@@ -0,0 +1,77 @@
#include "PLWidgets.h"
#include "MemoryManager.h"
namespace PortabilityLayer
{
WidgetBasicState::WidgetBasicState()
: m_resID(0)
, m_rect(Rect::Create(0, 0, 0, 0))
, m_enabled(true)
, m_window(nullptr)
{
}
WidgetHandleState_t Widget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
(void)evt;
return WidgetHandleStates::kIgnored;
}
void Widget::DrawControl(DrawSurface *surface)
{
(void)surface;
}
void Widget::SetEnabled(bool enabled)
{
m_enabled = enabled;
OnEnabledChanged();
}
void Widget::SetState(int16_t state)
{
m_state = state;
OnStateChanged();
}
void Widget::SetHighlightStyle(int16_t style)
{
(void)style;
}
const Rect &Widget::GetRect() const
{
return m_rect;
}
Widget::Widget(const WidgetBasicState &state)
: m_rect(state.m_rect)
, m_window(state.m_window)
, m_enabled(state.m_enabled)
, m_state(0)
{
}
Widget::~Widget()
{
}
void Widget::OnEnabledChanged()
{
}
void Widget::OnStateChanged()
{
}
void Widget::BaseRelease(void *storage)
{
PortabilityLayer::MemoryManager::GetInstance()->Release(storage);
}
void *Widget::BaseAlloc(size_t sz)
{
return PortabilityLayer::MemoryManager::GetInstance()->Alloc(sz);
}
}

View File

@@ -0,0 +1,106 @@
#pragma once
#include "PascalStr.h"
#include "SharedTypes.h"
struct DrawSurface;
class PLPasStr;
struct TimeTaggedVOSEvent;
struct Window;
namespace PortabilityLayer
{
namespace WidgetHandleStates
{
enum WidgetHandleState
{
kIgnored, // Event was ignored
kDigested, // Event was digested by the control
kCaptured, // Event was digested by the control and only this control should receive events until it returns a different result
kActivated, // Event caused the control to activate
};
}
typedef WidgetHandleStates::WidgetHandleState WidgetHandleState_t;
struct WidgetBasicState
{
WidgetBasicState();
Rect m_rect;
int16_t m_resID;
PascalStr<255> m_text;
bool m_enabled;
Window *m_window;
};
class Widget
{
public:
virtual bool Init(const WidgetBasicState &state) = 0;
virtual void Destroy() = 0;
virtual WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt);
virtual void DrawControl(DrawSurface *surface);
void SetEnabled(bool enabled);
void SetState(int16_t state);
virtual void SetHighlightStyle(int16_t style);
const Rect &GetRect() const;
protected:
explicit Widget(const WidgetBasicState &state);
virtual ~Widget();
virtual void OnEnabledChanged();
virtual void OnStateChanged();
static void BaseRelease(void *storage);
static void *BaseAlloc(size_t sz);
Window *m_window;
Rect m_rect;
int16_t m_state;
bool m_enabled;
};
}
#include <new>
#include <stdint.h>
namespace PortabilityLayer
{
template<class T>
class WidgetSpec : public Widget
{
public:
explicit WidgetSpec(const WidgetBasicState &state)
: Widget(state)
{
}
void Destroy() override
{
static_cast<T*>(this)->~T();
Widget::BaseRelease(static_cast<T*>(this));
}
static WidgetSpec<T> *Create(const WidgetBasicState &state)
{
void *storage = Widget::BaseAlloc(sizeof(T));
if (!storage)
return nullptr;
T *widgetT = new (storage) T(state);
Widget *widget = static_cast<Widget*>(widgetT);
if (!widget->Init(state))
{
widget->Destroy();
return nullptr;
}
return widgetT;
}
};
}

View File

@@ -163,6 +163,7 @@
<ClInclude Include="HostSystemServices.h" /> <ClInclude Include="HostSystemServices.h" />
<ClInclude Include="HostThreadEvent.h" /> <ClInclude Include="HostThreadEvent.h" />
<ClInclude Include="HostVOSEventQueue.h" /> <ClInclude Include="HostVOSEventQueue.h" />
<ClInclude Include="IconLoader.h" />
<ClInclude Include="InputManager.h" /> <ClInclude Include="InputManager.h" />
<ClInclude Include="IOStream.h" /> <ClInclude Include="IOStream.h" />
<ClInclude Include="IPlotter.h" /> <ClInclude Include="IPlotter.h" />
@@ -189,20 +190,28 @@
<ClInclude Include="PLArrayView.h" /> <ClInclude Include="PLArrayView.h" />
<ClInclude Include="PLArrayViewIterator.h" /> <ClInclude Include="PLArrayViewIterator.h" />
<ClInclude Include="PLBigEndian.h" /> <ClInclude Include="PLBigEndian.h" />
<ClInclude Include="PLButtonWidget.h" />
<ClInclude Include="PLControlDefinitions.h" /> <ClInclude Include="PLControlDefinitions.h" />
<ClInclude Include="PLCore.h" /> <ClInclude Include="PLCore.h" />
<ClInclude Include="PLCTabReducer.h" />
<ClInclude Include="PLDialogs.h" /> <ClInclude Include="PLDialogs.h" />
<ClInclude Include="PLErrorCodes.h" /> <ClInclude Include="PLErrorCodes.h" />
<ClInclude Include="PLEventQueue.h" /> <ClInclude Include="PLEventQueue.h" />
<ClInclude Include="PLHacks.h" /> <ClInclude Include="PLHacks.h" />
<ClInclude Include="PLHandle.h" /> <ClInclude Include="PLHandle.h" />
<ClInclude Include="PLIconWidget.h" />
<ClInclude Include="PLInvisibleWidget.h" />
<ClInclude Include="PLLabelWidget.h" />
<ClInclude Include="PLWidgets.h" />
<ClInclude Include="SimpleImage.h" />
<ClInclude Include="PLKeyEncoding.h" /> <ClInclude Include="PLKeyEncoding.h" />
<ClInclude Include="PLLowMem.h" />
<ClInclude Include="PLMacTypes.h" /> <ClInclude Include="PLMacTypes.h" />
<ClInclude Include="MenuManager.h" /> <ClInclude Include="MenuManager.h" />
<ClInclude Include="PlotDirection.h" /> <ClInclude Include="PlotDirection.h" />
<ClInclude Include="PLStandardColors.h" /> <ClInclude Include="PLStandardColors.h" />
<ClInclude Include="PLSysCalls.h" />
<ClInclude Include="PLTimeTaggedVOSEvent.h" /> <ClInclude Include="PLTimeTaggedVOSEvent.h" />
<ClInclude Include="RenderedFontMetrics.h" />
<ClInclude Include="ResolvedColor.h" /> <ClInclude Include="ResolvedColor.h" />
<ClInclude Include="ScanlineMaskBuilder.h" /> <ClInclude Include="ScanlineMaskBuilder.h" />
<ClInclude Include="ScanlineMaskConverter.h" /> <ClInclude Include="ScanlineMaskConverter.h" />
@@ -279,6 +288,7 @@
<ClCompile Include="HostSuspendHook.cpp" /> <ClCompile Include="HostSuspendHook.cpp" />
<ClCompile Include="HostSystemServices.cpp" /> <ClCompile Include="HostSystemServices.cpp" />
<ClCompile Include="HostVOSEventQueue.cpp" /> <ClCompile Include="HostVOSEventQueue.cpp" />
<ClCompile Include="IconLoader.cpp" />
<ClCompile Include="InputManager.cpp" /> <ClCompile Include="InputManager.cpp" />
<ClCompile Include="LinePlotter.cpp" /> <ClCompile Include="LinePlotter.cpp" />
<ClCompile Include="MacBinary2.cpp" /> <ClCompile Include="MacBinary2.cpp" />
@@ -292,11 +302,16 @@
<ClCompile Include="MMHandleBlock.cpp" /> <ClCompile Include="MMHandleBlock.cpp" />
<ClCompile Include="PLAppleEvents.cpp" /> <ClCompile Include="PLAppleEvents.cpp" />
<ClCompile Include="PLApplication.cpp" /> <ClCompile Include="PLApplication.cpp" />
<ClCompile Include="PLButtonWidget.cpp" />
<ClCompile Include="PLControlDefinitions.cpp" /> <ClCompile Include="PLControlDefinitions.cpp" />
<ClCompile Include="PLCore.cpp" /> <ClCompile Include="PLCore.cpp" />
<ClCompile Include="PLCTabReducer.cpp" />
<ClCompile Include="PLDialogs.cpp" /> <ClCompile Include="PLDialogs.cpp" />
<ClCompile Include="PLEventQueue.cpp" /> <ClCompile Include="PLEventQueue.cpp" />
<ClCompile Include="PLHacks.cpp" /> <ClCompile Include="PLHacks.cpp" />
<ClCompile Include="PLIconWidget.cpp" />
<ClCompile Include="PLInvisibleWidget.cpp" />
<ClCompile Include="PLLabelWidget.cpp" />
<ClCompile Include="PLMenus.cpp" /> <ClCompile Include="PLMenus.cpp" />
<ClCompile Include="PLMovies.cpp" /> <ClCompile Include="PLMovies.cpp" />
<ClCompile Include="PLNavigation.cpp" /> <ClCompile Include="PLNavigation.cpp" />
@@ -308,7 +323,9 @@
<ClCompile Include="PLSound.cpp" /> <ClCompile Include="PLSound.cpp" />
<ClCompile Include="PLStandardColors.cpp" /> <ClCompile Include="PLStandardColors.cpp" />
<ClCompile Include="PLStringCompare.cpp" /> <ClCompile Include="PLStringCompare.cpp" />
<ClCompile Include="PLSysCalls.cpp" />
<ClCompile Include="PLTimeTaggedVOSEvent.cpp" /> <ClCompile Include="PLTimeTaggedVOSEvent.cpp" />
<ClCompile Include="PLWidgets.cpp" />
<ClCompile Include="ScanlineMask.cpp" /> <ClCompile Include="ScanlineMask.cpp" />
<ClCompile Include="ScanlineMaskBuilder.cpp" /> <ClCompile Include="ScanlineMaskBuilder.cpp" />
<ClCompile Include="ScanlineMaskConverter.cpp" /> <ClCompile Include="ScanlineMaskConverter.cpp" />

View File

@@ -132,9 +132,6 @@
<ClInclude Include="PLPalettes.h"> <ClInclude Include="PLPalettes.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="PLLowMem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MemReaderStream.h"> <ClInclude Include="MemReaderStream.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@@ -408,6 +405,36 @@
<ClInclude Include="PLTimeTaggedVOSEvent.h"> <ClInclude Include="PLTimeTaggedVOSEvent.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="PLSysCalls.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RenderedFontMetrics.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IconLoader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SimpleImage.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLCTabReducer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLWidgets.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLButtonWidget.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLIconWidget.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLInvisibleWidget.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLLabelWidget.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="CFileStream.cpp"> <ClCompile Include="CFileStream.cpp">
@@ -620,5 +647,29 @@
<ClCompile Include="PLTimeTaggedVOSEvent.cpp"> <ClCompile Include="PLTimeTaggedVOSEvent.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="PLSysCalls.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IconLoader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLCTabReducer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLButtonWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLIconWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLWidgets.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLInvisibleWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLLabelWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -76,6 +76,9 @@ struct DrawSurface final
void SetSystemFont(int size, int variationFlags); void SetSystemFont(int size, int variationFlags);
void DrawString(const Point &point, const PLPasStr &str); void DrawString(const Point &point, const PLPasStr &str);
size_t MeasureString(const PLPasStr &str);
int32_t MeasureFontAscender();
void DrawPicture(THandle<Picture> pictHandle, const Rect &rect); void DrawPicture(THandle<Picture> pictHandle, const Rect &rect);
void SetPattern8x8(const uint8_t *pattern); void SetPattern8x8(const uint8_t *pattern);

View File

@@ -46,6 +46,11 @@ namespace PortabilityLayer
void QDManagerImpl::SetPort(QDPort *gw) void QDManagerImpl::SetPort(QDPort *gw)
{ {
#if GP_DEBUG_CONFIG
if (gw)
gw->CheckPortSentinel();
#endif
m_port = gw; m_port = gw;
} }

View File

@@ -1,4 +1,5 @@
#include "CoreDefs.h" #include "CoreDefs.h"
#include "PLCTabReducer.h"
#include "QDPictDecoder.h" #include "QDPictDecoder.h"
#include "QDPictEmitContext.h" #include "QDPictEmitContext.h"
#include "QDPictHeader.h" #include "QDPictHeader.h"
@@ -11,29 +12,6 @@
#include <vector> #include <vector>
#include <assert.h> #include <assert.h>
namespace
{
static void DecodeClutItemChannel(uint8_t &outChannel, const uint8_t *color16)
{
const int colorHigh = color16[0];
const int colorLow = color16[1];
const int lowDelta = colorLow - colorHigh;
if (lowDelta < -128)
outChannel = static_cast<uint8_t>(colorHigh - 1);
else if (lowDelta > 128)
outChannel = static_cast<uint8_t>(colorHigh + 1);
outChannel = static_cast<uint8_t>(colorHigh);
}
static void DecodeClutItem(PortabilityLayer::RGBAColor &decoded, const BEColorTableItem &clutItem)
{
DecodeClutItemChannel(decoded.r, clutItem.m_red);
DecodeClutItemChannel(decoded.g, clutItem.m_green);
DecodeClutItemChannel(decoded.b, clutItem.m_blue);
decoded.a = 255;
}
}
namespace PortabilityLayer namespace PortabilityLayer
{ {
@@ -88,7 +66,7 @@ namespace PortabilityLayer
if (stream->Read(scratchBytes, 10) != 10 || scratchBytes[0] != 0 || scratchBytes[1] != 10) if (stream->Read(scratchBytes, 10) != 10 || scratchBytes[0] != 0 || scratchBytes[1] != 10)
return false; // Unknown format region return false; // Unknown format region
PL_STATIC_ASSERT(sizeof(scratchBERect) == 8); GP_STATIC_ASSERT(sizeof(scratchBERect) == 8);
memcpy(&scratchBERect, scratchBytes + 2, 8); memcpy(&scratchBERect, scratchBytes + 2, 8);
scratchRect = scratchBERect.ToRect(); scratchRect = scratchBERect.ToRect();
@@ -280,7 +258,7 @@ namespace PortabilityLayer
// If pack type == 3, 16-bit RLE // If pack type == 3, 16-bit RLE
// If pack type == 4, 8-bit planar component RLE // If pack type == 4, 8-bit planar component RLE
PL_STATIC_ASSERT(sizeof(BEPixMap) == 44); GP_STATIC_ASSERT(sizeof(BEPixMap) == 44);
if (stream->Read(&pixMapBE, sizeof(BEPixMap)) != sizeof(BEPixMap)) if (stream->Read(&pixMapBE, sizeof(BEPixMap)) != sizeof(BEPixMap))
return 13; return 13;
@@ -303,7 +281,7 @@ namespace PortabilityLayer
return 16; return 16;
for (size_t i = 0; i < numColors; i++) for (size_t i = 0; i < numColors; i++)
DecodeClutItem(colors[i], clutItems[i]); colors[i] = CTabReducer::DecodeClutItem(clutItems[i]);
} }
BERect srcRectBE; BERect srcRectBE;

View File

@@ -15,7 +15,7 @@ namespace PortabilityLayer
bool QDPictHeader::Load(IOStream *stream) bool QDPictHeader::Load(IOStream *stream)
{ {
PL_STATIC_ASSERT(sizeof(Picture) == 10); GP_STATIC_ASSERT(sizeof(Picture) == 10);
Picture pictHeader; Picture pictHeader;
if (stream->Read(&pictHeader, sizeof(Picture)) != sizeof(Picture)) if (stream->Read(&pictHeader, sizeof(Picture)) != sizeof(Picture))

View File

@@ -1,10 +1,21 @@
#include "QDPixMap.h" #include "QDPixMap.h"
#include "CoreDefs.h" #include "CoreDefs.h"
#include "MemoryManager.h"
#include <assert.h> #include <assert.h>
namespace PortabilityLayer namespace PortabilityLayer
{ {
void PixMapImpl::Destroy(THandle<PixMapImpl> &hdl)
{
if (hdl)
{
(*hdl)->~PixMapImpl();
}
hdl.Dispose();
}
PixMapImpl::PixMapImpl(int16_t left, int16_t top, uint16_t width, uint16_t height, GpPixelFormat_t pixelFormat) PixMapImpl::PixMapImpl(int16_t left, int16_t top, uint16_t width, uint16_t height, GpPixelFormat_t pixelFormat)
: m_left(left) : m_left(left)
, m_top(top) , m_top(top)
@@ -22,6 +33,10 @@ namespace PortabilityLayer
static_cast<PixMap*>(this)->Init(rect, pixelFormat, PitchForWidth(width, pixelFormat), dataPtr); static_cast<PixMap*>(this)->Init(rect, pixelFormat, PitchForWidth(width, pixelFormat), dataPtr);
} }
PixMapImpl::~PixMapImpl()
{
}
size_t PixMapImpl::SizeForDimensions(uint16_t width, uint16_t height, GpPixelFormat_t pixelFormat) size_t PixMapImpl::SizeForDimensions(uint16_t width, uint16_t height, GpPixelFormat_t pixelFormat)
{ {
return AlignedSize() + PitchForWidth(width, pixelFormat) * height; return AlignedSize() + PitchForWidth(width, pixelFormat) * height;
@@ -29,8 +44,8 @@ namespace PortabilityLayer
size_t PixMapImpl::AlignedSize() size_t PixMapImpl::AlignedSize()
{ {
const size_t szBase = sizeof(PixMapImpl) + PL_SYSTEM_MEMORY_ALIGNMENT - 1; const size_t szBase = sizeof(PixMapImpl) + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
const size_t szAdjusted = szBase - szBase % PL_SYSTEM_MEMORY_ALIGNMENT; const size_t szAdjusted = szBase - szBase % GP_SYSTEM_MEMORY_ALIGNMENT;
return szAdjusted; return szAdjusted;
} }
@@ -59,11 +74,34 @@ namespace PortabilityLayer
assert(false); assert(false);
return 0; return 0;
} }
const size_t szBase = rowByteCount + PL_SYSTEM_MEMORY_ALIGNMENT - 1; const size_t szBase = rowByteCount + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
const size_t szAdjusted = szBase - szBase % PL_SYSTEM_MEMORY_ALIGNMENT; const size_t szAdjusted = szBase - szBase % GP_SYSTEM_MEMORY_ALIGNMENT;
return szAdjusted; return szAdjusted;
} }
THandle<PixMapImpl> PixMapImpl::Create(const Rect &rect, GpPixelFormat_t pixelFormat)
{
if (!rect.IsValid())
return THandle<PixMapImpl>();
const uint16_t width = static_cast<uint16_t>(rect.right - rect.left);
const uint16_t height = static_cast<uint16_t>(rect.bottom - rect.top);
const size_t pixMapSize = PixMapImpl::SizeForDimensions(width, height, pixelFormat);
if (pixMapSize == 0)
return THandle<PixMapImpl>();
MMHandleBlock *pmBlock = PortabilityLayer::MemoryManager::GetInstance()->AllocHandle(pixMapSize);
if (!pmBlock)
return THandle<PixMapImpl>();
memset(pmBlock->m_contents, 0, pixMapSize);
new (pmBlock->m_contents) PixMapImpl(rect.left, rect.top, width, height, pixelFormat);
return THandle<PixMapImpl>(pmBlock);
}
} }
void PixMap::Init(const Rect &rect, GpPixelFormat_t pixelFormat, size_t pitch, void *dataPtr) void PixMap::Init(const Rect &rect, GpPixelFormat_t pixelFormat, size_t pitch, void *dataPtr)

View File

@@ -16,7 +16,7 @@ namespace PortabilityLayer
class PixMapImpl final : public PixMap class PixMapImpl final : public PixMap
{ {
public: public:
PixMapImpl(int16_t left, int16_t top, uint16_t width, uint16_t height, GpPixelFormat_t pixelFormat); static void Destroy(THandle<PixMapImpl> &hdl);
GpPixelFormat_t GetPixelFormat() const; GpPixelFormat_t GetPixelFormat() const;
size_t GetPitch() const; size_t GetPitch() const;
@@ -24,9 +24,14 @@ namespace PortabilityLayer
const void *GetPixelData() const; const void *GetPixelData() const;
size_t GetDataCapacity() const; size_t GetDataCapacity() const;
static THandle<PixMapImpl> Create(const Rect &rect, GpPixelFormat_t pixelFormat);
static size_t SizeForDimensions(uint16_t width, uint16_t height, GpPixelFormat_t pixelFormat); static size_t SizeForDimensions(uint16_t width, uint16_t height, GpPixelFormat_t pixelFormat);
private: private:
PixMapImpl(int16_t left, int16_t top, uint16_t width, uint16_t height, GpPixelFormat_t pixelFormat);
~PixMapImpl();
static size_t AlignedSize(); static size_t AlignedSize();
static size_t PitchForWidth(uint16_t width, GpPixelFormat_t pixelFormat); static size_t PitchForWidth(uint16_t width, GpPixelFormat_t pixelFormat);

View File

@@ -1,9 +1,16 @@
#include "QDPort.h" #include "QDPort.h"
#include "PLErrorCodes.h" #include "PLErrorCodes.h"
#include "PLHandle.h"
#include "MemoryManager.h" #include "MemoryManager.h"
#include "MMHandleBlock.h" #include "MMHandleBlock.h"
#include "QDPixMap.h" #include "QDPixMap.h"
#if GP_DEBUG_CONFIG
#include <assert.h>
static const int32_t kQDPortSentinelValue = 0x222a1877; // Completely arbitrary number
#endif
namespace PortabilityLayer namespace PortabilityLayer
{ {
static uint32_t gs_nextQDPortDebugID = 0; static uint32_t gs_nextQDPortDebugID = 0;
@@ -14,10 +21,12 @@ namespace PortabilityLayer
, m_top(0) , m_top(0)
, m_width(0) , m_width(0)
, m_height(0) , m_height(0)
, m_pixMap(nullptr)
, m_pixelFormat(GpPixelFormats::kInvalid) , m_pixelFormat(GpPixelFormats::kInvalid)
, m_dirtyFlags(0) , m_dirtyFlags(0)
, m_debugID(gs_nextQDPortDebugID++) , m_debugID(gs_nextQDPortDebugID++)
#if GP_DEBUG_CONFIG
, m_portSentinel(kQDPortSentinelValue)
#endif
{ {
} }
@@ -29,11 +38,7 @@ namespace PortabilityLayer
void QDPort::DisposePixMap() void QDPort::DisposePixMap()
{ {
if (m_pixMap) if (m_pixMap)
{ PixMapImpl::Destroy(m_pixMap);
if (*m_pixMap)
static_cast<PixMapImpl*>(*m_pixMap)->~PixMapImpl();
MemoryManager::GetInstance()->ReleaseHandle(reinterpret_cast<MMHandleBlock*>(m_pixMap));
}
} }
PLError_t QDPort::Init(const Rect &rect, GpPixelFormat_t pixelFormat) PLError_t QDPort::Init(const Rect &rect, GpPixelFormat_t pixelFormat)
@@ -49,31 +54,24 @@ namespace PortabilityLayer
bool QDPort::Resize(const Rect &rect) bool QDPort::Resize(const Rect &rect)
{ {
const uint16_t width = static_cast<uint16_t>(rect.right - rect.left); if (!rect.IsValid())
const uint16_t height = static_cast<uint16_t>(rect.bottom - rect.top);
size_t pixMapSize = PixMapImpl::SizeForDimensions(width, height, m_pixelFormat);
if (pixMapSize == 0)
return false; return false;
MMHandleBlock *pmBlock = MemoryManager::GetInstance()->AllocHandle(pixMapSize); THandle<PixMapImpl> newPixMap = PixMapImpl::Create(rect, m_pixelFormat);
if (!pmBlock)
return false;
memset(pmBlock->m_contents, 0, pixMapSize); if (!newPixMap)
return false;
SetDirty(QDPortDirtyFlag_Size | QDPortDirtyFlag_Contents); SetDirty(QDPortDirtyFlag_Size | QDPortDirtyFlag_Contents);
m_left = rect.left; m_left = rect.left;
m_top = rect.top; m_top = rect.top;
m_width = width; m_width = rect.Width();
m_height = height; m_height = rect.Height();
new (pmBlock->m_contents) PixMapImpl(m_left, m_top, width, height, m_pixelFormat);
DisposePixMap(); DisposePixMap();
m_pixMap = reinterpret_cast<PixMap**>(&pmBlock->m_contents); m_pixMap = newPixMap;
return true; return true;
} }
@@ -93,9 +91,9 @@ namespace PortabilityLayer
m_dirtyFlags &= ~flag; m_dirtyFlags &= ~flag;
} }
PixMap **QDPort::GetPixMap() const THandle<PixMap> QDPort::GetPixMap() const
{ {
return m_pixMap; return m_pixMap.ImplicitCast<PixMap>();
} }
const QDState *QDPort::GetState() const const QDState *QDPort::GetState() const
@@ -117,4 +115,11 @@ namespace PortabilityLayer
{ {
return Rect::Create(m_top, m_left, m_top + m_height, m_left + m_width); return Rect::Create(m_top, m_left, m_top + m_height, m_left + m_width);
} }
#if GP_DEBUG_CONFIG
void QDPort::CheckPortSentinel() const
{
assert(m_portSentinel == kQDPortSentinelValue);
}
#endif
} }

View File

@@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include "GpPixelFormat.h" #include "GpPixelFormat.h"
#include "PLErrorCodes.h" #include "PLErrorCodes.h"
#include "PLHandle.h"
#include "QDState.h" #include "QDState.h"
struct PixMap; struct PixMap;
@@ -10,6 +11,8 @@ struct Rect;
namespace PortabilityLayer namespace PortabilityLayer
{ {
class PixMapImpl;
enum QDPortType enum QDPortType
{ {
QDPortType_Invalid, QDPortType_Invalid,
@@ -33,7 +36,7 @@ namespace PortabilityLayer
PLError_t Init(const Rect &rect, GpPixelFormat_t pixelFormat); PLError_t Init(const Rect &rect, GpPixelFormat_t pixelFormat);
QDPortType GetPortType() const; QDPortType GetPortType() const;
PixMap **GetPixMap() const; THandle<PixMap> GetPixMap() const;
const QDState *GetState() const; const QDState *GetState() const;
QDState *GetState(); QDState *GetState();
GpPixelFormat_t GetPixelFormat() const; GpPixelFormat_t GetPixelFormat() const;
@@ -45,13 +48,21 @@ namespace PortabilityLayer
void SetDirty(uint32_t flag); void SetDirty(uint32_t flag);
void ClearDirty(uint32_t flag); void ClearDirty(uint32_t flag);
#if GP_DEBUG_CONFIG
void CheckPortSentinel() const;
#endif
private: private:
void DisposePixMap(); void DisposePixMap();
#if GP_DEBUG_CONFIG
int32_t m_portSentinel;
#endif
QDPortType m_portType; QDPortType m_portType;
QDState m_state; QDState m_state;
PixMap **m_pixMap; THandle<PixMapImpl> m_pixMap;
int16_t m_left; int16_t m_left;
int16_t m_top; int16_t m_top;

View File

@@ -4,12 +4,15 @@
namespace PortabilityLayer namespace PortabilityLayer
{ {
struct RenderedFontMetrics;
struct RenderedGlyphMetrics; struct RenderedGlyphMetrics;
class RenderedFont class RenderedFont
{ {
public: public:
virtual bool GetGlyph(unsigned int character, const RenderedGlyphMetrics **outMetricsPtr, const void **outData) const = 0; virtual bool GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const = 0;
virtual const RenderedFontMetrics &GetMetrics() const = 0;
virtual size_t MeasureString(const uint8_t *chars, size_t len) const = 0; virtual size_t MeasureString(const uint8_t *chars, size_t len) const = 0;
virtual void Destroy() = 0; virtual void Destroy() = 0;

View File

@@ -0,0 +1,13 @@
#pragma once
#include <stdint.h>
namespace PortabilityLayer
{
struct RenderedFontMetrics
{
int32_t m_ascent;
int32_t m_descent;
int32_t m_linegap;
};
}

View File

@@ -26,8 +26,8 @@ namespace PortabilityLayer
ScanlineMask *ScanlineMask::Create(const Rect &rect, const ScanlineMaskBuilder &builder) ScanlineMask *ScanlineMask::Create(const Rect &rect, const ScanlineMaskBuilder &builder)
{ {
size_t alignedPrefixSize = sizeof(ScanlineMask) + PL_SYSTEM_MEMORY_ALIGNMENT - 1; size_t alignedPrefixSize = sizeof(ScanlineMask) + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
alignedPrefixSize -= alignedPrefixSize % PL_SYSTEM_MEMORY_ALIGNMENT; alignedPrefixSize -= alignedPrefixSize % GP_SYSTEM_MEMORY_ALIGNMENT;
const size_t longestSpan = builder.GetLongestSpan(); const size_t longestSpan = builder.GetLongestSpan();
const size_t numSpans = builder.GetNumSpans(); const size_t numSpans = builder.GetNumSpans();

View File

@@ -23,8 +23,8 @@ namespace PortabilityLayer
void Set(T *ref); void Set(T *ref);
private: private:
ScopedArray(const ScopedArray<T> &other) PL_DELETED; ScopedArray(const ScopedArray<T> &other) GP_DELETED;
void operator=(const ScopedArray<T> &other) PL_DELETED; void operator=(const ScopedArray<T> &other) GP_DELETED;
T *m_ref; T *m_ref;
}; };
} }

View File

@@ -25,8 +25,8 @@ namespace PortabilityLayer
void Set(T *ref); void Set(T *ref);
private: private:
ScopedPtr(const ScopedPtr<T> &other) PL_DELETED; ScopedPtr(const ScopedPtr<T> &other) GP_DELETED;
void operator=(const ScopedPtr<T> &other) PL_DELETED; void operator=(const ScopedPtr<T> &other) GP_DELETED;
T *m_ref; T *m_ref;
}; };
} }

View File

@@ -29,6 +29,11 @@ struct Rect
Rect operator-(const Point &point) const; Rect operator-(const Point &point) const;
Rect operator+(const Point &point) const; Rect operator+(const Point &point) const;
uint16_t Height() const;
uint16_t Width() const;
bool Contains(const Point &point) const;
static Rect Create(int16_t top, int16_t left, int16_t bottom, int16_t right); static Rect Create(int16_t top, int16_t left, int16_t bottom, int16_t right);
static Rect CreateFromPoints(const Point &topLeft, const Point &bottomRight); static Rect CreateFromPoints(const Point &topLeft, const Point &bottomRight);
}; };
@@ -97,7 +102,7 @@ struct GDevice
{ {
GpPixelFormat_t pixelFormat; GpPixelFormat_t pixelFormat;
uint8_t paletteStorage[256 * 4 + PL_SYSTEM_MEMORY_ALIGNMENT]; uint8_t paletteStorage[256 * 4 + GP_SYSTEM_MEMORY_ALIGNMENT];
uint8_t paletteDataOffset; uint8_t paletteDataOffset;
bool paletteIsDirty; bool paletteIsDirty;
}; };
@@ -164,6 +169,21 @@ inline Rect Rect::operator+(const Point &point) const
return Rect::Create(this->top + point.v, this->left + point.h, this->bottom + point.v, this->right + point.h); return Rect::Create(this->top + point.v, this->left + point.h, this->bottom + point.v, this->right + point.h);
} }
inline uint16_t Rect::Height() const
{
return static_cast<uint16_t>(static_cast<int32_t>(this->bottom) - static_cast<int32_t>(this->top));
}
inline uint16_t Rect::Width() const
{
return static_cast<uint16_t>(static_cast<int32_t>(this->right) - static_cast<int32_t>(this->left));
}
inline bool Rect::Contains(const Point &point) const
{
return point.h >= this->left && point.h < this->right && point.v >= this->top && point.v < this->bottom;
}
inline Rect Rect::Create(int16_t top, int16_t left, int16_t bottom, int16_t right) inline Rect Rect::Create(int16_t top, int16_t left, int16_t bottom, int16_t right)
{ {
Rect result; Rect result;

View File

@@ -0,0 +1,22 @@
#pragma once
#include "GpPixelFormat.h"
#include <stdint.h>
namespace PortabilityLayer
{
class SimpleImage final
{
public:
void Destroy();
void *GetData();
const void *GetData() const;
static SimpleImage *Create(GpPixelFormat_t pixelFormat, size_t pitch, size_t dataSize);
private:
GpPixelFormat_t m_pixelFormat;
size_t m_pitch;
void *m_data;
};
}

View File

@@ -6,6 +6,8 @@
#include "DataTypes.h" #include "DataTypes.h"
#include "SmallestInt.h" #include "SmallestInt.h"
class PLPasStr;
namespace PortabilityLayer namespace PortabilityLayer
{ {
template<size_t TSize, bool TCStr> template<size_t TSize, bool TCStr>
@@ -21,6 +23,9 @@ namespace PortabilityLayer
void SetLength(size_t size); void SetLength(size_t size);
size_t Length() const; size_t Length() const;
const char *UnsafeCharPtr() const;
PLPasStr ToShortStr() const;
private: private:
char m_chars[TSize + (TCStr ? 1 : 0)]; char m_chars[TSize + (TCStr ? 1 : 0)];
typename SmallestUInt<TSize>::ValueType_t m_size; typename SmallestUInt<TSize>::ValueType_t m_size;
@@ -30,6 +35,8 @@ namespace PortabilityLayer
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "PLPasStr.h"
namespace PortabilityLayer namespace PortabilityLayer
{ {
template<size_t TSize, bool TCStr> template<size_t TSize, bool TCStr>
@@ -85,6 +92,21 @@ namespace PortabilityLayer
{ {
return m_size; return m_size;
} }
template<size_t TSize, bool TCStr>
inline const char *UnsafePascalStr<TSize, TCStr>::UnsafeCharPtr() const
{
return m_chars;
}
template<size_t TSize, bool TCStr>
PLPasStr UnsafePascalStr<TSize, TCStr>::ToShortStr() const
{
if (m_size > 255)
return PLPasStr(255, m_chars);
else
return PLPasStr(static_cast<uint8_t>(m_size), m_chars);
}
} }
#endif #endif

View File

@@ -19,7 +19,7 @@ namespace PortabilityLayer
uint8_t m_titleLength; uint8_t m_titleLength;
}; };
PL_STATIC_ASSERT(sizeof(WindowDefPart1) == 19); GP_STATIC_ASSERT(sizeof(WindowDefPart1) == 19);
WindowDefPart1 wdefPart1; WindowDefPart1 wdefPart1;

View File

@@ -86,7 +86,7 @@ namespace PortabilityLayer
WindowImpl::~WindowImpl() WindowImpl::~WindowImpl()
{ {
PL_NotYetImplemented(); assert(m_windowAbove == nullptr && m_windowBelow == nullptr);
} }
bool WindowImpl::Init(const WindowDef &windowDef) bool WindowImpl::Init(const WindowDef &windowDef)