Touchscreen things

This commit is contained in:
elasota
2020-10-11 19:50:03 -04:00
parent 5c98783bbb
commit 184daefe7b
34 changed files with 799 additions and 35 deletions

View File

@@ -265,6 +265,9 @@ Boolean GetColorCursors (acurHandle ballCursH, compiledAcurHandle compiledBallCu
void InitAnimatedCursor (acurHandle ballCursH)
{
if (thisMac.isTouchscreen)
return;
compiledAcurHandle compiledBallCursorH;
if (ballCursH == nil)
@@ -275,7 +278,6 @@ void InitAnimatedCursor (acurHandle ballCursH)
if (!compiledBallCursorH)
RedAlert(kErrFailedResourceLoad);
GetColorCursors(ballCursH, compiledBallCursorH);
DisposCursors();
animCursorH = ballCursH;
@@ -335,8 +337,9 @@ void IncrementCursor (void)
InitAnimatedCursor(nil);
if (animCursorH)
{
(*animCursorH)->index++;
(*animCursorH)->index %= (*animCursorH)->n;
acurRec *acur = *animCursorH;
acur->index++;
acur->index %= acur->n;
PortabilityLayer::HostDisplayDriver::GetInstance()->SetCursor((*compiledAnimCursorH)->frame[(*animCursorH)->index].hwCursor);
}

View File

@@ -301,6 +301,9 @@ void CheckOurEnvirons (void)
thisMac.numScreens = HowManyUsableScreens(false, true, true);
thisMac.isResolutionDirty = true;
thisMac.isTouchscreen = PortabilityLayer::HostSystemServices::GetInstance()->IsTouchscreen();
thisMac.isMouseTouchscreen = PortabilityLayer::HostSystemServices::GetInstance()->IsUsingMouseAsTouch();
FlushResolutionChange();
}

View File

@@ -29,6 +29,8 @@ typedef struct
Boolean hasQT;
Boolean hasDrag;
Boolean isResolutionDirty;
Boolean isTouchscreen;
Boolean isMouseTouchscreen;
} macEnviron;

View File

@@ -362,4 +362,72 @@ typedef struct
short object;
} retroLink, *retroLinkPtr;
namespace TouchScreenCtrlIDs
{
enum TouchScreenCtrlID
{
None,
MoveLeft,
MoveRight,
Flip,
Bands,
BatteryHelium,
Count,
};
};
typedef TouchScreenCtrlIDs::TouchScreenCtrlID TouchScreenCtrlID_t;
typedef struct
{
int fingerID;
Point point;
TouchScreenCtrlID_t capturingControl;
} touchScreenFingerState;
typedef struct
{
Rect graphicRect;
Rect touchRect;
Boolean isEnabled;
} touchScreenControl;
namespace touchScreenControlGraphics
{
enum touchScreenControlGraphic
{
BandsDisabled,
BandsActive,
BandsIdle,
FlipActive,
FlipIdle,
MoveRightActive,
MoveRightIdle,
MoveLeftActive,
MoveLeftIdle,
HeliumDisabled,
HeliumActive,
HeliumIdle,
BatteryDisabled,
BatteryActive,
BatteryIdle,
Count,
};
static const int kTouchScreenGraphicStartID = 1973;
}
typedef touchScreenControlGraphics::touchScreenControlGraphic touchScreenControlGraphic_t;
typedef struct
{
static const int kMaxFingers = 4;
touchScreenControl controls[TouchScreenCtrlIDs::Count];
touchScreenFingerState fingers[kMaxFingers];
DrawSurface *graphics[touchScreenControlGraphics::Count];
} touchScreenControlState, *touchScreenControlStatePtr;

View File

@@ -13,9 +13,12 @@
#include "Environ.h"
#include "House.h"
#include "MainWindow.h"
#include "PLEventQueue.h"
#include "PLTimeTaggedVOSEvent.h"
#include "RectUtils.h"
#include "ResolveCachingColor.h"
#include "Scoreboard.h"
#include "Utilities.h"
#define kHouseBannerAlert 1009
@@ -42,8 +45,6 @@ void HandleRoomVisitation (void);
void SetObjectsToDefaults (void);
void InitTelephone (void);
void HandleTelephone (void);
Boolean DoesStarCodeExist (short);
short GetNumStarsRemaining (short, short);
phoneType thePhone, theChimes;
@@ -55,11 +56,14 @@ short batteryTotal, bandsTotal, foilTotal, mortals;
Boolean playing, evenFrame, twoPlayerGame, showFoil, demoGoing;
Boolean doBackground, playerSuicide, phoneBitSet, tvOn;
touchScreenControlState touchScreen;
extern VFileSpec *theHousesSpecs;
extern demoPtr demoData;
extern gameType smallGame;
extern Rect gliderSrc[kNumGliderSrcRects];
extern Rect boardDestRect, boardSrcRect;
extern Rect localRoomsDest[];
extern long incrementModeTime;
extern short numBands, otherPlayerEscaped, demoIndex, demoHouseIndex;
extern short splashOriginH, splashOriginV, countDown, thisHouseIndex;
@@ -384,15 +388,215 @@ void HandleGameResolutionChange(void)
DumpScreenOn(&justRoomsRect, true);
}
//-------------------------------------------------------------- HandleTouchUp
void HandleTouchUp(int fingerID)
{
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{
if (touchScreen.fingers[i].fingerID == fingerID)
{
touchScreen.fingers[i].fingerID = -1;
touchScreen.fingers[i].capturingControl = TouchScreenCtrlIDs::None;
return;
}
}
}
//-------------------------------------------------------------- HandleTouchMove
void HandleTouchMove(int fingerID, const Point &pt)
{
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{
if (touchScreen.fingers[i].fingerID == fingerID)
{
touchScreen.fingers[i].point = pt;
return;
}
}
}
//-------------------------------------------------------------- HandleTouchDown
void HandleTouchDown(int fingerID, const Point &pt)
{
int freeFingerIndex = -1;
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{
if (touchScreen.fingers[i].fingerID == fingerID)
{
// Finger is already considered down, something weird happened
HandleTouchMove(fingerID, pt);
return;
}
else if (touchScreen.fingers[i].fingerID < 0)
freeFingerIndex = i;
}
if (freeFingerIndex < 0)
return;
touchScreenFingerState &fingerState = touchScreen.fingers[freeFingerIndex];
for (int j = 0; j < TouchScreenCtrlIDs::Count; j++)
{
if (touchScreen.controls[j].isEnabled)
{
if (touchScreen.controls[j].touchRect.Contains(pt))
{
fingerState.fingerID = fingerID;
fingerState.capturingControl = static_cast<TouchScreenCtrlID_t>(j);
fingerState.point = pt;
return;
}
}
}
}
//-------------------------------------------------------------- HandleTouchLeave
void HandleTouchLeave(int fingerID)
{
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{
if (touchScreen.fingers[i].fingerID == fingerID)
{
touchScreen.fingers[i].fingerID = -1;
touchScreen.fingers[i].capturingControl = TouchScreenCtrlIDs::None;
return;
}
}
}
//-------------------------------------------------------------- HandleInGameEvents
void HandleInGameEvents(void)
{
PortabilityLayer::EventQueue *queue = PortabilityLayer::EventQueue::GetInstance();
TimeTaggedVOSEvent evt;
while (queue->Dequeue(&evt))
{
if (thisMac.isTouchscreen)
{
if (thisMac.isMouseTouchscreen && evt.m_vosEvent.m_eventType == GpVOSEventTypes::kMouseInput)
{
const GpMouseInputEvent &mouseInput = evt.m_vosEvent.m_event.m_mouseInputEvent;
const Point mousePt = mainWindow->MouseToLocal(mouseInput);
switch (mouseInput.m_eventType)
{
case GpMouseEventTypes::kDown:
if (mouseInput.m_button == GpMouseButtons::kLeft)
HandleTouchDown(0, mousePt);
break;
case GpMouseEventTypes::kLeave:
HandleTouchLeave(0);
break;
case GpMouseEventTypes::kUp:
HandleTouchMove(0, mousePt);
HandleTouchUp(0);
break;
case GpMouseEventTypes::kMove:
HandleTouchMove(0, mousePt);
break;
default:
break;
};
}
}
}
}
//-------------------------------------------------------------- ResetTouchScreenControlBounds
static int16_t touchScreenControlSize = 32;
void ResetTouchScreenControlBounds (void)
{
if (!thisMac.isTouchscreen)
return;
const Rect centerRoomRect = localRoomsDest[kCentralRoom];
int16_t touchScreenControlInterSpacing = 16;
int16_t touchScreenControlEdgeSpacing = 24;
Point points[TouchScreenCtrlIDs::Count];
Point sizes[TouchScreenCtrlIDs::Count];
points[TouchScreenCtrlIDs::MoveLeft] = Point::Create(mainWindowRect.left + touchScreenControlEdgeSpacing, mainWindowRect.bottom - touchScreenControlEdgeSpacing - touchScreenControlSize);
points[TouchScreenCtrlIDs::MoveRight] = points[TouchScreenCtrlIDs::MoveLeft] + Point::Create(touchScreenControlInterSpacing + touchScreenControlSize, 0);
points[TouchScreenCtrlIDs::BatteryHelium] = Point::Create(mainWindowRect.right - touchScreenControlEdgeSpacing - touchScreenControlSize, mainWindowRect.bottom - touchScreenControlEdgeSpacing - touchScreenControlSize);
points[TouchScreenCtrlIDs::Flip] = points[TouchScreenCtrlIDs::BatteryHelium] + Point::Create(0, -touchScreenControlInterSpacing - touchScreenControlSize);
points[TouchScreenCtrlIDs::Bands] = points[TouchScreenCtrlIDs::BatteryHelium] + Point::Create(-touchScreenControlInterSpacing - touchScreenControlSize, 0);
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
sizes[i] = Point::Create(touchScreenControlSize, touchScreenControlSize);
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
{
Point lowerRight = points[i] + sizes[i];
touchScreen.controls[i].graphicRect = Rect::Create(points[i].v, points[i].h, lowerRight.v, lowerRight.h);
touchScreen.controls[i].touchRect = touchScreen.controls[i].graphicRect.Inset(-(touchScreenControlInterSpacing / 2), -(touchScreenControlInterSpacing / 2));
}
// Clear all active touches
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{
touchScreen.fingers[i].fingerID = -1;
touchScreen.fingers[i].capturingControl = TouchScreenCtrlIDs::None;
}
}
//-------------------------------------------------------------- InitTouchScreenControlState
void InitTouchScreenControlState(void)
{
if (!thisMac.isTouchscreen)
return;
ResetTouchScreenControlBounds();
for (int i = 0; i < touchScreenControlGraphics::Count; i++)
{
if (touchScreen.graphics[i] != nil)
continue;
int resID = touchScreenControlGraphics::kTouchScreenGraphicStartID + i;
Rect resRect = Rect::Create(0, 0, touchScreenControlSize, touchScreenControlSize);
(void)CreateOffScreenGWorld(&touchScreen.graphics[i], &resRect);
LoadGraphic(touchScreen.graphics[i], resID);
}
}
//-------------------------------------------------------------- PlayGame
void PlayGame (void)
{
InitTouchScreenControlState();
touchScreen.controls[TouchScreenCtrlIDs::MoveLeft].isEnabled = true;
touchScreen.controls[TouchScreenCtrlIDs::MoveRight].isEnabled = true;
touchScreen.controls[TouchScreenCtrlIDs::Flip].isEnabled = true;
touchScreen.controls[TouchScreenCtrlIDs::Bands].isEnabled = true;
touchScreen.controls[TouchScreenCtrlIDs::BatteryHelium].isEnabled = true;
while ((playing) && (!quitting))
{
HandleInGameEvents();
if (thisMac.isResolutionDirty)
{
HandleGameResolutionChange();
ResetTouchScreenControlBounds();
}
gameFrame++;

View File

@@ -29,6 +29,7 @@ void RenderSparkles (void);
void RenderStars (void);
void RenderBands (void);
void RenderShreds (void);
void RenderTouchScreenControls (void);
void CopyRectsQD (void);
@@ -55,6 +56,7 @@ extern short numBands, numStars, numShredded;
extern short numSparkles, numFlyingPts, numPendulums, clockFrame;
extern short numFlames, numSavedMaps, numTikiFlames, numCoals;
extern Boolean evenFrame, shadowVisible, twoPlayerGame, tvOn;
extern touchScreenControlState touchScreen;
//============================================================== Functions
@@ -604,6 +606,66 @@ void RenderShreds (void)
}
}
//-------------------------------------------------------------- RenderTouchScreenControls
void RenderTouchScreenControls (void)
{
DrawSurface *ctrlGraphics[TouchScreenCtrlIDs::Count];
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
ctrlGraphics[i] = nullptr;
ctrlGraphics[TouchScreenCtrlIDs::MoveLeft] = touchScreen.graphics[touchScreenControlGraphics::MoveLeftIdle];
ctrlGraphics[TouchScreenCtrlIDs::MoveRight] = touchScreen.graphics[touchScreenControlGraphics::MoveRightIdle];
ctrlGraphics[TouchScreenCtrlIDs::Flip] = touchScreen.graphics[touchScreenControlGraphics::FlipIdle];
ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsDisabled];
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryDisabled];
if (batteryTotal < 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::HeliumIdle];
else if (batteryTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryIdle];
if (bandsTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsIdle];
for (int i = 0; i < touchScreenControlState::kMaxFingers; i++)
{
if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::BatteryHelium)
{
if (batteryTotal < 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::HeliumActive];
else if (batteryTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BandsActive];
}
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Bands)
{
if (bandsTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsActive];
}
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Flip)
ctrlGraphics[TouchScreenCtrlIDs::Flip] = touchScreen.graphics[touchScreenControlGraphics::FlipActive];
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::MoveLeft)
ctrlGraphics[TouchScreenCtrlIDs::MoveLeft] = touchScreen.graphics[touchScreenControlGraphics::MoveLeftActive];
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::MoveRight)
ctrlGraphics[TouchScreenCtrlIDs::MoveRight] = touchScreen.graphics[touchScreenControlGraphics::MoveRightActive];
}
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
{
DrawSurface *graphic = ctrlGraphics[i];
if (!graphic)
continue;
const Rect sourceRect = ctrlGraphics[i]->m_port.GetRect();
Rect destRect = touchScreen.controls[i].graphicRect;
CopyMask(*GetGWorldPixMap(ctrlGraphics[i]), *GetGWorldPixMap(ctrlGraphics[i]), *GetGWorldPixMap(workSrcMap), &sourceRect, &sourceRect, &destRect);
AddRectToBackRects(&destRect);
AddRectToWorkRects(&destRect);
}
}
//-------------------------------------------------------------- CopyRectsQD
void CopyRectsQD (void)
@@ -655,6 +717,7 @@ void RenderFrame (void)
RenderGlider(&theGlider2, false);
RenderShreds();
RenderBands();
RenderTouchScreenControls();
while (TickCount() < nextFrame)
{