Files
Aerofoil/GpApp/ColorUtils.cpp

197 lines
7.4 KiB
C++
Raw Normal View History

2019-11-11 00:11:59 -05:00
//============================================================================
//----------------------------------------------------------------------------
// ColorUtils.c
//----------------------------------------------------------------------------
//============================================================================
#include "Externs.h"
#include "PLPalettes.h"
#include "PLPasStr.h"
2019-12-30 20:53:11 -05:00
#include "QDStandardPalette.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.
2019-12-30 20:53:11 -05:00
void ColorText (DrawSurface *surface, const Point &point, StringPtr theStr, long color)
2019-11-11 00:11:59 -05:00
{
2019-12-30 20:53:11 -05:00
const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color];
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(rgbaColor);
surface->DrawString(point, theStr, true);
2019-12-30 20:53:11 -05:00
surface->SetForeColor(wasColor);
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
{
2019-12-30 20:53:11 -05:00
const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color];
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(rgbaColor);
surface->FillRect(theRect);
surface->SetForeColor(wasColor);
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
{
2019-12-30 20:53:11 -05:00
const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color];
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(rgbaColor);
surface->FillEllipse(theRect);
surface->SetForeColor(wasColor);
2019-11-11 00:11:59 -05:00
}
2020-03-01 17:01:35 -05:00
void ColorOvalMaskPattern(DrawSurface *surface, const Rect &theRect, long color, bool isMask, const uint8_t *pattern)
{
const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color];
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(rgbaColor);
surface->FillEllipseWithPattern(theRect, isMask, pattern);
surface->SetForeColor(wasColor);
}
//-------------------------------------------------------------- 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-03-01 17:01:35 -05:00
void ColorRegionMaskPattern (DrawSurface *surface, PortabilityLayer::ScanlineMask *scanlineMask, long colorIndex, bool isMask, const uint8_t *pattern)
2019-11-11 00:11:59 -05:00
{
2019-12-30 20:53:11 -05:00
const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[colorIndex];
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(rgbaColor);
2020-03-01 17:01:35 -05:00
surface->FillScanlineMaskWithPattern(scanlineMask, isMask, pattern);
2019-12-30 20:53:11 -05:00
surface->SetForeColor(wasColor);
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
{
2019-12-30 20:53:11 -05:00
const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color];
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(rgbaColor);
surface->DrawLine(Point::Create(h0, v0), Point::Create(h1, v1));
surface->SetForeColor(wasColor);
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
{
2019-12-30 20:53:11 -05:00
const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color];
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(rgbaColor);
surface->FrameRect(theRect);
surface->SetForeColor(wasColor);
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
{
2019-12-30 20:53:11 -05:00
const PortabilityLayer::RGBAColor &rgbaColor = PortabilityLayer::StandardPalette::GetInstance()->GetColors()[color];
const PortabilityLayer::RGBAColor wasColor = surface->GetForeColor();
surface->SetForeColor(rgbaColor);
surface->FrameEllipse(theRect);
surface->SetForeColor(wasColor);
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.
2019-12-30 20:53:11 -05:00
void LtGrayForeColor (DrawSurface *surface)
2019-11-11 00:11:59 -05:00
{
2019-12-30 20:53:11 -05:00
surface->SetForeColor(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.
2019-12-30 20:53:11 -05:00
void GrayForeColor (DrawSurface *surface)
2019-11-11 00:11:59 -05:00
{
2019-12-30 20:53:11 -05:00
surface->SetForeColor(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.
2019-12-30 20:53:11 -05:00
void DkGrayForeColor (DrawSurface *surface)
2019-11-11 00:11:59 -05:00
{
2019-12-30 20:53:11 -05:00
surface->SetForeColor(PortabilityLayer::RGBAColor::Create(63, 63, 63, 255));
2019-11-11 00:11:59 -05:00
}