Refactor some dialog handling, enforce proper port disposal

This commit is contained in:
elasota
2020-01-01 20:49:18 -05:00
parent 5fe6218c28
commit 1c6ab800a7
25 changed files with 121 additions and 91 deletions

View File

@@ -87,7 +87,7 @@ void DoAbout (void)
if (okayButtScanlineMask != nil)
okayButtScanlineMask->Destroy(); // Clean up!
DisposeDialog(aboutDialog);
aboutDialog->Destroy();
UseResFile(wasResFile);
}

View File

@@ -33,7 +33,7 @@ void BringUpDialog (Dialog **theDialog, short dialogID)
// CenterDialog(dialogID);
if (*theDialog == nil)
RedAlert(kErrDialogDidntLoad);
SetGraphicsPort(&(*theDialog)->GetWindow()->m_graf);
SetGraphicsPort(&(*theDialog)->GetWindow()->m_surface);
ShowWindow((*theDialog)->GetWindow());
DrawDefaultButton(*theDialog);
}

View File

@@ -514,7 +514,7 @@ void GetHighScoreName (short place)
}
}
DisposeDialog(theDial);
theDial->Destroy();
}
//-------------------------------------------------------------- UpdateBannerDialog

View File

@@ -697,7 +697,7 @@ Boolean GoToFilter (Dialog *dial, EventRecord *event, short *item)
}
}
DisposeDialog(theDialog);
theDialog->Destroy();
if (!canceled)
{

View File

@@ -287,7 +287,7 @@ void DoHouseInfo (void)
}
}
InitCursor();
DisposeDialog(houseInfoDialog);
houseInfoDialog->Destroy();
}
//-------------------------------------------------------------- WarnLockingHouse

View File

@@ -124,7 +124,7 @@ void RedrawSplashScreen (void)
// DissBits(&workSrcRect);
CopyRectMainToWork(&workSrcRect);
mainWindow->m_graf.m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
mainWindow->m_surface.m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
PortabilityLayer::MenuManager::GetInstance()->SetMenuVisible(true);
}
@@ -160,7 +160,7 @@ void UpdateMainWindow (void)
DrawOnSplash(mainWindow->GetDrawSurface());
}
mainWindow->m_graf.m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
mainWindow->m_surface.m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
splashDrawn = true;
}

View File

@@ -749,7 +749,7 @@ short QueryResumeGame (void)
leaving = true;
}
}
DisposeDialog(theDial);
theDial->Destroy();
return (hitWhat);
}

View File

@@ -1088,7 +1088,7 @@ void DoBlowerObjectInfo (short what)
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{
@@ -1149,7 +1149,7 @@ void DoFurnitureObjectInfo (void)
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{
@@ -1247,8 +1247,8 @@ void DoCustPictObjectInfo (void)
leaving = true;
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
}
//-------------------------------------------------------------- DoSwitchObjectInfo
@@ -1346,8 +1346,8 @@ void DoSwitchObjectInfo (void)
doReturn = true;
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doLink)
{
@@ -1498,8 +1498,8 @@ void DoTriggerObjectInfo (void)
}
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doLink)
{
@@ -1593,8 +1593,8 @@ void DoLightObjectInfo (void)
doReturn = true;
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{
@@ -1705,8 +1705,8 @@ void DoApplianceObjectInfo (short what)
}
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{
@@ -1825,8 +1825,8 @@ void DoMicrowaveObjectInfo (void)
doReturn = true;
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{
@@ -1895,8 +1895,8 @@ void DoGreaseObjectInfo (void)
doReturn = true;
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{
@@ -2004,8 +2004,8 @@ void DoInvisBonusObjectInfo (void)
doReturn = true;
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{
@@ -2110,8 +2110,8 @@ void DoTransObjectInfo (short what)
SetDialogItemValue(infoDial, kInitialStateCheckbox3, (short)wasState);
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doLink)
{
@@ -2229,8 +2229,8 @@ void DoEnemyObjectInfo (short what)
}
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{
@@ -2324,8 +2324,8 @@ void DoFlowerObjectInfo (void)
doReturn = true;
}
}
DisposeDialog(infoDial);
infoDial->Destroy();
if (doReturn)
{

View File

@@ -143,7 +143,7 @@ void NewGame (short mode)
#ifdef COMPILEQT
if ((thisMac.hasQT) && (hasMovie))
{
SetMovieGWorld(theMovie, &mainWindow->m_graf, nil);
SetMovieGWorld(theMovie, &mainWindow->m_surface, nil);
}
#endif

View File

@@ -594,7 +594,7 @@ void DoRoomInfo (void)
}
InitCursor();
DisposeDialog(roomInfoDialog);
roomInfoDialog->Destroy();
// KillOffScreenPixMap(tileSrcMap);
DisposeGWorld(tileSrcMap);
@@ -847,7 +847,7 @@ short ChooseOriginalArt (short was)
}
}
DisposeDialog(theDialog);
theDialog->Destroy();
return (newPictID);
}

View File

@@ -514,8 +514,8 @@ void DoLoadHouse (void)
PageDownHouses(theDial);
}
}
DisposeDialog(theDial);
theDial->Destroy();
}
#endif

View File

@@ -75,7 +75,7 @@ void HandleSoundMusicChange (short, Boolean);
Boolean SoundFilter (Dialog *, EventRecord *, short *);
void DoSoundPrefs (void);
void DisplayDefaults (void);
void FrameDisplayIcon (Dialog *);
void FrameDisplayIcon (Dialog *, const PortabilityLayer::RGBAColor &color);
void DisplayUpdate (Dialog *);
Boolean DisplayFilter (Dialog *, EventRecord *, short *);
void DoDisplayPrefs (void);
@@ -317,7 +317,7 @@ void DoBrainsPrefs (void)
}
}
DisposeDialog(prefDlg);
prefDlg->Destroy();
}
//-------------------------------------------------------------- SetControlsToDefaults
@@ -601,8 +601,8 @@ void DoControlPrefs (void)
break;
}
}
DisposeDialog(prefDlg);
prefDlg->Destroy();
}
//-------------------------------------------------------------- SoundDefaults
@@ -882,8 +882,8 @@ void DoSoundPrefs (void)
break;
}
}
DisposeDialog(prefDlg);
prefDlg->Destroy();
}
//-------------------------------------------------------------- DisplayDefaults
@@ -898,7 +898,7 @@ void DisplayDefaults (void)
//-------------------------------------------------------------- FrameDisplayIcon
void FrameDisplayIcon (Dialog *theDialog)
void FrameDisplayIcon (Dialog *theDialog, const PortabilityLayer::RGBAColor &color)
{
Rect theRect;
@@ -919,7 +919,7 @@ void FrameDisplayIcon (Dialog *theDialog)
DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface();
surface->SetForeColor(StdColors::Black());
surface->SetForeColor(color);
theRect.left -= 3;
theRect.top += 0;
@@ -943,7 +943,7 @@ void DisplayUpdate (Dialog *theDialog)
SetDialogItemValue(theDialog, kUseScreen2Item, (short)wasScreen2);
ForeColor(redColor);
FrameDisplayIcon(theDialog);
FrameDisplayIcon(theDialog, StdColors::Red());
ForeColor(blackColor);
FrameDialogItemC(theDialog, 8, kRedOrangeColor8);
FrameDialogItemC(theDialog, 13, kRedOrangeColor8);
@@ -1058,9 +1058,11 @@ int16_t DisplayFilter(Dialog *dial, const TimeTaggedVOSEvent &evt)
return kUseQDItem;
default:
return(false);
return -1;
}
}
return -1;
}
//-------------------------------------------------------------- DoDisplayPrefs
@@ -1110,35 +1112,26 @@ void DoDisplayPrefs (void)
break;
case kDisplay1Item:
ForeColor(whiteColor);
FrameDisplayIcon(prefDlg);
FrameDisplayIcon(prefDlg, StdColors::White());
numNeighbors = 1;
ForeColor(redColor);
FrameDisplayIcon(prefDlg);
ForeColor(blackColor);
FrameDisplayIcon(prefDlg, StdColors::Red());
break;
case kDisplay3Item:
if (thisMac.screen.right > 512)
{
ForeColor(whiteColor);
FrameDisplayIcon(prefDlg);
FrameDisplayIcon(prefDlg, StdColors::White());
numNeighbors = 3;
ForeColor(redColor);
FrameDisplayIcon(prefDlg);
ForeColor(blackColor);
FrameDisplayIcon(prefDlg, StdColors::Red());
}
break;
case kDisplay9Item:
if (thisMac.screen.right > 512)
{
ForeColor(whiteColor);
FrameDisplayIcon(prefDlg);
FrameDisplayIcon(prefDlg, StdColors::White());
numNeighbors = 9;
ForeColor(redColor);
FrameDisplayIcon(prefDlg);
ForeColor(blackColor);
FrameDisplayIcon(prefDlg, StdColors::Red());
}
break;
@@ -1155,8 +1148,7 @@ void DoDisplayPrefs (void)
break;
case kDispDefault:
ForeColor(whiteColor);
FrameDisplayIcon(prefDlg);
FrameDisplayIcon(prefDlg, StdColors::White());
ForeColor(blackColor);
DisplayDefaults();
DisplayUpdate(prefDlg);
@@ -1361,20 +1353,20 @@ void DoSettingsMain (void)
case kDisplayButton:
FlashSettingsButton(surface, 0);
DoDisplayPrefs();
SetGraphicsPort(&prefDlg->GetWindow()->m_graf);
SetGraphicsPort(&prefDlg->GetWindow()->m_surface);
break;
case kSoundButton:
FlashSettingsButton(surface, 1);
DoSoundPrefs();
SetGraphicsPort(&prefDlg->GetWindow()->m_graf);
SetGraphicsPort(&prefDlg->GetWindow()->m_surface);
FlushEvents(everyEvent, 0);
break;
case kControlsButton:
FlashSettingsButton(surface, 2);
DoControlPrefs();
SetGraphicsPort(&prefDlg->GetWindow()->m_graf);
SetGraphicsPort(&prefDlg->GetWindow()->m_surface);
break;
case kBrainsButton:
@@ -1386,7 +1378,7 @@ void DoSettingsMain (void)
}
FlashSettingsButton(surface, 3);
DoBrainsPrefs();
SetGraphicsPort(&prefDlg->GetWindow()->m_graf);
SetGraphicsPort(&prefDlg->GetWindow()->m_surface);
break;
case kAllDefaultsButton:
@@ -1395,7 +1387,7 @@ void DoSettingsMain (void)
}
}
DisposeDialog(prefDlg);
prefDlg->Destroy();
if (nextRestartChange)
BitchAboutChanges();

View File

@@ -10,7 +10,7 @@ namespace PortabilityLayer
{
}
WidgetHandleState_t ButtonWidget::ProcessEvent(Window *window, const TimeTaggedVOSEvent &evt)
WidgetHandleState_t ButtonWidget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
if (m_haveMouseDown)
{
@@ -18,7 +18,7 @@ namespace PortabilityLayer
{
m_haveMouseDown = false;
const Point pt = window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent);
const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent);
if (m_rect.Contains(pt))
return WidgetHandleStates::kActivated;
else
@@ -31,7 +31,7 @@ namespace PortabilityLayer
{
if (evt.IsLMouseDownEvent())
{
const Point pt = window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent);
const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent);
if (m_rect.Contains(pt))
{

View File

@@ -12,7 +12,7 @@ namespace PortabilityLayer
bool Init(const WidgetBasicState &state) override;
WidgetHandleState_t ProcessEvent(Window *window, const TimeTaggedVOSEvent &evt);
WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt) override;
private:
bool m_haveMouseDown;

View File

@@ -225,7 +225,7 @@ void DisposeWindow(WindowPtr window)
void GetWindowBounds(WindowPtr window, WindowRegionType windowRegion, Rect *rect)
{
if (windowRegion == kWindowContentRgn)
*rect = window->m_graf.m_port.GetRect();
*rect = window->m_surface.m_port.GetRect();
else
{
PL_NotYetImplemented();
@@ -817,15 +817,19 @@ WindowPtr PL_GetPutInFrontWindowPtr()
}
Window::Window()
: m_graf(PortabilityLayer::QDPortType_Window)
: m_surface(PortabilityLayer::QDPortType_Window)
, m_wmX(0)
, m_wmY(0)
{
}
Window::~Window()
{
}
DrawSurface *Window::GetDrawSurface() const
{
return const_cast<DrawSurface*>(&m_graf);
return const_cast<DrawSurface*>(&m_surface);
}
Point Window::MouseToLocal(const GpMouseInputEvent &evt) const

View File

@@ -108,12 +108,15 @@ struct Window
// 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_surface; // Must be the first item until the immediate mode draw API is completely removed
// The port is always at 0,0
// These are the WM coordinates
int32_t m_wmX;
int32_t m_wmY;
protected:
~Window();
};
struct DateTimeRec

View File

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

View File

@@ -41,7 +41,5 @@ void SelectDialogItemText(Dialog *dialog, int item, int firstSelChar, int lastSe
void ModalDialog(ModalFilterUPP filter, short *item);
void DisposeDialog(Dialog *dialog);
void ShowDialogItem(Dialog *dialog, int item);
void HideDialogItem(Dialog *dialog, int item);

View File

@@ -2,6 +2,7 @@
#include "IconLoader.h"
#include "QDPixMap.h"
#include "PLTimeTaggedVOSEvent.h"
#include <assert.h>
@@ -46,4 +47,12 @@ namespace PortabilityLayer
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);
}
WidgetHandleState_t IconWidget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
if (evt.IsLMouseDownEvent() && m_rect.Contains(m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent)))
return WidgetHandleStates::kActivated;
else
return WidgetHandleStates::kIgnored;
}
}

View File

@@ -17,6 +17,8 @@ namespace PortabilityLayer
void DrawControl(DrawSurface *surface) override;
WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt) override;
private:
THandle<PixMapImpl> m_iconImage;
THandle<PixMapImpl> m_iconMask;

View File

@@ -260,7 +260,7 @@ void SetPort(GrafPtr graf)
void EndUpdate(WindowPtr graf)
{
graf->m_graf.m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
graf->m_surface.m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
PLError_t GetIconSuite(Handle *suite, short resID, IconSuiteFlags flags)
@@ -286,7 +286,7 @@ void SetRect(Rect *rect, short left, short top, short right, short bottom)
void SetPortWindowPort(WindowPtr window)
{
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
PortabilityLayer::QDManager::GetInstance()->SetPort(&window->m_graf.m_port);
PortabilityLayer::QDManager::GetInstance()->SetPort(&window->m_surface.m_port);
}
void SetPortDialogPort(Dialog *dialog)
@@ -423,6 +423,8 @@ static void PlotLine(PortabilityLayer::QDState *qdState, DrawSurface *surface, c
PL_NotYetImplemented();
return;
}
surface->m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
void SetOrigin(int x, int y)
@@ -604,6 +606,8 @@ void DrawSurface::DrawString(const Point &point, const PLPasStr &str)
else
DrawGlyph(qdState, pixMap, rect, penPos, rfont, chars[i]);
}
m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
size_t DrawSurface::MeasureString(const PLPasStr &str)
@@ -765,11 +769,14 @@ void DrawSurface::FillRect(const Rect &rect)
PL_NotYetImplemented();
return;
}
m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
void DrawSurface::FillRectWithPattern8x8(const Rect &rect, const uint8_t *pattern)
{
PL_NotYetImplemented();
m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
void DrawSurface::SetApplicationFont(int size, int variationFlags)
@@ -992,6 +999,8 @@ void DrawSurface::FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlin
}
}
}
m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
@@ -1051,6 +1060,8 @@ void DrawSurface::FrameRect(const Rect &rect)
edgeRect.top = edgeRect.bottom - 1;
FillRect(edgeRect);
}
m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
}
void DrawSurface::FrameRoundRect(const Rect &rect, int quadrantWidth, int quadrantHeight)
@@ -1396,7 +1407,7 @@ BitMap *GetPortBitMapForCopyBits(DrawSurface *grafPtr)
DrawSurface *GetWindowPort(WindowPtr window)
{
return &window->m_graf;
return &window->m_surface;
}

View File

@@ -4,6 +4,10 @@
#include "IGpDisplayDriver.h"
#include "IGpDisplayDriverSurface.h"
DrawSurface::~DrawSurface()
{
}
void DrawSurface::PushToDDSurface(IGpDisplayDriver *displayDriver)
{
const PixMap *pixMap = *m_port.GetPixMap();

View File

@@ -36,6 +36,8 @@ struct DrawSurface final
{
}
~DrawSurface();
PLError_t Init(const Rect &rect, GpPixelFormat_t pixelFormat)
{
if (PLError_t errorCode = m_port.Init(rect, pixelFormat))

View File

@@ -3,6 +3,7 @@
#include "PLHandle.h"
#include "MemoryManager.h"
#include "MMHandleBlock.h"
#include "QDManager.h"
#include "QDPixMap.h"
#if GP_DEBUG_CONFIG
@@ -32,6 +33,11 @@ namespace PortabilityLayer
QDPort::~QDPort()
{
#if GP_DEBUG_CONFIG
// Detach the port BEFORE destroying it!!
assert(PortabilityLayer::QDManager::GetInstance()->GetPort() != this);
#endif
DisposePixMap();
}

View File

@@ -100,7 +100,7 @@ namespace PortabilityLayer
GpPixelFormat_t pixelFormat = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetPixelFormat();
if (int errorCode = m_graf.Init(adjustedBounds, pixelFormat))
if (int errorCode = m_surface.Init(adjustedBounds, pixelFormat))
return false;
return true;
@@ -108,11 +108,11 @@ namespace PortabilityLayer
bool WindowImpl::Resize(int width, int height)
{
Rect rect = m_graf.m_port.GetRect();
Rect rect = m_surface.m_port.GetRect();
rect.right = rect.left + width;
rect.bottom = rect.top + height;
return m_graf.Resize(rect);
return m_surface.Resize(rect);
}
WindowImpl *WindowImpl::GetWindowAbove() const
@@ -254,7 +254,7 @@ namespace PortabilityLayer
WindowImpl *window = m_windowStackTop;
while (window)
{
const Rect windowRect = window->m_graf.m_port.GetRect();
const Rect windowRect = window->m_surface.m_port.GetRect();
const int32_t localX = point.h - window->m_wmX;
const int32_t localY = point.v - window->m_wmY;
@@ -286,6 +286,9 @@ namespace PortabilityLayer
DetachWindow(window);
if (PortabilityLayer::QDManager::GetInstance()->GetPort() == &windowImpl->m_surface.m_port)
PortabilityLayer::QDManager::GetInstance()->SetPort(nullptr);
windowImpl->~WindowImpl();
PortabilityLayer::MemoryManager::GetInstance()->Release(windowImpl);
}
@@ -341,7 +344,7 @@ namespace PortabilityLayer
void WindowManagerImpl::RenderWindow(WindowImpl *window, IGpDisplayDriver *displayDriver)
{
DrawSurface &graf = window->m_graf;
DrawSurface &graf = window->m_surface;
graf.PushToDDSurface(displayDriver);