diff --git a/GpApp/Banner.cpp b/GpApp/Banner.cpp index c809fbb..1bafd38 100644 --- a/GpApp/Banner.cpp +++ b/GpApp/Banner.cpp @@ -14,6 +14,7 @@ #include "FontManager.h" #include "MainWindow.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "Room.h" #include "Utilities.h" #include "WindowDef.h" @@ -120,12 +121,15 @@ void DrawBannerMessage (Point topLeft) PasStringCopy((*thisHouse)->banner, bannerStr); workSrcMap->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold); - workSrcMap->SetForeColor(StdColors::Black()); + + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + + count = 0; do { GetLineOfText(bannerStr, count, subStr); - workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 32 + (count * 20)), subStr, true); + workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 32 + (count * 20)), subStr, true, blackColor); count++; } while (subStr[0] > 0); @@ -146,13 +150,12 @@ void DrawBannerMessage (Point topLeft) GetLocalizedString(4, subStr); PasStringConcat(bannerStr, subStr); - workSrcMap->SetForeColor(StdColors::Red()); - workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 164), bannerStr, true); + PortabilityLayer::ResolveCachingColor redColor = StdColors::Red(); + workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 164), bannerStr, true, redColor); GetLocalizedString(5, subStr); - workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 180), subStr, true); + workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 180), subStr, true, redColor); } - workSrcMap->SetForeColor(StdColors::Black()); SetGraphicsPort(wasGWorld); } diff --git a/GpApp/ColorUtils.cpp b/GpApp/ColorUtils.cpp index abc8bac..f25ed40 100644 --- a/GpApp/ColorUtils.cpp +++ b/GpApp/ColorUtils.cpp @@ -10,6 +10,7 @@ #include "PLPalettes.h" #include "PLPasStr.h" #include "QDStandardPalette.h" +#include "ResolveCachingColor.h" //============================================================== Functions @@ -21,12 +22,9 @@ void ColorText (DrawSurface *surface, const Point &point, StringPtr theStr, long color) { - const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]; + PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color); - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(rgbaColor); - surface->DrawString(point, theStr, true); - surface->SetForeColor(wasColor); + surface->DrawString(point, theStr, true, rColor); } //-------------------------------------------------------------- ColorRect @@ -36,12 +34,9 @@ void ColorText (DrawSurface *surface, const Point &point, StringPtr theStr, long void ColorRect (DrawSurface *surface, const Rect &theRect, long color) { - const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]; + PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color); - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(rgbaColor); - surface->FillRect(theRect); - surface->SetForeColor(wasColor); + surface->FillRect(theRect, rColor); } //-------------------------------------------------------------- ColorOval @@ -51,22 +46,16 @@ void ColorRect (DrawSurface *surface, const Rect &theRect, long color) void ColorOval (DrawSurface *surface, const Rect &theRect, long color) { - const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]; + PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color); - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(rgbaColor); - surface->FillEllipse(theRect); - surface->SetForeColor(wasColor); + surface->FillEllipse(theRect, rColor); } void ColorOvalMaskPattern(DrawSurface *surface, const Rect &theRect, long color, const uint8_t *pattern) { - const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]; + PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color); - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(rgbaColor); - surface->FillEllipseWithMaskPattern(theRect, pattern); - surface->SetForeColor(wasColor); + surface->FillEllipseWithMaskPattern(theRect, pattern, rColor); } //-------------------------------------------------------------- ColorRegionMaskPattern @@ -76,12 +65,8 @@ void ColorOvalMaskPattern(DrawSurface *surface, const Rect &theRect, long color, void ColorRegionMaskPattern (DrawSurface *surface, PortabilityLayer::ScanlineMask *scanlineMask, long colorIndex, const uint8_t *pattern) { - const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[colorIndex]; - - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(rgbaColor); - surface->FillScanlineMaskWithMaskPattern(scanlineMask, pattern); - surface->SetForeColor(wasColor); + PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(colorIndex); + surface->FillScanlineMaskWithMaskPattern(scanlineMask, pattern, rColor); } //-------------------------------------------------------------- ColorLine @@ -91,12 +76,9 @@ void ColorRegionMaskPattern (DrawSurface *surface, PortabilityLayer::ScanlineMas void ColorLine (DrawSurface *surface, short h0, short v0, short h1, short v1, long color) { - const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]; + PortabilityLayer::ResolveCachingColor cacheColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color); - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(rgbaColor); - surface->DrawLine(Point::Create(h0, v0), Point::Create(h1, v1)); - surface->SetForeColor(wasColor); + surface->DrawLine(Point::Create(h0, v0), Point::Create(h1, v1), cacheColor); } //-------------------------------------------------------------- HiliteRect @@ -125,12 +107,9 @@ void HiliteRect (DrawSurface *surface, const Rect &theRect, short color1, short void ColorFrameRect (DrawSurface *surface, const Rect &theRect, long color) { - const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]; + PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color); - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(rgbaColor); - surface->FrameRect(theRect); - surface->SetForeColor(wasColor); + surface->FrameRect(theRect, rColor); } //-------------------------------------------------------------- ColorFrameWHRect @@ -157,12 +136,9 @@ void ColorFrameWHRect (DrawSurface *surface, short left, short top, short wide, void ColorFrameOval (DrawSurface *surface, const Rect &theRect, long color) { - const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]; + PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color); - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(rgbaColor); - surface->FrameEllipse(theRect); - surface->SetForeColor(wasColor); + surface->FrameEllipse(theRect, rColor); } //-------------------------------------------------------------- LtGrayForeColor @@ -170,9 +146,9 @@ void ColorFrameOval (DrawSurface *surface, const Rect &theRect, long color) // This function finds the closest match to a "light gray" in theÉ // current palette and sets the pen color to that. -void LtGrayForeColor (DrawSurface *surface) +PortabilityLayer::ResolveCachingColor LtGrayForeColor () { - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(191, 191, 191, 255)); + return PortabilityLayer::RGBAColor::Create(191, 191, 191, 255); } //-------------------------------------------------------------- GrayForeColor @@ -180,9 +156,9 @@ void LtGrayForeColor (DrawSurface *surface) // This function finds the closest match to a "medium gray" in theÉ // current palette and sets the pen color to that. -void GrayForeColor (DrawSurface *surface) +PortabilityLayer::ResolveCachingColor GrayForeColor () { - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(127, 127, 127, 255)); + return PortabilityLayer::RGBAColor::Create(127, 127, 127, 255); } //-------------------------------------------------------------- DkGrayForeColor @@ -190,7 +166,7 @@ void GrayForeColor (DrawSurface *surface) // This function finds the closest match to a "dark gray" in theÉ // current palette and sets the pen color to that. -void DkGrayForeColor (DrawSurface *surface) +PortabilityLayer::ResolveCachingColor DkGrayForeColor () { - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(63, 63, 63, 255)); + return PortabilityLayer::RGBAColor::Create(63, 63, 63, 255); } diff --git a/GpApp/Coordinates.cpp b/GpApp/Coordinates.cpp index 6885dde..53ccd1d 100644 --- a/GpApp/Coordinates.cpp +++ b/GpApp/Coordinates.cpp @@ -13,6 +13,7 @@ #include "Marquee.h" #include "ObjectEdit.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "WindowDef.h" #include "WindowManager.h" @@ -70,12 +71,14 @@ void UpdateCoordWindow (void) if (coordWindow == nil) return; + + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + PortabilityLayer::ResolveCachingColor blueColor = StdColors::Blue(); + DrawSurface *surface = coordWindow->GetDrawSurface(); - surface->SetForeColor(StdColors::White()); - surface->FillRect(coordWindowRect); - - surface->SetForeColor(StdColors::Black()); + surface->FillRect(coordWindowRect, whiteColor); PasStringCopy(PSTR("h: "), tempStr); if (coordH != -1) @@ -86,7 +89,7 @@ void UpdateCoordWindow (void) else PasStringConcat(tempStr, PSTR("-")); - surface->DrawString(Point::Create(5, 12), tempStr, true); + surface->DrawString(Point::Create(5, 12), tempStr, true, blackColor); PasStringCopy(PSTR("v: "), tempStr); if (coordV != -1) @@ -97,9 +100,8 @@ void UpdateCoordWindow (void) else PasStringConcat(tempStr, PSTR("-")); - surface->DrawString(Point::Create(4, 22), tempStr, true); + surface->DrawString(Point::Create(4, 22), tempStr, true, blackColor); - surface->SetForeColor(StdColors::Blue()); PasStringCopy(PSTR("d: "), tempStr); if (coordD != -1) { @@ -109,8 +111,7 @@ void UpdateCoordWindow (void) else PasStringConcat(tempStr, PSTR("-")); - surface->DrawString(Point::Create(5, 32), tempStr, true); - surface->SetForeColor(StdColors::Black()); + surface->DrawString(Point::Create(5, 32), tempStr, true, blueColor); #endif } diff --git a/GpApp/DialogUtils.cpp b/GpApp/DialogUtils.cpp index 86edd44..da02e2f 100644 --- a/GpApp/DialogUtils.cpp +++ b/GpApp/DialogUtils.cpp @@ -17,6 +17,7 @@ #include "Externs.h" #include "FontFamily.h" #include "ResourceManager.h" +#include "ResolveCachingColor.h" #include @@ -581,8 +582,8 @@ void DrawDialogUserText (Dialog *dial, short item, StringPtr text, Boolean inver if ((surface->MeasureString(stringCopy) + 2) > (iRect.right - iRect.left)) CollapseStringToWidth(surface, stringCopy, iRect.right - iRect.left - 2); - surface->SetForeColor(StdColors::White()); - surface->FillRect(iRect); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(iRect, whiteColor); short strWidth = surface->MeasureString(stringCopy); inset = ((iRect.right - iRect.left) - (strWidth + 2)) / 2; @@ -593,24 +594,24 @@ void DrawDialogUserText (Dialog *dial, short item, StringPtr text, Boolean inver const int32_t ascender = surface->MeasureFontAscender(); + PortabilityLayer::ResolveCachingColor backgroundColor; + PortabilityLayer::ResolveCachingColor textColor; + if (invert) { - surface->SetForeColor(StdColors::Black()); - surface->FillRect(iRect); - surface->SetForeColor(StdColors::White()); + backgroundColor = StdColors::Black(); + textColor = StdColors::White(); } else { - surface->SetForeColor(StdColors::White()); - surface->FillRect(iRect); - surface->SetForeColor(StdColors::Black()); + backgroundColor = StdColors::White(); + textColor = StdColors::Black(); } - const Point centeredDrawPoint = Point::Create((iRect.left + iRect.right - strWidth) / 2, (iRect.top + iRect.bottom + ascender) / 2); - surface->DrawString(centeredDrawPoint, stringCopy, true); + surface->FillRect(iRect, backgroundColor); - if (invert) - surface->SetForeColor(StdColors::Black()); + const Point centeredDrawPoint = Point::Create((iRect.left + iRect.right - strWidth) / 2, (iRect.top + iRect.bottom + ascender) / 2); + surface->DrawString(centeredDrawPoint, stringCopy, true, textColor); } //-------------------------------------------------------------- DrawDialogUserText @@ -633,8 +634,8 @@ void DrawDialogUserText2 (Dialog *dial, short item, StringPtr text) if ((surface->MeasureString(stringCopy) + 2) > (iRect.right - iRect.left)) CollapseStringToWidth(surface, stringCopy, iRect.right - iRect.left - 2); - surface->SetForeColor(StdColors::Black()); - surface->DrawString(Point::Create(iRect.left, iRect.bottom), stringCopy, true); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + surface->DrawString(Point::Create(iRect.left, iRect.bottom), stringCopy, true, blackColor); } //-------------------------------------------------------------- LoadDialogPICT @@ -655,14 +656,14 @@ void LoadDialogPICT (Dialog *theDialog, short item, short theID) //-------------------------------------------------------------- FrameDialogItem // Given a dialog item, this function draws a box around it. -void FrameDialogItem (Dialog *theDialog, short item) +void FrameDialogItem (Dialog *theDialog, short item, PortabilityLayer::ResolveCachingColor &color) { const PortabilityLayer::DialogItem &itemRef = theDialog->GetItems()[item - 1]; PortabilityLayer::Widget *widget = itemRef.GetWidget(); const Rect itemRect = widget->GetRect(); - theDialog->GetWindow()->GetDrawSurface()->FrameRect(itemRect); + theDialog->GetWindow()->GetDrawSurface()->FrameRect(itemRect, color); } //-------------------------------------------------------------- FrameDialogItemC @@ -673,23 +674,22 @@ void FrameDialogItemC (Dialog *theDialog, short item, long color) DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface(); const Rect itemRect = theDialog->GetItems()[item - 1].GetWidget()->GetRect(); - const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor(); - surface->SetForeColor(PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color]); - surface->FrameRect(itemRect); - surface->SetForeColor(wasColor); + PortabilityLayer::ResolveCachingColor frameColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color); + + surface->FrameRect(itemRect, frameColor); } //-------------------------------------------------------------- FrameOvalDialogItem // Given a dialog item, this function draws an oval around it. -void FrameOvalDialogItem (Dialog *theDialog, short item) +void FrameOvalDialogItem (Dialog *theDialog, short item, PortabilityLayer::ResolveCachingColor &color) { const PortabilityLayer::DialogItem &itemRef = theDialog->GetItems()[item - 1]; PortabilityLayer::Widget *widget = itemRef.GetWidget(); const Rect itemRect = widget->GetRect(); - theDialog->GetWindow()->GetDrawSurface()->FrameEllipse(itemRect); + theDialog->GetWindow()->GetDrawSurface()->FrameEllipse(itemRect, color); } //-------------------------------------------------------------- BorderDialogItem @@ -703,6 +703,9 @@ void BorderDialogItem(Dialog *theDialog, short item, short sides, short thicknes // 4 = bottom // 8 = right ... so 6 = top & bottom, 15 = all 4 sides + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + const PortabilityLayer::DialogItem &itemRef = theDialog->GetItems()[item - 1]; PortabilityLayer::Widget *widget = itemRef.GetWidget(); const Rect itemRect = widget->GetRect(); @@ -716,13 +719,11 @@ void BorderDialogItem(Dialog *theDialog, short item, short sides, short thicknes const Rect rect = Rect::Create(pointA.v, pointA.h, pointB.v, pointB.h); if (pattern) { - surface->SetForeColor(StdColors::White()); - surface->FillRect(rect); - surface->SetForeColor(StdColors::Black()); - surface->FillRectWithMaskPattern8x8(rect, pattern); + surface->FillRect(rect, whiteColor); + surface->FillRectWithMaskPattern8x8(rect, pattern,blackColor); } else - surface->FillRect(rect); + surface->FillRect(rect, blackColor); sides -= 8; } if (sides >= 4) // 4 = bottom @@ -732,13 +733,11 @@ void BorderDialogItem(Dialog *theDialog, short item, short sides, short thicknes const Rect rect = Rect::Create(pointA.v, pointA.h, pointB.v, pointB.h); if (pattern) { - surface->SetForeColor(StdColors::White()); - surface->FillRect(rect); - surface->SetForeColor(StdColors::Black()); - surface->FillRectWithMaskPattern8x8(rect, pattern); + surface->FillRect(rect, whiteColor); + surface->FillRectWithMaskPattern8x8(rect, pattern, blackColor); } else - surface->FillRect(rect); + surface->FillRect(rect, blackColor); sides -= 4; } if (sides >= 2) // 2 = top @@ -748,13 +747,11 @@ void BorderDialogItem(Dialog *theDialog, short item, short sides, short thicknes const Rect rect = Rect::Create(pointA.v, pointA.h, pointB.v, pointB.h); if (pattern) { - surface->SetForeColor(StdColors::White()); - surface->FillRect(rect); - surface->SetForeColor(StdColors::Black()); - surface->FillRectWithMaskPattern8x8(rect, pattern); + surface->FillRect(rect, whiteColor); + surface->FillRectWithMaskPattern8x8(rect, pattern, blackColor); } else - surface->FillRect(rect); + surface->FillRect(rect, blackColor); sides -= 2; } if (sides >= 1) // 1 = left @@ -764,13 +761,11 @@ void BorderDialogItem(Dialog *theDialog, short item, short sides, short thicknes const Rect rect = Rect::Create(pointA.v, pointA.h, pointB.v, pointB.h); if (pattern) { - surface->SetForeColor(StdColors::White()); - surface->FillRect(rect); - surface->SetForeColor(StdColors::Black()); - surface->FillRectWithMaskPattern8x8(rect, pattern); + surface->FillRect(rect, whiteColor); + surface->FillRectWithMaskPattern8x8(rect, pattern, blackColor); } else - surface->FillRect(rect); + surface->FillRect(rect, blackColor); } } @@ -784,13 +779,14 @@ void ShadowDialogItem (Dialog *theDialog, short item, short thickness) const PortabilityLayer::DialogItem &itemRef = theDialog->GetItems()[item - 1]; const Rect itemRect = itemRef.GetWidget()->GetRect(); - surface->SetForeColor(StdColors::Black()); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + const Point bottomLeftCorner = Point::Create(itemRect.left + thickness, itemRect.bottom); const Point topRightCorner = Point::Create(itemRect.right, itemRect.top + thickness); const Point bottomRightCorner = Point::Create(itemRect.right + thickness, itemRect.bottom + thickness); - surface->FillRect(Rect::Create(topRightCorner.v, topRightCorner.h, bottomRightCorner.v, bottomRightCorner.h)); - surface->FillRect(Rect::Create(bottomLeftCorner.v, bottomLeftCorner.h, bottomRightCorner.v, bottomRightCorner.h)); + surface->FillRect(Rect::Create(topRightCorner.v, topRightCorner.h, bottomRightCorner.v, bottomRightCorner.h), blackColor); + surface->FillRect(Rect::Create(bottomLeftCorner.v, bottomLeftCorner.h, bottomRightCorner.v, bottomRightCorner.h), blackColor); } //-------------------------------------------------------------- EraseDialogItem @@ -803,9 +799,9 @@ void EraseDialogItem (Dialog *theDialog, short item) const Rect itemRect = widget->GetRect(); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface(); - surface->SetForeColor(StdColors::White()); - surface->FillRect(itemRect); - surface->SetForeColor(StdColors::Black()); + surface->FillRect(itemRect, whiteColor); } diff --git a/GpApp/DialogUtils.h b/GpApp/DialogUtils.h index cde738a..9ba3b37 100644 --- a/GpApp/DialogUtils.h +++ b/GpApp/DialogUtils.h @@ -7,6 +7,11 @@ #include "PLDialogs.h" +namespace PortabilityLayer +{ + class ResolveCachingColor; +} + struct DialogTextSubstitutions; void BringUpDialog (Dialog **theDialog, short dialogID, const DialogTextSubstitutions *); @@ -40,9 +45,9 @@ void MyDisableControl(Dialog *, short); void DrawDialogUserText (Dialog *, short, StringPtr, Boolean); void DrawDialogUserText2 (Dialog *, short, StringPtr); void LoadDialogPICT (Dialog *, short, short); -void FrameDialogItem (Dialog *, short); +void FrameDialogItem (Dialog *, short, PortabilityLayer::ResolveCachingColor &color); void FrameDialogItemC (Dialog *, short, long); -void FrameOvalDialogItem (Dialog *, short); +void FrameOvalDialogItem (Dialog *, short, PortabilityLayer::ResolveCachingColor &color); void BorderDialogItem (Dialog *theDialog, short item, short sides, short thickness, const uint8_t *pattern); void ShadowDialogItem (Dialog *, short, short); void EraseDialogItem (Dialog *, short); diff --git a/GpApp/Dynamics.cpp b/GpApp/Dynamics.cpp index 4d6b258..ecb6416 100644 --- a/GpApp/Dynamics.cpp +++ b/GpApp/Dynamics.cpp @@ -11,8 +11,10 @@ #include "MainWindow.h" #include "Objects.h" #include "PLHacks.h" +#include "PLStandardColors.h" #include "RectUtils.h" #include "Room.h" +#include "ResolveCachingColor.h" #define kShoveVelocity 8 @@ -578,7 +580,8 @@ void HandleOutlet (short who) } else { - workSrcMap->FillRect(dinahs[who].dest); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + workSrcMap->FillRect(dinahs[who].dest, blackColor); } AddRectToWorkRects(&dinahs[who].dest); } diff --git a/GpApp/Externs.h b/GpApp/Externs.h index 0e1128f..34df2cb 100644 --- a/GpApp/Externs.h +++ b/GpApp/Externs.h @@ -13,6 +13,7 @@ namespace PortabilityLayer { + class ResolveCachingColor; class ResourceArchive; class ScanlineMask; class ResTypeID; @@ -143,10 +144,9 @@ void HiliteRect (DrawSurface *surface, const Rect &rect, short, short); void ColorFrameRect (DrawSurface *surface, const Rect &theRect, long colorIndex); void ColorFrameWHRect (DrawSurface *surface, short, short, short, short, long); void ColorFrameOval (DrawSurface *surface, const Rect &, long); -void LtGrayForeColor (DrawSurface *surface); -void GrayForeColor (DrawSurface *surface); -void DkGrayForeColor (DrawSurface *surface); -void RestoreColorsSlam (DrawSurface *surface); +PortabilityLayer::ResolveCachingColor LtGrayForeColor (); +PortabilityLayer::ResolveCachingColor GrayForeColor (); +PortabilityLayer::ResolveCachingColor DkGrayForeColor (); void MonitorWait (void); // --- DebugUtils.c void DisplayRect (Rect *); diff --git a/GpApp/GameOver.cpp b/GpApp/GameOver.cpp index 1e5c30a..743b3c5 100644 --- a/GpApp/GameOver.cpp +++ b/GpApp/GameOver.cpp @@ -17,7 +17,9 @@ #include "InputManager.h" #include "MainWindow.h" #include "Objects.h" +#include "PLStandardColors.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "Utilities.h" @@ -87,6 +89,9 @@ void SetUpFinalScreen (void) short count, offset, i, textDown; char wasState; DrawSurface *surface = workSrcMap; + + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); ColorRect(surface, workSrcRect, 244); QSetRect(&tempRect, 0, 0, 640, 460); @@ -107,14 +112,12 @@ void SetUpFinalScreen (void) offset = ((thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) - surface->MeasureString(subStr)) / 2; - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); const Point textShadowPos = Point::Create(offset + 1, textDown + 33 + (count * 20)); - surface->DrawString(textShadowPos, subStr, true); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)); + surface->DrawString(textShadowPos, subStr, true, blackColor); const Point textPos = Point::Create(offset, textDown + 32 + (count * 20)); - surface->DrawString(textPos, subStr, true); + surface->DrawString(textPos, subStr, true, whiteColor); count++; } while (subStr[0] > 0); diff --git a/GpApp/Grease.cpp b/GpApp/Grease.cpp index 8cdeba1..3eacc01 100644 --- a/GpApp/Grease.cpp +++ b/GpApp/Grease.cpp @@ -10,7 +10,9 @@ #include "Environ.h" #include "MainWindow.h" #include "Objects.h" +#include "PLStandardColors.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "Room.h" @@ -102,9 +104,11 @@ void HandleGrease (void) } { - backSrcMap->FillRect(src); - - workSrcMap->FillRect(src); + PortabilityLayer::ResolveCachingColor blackColorBack = StdColors::Black(); + backSrcMap->FillRect(src, blackColorBack); + + PortabilityLayer::ResolveCachingColor blackColorWork = StdColors::Black(); + workSrcMap->FillRect(src, blackColorWork); AddRectToWorkRects(&src); } @@ -282,13 +286,16 @@ void RedrawAllGrease (void) if ((grease[i].where == thisRoomNumber) && ((src.bottom - src.top) == 2)) { + PortabilityLayer::ResolveCachingColor blackColorBack = StdColors::Black(); + PortabilityLayer::ResolveCachingColor blackColorWork = StdColors::Black(); + QOffsetRect(&src, playOriginH, playOriginV); wasCPort = GetGraphicsPort(); - backSrcMap->FillRect(src); + backSrcMap->FillRect(src, blackColorBack); - workSrcMap->FillRect(src); + workSrcMap->FillRect(src, blackColorWork); AddRectToWorkRects(&src); SetGraphicsPort(wasCPort); diff --git a/GpApp/HighScores.cpp b/GpApp/HighScores.cpp index 1971bb5..c80bde4 100644 --- a/GpApp/HighScores.cpp +++ b/GpApp/HighScores.cpp @@ -22,9 +22,10 @@ #include "House.h" #include "IOStream.h" #include "MainWindow.h" -#include "RectUtils.h" #include "PLStandardColors.h" #include "PLTimeTaggedVOSEvent.h" +#include "RectUtils.h" +#include "ResolveCachingColor.h" #include "Utilities.h" #include "WindowManager.h" @@ -69,11 +70,11 @@ extern Boolean quickerTransitions, resumedSavedGame; void DoHighScores (void) { Rect tempRect; + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); SpinCursor(3); SetPort(workSrcMap); - workSrcMap->SetForeColor(StdColors::Black()); - workSrcMap->FillRect(workSrcRect); + workSrcMap->FillRect(workSrcRect, blackColor); QSetRect(&tempRect, 0, 0, 640, 480); QOffsetRect(&tempRect, splashOriginH, splashOriginV); LoadScaledGraphic(workSrcMap, kStarPictID, &tempRect); @@ -120,11 +121,11 @@ void DrawHighScores (DrawSurface *surface) Str255 tempStr; short scoreLeft, bannerWidth, i, dropIt; char wasState; - PortabilityLayer::RGBAColor blackColor = PortabilityLayer::RGBAColor::Create(0, 0, 0, 255); - PortabilityLayer::RGBAColor yellowColor = PortabilityLayer::RGBAColor::Create(255, 255, 0, 255); - PortabilityLayer::RGBAColor cyanColor = PortabilityLayer::RGBAColor::Create(0, 255, 255, 255); - PortabilityLayer::RGBAColor whiteColor = PortabilityLayer::RGBAColor::Create(255, 255, 255, 255); - PortabilityLayer::RGBAColor blueColor = PortabilityLayer::RGBAColor::Create(0, 0, 255, 255); + PortabilityLayer::ResolveCachingColor blackColor = PortabilityLayer::RGBAColor::Create(0, 0, 0, 255); + PortabilityLayer::ResolveCachingColor yellowColor = PortabilityLayer::RGBAColor::Create(255, 255, 0, 255); + PortabilityLayer::ResolveCachingColor cyanColor = PortabilityLayer::RGBAColor::Create(0, 255, 255, 255); + PortabilityLayer::ResolveCachingColor whiteColor = PortabilityLayer::RGBAColor::Create(255, 255, 255, 255); + PortabilityLayer::ResolveCachingColor blueColor = PortabilityLayer::RGBAColor::Create(0, 0, 255, 255); scoreLeft = ((thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) - kScoreWide) / 2; dropIt = 129 + splashOriginV; @@ -154,12 +155,10 @@ void DrawHighScores (DrawSurface *surface) PasStringConcat(tempStr, PSTR(" ¥")); const Point scoreShadowPoint = Point::Create(scoreLeft + ((kScoreWide - surface->MeasureString(tempStr)) / 2) - 1, dropIt - 66); - surface->SetForeColor(blackColor); - surface->DrawString(scoreShadowPoint, tempStr, true); + surface->DrawString(scoreShadowPoint, tempStr, true, blackColor); const Point scoreTextPoint = Point::Create(scoreLeft + ((kScoreWide - surface->MeasureString(tempStr)) / 2), dropIt - 65); - surface->SetForeColor(cyanColor); - surface->DrawString(scoreTextPoint, tempStr, true); + surface->DrawString(scoreTextPoint, tempStr, true, cyanColor); surface->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold); @@ -167,23 +166,19 @@ void DrawHighScores (DrawSurface *surface) // message for score #1 PasStringCopy(thisHousePtr->highScores.banner, tempStr); bannerWidth = surface->MeasureString(tempStr); - surface->SetForeColor(blackColor); const Point topScoreShadowPoint = Point::Create(scoreLeft + (kScoreWide - bannerWidth) / 2, dropIt - kKimsLifted); - surface->DrawString(topScoreShadowPoint, tempStr, true); + surface->DrawString(topScoreShadowPoint, tempStr, true, blackColor); - surface->SetForeColor(yellowColor); const Point topScoreTextPoint = Point::Create(scoreLeft + (kScoreWide - bannerWidth) / 2, dropIt - kKimsLifted - 1); - surface->DrawString(topScoreTextPoint, tempStr, true); + surface->DrawString(topScoreTextPoint, tempStr, true, yellowColor); QSetRect(&tempRect, 0, 0, bannerWidth + 8, kScoreSpacing); QOffsetRect(&tempRect, scoreLeft - 3 + (kScoreWide - bannerWidth) / 2, dropIt + 5 - kScoreSpacing - kKimsLifted); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); - surface->FrameRect(tempRect); + surface->FrameRect(tempRect, blackColor); QOffsetRect(&tempRect, -1, -1); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 0, 255)); - surface->FrameRect(tempRect); + surface->FrameRect(tempRect, yellowColor); for (i = 0; i < kMaxScores; i++) { @@ -193,101 +188,90 @@ void DrawHighScores (DrawSurface *surface) SpinCursor(1); NumToString((long)i + 1L, tempStr); // draw placing number - surface->SetForeColor(blackColor); if (i == 0) strPos = Point::Create(scoreLeft + 1, dropIt - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 1, dropIt + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); - if (i == lastHighScore) - surface->SetForeColor(whiteColor); - else - surface->SetForeColor(cyanColor); + surface->DrawString(strPos, tempStr, true, blackColor); + + PortabilityLayer::ResolveCachingColor *scoreColor = (i == lastHighScore) ? &whiteColor : &cyanColor; + if (i == 0) strPos = Point::Create(scoreLeft + 0, dropIt - 1 - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 0, dropIt - 1 + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); + surface->DrawString(strPos, tempStr, true, *scoreColor); // draw high score name PasStringCopy(thisHousePtr->highScores.names[i], tempStr); - surface->SetForeColor(blackColor); + if (i == 0) strPos = Point::Create(scoreLeft + 31, dropIt - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 31, dropIt + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); - if (i == lastHighScore) - surface->SetForeColor(whiteColor); - else - surface->SetForeColor(yellowColor); + surface->DrawString(strPos, tempStr, true, blackColor); + + + PortabilityLayer::ResolveCachingColor *nameColor = (i == lastHighScore) ? &whiteColor : &yellowColor; + if (i == 0) strPos = Point::Create(scoreLeft + 30, dropIt - 1 - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 30, dropIt - 1 + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); + surface->DrawString(strPos, tempStr, true, *nameColor); // draw level number NumToString(thisHousePtr->highScores.levels[i], tempStr); - surface->SetForeColor(blackColor); + if (i == 0) strPos = Point::Create(scoreLeft + 161, dropIt - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 161, dropIt + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); - if (i == lastHighScore) - surface->SetForeColor(whiteColor); - else - surface->SetForeColor(yellowColor); + surface->DrawString(strPos, tempStr, true, blackColor); + + PortabilityLayer::ResolveCachingColor *levelColor = (i == lastHighScore) ? &whiteColor : &yellowColor; if (i == 0) strPos = Point::Create(scoreLeft + 160, dropIt - 1 - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 160, dropIt - 1 + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); + surface->DrawString(strPos, tempStr, true, *levelColor); // draw word "rooms" if (thisHousePtr->highScores.levels[i] == 1) GetLocalizedString(6, tempStr); else GetLocalizedString(7, tempStr); - surface->SetForeColor(blackColor); + if (i == 0) strPos = Point::Create(scoreLeft + 193, dropIt - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 193, dropIt + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); - surface->SetForeColor(cyanColor); + surface->DrawString(strPos, tempStr, true, blackColor); if (i == 0) strPos = Point::Create(scoreLeft + 192, dropIt - 1 - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 192, dropIt - 1 + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); + surface->DrawString(strPos, tempStr, true, cyanColor); // draw high score points NumToString(thisHousePtr->highScores.scores[i], tempStr); - surface->SetForeColor(blackColor); if (i == 0) strPos = Point::Create(scoreLeft + 291, dropIt - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 291, dropIt + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); - if (i == lastHighScore) - surface->SetForeColor(whiteColor); - else - surface->SetForeColor(yellowColor); + surface->DrawString(strPos, tempStr, true, blackColor); + + PortabilityLayer::ResolveCachingColor *pointsColor = (i == lastHighScore) ? &whiteColor : &yellowColor; + if (i == 0) strPos = Point::Create(scoreLeft + 290, dropIt - 1 - kScoreSpacing - kKimsLifted); else strPos = Point::Create(scoreLeft + 290, dropIt - 1 + (i * kScoreSpacing)); - surface->DrawString(strPos, tempStr, true); + surface->DrawString(strPos, tempStr, true, *pointsColor); } } - surface->SetForeColor(blueColor); - surface->SetApplicationFont(9, PortabilityLayer::FontFamilyFlag_Bold); const Point textPos = Point::Create(scoreLeft + 80, dropIt - 1 + (10 * kScoreSpacing)); GetLocalizedString(8, tempStr); - surface->DrawString(textPos, tempStr, true); - - surface->SetForeColor(blackColor); + surface->DrawString(textPos, tempStr, true, blueColor); } //-------------------------------------------------------------- SortHighScores diff --git a/GpApp/MainWindow.cpp b/GpApp/MainWindow.cpp index a6044e5..baa0423 100644 --- a/GpApp/MainWindow.cpp +++ b/GpApp/MainWindow.cpp @@ -20,6 +20,7 @@ #include "RectUtils.h" #include "PLKeyEncoding.h" #include "PLStandardColors.h" +#include "ResolveCachingColor.h" #include "WindowDef.h" #include "WindowManager.h" @@ -74,8 +75,8 @@ void DrawOnSplash(DrawSurface *surface) const Point textPoint = Point::Create(splashOriginH + 436, splashOriginV + 314); if (thisMac.isDepth == 4) { - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)); - surface->DrawString(textPoint, houseLoadedStr, true); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->DrawString(textPoint, houseLoadedStr, true, whiteColor); } else { @@ -106,8 +107,8 @@ void RedrawSplashScreen (void) Rect tempRect; DrawSurface *surface = workSrcMap; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(workSrcRect); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRect(workSrcRect, blackColor); QSetRect(&tempRect, 0, 0, 640, 460); QOffsetRect(&tempRect, splashOriginH, splashOriginV); @@ -150,7 +151,9 @@ void UpdateMainWindow (void) } else if ((theMode == kSplashMode) || (theMode == kPlayMode)) { - workSrcMap->FillRect(workSrcRect); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + workSrcMap->FillRect(workSrcRect, blackColor); + QSetRect(&tempRect, 0, 0, 640, 460); QOffsetRect(&tempRect, splashOriginH, splashOriginV); LoadScaledGraphic(workSrcMap, kSplash8BitPICT, &tempRect); @@ -174,7 +177,9 @@ void OpenMainWindow (void) { // long wasSeed; short whichRoom; - + + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + if (mainWindow != nil) { YellowAlert(kYellowUnaccounted, 6); @@ -201,7 +206,6 @@ void OpenMainWindow (void) DrawSurface *mainWindowSurface = mainWindow->GetDrawSurface(); mainWindowSurface->SetClipRect(mainWindowRect); - mainWindowSurface->SetForeColor(StdColors::Black()); whichRoom = GetFirstRoomNumber(); CopyRoomToThisRoom(whichRoom); @@ -250,8 +254,8 @@ void OpenMainWindow (void) mainWindowSurface->SetClipRect(mainWindowRect); // CopyRgn(mainWindow->clipRgn, mainWindow->visRgn); - mainWindowSurface->SetForeColor(StdColors::Black()); - mainWindowSurface->FillRect(mainWindowRect); + + mainWindowSurface->FillRect(mainWindowRect, blackColor); splashOriginH = ((thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) - 640) / 2; if (splashOriginH < 0) @@ -260,7 +264,7 @@ void OpenMainWindow (void) if (splashOriginV < 0) splashOriginV = 0; - workSrcMap->FillRect(workSrcRect); + workSrcMap->FillRect(workSrcRect, blackColor); // if ((fadeGraysOut) && (isDoColorFade)) // { diff --git a/GpApp/Map.cpp b/GpApp/Map.cpp index f07dad4..feb7271 100644 --- a/GpApp/Map.cpp +++ b/GpApp/Map.cpp @@ -19,6 +19,7 @@ #include "WindowManager.h" #include "QDPixMap.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "Utilities.h" @@ -227,7 +228,6 @@ void RedrawMapContents (void) type = kNumBackgrounds; // Draw "?" thumbnail. } - surface->SetForeColor(StdColors::Black()); if (type > kNumBackgrounds) // Do a "pretty" thumbnail. { LoadGraphicPlus(surface, type + kBaseBackgroundID, aRoom); @@ -249,45 +249,46 @@ void RedrawMapContents (void) } else { - surface->SetForeColor(StdColors::White()); - surface->FillRect(aRoom); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(aRoom, whiteColor); + PortabilityLayer::ResolveCachingColor overlayColor; if (i >= groundLevel) - surface->SetForeColor(StdColors::Green()); + overlayColor = StdColors::Green(); else - surface->SetForeColor(StdColors::Blue()); + overlayColor = StdColors::Blue(); Pattern dummyPat; - surface->FillRectWithMaskPattern8x8(aRoom, *GetQDGlobalsGray(&dummyPat)); + surface->FillRectWithMaskPattern8x8(aRoom, *GetQDGlobalsGray(&dummyPat), overlayColor); } } } - surface->SetForeColor(StdColors::Black()); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); for (i = 1; i < mapRoomsWide; i++) { const Point upperPoint = Point::Create(i * kMapRoomWidth, 0); const Point lowerPoint = Point::Create(upperPoint.h, upperPoint.v + mapRoomsHigh * kMapRoomHeight); - surface->DrawLine(upperPoint, lowerPoint); + surface->DrawLine(upperPoint, lowerPoint, blackColor); } for (i = 1; i < mapRoomsHigh; i++) { const Point leftPoint = Point::Create(0, i * kMapRoomHeight); const Point rightPoint = leftPoint + Point::Create(mapRoomsWide * kMapRoomWidth, 0); - surface->DrawLine(leftPoint, rightPoint); + surface->DrawLine(leftPoint, rightPoint, blackColor); } if (activeRoomVisible) { - surface->SetForeColor(StdColors::Red()); + PortabilityLayer::ResolveCachingColor redColor = StdColors::Red(); + activeRoomRect.right++; activeRoomRect.bottom++; - surface->FrameRect(activeRoomRect); + surface->FrameRect(activeRoomRect, redColor); InsetRect(&activeRoomRect, 1, 1); - surface->FrameRect(activeRoomRect); - surface->SetForeColor(StdColors::Black()); + surface->FrameRect(activeRoomRect, redColor); InsetRect(&activeRoomRect, -1, -1); } @@ -304,18 +305,18 @@ void DrawMapResizeBox(void) const Rect windowRect = surface->m_port.GetRect(); Rect growBoxRect = Rect::Create(windowRect.bottom - 14, windowRect.right - 14, windowRect.bottom, windowRect.right); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(204, 204, 204, 255)); - surface->FillRect(growBoxRect); + PortabilityLayer::ResolveCachingColor backgroundColor = PortabilityLayer::RGBAColor::Create(204, 204, 204, 255); + surface->FillRect(growBoxRect, backgroundColor); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(growBoxRect.top + 2, growBoxRect.left + 2, growBoxRect.top + 3, growBoxRect.left + 6)); - surface->FillRect(Rect::Create(growBoxRect.top + 3, growBoxRect.left + 2, growBoxRect.top + 6, growBoxRect.left + 3)); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRect(Rect::Create(growBoxRect.top + 2, growBoxRect.left + 2, growBoxRect.top + 3, growBoxRect.left + 6), blackColor); + surface->FillRect(Rect::Create(growBoxRect.top + 3, growBoxRect.left + 2, growBoxRect.top + 6, growBoxRect.left + 3), blackColor); - surface->FillRect(Rect::Create(growBoxRect.top + 8, growBoxRect.left + 11, growBoxRect.top + 12, growBoxRect.left + 12)); - surface->FillRect(Rect::Create(growBoxRect.top + 11, growBoxRect.left + 8, growBoxRect.top + 12, growBoxRect.left + 11)); + surface->FillRect(Rect::Create(growBoxRect.top + 8, growBoxRect.left + 11, growBoxRect.top + 12, growBoxRect.left + 12), blackColor); + surface->FillRect(Rect::Create(growBoxRect.top + 11, growBoxRect.left + 8, growBoxRect.top + 12, growBoxRect.left + 11), blackColor); for (int i = 0; i < 7; i++) - surface->FillRect(Rect::Create(growBoxRect.top + 3 + i, growBoxRect.left + 3 + i, growBoxRect.top + 5 + i, growBoxRect.left + 5 + i)); + surface->FillRect(Rect::Create(growBoxRect.top + 3 + i, growBoxRect.left + 3 + i, growBoxRect.top + 5 + i, growBoxRect.left + 5 + i), blackColor); } //-------------------------------------------------------------- UpdateMapWindow @@ -359,8 +360,8 @@ void ResizeMapWindow (short newH, short newV) mapRoomsWide * kMapRoomWidth + kMapScrollBarWidth - 1, mapRoomsHigh * kMapRoomHeight + kMapScrollBarWidth - 1); - surface->SetForeColor(StdColors::White()); - surface->FillRect(mapWindowRect); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(mapWindowRect, whiteColor); SizeWindow(mapWindow, mapWindowRect.right, mapWindowRect.bottom, true); mapHScroll->SetMax(kMaxNumRoomsH - mapRoomsWide); diff --git a/GpApp/ObjectDraw.cpp b/GpApp/ObjectDraw.cpp index 2c59322..53e5009 100644 --- a/GpApp/ObjectDraw.cpp +++ b/GpApp/ObjectDraw.cpp @@ -14,6 +14,7 @@ #include "Room.h" #include "Vec2i.h" #include "PLStandardColors.h" +#include "ResolveCachingColor.h" #include "ScanlineMask.h" #include "ScanlineMaskConverter.h" @@ -445,7 +446,8 @@ void DrawCabinet (Rect *cabinet) (BitMap *)*GetGWorldPixMap(backSrcMap), &handleSrc, &handleSrc, &tempRect); - backSrcMap->FrameRect(*cabinet); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + backSrcMap->FrameRect(*cabinet, blackColor); } //-------------------------------------------------------------- DrawSimpleFurniture @@ -982,7 +984,7 @@ void DrawClockHands (Point where, short bigHand, short littleHand) { DrawSurface *surface = backSrcMap; - surface->SetForeColor(StdColors::Black()); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); const Point midPoint = Point::Create(where.h, where.v); Point otherPoint = midPoint; @@ -1037,7 +1039,7 @@ void DrawClockHands (Point where, short bigHand, short littleHand) break; } - surface->DrawLine(midPoint, otherPoint); + surface->DrawLine(midPoint, otherPoint, blackColor); switch (littleHand) { @@ -1090,7 +1092,7 @@ void DrawClockHands (Point where, short bigHand, short littleHand) break; } - surface->DrawLine(midPoint, otherPoint); + surface->DrawLine(midPoint, otherPoint, blackColor); } //-------------------------------------------------------------- DrawClockHands @@ -1099,7 +1101,7 @@ void DrawLargeClockHands (Point where, short bigHand, short littleHand) { DrawSurface *surface = backSrcMap; - surface->SetForeColor(StdColors::White()); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); const Point midPoint = Point::Create(where.h, where.v); Point otherPoint = midPoint; @@ -1155,7 +1157,7 @@ void DrawLargeClockHands (Point where, short bigHand, short littleHand) break; } - surface->DrawLine(midPoint, otherPoint); + surface->DrawLine(midPoint, otherPoint, whiteColor); switch (littleHand) { @@ -1208,8 +1210,7 @@ void DrawLargeClockHands (Point where, short bigHand, short littleHand) break; } - surface->DrawLine(midPoint, otherPoint); - surface->SetForeColor(StdColors::Black()); + surface->DrawLine(midPoint, otherPoint, whiteColor); } //-------------------------------------------------------------- DrawSimplePrizes @@ -1249,8 +1250,8 @@ void DrawGreaseRt (Rect *theRect, short distance, Boolean state, Boolean drawSpi QSetRect(&spill, 0, -2, distance - 5, 0); QOffsetRect(&spill, dest.right - 1, dest.bottom); - backSrcMap->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); - backSrcMap->FillRect(spill); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + backSrcMap->FillRect(spill, blackColor); } } } @@ -1280,11 +1281,11 @@ void DrawGreaseLf (Rect *theRect, short distance, Boolean state, Boolean drawSpi if (drawSpill) { - backSrcMap->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); QSetRect(&spill, -distance + 5, -2, 0, 0); QOffsetRect(&spill, dest.left + 1, dest.bottom); - backSrcMap->FillRect(spill); + backSrcMap->FillRect(spill, blackColor); } } } @@ -1312,6 +1313,7 @@ void DrawInvisBonus (Rect *theRect) void DrawSlider (Rect *theRect) { - backSrcMap->FrameRect(*theRect); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + backSrcMap->FrameRect(*theRect, blackColor); } diff --git a/GpApp/ObjectDraw2.cpp b/GpApp/ObjectDraw2.cpp index 8d04a2c..3f82826 100644 --- a/GpApp/ObjectDraw2.cpp +++ b/GpApp/ObjectDraw2.cpp @@ -15,6 +15,7 @@ #include "Environ.h" #include "Objects.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "ResourceManager.h" #include "Room.h" #include "Utilities.h" @@ -578,8 +579,7 @@ void DrawMacPlus (Rect *theRect, Boolean isOn, Boolean isLit) if (IsMacPlusGraphicBanned()) { - const PortabilityLayer::RGBAColor beigeColor = PortabilityLayer::RGBAColor::Create(255, 255, 204, 255); - const PortabilityLayer::RGBAColor wasColor = backSrcMap->GetForeColor(); + PortabilityLayer::ResolveCachingColor beigeColor = PortabilityLayer::RGBAColor::Create(255, 255, 204, 255); Rect paintOverRect = *theRect; paintOverRect.left += 8; @@ -587,9 +587,7 @@ void DrawMacPlus (Rect *theRect, Boolean isOn, Boolean isLit) paintOverRect.right = paintOverRect.left + 17; paintOverRect.bottom = paintOverRect.top + 6; - backSrcMap->SetForeColor(beigeColor); - backSrcMap->FillRect(paintOverRect); - backSrcMap->SetForeColor(wasColor); + backSrcMap->FillRect(paintOverRect, beigeColor); } } diff --git a/GpApp/ObjectEdit.cpp b/GpApp/ObjectEdit.cpp index 4eb5f4a..f8ecd9e 100644 --- a/GpApp/ObjectEdit.cpp +++ b/GpApp/ObjectEdit.cpp @@ -19,6 +19,7 @@ #include "Play.h" #include "PLStandardColors.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "ResourceManager.h" #include "Room.h" @@ -2251,7 +2252,8 @@ void DrawThisRoomsObjects (void) { if (GetNumberOfLights(thisRoomNumber) <= 0) { - surface->FillRectWithMaskPattern8x8(backSrcRect, *GetQDGlobalsGray(&dummyPattern)); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRectWithMaskPattern8x8(backSrcRect, *GetQDGlobalsGray(&dummyPattern), blackColor); } for (i = 0; i < kMaxRoomObs; i++) diff --git a/GpApp/ObjectInfo.cpp b/GpApp/ObjectInfo.cpp index 00ac626..62b2b45 100644 --- a/GpApp/ObjectInfo.cpp +++ b/GpApp/ObjectInfo.cpp @@ -18,6 +18,7 @@ #include "PLTimeTaggedVOSEvent.h" #include "QDPixMap.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #define kBlowerInfoDialogID 1007 @@ -126,11 +127,12 @@ void UpdateBlowerInfo (Dialog *theDialog) { #define kArrowheadLength 4 Rect bounds; + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); Window *window = theDialog->GetWindow(); DrawSurface *surface = window->GetDrawSurface(); - surface->SetForeColor(StdColors::White()); - surface->FillRect((*surface->m_port.GetPixMap())->m_rect); + + surface->FillRect((*surface->m_port.GetPixMap())->m_rect, whiteColor); window->DrawControls(); @@ -140,19 +142,20 @@ void UpdateBlowerInfo (Dialog *theDialog) if ((thisRoom->objects[objActive].what != kLeftFan) && (thisRoom->objects[objActive].what != kRightFan)) { + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + GetDialogItemRect(theDialog, 8, &bounds); bounds.right += 2; bounds.bottom += 2; - surface->SetForeColor(StdColors::White()); - surface->FillRect(bounds); + surface->FillRect(bounds, whiteColor); bounds.right -= 2; bounds.bottom -= 2; - surface->SetForeColor(StdColors::Black()); - for (int16_t offsetChunk = 0; offsetChunk < 4; offsetChunk++) { + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + const int16_t xOffset = offsetChunk & 1; const int16_t yOffset = (offsetChunk >> 1) & 1; @@ -163,36 +166,36 @@ void UpdateBlowerInfo (Dialog *theDialog) case 1: // up { const Point basePoint = offset + Point::Create(bounds.left + HalfRectWide(&bounds), bounds.top); - surface->DrawLine(basePoint, basePoint + Point::Create(0, RectTall(&bounds))); - surface->DrawLine(basePoint, basePoint + Point::Create(kArrowheadLength, kArrowheadLength)); - surface->DrawLine(basePoint, basePoint + Point::Create(-kArrowheadLength, kArrowheadLength)); + surface->DrawLine(basePoint, basePoint + Point::Create(0, RectTall(&bounds)), blackColor); + surface->DrawLine(basePoint, basePoint + Point::Create(kArrowheadLength, kArrowheadLength), blackColor); + surface->DrawLine(basePoint, basePoint + Point::Create(-kArrowheadLength, kArrowheadLength), blackColor); } break; case 2: // right { const Point basePoint = offset + Point::Create(bounds.right, bounds.top + HalfRectTall(&bounds)); - surface->DrawLine(basePoint, basePoint + Point::Create(-RectWide(&bounds), 0)); - surface->DrawLine(basePoint, basePoint + Point::Create(-kArrowheadLength, kArrowheadLength)); - surface->DrawLine(basePoint, basePoint + Point::Create(-kArrowheadLength, -kArrowheadLength)); + surface->DrawLine(basePoint, basePoint + Point::Create(-RectWide(&bounds), 0), blackColor); + surface->DrawLine(basePoint, basePoint + Point::Create(-kArrowheadLength, kArrowheadLength), blackColor); + surface->DrawLine(basePoint, basePoint + Point::Create(-kArrowheadLength, -kArrowheadLength), blackColor); } break; case 4: // down { const Point basePoint = offset + Point::Create(bounds.left + HalfRectWide(&bounds), bounds.bottom); - surface->DrawLine(basePoint, basePoint + Point::Create(0, -RectTall(&bounds))); - surface->DrawLine(basePoint, basePoint + Point::Create(kArrowheadLength, -kArrowheadLength)); - surface->DrawLine(basePoint, basePoint + Point::Create(-kArrowheadLength, -kArrowheadLength)); + surface->DrawLine(basePoint, basePoint + Point::Create(0, -RectTall(&bounds)), blackColor); + surface->DrawLine(basePoint, basePoint + Point::Create(kArrowheadLength, -kArrowheadLength), blackColor); + surface->DrawLine(basePoint, basePoint + Point::Create(-kArrowheadLength, -kArrowheadLength), blackColor); } break; case 8: // left { const Point basePoint = offset + Point::Create(bounds.left, bounds.top + HalfRectTall(&bounds)); - surface->DrawLine(basePoint, basePoint + Point::Create(RectWide(&bounds), 0)); - surface->DrawLine(basePoint, basePoint + Point::Create(kArrowheadLength, -kArrowheadLength)); - surface->DrawLine(basePoint, basePoint + Point::Create(kArrowheadLength, kArrowheadLength)); + surface->DrawLine(basePoint, basePoint + Point::Create(RectWide(&bounds), 0), blackColor); + surface->DrawLine(basePoint, basePoint + Point::Create(kArrowheadLength, -kArrowheadLength), blackColor); + surface->DrawLine(basePoint, basePoint + Point::Create(kArrowheadLength, kArrowheadLength), blackColor); } break; @@ -204,33 +207,35 @@ void UpdateBlowerInfo (Dialog *theDialog) if ((thisRoom->objects[objActive].what == kInvisBlower) || (thisRoom->objects[objActive].what == kLiftArea)) { + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + switch (newDirection) { case 1: // up EraseDialogItem(theDialog, 11); - FrameOvalDialogItem(theDialog, 12); - FrameOvalDialogItem(theDialog, 13); - FrameOvalDialogItem(theDialog, 14); + FrameOvalDialogItem(theDialog, 12, blackColor); + FrameOvalDialogItem(theDialog, 13, blackColor); + FrameOvalDialogItem(theDialog, 14, blackColor); break; case 2: // right - FrameOvalDialogItem(theDialog, 11); + FrameOvalDialogItem(theDialog, 11, blackColor); EraseDialogItem(theDialog, 12); - FrameOvalDialogItem(theDialog, 13); - FrameOvalDialogItem(theDialog, 14); + FrameOvalDialogItem(theDialog, 13, blackColor); + FrameOvalDialogItem(theDialog, 14, blackColor); break; case 4: // down - FrameOvalDialogItem(theDialog, 11); - FrameOvalDialogItem(theDialog, 12); + FrameOvalDialogItem(theDialog, 11, blackColor); + FrameOvalDialogItem(theDialog, 12, blackColor); EraseDialogItem(theDialog, 13); - FrameOvalDialogItem(theDialog, 14); + FrameOvalDialogItem(theDialog, 14, blackColor); break; case 8: // left - FrameOvalDialogItem(theDialog, 11); - FrameOvalDialogItem(theDialog, 12); - FrameOvalDialogItem(theDialog, 13); + FrameOvalDialogItem(theDialog, 11, blackColor); + FrameOvalDialogItem(theDialog, 12, blackColor); + FrameOvalDialogItem(theDialog, 13, blackColor); EraseDialogItem(theDialog, 14); break; } diff --git a/GpApp/Play.cpp b/GpApp/Play.cpp index 18479a7..f7e25df 100644 --- a/GpApp/Play.cpp +++ b/GpApp/Play.cpp @@ -14,6 +14,7 @@ #include "House.h" #include "MainWindow.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "Scoreboard.h" @@ -136,9 +137,11 @@ void NewGame (short mode) DrawSurface *mainWindowSurface = mainWindow->GetDrawSurface(); + PortabilityLayer::ResolveCachingColor blackColorMain = StdColors::Black(); + tempRect = thisMac.constrainedScreen; tempRect.top = tempRect.bottom - 20; // thisMac.menuHigh - mainWindowSurface->FillRect(tempRect); + mainWindowSurface->FillRect(tempRect, blackColorMain); #ifdef COMPILEQT if ((thisMac.hasQT) && (hasMovie)) @@ -146,9 +149,9 @@ void NewGame (short mode) theMovie.m_surface = mainWindow->GetDrawSurface(); } #endif - - workSrcMap->SetForeColor(StdColors::Black()); - workSrcMap->FillRect(workSrcRect); + + PortabilityLayer::ResolveCachingColor blackColorWork = StdColors::Black(); + workSrcMap->FillRect(workSrcRect, blackColorWork); // if (quickerTransitions) // DissBitsChunky(&workSrcRect); // else @@ -752,8 +755,8 @@ void RestoreEntireGameScreen (void) DrawSurface *surface = mainWindow->GetDrawSurface(); tempRect = thisMac.constrainedScreen; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(tempRect); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRect(tempRect, blackColor); ResetLocale(false); RefreshScoreboard(kNormalTitleMode); diff --git a/GpApp/RectUtils.cpp b/GpApp/RectUtils.cpp index 7b7f8fc..bc3f0ea 100644 --- a/GpApp/RectUtils.cpp +++ b/GpApp/RectUtils.cpp @@ -16,7 +16,7 @@ // Given the top left corner and a width and height, this functionÉ // simply creates the necessary rectangle and frames it. -void FrameWHRect (DrawSurface *surface, short left, short top, short wide, short high) +void FrameWHRect (DrawSurface *surface, short left, short top, short wide, short high, PortabilityLayer::ResolveCachingColor &color) { Rect theRect; @@ -24,7 +24,7 @@ void FrameWHRect (DrawSurface *surface, short left, short top, short wide, short theRect.top = top; theRect.right = left + wide; theRect.bottom = top + high; - surface->FrameRect(theRect); + surface->FrameRect(theRect, color); } //-------------------------------------------------------------- NormalizeRect diff --git a/GpApp/RectUtils.h b/GpApp/RectUtils.h index dd894b9..5affd19 100644 --- a/GpApp/RectUtils.h +++ b/GpApp/RectUtils.h @@ -10,8 +10,13 @@ #include "PLQDraw.h" +namespace PortabilityLayer +{ + class ResolveCachingColor; +} -void FrameWHRect (short, short, short, short); + +void FrameWHRect (short, short, short, short, PortabilityLayer::ResolveCachingColor &color); void NormalizeRect (Rect *); void ZeroRectCorner (Rect *); void CenterRectOnPoint (Rect *, Point); diff --git a/GpApp/Room.cpp b/GpApp/Room.cpp index aa85f0c..325aae3 100644 --- a/GpApp/Room.cpp +++ b/GpApp/Room.cpp @@ -18,6 +18,7 @@ #include "MainWindow.h" #include "MemoryManager.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #define kDeleteRoomAlert 1005 @@ -246,16 +247,18 @@ void ReadyBackground (short theID, short *theTiles) if ((noRoomAtAll) || (!houseUnlocked)) { - LtGrayForeColor(workSrcMap); - workSrcMap->FillRect(workSrcRect); - workSrcMap->SetForeColor(StdColors::Black()); + PortabilityLayer::ResolveCachingColor ltGrayColor = LtGrayForeColor(); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + + workSrcMap->FillRect(workSrcRect, ltGrayColor); + workSrcMap->SetApplicationFont(9, PortabilityLayer::FontFamilyFlag_None); const Point textPoint = Point::Create(10, 20); if (houseUnlocked) - workSrcMap->DrawString(textPoint, PSTR("No rooms"), true); + workSrcMap->DrawString(textPoint, PSTR("No rooms"), true, blackColor); else - workSrcMap->DrawString(textPoint, PSTR("Nothing to show"), true); + workSrcMap->DrawString(textPoint, PSTR("Nothing to show"), true, blackColor); CopyBits((BitMap *)*GetGWorldPixMap(workSrcMap), (BitMap *)*GetGWorldPixMap(backSrcMap), diff --git a/GpApp/RoomGraphics.cpp b/GpApp/RoomGraphics.cpp index 34f3d9f..1920451 100644 --- a/GpApp/RoomGraphics.cpp +++ b/GpApp/RoomGraphics.cpp @@ -11,6 +11,7 @@ #include "Environ.h" #include "MainWindow.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "Room.h" #include "BitmapImage.h" @@ -82,8 +83,8 @@ void ResetLocale (Boolean soft) DrawSurface *wasCPort = GetGraphicsPort(); const short roomV = (*thisHouse)->rooms[thisRoomNumber].floor; - backSrcMap->SetForeColor(StdColors::Black()); - backSrcMap->FillRect(backSrcRect); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + backSrcMap->FillRect(backSrcRect, blackColor); if (numNeighbors > 3) { @@ -185,8 +186,8 @@ void DrawRoomBackground (short who, short where, short elevation) if ((numLights == 0) && (who != kRoomIsEmpty)) { - backSrcMap->SetForeColor(StdColors::Black()); - backSrcMap->FillRect(localRoomsDest[where]); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + backSrcMap->FillRect(localRoomsDest[where], blackColor); return; } @@ -195,8 +196,8 @@ void DrawRoomBackground (short who, short where, short elevation) { if (wardBitSet) { - backSrcMap->SetForeColor(StdColors::Black()); - backSrcMap->FillRect(localRoomsDest[where]); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + backSrcMap->FillRect(localRoomsDest[where], blackColor); return; } diff --git a/GpApp/RoomInfo.cpp b/GpApp/RoomInfo.cpp index c9da2b1..7e54fc6 100644 --- a/GpApp/RoomInfo.cpp +++ b/GpApp/RoomInfo.cpp @@ -20,6 +20,7 @@ #include "PLPopupMenuWidget.h" #include "PLTimeTaggedVOSEvent.h" #include "QDPixMap.h" +#include "ResolveCachingColor.h" #include "ResourceCompiledRef.h" #include "ResourceManager.h" #include "Utilities.h" @@ -117,11 +118,13 @@ void UpdateRoomInfoDialog (Dialog *theDialog) SetDialogString(theDialog, kLitUnlitText, PSTR("(Room Is Dark)")); else SetDialogString(theDialog, kLitUnlitText, PSTR("(Room Is Lit)")); + + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); FrameDialogItemC(theDialog, kRoomLocationBox, kRedOrangeColor8); - FrameDialogItem(theDialog, kRoomTilesBox); + FrameDialogItem(theDialog, kRoomTilesBox, blackColor); FrameDialogItemC(theDialog, kRoomDividerLine, kRedOrangeColor8); - FrameDialogItem(theDialog, kRoomTilesBox2); + FrameDialogItem(theDialog, kRoomTilesBox2, blackColor); } #endif @@ -134,6 +137,9 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n Point mouseWas; short wasTileOver; Pattern dummyPattern; + + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + PortabilityLayer::ResolveCachingColor blueColor = StdColors::Blue(); tileOver = (mouseIs.h - tileSrc.left) / kMiniTileWide; wasTileOver = -1; @@ -161,14 +167,13 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n *newTileOver = (mouseIs.h - tileDest.left) / kMiniTileWide; if (*newTileOver != wasTileOver) { - surface->SetForeColor(StdColors::Blue()); for (int offset = 0; offset < 2; offset++) { Point pointA = Point::Create(tileDest.left + (*newTileOver * kMiniTileWide), tileDest.top - 3 + offset); Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v); - surface->DrawLine(pointA, pointB); + surface->DrawLine(pointA, pointB, blueColor); } for (int offset = 0; offset < 2; offset++) @@ -176,19 +181,17 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n Point pointA = Point::Create(tileDest.left + (*newTileOver * kMiniTileWide), tileDest.bottom + 1 + offset); Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v); - surface->DrawLine(pointA, pointB); + surface->DrawLine(pointA, pointB, blueColor); } if (wasTileOver != -1) { - surface->SetForeColor(StdColors::White()); - for (int offset = 0; offset < 2; offset++) { Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.top - 3 + offset); Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v); - surface->DrawLine(pointA, pointB); + surface->DrawLine(pointA, pointB, whiteColor); } for (int offset = 0; offset < 2; offset++) @@ -196,7 +199,7 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.bottom + 1 + offset); Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v); - surface->DrawLine(pointA, pointB); + surface->DrawLine(pointA, pointB, whiteColor); } } @@ -208,14 +211,12 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n *newTileOver = -1; // we're not in the drop zone if (wasTileOver != -1) { - surface->SetForeColor(StdColors::White()); - for (int offset = 0; offset < 2; offset++) { Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.top - 3 + offset); Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v); - surface->DrawLine(pointA, pointB); + surface->DrawLine(pointA, pointB, whiteColor); } for (int offset = 0; offset < 2; offset++) @@ -223,7 +224,7 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.bottom + 1 + offset); Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v); - surface->DrawLine(pointA, pointB); + surface->DrawLine(pointA, pointB, whiteColor); } wasTileOver = -1; @@ -235,14 +236,12 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n } if (wasTileOver != -1) { - surface->SetForeColor(StdColors::White()); - for (int offset = 0; offset < 2; offset++) { Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.top - 3 + offset); Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v); - surface->DrawLine(pointA, pointB); + surface->DrawLine(pointA, pointB, whiteColor); } for (int offset = 0; offset < 2; offset++) @@ -250,7 +249,7 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.bottom + 1 + offset); Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v); - surface->DrawLine(pointA, pointB); + surface->DrawLine(pointA, pointB, whiteColor); } wasTileOver = -1; @@ -265,6 +264,8 @@ void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *n void HiliteTileOver (DrawSurface *surface, Point mouseIs) { short newTileOver; + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + PortabilityLayer::ResolveCachingColor redColor = StdColors::Red(); if (tileSrc.Contains(mouseIs)) { @@ -277,33 +278,27 @@ void HiliteTileOver (DrawSurface *surface, Point mouseIs) newTileOver = (mouseIs.h - tileSrc.left) / kMiniTileWide; if (newTileOver != tileOver) { - surface->SetForeColor(StdColors::Red()); - { const Point tileLineTopLeft = Point::Create(tileSrc.left + (newTileOver * kMiniTileWide), tileSrc.top - 3); const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2); - surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h)); + surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), redColor); } if (tileOver != -1) { - surface->SetForeColor(StdColors::White()); - { const Point tileLineTopLeft = Point::Create(tileSrc.left + (tileOver * kMiniTileWide), tileSrc.top - 3); const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2); - surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h)); + surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), whiteColor); } { const Point tileLineTopLeft = Point::Create(tileSrc.left + (tileOver * kMiniTileWide), tileSrc.bottom + 1); const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2); - surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h)); + surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), whiteColor); } } - surface->SetForeColor(StdColors::Black()); - tileOver = newTileOver; } } @@ -311,21 +306,18 @@ void HiliteTileOver (DrawSurface *surface, Point mouseIs) { if (tileOver != -1) { - surface->SetForeColor(StdColors::White()); - { const Point tileLineTopLeft = Point::Create(tileSrc.left + (tileOver * kMiniTileWide), tileSrc.top - 3); const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2); - surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h)); + surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), whiteColor); } { const Point tileLineTopLeft = Point::Create(tileSrc.left + (tileOver * kMiniTileWide), tileSrc.bottom + 1); const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2); - surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h)); + surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), whiteColor); } - surface->SetForeColor(StdColors::Black()); tileOver = -1; } diff --git a/GpApp/Scoreboard.cpp b/GpApp/Scoreboard.cpp index 0e0462b..ee429f8 100644 --- a/GpApp/Scoreboard.cpp +++ b/GpApp/Scoreboard.cpp @@ -11,9 +11,11 @@ #include "Externs.h" #include "Environ.h" #include "MenuManager.h" +#include "PLStandardColors.h" #include "QDPixMap.h" #include "QDStandardPalette.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #define kGrayBackgroundColor 251 @@ -153,48 +155,42 @@ void RefreshRoomTitle (short mode) { DrawSurface *surface = boardTSrcMap; - PortabilityLayer::RGBAColor theRGBColor, wasColor; + PortabilityLayer::ResolveCachingColor theRGBColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(kGrayBackgroundColor); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); - wasColor = surface->GetForeColor(); - theRGBColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[kGrayBackgroundColor]; - surface->SetForeColor(theRGBColor); - surface->FillRect(boardTSrcRect); - surface->SetForeColor(wasColor); + surface->FillRect(boardTSrcRect, theRGBColor); const Point strShadowPoint = Point::Create(1, 10); const Point strPoint = Point::Create(0, 9); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); - switch (mode) { case kEscapedTitleMode: - surface->DrawString(strShadowPoint, PSTR("Hit Delete key if unable to Follow"), true); + surface->DrawString(strShadowPoint, PSTR("Hit Delete key if unable to Follow"), true, blackColor); break; case kSavingTitleMode: - surface->DrawString(strShadowPoint, PSTR("Saving GameÉ"), true); + surface->DrawString(strShadowPoint, PSTR("Saving GameÉ"), true, blackColor); break; default: - surface->DrawString(strShadowPoint, thisRoom->name, true); + surface->DrawString(strShadowPoint, thisRoom->name, true, blackColor); break; } - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)); - switch (mode) { case kEscapedTitleMode: - surface->DrawString(strPoint, PSTR("Hit Delete key if unable to Follow"), true); + surface->DrawString(strPoint, PSTR("Hit Delete key if unable to Follow"), true, whiteColor); break; case kSavingTitleMode: - surface->DrawString(strPoint, PSTR("Saving GameÉ"), true); + surface->DrawString(strPoint, PSTR("Saving GameÉ"), true, whiteColor); break; default: - surface->DrawString(strPoint, thisRoom->name, true); + surface->DrawString(strPoint, thisRoom->name, true, whiteColor); break; } @@ -207,16 +203,15 @@ void RefreshRoomTitle (short mode) void RefreshNumGliders (void) { - PortabilityLayer::RGBAColor theRGBColor, wasColor; Str255 nGlidersStr; long displayMortals; DrawSurface *surface = boardGSrcMap; - theRGBColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[kGrayBackgroundColor]; + PortabilityLayer::ResolveCachingColor theRGBColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(kGrayBackgroundColor); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); - wasColor = surface->GetForeColor(); - surface->SetForeColor(theRGBColor); - surface->FillRect(boardGSrcRect); + surface->FillRect(boardGSrcRect, theRGBColor); displayMortals = mortals; if (displayMortals < 0) @@ -226,11 +221,8 @@ void RefreshNumGliders (void) const Point shadowPoint = Point::Create(1, 10); const Point textPoint = Point::Create(0, 9); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); - surface->DrawString(shadowPoint, nGlidersStr, true); - - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)); - surface->DrawString(textPoint, nGlidersStr, true); + surface->DrawString(shadowPoint, nGlidersStr, true, blackColor); + surface->DrawString(textPoint, nGlidersStr, true, whiteColor); CopyBits((BitMap *)*GetGWorldPixMap(boardGSrcMap), (BitMap *)*GetGWorldPixMap(boardSrcMap), @@ -241,25 +233,22 @@ void RefreshNumGliders (void) void RefreshPoints (void) { - PortabilityLayer::RGBAColor theRGBColor, wasColor; Str255 scoreStr; DrawSurface *surface = boardPSrcMap; - theRGBColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[kGrayBackgroundColor]; + PortabilityLayer::ResolveCachingColor theRGBColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(kGrayBackgroundColor); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); - surface->SetForeColor(theRGBColor); - surface->FillRect(boardPSrcRect); + surface->FillRect(boardPSrcRect, theRGBColor); NumToString(theScore, scoreStr); const Point shadowPoint = Point::Create(1, 10); const Point textPoint = Point::Create(0, 9); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); - surface->DrawString(shadowPoint, scoreStr, true); - - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)); - surface->DrawString(textPoint, scoreStr, true); + surface->DrawString(shadowPoint, scoreStr, true, blackColor); + surface->DrawString(textPoint, scoreStr, true, whiteColor); CopyBits((BitMap *)*GetGWorldPixMap(boardPSrcMap), (BitMap *)*GetGWorldPixMap(boardSrcMap), @@ -272,25 +261,22 @@ void RefreshPoints (void) void QuickGlidersRefresh (void) { - PortabilityLayer::RGBAColor theRGBColor, wasColor; Str255 nGlidersStr; DrawSurface *surface = boardGSrcMap; - theRGBColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[kGrayBackgroundColor]; + PortabilityLayer::ResolveCachingColor theRGBColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(kGrayBackgroundColor); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); - surface->SetForeColor(theRGBColor); - surface->FillRect(boardGSrcRect); + surface->FillRect(boardGSrcRect, theRGBColor); NumToString((long)mortals, nGlidersStr); const Point shadowPoint = Point::Create(1, 10); const Point textPoint = Point::Create(0, 9); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); - surface->DrawString(shadowPoint, nGlidersStr, true); - - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)); - surface->DrawString(textPoint, nGlidersStr, true); + surface->DrawString(shadowPoint, nGlidersStr, true, blackColor); + surface->DrawString(textPoint, nGlidersStr, true, whiteColor); CopyBits((BitMap *)*GetGWorldPixMap(boardGSrcMap), GetPortBitMapForCopyBits(boardWindow->GetDrawSurface()), @@ -303,24 +289,22 @@ void QuickGlidersRefresh (void) void QuickScoreRefresh (void) { - PortabilityLayer::RGBAColor theRGBColor, wasColor; Str255 scoreStr; DrawSurface *surface = boardPSrcMap; - theRGBColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[kGrayBackgroundColor]; - surface->SetForeColor(theRGBColor); - surface->FillRect(boardPSrcRect); + PortabilityLayer::ResolveCachingColor theRGBColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(kGrayBackgroundColor); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + + surface->FillRect(boardPSrcRect, theRGBColor); NumToString(displayedScore, scoreStr); const Point shadowPoint = Point::Create(1, 10); const Point textPoint = Point::Create(0, 9); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); - surface->DrawString(shadowPoint, scoreStr, true); - - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)); - surface->DrawString(textPoint, scoreStr, true); + surface->DrawString(shadowPoint, scoreStr, true, blackColor); + surface->DrawString(textPoint, scoreStr, true, whiteColor); CopyBits((BitMap *)*GetGWorldPixMap(boardPSrcMap), GetPortBitMapForCopyBits(boardWindow->GetDrawSurface()), diff --git a/GpApp/SelectHouse.cpp b/GpApp/SelectHouse.cpp index d84abef..f4db1c4 100644 --- a/GpApp/SelectHouse.cpp +++ b/GpApp/SelectHouse.cpp @@ -17,6 +17,7 @@ #include "FileManager.h" #include "House.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "ResourceFile.h" #include "ResourceManager.h" #include "PLTimeTaggedVOSEvent.h" @@ -157,9 +158,8 @@ void PageUpHouses (Dialog *theDial) QSetRect(&tempRect, 8, 39, 421, 223); - surface->SetForeColor(StdColors::White()); - surface->FillRect(tempRect); - surface->SetForeColor(StdColors::Black()); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(tempRect, whiteColor); UpdateLoadDialog(theDial); } @@ -191,9 +191,8 @@ void PageDownHouses (Dialog *theDial) } QSetRect(&tempRect, 8, 39, 421, 223); - surface->SetForeColor(StdColors::White()); - surface->FillRect(tempRect); - surface->SetForeColor(StdColors::Black()); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(tempRect, whiteColor); UpdateLoadDialog(theDial); } diff --git a/GpApp/Settings.cpp b/GpApp/Settings.cpp index c81d76b..64cc294 100644 --- a/GpApp/Settings.cpp +++ b/GpApp/Settings.cpp @@ -12,6 +12,7 @@ #include "PLTextUtils.h" #include "PLTimeTaggedVOSEvent.h" #include "PLWidgets.h" +#include "ResolveCachingColor.h" #include "DialogManager.h" #include "DialogUtils.h" #include "Externs.h" @@ -348,27 +349,26 @@ void UpdateSettingsControl (Dialog *theDialog) { short i; DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface(); + + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)); for (i = 0; i < 4; i++) { Rect rect = controlRects[i]; - surface->FrameRect(rect); + surface->FrameRect(rect, whiteColor); InsetRect(&rect, 1, 1); - surface->FrameRect(rect); + surface->FrameRect(rect, whiteColor); } - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(255, 0, 0, 255)); + PortabilityLayer::ResolveCachingColor redColor = StdColors::Red(); { Rect rect = controlRects[whichCtrl]; - surface->FrameRect(rect); + surface->FrameRect(rect, redColor); InsetRect(&rect, 1, 1); - surface->FrameRect(rect); + surface->FrameRect(rect, redColor); } - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)); - UpdateControlKeyName(theDialog); FrameDialogItemC(theDialog, 3, kRedOrangeColor8); } @@ -555,18 +555,20 @@ void DoControlPrefs (void) { Rect ctrlRect = controlRects[whichCtrl]; - surface->SetForeColor(StdColors::White()); - surface->FrameRect(ctrlRect); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FrameRect(ctrlRect, whiteColor); InsetRect(&ctrlRect, 1, 1); - surface->FrameRect(ctrlRect); + surface->FrameRect(ctrlRect, whiteColor); whichCtrl = itemHit - kRightControl; ctrlRect = controlRects[whichCtrl]; - surface->SetForeColor(StdColors::Red()); - surface->FrameRect(ctrlRect); + + + PortabilityLayer::ResolveCachingColor redColor = StdColors::Red(); + surface->FrameRect(ctrlRect, redColor); InsetRect(&ctrlRect, 1, 1); - surface->FrameRect(ctrlRect); + surface->FrameRect(ctrlRect, redColor); } UpdateControlKeyName(prefDlg); @@ -887,17 +889,15 @@ void FrameDisplayIcon (Dialog *theDialog, const PortabilityLayer::RGBAColor &col DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface(); - surface->SetForeColor(color); + PortabilityLayer::ResolveCachingColor cacheColor = color; theRect.left -= 3; theRect.top += 0; theRect.right += 3; theRect.bottom -= 1; - surface->FrameRect(theRect); + surface->FrameRect(theRect, cacheColor); InsetRect(&theRect, 1, 1); - surface->FrameRect(theRect); - - surface->SetForeColor(StdColors::Black()); + surface->FrameRect(theRect, cacheColor); } //-------------------------------------------------------------- DisplayUpdate diff --git a/GpApp/Tools.cpp b/GpApp/Tools.cpp index 5933cda..3652222 100644 --- a/GpApp/Tools.cpp +++ b/GpApp/Tools.cpp @@ -16,6 +16,7 @@ #include "PLPopupMenuWidget.h" #include "QDPixMap.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "Utilities.h" #include "WindowDef.h" #include "WindowManager.h" @@ -129,13 +130,12 @@ void FrameSelectedTool (DrawSurface *surface) } theRect = toolRects[toolIcon]; - surface->SetForeColor(StdColors::Red()); - surface->FrameRect(theRect); + PortabilityLayer::ResolveCachingColor redColor = StdColors::Red(); + + surface->FrameRect(theRect, redColor); InsetRect(&theRect, 1, 1); - surface->FrameRect(theRect); - - surface->SetForeColor(StdColors::Black()); + surface->FrameRect(theRect, redColor); } #endif @@ -152,9 +152,8 @@ void DrawToolName (DrawSurface *surface) GetIndString(theString, kObjectNameStrings, toolSelected + ((toolMode - 1) * 0x0010)); - surface->SetForeColor(StdColors::White()); - surface->FillRect(toolTextRect); - surface->SetForeColor(StdColors::Black()); + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(toolTextRect, whiteColor); const Point textPoint = Point::Create(toolTextRect.left + 3, toolTextRect.bottom - 6); @@ -216,10 +215,11 @@ void EraseSelectedTool (void) } theRect = toolRects[toolIcon]; - surface->SetForeColor(StdColors::White()); - surface->FrameRect(theRect); + + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FrameRect(theRect, whiteColor); InsetRect(&theRect, 1, 1); - surface->FrameRect(theRect); + surface->FrameRect(theRect, whiteColor); #endif } @@ -250,11 +250,12 @@ void SelectTool (short which) } theRect = toolRects[toolIcon]; - surface->SetForeColor(StdColors::Red()); - surface->FrameRect(theRect); + PortabilityLayer::ResolveCachingColor redColor = StdColors::Red(); + + surface->FrameRect(theRect, redColor); InsetRect(&theRect, 1, 1); - surface->FrameRect(theRect); + surface->FrameRect(theRect, redColor); toolSelected = which; DrawToolName(surface); @@ -271,9 +272,8 @@ void UpdateToolsWindow (void) DrawSurface *surface = toolsWindow->GetDrawSurface(); - DkGrayForeColor(surface); - surface->DrawLine(Point::Create(4, 25), Point::Create(112, 25)); - surface->SetForeColor(StdColors::Black()); + PortabilityLayer::ResolveCachingColor lineColor = DkGrayForeColor(); + surface->DrawLine(Point::Create(4, 25), Point::Create(112, 25), lineColor); DrawToolTiles(surface); FrameSelectedTool(surface); diff --git a/GpApp/WindowUtils.cpp b/GpApp/WindowUtils.cpp index a6ec075..7feb045 100644 --- a/GpApp/WindowUtils.cpp +++ b/GpApp/WindowUtils.cpp @@ -10,6 +10,7 @@ #include "Environ.h" #include "PLStandardColors.h" #include "RectUtils.h" +#include "ResolveCachingColor.h" #include "WindowDef.h" #include "WindowManager.h" @@ -126,8 +127,6 @@ void OpenMessageWindow (const PLPasStr &title) DrawSurface *surface = mssgWindow->GetDrawSurface(); surface->SetClipRect(mssgWindowRect); - surface->SetForeColor(StdColors::Black()); - surface->SetSystemFont(12, 0); } @@ -154,12 +153,14 @@ void SetMessageWindowMessage (StringPtr message, const PortabilityLayer::RGBACol SetRect(&mssgWindowRect, 0, 0, 256, kMessageWindowTall); InsetRect(&mssgWindowRect, 16, 16); - surface->SetForeColor(StdColors::White()); - surface->FillRect(mssgWindowRect); + + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(mssgWindowRect, whiteColor); const Point textPoint = Point::Create(mssgWindowRect.left, mssgWindowRect.bottom - 6); - surface->SetForeColor(color); - surface->DrawString(textPoint, message, true); + + PortabilityLayer::ResolveCachingColor specifiedColor = color; + surface->DrawString(textPoint, message, true, specifiedColor); } } diff --git a/PortabilityLayer/MenuManager.cpp b/PortabilityLayer/MenuManager.cpp index 5d03007..2890a43 100644 --- a/PortabilityLayer/MenuManager.cpp +++ b/PortabilityLayer/MenuManager.cpp @@ -20,6 +20,7 @@ #include "QDManager.h" #include "QDPixMap.h" #include "RGBAColor.h" +#include "ResolveCachingColor.h" #include "Vec2i.h" #include @@ -812,42 +813,44 @@ namespace PortabilityLayer PortabilityLayer::QDState *qdState = qdManager->GetState(); - graf->SetForeColor(gs_barMidColor); - graf->FillRect(menuRect); - graf->SetForeColor(gs_barBrightColor); + ResolveCachingColor barMidColor = gs_barMidColor; + + graf->FillRect(menuRect, barMidColor); + + ResolveCachingColor barBrightColor = gs_barBrightColor; // Top stripe { const Rect rect = Rect::Create(0, 0, 1, static_cast(width) - 1); - m_menuBarGraf->FillRect(rect); + m_menuBarGraf->FillRect(rect, barBrightColor); } // Left stripe { const Rect rect = Rect::Create(0, 0, kMenuBarHeight - 1, 1); - m_menuBarGraf->FillRect(rect); + m_menuBarGraf->FillRect(rect, barBrightColor); } - qdState->SetForeColor(gs_barDarkColor); + ResolveCachingColor barDarkColor = gs_barDarkColor; // Bottom stripe { const Rect rect = Rect::Create(kMenuBarHeight - 2, 1, kMenuBarHeight - 1, width); - m_menuBarGraf->FillRect(rect); + m_menuBarGraf->FillRect(rect, barDarkColor); } // Right stripe { const Rect rect = Rect::Create(0, width - 1, kMenuBarHeight - 1, width); - m_menuBarGraf->FillRect(rect); + m_menuBarGraf->FillRect(rect, barDarkColor); } - qdState->SetForeColor(gs_barBottomEdgeColor); + ResolveCachingColor barBottomEdgeColor = gs_barBottomEdgeColor; // Bottom edge { const Rect rect = Rect::Create(kMenuBarHeight - 1, 0, kMenuBarHeight, width); - m_menuBarGraf->FillRect(rect); + m_menuBarGraf->FillRect(rect, barBottomEdgeColor); } PixMapHandle pixMap = m_menuBarGraf->m_port.GetPixMap(); @@ -869,28 +872,28 @@ namespace PortabilityLayer const int16_t right = static_cast(xCoordinate + width); // Top edge - qdState->SetForeColor(gs_barHighlightBrightColor); { + ResolveCachingColor barHighlightBrightColor = gs_barHighlightBrightColor; const Rect rect = Rect::Create(0, left, 1, right); - m_menuBarGraf->FillRect(rect); + m_menuBarGraf->FillRect(rect, barHighlightBrightColor); } // Middle - qdState->SetForeColor(gs_barHighlightMidColor); { + ResolveCachingColor barHighlightMidColor = gs_barHighlightMidColor; const Rect rect = Rect::Create(1, left, kMenuBarHeight - 2, right); - m_menuBarGraf->FillRect(rect); + m_menuBarGraf->FillRect(rect, barHighlightMidColor); } - qdState->SetForeColor(gs_barHighlightDarkColor); { + ResolveCachingColor barHighlightDarkColor = gs_barHighlightDarkColor; const Rect rect = Rect::Create(kMenuBarHeight - 2, left, kMenuBarHeight - 1, right); - m_menuBarGraf->FillRect(rect); + m_menuBarGraf->FillRect(rect, barHighlightDarkColor); } } // Text items - qdState->SetForeColor(gs_barNormalTextColor); + ResolveCachingColor barNormalTextColor = gs_barNormalTextColor; m_menuBarGraf->SetSystemFont(kMenuFontSize, PortabilityLayer::FontFamilyFlag_Bold); { @@ -913,7 +916,7 @@ namespace PortabilityLayer if (menuHdl != selectedMenuHdl) { const Point itemPos = Point::Create(static_cast(xCoordinate), kMenuBarTextYOffset); - graf->DrawString(itemPos, PLPasStr(static_cast(menu->stringBlobHandle->m_contents)), true); + graf->DrawString(itemPos, PLPasStr(static_cast(menu->stringBlobHandle->m_contents)), true, barNormalTextColor); } } } @@ -928,11 +931,12 @@ namespace PortabilityLayer if (menu->stringBlobHandle && !menu->isIcon) { - qdState->SetForeColor(gs_barHighlightTextColor); + ResolveCachingColor barHighlightTextColor = gs_barHighlightTextColor; + size_t xCoordinate = menu->cumulativeOffset + (menu->menuIndex * 2) * kMenuBarItemPadding + kMenuBarInitialPadding; const Point itemPos = Point::Create(static_cast(xCoordinate), kMenuBarTextYOffset); - graf->DrawString(itemPos, PLPasStr(static_cast(menu->stringBlobHandle->m_contents)), true); + graf->DrawString(itemPos, PLPasStr(static_cast(menu->stringBlobHandle->m_contents)), true, barHighlightTextColor); } } @@ -1373,19 +1377,21 @@ namespace PortabilityLayer QDState *qdState = qdManager->GetState(); - qdState->SetForeColor(gs_barMidColor); + ResolveCachingColor barMidColor = gs_barMidColor; { const Rect rect = Rect::Create(0, 0, menu->layoutFinalHeight, menu->layoutWidth); - surface->FillRect(rect); + surface->FillRect(rect, barMidColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(0, 0, 1, menu->layoutWidth - 1)); - surface->FillRect(Rect::Create(1, 0, menu->layoutFinalHeight - 1, 1)); + ResolveCachingColor whiteColor = StdColors::White(); - surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(1, menu->layoutWidth - 1, menu->layoutFinalHeight, menu->layoutWidth)); - surface->FillRect(Rect::Create(menu->layoutFinalHeight - 1, 1, menu->layoutFinalHeight, menu->layoutWidth - 1)); + surface->FillRect(Rect::Create(0, 0, 1, menu->layoutWidth - 1), whiteColor); + surface->FillRect(Rect::Create(1, 0, menu->layoutFinalHeight - 1, 1), whiteColor); + + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + + surface->FillRect(Rect::Create(1, menu->layoutWidth - 1, menu->layoutFinalHeight, menu->layoutWidth), darkGrayColor); + surface->FillRect(Rect::Create(menu->layoutFinalHeight - 1, 1, menu->layoutFinalHeight, menu->layoutWidth - 1), darkGrayColor); } m_menuGraf->SetSystemFont(kMenuFontSize, PortabilityLayer::FontFamilyFlag_Bold); @@ -1403,21 +1409,23 @@ namespace PortabilityLayer if (ItemIsSeparator(*menu, item)) { - surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(item.layoutYOffset + 2, 0, item.layoutYOffset + 3, menu->layoutWidth)); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(item.layoutYOffset + 3, 0, item.layoutYOffset + 4, menu->layoutWidth)); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + surface->FillRect(Rect::Create(item.layoutYOffset + 2, 0, item.layoutYOffset + 3, menu->layoutWidth), darkGrayColor); + ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(Rect::Create(item.layoutYOffset + 3, 0, item.layoutYOffset + 4, menu->layoutWidth), whiteColor); } else { itemPos.v = item.layoutYOffset + kMenuItemTextYOffset; - if (item.enabled) - qdState->SetForeColor(gs_barNormalTextColor); - else - qdState->SetForeColor(gs_barDisabledTextColor); + ResolveCachingColor itemTextAndCheckColor; - surface->DrawString(itemPos, PLPasStr(strBlob + item.nameOffsetInStringBlob), true); + if (item.enabled) + itemTextAndCheckColor = gs_barNormalTextColor; + else + itemTextAndCheckColor = gs_barDisabledTextColor; + + surface->DrawString(itemPos, PLPasStr(strBlob + item.nameOffsetInStringBlob), true, itemTextAndCheckColor); if (item.key) { @@ -1425,38 +1433,39 @@ namespace PortabilityLayer uint8_t hintText[kHintTextCapacity]; const size_t hintLength = FormatHintText(hintText, item.key); - surface->DrawString(hintPos, PLPasStr(hintLength, reinterpret_cast(hintText)), true); + surface->DrawString(hintPos, PLPasStr(hintLength, reinterpret_cast(hintText)), true, itemTextAndCheckColor); } if (item.checked) - surface->FillRect(Rect::Create(item.layoutYOffset + kMenuItemCheckTopOffset, kMenuItemCheckLeftOffset, item.layoutYOffset + kMenuItemCheckBottomOffset, kMenuItemCheckRightOffset)); + surface->FillRect(Rect::Create(item.layoutYOffset + kMenuItemCheckTopOffset, kMenuItemCheckLeftOffset, item.layoutYOffset + kMenuItemCheckBottomOffset, kMenuItemCheckRightOffset), itemTextAndCheckColor); } } if (m_haveItem) { const MenuItem &selectedItem = menu->menuItems[m_itemIndex]; - qdState->SetForeColor(gs_barHighlightMidColor); const Rect itemRect = Rect::Create(selectedItem.layoutYOffset, 0, selectedItem.layoutYOffset + selectedItem.layoutHeight, menu->layoutWidth); - surface->FillRect(itemRect); - qdState->SetForeColor(gs_barHighlightBrightColor); - surface->FillRect(Rect::Create(itemRect.top, 0, itemRect.bottom, 1)); + PortabilityLayer::ResolveCachingColor barHighlightMidColor = gs_barHighlightMidColor; + surface->FillRect(itemRect, barHighlightMidColor); + + ResolveCachingColor barHighlightBrightColor = gs_barHighlightBrightColor; + surface->FillRect(Rect::Create(itemRect.top, 0, itemRect.bottom, 1), barHighlightBrightColor); if (m_itemIndex == 0) - surface->FillRect(Rect::Create(0, 1, 1, itemRect.right - 1)); + surface->FillRect(Rect::Create(0, 1, 1, itemRect.right - 1), barHighlightBrightColor); - qdState->SetForeColor(gs_barHighlightDarkColor); - surface->FillRect(Rect::Create(itemRect.top, itemRect.right - 1, itemRect.bottom, itemRect.right)); + ResolveCachingColor barHighlightDarkColor = gs_barHighlightDarkColor; + surface->FillRect(Rect::Create(itemRect.top, itemRect.right - 1, itemRect.bottom, itemRect.right), barHighlightDarkColor); if (m_itemIndex == menu->numMenuItems - 1) - surface->FillRect(Rect::Create(itemRect.bottom - 1, 1, itemRect.bottom, itemRect.right - 1)); + surface->FillRect(Rect::Create(itemRect.bottom - 1, 1, itemRect.bottom, itemRect.right - 1), barHighlightDarkColor); - qdState->SetForeColor(gs_barHighlightTextColor); + ResolveCachingColor barHighlightTextColor = gs_barHighlightTextColor; const MenuItem &item = menu->menuItems[m_itemIndex]; itemPos.v = item.layoutYOffset + kMenuItemTextYOffset; - surface->DrawString(itemPos, PLPasStr(strBlob + item.nameOffsetInStringBlob), true); + surface->DrawString(itemPos, PLPasStr(strBlob + item.nameOffsetInStringBlob), true, barHighlightTextColor); if (item.key) { @@ -1464,10 +1473,10 @@ namespace PortabilityLayer uint8_t hintText[kHintTextCapacity]; const size_t hintLength = FormatHintText(hintText, item.key); - surface->DrawString(hintPos, PLPasStr(hintLength, reinterpret_cast(hintText)), true); + surface->DrawString(hintPos, PLPasStr(hintLength, reinterpret_cast(hintText)), true, barHighlightTextColor); if (item.checked) - surface->FillRect(Rect::Create(item.layoutYOffset + kMenuItemCheckTopOffset, kMenuItemCheckLeftOffset, item.layoutYOffset + kMenuItemCheckBottomOffset, kMenuItemCheckRightOffset)); + surface->FillRect(Rect::Create(item.layoutYOffset + kMenuItemCheckTopOffset, kMenuItemCheckLeftOffset, item.layoutYOffset + kMenuItemCheckBottomOffset, kMenuItemCheckRightOffset), barHighlightTextColor); } } diff --git a/PortabilityLayer/PLButtonWidget.cpp b/PortabilityLayer/PLButtonWidget.cpp index 8ea017a..56e3cd4 100644 --- a/PortabilityLayer/PLButtonWidget.cpp +++ b/PortabilityLayer/PLButtonWidget.cpp @@ -5,6 +5,7 @@ #include "PLTimeTaggedVOSEvent.h" #include "PLStandardColors.h" #include "FontFamily.h" +#include "ResolveCachingColor.h" #include "SimpleGraphic.h" #include @@ -410,39 +411,41 @@ namespace PortabilityLayer for (int i = 0; i < 3; i++) { + ResolveCachingColor color; + if (i == 0) - surface->SetForeColor(borderColor); + color = borderColor; if (i != 0) - surface->SetForeColor(leftStripeColors[i - 1]); + color = leftStripeColors[i - 1]; - surface->FillRect(Rect::Create(rect.top + 3, rect.left + i, rect.bottom - 3, rect.left + i + 1)); + surface->FillRect(Rect::Create(rect.top + 3, rect.left + i, rect.bottom - 3, rect.left + i + 1), color); if (i != 0) - surface->SetForeColor(rightStripeColors[i - 1]); + color = rightStripeColors[i - 1]; - surface->FillRect(Rect::Create(rect.top + 3, rect.right - 1 - i, rect.bottom - 3, rect.right - i)); + surface->FillRect(Rect::Create(rect.top + 3, rect.right - 1 - i, rect.bottom - 3, rect.right - i), color); if (i != 0) - surface->SetForeColor(topStripeColors[i - 1]); + color = topStripeColors[i - 1]; - surface->FillRect(Rect::Create(rect.top + i, rect.left + 3, rect.top + i + 1, rect.right - 3)); + surface->FillRect(Rect::Create(rect.top + i, rect.left + 3, rect.top + i + 1, rect.right - 3), color); if (i != 0) - surface->SetForeColor(bottomStripeColors[i - 1]); + color = bottomStripeColors[i - 1]; - surface->FillRect(Rect::Create(rect.bottom - 1 - i, rect.left + 3, rect.bottom - i, rect.right - 3)); + surface->FillRect(Rect::Create(rect.bottom - 1 - i, rect.left + 3, rect.bottom - i, rect.right - 3), color); } - surface->SetForeColor(centerColor); - surface->FillRect(rect.Inset(3, 3)); + ResolveCachingColor centerCacheColor = centerColor; + surface->FillRect(rect.Inset(3, 3), centerCacheColor); - surface->SetForeColor(textColor); + ResolveCachingColor textCacheColor = textColor; surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold); int32_t x = (m_rect.left + m_rect.right - static_cast(surface->MeasureString(m_text.ToShortStr()))) / 2; int32_t y = (m_rect.top + m_rect.bottom + static_cast(surface->MeasureFontAscender())) / 2; - surface->DrawString(Point::Create(x, y), m_text.ToShortStr(), true); + surface->DrawString(Point::Create(x, y), m_text.ToShortStr(), true, textCacheColor); } void ButtonWidget::DrawAsCheck(DrawSurface *surface, bool inverted) @@ -450,57 +453,55 @@ namespace PortabilityLayer if (!m_rect.IsValid()) return; - surface->SetForeColor(StdColors::White()); - surface->FillRect(m_rect); + ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(m_rect, whiteColor); uint16_t checkFrameSize = std::min(12, std::min(m_rect.Width(), m_rect.Height())); int16_t top = (m_rect.top + m_rect.bottom - static_cast(checkFrameSize)) / 2; const Rect checkRect = Rect::Create(top, m_rect.left, top + static_cast(checkFrameSize), m_rect.left + static_cast(checkFrameSize)); - RGBAColor checkColor; - RGBAColor checkEraseColor; - RGBAColor textColor; + ResolveCachingColor *checkColor = nullptr; + ResolveCachingColor *checkEraseColor = nullptr; + ResolveCachingColor *textColor = nullptr; + + ResolveCachingColor midGrayColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + ResolveCachingColor lightGrayColor = RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + ResolveCachingColor blackColor = StdColors::Black(); + if (!m_enabled) { - surface->SetForeColor(RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillRect(checkRect); - surface->SetForeColor(RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255)); - surface->FillRect(checkRect.Inset(1, 1)); + surface->FillRect(checkRect, midGrayColor); + surface->FillRect(checkRect.Inset(1, 1), lightGrayColor); - checkColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); - checkEraseColor = RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255); - textColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + checkColor = &midGrayColor; + checkEraseColor = &lightGrayColor; + textColor = &midGrayColor; } else if (inverted) { - surface->SetForeColor(StdColors::Black()); - surface->FillRect(checkRect); - surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(checkRect.Inset(1, 1)); + surface->FillRect(checkRect, blackColor); + surface->FillRect(checkRect.Inset(1, 1), darkGrayColor); - checkColor = StdColors::White(); - checkEraseColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); - textColor = StdColors::Black(); + checkColor = &whiteColor; + checkEraseColor = &darkGrayColor; + textColor = &blackColor; } else { - surface->SetForeColor(StdColors::Black()); - surface->FillRect(checkRect); - surface->SetForeColor(RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillRect(checkRect.Inset(1, 1)); + surface->FillRect(checkRect, blackColor); + surface->FillRect(checkRect.Inset(1, 1), midGrayColor); - surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(checkRect.top + 2, checkRect.right - 2, checkRect.bottom - 2, checkRect.right - 1)); - surface->FillRect(Rect::Create(checkRect.bottom - 2, checkRect.left + 2, checkRect.bottom - 1, checkRect.right - 1)); + surface->FillRect(Rect::Create(checkRect.top + 2, checkRect.right - 2, checkRect.bottom - 2, checkRect.right - 1), darkGrayColor); + surface->FillRect(Rect::Create(checkRect.bottom - 2, checkRect.left + 2, checkRect.bottom - 1, checkRect.right - 1), darkGrayColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(checkRect.top + 1, checkRect.left + 1, checkRect.top + 2, checkRect.right - 2)); - surface->FillRect(Rect::Create(checkRect.top + 2, checkRect.left + 1, checkRect.bottom - 2, checkRect.left + 2)); + surface->FillRect(Rect::Create(checkRect.top + 1, checkRect.left + 1, checkRect.top + 2, checkRect.right - 2), whiteColor); + surface->FillRect(Rect::Create(checkRect.top + 2, checkRect.left + 1, checkRect.bottom - 2, checkRect.left + 2), whiteColor); - checkColor = StdColors::Black(); - checkEraseColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); - textColor = StdColors::Black(); + checkColor = &blackColor; + checkEraseColor = &midGrayColor; + textColor = &blackColor; } if (m_state) @@ -509,22 +510,19 @@ namespace PortabilityLayer if (checkmarkRect.IsValid()) { - surface->SetForeColor(checkColor); - surface->FillRect(checkmarkRect); + surface->FillRect(checkmarkRect, *checkColor); if (checkmarkRect.Width() >= 5) { int32_t eraseSpan = checkmarkRect.Width() - 4; int16_t coordinateOffset = 0; - surface->SetForeColor(checkEraseColor); - while (eraseSpan > 0) { - surface->FillRect(Rect::Create(checkmarkRect.top + coordinateOffset, checkmarkRect.left + 2 + coordinateOffset, checkmarkRect.top + 1 + coordinateOffset, checkmarkRect.right - 2 - coordinateOffset)); - surface->FillRect(Rect::Create(checkmarkRect.top + 2 + coordinateOffset, checkmarkRect.left + coordinateOffset, checkmarkRect.bottom - 2 - coordinateOffset, checkmarkRect.left + 1 + coordinateOffset)); - surface->FillRect(Rect::Create(checkmarkRect.bottom - 1 - coordinateOffset, checkmarkRect.left + 2 + coordinateOffset, checkmarkRect.bottom - coordinateOffset, checkmarkRect.right - 2 - coordinateOffset)); - surface->FillRect(Rect::Create(checkmarkRect.top + 2 + coordinateOffset, checkmarkRect.right - 1 - coordinateOffset, checkmarkRect.bottom - 2 - coordinateOffset, checkmarkRect.right - coordinateOffset)); + surface->FillRect(Rect::Create(checkmarkRect.top + coordinateOffset, checkmarkRect.left + 2 + coordinateOffset, checkmarkRect.top + 1 + coordinateOffset, checkmarkRect.right - 2 - coordinateOffset), *checkEraseColor); + surface->FillRect(Rect::Create(checkmarkRect.top + 2 + coordinateOffset, checkmarkRect.left + coordinateOffset, checkmarkRect.bottom - 2 - coordinateOffset, checkmarkRect.left + 1 + coordinateOffset), *checkEraseColor); + surface->FillRect(Rect::Create(checkmarkRect.bottom - 1 - coordinateOffset, checkmarkRect.left + 2 + coordinateOffset, checkmarkRect.bottom - coordinateOffset, checkmarkRect.right - 2 - coordinateOffset), *checkEraseColor); + surface->FillRect(Rect::Create(checkmarkRect.top + 2 + coordinateOffset, checkmarkRect.right - 1 - coordinateOffset, checkmarkRect.bottom - 2 - coordinateOffset, checkmarkRect.right - coordinateOffset), *checkEraseColor); eraseSpan -= 2; coordinateOffset++; @@ -533,11 +531,9 @@ namespace PortabilityLayer } } - surface->SetForeColor(textColor); - surface->SetSystemFont(12, FontFamilyFlag_Bold); int32_t textV = (m_rect.top + m_rect.bottom + surface->MeasureFontAscender()) / 2; - surface->DrawString(Point::Create(m_rect.left + checkFrameSize + 2, textV), m_text.ToShortStr(), true); + surface->DrawString(Point::Create(m_rect.left + checkFrameSize + 2, textV), m_text.ToShortStr(), true, *textColor); } @@ -546,42 +542,44 @@ namespace PortabilityLayer if (!m_rect.IsValid()) return; - surface->SetForeColor(StdColors::White()); - surface->FillRect(m_rect); + ResolveCachingColor whiteColor = StdColors::White(); + ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRect(m_rect, whiteColor); uint16_t checkFrameSize = std::min(12, std::min(m_rect.Width(), m_rect.Height())); int16_t top = (m_rect.top + m_rect.bottom - static_cast(checkFrameSize)) / 2; const Rect checkRect = Rect::Create(top, m_rect.left, top + static_cast(checkFrameSize), m_rect.left + static_cast(checkFrameSize)); - RGBAColor radioColor; - RGBAColor textColor; + ResolveCachingColor *radioColor = nullptr; + ResolveCachingColor *textColor = nullptr; + + ResolveCachingColor midGrayColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + ResolveCachingColor lightGrayColor = RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + if (!m_enabled) { - surface->SetForeColor(RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillEllipse(checkRect); - surface->SetForeColor(RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255)); - surface->FillEllipse(checkRect.Inset(1, 1)); + surface->FillEllipse(checkRect, midGrayColor); + surface->FillEllipse(checkRect.Inset(1, 1), lightGrayColor); - radioColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); - textColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + radioColor = &midGrayColor; + textColor = &midGrayColor; } else if (inverted) { - surface->SetForeColor(StdColors::Black()); - surface->FillEllipse(checkRect); - surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillEllipse(checkRect.Inset(1, 1)); + surface->FillEllipse(checkRect, blackColor); + surface->FillEllipse(checkRect.Inset(1, 1), darkGrayColor); - radioColor = StdColors::Black(); - textColor = StdColors::Black(); + radioColor = &blackColor; + textColor = &blackColor; } else { gs_buttonRadioGraphic.DrawToPixMapWithMask(surface->m_port.GetPixMap(), gs_buttonRadioGraphicMask, checkRect.left, checkRect.top); - radioColor = StdColors::Black(); - textColor = StdColors::Black(); + radioColor = &blackColor; + textColor = &blackColor; } if (m_state) @@ -590,16 +588,13 @@ namespace PortabilityLayer if (checkmarkRect.IsValid()) { - surface->SetForeColor(radioColor); - surface->FillEllipse(checkmarkRect); + surface->FillEllipse(checkmarkRect, *radioColor); } } - surface->SetForeColor(textColor); - surface->SetSystemFont(12, FontFamilyFlag_Bold); int32_t textV = (m_rect.top + m_rect.bottom + surface->MeasureFontAscender()) / 2; - surface->DrawString(Point::Create(m_rect.left + checkFrameSize + 2, textV), m_text.ToShortStr(), true); + surface->DrawString(Point::Create(m_rect.left + checkFrameSize + 2, textV), m_text.ToShortStr(), true, *textColor); } void ButtonWidget::DrawDefaultButtonChrome(const Rect &rectRef, DrawSurface *surface) @@ -629,16 +624,16 @@ namespace PortabilityLayer for (int i = 0; i < 3; i++) { - surface->SetForeColor(upperLeftStripeColors[i]); - surface->FillRect(Rect::Create(rect.top - 1 - i, rect.left + 2, rect.top - i, rect.right - 2)); - surface->FillRect(Rect::Create(rect.top + 2, rect.left - 1 - i, rect.bottom - 2, rect.left - i)); + ResolveCachingColor color = upperLeftStripeColors[i]; + surface->FillRect(Rect::Create(rect.top - 1 - i, rect.left + 2, rect.top - i, rect.right - 2), color); + surface->FillRect(Rect::Create(rect.top + 2, rect.left - 1 - i, rect.bottom - 2, rect.left - i), color); } for (int i = 0; i < 3; i++) { - surface->SetForeColor(bottomRightStripeColors[i]); - surface->FillRect(Rect::Create(rect.bottom + i, rect.left + 2, rect.bottom + i + 1, rect.right - 2)); - surface->FillRect(Rect::Create(rect.top + 2, rect.right + i, rect.bottom - 2, rect.right + i + 1)); + ResolveCachingColor color = bottomRightStripeColors[i]; + surface->FillRect(Rect::Create(rect.bottom + i, rect.left + 2, rect.bottom + i + 1, rect.right - 2), color); + surface->FillRect(Rect::Create(rect.top + 2, rect.right + i, rect.bottom - 2, rect.right + i + 1), color); } } diff --git a/PortabilityLayer/PLDialogs.cpp b/PortabilityLayer/PLDialogs.cpp index 59664b9..e5dcaad 100644 --- a/PortabilityLayer/PLDialogs.cpp +++ b/PortabilityLayer/PLDialogs.cpp @@ -5,6 +5,7 @@ #include "PLPasStr.h" #include "PLEditboxWidget.h" #include "PLStandardColors.h" +#include "ResolveCachingColor.h" DialogTextSubstitutions::DialogTextSubstitutions() @@ -117,7 +118,8 @@ void HideDialogItem(Dialog *dialog, int item) widget->SetVisible(false); DrawSurface *surface = dialog->GetWindow()->GetDrawSurface(); - surface->SetForeColor(StdColors::White()); - surface->FillRect(widget->GetExpandedRect()); + + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(widget->GetExpandedRect(), whiteColor); } } diff --git a/PortabilityLayer/PLEditboxWidget.cpp b/PortabilityLayer/PLEditboxWidget.cpp index 6532ed9..a0dda11 100644 --- a/PortabilityLayer/PLEditboxWidget.cpp +++ b/PortabilityLayer/PLEditboxWidget.cpp @@ -10,6 +10,7 @@ #include "PLKeyEncoding.h" #include "PLStandardColors.h" #include "PLTimeTaggedVOSEvent.h" +#include "ResolveCachingColor.h" #include "TextPlacer.h" #include @@ -59,14 +60,15 @@ namespace PortabilityLayer if (!m_visible) return; + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor whiteColor = StdColors::White(); + const Rect textRect = m_rect; const Rect innerRect = textRect.Inset(-2, -2); const Rect outerRect = innerRect.Inset(-1, -1); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(outerRect); - surface->SetForeColor(StdColors::White()); - surface->FillRect(innerRect); + surface->FillRect(outerRect, blackColor); + surface->FillRect(innerRect, whiteColor); surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_None); int32_t ascender = surface->MeasureFontAscender(); @@ -87,14 +89,12 @@ namespace PortabilityLayer int32_t verticalOffset = (ascender + lineGap + 1) / 2; - surface->SetForeColor(StdColors::Black()); - const Point stringBasePoint = Point::Create(basePoint.m_x, basePoint.m_y + verticalOffset); if (m_isMultiLine) - surface->DrawStringWrap(stringBasePoint, m_rect, this->GetString(), true); + surface->DrawStringWrap(stringBasePoint, m_rect, this->GetString(), true, blackColor); else - surface->DrawStringConstrained(stringBasePoint, this->GetString(), true, m_rect); + surface->DrawStringConstrained(stringBasePoint, this->GetString(), true, m_rect, blackColor); if (m_hasFocus && m_selEndChar == m_selStartChar && m_caratTimer < kCaratBlinkRate) { @@ -107,7 +107,7 @@ namespace PortabilityLayer caratRect = caratRect.Intersect(m_rect); if (caratRect.IsValid()) - surface->FillRect(caratRect); + surface->FillRect(caratRect, blackColor); } } @@ -725,8 +725,7 @@ namespace PortabilityLayer return; } - PortabilityLayer::RGBAColor focusColor = PortabilityLayer::RGBAColor::Create(153, 153, 255, 255); - surface->SetForeColor(focusColor); + ResolveCachingColor focusColor = RGBAColor::Create(153, 153, 255, 255); int32_t lineGap = rfont->GetMetrics().m_linegap; int32_t ascender = rfont->GetMetrics().m_ascent; @@ -738,21 +737,21 @@ namespace PortabilityLayer if (endIsLineBreak || (m_isMultiLine == false && m_selEndChar == m_length)) selRect.right = m_rect.right; - surface->FillRect(selRect); + surface->FillRect(selRect, focusColor); } else { const Rect firstLineRect = Rect::Create(globalSelStart.m_y, globalSelStart.m_x, globalSelStart.m_y + lineGap, m_rect.right).Intersect(m_rect); - surface->FillRect(firstLineRect); + surface->FillRect(firstLineRect, focusColor); const Rect midLinesRect = Rect::Create(globalSelStart.m_y + lineGap, m_rect.left, globalSelEnd.m_y, m_rect.right).Intersect(m_rect); - surface->FillRect(midLinesRect); + surface->FillRect(midLinesRect, focusColor); Rect lastLineRect = Rect::Create(globalSelEnd.m_y, m_rect.left, globalSelEnd.m_y + lineGap, globalSelEnd.m_x); if (endIsLineBreak || (m_isMultiLine == false && m_selEndChar == m_length)) lastLineRect.right = m_rect.right; - surface->FillRect(lastLineRect); + surface->FillRect(lastLineRect, focusColor); } } diff --git a/PortabilityLayer/PLLabelWidget.cpp b/PortabilityLayer/PLLabelWidget.cpp index e5a8451..a718501 100644 --- a/PortabilityLayer/PLLabelWidget.cpp +++ b/PortabilityLayer/PLLabelWidget.cpp @@ -2,6 +2,7 @@ #include "PLQDraw.h" #include "FontFamily.h" #include "PLStandardColors.h" +#include "ResolveCachingColor.h" #include @@ -31,15 +32,16 @@ namespace PortabilityLayer void LabelWidget::DrawControl(DrawSurface *surface) { - surface->SetForeColor(StdColors::White()); - surface->FillRect(m_rect); + ResolveCachingColor whiteColor = StdColors::White(); + ResolveCachingColor blackColor = StdColors::Black(); + + surface->FillRect(m_rect, whiteColor); surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold); - surface->SetForeColor(StdColors::Black()); const Point topLeftCorner = Point::Create(m_rect.left, m_rect.top); const Point textStartPoint = topLeftCorner + Point::Create(0, surface->MeasureFontAscender()); - surface->DrawStringWrap(textStartPoint, m_rect, m_text.ToShortStr(), true); + surface->DrawStringWrap(textStartPoint, m_rect, m_text.ToShortStr(), true, blackColor); } } diff --git a/PortabilityLayer/PLPopupMenuWidget.cpp b/PortabilityLayer/PLPopupMenuWidget.cpp index 130d93f..9373338 100644 --- a/PortabilityLayer/PLPopupMenuWidget.cpp +++ b/PortabilityLayer/PLPopupMenuWidget.cpp @@ -5,6 +5,7 @@ #include "PLPasStr.h" #include "PLStandardColors.h" #include "PLTimeTaggedVOSEvent.h" +#include "ResolveCachingColor.h" #include "FontFamily.h" #include "Vec2i.h" @@ -75,23 +76,25 @@ namespace PortabilityLayer void PopupMenuWidget::DrawControl(DrawSurface *surface) { + + PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White(); + PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black(); + PortabilityLayer::ResolveCachingColor midGrayColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + PortabilityLayer::ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + const Rect rect = m_rect; const Rect innerRect = rect.Inset(2, 2); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(rect); + surface->FillRect(rect, blackColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(rect.Inset(1, 1)); + surface->FillRect(rect.Inset(1, 1), whiteColor); - surface->SetForeColor(RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillRect(rect.Inset(2, 2)); + surface->FillRect(rect.Inset(2, 2), midGrayColor); const Rect inset2Rect = rect.Inset(2, 2); - surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(inset2Rect.bottom, inset2Rect.left, inset2Rect.bottom + 1, inset2Rect.right + 1)); - surface->FillRect(Rect::Create(inset2Rect.top, inset2Rect.right, inset2Rect.bottom + 1, inset2Rect.right + 1)); + surface->FillRect(Rect::Create(inset2Rect.bottom, inset2Rect.left, inset2Rect.bottom + 1, inset2Rect.right + 1), darkGrayColor); + surface->FillRect(Rect::Create(inset2Rect.top, inset2Rect.right, inset2Rect.bottom + 1, inset2Rect.right + 1), darkGrayColor); Rect textRect = innerRect; @@ -100,8 +103,7 @@ namespace PortabilityLayer surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold); Point basePoint = Point::Create(textRect.left + 2, (textRect.top + textRect.bottom + surface->MeasureFontAscender() + 1) / 2 - 1); - surface->SetForeColor(StdColors::Black()); - surface->DrawStringConstrained(basePoint, GetString(), true, textRect); + surface->DrawStringConstrained(basePoint, GetString(), true, textRect, blackColor); Point arrowMidPoint = Point::Create(textRect.right + 5, (textRect.top + textRect.bottom + 1) / 2); @@ -116,7 +118,7 @@ namespace PortabilityLayer for (int i = 0; i < 4; i++) { const Rect constrainedRect = innerRect.Intersect(arrowRects[i]); - surface->FillRect(constrainedRect); + surface->FillRect(constrainedRect, blackColor); } } diff --git a/PortabilityLayer/PLQDraw.cpp b/PortabilityLayer/PLQDraw.cpp index 63520a8..1eb63ef 100644 --- a/PortabilityLayer/PLQDraw.cpp +++ b/PortabilityLayer/PLQDraw.cpp @@ -24,6 +24,7 @@ #include "ScanlineMaskIterator.h" #include "QDGraf.h" #include "QDStandardPalette.h" +#include "ResolveCachingColor.h" #include "TextPlacer.h" #include "WindowManager.h" #include "QDGraf.h" @@ -62,26 +63,7 @@ void SetPortWindowPort(WindowPtr window) PortabilityLayer::QDManager::GetInstance()->SetPort(window->GetDrawSurface()); } -void SetPortDialogPort(Dialog *dialog) -{ - PL_NotYetImplemented(); -} - -int TextWidth(const PLPasStr &str, int firstChar1Based, int length) -{ - PL_NotYetImplemented(); - return 0; -} - -void MoveTo(int x, int y) -{ - Point &penPos = PortabilityLayer::QDManager::GetInstance()->GetState()->m_penPos; - - penPos.h = x; - penPos.v = y; -} - -static void PlotLine(PortabilityLayer::QDState *qdState, DrawSurface *surface, const PortabilityLayer::Vec2i &pointA, const PortabilityLayer::Vec2i &pointB) +static void PlotLine(PortabilityLayer::QDState *qdState, DrawSurface *surface, const PortabilityLayer::Vec2i &pointA, const PortabilityLayer::Vec2i &pointB, PortabilityLayer::ResolveCachingColor &foreColor) { const Rect lineRect = Rect::Create( std::min(pointA.m_y, pointB.m_y), @@ -92,7 +74,7 @@ static void PlotLine(PortabilityLayer::QDState *qdState, DrawSurface *surface, c // If the points are a straight line, paint as a rect if (pointA.m_y == pointB.m_y || pointA.m_x == pointB.m_x) { - surface->FillRect(lineRect); + surface->FillRect(lineRect, foreColor); return; } @@ -141,7 +123,7 @@ static void PlotLine(PortabilityLayer::QDState *qdState, DrawSurface *surface, c case GpPixelFormats::k8BitStandard: { const size_t pixelSize = 1; - const uint8_t color = qdState->ResolveForeColor8(nullptr, 0); + const uint8_t color = foreColor.Resolve8(nullptr, 0); while (currentPoint.m_x >= constrainedRect.left && currentPoint.m_x < constrainedRect.right && currentPoint.m_y < constrainedRect.bottom) { @@ -200,14 +182,8 @@ static void PlotLine(PortabilityLayer::QDState *qdState, DrawSurface *surface, c surface->m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents); } -void GetForeColor(RGBColor *color) -{ - const PortabilityLayer::RGBAColor foreColor = PortabilityLayer::QDManager::GetInstance()->GetState()->GetForeColor(); - *color = RGBColor(foreColor.r, foreColor.g, foreColor.b); -} - static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const Rect &rect, const Point &penPos, const PortabilityLayer::RenderedFont *rfont, unsigned int character, - PortabilityLayer::AntiAliasTable *&cachedAATable, PortabilityLayer::RGBAColor &cachedAATableColor) + PortabilityLayer::AntiAliasTable *&cachedAATable, PortabilityLayer::RGBAColor &cachedAATableColor, PortabilityLayer::ResolveCachingColor &cacheColor) { assert(rect.IsValid()); @@ -254,12 +230,11 @@ static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const if (isAA) { - const PortabilityLayer::RGBAColor foreColor = qdState->GetForeColor(); - if (foreColor == PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)) + if (cacheColor.GetRGBAColor() == PortabilityLayer::RGBAColor::Create(0, 0, 0, 255)) aaTable = &PortabilityLayer::StandardPalette::GetInstance()->GetBlackAATable(); - else if (foreColor == PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)) + else if (cacheColor.GetRGBAColor() == PortabilityLayer::RGBAColor::Create(255, 255, 255, 255)) aaTable = &PortabilityLayer::StandardPalette::GetInstance()->GetWhiteAATable(); - else if (cachedAATable != nullptr && foreColor == cachedAATableColor) + else if (cachedAATable != nullptr && cacheColor.GetRGBAColor() == cachedAATableColor) aaTable = cachedAATable; else { @@ -270,14 +245,14 @@ static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const return; } - cachedAATableColor = foreColor; - cachedAATable->GenerateForPalette(foreColor, PortabilityLayer::StandardPalette::GetInstance()->GetColors(), 256); + cachedAATableColor = cacheColor.GetRGBAColor(); + cachedAATable->GenerateForPalette(cacheColor.GetRGBAColor(), PortabilityLayer::StandardPalette::GetInstance()->GetColors(), 256); aaTable = cachedAATable; } } - const uint8_t color = qdState->ResolveForeColor8(nullptr, 0); + const uint8_t color = cacheColor.Resolve8(nullptr, 0); for (uint32_t row = 0; row < numRows; row++) { const uint8_t *inputRowData = firstInputRowData + row * inputPitch; @@ -314,22 +289,22 @@ static void DrawGlyph(PortabilityLayer::QDState *qdState, PixMap *pixMap, const } static void DrawText(PortabilityLayer::TextPlacer &placer, PortabilityLayer::QDState *qdState, PixMap *pixMap, const Rect &rect, const PortabilityLayer::RenderedFont *rfont, - PortabilityLayer::AntiAliasTable *&cachedAATable, PortabilityLayer::RGBAColor &cachedAATableColor) + PortabilityLayer::AntiAliasTable *&cachedAATable, PortabilityLayer::RGBAColor &cachedAATableColor, PortabilityLayer::ResolveCachingColor &cacheColor) { PortabilityLayer::GlyphPlacementCharacteristics characteristics; while (placer.PlaceGlyph(characteristics)) { if (characteristics.m_haveGlyph) - DrawGlyph(qdState, pixMap, rect, Point::Create(characteristics.m_glyphStartPos.m_x, characteristics.m_glyphStartPos.m_y), rfont, characteristics.m_character, cachedAATable, cachedAATableColor); + DrawGlyph(qdState, pixMap, rect, Point::Create(characteristics.m_glyphStartPos.m_x, characteristics.m_glyphStartPos.m_y), rfont, characteristics.m_character, cachedAATable, cachedAATableColor, cacheColor); } } -void DrawSurface::DrawString(const Point &point, const PLPasStr &str, bool aa) +void DrawSurface::DrawString(const Point &point, const PLPasStr &str, bool aa, PortabilityLayer::ResolveCachingColor &cacheColor) { - DrawStringConstrained(point, str, aa, Rect::CreateLargest()); + DrawStringConstrained(point, str, aa, Rect::CreateLargest(), cacheColor); } -void DrawSurface::DrawStringConstrained(const Point &point, const PLPasStr &str, bool aa, const Rect &constraintRect) +void DrawSurface::DrawStringConstrained(const Point &point, const PLPasStr &str, bool aa, const Rect &constraintRect, PortabilityLayer::ResolveCachingColor &cacheColor) { PortabilityLayer::QDPort *port = &m_port; @@ -351,12 +326,12 @@ void DrawSurface::DrawStringConstrained(const Point &point, const PLPasStr &str, PortabilityLayer::TextPlacer placer(PortabilityLayer::Vec2i(point.h, point.v), -1, rfont, str); - DrawText(placer, qdState, pixMap, rect, rfont, m_cachedAATable, m_cachedAAColor); + DrawText(placer, qdState, pixMap, rect, rfont, m_cachedAATable, m_cachedAAColor, cacheColor); m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents); } -void DrawSurface::DrawStringWrap(const Point &point, const Rect &constrainRect, const PLPasStr &str, bool aa) +void DrawSurface::DrawStringWrap(const Point &point, const Rect &constrainRect, const PLPasStr &str, bool aa, PortabilityLayer::ResolveCachingColor &cacheColor) { PortabilityLayer::QDPort *port = &m_port; @@ -384,7 +359,7 @@ void DrawSurface::DrawStringWrap(const Point &point, const Rect &constrainRect, PortabilityLayer::TextPlacer placer(PortabilityLayer::Vec2i(point.h, point.v), areaRect.Width(), rfont, str); - DrawText(placer, qdState, pixMap, limitRect, rfont, m_cachedAATable, m_cachedAAColor); + DrawText(placer, qdState, pixMap, limitRect, rfont, m_cachedAATable, m_cachedAAColor, cacheColor); m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents); } @@ -780,7 +755,7 @@ PortabilityLayer::RenderedFont *DrawSurface::ResolveFont(bool aa) const return fontManager->GetRenderedFontFromFamily(fontFamily, fontSize, aa, fontVariationFlags); } -void DrawSurface::FillRect(const Rect &rect) +void DrawSurface::FillRect(const Rect &rect, PortabilityLayer::ResolveCachingColor &cacheColor) { if (!rect.IsValid()) return; @@ -809,7 +784,7 @@ void DrawSurface::FillRect(const Rect &rect) { case GpPixelFormats::k8BitStandard: { - const uint8_t color = qdState->ResolveForeColor8(nullptr, 0); + const uint8_t color = cacheColor.Resolve8(nullptr, 0); size_t scanlineIndex = 0; for (size_t ln = 0; ln < numLines; ln++) @@ -828,7 +803,7 @@ void DrawSurface::FillRect(const Rect &rect) m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents); } -void DrawSurface::FillRectWithMaskPattern8x8(const Rect &rect, const uint8_t *pattern) +void DrawSurface::FillRectWithMaskPattern8x8(const Rect &rect, const uint8_t *pattern, PortabilityLayer::ResolveCachingColor &cacheColor) { if (!rect.IsValid()) return; @@ -863,7 +838,7 @@ void DrawSurface::FillRectWithMaskPattern8x8(const Rect &rect, const uint8_t *pa { case GpPixelFormats::k8BitStandard: { - const uint8_t color = qdState->ResolveForeColor8(nullptr, 0); + const uint8_t color = cacheColor.Resolve8(nullptr, 0); uint8_t backColor = 0; size_t scanlineIndex = 0; @@ -915,52 +890,52 @@ void DrawSurface::SetSystemFont(int size, int variationFlags) qdState->m_fontVariationFlags = variationFlags; } -void DrawSurface::FillEllipse(const Rect &rect) +void DrawSurface::FillEllipse(const Rect &rect, PortabilityLayer::ResolveCachingColor &cacheColor) { if (!rect.IsValid() || rect.Width() < 1 || rect.Height() < 1) return; if (rect.Width() <= 2 || rect.Height() <= 2) { - FillRect(rect); + FillRect(rect, cacheColor); return; } PortabilityLayer::ScanlineMask *mask = PortabilityLayer::ScanlineMaskConverter::CompileEllipse(PortabilityLayer::Rect2i(rect.top, rect.left, rect.bottom, rect.right)); if (mask) { - FillScanlineMask(mask); + FillScanlineMask(mask, cacheColor); mask->Destroy(); } } -void DrawSurface::FillEllipseWithMaskPattern(const Rect &rect, const uint8_t *pattern) +void DrawSurface::FillEllipseWithMaskPattern(const Rect &rect, const uint8_t *pattern, PortabilityLayer::ResolveCachingColor &cacheColor) { if (!rect.IsValid() || rect.Width() < 1 || rect.Height() < 1) return; if (rect.Width() <= 2 || rect.Height() <= 2) { - FillRectWithMaskPattern8x8(rect, pattern); + FillRectWithMaskPattern8x8(rect, pattern, cacheColor); return; } PortabilityLayer::ScanlineMask *mask = PortabilityLayer::ScanlineMaskConverter::CompileEllipse(PortabilityLayer::Rect2i(rect.top, rect.left, rect.bottom, rect.right)); if (mask) { - FillScanlineMaskWithMaskPattern(mask, pattern); + FillScanlineMaskWithMaskPattern(mask, pattern, cacheColor); mask->Destroy(); } } -void DrawSurface::FrameEllipse(const Rect &rect) +void DrawSurface::FrameEllipse(const Rect &rect, PortabilityLayer::ResolveCachingColor &cacheColor) { if (!rect.IsValid()) return; if (rect.Width() <= 2 || rect.Height() <= 2) { - FillRect(rect); + FillRect(rect, cacheColor); return; } @@ -995,7 +970,7 @@ void DrawSurface::FrameEllipse(const Rect &rect) { case GpPixelFormats::k8BitStandard: { - const uint8_t color = qdState->ResolveForeColor8(nullptr, 0); + const uint8_t color = cacheColor.Resolve8(nullptr, 0); for (;;) { @@ -1037,12 +1012,12 @@ static void FillScanlineSpan(uint8_t *rowStart, size_t startCol, size_t endCol, } } -void DrawSurface::FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask) +void DrawSurface::FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask, PortabilityLayer::ResolveCachingColor &cacheColor) { - FillScanlineMaskWithMaskPattern(scanlineMask, nullptr); + FillScanlineMaskWithMaskPattern(scanlineMask, nullptr, cacheColor); } -void DrawSurface::FillScanlineMaskWithMaskPattern(const PortabilityLayer::ScanlineMask *scanlineMask, const uint8_t *pattern) +void DrawSurface::FillScanlineMaskWithMaskPattern(const PortabilityLayer::ScanlineMask *scanlineMask, const uint8_t *pattern, PortabilityLayer::ResolveCachingColor &cacheColor) { if (!scanlineMask) return; @@ -1082,7 +1057,7 @@ void DrawSurface::FillScanlineMaskWithMaskPattern(const PortabilityLayer::Scanli switch (pixMap->m_pixelFormat) { case GpPixelFormats::k8BitStandard: - foreColor8 = qdState->ResolveForeColor8(nullptr, 256); + foreColor8 = cacheColor.Resolve8(nullptr, 256); break; default: PL_NotYetImplemented(); @@ -1190,9 +1165,9 @@ void DrawSurface::FillScanlineMaskWithMaskPattern(const PortabilityLayer::Scanli } -void DrawSurface::DrawLine(const Point &a, const Point &b) +void DrawSurface::DrawLine(const Point &a, const Point &b, PortabilityLayer::ResolveCachingColor &cacheColor) { - PlotLine(m_port.GetState(), this, PortabilityLayer::Vec2i(a.h, a.v), PortabilityLayer::Vec2i(b.h, b.v)); + PlotLine(m_port.GetState(), this, PortabilityLayer::Vec2i(a.h, a.v), PortabilityLayer::Vec2i(b.h, b.v), cacheColor); } void GetClip(Rect *rect) @@ -1210,7 +1185,7 @@ void ClipRect(const Rect *rect) qdState->m_clipRect = *rect; } -void DrawSurface::FrameRect(const Rect &rect) +void DrawSurface::FrameRect(const Rect &rect, PortabilityLayer::ResolveCachingColor &cacheColor) { if (!rect.IsValid()) return; @@ -1219,7 +1194,7 @@ void DrawSurface::FrameRect(const Rect &rect) uint16_t height = rect.bottom - rect.top; if (width <= 2 || height <= 2) - FillRect(rect); + FillRect(rect, cacheColor); else { // This is stupid, especially in the vertical case, but oh well @@ -1227,28 +1202,28 @@ void DrawSurface::FrameRect(const Rect &rect) edgeRect = rect; edgeRect.right = edgeRect.left + 1; - FillRect(edgeRect); + FillRect(edgeRect, cacheColor); edgeRect = rect; edgeRect.left = edgeRect.right - 1; - FillRect(edgeRect); + FillRect(edgeRect, cacheColor); edgeRect = rect; edgeRect.bottom = edgeRect.top + 1; - FillRect(edgeRect); + FillRect(edgeRect, cacheColor); edgeRect = rect; edgeRect.top = edgeRect.bottom - 1; - FillRect(edgeRect); + FillRect(edgeRect, cacheColor); } m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents); } -void DrawSurface::FrameRoundRect(const Rect &rect, int quadrantWidth, int quadrantHeight) +void DrawSurface::FrameRoundRect(const Rect &rect, int quadrantWidth, int quadrantHeight, PortabilityLayer::ResolveCachingColor &cacheColor) { PL_NotYetImplemented_TODO("RoundRect"); - this->FrameRect(rect); + this->FrameRect(rect, cacheColor); } void DrawSurface::InvertFrameRect(const Rect &rect, const uint8_t *pattern) @@ -1305,8 +1280,6 @@ void DrawSurface::InvertFillRect(const Rect &rect, const uint8_t *pattern) { case GpPixelFormats::k8BitStandard: { - const uint8_t color = qdState->ResolveForeColor8(nullptr, 0); - size_t scanlineIndex = 0; for (size_t ln = 0; ln < numLines; ln++) { @@ -1330,21 +1303,6 @@ void DrawSurface::InvertFillRect(const Rect &rect, const uint8_t *pattern) m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents); } -void DrawSurface::SetForeColor(const PortabilityLayer::RGBAColor &color) -{ - m_port.GetState()->SetForeColor(color); -} - -const PortabilityLayer::RGBAColor &DrawSurface::GetForeColor() const -{ - return m_port.GetState()->GetForeColor(); -} - -void PenSize(int w, int h) -{ - PL_NotYetImplemented(); -} - void InsetRect(Rect *rect, int x, int y) { rect->left += x; diff --git a/PortabilityLayer/PLQDraw.h b/PortabilityLayer/PLQDraw.h index 12a1a03..2a540e5 100644 --- a/PortabilityLayer/PLQDraw.h +++ b/PortabilityLayer/PLQDraw.h @@ -61,7 +61,6 @@ typedef CIconPtr *CIconHandle; typedef Byte Pattern[8]; void SetPortWindowPort(WindowPtr window); -void SetPortDialogPort(Dialog *dialog); void SetPort(DrawSurface *graf); @@ -69,13 +68,9 @@ void EndUpdate(WindowPtr graf); void SetRect(Rect *rect, short left, short top, short right, short bottom); -int TextWidth(const PLPasStr &str, int firstChar1Based, int length); -void GetForeColor(RGBColor *color); - void ClipRect(const Rect *rect); void GetClip(Rect *rect); -void PenSize(int w, int h); void InsetRect(Rect *rect, int x, int y); Pattern *GetQDGlobalsGray(Pattern *pattern); Pattern *GetQDGlobalsBlack(Pattern *pattern); diff --git a/PortabilityLayer/PLScrollBarWidget.cpp b/PortabilityLayer/PLScrollBarWidget.cpp index a7e6efb..8152826 100644 --- a/PortabilityLayer/PLScrollBarWidget.cpp +++ b/PortabilityLayer/PLScrollBarWidget.cpp @@ -2,6 +2,7 @@ #include "PLControlDefinitions.h" #include "PLStandardColors.h" #include "PLTimeTaggedVOSEvent.h" +#include "ResolveCachingColor.h" namespace PortabilityLayer { @@ -40,8 +41,8 @@ namespace PortabilityLayer void ScrollBarWidget::DrawControl(DrawSurface *surface) { - surface->SetForeColor(StdColors::White()); - surface->FillRect(this->m_rect.Inset(1, 1)); + ResolveCachingColor whiteColor = StdColors::White(); + surface->FillRect(this->m_rect.Inset(1, 1), whiteColor); if (m_rect.Width() < 16 || m_rect.Height() < 16) return; @@ -54,43 +55,41 @@ namespace PortabilityLayer void ScrollBarWidget::DrawControlHorizontal(DrawSurface *surface) { - surface->SetForeColor(StdColors::Black()); - surface->FrameRect(m_rect); + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor whiteColor = StdColors::White(); + ResolveCachingColor midGrayColor = RGBAColor::Create(136, 136, 136, 255); + ResolveCachingColor lightGrayColor = RGBAColor::Create(187, 187, 187, 255); + + surface->FrameRect(m_rect, blackColor); const Rect leftArrowRect = Rect::Create(m_rect.top, m_rect.left, m_rect.bottom, m_rect.left + 16); DrawBeveledBox(surface, leftArrowRect); - surface->SetForeColor(StdColors::Black()); for (int i = 0; i < 4; i++) { const Rect arrowSegRect = Rect::Create(7 - i + leftArrowRect.top, 6 + i + leftArrowRect.left, 9 + i + leftArrowRect.top, 7 + i + leftArrowRect.left); - surface->FillRect(arrowSegRect); + surface->FillRect(arrowSegRect, blackColor); } const Rect rightArrowRect = Rect::Create(m_rect.top, m_rect.right - 16, m_rect.bottom, m_rect.right); DrawBeveledBox(surface, rightArrowRect); - surface->SetForeColor(StdColors::Black()); for (int i = 0; i < 4; i++) { const Rect arrowSegRect = Rect::Create(4 + i + rightArrowRect.top, 6 + i + rightArrowRect.left, 12 - i + rightArrowRect.top, 7 + i + rightArrowRect.left); - surface->FillRect(arrowSegRect); + surface->FillRect(arrowSegRect, blackColor); } const Rect laneRect = Rect::Create(m_rect.top, leftArrowRect.right, m_rect.bottom, rightArrowRect.left); - surface->SetForeColor(RGBAColor::Create(136, 136, 136, 255)); - surface->FillRect(Rect::Create(laneRect.top + 1, laneRect.left, laneRect.top + 2, laneRect.right)); + surface->FillRect(Rect::Create(laneRect.top + 1, laneRect.left, laneRect.top + 2, laneRect.right), midGrayColor); - surface->SetForeColor(RGBAColor::Create(187, 187, 187, 255)); - surface->FillRect(Rect::Create(laneRect.top + 2, laneRect.left, laneRect.bottom - 2, laneRect.right)); + surface->FillRect(Rect::Create(laneRect.top + 2, laneRect.left, laneRect.bottom - 2, laneRect.right), lightGrayColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(laneRect.bottom - 2, laneRect.left, laneRect.bottom - 1, laneRect.right)); + surface->FillRect(Rect::Create(laneRect.bottom - 2, laneRect.left, laneRect.bottom - 1, laneRect.right), whiteColor); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(laneRect.top, laneRect.left, laneRect.top + 1, laneRect.right)); - surface->FillRect(Rect::Create(laneRect.bottom - 1, laneRect.left, laneRect.bottom, laneRect.right)); + surface->FillRect(Rect::Create(laneRect.top, laneRect.left, laneRect.top + 1, laneRect.right), blackColor); + surface->FillRect(Rect::Create(laneRect.bottom - 1, laneRect.left, laneRect.bottom, laneRect.right), blackColor); if (m_laneCapacity > 0) @@ -99,43 +98,38 @@ namespace PortabilityLayer void ScrollBarWidget::DrawControlVertical(DrawSurface *surface) { - surface->SetForeColor(StdColors::Black()); - surface->FrameRect(m_rect); + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor whiteColor = StdColors::White(); + ResolveCachingColor midGrayColor = RGBAColor::Create(136, 136, 136, 255); + ResolveCachingColor lightGrayColor = RGBAColor::Create(187, 187, 187, 255); + + surface->FrameRect(m_rect, blackColor); const Rect topArrowRect = Rect::Create(m_rect.top, m_rect.left, m_rect.top + 16, m_rect.right); DrawBeveledBox(surface, topArrowRect); - surface->SetForeColor(StdColors::Black()); for (int i = 0; i < 4; i++) { const Rect arrowSegRect = Rect::Create(6 + i + topArrowRect.top, 7 - i + topArrowRect.left, 7 + i + topArrowRect.top, 9 + i + topArrowRect.left); - surface->FillRect(arrowSegRect); + surface->FillRect(arrowSegRect, blackColor); } const Rect bottomArrowRect = Rect::Create(m_rect.bottom - 16, m_rect.left, m_rect.bottom, m_rect.right); DrawBeveledBox(surface, bottomArrowRect); - surface->SetForeColor(StdColors::Black()); for (int i = 0; i < 4; i++) { const Rect arrowSegRect = Rect::Create(6 + i + bottomArrowRect.top, 4 + i + bottomArrowRect.left, 7 + i + bottomArrowRect.top, 12 - i + bottomArrowRect.left); - surface->FillRect(arrowSegRect); + surface->FillRect(arrowSegRect, blackColor); } const Rect laneRect = Rect::Create(topArrowRect.bottom, m_rect.left, bottomArrowRect.top, m_rect.right); - surface->SetForeColor(RGBAColor::Create(136, 136, 136, 255)); - surface->FillRect(Rect::Create(laneRect.top, laneRect.left + 1, laneRect.bottom, laneRect.left + 2)); - - surface->SetForeColor(RGBAColor::Create(187, 187, 187, 255)); - surface->FillRect(Rect::Create(laneRect.top, laneRect.left + 2, laneRect.bottom, laneRect.right - 2)); - - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(laneRect.bottom, laneRect.right - 2, laneRect.bottom, laneRect.right - 1)); - - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(laneRect.top, laneRect.left, laneRect.bottom, laneRect.left + 1)); - surface->FillRect(Rect::Create(laneRect.top, laneRect.right - 1, laneRect.bottom, laneRect.right)); + surface->FillRect(Rect::Create(laneRect.top, laneRect.left + 1, laneRect.bottom, laneRect.left + 2), midGrayColor); + surface->FillRect(Rect::Create(laneRect.top, laneRect.left + 2, laneRect.bottom, laneRect.right - 2), lightGrayColor); + surface->FillRect(Rect::Create(laneRect.bottom, laneRect.right - 2, laneRect.bottom, laneRect.right - 1), whiteColor); + surface->FillRect(Rect::Create(laneRect.top, laneRect.left, laneRect.bottom, laneRect.left + 1), blackColor); + surface->FillRect(Rect::Create(laneRect.top, laneRect.right - 1, laneRect.bottom, laneRect.right), blackColor); if (m_laneCapacity > 0) DrawBeveledBox(surface, Rect::Create(laneRect.top + m_gripPos, laneRect.left, laneRect.top + m_gripPos + m_gripSize, laneRect.right)); @@ -143,19 +137,19 @@ namespace PortabilityLayer void ScrollBarWidget::DrawBeveledBox(DrawSurface *surface, const Rect &rect) { - surface->SetForeColor(StdColors::Black()); - surface->FrameRect(rect); + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor whiteColor = StdColors::White(); + ResolveCachingColor midGrayColor = RGBAColor::Create(136, 136, 136, 255); + ResolveCachingColor lightGrayColor = RGBAColor::Create(187, 187, 187, 255); - surface->SetForeColor(RGBAColor::Create(187, 187, 187, 187)); - surface->FillRect(rect.Inset(1, 1)); + surface->FrameRect(rect, blackColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2)); - surface->FillRect(Rect::Create(rect.top + 2, rect.left + 1, rect.bottom - 2, rect.left + 2)); + surface->FillRect(rect.Inset(1, 1), lightGrayColor); - surface->SetForeColor(RGBAColor::Create(136, 136, 136, 136)); - surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 1)); - surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom - 2, rect.right - 1)); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2), whiteColor); + surface->FillRect(Rect::Create(rect.top + 2, rect.left + 1, rect.bottom - 2, rect.left + 2), whiteColor); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 1), midGrayColor); + surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom - 2, rect.right - 1), midGrayColor); } bool ScrollBarWidget::IsHorizontal() const diff --git a/PortabilityLayer/PortabilityLayer.vcxproj b/PortabilityLayer/PortabilityLayer.vcxproj index 0725436..4a0b902 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj +++ b/PortabilityLayer/PortabilityLayer.vcxproj @@ -367,6 +367,7 @@ + diff --git a/PortabilityLayer/PortabilityLayer.vcxproj.filters b/PortabilityLayer/PortabilityLayer.vcxproj.filters index fb086ae..db80f7d 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj.filters +++ b/PortabilityLayer/PortabilityLayer.vcxproj.filters @@ -752,14 +752,17 @@ Source Files - - Header Files - Source Files Source Files + + Source Files + + + Source Files + \ No newline at end of file diff --git a/PortabilityLayer/QDGraf.h b/PortabilityLayer/QDGraf.h index bf6d92e..988f37a 100644 --- a/PortabilityLayer/QDGraf.h +++ b/PortabilityLayer/QDGraf.h @@ -13,6 +13,7 @@ namespace PortabilityLayer class FontFamily; struct RGBAColor; class RenderedFont; + class ResolveCachingColor; class ScanlineMask; } @@ -59,30 +60,27 @@ struct DrawSurface void PushToDDSurface(IGpDisplayDriver *displayDriver); - void FillRect(const Rect &rect); - void FillRectWithMaskPattern8x8(const Rect &rect, const uint8_t *pattern); - void FrameRect(const Rect &rect); - void FrameRoundRect(const Rect &rect, int quadrantWidth, int quadrantHeight); + void FillRect(const Rect &rect, PortabilityLayer::ResolveCachingColor &cacheColor); + void FillRectWithMaskPattern8x8(const Rect &rect, const uint8_t *pattern, PortabilityLayer::ResolveCachingColor &cacheColor); + void FrameRect(const Rect &rect, PortabilityLayer::ResolveCachingColor &cacheColor); + void FrameRoundRect(const Rect &rect, int quadrantWidth, int quadrantHeight, PortabilityLayer::ResolveCachingColor &cacheColor); void InvertFrameRect(const Rect &rect, const uint8_t *pattern); void InvertFillRect(const Rect &rect, const uint8_t *pattern); - void FillEllipse(const Rect &rect); - void FillEllipseWithMaskPattern(const Rect &rect, const uint8_t *pattern); - void FrameEllipse(const Rect &rect); + void FillEllipse(const Rect &rect, PortabilityLayer::ResolveCachingColor &cacheColor); + void FillEllipseWithMaskPattern(const Rect &rect, const uint8_t *pattern, PortabilityLayer::ResolveCachingColor &cacheColor); + void FrameEllipse(const Rect &rect, PortabilityLayer::ResolveCachingColor &cacheColor); - void FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask); - void FillScanlineMaskWithMaskPattern(const PortabilityLayer::ScanlineMask *scanlineMask, const uint8_t *pattern); + void FillScanlineMask(const PortabilityLayer::ScanlineMask *scanlineMask, PortabilityLayer::ResolveCachingColor &cacheColor); + void FillScanlineMaskWithMaskPattern(const PortabilityLayer::ScanlineMask *scanlineMask, const uint8_t *pattern, PortabilityLayer::ResolveCachingColor &cacheColor); - void DrawLine(const Point &a, const Point &b); - - void SetForeColor(const PortabilityLayer::RGBAColor &color); - const PortabilityLayer::RGBAColor &GetForeColor() const; + void DrawLine(const Point &a, const Point &b, PortabilityLayer::ResolveCachingColor &cacheColor); void SetApplicationFont(int size, int variationFlags); void SetSystemFont(int size, int variationFlags); - void DrawString(const Point &point, const PLPasStr &str, bool aa); - void DrawStringConstrained(const Point &point, const PLPasStr &str, bool aa, const Rect &constraintRect); - void DrawStringWrap(const Point &point, const Rect &constrainRect, const PLPasStr &str, bool aa); + void DrawString(const Point &point, const PLPasStr &str, bool aa, PortabilityLayer::ResolveCachingColor &cacheColor); + void DrawStringConstrained(const Point &point, const PLPasStr &str, bool aa, const Rect &constraintRect, PortabilityLayer::ResolveCachingColor &cacheColor); + void DrawStringWrap(const Point &point, const Rect &constrainRect, const PLPasStr &str, bool aa, PortabilityLayer::ResolveCachingColor &cacheColor); size_t MeasureString(const PLPasStr &str); int32_t MeasureFontAscender(); diff --git a/PortabilityLayer/QDState.cpp b/PortabilityLayer/QDState.cpp index 3c99ebd..986f797 100644 --- a/PortabilityLayer/QDState.cpp +++ b/PortabilityLayer/QDState.cpp @@ -9,57 +9,7 @@ namespace PortabilityLayer : m_fontFamily(nullptr) , m_fontSize(12) , m_fontVariationFlags(0) - , m_foreResolvedColor16(0) - , m_backResolvedColor16(0) - , m_foreResolvedColor8(0) - , m_backResolvedColor8(0) - , m_isForeResolved16(false) - , m_isBackResolved16(false) - , m_isForeResolved8(false) - , m_isBackResolved8(false) , m_clipRect(Rect::Create(INT16_MIN, INT16_MIN, INT16_MAX, INT16_MAX)) { - m_backUnresolvedColor.r = m_backUnresolvedColor.g = m_backUnresolvedColor.b = m_backUnresolvedColor.a = 255; - m_foreUnresolvedColor.r = m_foreUnresolvedColor.g = m_foreUnresolvedColor.b = 0; - m_foreUnresolvedColor.a = 255; - m_penPos.h = m_penPos.v = 0; - } - - void QDState::SetForeColor(const RGBAColor &color) - { - m_foreUnresolvedColor = color; - m_isForeResolved16 = false; - m_isForeResolved8 = false; - } - - const RGBAColor &QDState::GetForeColor() const - { - return m_foreUnresolvedColor; - } - - uint8_t QDState::ResolveForeColor8(const RGBAColor *palette, unsigned int numColors) - { - return ResolveColor8(m_foreUnresolvedColor, m_foreResolvedColor8, m_isForeResolved8, palette, numColors); - } - - uint8_t QDState::ResolveColor8(const RGBAColor &color, uint8_t &cached, bool &isCached, const RGBAColor *palette, unsigned int numColors) - { - if (isCached) - return cached; - - if (palette) - { - PL_NotYetImplemented(); - return 0; - } - else - { - const uint8_t resolvedColor = StandardPalette::GetInstance()->MapColorLUT(color); - - isCached = true; - cached = resolvedColor; - - return resolvedColor; - } } } diff --git a/PortabilityLayer/QDState.h b/PortabilityLayer/QDState.h index 1b38135..7d8ff4b 100644 --- a/PortabilityLayer/QDState.h +++ b/PortabilityLayer/QDState.h @@ -15,28 +15,5 @@ namespace PortabilityLayer int m_fontVariationFlags; int m_fontSize; Rect m_clipRect; - Point m_penPos; - - void SetForeColor(const RGBAColor &color); - - const RGBAColor &GetForeColor() const; - - uint8_t ResolveForeColor8(const RGBAColor *palette, unsigned int numColors); - - private: - static uint8_t ResolveColor8(const RGBAColor &color, uint8_t &cached, bool &isCached, const RGBAColor *palette, unsigned int numColors); - - RGBAColor m_foreUnresolvedColor; - RGBAColor m_backUnresolvedColor; - - uint16_t m_foreResolvedColor16; - uint16_t m_backResolvedColor16; - uint8_t m_foreResolvedColor8; - uint8_t m_backResolvedColor8; - - bool m_isForeResolved16; - bool m_isForeResolved8; - bool m_isBackResolved16; - bool m_isBackResolved8; }; } diff --git a/PortabilityLayer/ResolveCachingColor.cpp b/PortabilityLayer/ResolveCachingColor.cpp new file mode 100644 index 0000000..57ad36b --- /dev/null +++ b/PortabilityLayer/ResolveCachingColor.cpp @@ -0,0 +1,75 @@ +#include "ResolveCachingColor.h" + +#include "PLCore.h" +#include "QDStandardPalette.h" + +namespace PortabilityLayer +{ + ResolveCachingColor::ResolveCachingColor() + : m_isResolved16(false) + , m_isResolved8(false) + , m_resolved16(0) + , m_resolved8(0) + , m_rgbaColor(RGBAColor::Create(0, 0, 0, 255)) + { + } + + ResolveCachingColor::ResolveCachingColor(const RGBAColor &color) + : m_isResolved16(false) + , m_isResolved8(false) + , m_resolved16(0) + , m_resolved8(0) + , m_rgbaColor(color) + { + } + + ResolveCachingColor::ResolveCachingColor(const ResolveCachingColor &color) + : m_isResolved16(color.m_isResolved16) + , m_isResolved8(color.m_isResolved8) + , m_resolved16(color.m_resolved16) + , m_resolved8(color.m_resolved8) + , m_rgbaColor(color.m_rgbaColor) + { + } + + uint8_t ResolveCachingColor::Resolve8(const RGBAColor *palette, unsigned int numColors) + { + if (m_isResolved8) + return m_resolved8; + + if (palette) + { + PL_NotYetImplemented(); + return 0; + } + else + { + const uint8_t resolvedColor = StandardPalette::GetInstance()->MapColorLUT(m_rgbaColor); + + m_isResolved8 = true; + m_resolved8 = resolvedColor; + + return resolvedColor; + } + } + + ResolveCachingColor &ResolveCachingColor::operator=(const ResolveCachingColor &other) + { + m_isResolved16 = other.m_isResolved16; + m_isResolved8 = other.m_isResolved8; + m_resolved16 = other.m_resolved16; + m_resolved8 = other.m_resolved8; + m_rgbaColor = other.m_rgbaColor; + + return *this; + } + + ResolveCachingColor ResolveCachingColor::FromStandardColor(uint8_t standardColor) + { + ResolveCachingColor result(StandardPalette::GetInstance()->GetColors()[standardColor]); + result.m_isResolved8 = true; + result.m_resolved8 = standardColor; + + return result; + } +} diff --git a/PortabilityLayer/ResolveCachingColor.h b/PortabilityLayer/ResolveCachingColor.h index b59cb2f..a53bf71 100644 --- a/PortabilityLayer/ResolveCachingColor.h +++ b/PortabilityLayer/ResolveCachingColor.h @@ -1,17 +1,24 @@ #pragma once -#include "RGBAColor.h" +#include "RGBAColor.h" namespace PortabilityLayer { class ResolveCachingColor { public: + ResolveCachingColor(); ResolveCachingColor(const RGBAColor &color); ResolveCachingColor(const ResolveCachingColor &color); uint8_t Resolve8(const RGBAColor *palette, unsigned int numColors); + ResolveCachingColor &operator=(const ResolveCachingColor &other); + + static ResolveCachingColor FromStandardColor(uint8_t standardColor); + + const RGBAColor &GetRGBAColor() const; + private: RGBAColor m_rgbaColor; @@ -22,3 +29,8 @@ namespace PortabilityLayer bool m_isResolved8; }; } + +inline const PortabilityLayer::RGBAColor &PortabilityLayer::ResolveCachingColor::GetRGBAColor() const +{ + return m_rgbaColor; +} diff --git a/PortabilityLayer/WindowManager.cpp b/PortabilityLayer/WindowManager.cpp index 4abf280..35f2c21 100644 --- a/PortabilityLayer/WindowManager.cpp +++ b/PortabilityLayer/WindowManager.cpp @@ -16,6 +16,7 @@ #include "QDPixMap.h" #include "PLTimeTaggedVOSEvent.h" #include "Rect2i.h" +#include "ResolveCachingColor.h" #include "Vec2i.h" #include "WindowDef.h" @@ -249,8 +250,8 @@ namespace PortabilityLayer void SimpleBoxChromeTheme::RenderChrome(WindowImpl *window, DrawSurface *surface, WindowChromeSide_t chromeSide) const { - surface->SetForeColor(StdColors::Black()); - surface->FillRect((*surface->m_port.GetPixMap())->m_rect); + ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRect((*surface->m_port.GetPixMap())->m_rect, blackColor); } //--------------------------------------------------------------------------- @@ -421,31 +422,31 @@ namespace PortabilityLayer void GenericWindowChromeTheme::RenderChromeTop(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + ResolveCachingColor midGrayColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + ResolveCachingColor whiteColor = StdColors::White(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillRect(rect); + surface->FillRect(rect, midGrayColor); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.left, rect.top + 1, rect.right)); - surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, 1)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); - surface->FillRect(Rect::Create(rect.bottom - 1, rect.left + 5, rect.bottom, rect.right - 5)); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.top + 1, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, 1), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.left + 5, rect.bottom, rect.right - 5), blackColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom - 1, rect.right - 5)); - surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom, rect.left + 5)); - surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom, rect.right - 1)); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom - 1, rect.right - 5), darkGrayColor); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom, rect.left + 5), darkGrayColor); + surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom, rect.right - 1), darkGrayColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.bottom, rect.left + 2)); - surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2)); - surface->FillRect(Rect::Create(rect.bottom - 1, rect.right - 5, rect.bottom, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.bottom, rect.left + 2), whiteColor); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2), whiteColor); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.right - 5, rect.bottom, rect.right - 4), whiteColor); if (window->GetStyleFlags() & WindowStyleFlags::kCloseBox) RenderChromeCloseBox(surface, rect, false); - surface->SetForeColor(StdColors::Black()); surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlags::FontFamilyFlag_Bold); int32_t ascender = surface->MeasureFontAscender(); @@ -455,98 +456,101 @@ namespace PortabilityLayer int32_t titleH = (rect.left + rect.right - static_cast(titleWidth) + 1) / 2; int32_t titleV = (rect.top + rect.bottom + ascender + 1) / 2; - surface->DrawString(Point::Create(titleH, titleV), titlePStr, true); + surface->DrawString(Point::Create(titleH, titleV), titlePStr, true, blackColor); } void GenericWindowChromeTheme::RenderChromeLeft(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + ResolveCachingColor midGrayColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + ResolveCachingColor whiteColor = StdColors::White(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4), whiteColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1)); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1), darkGrayColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2)); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2), midGrayColor); } void GenericWindowChromeTheme::RenderChromeBottom(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + ResolveCachingColor midGrayColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + ResolveCachingColor whiteColor = StdColors::White(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 1, rect.left + 5)); - surface->FillRect(Rect::Create(rect.bottom - 4, rect.left + 5, rect.bottom - 2, rect.right - 4)); - surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom - 2, rect.right - 2)); + surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 1, rect.left + 5), midGrayColor); + surface->FillRect(Rect::Create(rect.bottom - 4, rect.left + 5, rect.bottom - 2, rect.right - 4), midGrayColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom - 2, rect.right - 2), midGrayColor); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, rect.left + 1)); - surface->FillRect(Rect::Create(rect.bottom - 1, rect.left, rect.bottom, rect.right)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); - surface->FillRect(Rect::Create(rect.top, rect.left + 5, rect.bottom - 5, rect.left + 6)); - surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom - 5, rect.right - 5)); - surface->FillRect(Rect::Create(rect.bottom - 6, rect.left + 6, rect.bottom - 5, rect.right - 6)); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, rect.left + 1), blackColor); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.left, rect.bottom, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.left + 5, rect.bottom - 5, rect.left + 6), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom - 5, rect.right - 5), blackColor); + surface->FillRect(Rect::Create(rect.bottom - 6, rect.left + 6, rect.bottom - 5, rect.right - 6), blackColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom - 5, rect.right - 4)); - surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 2, rect.left + 2)); - surface->FillRect(Rect::Create(rect.bottom - 5, rect.left + 5, rect.bottom - 4, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom - 5, rect.right - 4), whiteColor); + surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 2, rect.left + 2), whiteColor); + surface->FillRect(Rect::Create(rect.bottom - 5, rect.left + 5, rect.bottom - 4, rect.right - 4), whiteColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 2)); - surface->FillRect(Rect::Create(rect.top, rect.left + 4, rect.bottom - 5, rect.left + 5)); - surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom - 1, rect.right - 1)); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 2), darkGrayColor); + surface->FillRect(Rect::Create(rect.top, rect.left + 4, rect.bottom - 5, rect.left + 5), darkGrayColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom - 1, rect.right - 1), darkGrayColor); } void GenericWindowChromeTheme::RenderChromeRight(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + ResolveCachingColor midGrayColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + ResolveCachingColor whiteColor = StdColors::White(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4), whiteColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1)); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1), darkGrayColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2)); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2), midGrayColor); } void GenericWindowChromeTheme::RenderChromeTopMini(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + ResolveCachingColor lightGrayColor = RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255); + ResolveCachingColor whiteColor = StdColors::White(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255)); - surface->FillRect(rect); + surface->FillRect(rect, lightGrayColor); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.left, rect.top + 1, rect.right)); - surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, 1)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); - surface->FillRect(Rect::Create(rect.bottom - 1, rect.left + 1, rect.bottom, rect.right - 1)); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.top + 1, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, 1), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.left + 1, rect.bottom, rect.right - 1), blackColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 2)); - surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom - 1, rect.right - 1)); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 2), darkGrayColor); + surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom - 1, rect.right - 1), darkGrayColor); - surface->SetForeColor(StdColors::White()); - surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.bottom - 2, rect.left + 2)); - surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2)); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.bottom - 2, rect.left + 2), whiteColor); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2), whiteColor); if (window->GetStyleFlags() & WindowStyleFlags::kCloseBox) RenderChromeCloseBox(surface, rect, false); - surface->SetForeColor(StdColors::Black()); surface->SetApplicationFont(10, PortabilityLayer::FontFamilyFlags::FontFamilyFlag_Bold); int32_t ascender = surface->MeasureFontAscender(); @@ -556,31 +560,31 @@ namespace PortabilityLayer int32_t titleH = (rect.left + rect.right - static_cast(titleWidth) + 1) / 2; int32_t titleV = (rect.top + rect.bottom + ascender + 1) / 2; - surface->DrawString(Point::Create(titleH, titleV), titlePStr, true); + surface->DrawString(Point::Create(titleH, titleV), titlePStr, true, blackColor); } void GenericWindowChromeTheme::RenderChromeLeftMini(WindowImpl *window, DrawSurface *surface) const { const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(rect); + ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRect(rect, blackColor); } void GenericWindowChromeTheme::RenderChromeBottomMini(WindowImpl *window, DrawSurface *surface) const { const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(rect); + ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRect(rect, blackColor); } void GenericWindowChromeTheme::RenderChromeRightMini(WindowImpl *window, DrawSurface *surface) const { const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(rect); + ResolveCachingColor blackColor = StdColors::Black(); + surface->FillRect(rect, blackColor); } Rect GenericWindowChromeTheme::GetCloseBoxRectInTopChrome() @@ -600,25 +604,25 @@ namespace PortabilityLayer if (isClicked) { - surface->SetForeColor(StdColors::Black()); - surface->FillRect(closeBoxRect); + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(closeBoxRect.top + 1, closeBoxRect.left + 1, closeBoxRect.bottom - 1, closeBoxRect.right - 1)); + surface->FillRect(closeBoxRect, blackColor); + + surface->FillRect(Rect::Create(closeBoxRect.top + 1, closeBoxRect.left + 1, closeBoxRect.bottom - 1, closeBoxRect.right - 1), darkGrayColor); } else { - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(closeBoxRect); + ResolveCachingColor darkGrayColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + ResolveCachingColor midGrayColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + ResolveCachingColor lightGrayColor = RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255); + surface->FillRect(closeBoxRect, darkGrayColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); - surface->FillRect(Rect::Create(closeBoxRect.top + 1, closeBoxRect.left + 1, closeBoxRect.bottom, closeBoxRect.right)); + surface->FillRect(Rect::Create(closeBoxRect.top + 1, closeBoxRect.left + 1, closeBoxRect.bottom, closeBoxRect.right), midGrayColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); - surface->FillRect(Rect::Create(closeBoxRect.top + 2, closeBoxRect.left + 2, closeBoxRect.bottom - 1, closeBoxRect.right - 1)); + surface->FillRect(Rect::Create(closeBoxRect.top + 2, closeBoxRect.left + 2, closeBoxRect.bottom - 1, closeBoxRect.right - 1), darkGrayColor); - surface->SetForeColor(PortabilityLayer::RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255)); - surface->FillRect(Rect::Create(closeBoxRect.top + 2, closeBoxRect.left + 2, closeBoxRect.bottom - 2, closeBoxRect.right - 2)); + surface->FillRect(Rect::Create(closeBoxRect.top + 2, closeBoxRect.left + 2, closeBoxRect.bottom - 2, closeBoxRect.right - 2), lightGrayColor); } } @@ -674,90 +678,94 @@ namespace PortabilityLayer void AlertWindowChromeTheme::RenderChromeTop(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor darkColor = kDarkColor; + ResolveCachingColor midColor = kMidColor; + ResolveCachingColor lightColor = kLightColor; + ResolveCachingColor blackColor = StdColors::Black(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(kMidColor); - surface->FillRect(rect); + surface->FillRect(rect, midColor); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.left, rect.top + 1, rect.right)); - surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, 1)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); - surface->FillRect(Rect::Create(rect.bottom - 1, rect.left + 5, rect.bottom, rect.right - 5)); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.top + 1, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, 1), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.left + 5, rect.bottom, rect.right - 5), blackColor); - surface->SetForeColor(kDarkColor); - surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom - 1, rect.right - 5)); - surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom, rect.left + 5)); - surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom, rect.right - 1)); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom - 1, rect.right - 5), darkColor); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom, rect.left + 5), darkColor); + surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom, rect.right - 1), darkColor); - surface->SetForeColor(kLightColor); - surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.bottom, rect.left + 2)); - surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2)); - surface->FillRect(Rect::Create(rect.bottom - 1, rect.right - 5, rect.bottom, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.bottom, rect.left + 2), lightColor); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2), lightColor); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.right - 5, rect.bottom, rect.right - 4), lightColor); } void AlertWindowChromeTheme::RenderChromeLeft(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor darkColor = kDarkColor; + ResolveCachingColor midColor = kMidColor; + ResolveCachingColor lightColor = kLightColor; + ResolveCachingColor blackColor = StdColors::Black(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); - surface->SetForeColor(kLightColor); - surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4), lightColor); - surface->SetForeColor(kDarkColor); - surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1)); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1), darkColor); - surface->SetForeColor(kMidColor); - surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2)); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2), midColor); } void AlertWindowChromeTheme::RenderChromeBottom(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor darkColor = kDarkColor; + ResolveCachingColor midColor = kMidColor; + ResolveCachingColor lightColor = kLightColor; + ResolveCachingColor blackColor = StdColors::Black(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(kMidColor); - surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 1, rect.left + 5)); - surface->FillRect(Rect::Create(rect.bottom - 4, rect.left + 5, rect.bottom - 2, rect.right - 4)); - surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom - 2, rect.right - 2)); + surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 1, rect.left + 5), midColor); + surface->FillRect(Rect::Create(rect.bottom - 4, rect.left + 5, rect.bottom - 2, rect.right - 4), midColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom - 2, rect.right - 2), midColor); - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, rect.left + 1)); - surface->FillRect(Rect::Create(rect.bottom - 1, rect.left, rect.bottom, rect.right)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); - surface->FillRect(Rect::Create(rect.top, rect.left + 5, rect.bottom - 5, rect.left + 6)); - surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom - 5, rect.right - 5)); - surface->FillRect(Rect::Create(rect.bottom - 6, rect.left + 6, rect.bottom - 5, rect.right - 6)); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, rect.left + 1), blackColor); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.left, rect.bottom, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.left + 5, rect.bottom - 5, rect.left + 6), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom - 5, rect.right - 5), blackColor); + surface->FillRect(Rect::Create(rect.bottom - 6, rect.left + 6, rect.bottom - 5, rect.right - 6), blackColor); - surface->SetForeColor(kLightColor); - surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom - 5, rect.right - 4)); - surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 2, rect.left + 2)); - surface->FillRect(Rect::Create(rect.bottom - 5, rect.left + 5, rect.bottom - 4, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom - 5, rect.right - 4), lightColor); + surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 2, rect.left + 2), lightColor); + surface->FillRect(Rect::Create(rect.bottom - 5, rect.left + 5, rect.bottom - 4, rect.right - 4), lightColor); - surface->SetForeColor(kDarkColor); - surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 2)); - surface->FillRect(Rect::Create(rect.top, rect.left + 4, rect.bottom - 5, rect.left + 5)); - surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom - 1, rect.right - 1)); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 2), darkColor); + surface->FillRect(Rect::Create(rect.top, rect.left + 4, rect.bottom - 5, rect.left + 5), darkColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom - 1, rect.right - 1), darkColor); } void AlertWindowChromeTheme::RenderChromeRight(WindowImpl *window, DrawSurface *surface) const { + ResolveCachingColor darkColor = kDarkColor; + ResolveCachingColor midColor = kMidColor; + ResolveCachingColor lightColor = kLightColor; + ResolveCachingColor blackColor = StdColors::Black(); + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; - surface->SetForeColor(StdColors::Black()); - surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5)); - surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5), blackColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right), blackColor); - surface->SetForeColor(kLightColor); - surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4), lightColor); - surface->SetForeColor(kDarkColor); - surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1)); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1), darkColor); - surface->SetForeColor(kMidColor); - surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2)); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2), midColor); } //--------------------------------------------------------------------------- @@ -1294,15 +1302,16 @@ namespace PortabilityLayer void WindowManagerImpl::SetResizeInProgress(Window *window, const PortabilityLayer::Vec2i &size) { + ResolveCachingColor blackColor = StdColors::Black(); + ResolveCachingColor whiteColor = StdColors::White(); + ResetResizeInProgressSurfaces(); m_isResizeInProgress = true; if (!m_resizeInProgressHorizontalBar.Init(Rect::Create(0, 0, 3, size.m_x + 4), GpPixelFormats::k8BitStandard)) { - m_resizeInProgressHorizontalBar.SetForeColor(StdColors::Black()); - m_resizeInProgressHorizontalBar.FillRect(Rect::Create(0, 0, 3, size.m_x + 4)); - m_resizeInProgressHorizontalBar.SetForeColor(StdColors::White()); - m_resizeInProgressHorizontalBar.FillRect(Rect::Create(1, 1, 2, size.m_x + 3)); + m_resizeInProgressHorizontalBar.FillRect(Rect::Create(0, 0, 3, size.m_x + 4), blackColor); + m_resizeInProgressHorizontalBar.FillRect(Rect::Create(1, 1, 2, size.m_x + 3), whiteColor); } else { @@ -1312,11 +1321,9 @@ namespace PortabilityLayer if (!m_resizeInProgressVerticalBar.Init(Rect::Create(0, 0, size.m_y, 3), GpPixelFormats::k8BitStandard)) { - m_resizeInProgressVerticalBar.SetForeColor(StdColors::Black()); - m_resizeInProgressVerticalBar.FillRect(Rect::Create(0, 0, size.m_y, 1)); - m_resizeInProgressVerticalBar.FillRect(Rect::Create(0, 2, size.m_y, 3)); - m_resizeInProgressVerticalBar.SetForeColor(StdColors::White()); - m_resizeInProgressVerticalBar.FillRect(Rect::Create(0, 1, size.m_y, 2)); + m_resizeInProgressVerticalBar.FillRect(Rect::Create(0, 0, size.m_y, 1), blackColor); + m_resizeInProgressVerticalBar.FillRect(Rect::Create(0, 2, size.m_y, 3), blackColor); + m_resizeInProgressVerticalBar.FillRect(Rect::Create(0, 1, size.m_y, 2), whiteColor); } else {