Fix up some level editor dialog behavior

This commit is contained in:
elasota
2020-02-26 12:17:04 -05:00
parent d617795591
commit cc17911776
23 changed files with 224 additions and 201 deletions

View File

@@ -1,6 +1,7 @@
#include "InputManager.h"
#include "MacRomanConversion.h"
#include "PLKeyEncoding.h"
#include "Vec2i.h"
#include <string.h>
#include <assert.h>
@@ -17,6 +18,7 @@ namespace PortabilityLayer
void ApplyGamepadEvent(const GpGamepadInputEvent &vosEvent) override;
void ApplyMouseEvent(const GpMouseInputEvent &vosEvent) override;
int16_t GetGamepadAxis(unsigned int playerNum, GpGamepadAxis_t gamepadAxis) override;
Vec2i GetMousePosition() const override;
void ClearState() override;
static InputManagerImpl *GetInstance();
@@ -28,6 +30,7 @@ namespace PortabilityLayer
KeyDownStates m_keyMap;
int16_t m_axisStates[PL_INPUT_MAX_PLAYERS][GpGamepadAxes::kCount];
Vec2i m_mousePos;
static InputManagerImpl ms_instance;
};
@@ -53,6 +56,9 @@ namespace PortabilityLayer
void InputManagerImpl::ApplyMouseEvent(const GpMouseInputEvent &vosEvent)
{
m_mousePos.m_x = vosEvent.m_x;
m_mousePos.m_y = vosEvent.m_y;
if (vosEvent.m_eventType == GpMouseEventTypes::kUp || vosEvent.m_eventType == GpMouseEventTypes::kLeave)
this->ApplyEventAsMouseButton(vosEvent, false);
else if (vosEvent.m_eventType == GpMouseEventTypes::kDown)
@@ -66,6 +72,11 @@ namespace PortabilityLayer
return m_axisStates[playerNum][gamepadAxis];
}
Vec2i InputManagerImpl::GetMousePosition() const
{
return m_mousePos;
}
void InputManagerImpl::ClearState()
{
memset(&m_axisStates, 0, sizeof(m_axisStates));
@@ -132,6 +143,7 @@ namespace PortabilityLayer
}
InputManagerImpl::InputManagerImpl()
: m_mousePos(0, 0)
{
memset(m_axisStates, 0, sizeof(m_axisStates));
}

View File

@@ -9,6 +9,8 @@ struct KeyDownStates;
namespace PortabilityLayer
{
struct Vec2i;
class InputManager
{
public:
@@ -17,6 +19,7 @@ namespace PortabilityLayer
virtual void ApplyGamepadEvent(const GpGamepadInputEvent &vosEvent) = 0;
virtual void ApplyMouseEvent(const GpMouseInputEvent &vosEvent) = 0;
virtual int16_t GetGamepadAxis(unsigned int playerNum, GpGamepadAxis_t gamepadAxis) = 0;
virtual Vec2i GetMousePosition() const = 0;
virtual void ClearState() = 0;
static InputManager *GetInstance();

View File

@@ -15,6 +15,9 @@ namespace PortabilityLayer
WidgetHandleState_t ButtonWidget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
if (!m_visible || !m_enabled)
return WidgetHandleStates::kIgnored;
if (m_haveMouseDown)
{
if (evt.IsLMouseUpEvent())

View File

@@ -74,6 +74,9 @@ namespace PortabilityLayer
WidgetHandleState_t CheckboxWidget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
if (!m_visible || !m_enabled)
return WidgetHandleStates::kIgnored;
if (m_haveMouseDown)
{
if (evt.IsLMouseUpEvent())

View File

@@ -496,9 +496,11 @@ void DisposeDirectoryFiles(DirectoryFileListEntry *firstDFL)
}
}
void GetMouse(Point *point)
void GetMouse(Window *window, Point *point)
{
PL_NotYetImplemented();
const PortabilityLayer::Vec2i mousePos = PortabilityLayer::InputManager::GetInstance()->GetMousePosition();
point->h = mousePos.m_x - window->m_wmX;
point->v = mousePos.m_y - window->m_wmY;
}
Boolean Button()
@@ -514,7 +516,11 @@ Boolean StillDown()
Boolean WaitMouseUp()
{
return StillDown();
const Boolean isDown = StillDown();
if (isDown)
PLSysCalls::Sleep(1);
return isDown;
}
short Random()

View File

@@ -285,7 +285,7 @@ PLError_t FSpGetFInfo(const VFileSpec &spec, VFileInfo &finfoOut);
DirectoryFileListEntry *GetDirectoryFiles(PortabilityLayer::VirtualDirectory_t dirID);
void DisposeDirectoryFiles(DirectoryFileListEntry *firstDFL);
void GetMouse(Point *point);
void GetMouse(Window *window, Point *point);
Boolean Button(); // Returns true if there's a mouse down event in the queue
Boolean StillDown();
Boolean WaitMouseUp();

View File

@@ -109,5 +109,5 @@ void ShowDialogItem(Dialog *dialog, int item)
void HideDialogItem(Dialog *dialog, int item)
{
PL_NotYetImplemented();
dialog->GetItems()[item - 1].GetWidget()->SetVisible(false);
}

View File

@@ -164,6 +164,9 @@ namespace PortabilityLayer
WidgetHandleState_t EditboxWidget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
if (!m_visible || !m_enabled)
return WidgetHandleStates::kIgnored;
if (evt.m_vosEvent.m_eventType == GpVOSEventTypes::kKeyboardInput)
{
if (!m_hasFocus)

View File

@@ -50,6 +50,9 @@ namespace PortabilityLayer
WidgetHandleState_t IconWidget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
if (!m_visible || !m_enabled)
return WidgetHandleStates::kIgnored;
if (evt.IsLMouseDownEvent() && m_rect.Contains(m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent)))
return WidgetHandleStates::kActivated;
else

View File

@@ -23,6 +23,9 @@ namespace PortabilityLayer
WidgetHandleState_t InvisibleWidget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
if (!m_visible || !m_enabled)
return WidgetHandleStates::kIgnored;
if (m_clickable && evt.IsLMouseDownEvent() && m_rect.Contains(m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent)))
return WidgetHandleStates::kActivated;
else

View File

@@ -31,6 +31,11 @@
#include <algorithm>
#include <assert.h>
static inline void InvertPixel8(uint8_t &pixel)
{
pixel = 255 ^ pixel;
}
void GetPort(GrafPtr *graf)
{
@@ -1362,7 +1367,7 @@ void DrawSurface::InvertFrameRect(const Rect &rect, const uint8_t *pattern)
{
InvertFillRect(Rect::Create(rect.top, rect.left, rect.top + 1, rect.right), pattern);
InvertFillRect(Rect::Create(rect.top + 1, rect.left, rect.bottom - 1, rect.left + 1), pattern);
InvertFillRect(Rect::Create(rect.bottom - 1, rect.left, rect.bottom + 1, rect.right), pattern);
InvertFillRect(Rect::Create(rect.bottom - 1, rect.left, rect.bottom, rect.right), pattern);
InvertFillRect(Rect::Create(rect.top + 1, rect.right - 1, rect.bottom - 1, rect.right), pattern);
}
}
@@ -1414,7 +1419,7 @@ void DrawSurface::InvertFillRect(const Rect &rect, const uint8_t *pattern)
{
const int patternCol = static_cast<int>((patternFirstCol + col) & 7);
if ((pattern[patternRow] >> patternCol) & 1)
pixData[firstLineIndex + col] = 255 - pixData[firstLineIndex + col];
InvertPixel8(pixData[firstLineIndex + col]);
}
}
}
@@ -1477,11 +1482,6 @@ void PenNormal()
qdState->m_penMask = false;
}
void InvertRect(const Rect *rect)
{
PL_NotYetImplemented();
}
void InsetRect(Rect *rect, int x, int y)
{
rect->left += x;
@@ -1783,7 +1783,7 @@ void ImageInvert(const PixMap *invertMask, PixMap *targetBitmap, const Rect &src
const int32_t srcCol = c + firstSrcCol;
const int32_t destCol = c + firstDestCol;
if (invertRowStart[srcCol] != 0)
targetRowStart[destCol] = 255 - targetRowStart[destCol];
InvertPixel8(targetRowStart[destCol]);
}
break;
default:
@@ -1814,14 +1814,6 @@ DrawSurface *GetWindowPort(WindowPtr window)
return &window->m_surface;
}
Int32 DeltaPoint(Point pointA, Point pointB)
{
PL_NotYetImplemented();
return 0;
}
void SubPt(Point srcPoint, Point *destPoint)
{
PL_NotYetImplemented();

View File

@@ -117,7 +117,6 @@ void PenMask(bool maskMode);
void PenPat(const Pattern *pattern);
void PenSize(int w, int h);
void PenNormal();
void InvertRect(const Rect *rect);
void InsetRect(Rect *rect, int x, int y);
Pattern *GetQDGlobalsGray(Pattern *pattern);
Pattern *GetQDGlobalsBlack(Pattern *pattern);
@@ -140,9 +139,6 @@ bool PointInScanlineMask(Point point, PortabilityLayer::ScanlineMask *scanlineMa
PixMap *GetPortBitMapForCopyBits(DrawSurface *grafPtr);
DrawSurface *GetWindowPort(WindowPtr window);
// Computes A - B and returns it packed?
Int32 DeltaPoint(Point pointA, Point pointB);
// Subtracts srcPoint from destPoint (reverse of DeltaPoint)
void SubPt(Point srcPoint, Point *destPoint);

View File

@@ -73,6 +73,9 @@ namespace PortabilityLayer
WidgetHandleState_t RadioButtonWidget::ProcessEvent(const TimeTaggedVOSEvent &evt)
{
if (!m_visible || !m_enabled)
return WidgetHandleStates::kIgnored;
if (m_haveMouseDown)
{
if (evt.IsLMouseUpEvent())

View File

@@ -18,6 +18,9 @@ struct Point
Point &operator-=(const Point &other);
Point &operator+=(const Point &other);
bool operator==(const Point &other) const;
bool operator!=(const Point &other) const;
static Point Create(int16_t h, int16_t v);
};
@@ -139,6 +142,17 @@ inline Point &Point::operator+=(const Point &other)
return *this;
}
inline bool Point::operator==(const Point &other) const
{
return this->h == other.h && this->v == other.v;
}
inline bool Point::operator!=(const Point &other) const
{
return !((*this) == other);
}
inline Point Point::Create(int16_t h, int16_t v)
{
Point p;

View File

@@ -28,7 +28,7 @@ namespace PortabilityLayer
{
virtual void GetChromePadding(const WindowImpl *window, uint16_t padding[WindowChromeSides::kCount]) const = 0;
virtual void RenderChrome(WindowImpl *window, DrawSurface *surface, WindowChromeSide_t chromeSide) const = 0;
virtual bool GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID &outRegion) const = 0;
virtual bool GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID_t &outRegion) const = 0;
};
template<class T>
@@ -46,7 +46,7 @@ namespace PortabilityLayer
public:
void GetChromePadding(const WindowImpl *window, uint16_t padding[WindowChromeSides::kCount]) const override;
void RenderChrome(WindowImpl *window, DrawSurface *surface, WindowChromeSide_t chromeSide) const override;
bool GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID &outRegion) const override;
bool GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID_t &outRegion) const override;
};
class GenericWindowChromeTheme final : public WindowChromeThemeSingleton<GenericWindowChromeTheme>
@@ -54,7 +54,7 @@ namespace PortabilityLayer
public:
void GetChromePadding(const WindowImpl *window, uint16_t padding[WindowChromeSides::kCount]) const override;
void RenderChrome(WindowImpl *window, DrawSurface *surface, WindowChromeSide_t chromeSide) const override;
bool GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID &outRegion) const override;
bool GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID_t &outRegion) const override;
private:
void RenderChromeTop(WindowImpl *window, DrawSurface *surface) const;
@@ -93,7 +93,7 @@ namespace PortabilityLayer
void GetChromePadding(uint16_t padding[WindowChromeSides::kCount]) const;
void GetChromeDimensions(int width, int height, Rect dimensions[WindowChromeSides::kCount]) const;
bool GetChromeInteractionZone(const Vec2i &point, RegionID &outRegion) const;
bool GetChromeInteractionZone(const Vec2i &point, RegionID_t &outRegion) const;
bool IsBorderless() const;
uint16_t GetStyleFlags() const;
@@ -163,7 +163,7 @@ namespace PortabilityLayer
padding[WindowChromeSides::kRight] = 1;
}
bool SimpleBoxChromeTheme::GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID &outRegion) const
bool SimpleBoxChromeTheme::GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID_t &outRegion) const
{
return false;
}
@@ -205,7 +205,7 @@ namespace PortabilityLayer
}
}
bool GenericWindowChromeTheme::GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID &outRegion) const
bool GenericWindowChromeTheme::GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID_t &outRegion) const
{
const DrawSurface *surface = window->GetDrawSurface();
const Rect rect = (*surface->m_port.GetPixMap())->m_rect;
@@ -214,7 +214,7 @@ namespace PortabilityLayer
{
if (point.m_x >= 0 && point.m_x < rect.Width() && point.m_y < 0 && point.m_y >= -13)
{
outRegion = RegionID::inDrag;
outRegion = RegionIDs::kTitleBar;
return true;
}
}
@@ -222,7 +222,7 @@ namespace PortabilityLayer
{
if (point.m_x >= 0 && point.m_x < rect.Width() && point.m_y < 0 && point.m_y >= -17)
{
outRegion = RegionID::inDrag;
outRegion = RegionIDs::kTitleBar;
return true;
}
}
@@ -457,6 +457,8 @@ namespace PortabilityLayer
m_styleFlags = windowDef.m_styleFlags;
const Rect adjustedBounds = Rect::Create(0, 0, bounds.Height(), bounds.Width());
m_wmX = bounds.left;
m_wmY = bounds.top;
GpPixelFormat_t pixelFormat = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetPixelFormat();
@@ -565,7 +567,7 @@ namespace PortabilityLayer
dimensions[WindowChromeSides::kRight] = Rect::Create(0, 0, leftAndRightHeight, padding[WindowChromeSides::kRight]);
}
bool WindowImpl::GetChromeInteractionZone(const Vec2i &point, RegionID &outRegion) const
bool WindowImpl::GetChromeInteractionZone(const Vec2i &point, RegionID_t &outRegion) const
{
return m_chromeTheme->GetChromeInteractionZone(this, point, outRegion);
}
@@ -669,24 +671,13 @@ namespace PortabilityLayer
void WindowManagerImpl::FindWindow(const Point &point, Window **outWindow, short *outRegion) const
{
// outRegion = One of:
/*
inMenuBar,
inContent,
inDrag,
inGrow,
inGoAway,
inZoomIn,
inZoomOut,
*/
if (PortabilityLayer::MenuManager::GetInstance()->IsPointInMenuBar(PortabilityLayer::Vec2i(point.h, point.v)))
{
if (outWindow)
*outWindow = nullptr;
if (outRegion)
*outRegion = inMenuBar;
*outRegion = RegionIDs::kMenuBar;
return;
}
@@ -699,7 +690,7 @@ namespace PortabilityLayer
const int32_t localX = point.h - window->m_wmX;
const int32_t localY = point.v - window->m_wmY;
RegionID chromeInteractionZone = inContent;
RegionID_t chromeInteractionZone = RegionIDs::kContent;
if (window->GetChromeInteractionZone(Vec2i(localX, localY), chromeInteractionZone))
{
*outRegion = chromeInteractionZone;
@@ -713,7 +704,7 @@ namespace PortabilityLayer
*outWindow = window;
if (outRegion)
*outRegion = inContent;
*outRegion = RegionIDs::kContent;
return;
}