From 9daee7af4e3269dbf6110e332f813a17dacc32ed Mon Sep 17 00:00:00 2001 From: elasota Date: Tue, 18 Feb 2020 20:53:54 -0500 Subject: [PATCH] More editor progress --- Common/CoreDefs.h | 2 ++ GpApp/HouseInfo.cpp | 4 ++-- GpApp/Marquee.cpp | 2 +- GpApp/ObjectEdit.cpp | 8 ++++---- GpApp/RoomInfo.cpp | 16 +++++++-------- GpApp/Tools.cpp | 13 ++++++------ PortabilityLayer/PLArrayView.h | 24 +++++++++++------------ PortabilityLayer/PLControlDefinitions.cpp | 20 +++++++++++++++++-- PortabilityLayer/PLCore.cpp | 7 +++++++ PortabilityLayer/PLCore.h | 5 +++++ PortabilityLayer/PLHacks.cpp | 4 ++-- PortabilityLayer/PLQDraw.cpp | 7 ------- PortabilityLayer/PLQDraw.h | 2 -- 13 files changed, 68 insertions(+), 46 deletions(-) diff --git a/Common/CoreDefs.h b/Common/CoreDefs.h index 11e296a..2b43709 100644 --- a/Common/CoreDefs.h +++ b/Common/CoreDefs.h @@ -41,4 +41,6 @@ struct __GpStaticAssertHelper static const size_t GP_SYSTEM_MEMORY_ALIGNMENT = 16; +#if !defined(NDEBUG) #define GP_DEBUG_CONFIG 1 +#endif diff --git a/GpApp/HouseInfo.cpp b/GpApp/HouseInfo.cpp index 4df745f..aa42027 100644 --- a/GpApp/HouseInfo.cpp +++ b/GpApp/HouseInfo.cpp @@ -176,8 +176,8 @@ Boolean HouseFilter (Dialog *dial, EventRecord *event, short *item) default: mouseIs = event->where; mouseIs -= dial->GetWindow()->TopLeftCoord(); - if ((PtInRect(mouseIs, &houseEditText1)) || - (PtInRect(mouseIs, &houseEditText2))) + if ((houseEditText1.Contains(mouseIs)) || + (houseEditText2.Contains(mouseIs))) { if (houseCursorIs != kBeamCursor) { diff --git a/GpApp/Marquee.cpp b/GpApp/Marquee.cpp index 1e20d51..8ce4c6f 100644 --- a/GpApp/Marquee.cpp +++ b/GpApp/Marquee.cpp @@ -421,7 +421,7 @@ Boolean MarqueeHasHandles (short *direction, short *dist) Boolean PtInMarqueeHandle (Point where) { - return (PtInRect(where, &theMarquee.handle)); + return theMarquee.handle.Contains(where); } //-------------------------------------------------------------- DrawGliderMarquee diff --git a/GpApp/ObjectEdit.cpp b/GpApp/ObjectEdit.cpp index 251ed5e..a587c76 100644 --- a/GpApp/ObjectEdit.cpp +++ b/GpApp/ObjectEdit.cpp @@ -53,16 +53,16 @@ short FindObjectSelected (Point where) found = kNoObjectSelected; - if (PtInRect(where, &initialGliderRect)) + if (initialGliderRect.Contains(where)) return (kInitialGliderSelected); - else if (PtInRect(where, &leftStartGliderDest)) + else if (leftStartGliderDest.Contains(where)) return (kLeftGliderSelected); - else if (PtInRect(where, &rightStartGliderDest)) + else if (rightStartGliderDest.Contains(where)) return (kRightGliderSelected); for (i = kMaxRoomObs - 1; i >= 0; i--) { - if (PtInRect(where, &roomObjectRects[i])) + if (roomObjectRects[i].Contains(where)) { found = i; break; diff --git a/GpApp/RoomInfo.cpp b/GpApp/RoomInfo.cpp index 43cfc69..67b5228 100644 --- a/GpApp/RoomInfo.cpp +++ b/GpApp/RoomInfo.cpp @@ -149,7 +149,7 @@ void DragMiniTile (DrawSurface *surface, Point mouseIs, short *newTileOver) QOffsetRect(&dragRect, mouseIs.h - mouseWas.h, 0); surface->InvertFrameRect(dragRect, pattern); - if (PtInRect(mouseIs, &tileDest)) // is cursor in the drop rect + if (tileDest.Contains(mouseIs)) // is cursor in the drop rect { *newTileOver = (mouseIs.h - tileDest.left) / kMiniTileWide; if (*newTileOver != wasTileOver) @@ -259,7 +259,7 @@ void HiliteTileOver (DrawSurface *surface, Point mouseIs) { short newTileOver; - if (PtInRect(mouseIs, &tileSrc)) + if (tileSrc.Contains(mouseIs)) { if (cursorIs != kHandCursor) { @@ -323,7 +323,7 @@ void HiliteTileOver (DrawSurface *surface, Point mouseIs) tileOver = -1; } - if (PtInRect(mouseIs, &editTETextBox)) + if (editTETextBox.Contains(mouseIs)) { if (cursorIs != kBeamCursor) { @@ -384,7 +384,7 @@ Boolean RoomFilter (Dialog *dial, EventRecord *event, short *item) case mouseDown: mouseIs = event->where; mouseIs -= dial->GetWindow()->TopLeftCoord(); - if (PtInRect(mouseIs, &tileSrc)) + if (tileSrc.Contains(mouseIs)) { if (StillDown()) { @@ -694,22 +694,22 @@ Boolean OriginalArtFilter (Dialog *dial, EventRecord *event, short *item) case mouseDown: mouseIs = event->where; mouseIs -= dial->GetWindow()->TopLeftCoord(); - if (PtInRect(mouseIs, &leftBound)) + if (leftBound.Contains(mouseIs)) { *item = 7; return(true); } - else if (PtInRect(mouseIs, &topBound)) + else if (topBound.Contains(mouseIs)) { *item = 8; return(true); } - else if (PtInRect(mouseIs, &rightBound)) + else if (rightBound.Contains(mouseIs)) { *item = 9; return(true); } - else if (PtInRect(mouseIs, &bottomBound)) + else if (bottomBound.Contains(mouseIs)) { *item = 10; return(true); diff --git a/GpApp/Tools.cpp b/GpApp/Tools.cpp index cb81abe..08d5f1b 100644 --- a/GpApp/Tools.cpp +++ b/GpApp/Tools.cpp @@ -192,7 +192,7 @@ void DrawToolTiles (DrawSurface *surface) void EraseSelectedTool (void) { #ifndef COMPILEDEMO - DrawSurface *surface = mainWindow->GetDrawSurface(); + DrawSurface *surface = toolsWindow->GetDrawSurface(); Rect theRect; short toolIcon; @@ -269,7 +269,6 @@ void UpdateToolsWindow (void) return; DrawSurface *surface = toolsWindow->GetDrawSurface(); - DrawControls(toolsWindow); DkGrayForeColor(surface); surface->DrawLine(Point::Create(4, 25), Point::Create(112, 25)); @@ -353,6 +352,8 @@ void OpenToolsWindow (void) } UpdateToolsCheckmark(true); + + UpdateToolsWindow(); #endif } @@ -460,7 +461,7 @@ void SwitchToolModes (short newMode) void HandleToolsClick (Point wherePt) { #ifndef COMPILEDEMO - ControlHandle theControl; + PortabilityLayer::Widget *theControl; short i, part, newMode, toolIcon; if (toolsWindow == nil) @@ -472,10 +473,10 @@ void HandleToolsClick (Point wherePt) part = FindControl(wherePt, toolsWindow, &theControl); if ((theControl != nil) && (part != 0)) { - part = TrackControl(theControl, wherePt, (ControlActionUPP)-1L); + part = TrackControl(theControl, wherePt, nullptr); if (part != 0) { - newMode = GetControlValue(theControl); + newMode = theControl->GetState(); if (newMode != toolMode) { EraseSelectedTool(); @@ -486,7 +487,7 @@ void HandleToolsClick (Point wherePt) else { for (i = 0; i < kTotalTools; i++) - if ((PtInRect(wherePt, &toolRects[i])) && (i <= lastTool)) + if ((toolRects[i].Contains(wherePt)) && (i <= lastTool)) { EraseSelectedTool(); toolIcon = i; diff --git a/PortabilityLayer/PLArrayView.h b/PortabilityLayer/PLArrayView.h index 172f98d..95edb52 100644 --- a/PortabilityLayer/PLArrayView.h +++ b/PortabilityLayer/PLArrayView.h @@ -7,7 +7,7 @@ class ArrayViewIterator; template class ArrayView -{ +{ public: ArrayView(const T *items, size_t count); ArrayView(const ArrayView &other); @@ -15,8 +15,8 @@ public: size_t Count() const; const T &operator[](size_t index) const; - ArrayViewIterator begin() const; - ArrayViewIterator end() const; + ArrayViewIterator begin() const; + ArrayViewIterator end() const; private: const T *m_items; @@ -34,14 +34,14 @@ template inline ArrayView::ArrayView(const T *items, size_t count) : m_items(items) , m_count(count) -{ +{ } template inline ArrayView::ArrayView(const ArrayView &other) : m_items(other.m_items) , m_count(other.m_count) -{ +{ } template @@ -51,7 +51,7 @@ inline size_t ArrayView::Count() const } template -const T &ArrayView::operator[](size_t index) const +inline const T &ArrayView::operator[](size_t index) const { #if GP_DEBUG_CONFIG assert(index < m_count); @@ -61,21 +61,21 @@ const T &ArrayView::operator[](size_t index) const } template -inline ArrayViewIterator ArrayView::begin() const +inline ArrayViewIterator ArrayView::begin() const { #if GP_DEBUG_CONFIG - return ArrayViewIterator(m_items, m_count, 0); + return ArrayViewIterator(this->m_items, this->m_count, 0); #else - return ArrayViewIterator(m_items); + return ArrayViewIterator(this->m_items); #endif } template -inline ArrayViewIterator ArrayView::end() const +inline ArrayViewIterator ArrayView::end() const { #if GP_DEBUG_CONFIG - return ArrayViewIterator(m_items, m_count, m_count); + return ArrayViewIterator(m_items, m_count, m_count); #else - return ArrayViewIterator(m_items + m_count); + return ArrayViewIterator(m_items + m_count); #endif } diff --git a/PortabilityLayer/PLControlDefinitions.cpp b/PortabilityLayer/PLControlDefinitions.cpp index 84a33c3..e00f673 100644 --- a/PortabilityLayer/PLControlDefinitions.cpp +++ b/PortabilityLayer/PLControlDefinitions.cpp @@ -1,5 +1,7 @@ #include "PLControlDefinitions.h" - +#include "PLArrayView.h" +#include "PLArrayViewIterator.h" +#include "PLWidgets.h" int FindControl(Point point, WindowPtr window, ControlHandle *outControl) { @@ -9,7 +11,21 @@ int FindControl(Point point, WindowPtr window, ControlHandle *outControl) int FindControl(Point point, WindowPtr window, PortabilityLayer::Widget **outControl) { - PL_NotYetImplemented(); + // Returns clicked part + ArrayView widgets = window->GetWidgets(); + + for (ArrayViewIterator it = widgets.begin(), itEnd = widgets.end(); it != itEnd; ++it) + { + PortabilityLayer::Widget *widget = *it; + const Rect widgetRect = widget->GetRect(); + if (widgetRect.Contains(point)) + { + *outControl = widget; + return kControlButtonPart; + } + } + + *outControl = nullptr; return 0; } diff --git a/PortabilityLayer/PLCore.cpp b/PortabilityLayer/PLCore.cpp index 7f6e4a2..ab7d386 100644 --- a/PortabilityLayer/PLCore.cpp +++ b/PortabilityLayer/PLCore.cpp @@ -1,4 +1,6 @@ #include "PLCore.h" + +#include "PLArrayView.h" #include "PLApplication.h" #include "PLPasStr.h" #include "PLKeyEncoding.h" @@ -822,3 +824,8 @@ void Window::OnTick() for (size_t i = 0; i < m_numWidgets; i++) m_widgets[i]->OnTick(); } + +ArrayView Window::GetWidgets() const +{ + return ArrayView< PortabilityLayer::Widget*>(m_widgets, m_numWidgets); +} diff --git a/PortabilityLayer/PLCore.h b/PortabilityLayer/PLCore.h index 0982db2..479d120 100644 --- a/PortabilityLayer/PLCore.h +++ b/PortabilityLayer/PLCore.h @@ -13,11 +13,14 @@ #pragma warning(error:4311) // Pointer truncation to int #endif +template +class ArrayView; struct IGpColorCursor; struct GpVOSEvent; struct GpMouseInputEvent; struct TimeTaggedVOSEvent; + namespace PortabilityLayer { struct MMHandleBlock; @@ -90,6 +93,8 @@ struct Window void OnTick(); + ArrayView GetWidgets() const; + DrawSurface m_surface; // Must be the first item until the immediate mode draw API is completely removed // The port is always at 0,0 diff --git a/PortabilityLayer/PLHacks.cpp b/PortabilityLayer/PLHacks.cpp index 3ae7ad3..da7710a 100644 --- a/PortabilityLayer/PLHacks.cpp +++ b/PortabilityLayer/PLHacks.cpp @@ -17,10 +17,10 @@ bool IsHighScoreDisabled() bool IsRoomEditorDisabled() { - return true; + return false; } bool IsHighScoreForceTop() -{ +{ return false; } diff --git a/PortabilityLayer/PLQDraw.cpp b/PortabilityLayer/PLQDraw.cpp index 9d57c0e..84ff334 100644 --- a/PortabilityLayer/PLQDraw.cpp +++ b/PortabilityLayer/PLQDraw.cpp @@ -1655,13 +1655,6 @@ Boolean SectRect(const Rect *rectA, const Rect *rectB, Rect *outIntersection) } -Boolean PtInRect(Point point, const Rect *rect) -{ - PL_NotYetImplemented(); - return false; -} - - void RestoreDeviceClut(void *unknown) { PL_NotYetImplemented(); diff --git a/PortabilityLayer/PLQDraw.h b/PortabilityLayer/PLQDraw.h index 0ed8af8..e947078 100644 --- a/PortabilityLayer/PLQDraw.h +++ b/PortabilityLayer/PLQDraw.h @@ -146,8 +146,6 @@ void SubPt(Point srcPoint, Point *destPoint); Boolean SectRect(const Rect *rectA, const Rect *rectB, Rect *outIntersection); -Boolean PtInRect(Point point, const Rect *rect); - void RestoreDeviceClut(void *unknown);