Add stop demo button

This commit is contained in:
elasota
2020-11-03 19:59:26 -05:00
parent 0d304e8a96
commit 3a327a27e7
10 changed files with 146 additions and 54 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -201,6 +201,7 @@ short RandomInt (short);
long RandomLong (long);
void RedAlert (short);
void LoadGraphic (DrawSurface *surface, short resID); // Only loads from app resources
void LoadGraphicNoDither (DrawSurface *surface, short resID);
void LoadGraphicCustom (DrawSurface *surface, short resID); // Supports custom graphics
void LoadScaledGraphic (DrawSurface *, short, Rect *); // Only loads from app resources
void LoadScaledGraphicCustom (DrawSurface *, short, Rect *); // Supports custom graphics

View File

@@ -439,8 +439,8 @@ namespace touchScreenControlGraphics
BandsDisabled,
BandsActive,
BandsIdle,
FlipActive,
FlipIdle,
StopActive,
StopIdle,
MoveRightActive,
MoveRightIdle,
MoveLeftActive,

View File

@@ -494,6 +494,12 @@ void DoHeliumEngaged (gliderPtr thisGlider)
if (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl)))
DoCommandKey();
// Cheesy - Use touchscreen menu as quit
if (pendingTouchScreenMenu)
{
playing = false;
paused = false;
}
#endif
}

View File

@@ -581,7 +581,11 @@ void ResetTouchScreenControlBounds (void)
points[TouchScreenCtrlIDs::Movement] = Point::Create(mainWindowRect.left, mainWindowRect.top);
points[TouchScreenCtrlIDs::BatteryHelium] = Point::Create(mainWindowRect.left + touchScreenControlEdgeSpacing, mainWindowRect.top + touchScreenControlEdgeSpacing);
points[TouchScreenCtrlIDs::Bands] = Point::Create(mainWindowRect.right - touchScreenControlEdgeSpacing - touchScreenControlSize, mainWindowRect.top + touchScreenControlEdgeSpacing);
points[TouchScreenCtrlIDs::Menu] = Point::Create(points[TouchScreenCtrlIDs::Bands].h - touchScreenControlInterSpacing - touchScreenControlSize, points[TouchScreenCtrlIDs::BatteryHelium].v);
if (demoGoing)
points[TouchScreenCtrlIDs::Menu] = Point::Create(mainWindowRect.right - touchScreenControlEdgeSpacing - touchScreenControlSize, mainWindowRect.top + touchScreenControlEdgeSpacing);
else
points[TouchScreenCtrlIDs::Menu] = Point::Create(points[TouchScreenCtrlIDs::Bands].h - touchScreenControlInterSpacing - touchScreenControlSize, points[TouchScreenCtrlIDs::BatteryHelium].v);
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
sizes[i] = Point::Create(touchScreenControlSize, touchScreenControlSize);
@@ -622,7 +626,7 @@ void InitTouchScreenControlState(void)
Rect resRect = Rect::Create(0, 0, touchScreenControlSize, touchScreenControlSize);
(void)CreateOffScreenGWorld(&touchScreen.graphics[i], &resRect);
LoadGraphic(touchScreen.graphics[i], resID);
LoadGraphicNoDither(touchScreen.graphics[i], resID);
}
pendingTouchScreenMenu = false;

View File

@@ -611,43 +611,62 @@ void RenderShreds (void)
void RenderTouchScreenControls (void)
{
if (demoGoing)
return;
DrawSurface *ctrlGraphics[TouchScreenCtrlIDs::Count];
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)
ctrlGraphics[i] = nullptr;
ctrlGraphics[TouchScreenCtrlIDs::Movement] = nullptr;
ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsDisabled];
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryDisabled];
ctrlGraphics[TouchScreenCtrlIDs::Menu] = touchScreen.graphics[touchScreenControlGraphics::MenuIdle];
if (batteryTotal < 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::HeliumIdle];
else if (batteryTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryIdle];
if (demoGoing)
{
ctrlGraphics[TouchScreenCtrlIDs::Bands] = nullptr;
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = nullptr;
ctrlGraphics[TouchScreenCtrlIDs::Menu] = touchScreen.graphics[touchScreenControlGraphics::StopIdle];
}
else
{
ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsDisabled];
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryDisabled];
ctrlGraphics[TouchScreenCtrlIDs::Menu] = touchScreen.graphics[touchScreenControlGraphics::MenuIdle];
if (bandsTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsIdle];
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 (demoGoing)
{
if (batteryTotal < 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::HeliumActive];
else if (batteryTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::BatteryHelium] = touchScreen.graphics[touchScreenControlGraphics::BatteryActive];
if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Menu)
{
ctrlGraphics[TouchScreenCtrlIDs::Menu] = touchScreen.graphics[touchScreenControlGraphics::StopActive];
}
}
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Bands)
else
{
if (bandsTotal > 0)
ctrlGraphics[TouchScreenCtrlIDs::Bands] = touchScreen.graphics[touchScreenControlGraphics::BandsActive];
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::BatteryActive];
}
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::Menu)
{
ctrlGraphics[TouchScreenCtrlIDs::Menu] = touchScreen.graphics[touchScreenControlGraphics::MenuActive];
}
}
else if (touchScreen.fingers[i].capturingControl == TouchScreenCtrlIDs::Menu)
ctrlGraphics[TouchScreenCtrlIDs::Menu] = touchScreen.graphics[touchScreenControlGraphics::MenuActive];
}
for (int i = 0; i < TouchScreenCtrlIDs::Count; i++)

View File

@@ -277,6 +277,22 @@ void LoadGraphic (DrawSurface *surface, short resID)
thePicture.Dispose();
}
void LoadGraphicNoDither(DrawSurface *surface, short resID)
{
Rect bounds;
THandle<BitmapImage> thePicture;
thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', resID).StaticCast<BitmapImage>();
if (thePicture == nil)
RedAlert(kErrFailedGraphicLoad);
bounds = (*thePicture)->GetRect();
OffsetRect(&bounds, -bounds.left, -bounds.top);
surface->DrawPicture(thePicture, bounds, false);
thePicture.Dispose();
}
//-------------------------------------------------------------- LoadGraphicCustom
// Same as LoadGraphic but supports custom graphics
void LoadGraphicCustom(DrawSurface *surface, short resID)

View File

@@ -543,7 +543,7 @@ static void RedistributeError(int16_t *errorDiffusionNextRow, int16_t *errorDiff
}
}
void DrawSurface::DrawPicture(THandle<BitmapImage> pictHdl, const Rect &bounds)
void DrawSurface::DrawPicture(THandle<BitmapImage> pictHdl, const Rect &bounds, bool errorDiffusion)
{
if (!pictHdl)
return;
@@ -722,7 +722,7 @@ void DrawSurface::DrawPicture(THandle<BitmapImage> pictHdl, const Rect &bounds)
int16_t *errorDiffusionNextRow = nullptr;
int16_t *errorDiffusionCurrentRow = nullptr;
if (bpp == 16 || bpp == 24)
if ((bpp == 16 || bpp == 24) && errorDiffusion)
{
errorDiffusionBuffer = static_cast<int16_t*>(memManager->Alloc(sizeof(int16_t) * numCopyCols * 2 * 3));
if (!errorDiffusionBuffer)
@@ -802,31 +802,58 @@ void DrawSurface::DrawPicture(THandle<BitmapImage> pictHdl, const Rect &bounds)
}
else
{
for (size_t col = 0; col < numCopyCols; col++)
if (!errorDiffusion)
{
const size_t srcColIndex = col + firstSourceCol;
const size_t destColIndex = col + firstDestCol;
for (size_t col = 0; col < numCopyCols; col++)
{
const size_t srcColIndex = col + firstSourceCol;
const size_t destColIndex = col + firstDestCol;
const uint8_t srcLow = currentSourceRow[srcColIndex * 2 + 0];
const uint8_t srcHigh = currentSourceRow[srcColIndex * 2 + 1];
const uint8_t srcLow = currentSourceRow[srcColIndex * 2 + 0];
const uint8_t srcHigh = currentSourceRow[srcColIndex * 2 + 1];
const unsigned int combinedValue = srcLow | (srcHigh << 8);
const unsigned int b = (combinedValue & 0x1f);
const unsigned int g = ((combinedValue >> 5) & 0x1f);
const unsigned int r = ((combinedValue >> 10) & 0x1f);
const unsigned int combinedValue = srcLow | (srcHigh << 8);
const unsigned int b = (combinedValue & 0x1f);
const unsigned int g = ((combinedValue >> 5) & 0x1f);
const unsigned int r = ((combinedValue >> 10) & 0x1f);
const unsigned int xr = (r << 5) | (r >> 2);
const unsigned int xg = (g << 5) | (g >> 2);
const unsigned int xb = (b << 5) | (b >> 2);
const unsigned int xr = (r << 5) | (r >> 2);
const unsigned int xg = (g << 5) | (g >> 2);
const unsigned int xb = (b << 5) | (b >> 2);
ErrorDiffusionWorkPixel wp = ApplyErrorDiffusion(errorDiffusionCurrentRow, xr, xg, xb, col, numCopyCols);
uint8_t colorIndex = stdPalette->MapColorLUT(PortabilityLayer::RGBAColor::Create(xr, xg, xb, 255));
uint8_t colorIndex = stdPalette->MapColorLUT(PortabilityLayer::RGBAColor::Create(wp.m_8[0], wp.m_8[1], wp.m_8[2], 255));
PortabilityLayer::RGBAColor resultColor = stdPalette->GetColors()[colorIndex];
currentDestRow[destColIndex] = colorIndex;
}
}
else
{
for (size_t col = 0; col < numCopyCols; col++)
{
const size_t srcColIndex = col + firstSourceCol;
const size_t destColIndex = col + firstDestCol;
RedistributeError(errorDiffusionNextRow, errorDiffusionCurrentRow, wp.m_16[0], wp.m_16[1], wp.m_16[2], resultColor.r, resultColor.g, resultColor.b, col, numCopyCols);
const uint8_t srcLow = currentSourceRow[srcColIndex * 2 + 0];
const uint8_t srcHigh = currentSourceRow[srcColIndex * 2 + 1];
currentDestRow[destColIndex] = colorIndex;
const unsigned int combinedValue = srcLow | (srcHigh << 8);
const unsigned int b = (combinedValue & 0x1f);
const unsigned int g = ((combinedValue >> 5) & 0x1f);
const unsigned int r = ((combinedValue >> 10) & 0x1f);
const unsigned int xr = (r << 5) | (r >> 2);
const unsigned int xg = (g << 5) | (g >> 2);
const unsigned int xb = (b << 5) | (b >> 2);
ErrorDiffusionWorkPixel wp = ApplyErrorDiffusion(errorDiffusionCurrentRow, xr, xg, xb, col, numCopyCols);
uint8_t colorIndex = stdPalette->MapColorLUT(PortabilityLayer::RGBAColor::Create(wp.m_8[0], wp.m_8[1], wp.m_8[2], 255));
PortabilityLayer::RGBAColor resultColor = stdPalette->GetColors()[colorIndex];
RedistributeError(errorDiffusionNextRow, errorDiffusionCurrentRow, wp.m_16[0], wp.m_16[1], wp.m_16[2], resultColor.r, resultColor.g, resultColor.b, col, numCopyCols);
currentDestRow[destColIndex] = colorIndex;
}
}
}
}
@@ -855,19 +882,38 @@ void DrawSurface::DrawPicture(THandle<BitmapImage> pictHdl, const Rect &bounds)
}
else
{
for (size_t col = 0; col < numCopyCols; col++)
if (!errorDiffusion)
{
const size_t srcColIndex = col + firstSourceCol;
const size_t destColIndex = col + firstDestCol;
for (size_t col = 0; col < numCopyCols; col++)
{
const size_t srcColIndex = col + firstSourceCol;
const size_t destColIndex = col + firstDestCol;
ErrorDiffusionWorkPixel wp = ApplyErrorDiffusion(errorDiffusionCurrentRow, currentSourceRow[srcColIndex * 3 + 2], currentSourceRow[srcColIndex * 3 + 1], currentSourceRow[srcColIndex * 3 + 0], col, numCopyCols);
const uint8_t r = currentSourceRow[srcColIndex * 3 + 2];
const uint8_t g = currentSourceRow[srcColIndex * 3 + 1];
const uint8_t b = currentSourceRow[srcColIndex * 3 + 0];
uint8_t colorIndex = stdPalette->MapColorLUT(PortabilityLayer::RGBAColor::Create(wp.m_8[0], wp.m_8[1], wp.m_8[2], 255));
PortabilityLayer::RGBAColor resultColor = stdPalette->GetColors()[colorIndex];
uint8_t colorIndex = stdPalette->MapColorLUT(PortabilityLayer::RGBAColor::Create(r, g, b, 255));
RedistributeError(errorDiffusionNextRow, errorDiffusionCurrentRow, wp.m_16[0], wp.m_16[1], wp.m_16[2], resultColor.r, resultColor.g, resultColor.b, col, numCopyCols);
currentDestRow[destColIndex] = colorIndex;
}
}
else
{
for (size_t col = 0; col < numCopyCols; col++)
{
const size_t srcColIndex = col + firstSourceCol;
const size_t destColIndex = col + firstDestCol;
currentDestRow[destColIndex] = colorIndex;
ErrorDiffusionWorkPixel wp = ApplyErrorDiffusion(errorDiffusionCurrentRow, currentSourceRow[srcColIndex * 3 + 2], currentSourceRow[srcColIndex * 3 + 1], currentSourceRow[srcColIndex * 3 + 0], col, numCopyCols);
uint8_t colorIndex = stdPalette->MapColorLUT(PortabilityLayer::RGBAColor::Create(wp.m_8[0], wp.m_8[1], wp.m_8[2], 255));
PortabilityLayer::RGBAColor resultColor = stdPalette->GetColors()[colorIndex];
RedistributeError(errorDiffusionNextRow, errorDiffusionCurrentRow, wp.m_16[0], wp.m_16[1], wp.m_16[2], resultColor.r, resultColor.g, resultColor.b, col, numCopyCols);
currentDestRow[destColIndex] = colorIndex;
}
}
}
}

View File

@@ -81,7 +81,7 @@ struct DrawSurface
void DrawStringConstrained(const Point &point, const PLPasStr &str, const Rect &constraintRect, PortabilityLayer::ResolveCachingColor &cacheColor, PortabilityLayer::RenderedFont *font);
void DrawStringWrap(const Point &point, const Rect &constrainRect, const PLPasStr &str, PortabilityLayer::ResolveCachingColor &cacheColor, PortabilityLayer::RenderedFont *font);
void DrawPicture(THandle<BitmapImage> pictHandle, const Rect &rect);
void DrawPicture(THandle<BitmapImage> pictHandle, const Rect &rect, bool errorDiffusion = true);
IGpDisplayDriverSurface *m_ddSurface;