Files
Aerofoil/GpApp/ColorUtils.cpp

172 lines
6.4 KiB
C++
Raw Normal View History

2019-11-11 00:11:59 -05:00
//============================================================================
//----------------------------------------------------------------------------
// ColorUtils.c
//----------------------------------------------------------------------------
//============================================================================
#include "Externs.h"
#include "PLPasStr.h"
2019-12-30 20:53:11 -05:00
#include "QDStandardPalette.h"
2020-05-21 03:30:11 -04:00
#include "ResolveCachingColor.h"
2019-11-11 00:11:59 -05:00
//============================================================== Functions
//-------------------------------------------------------------- ColorText
// Given a string and a color index (index into the current palette),<2C>
// this function draws text in that color. It assumes the current port,<2C>
// the current font, the current pen location, etc.
2020-05-21 05:01:16 -04:00
void ColorText (DrawSurface *surface, const Point &point, StringPtr theStr, long color, PortabilityLayer::RenderedFont *font)
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color);
2019-12-30 20:53:11 -05:00
2020-05-21 05:01:16 -04:00
surface->DrawString(point, theStr, rColor, font);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- ColorRect
// Given a rectangle and color index, this function draws a solid<69>
// rectangle in that color. Current port, pen mode, etc. assumed.
2019-12-30 20:53:11 -05:00
void ColorRect (DrawSurface *surface, const Rect &theRect, long color)
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color);
2019-12-30 20:53:11 -05:00
2020-05-21 03:30:11 -04:00
surface->FillRect(theRect, rColor);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- ColorOval
// Given a rectangle and color index, this function draws a solid<69>
// oval in that color. Current port, pen mode, etc. assumed.
2019-12-30 20:53:11 -05:00
void ColorOval (DrawSurface *surface, const Rect &theRect, long color)
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color);
2019-12-30 20:53:11 -05:00
2020-05-21 03:30:11 -04:00
surface->FillEllipse(theRect, rColor);
2019-11-11 00:11:59 -05:00
}
2020-05-20 23:51:25 -04:00
void ColorOvalMaskPattern(DrawSurface *surface, const Rect &theRect, long color, const uint8_t *pattern)
2020-03-01 17:01:35 -05:00
{
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color);
2020-03-01 17:01:35 -05:00
2020-05-21 03:30:11 -04:00
surface->FillEllipseWithMaskPattern(theRect, pattern, rColor);
2020-03-01 17:01:35 -05:00
}
//-------------------------------------------------------------- ColorRegionMaskPattern
2019-11-11 00:11:59 -05:00
// Given a region and color index, this function draws a solid<69>
// region in that color. Current port, pen mode, etc. assumed.
2020-05-20 23:51:25 -04:00
void ColorRegionMaskPattern (DrawSurface *surface, PortabilityLayer::ScanlineMask *scanlineMask, long colorIndex, const uint8_t *pattern)
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(colorIndex);
surface->FillScanlineMaskWithMaskPattern(scanlineMask, pattern, rColor);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- ColorLine
// Given a the end points for a line and color index, this function<6F>
// draws a line in that color. Current port, pen mode, etc. assumed.
2019-12-30 20:53:11 -05:00
void ColorLine (DrawSurface *surface, short h0, short v0, short h1, short v1, long color)
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor cacheColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color);
2019-12-30 20:53:11 -05:00
2020-05-21 03:30:11 -04:00
surface->DrawLine(Point::Create(h0, v0), Point::Create(h1, v1), cacheColor);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- HiliteRect
// Given a rect and two hilite colors, this function frames the top and<6E>
// left edges of the rect with color 1 and frames the bottom and right<68>
// sides with color 2. A rect can be made to appear "hi-lit" or "3D"<22>
// in this way.
2019-12-30 20:53:11 -05:00
void HiliteRect (DrawSurface *surface, const Rect &theRect, short color1, short color2)
2019-11-11 00:11:59 -05:00
{
2019-12-30 20:53:11 -05:00
ColorLine(surface, theRect.left, theRect.top, theRect.right - 2,
theRect.top, color1);
ColorLine(surface, theRect.left, theRect.top, theRect.left,
theRect.bottom - 2, color1);
ColorLine(surface, theRect.right - 1, theRect.top, theRect.right - 1,
theRect.bottom - 2, color2);
ColorLine(surface, theRect.left + 1, theRect.bottom - 1, theRect.right - 1,
theRect.bottom - 1, color2);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- ColorFrameRect
// Given a rectangle and color index, this function frames a<>
// rectangle in that color. Current port, pen mode, etc. assumed.
2019-12-30 20:53:11 -05:00
void ColorFrameRect (DrawSurface *surface, const Rect &theRect, long color)
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color);
2019-12-30 20:53:11 -05:00
2020-05-21 03:30:11 -04:00
surface->FrameRect(theRect, rColor);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- ColorFrameWHRect
// Given a the top-left corner of a rectangle, its width and height,<2C>
// and a color index, this function frames a rectangle in that color.
// Current port, pen mode, etc. assumed.
2019-12-30 20:53:11 -05:00
void ColorFrameWHRect (DrawSurface *surface, short left, short top, short wide, short high, long color)
2019-11-11 00:11:59 -05:00
{
Rect theRect;
theRect.left = left;
theRect.top = top;
theRect.right = left + wide;
theRect.bottom = top + high;
2019-12-30 20:53:11 -05:00
ColorFrameRect(surface, theRect, color);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- ColorFrameOval
// Given a rectangle and color index, this function frames an<61>
// oval in that color. Current port, pen mode, etc. assumed.
2019-12-30 20:53:11 -05:00
void ColorFrameOval (DrawSurface *surface, const Rect &theRect, long color)
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor rColor = PortabilityLayer::ResolveCachingColor::FromStandardColor(color);
2019-12-30 20:53:11 -05:00
2020-05-21 03:30:11 -04:00
surface->FrameEllipse(theRect, rColor);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- LtGrayForeColor
// This function finds the closest match to a "light gray" in the<68>
// current palette and sets the pen color to that.
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor LtGrayForeColor ()
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
return PortabilityLayer::RGBAColor::Create(191, 191, 191, 255);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- GrayForeColor
// This function finds the closest match to a "medium gray" in the<68>
// current palette and sets the pen color to that.
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor GrayForeColor ()
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
return PortabilityLayer::RGBAColor::Create(127, 127, 127, 255);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- DkGrayForeColor
// This function finds the closest match to a "dark gray" in the<68>
// current palette and sets the pen color to that.
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor DkGrayForeColor ()
2019-11-11 00:11:59 -05:00
{
2020-05-21 03:30:11 -04:00
return PortabilityLayer::RGBAColor::Create(63, 63, 63, 255);
2019-11-11 00:11:59 -05:00
}