Level editor work

This commit is contained in:
elasota
2020-01-04 01:19:01 -05:00
parent ec7e511cdd
commit a4b8db1065
29 changed files with 358 additions and 168 deletions

View File

@@ -74,6 +74,12 @@ uint64_t GpSystemServices_Win32::GetFreeMemoryCosmetic() const
return memStatus.ullAvailPhys; return memStatus.ullAvailPhys;
} }
void GpSystemServices_Win32::Beep() const
{
MessageBeep(MB_OK);
}
GpSystemServices_Win32 *GpSystemServices_Win32::GetInstance() GpSystemServices_Win32 *GpSystemServices_Win32::GetInstance()
{ {
return &ms_instance; return &ms_instance;

View File

@@ -20,6 +20,7 @@ public:
PortabilityLayer::HostMutex *CreateMutex() override; PortabilityLayer::HostMutex *CreateMutex() override;
PortabilityLayer::HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override; PortabilityLayer::HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override;
uint64_t GetFreeMemoryCosmetic() const override; uint64_t GetFreeMemoryCosmetic() const override;
void Beep() const override;
static GpSystemServices_Win32 *GetInstance(); static GpSystemServices_Win32 *GetInstance();

View File

@@ -94,8 +94,8 @@ void ConvertCursors(PortabilityLayer::ResourceFile *resFile)
for (size_t i = 0; i < numRefs; i++) for (size_t i = 0; i < numRefs; i++)
{ {
const int resID = typeList->m_firstRef[i].m_resID; const int resID = typeList->m_firstRef[i].m_resID;
const PortabilityLayer::MMHandleBlock *hBlock = resFile->GetResource('crsr', resID, true); const THandle<void> resHdl = resFile->GetResource('crsr', resID, true);
const void *cursorDataBase = hBlock->m_contents; const void *cursorDataBase = *resHdl;
const void *cursorData = cursorDataBase; const void *cursorData = cursorDataBase;
const CursorHeader *cursorHeader = static_cast<const CursorHeader *>(cursorData); const CursorHeader *cursorHeader = static_cast<const CursorHeader *>(cursorData);
@@ -247,16 +247,16 @@ void ConvertIconFamily(PortabilityLayer::ResourceFile *resFile, int32_t iconBitm
for (size_t i = 0; i < numRefs; i++) for (size_t i = 0; i < numRefs; i++)
{ {
const int resID = typeList->m_firstRef[i].m_resID; const int resID = typeList->m_firstRef[i].m_resID;
const PortabilityLayer::MMHandleBlock *bwBlock = resFile->GetResource(iconBitmapType, resID, true); const THandle<void> bwBlock = resFile->GetResource(iconBitmapType, resID, true);
const PortabilityLayer::MMHandleBlock *colorBlock = resFile->GetResource(iconColorType, resID, true); const THandle<void> colorBlock = resFile->GetResource(iconColorType, resID, true);
if (!bwBlock || !colorBlock) if (!bwBlock || !colorBlock)
continue; continue;
const uint8_t *bwIconData = static_cast<const uint8_t*>(bwBlock->m_contents); const uint8_t *bwIconData = static_cast<const uint8_t*>(*bwBlock);
const uint8_t *bwMaskData = bwIconData + (dimension * dimension / 8); const uint8_t *bwMaskData = bwIconData + (dimension * dimension / 8);
const uint8_t *indexedData = static_cast<const uint8_t*>(colorBlock->m_contents); const uint8_t *indexedData = static_cast<const uint8_t*>(*colorBlock);
PortabilityLayer::RGBAColor *pixelData = new PortabilityLayer::RGBAColor[dimension * dimension * 4]; PortabilityLayer::RGBAColor *pixelData = new PortabilityLayer::RGBAColor[dimension * dimension * 4];
@@ -321,7 +321,7 @@ int main(int argc, const char **argv)
PortabilityLayer::CFileStream stream(f); PortabilityLayer::CFileStream stream(f);
PortabilityLayer::ResourceFile *resFile = new PortabilityLayer::ResourceFile(); PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceFile::Create();
if (!resFile->Load(&stream)) if (!resFile->Load(&stream))
return -1; return -1;

View File

@@ -364,9 +364,9 @@ void DrawDefaultButton (Dialog *theDialog)
surface->SetForeColor(StdColors::Black()); surface->SetForeColor(StdColors::Black());
for (int xOffset = 0; xOffset < 3; xOffset++) for (int xOffset = -1; xOffset <= 1; xOffset++)
{ {
for (int yOffset = 0; yOffset < 3; yOffset++) for (int yOffset = -1; yOffset <= 1; yOffset++)
{ {
const Rect offsetRect = itemRect + Point::Create(xOffset, yOffset); const Rect offsetRect = itemRect + Point::Create(xOffset, yOffset);
surface->FrameRoundRect(offsetRect, 8, 8); surface->FrameRoundRect(offsetRect, 8, 8);
@@ -646,7 +646,7 @@ void DrawDialogUserText (Dialog *dial, short item, StringPtr text, Boolean inver
if (invert) if (invert)
{ {
OffsetRect(&iRect, 0, 1); OffsetRect(&iRect, 0, 1);
InvertRect(&iRect); surface->InvertFillRect(iRect, nullptr);
} }
} }
@@ -680,12 +680,10 @@ void DrawDialogUserText2 (Dialog *dial, short item, StringPtr text)
void LoadDialogPICT (Dialog *theDialog, short item, short theID) void LoadDialogPICT (Dialog *theDialog, short item, short theID)
{ {
Rect iRect;
ControlHandle iHandle;
THandle<Picture> thePict; THandle<Picture> thePict;
short iType;
GetDialogItem(theDialog, item, &iType, &iHandle, &iRect); Rect iRect = theDialog->GetItems()[item - 1].GetWidget()->GetRect();;
thePict = GetPicture(theID); thePict = GetPicture(theID);
if (thePict) if (thePict)
theDialog->GetWindow()->GetDrawSurface()->DrawPicture(thePict, iRect); theDialog->GetWindow()->GetDrawSurface()->DrawPicture(thePict, iRect);

View File

@@ -13,6 +13,7 @@
namespace PortabilityLayer namespace PortabilityLayer
{ {
class ResourceFile;
class ScanlineMask; class ScanlineMask;
} }
@@ -197,7 +198,7 @@ UInt32 RandomLongQUS (void);
void RedAlert (short); 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); bool LargeIconPlot (DrawSurface *, PortabilityLayer::ResourceFile *, short, const Rect &);
void DrawCIcon (DrawSurface *surface, short, short, short); void DrawCIcon (DrawSurface *surface, short, short, short);
char KeyMapOffsetFromRawKey (char); char KeyMapOffsetFromRawKey (char);
long LongSquareRoot (long); long LongSquareRoot (long);

View File

@@ -994,6 +994,10 @@ void HandleSwitches (hotPtr who)
roomLinked = masterObjects[whoLinked].roomLink; roomLinked = masterObjects[whoLinked].roomLink;
objectLinked = masterObjects[whoLinked].objectLink; objectLinked = masterObjects[whoLinked].objectLink;
linkIndex = masterObjects[whoLinked].localLink; linkIndex = masterObjects[whoLinked].localLink;
if (roomLinked < 0)
return; // GP: Some objects (like Leviathan) have corrupted switch data
// change state of linked obj. // change state of linked obj.
if (SetObjectState(roomLinked, objectLinked, if (SetObjectState(roomLinked, objectLinked,
masterObjects[whoLinked].theObject.data.e.type, linkIndex)) masterObjects[whoLinked].theObject.data.e.type, linkIndex))

View File

@@ -346,7 +346,7 @@ void DoGameMenu (short theItem)
Rect updateRect; Rect updateRect;
SetRect(&updateRect, splashOriginH + 474, splashOriginV + 304, splashOriginH + 474 + 166, splashOriginV + 304 + 12); SetRect(&updateRect, splashOriginH + 474, splashOriginV + 304, splashOriginH + 474 + 166, splashOriginV + 304 + 12);
InvalWindowRect(mainWindow, &updateRect); UpdateMainWindow();
} }
} }
#endif #endif

View File

@@ -355,7 +355,7 @@ void AddTempManholeRect (Rect *manHole)
Boolean SetObjectState (short room, short object, short action, short local) Boolean SetObjectState (short room, short object, short action, short local)
{ {
char wasState; char wasState;
Boolean changed; Boolean changed = false;
switch ((*thisHouse)->rooms[room].objects[object].what) switch ((*thisHouse)->rooms[room].objects[object].what)
{ {

View File

@@ -17,7 +17,9 @@
#include "FileManager.h" #include "FileManager.h"
#include "House.h" #include "House.h"
#include "RectUtils.h" #include "RectUtils.h"
#include "ResourceFile.h"
#include "ResourceManager.h" #include "ResourceManager.h"
#include "PLTimeTaggedVOSEvent.h"
#include "VirtualDirectory.h" #include "VirtualDirectory.h"
@@ -42,7 +44,7 @@
void UpdateLoadDialog (Dialog *); void UpdateLoadDialog (Dialog *);
void PageUpHouses (Dialog *); void PageUpHouses (Dialog *);
void PageDownHouses (Dialog *); void PageDownHouses (Dialog *);
Boolean LoadFilter (Dialog *, EventRecord *, short *); int16_t LoadFilter (Dialog *, const TimeTaggedVOSEvent &);
void SortHouseList (void); void SortHouseList (void);
void DoDirSearch (void); void DoDirSearch (void);
@@ -66,12 +68,14 @@ extern UInt32 doubleTime;
void UpdateLoadDialog (Dialog *theDialog) void UpdateLoadDialog (Dialog *theDialog)
{ {
Rect tempRect, dialogRect, dummyRect; Rect tempRect, dialogRect, dummyRect;
short houseStart, houseStop, i, wasResFile, isResFile, count; short houseStart, houseStop, i, wasResFile, count;
// char wasState; // char wasState;
WindowRef theWindow; WindowRef theWindow;
// RgnHandle theRegion; // RgnHandle theRegion;
theWindow = theDialog->GetWindow(); theWindow = theDialog->GetWindow();
DrawSurface *surface = theWindow->GetDrawSurface();
GetWindowBounds(theWindow, kWindowContentRgn, &dialogRect); GetWindowBounds(theWindow, kWindowContentRgn, &dialogRect);
/* /*
wasState = HGetState((Handle)(((DialogPeek)theDialog)->window).port.visRgn); wasState = HGetState((Handle)(((DialogPeek)theDialog)->window).port.visRgn);
@@ -80,7 +84,6 @@ void UpdateLoadDialog (Dialog *theDialog)
HSetState((Handle)(((DialogPeek)theDialog)->window).port.visRgn, wasState); HSetState((Handle)(((DialogPeek)theDialog)->window).port.visRgn, wasState);
*/ */
DrawDialog(theDialog);
ColorFrameWHRect(theDialog->GetWindow()->GetDrawSurface(), 8, 39, 413, 184, kRedOrangeColor8); // box around files ColorFrameWHRect(theDialog->GetWindow()->GetDrawSurface(), 8, 39, 413, 184, kRedOrangeColor8); // box around files
houseStart = housePage; houseStart = housePage;
@@ -88,7 +91,6 @@ void UpdateLoadDialog (Dialog *theDialog)
if ((houseStop - houseStart) > kDispFiles) if ((houseStop - houseStart) > kDispFiles)
houseStop = houseStart + kDispFiles; houseStop = houseStart + kDispFiles;
wasResFile = CurResFile();
count = 0; count = 0;
for (i = 0; i < 12; i++) for (i = 0; i < 12; i++)
@@ -103,17 +105,16 @@ void UpdateLoadDialog (Dialog *theDialog)
if (SectRect(&dialogRect, &tempRect, &dummyRect)) if (SectRect(&dialogRect, &tempRect, &dummyRect))
{ {
isResFile = HOpenResFile(theHousesSpecs[i].m_dir, theHousesSpecs[i].m_name, fsRdPerm); PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceManager::GetInstance()->LoadResFile(theHousesSpecs[i].m_dir, theHousesSpecs[i].m_name);
if (isResFile != -1) if (resFile != nullptr)
{ {
if (Get1Resource('icl8', -16455) != nil) if (!LargeIconPlot(surface, resFile, -16455, tempRect))
{ {
LargeIconPlot(&tempRect, -16455);
}
else
LoadDialogPICT(theDialog, kLoadIconFirstItem + i - housePage, LoadDialogPICT(theDialog, kLoadIconFirstItem + i - housePage,
kDefaultHousePict8); kDefaultHousePict8);
PortabilityLayer::ResourceManager::GetInstance()->CloseResFile(isResFile); }
resFile->Destroy();
} }
else else
LoadDialogPICT(theDialog, kLoadIconFirstItem + i - housePage, LoadDialogPICT(theDialog, kLoadIconFirstItem + i - housePage,
@@ -131,7 +132,6 @@ void UpdateLoadDialog (Dialog *theDialog)
} }
InitCursor(); InitCursor();
UseResFile(wasResFile);
} }
#endif #endif
@@ -152,11 +152,11 @@ void PageUpHouses (Dialog *theDial)
housePage -= kDispFiles; housePage -= kDispFiles;
thisHouseIndex = kDispFiles - 1; thisHouseIndex = kDispFiles - 1;
ShowDialogItem(theDial, kScrollDownItem); theDial->SetItemVisibility(kScrollDownItem - 1, true);
if (housePage < kDispFiles) if (housePage < kDispFiles)
{ {
GetDialogItemRect(theDial, kScrollUpItem, &tempRect); GetDialogItemRect(theDial, kScrollUpItem, &tempRect);
HideDialogItem(theDial, kScrollUpItem); theDial->SetItemVisibility(kScrollUpItem - 1, false);
DrawCIcon(surface, kGrayedOutUpArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutUpArrow, tempRect.left, tempRect.top);
} }
@@ -165,7 +165,8 @@ void PageUpHouses (Dialog *theDial)
surface->SetForeColor(StdColors::White()); surface->SetForeColor(StdColors::White());
surface->FillRect(tempRect); surface->FillRect(tempRect);
surface->SetForeColor(StdColors::Black()); surface->SetForeColor(StdColors::Black());
InvalWindowRect(theDial->GetWindow(), &tempRect);
UpdateLoadDialog(theDial);
} }
#endif #endif
@@ -186,11 +187,11 @@ void PageDownHouses (Dialog *theDial)
housePage += kDispFiles; housePage += kDispFiles;
thisHouseIndex = 0; thisHouseIndex = 0;
ShowDialogItem(theDial, kScrollUpItem); theDial->SetItemVisibility(kScrollUpItem - 1, true);
if (housePage >= (housesFound - kDispFiles)) if (housePage >= (housesFound - kDispFiles))
{ {
GetDialogItemRect(theDial, kScrollDownItem, &tempRect); GetDialogItemRect(theDial, kScrollDownItem, &tempRect);
HideDialogItem(theDial, kScrollDownItem); theDial->SetItemVisibility(kScrollDownItem - 1, false);
DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top);
} }
@@ -198,46 +199,39 @@ void PageDownHouses (Dialog *theDial)
surface->SetForeColor(StdColors::White()); surface->SetForeColor(StdColors::White());
surface->FillRect(tempRect); surface->FillRect(tempRect);
surface->SetForeColor(StdColors::Black()); surface->SetForeColor(StdColors::Black());
InvalWindowRect(theDial->GetWindow(), &tempRect);
UpdateLoadDialog(theDial);
} }
#endif #endif
//-------------------------------------------------------------- LoadFilter //-------------------------------------------------------------- LoadFilter
#ifndef COMPILEDEMO #ifndef COMPILEDEMO
Boolean LoadFilter (Dialog *dial, EventRecord *event, short *item) int16_t LoadFilter(Dialog *dial, const TimeTaggedVOSEvent &evt)
{ {
short screenCount, i, wasIndex; short screenCount, i, wasIndex;
switch (event->what) if (evt.IsKeyDownEvent())
{ {
case keyDown: const intptr_t keyCode = PackVOSKeyCode(evt.m_vosEvent.m_event.m_keyboardInputEvent);
switch (event->message) switch (keyCode)
{ {
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(kPageUp): case PL_KEY_SPECIAL(kPageUp):
*item = kScrollUpItem; return kScrollUpItem;
return (true);
break;
case PL_KEY_SPECIAL(kPageDown): case PL_KEY_SPECIAL(kPageDown):
*item = kScrollDownItem; return kScrollDownItem;
return (true);
break;
case PL_KEY_SPECIAL(kUpArrow): case PL_KEY_SPECIAL(kUpArrow):
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
thisHouseIndex -= 4; thisHouseIndex -= 4;
if (thisHouseIndex < 0) if (thisHouseIndex < 0)
@@ -248,15 +242,14 @@ Boolean LoadFilter (Dialog *dial, EventRecord *event, short *item)
thisHouseIndex += 4; thisHouseIndex += 4;
thisHouseIndex = (((screenCount - 1) / 4) * 4) + thisHouseIndex = (((screenCount - 1) / 4) * 4) +
(thisHouseIndex % 4); (thisHouseIndex % 4);
if (thisHouseIndex >= screenCount) if (thisHouseIndex >= screenCount)
thisHouseIndex -= 4; thisHouseIndex -= 4;
} }
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
return(true); return 0;
break;
case PL_KEY_SPECIAL(kDownArrow): case PL_KEY_SPECIAL(kDownArrow):
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
thisHouseIndex += 4; thisHouseIndex += 4;
screenCount = housesFound - housePage; screenCount = housesFound - housePage;
@@ -265,10 +258,10 @@ Boolean LoadFilter (Dialog *dial, EventRecord *event, short *item)
if (thisHouseIndex >= screenCount) if (thisHouseIndex >= screenCount)
thisHouseIndex %= 4; thisHouseIndex %= 4;
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
return(true);
break;
case PL_KEY_SPECIAL(kLeftArrow): return 0;
case PL_KEY_SPECIAL(kLeftArrow):
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
thisHouseIndex--; thisHouseIndex--;
if (thisHouseIndex < 0) if (thisHouseIndex < 0)
@@ -279,11 +272,10 @@ Boolean LoadFilter (Dialog *dial, EventRecord *event, short *item)
thisHouseIndex = screenCount - 1; thisHouseIndex = screenCount - 1;
} }
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
return(true); return 0;
break;
case PL_KEY_SPECIAL(kTab): case PL_KEY_SPECIAL(kTab):
case PL_KEY_SPECIAL(kRightArrow): case PL_KEY_SPECIAL(kRightArrow):
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
thisHouseIndex++; thisHouseIndex++;
screenCount = housesFound - housePage; screenCount = housesFound - housePage;
@@ -292,13 +284,12 @@ Boolean LoadFilter (Dialog *dial, EventRecord *event, short *item)
if (thisHouseIndex >= screenCount) if (thisHouseIndex >= screenCount)
thisHouseIndex = 0; thisHouseIndex = 0;
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
return(true); return 0;
break;
default: default:
if (PL_KEY_GET_EVENT_TYPE(event->message) == KeyEventType_ASCII) if (PL_KEY_GET_EVENT_TYPE(keyCode) == KeyEventType_ASCII)
{ {
char theChar = static_cast<char>(PL_KEY_GET_VALUE(event->message)); char theChar = static_cast<char>(PL_KEY_GET_VALUE(keyCode));
if (theChar >= 'A' && theChar <= 'Z') if (theChar >= 'A' && theChar <= 'Z')
{ {
@@ -325,35 +316,29 @@ Boolean LoadFilter (Dialog *dial, EventRecord *event, short *item)
InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]); InvalWindowRect(dial->GetWindow(), &loadHouseRects[thisHouseIndex]);
} }
} }
return(true); return 0;
} }
else else
return(false); return -1;
} }
break; }
else if (evt.IsLMouseDownEvent())
{
const GpMouseInputEvent &mouseEvt = evt.m_vosEvent.m_event.m_mouseInputEvent;
case mouseDown: lastWhenClick = evt.m_timestamp - lastWhenClick;
lastWhenClick = event->when - lastWhenClick; lastWhereClick -= Point::Create(mouseEvt.m_x, mouseEvt.m_y);
SubPt(event->where, &lastWhereClick);
return(false);
break;
case mouseUp: return -1;
lastWhenClick = event->when; }
lastWhereClick = event->where; else if (evt.IsLMouseUpEvent())
return(false); {
break; const GpMouseInputEvent &mouseEvt = evt.m_vosEvent.m_event.m_mouseInputEvent;
case updateEvt: lastWhenClick = evt.m_timestamp;
UpdateLoadDialog(dial); lastWhereClick = Point::Create(mouseEvt.m_x, mouseEvt.m_y);
EndUpdate(dial->GetWindow());
event->what = nullEvent;
return(false);
break;
default: return -1;
return(false);
break;
} }
} }
#endif #endif
@@ -365,7 +350,7 @@ void DoLoadHouse (void)
{ {
Rect tempRect; Rect tempRect;
Dialog *theDial; Dialog *theDial;
short i, item, wasIndex, screenCount; short i, wasIndex, screenCount;
Boolean leaving, whoCares; Boolean leaving, whoCares;
BringUpDialog(&theDial, kLoadHouseDialogID); BringUpDialog(&theDial, kLoadHouseDialogID);
@@ -375,11 +360,11 @@ void DoLoadHouse (void)
if (housesFound <= kDispFiles) if (housesFound <= kDispFiles)
{ {
GetDialogItemRect(theDial, kScrollUpItem, &tempRect); GetDialogItemRect(theDial, kScrollUpItem, &tempRect);
HideDialogItem(theDial, kScrollUpItem); theDial->SetItemVisibility(kScrollUpItem - 1, false);
DrawCIcon(surface, kGrayedOutUpArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutUpArrow, tempRect.left, tempRect.top);
GetDialogItemRect(theDial, kScrollDownItem, &tempRect); GetDialogItemRect(theDial, kScrollDownItem, &tempRect);
HideDialogItem(theDial, kScrollDownItem); theDial->SetItemVisibility(kScrollDownItem - 1, false);
DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top);
} }
else else
@@ -387,13 +372,13 @@ void DoLoadHouse (void)
if (thisHouseIndex < kDispFiles) if (thisHouseIndex < kDispFiles)
{ {
GetDialogItemRect(theDial, kScrollUpItem, &tempRect); GetDialogItemRect(theDial, kScrollUpItem, &tempRect);
HideDialogItem(theDial, kScrollUpItem); theDial->SetItemVisibility(kScrollUpItem - 1, false);
DrawCIcon(surface, 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); theDial->SetItemVisibility(kScrollDownItem - 1, false);
DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top); DrawCIcon(surface, kGrayedOutDownArrow, tempRect.left, tempRect.top);
} }
} }
@@ -413,9 +398,11 @@ void DoLoadHouse (void)
leaving = false; leaving = false;
UpdateLoadDialog(theDial);
while (!leaving) while (!leaving)
{ {
ModalDialog(LoadFilter, &item); int16_t item = theDial->ExecuteModal(LoadFilter);
if (item == kOkayButton) if (item == kOkayButton)
{ {

View File

@@ -14,6 +14,7 @@
#include "QDPixMap.h" #include "QDPixMap.h"
#include "Externs.h" #include "Externs.h"
#include "IconLoader.h" #include "IconLoader.h"
#include "ResourceFile.h"
#include "Utilities.h" #include "Utilities.h"
@@ -314,14 +315,39 @@ void LoadScaledGraphic (DrawSurface *surface, short resID, Rect *theRect)
//-------------------------------------------------------------- LargeIconPlot //-------------------------------------------------------------- LargeIconPlot
// Draws a standard b&w icon (32 x 32) - resource is an 'ICON'. // Draws a standard b&w icon (32 x 32) - resource is an 'ICON'.
void LargeIconPlot (Rect *theRect, short theID) bool LargeIconPlot (DrawSurface *surface, PortabilityLayer::ResourceFile *resFile, short resID, const Rect &theRect)
{ {
PLError_t theErr; Handle hdl = resFile->GetResource('icl8', resID, true);
Handle theSuite; if (hdl)
{
THandle<PortabilityLayer::PixMapImpl> img = PortabilityLayer::IconLoader::GetInstance()->LoadSimpleColorIcon(hdl);
theErr = GetIconSuite(&theSuite, theID, svAllLargeData); if (img)
if (theErr == PLErrors::kNone) {
theErr = PlotIconSuite(theRect, theSuite); CopyBits(*img, *surface->m_port.GetPixMap(), &(*img)->m_rect, &theRect, srcCopy);
img.Dispose();
}
hdl.Dispose();
return true;
}
hdl = resFile->GetResource('ICN#', resID, true);
if (hdl)
{
THandle<PortabilityLayer::PixMapImpl> img = PortabilityLayer::IconLoader::GetInstance()->LoadBWIcon(hdl);
if (img)
{
CopyBits(*img, *surface->m_port.GetPixMap(), &(*img)->m_rect, &theRect, srcCopy);
img.Dispose();
}
hdl.Dispose();
return true;
}
return false;
} }
//-------------------------------------------------------------- DrawCIcon //-------------------------------------------------------------- DrawCIcon

View File

@@ -1278,7 +1278,7 @@ int main(int argc, const char **argv)
FILE *f = fopen(filePath.c_str(), "rb"); FILE *f = fopen(filePath.c_str(), "rb");
CFileStream stream(f); CFileStream stream(f);
ResourceFile *resFile = new ResourceFile(); ResourceFile *resFile = ResourceFile::Create();
if (!resFile->Load(&stream)) if (!resFile->Load(&stream))
{ {
assert(false); assert(false);
@@ -1292,8 +1292,8 @@ int main(int argc, const char **argv)
const size_t numRefs = typeList->m_numRefs; const size_t numRefs = typeList->m_numRefs;
for (size_t i = 0; i < numRefs; i++) for (size_t i = 0; i < numRefs; i++)
{ {
const MMHandleBlock *hBlock = resFile->GetResource('PICT', typeList->m_firstRef[i].m_resID, true); const THandle<void> hBlock = resFile->GetResource('PICT', typeList->m_firstRef[i].m_resID, true);
const void *pictData = hBlock->m_contents; const void *pictData = *hBlock;
std::string dumpPath = "D:\\Source Code\\GlidePort\\DebugData\\PictDump\\"; std::string dumpPath = "D:\\Source Code\\GlidePort\\DebugData\\PictDump\\";
@@ -1311,7 +1311,7 @@ int main(int argc, const char **argv)
int n = 0; int n = 0;
} }
AuditPictOps2(static_cast<const uint8_t*>(pictData), hBlock->m_size, dumpPath.c_str()); AuditPictOps2(static_cast<const uint8_t*>(pictData), hBlock.MMBlock()->m_size, dumpPath.c_str());
} }
} }

View File

@@ -11,6 +11,7 @@
#include "PLInvisibleWidget.h" #include "PLInvisibleWidget.h"
#include "PLLabelWidget.h" #include "PLLabelWidget.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "PLStandardColors.h"
#include "PLSysCalls.h" #include "PLSysCalls.h"
#include "PLTimeTaggedVOSEvent.h" #include "PLTimeTaggedVOSEvent.h"
#include "PLWidgets.h" #include "PLWidgets.h"
@@ -77,12 +78,13 @@ namespace PortabilityLayer
Window *GetWindow() const override; Window *GetWindow() const override;
ArrayView<const DialogItem> GetItems() const override; ArrayView<const DialogItem> GetItems() const override;
void SetItemVisibility(unsigned int itemIndex, bool isVisible) override;
int16_t ExecuteModal(DialogFilterFunc_t filterFunc) override; int16_t ExecuteModal(DialogFilterFunc_t filterFunc) override;
bool Populate(DialogTemplate *tmpl); bool Populate(DialogTemplate *tmpl);
void DrawControls(); void DrawControls(bool redraw);
Point MouseToDialog(const GpMouseInputEvent &evt); Point MouseToDialog(const GpMouseInputEvent &evt);
@@ -192,6 +194,26 @@ namespace PortabilityLayer
return ArrayView<const DialogItem>(m_items, m_numItems); return ArrayView<const DialogItem>(m_items, m_numItems);
} }
void DialogImpl::SetItemVisibility(unsigned int itemIndex, bool isVisible)
{
Widget *widget = m_items[itemIndex].GetWidget();
if (widget->IsVisible() != isVisible)
{
widget->SetVisible(isVisible);
DrawSurface *surface = m_window->GetDrawSurface();
if (isVisible)
widget->DrawControl(surface);
else
{
surface->SetForeColor(StdColors::Red());
surface->FrameRect(surface->m_port.GetRect());
}
}
}
int16_t DialogImpl::ExecuteModal(DialogFilterFunc_t filterFunc) int16_t DialogImpl::ExecuteModal(DialogFilterFunc_t filterFunc)
{ {
Window *window = this->GetWindow(); Window *window = this->GetWindow();
@@ -297,14 +319,22 @@ namespace PortabilityLayer
return true; return true;
} }
void DialogImpl::DrawControls() void DialogImpl::DrawControls(bool redraw)
{ {
DrawSurface *surface = m_window->GetDrawSurface(); DrawSurface *surface = m_window->GetDrawSurface();
if (redraw)
{
surface->SetForeColor(StdColors::White());
surface->FillRect(surface->m_port.GetRect());
}
for (ArrayViewIterator<const DialogItem> it = GetItems().begin(), itEnd = GetItems().end(); it != itEnd; ++it) for (ArrayViewIterator<const DialogItem> it = GetItems().begin(), itEnd = GetItems().end(); it != itEnd; ++it)
{ {
const DialogItem &item = *it; const DialogItem &item = *it;
item.GetWidget()->DrawControl(surface); Widget *widget = item.GetWidget();
if (widget->IsVisible())
widget->DrawControl(surface);
} }
} }
@@ -469,7 +499,7 @@ namespace PortabilityLayer
return nullptr; return nullptr;
} }
dialog->DrawControls(); dialog->DrawControls(true);
return dialog; return dialog;
} }

View File

@@ -21,6 +21,7 @@ namespace PortabilityLayer
virtual HostMutex *CreateMutex() = 0; virtual HostMutex *CreateMutex() = 0;
virtual HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) = 0; virtual HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) = 0;
virtual size_t GetFreeMemoryCosmetic() const = 0; // Returns free memory in bytes, does not have to be accurate virtual size_t GetFreeMemoryCosmetic() const = 0; // Returns free memory in bytes, does not have to be accurate
virtual void Beep() const = 0;
static void SetInstance(HostSystemServices *instance); static void SetInstance(HostSystemServices *instance);
static HostSystemServices *GetInstance(); static HostSystemServices *GetInstance();

View File

@@ -41,7 +41,8 @@ namespace PortabilityLayer
{ {
public: public:
bool LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage) override; bool LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage) override;
THandle<PixMapImpl> LoadBWIcon(const int16_t id) override; THandle<PixMapImpl> LoadSimpleColorIcon(const THandle<void> &hdl) override;
THandle<PixMapImpl> LoadBWIcon(const THandle<void> &hdl) override;
static IconLoaderImpl *GetInstance(); static IconLoaderImpl *GetInstance();
@@ -238,10 +239,61 @@ namespace PortabilityLayer
return true; return true;
} }
THandle<PixMapImpl> IconLoaderImpl::LoadBWIcon(const int16_t id) THandle<PixMapImpl> IconLoaderImpl::LoadSimpleColorIcon(const THandle<void> &hdl)
{ {
PL_NotYetImplemented(); if (hdl == nullptr || hdl.MMBlock()->m_size != 1024)
return THandle<PixMapImpl>(); return THandle<PixMapImpl>();
const Rect rect = Rect::Create(0, 0, 32, 32);
THandle<PixMapImpl> pixMap = PixMapImpl::Create(rect, GpPixelFormats::k8BitStandard);
if (!pixMap)
return THandle<PixMapImpl>();
const uint8_t *inData = static_cast<const uint8_t*>(*hdl);
uint8_t *outData = static_cast<uint8_t*>((*pixMap)->GetPixelData());
const size_t outPitch = (*pixMap)->GetPitch();
for (size_t row = 0; row < 32; row++)
{
for (size_t col = 0; col < 32; col++)
outData[col] = inData[col];
inData += 32;
outData += outPitch;
}
return pixMap;
}
THandle<PixMapImpl> IconLoaderImpl::LoadBWIcon(const THandle<void> &hdl)
{
if (hdl == nullptr || hdl.MMBlock()->m_size != 128)
return THandle<PixMapImpl>();
const Rect rect = Rect::Create(0, 0, 32, 32);
THandle<PixMapImpl> pixMap = PixMapImpl::Create(rect, GpPixelFormats::kBW1);
if (!pixMap)
return THandle<PixMapImpl>();
const uint8_t *inData = static_cast<const uint8_t*>(*hdl);
uint8_t *outData = static_cast<uint8_t*>((*pixMap)->GetPixelData());
const size_t outPitch = (*pixMap)->GetPitch();
for (size_t row = 0; row < 32; row++)
{
for (size_t col = 0; col < 32; col++)
{
if (inData[col / 8] & (0x80 >> (col & 7)))
outData[col] = 0xff;
else
outData[col] = 0x00;
}
inData += 4;
outData += outPitch;
}
return pixMap;
} }
IconLoaderImpl *IconLoaderImpl::GetInstance() IconLoaderImpl *IconLoaderImpl::GetInstance()

View File

@@ -14,7 +14,8 @@ namespace PortabilityLayer
{ {
public: public:
virtual bool LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage) = 0; 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; virtual THandle<PixMapImpl> LoadSimpleColorIcon(const THandle<void> &hdl) = 0;
virtual THandle<PixMapImpl> LoadBWIcon(const THandle<void> &hdl) = 0;
static IconLoader *GetInstance(); static IconLoader *GetInstance();
}; };

View File

@@ -442,8 +442,6 @@ namespace PortabilityLayer
if (m_lastMenu == menu) if (m_lastMenu == menu)
m_lastMenu = menuPtr->prevMenu; m_lastMenu = menuPtr->prevMenu;
menu.Dispose();
DrawMenuBar(); DrawMenuBar();
} }

View File

@@ -1,5 +1,6 @@
#include "PLApplication.h" #include "PLApplication.h"
#include "PLCore.h" #include "PLCore.h"
#include "HostSystemServices.h"
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
@@ -19,5 +20,5 @@ namespace PortabilityLayer
void SysBeep(int duration) void SysBeep(int duration)
{ {
PL_NotYetImplemented(); PortabilityLayer::HostSystemServices::GetInstance()->Beep();
} }

View File

@@ -1,12 +1,15 @@
#include "PLButtonWidget.h" #include "PLButtonWidget.h"
#include "PLCore.h" #include "PLCore.h"
#include "PLTimeTaggedVOSEvent.h" #include "PLTimeTaggedVOSEvent.h"
#include "PLStandardColors.h"
#include "FontFamily.h"
namespace PortabilityLayer namespace PortabilityLayer
{ {
ButtonWidget::ButtonWidget(const WidgetBasicState &state) ButtonWidget::ButtonWidget(const WidgetBasicState &state)
: WidgetSpec<ButtonWidget>(state) : WidgetSpec<ButtonWidget>(state)
, m_haveMouseDown(false) , m_haveMouseDown(false)
, m_text(state.m_text)
{ {
} }
@@ -51,4 +54,14 @@ namespace PortabilityLayer
(void)state; (void)state;
return true; return true;
} }
void ButtonWidget::DrawControl(DrawSurface *surface)
{
surface->SetForeColor(StdColors::Black());
surface->FrameRect(this->m_rect);
surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold);
int32_t x = (m_rect.left + m_rect.right - static_cast<int32_t>(surface->MeasureString(m_text.ToShortStr()))) / 2;
int32_t y = (m_rect.top + m_rect.bottom + static_cast<int32_t>(surface->MeasureFontAscender())) / 2;
surface->DrawString(Point::Create(x, y), m_text.ToShortStr());
}
} }

View File

@@ -12,6 +12,8 @@ namespace PortabilityLayer
bool Init(const WidgetBasicState &state) override; bool Init(const WidgetBasicState &state) override;
void DrawControl(DrawSurface *surface) override;
WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt) override; WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt) override;
private: private:

View File

@@ -52,7 +52,6 @@ void ModalDialog(ModalFilterUPP filter, short *item)
PL_NotYetImplemented(); PL_NotYetImplemented();
} }
void DisposeModalFilterUPP(ModalFilterUPP upp) void DisposeModalFilterUPP(ModalFilterUPP upp)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented();

View File

@@ -23,6 +23,8 @@ struct Dialog
virtual Window *GetWindow() const = 0; virtual Window *GetWindow() const = 0;
virtual ArrayView<const PortabilityLayer::DialogItem> GetItems() const = 0; virtual ArrayView<const PortabilityLayer::DialogItem> GetItems() const = 0;
virtual void SetItemVisibility(unsigned int itemIndex, bool isVisible) = 0;
virtual int16_t ExecuteModal(DialogFilterFunc_t filterFunc) = 0; virtual int16_t ExecuteModal(DialogFilterFunc_t filterFunc) = 0;
}; };

View File

@@ -1101,7 +1101,7 @@ void DrawSurface::InvertFrameRect(const Rect &rect, const uint8_t *pattern)
void DrawSurface::InvertFillRect(const Rect &rect, const uint8_t *pattern) void DrawSurface::InvertFillRect(const Rect &rect, const uint8_t *pattern)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented_TODO("InvertFillRect");
} }
void DrawSurface::SetForeColor(const PortabilityLayer::RGBAColor &color) void DrawSurface::SetForeColor(const PortabilityLayer::RGBAColor &color)

View File

@@ -30,6 +30,7 @@ namespace PortabilityLayer
void SetResLoad(bool load) override; void SetResLoad(bool load) override;
ResourceFile *LoadResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) const override;
short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) override; short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) override;
void CloseResFile(short ref) override; void CloseResFile(short ref) override;
PLError_t CreateBlankResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) override; PLError_t CreateBlankResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) override;
@@ -131,7 +132,7 @@ namespace PortabilityLayer
} }
} }
delete rf; rf->Destroy();
} }
ResourceManagerImpl *ResourceManagerImpl::GetInstance() ResourceManagerImpl *ResourceManagerImpl::GetInstance()
@@ -144,6 +145,28 @@ namespace PortabilityLayer
m_load = load; m_load = load;
} }
ResourceFile *ResourceManagerImpl::LoadResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) const
{
IOStream *fStream = nullptr;
if (FileManager::GetInstance()->RawOpenFileResources(virtualDir, filename, EFilePermission_Read, true, GpFileCreationDispositions::kOpenExisting, fStream) != PLErrors::kNone)
return nullptr;
ResourceFile *resFile = ResourceFile::Create();
if (!resFile)
return nullptr;
bool loaded = resFile->Load(fStream);
fStream->Close();
if (!loaded)
{
resFile->Destroy();
return nullptr;
}
return resFile;
}
short ResourceManagerImpl::OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) short ResourceManagerImpl::OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename)
{ {
const size_t numSlots = m_resFiles.size(); const size_t numSlots = m_resFiles.size();
@@ -161,19 +184,11 @@ namespace PortabilityLayer
if (resFileIndex == 0x7fff) if (resFileIndex == 0x7fff)
return -1; return -1;
IOStream *fStream = nullptr;
if (FileManager::GetInstance()->RawOpenFileResources(virtualDir, filename, EFilePermission_Read, true, GpFileCreationDispositions::kOpenExisting, fStream) != PLErrors::kNone)
return -1;
ResourceFile *resFile = new ResourceFile(); ResourceFile *resFile = LoadResFile(virtualDir, filename);
bool loaded = resFile->Load(fStream);
fStream->Close();
if (!loaded) if (!resFile)
{
delete resFile;
return -1; return -1;
}
ResFileSlot slot; ResFileSlot slot;
slot.m_resourceFile = resFile; slot.m_resourceFile = resFile;
@@ -202,7 +217,10 @@ namespace PortabilityLayer
void ResourceManagerImpl::CloseResFile(short ref) void ResourceManagerImpl::CloseResFile(short ref)
{ {
ResFileSlot &slot = m_resFiles[ref]; ResFileSlot &slot = m_resFiles[ref];
delete slot.m_resourceFile;
assert(slot.m_resourceFile != nullptr);
slot.m_resourceFile->Destroy();
slot.m_resourceFile = nullptr; slot.m_resourceFile = nullptr;
if (m_lastResFile == ref) if (m_lastResFile == ref)
@@ -256,8 +274,9 @@ namespace PortabilityLayer
const ResFileSlot& slot = m_resFiles[searchIndex]; const ResFileSlot& slot = m_resFiles[searchIndex];
assert(slot.m_resourceFile); assert(slot.m_resourceFile);
if (MMHandleBlock *block = slot.m_resourceFile->GetResource(resType, id, m_load)) THandle<void> resHdl = slot.m_resourceFile->GetResource(resType, id, m_load);
return THandle<void>(block); if (resHdl != nullptr)
return resHdl;
searchIndex = slot.m_prevFile; searchIndex = slot.m_prevFile;
} }

View File

@@ -35,6 +35,16 @@ namespace PortabilityLayer
OnStateChanged(); OnStateChanged();
} }
void Widget::SetVisible(bool visible)
{
m_visible = visible;
}
bool Widget::IsVisible() const
{
return m_visible;
}
void Widget::SetHighlightStyle(int16_t style) void Widget::SetHighlightStyle(int16_t style)
{ {
(void)style; (void)style;
@@ -54,6 +64,7 @@ namespace PortabilityLayer
: m_rect(state.m_rect) : m_rect(state.m_rect)
, m_window(state.m_window) , m_window(state.m_window)
, m_enabled(state.m_enabled) , m_enabled(state.m_enabled)
, m_visible(true)
, m_state(0) , m_state(0)
{ {
} }

View File

@@ -44,6 +44,10 @@ namespace PortabilityLayer
void SetEnabled(bool enabled); void SetEnabled(bool enabled);
void SetState(int16_t state); void SetState(int16_t state);
void SetVisible(bool visible);
bool IsVisible() const;
virtual void SetString(const PLPasStr &str); virtual void SetString(const PLPasStr &str);
virtual void SetHighlightStyle(int16_t style); virtual void SetHighlightStyle(int16_t style);
@@ -63,6 +67,7 @@ namespace PortabilityLayer
Rect m_rect; Rect m_rect;
int16_t m_state; int16_t m_state;
bool m_enabled; bool m_enabled;
bool m_visible;
}; };
} }

View File

@@ -356,18 +356,18 @@ namespace PortabilityLayer
return tl; return tl;
} }
MMHandleBlock *ResourceFile::GetResource(const ResTypeID &resType, int id, bool load) THandle<void> ResourceFile::GetResource(const ResTypeID &resType, int id, bool load)
{ {
const ResourceCompiledTypeList *tl = GetResourceTypeList(resType); const ResourceCompiledTypeList *tl = GetResourceTypeList(resType);
if (tl == nullptr) if (tl == nullptr)
return nullptr; return THandle<void>();
ResourceCompiledRef *refStart = tl->m_firstRef; ResourceCompiledRef *refStart = tl->m_firstRef;
ResourceCompiledRef *refEnd = refStart + tl->m_numRefs; ResourceCompiledRef *refEnd = refStart + tl->m_numRefs;
ResourceCompiledRef *ref = BinarySearch(refStart, refEnd, id, CompiledRefSearchPredicate); ResourceCompiledRef *ref = BinarySearch(refStart, refEnd, id, CompiledRefSearchPredicate);
if (ref == refEnd) if (ref == refEnd)
return nullptr; return THandle<void>();
MMHandleBlock *handle = nullptr; MMHandleBlock *handle = nullptr;
if (ref->m_handle != nullptr) if (ref->m_handle != nullptr)
@@ -391,6 +391,21 @@ namespace PortabilityLayer
} }
} }
return handle; return THandle<void>(handle);
}
ResourceFile *ResourceFile::Create()
{
void *storage = PortabilityLayer::MemoryManager::GetInstance()->Alloc(sizeof(ResourceFile));
if (!storage)
return nullptr;
return new (storage) ResourceFile();
}
void ResourceFile::Destroy()
{
this->~ResourceFile();
PortabilityLayer::MemoryManager::GetInstance()->Release(this);
} }
} }

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#ifndef __PL_RESOURCE_FILE_H__
#define __PL_RESOURCE_FILE_H__
#include "PLHandle.h"
#include "ResTypeID.h" #include "ResTypeID.h"
#include <stdint.h> #include <stdint.h>
@@ -17,17 +16,19 @@ namespace PortabilityLayer
class ResourceFile class ResourceFile
{ {
public: public:
ResourceFile();
~ResourceFile();
bool Load(IOStream *stream); bool Load(IOStream *stream);
void GetAllResourceTypeLists(ResourceCompiledTypeList *&outTypeLists, size_t &outCount) const; void GetAllResourceTypeLists(ResourceCompiledTypeList *&outTypeLists, size_t &outCount) const;
const ResourceCompiledTypeList *GetResourceTypeList(const ResTypeID &resType); const ResourceCompiledTypeList *GetResourceTypeList(const ResTypeID &resType);
MMHandleBlock *GetResource(const ResTypeID &resType, int id, bool load); THandle<void> GetResource(const ResTypeID &resType, int id, bool load);
static ResourceFile *Create();
void Destroy();
private: private:
ResourceFile();
~ResourceFile();
uint8_t *m_resDataBlob; uint8_t *m_resDataBlob;
size_t m_resDataBlobSize; size_t m_resDataBlobSize;
@@ -48,5 +49,3 @@ namespace PortabilityLayer
static int CompiledTypeListSearchPredicate(const ResTypeID &resTypeID, const ResourceCompiledTypeList &typeList); static int CompiledTypeListSearchPredicate(const ResTypeID &resTypeID, const ResourceCompiledTypeList &typeList);
}; };
} }
#endif

View File

@@ -10,6 +10,7 @@ namespace PortabilityLayer
{ {
struct MMHandleBlock; struct MMHandleBlock;
struct ResourceCompiledRef; struct ResourceCompiledRef;
class ResourceFile;
class ResTypeID; class ResTypeID;
class ResourceManager class ResourceManager
@@ -20,6 +21,7 @@ namespace PortabilityLayer
virtual void SetResLoad(bool load) = 0; virtual void SetResLoad(bool load) = 0;
virtual ResourceFile *LoadResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) const = 0;
virtual short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0; virtual short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0;
virtual void CloseResFile(short ref) = 0; virtual void CloseResFile(short ref) = 0;
virtual PLError_t CreateBlankResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0; virtual PLError_t CreateBlankResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0;

View File

@@ -13,6 +13,9 @@ struct Point
Point operator-(const Point &other) const; Point operator-(const Point &other) const;
Point operator+(const Point &other) const; Point operator+(const Point &other) const;
Point &operator-=(const Point &other);
Point &operator+=(const Point &other);
static Point Create(int16_t h, int16_t v); static Point Create(int16_t h, int16_t v);
}; };
@@ -117,6 +120,20 @@ inline Point Point::operator+(const Point &other) const
return Point::Create(this->h + other.h, this->v + other.v); return Point::Create(this->h + other.h, this->v + other.v);
} }
inline Point &Point::operator-=(const Point &other)
{
this->h -= other.h;
this->v -= other.v;
return *this;
}
inline Point &Point::operator+=(const Point &other)
{
this->h += other.h;
this->v += other.v;
return *this;
}
inline Point Point::Create(int16_t h, int16_t v) inline Point Point::Create(int16_t h, int16_t v)
{ {
Point p; Point p;