mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 03:59:36 +00:00
Refactor some dialog handling, enforce proper port disposal
This commit is contained in:
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -52,10 +52,6 @@ void ModalDialog(ModalFilterUPP filter, short *item)
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void DisposeDialog(Dialog *dialog)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void DisposeModalFilterUPP(ModalFilterUPP upp)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpDisplayDriverSurface.h"
|
||||
|
||||
DrawSurface::~DrawSurface()
|
||||
{
|
||||
}
|
||||
|
||||
void DrawSurface::PushToDDSurface(IGpDisplayDriver *displayDriver)
|
||||
{
|
||||
const PixMap *pixMap = *m_port.GetPixMap();
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user