Merge pull request #25759 from Gymnasiast/refactor/some-palette-stuff

Refactor some palette stuff
This commit is contained in:
Michael Steenbeek authored and GitHub committed 2026-01-07 14:37:20 +01:00
commit 09dc9e9b43
29 files changed
+97 -174

No files matched your search

@@ -115,8 +115,10 @@ public:
void StartNewDraw();
void FinishDraw();
void Clear(RenderTarget& rt, uint8_t paletteIndex) override;
void FillRect(RenderTarget& rt, uint32_t colour, int32_t x, int32_t y, int32_t w, int32_t h) override;
void Clear(RenderTarget& rt, PaletteIndex paletteIndex) override;
void FillRect(
RenderTarget& rt, PaletteIndex paletteIndex, int32_t x, int32_t y, int32_t w, int32_t h,
bool crossHatch = false) override;
void FilterRect(
RenderTarget& rt, FilterPaletteID palette, int32_t left, int32_t top, int32_t right, int32_t bottom) override;
void DrawLine(RenderTarget& rt, uint32_t colour, const ScreenLine& line) override;
@@ -682,14 +684,15 @@ void OpenGLDrawingContext::FinishDraw()
_inDraw = false;
}
void OpenGLDrawingContext::Clear(RenderTarget& rt, uint8_t paletteIndex)
void OpenGLDrawingContext::Clear(RenderTarget& rt, PaletteIndex paletteIndex)
{
Guard::Assert(_inDraw == true);
FillRect(rt, paletteIndex, rt.x, rt.y, rt.x + rt.width, rt.y + rt.height);
}
void OpenGLDrawingContext::FillRect(RenderTarget& rt, uint32_t colour, int32_t left, int32_t top, int32_t right, int32_t bottom)
void OpenGLDrawingContext::FillRect(
RenderTarget& rt, PaletteIndex paletteIndex, int32_t left, int32_t top, int32_t right, int32_t bottom, bool crossHatch)
{
Guard::Assert(_inDraw == true);
@@ -708,22 +711,17 @@ void OpenGLDrawingContext::FillRect(RenderTarget& rt, uint32_t colour, int32_t l
command.texMaskAtlas = 0;
command.texMaskBounds = { 0.0f, 0.0f, 0.0f, 0.0f };
command.palettes = { 0, 0, 0 };
command.colour = colour & 0xFF;
command.colour = EnumValue(paletteIndex);
command.bounds = { left, top, right + 1, bottom + 1 };
command.flags = DrawRectCommand::FLAG_NO_TEXTURE;
command.depth = _drawCount++;
command.zoom = 1.0f;
if (colour & 0x1000000)
if (crossHatch)
{
// cross-pattern
command.flags |= DrawRectCommand::FLAG_CROSS_HATCH;
}
else if (colour & 0x2000000)
{
assert(false);
// Should be FilterRect
}
}
void OpenGLDrawingContext::FilterRect(
@@ -218,9 +218,10 @@ void TextureCache::GeneratePaletteTexture()
for (int i = 0; i < kPaletteTotalOffsets; ++i)
{
GLint y = PaletteToY(static_cast<FilterPaletteID>(i));
auto filterPaletteId = static_cast<FilterPaletteID>(i);
GLint y = PaletteToY(filterPaletteId);
auto g1Index = GetPaletteG1Index(i);
auto g1Index = GetPaletteG1Index(filterPaletteId);
if (g1Index.has_value())
{
const auto* element = GfxGetG1Element(g1Index.value());
+3 -3
View File
@@ -377,13 +377,13 @@ void InGameConsole::Draw(RenderTarget& rt) const
if (_consoleCaretTicks < kConsoleCaretFlashThreshold)
{
auto caret = screenCoords + ScreenCoordsXY{ _caretScreenPosX, lineHeight };
uint8_t caretColour = ColourMapA[textColour.colour].lightest;
auto caretColour = ColourMapA[textColour.colour].lightest;
Rectangle::fill(rt, { caret, caret + ScreenCoordsXY{ kConsoleCaretWidth, 1 } }, caretColour);
}
// What about border colours?
uint8_t borderColour1 = ColourMapA[backgroundColour.colour].light;
uint8_t borderColour2 = ColourMapA[backgroundColour.colour].mid_dark;
auto borderColour1 = ColourMapA[backgroundColour.colour].light;
auto borderColour2 = ColourMapA[backgroundColour.colour].mid_dark;
// Input area top border
Rectangle::fill(
+3 -3
View File
@@ -770,7 +770,7 @@ namespace OpenRCT2::Ui
// Trough
Rectangle::fill(rt, { { l + kScrollBarWidth, t }, { r - kScrollBarWidth, b } }, ColourMapA[colour.colour].lighter);
Rectangle::fill(
rt, { { l + kScrollBarWidth, t }, { r - kScrollBarWidth, b } }, 0x1000000 | ColourMapA[colour.colour].mid_dark);
rt, { { l + kScrollBarWidth, t }, { r - kScrollBarWidth, b } }, ColourMapA[colour.colour].mid_dark, true);
Rectangle::fill(
rt, { { l + kScrollBarWidth, t + 2 }, { r - kScrollBarWidth, t + 2 } }, ColourMapA[colour.colour].mid_dark);
Rectangle::fill(
@@ -817,7 +817,7 @@ namespace OpenRCT2::Ui
// Trough
Rectangle::fill(rt, { { l, t + kScrollBarWidth }, { r, b - kScrollBarWidth } }, ColourMapA[colour.colour].lighter);
Rectangle::fill(
rt, { { l, t + kScrollBarWidth }, { r, b - kScrollBarWidth } }, 0x1000000 | ColourMapA[colour.colour].mid_dark);
rt, { { l, t + kScrollBarWidth }, { r, b - kScrollBarWidth } }, ColourMapA[colour.colour].mid_dark, true);
Rectangle::fill(
rt, { { l + 2, t + kScrollBarWidth }, { l + 2, b - kScrollBarWidth } }, ColourMapA[colour.colour].mid_dark);
Rectangle::fill(
@@ -1211,7 +1211,7 @@ namespace OpenRCT2::Ui
{
auto colour = ColourMapA[w.colours[1].colour].mid_light;
auto y = topLeft.y + 1 + widget.height() - 5;
Rectangle::fill(rt, { { curX, y }, { curX + width, y } }, colour + 5);
Rectangle::fill(rt, { { curX, y }, { curX + width, y } }, static_cast<PaletteIndex>(colour + 5));
}
}
+1 -1
View File
@@ -610,7 +610,7 @@ void CustomListView::Paint(WindowBase* w, RenderTarget& rt, const ScrollArea* sc
{
Rectangle::fill(
rt, { { rt.x, y }, { rt.x + rt.width, y + (kListRowHeight - 1) } },
ColourMapA[w->colours[1].colour].lighter | 0x1000000);
ColourMapA[w->colours[1].colour].lighter, true);
}
// Columns
@@ -32,7 +32,7 @@ namespace OpenRCT2::Scripting
std::optional<colour_t> _tertiaryColour{};
std::optional<uint8_t> _paletteId{};
uint8_t _stroke{};
uint8_t _fill{};
PaletteIndex _fill{};
public:
ScGraphicsContext(duk_context* ctx, const RenderTarget& rt)
@@ -124,12 +124,12 @@ namespace OpenRCT2::Scripting
uint8_t fill_get() const
{
return _fill;
return EnumValue(_fill);
}
void fill_set(uint8_t value)
{
_fill = value;
_fill = static_cast<PaletteIndex>(value);
}
uint8_t stroke_get() const
@@ -230,7 +230,7 @@ namespace OpenRCT2::Scripting
width -= 2;
height -= 2;
}
if (_fill != 0)
if (_fill != PaletteIndex::pi0)
{
Rectangle::fill(_rt, { x, y, x + width - 1, y + height - 1 }, _fill);
}
@@ -275,7 +275,7 @@ namespace OpenRCT2::Ui::Windows
const auto& gameState = getGameState();
// Draw background
uint8_t paletteIndex = ColourMapA[colours[1].colour].mid_light;
auto paletteIndex = ColourMapA[colours[1].colour].mid_light;
GfxClear(rt, paletteIndex);
int16_t boxWidth = widgets[WIDX_RESEARCH_ORDER_SCROLL].width() - 1;
@@ -732,7 +732,7 @@ namespace OpenRCT2::Ui::Windows
ScreenCoordsXY screenCoords;
bool ridePage = (GetSelectedObjectType() == ObjectType::ride);
uint8_t paletteIndex = ColourMapA[colours[1].colour].mid_light;
auto paletteIndex = ColourMapA[colours[1].colour].mid_light;
GfxClear(rt, paletteIndex);
screenCoords.y = 0;
@@ -2339,7 +2339,7 @@ namespace OpenRCT2::Ui::Windows
*/
void RidesOnScrollDraw(Drawing::RenderTarget& rt, int32_t scrollIndex)
{
int32_t colour = ColourMapA[colours[1].colour].mid_light;
auto colour = ColourMapA[colours[1].colour].mid_light;
Rectangle::fill(rt, { { rt.x, rt.y }, { rt.x + rt.width - 1, rt.y + rt.height - 1 } }, colour);
for (int32_t i = 0; i < static_cast<int32_t>(_rideableRides.size()); i++)
+2 -2
View File
@@ -415,7 +415,7 @@ namespace OpenRCT2::Ui::Windows
rt,
{ screenCoords - ScreenCoordsXY{ 0, 1 },
screenCoords + ScreenCoordsXY{ row_width, (kTableCellHeight - 2) } },
ColourMapA[colours[1].colour].lighter | 0x1000000);
ColourMapA[colours[1].colour].lighter, true);
screenCoords.y += kTableCellHeight;
}
@@ -609,7 +609,7 @@ namespace OpenRCT2::Ui::Windows
Rectangle::fill(
rt,
{ screenCoords - ScreenCoordsXY{ 0, 1 }, screenCoords + ScreenCoordsXY{ 121, (kTableCellHeight - 2) } },
ColourMapA[colours[1].colour].lighter | 0x1000000);
ColourMapA[colours[1].colour].lighter, true);
DrawTextBasic(rt, screenCoords - ScreenCoordsXY{ 0, 1 }, _windowFinancesSummaryRowLabels[i]);
screenCoords.y += kTableCellHeight;
+1 -1
View File
@@ -157,7 +157,7 @@ namespace OpenRCT2::Ui::Windows
// Track preview
Widget* widget = &widgets[WIDX_TRACK_PREVIEW];
auto screenPos = windowPos + ScreenCoordsXY{ widget->left + 1, widget->top + 1 };
int32_t colour = ColourMapA[colours[0].colour].darkest;
auto colour = ColourMapA[colours[0].colour].darkest;
Rectangle::fill(rt, { screenPos, screenPos + ScreenCoordsXY{ 369, 216 } }, colour);
G1Element g1temp = {};
+13 -12
View File
@@ -178,11 +178,11 @@ namespace OpenRCT2::Ui::Windows
MapColour(PaletteIndex::pi161), // COLOUR_KEY_TOILETS
};
static constexpr uint8_t DefaultPeepMapColour = PaletteIndex::pi20;
static constexpr uint8_t GuestMapColour = PaletteIndex::pi172;
static constexpr uint8_t GuestMapColourAlternate = PaletteIndex::pi21;
static constexpr uint8_t StaffMapColour = PaletteIndex::pi138;
static constexpr uint8_t StaffMapColourAlternate = PaletteIndex::pi10;
static constexpr PaletteIndex DefaultPeepMapColour = PaletteIndex::pi20;
static constexpr PaletteIndex GuestMapColour = PaletteIndex::pi172;
static constexpr PaletteIndex GuestMapColourAlternate = PaletteIndex::pi21;
static constexpr PaletteIndex StaffMapColour = PaletteIndex::pi138;
static constexpr PaletteIndex StaffMapColourAlternate = PaletteIndex::pi10;
static constexpr uint16_t WaterColour = MapColour(PaletteIndex::pi195);
@@ -680,7 +680,7 @@ namespace OpenRCT2::Ui::Windows
{
Rectangle::fill(
rt, { screenCoords + ScreenCoordsXY{ 0, 2 }, screenCoords + ScreenCoordsXY{ 6, 8 } },
RideKeyColours[i]);
static_cast<PaletteIndex>(RideKeyColours[i] & 0xFF));
DrawTextBasic(rt, screenCoords + ScreenCoordsXY{ kListRowHeight, 0 }, MapLabels[i], {});
screenCoords.y += kListRowHeight;
if (i == 3)
@@ -962,7 +962,8 @@ namespace OpenRCT2::Ui::Windows
}
}
void DrawMapPeepPixel(Peep* peep, const uint8_t flashColour, Drawing::RenderTarget& rt, const ScreenCoordsXY& offset)
void DrawMapPeepPixel(
Peep* peep, const PaletteIndex flashColour, Drawing::RenderTarget& rt, const ScreenCoordsXY& offset)
{
if (peep->x == kLocationNull)
return;
@@ -970,7 +971,7 @@ namespace OpenRCT2::Ui::Windows
MapCoordsXY c = TransformToMapCoords({ peep->x, peep->y });
auto leftTop = ScreenCoordsXY{ c.x, c.y } + offset;
auto rightBottom = leftTop;
uint8_t colour = DefaultPeepMapColour;
auto colour = DefaultPeepMapColour;
if (getGameState().entities.EntityGetFlashing(peep))
{
colour = flashColour;
@@ -984,9 +985,9 @@ namespace OpenRCT2::Ui::Windows
Rectangle::fill(rt, { leftTop, rightBottom }, colour);
}
uint8_t GetGuestFlashColour() const
PaletteIndex GetGuestFlashColour() const
{
uint8_t colour = DefaultPeepMapColour;
auto colour = DefaultPeepMapColour;
if ((_flashingFlags & MapFlashingFlags::FlashGuests) != 0)
{
colour = GuestMapColour;
@@ -996,9 +997,9 @@ namespace OpenRCT2::Ui::Windows
return colour;
}
uint8_t GetStaffFlashColour() const
PaletteIndex GetStaffFlashColour() const
{
uint8_t colour = DefaultPeepMapColour;
auto colour = DefaultPeepMapColour;
if ((_flashingFlags & MapFlashingFlags::FlashStaff) != 0)
{
colour = StaffMapColour;
+4 -4
View File
@@ -5262,7 +5262,7 @@ namespace OpenRCT2::Ui::Windows
if (!isMusicActivated)
return;
uint8_t paletteIndex = ColourMapA[colours[1].colour].mid_light;
auto paletteIndex = ColourMapA[colours[1].colour].mid_light;
GfxClear(rt, paletteIndex);
auto* musicObj = ride->getMusicObject();
@@ -6066,8 +6066,8 @@ namespace OpenRCT2::Ui::Windows
}
// Vertical grid lines
const uint8_t lightColour = ColourMapA[COLOUR_SATURATED_GREEN].mid_light;
const uint8_t darkColour = ColourMapA[COLOUR_SATURATED_GREEN].mid_dark;
const auto lightColour = ColourMapA[COLOUR_SATURATED_GREEN].mid_light;
const auto darkColour = ColourMapA[COLOUR_SATURATED_GREEN].mid_dark;
int32_t time = 0;
for (int32_t x = 0; x < rt.x + rt.width; x += 80)
@@ -6101,7 +6101,7 @@ namespace OpenRCT2::Ui::Windows
for (int32_t y = widget->height() - 14; y >= 8; y -= yInterval, yUnit += yUnitInterval)
{
// Minor / major line
int32_t colour = yUnit == 0 ? lightColour : darkColour;
auto colour = yUnit == 0 ? lightColour : darkColour;
Rectangle::fill(rt, { { rt.x, y }, { rt.x + rt.width - 1, y } }, colour);
int16_t scaled_yUnit = yUnit;
+1 -1
View File
@@ -542,7 +542,7 @@ namespace OpenRCT2::Ui::Windows
void onScrollDraw(int32_t scrollIndex, Drawing::RenderTarget& rt) override
{
uint8_t paletteIndex = ColourMapA[colours[1].colour].mid_light;
auto paletteIndex = ColourMapA[colours[1].colour].mid_light;
GfxClear(rt, paletteIndex);
StringId highlighted_format = STR_WINDOW_COLOUR_2_STRINGID;
+1 -1
View File
@@ -328,7 +328,7 @@ namespace OpenRCT2::Ui::Windows
void onScrollDraw(int32_t scrollIndex, Drawing::RenderTarget& rt) override
{
uint8_t paletteIndex = ColourMapA[colours[1].colour].mid_light;
auto paletteIndex = ColourMapA[colours[1].colour].mid_light;
GfxClear(rt, paletteIndex);
auto& listWidget = widgets[WIDX_LIST];
+2 -1
View File
@@ -272,7 +272,8 @@ namespace OpenRCT2::Ui::Windows
uint8_t colour = ColourMapA[colours[1].colour].mid_light;
// TODO: palette index addition
Rectangle::fill(
rt, { { cursorX, screenCoords.y + 9 }, { cursorX + textWidth, screenCoords.y + 9 } }, colour + 5);
rt, { { cursorX, screenCoords.y + 9 }, { cursorX + textWidth, screenCoords.y + 9 } },
static_cast<PaletteIndex>(colour + 5));
}
cur_drawn++;
+4 -4
View File
@@ -769,11 +769,11 @@ namespace OpenRCT2::Ui::Windows
}
else
{
colour = ColourMapA[colours[1].colour].mid_dark;
Rectangle::fill(rt, { leftTop, rightBottom }, colour.colour);
auto fillColour = ColourMapA[colours[1].colour].mid_dark;
Rectangle::fill(rt, { leftTop, rightBottom }, fillColour);
colour = ColourMapA[colours[1].colour].lightest;
Rectangle::fill(rt, { leftTop + yPixelOffset, rightBottom + yPixelOffset }, colour.colour);
fillColour = ColourMapA[colours[1].colour].lightest;
Rectangle::fill(rt, { leftTop + yPixelOffset, rightBottom + yPixelOffset }, fillColour);
}
}
+2 -2
View File
@@ -1623,10 +1623,10 @@ static uint64_t PageDisabledWidgets[] = {
if (selectedRow)
Rectangle::fill(rt, fillRectangle, ColourMapA[colours[1].colour].mid_dark);
else if (hoveredRow)
Rectangle::fill(rt, fillRectangle, ColourMapA[colours[1].colour].mid_dark | 0x1000000);
Rectangle::fill(rt, fillRectangle, ColourMapA[colours[1].colour].mid_dark, true);
// Zebra stripes
else if (((windowTileInspectorElementCount - i) & 1) == 0)
Rectangle::fill(rt, fillRectangle, ColourMapA[colours[1].colour].light | 0x1000000);
Rectangle::fill(rt, fillRectangle, ColourMapA[colours[1].colour].light, true);
StringId stringFormat = STR_WINDOW_COLOUR_2_STRINGID;
if (selectedRow || hoveredRow)
+2 -2
View File
@@ -471,7 +471,7 @@ namespace OpenRCT2::Ui::Windows
// Track preview
auto& tdWidget = widgets[WIDX_TRACK_PREVIEW];
int32_t colour = ColourMapA[colours[0].colour].darkest;
auto colour = ColourMapA[colours[0].colour].darkest;
u8string path = _trackDesigns[trackIndex].path;
// Show track file path (in debug mode)
@@ -676,7 +676,7 @@ namespace OpenRCT2::Ui::Windows
void onScrollDraw(const int32_t scrollIndex, Drawing::RenderTarget& rt) override
{
uint8_t paletteIndex = ColourMapA[colours[0].colour].mid_light;
auto paletteIndex = ColourMapA[colours[0].colour].mid_light;
GfxClear(rt, paletteIndex);
auto screenCoords = ScreenCoordsXY{ 0, 0 };
+4 -4
View File
@@ -702,14 +702,14 @@ static std::optional<PaletteMap> FASTCALL GfxDrawSpriteGetPalette(ImageId imageI
{
paletteId &= 0x7F;
}
return GetPaletteMapForColour(paletteId);
return GetPaletteMapForColour(static_cast<FilterPaletteID>(paletteId));
}
auto paletteMap = PaletteMap(secondaryRemapPalette);
if (imageId.HasTertiary())
{
paletteMap = PaletteMap(tertiaryRemapPalette);
auto tertiaryPaletteMap = GetPaletteMapForColour(imageId.GetTertiary());
auto tertiaryPaletteMap = GetPaletteMapForColour(static_cast<FilterPaletteID>(imageId.GetTertiary()));
if (tertiaryPaletteMap.has_value())
{
paletteMap.Copy(
@@ -717,13 +717,13 @@ static std::optional<PaletteMap> FASTCALL GfxDrawSpriteGetPalette(ImageId imageI
}
}
auto primaryPaletteMap = GetPaletteMapForColour(imageId.GetPrimary());
auto primaryPaletteMap = GetPaletteMapForColour(static_cast<FilterPaletteID>(imageId.GetPrimary()));
if (primaryPaletteMap.has_value())
{
paletteMap.Copy(kPaletteOffsetRemapPrimary, primaryPaletteMap.value(), kPaletteOffsetRemapPrimary, kPaletteLengthRemap);
}
auto secondaryPaletteMap = GetPaletteMapForColour(imageId.GetSecondary());
auto secondaryPaletteMap = GetPaletteMapForColour(static_cast<FilterPaletteID>(imageId.GetSecondary()));
if (secondaryPaletteMap.has_value())
{
paletteMap.Copy(
+4 -4
View File
@@ -851,16 +851,16 @@ void GfxDrawPickedUpPeep(RenderTarget& rt)
}
}
std::optional<uint32_t> GetPaletteG1Index(colour_t paletteId)
std::optional<uint32_t> GetPaletteG1Index(FilterPaletteID paletteId)
{
if (paletteId < kPaletteTotalOffsets)
if (EnumValue(paletteId) < kPaletteTotalOffsets)
{
return kPaletteToG1Offset[paletteId];
return kPaletteToG1Offset[EnumValue(paletteId)];
}
return std::nullopt;
}
std::optional<PaletteMap> GetPaletteMapForColour(colour_t paletteId)
std::optional<PaletteMap> GetPaletteMapForColour(FilterPaletteID paletteId)
{
auto g1Index = GetPaletteG1Index(paletteId);
if (g1Index.has_value())
+5 -4
View File
@@ -44,7 +44,8 @@ namespace OpenRCT2
namespace OpenRCT2::Drawing
{
struct IDrawingEngine;
}
enum class FilterPaletteID : int32_t;
} // namespace OpenRCT2::Drawing
using DrawBlendOp = uint8_t;
@@ -245,7 +246,7 @@ void GfxTransposePalette(int32_t pal, uint8_t product);
void LoadPalette();
// other
void GfxClear(OpenRCT2::Drawing::RenderTarget& rt, uint8_t paletteIndex);
void GfxClear(OpenRCT2::Drawing::RenderTarget& rt, PaletteIndex paletteIndex);
void GfxFilterPixel(
OpenRCT2::Drawing::RenderTarget& rt, const ScreenCoordsXY& coords, OpenRCT2::Drawing::FilterPaletteID palette);
void GfxInvalidatePickedUpPeep();
@@ -326,8 +327,8 @@ void MaskFn(
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
std::optional<uint32_t> GetPaletteG1Index(colour_t paletteId);
std::optional<PaletteMap> GetPaletteMapForColour(colour_t paletteId);
std::optional<uint32_t> GetPaletteG1Index(OpenRCT2::Drawing::FilterPaletteID paletteId);
std::optional<PaletteMap> GetPaletteMapForColour(OpenRCT2::Drawing::FilterPaletteID paletteId);
void UpdatePalette(std::span<const OpenRCT2::Drawing::PaletteBGRA> palette, int32_t start_index, int32_t num_colours);
void UpdatePaletteEffects();
+5 -2
View File
@@ -22,8 +22,11 @@ namespace OpenRCT2::Drawing
{
virtual ~IDrawingContext() = default;
virtual void Clear(RenderTarget& rt, uint8_t paletteIndex) = 0;
virtual void FillRect(RenderTarget& rt, uint32_t colour, int32_t left, int32_t top, int32_t right, int32_t bottom) = 0;
virtual void Clear(RenderTarget& rt, PaletteIndex paletteIndex) = 0;
virtual void FillRect(
RenderTarget& rt, PaletteIndex paletteIndex, int32_t left, int32_t top, int32_t right, int32_t bottom,
bool crossHatch = false)
= 0;
virtual void FilterRect(
RenderTarget& rt, FilterPaletteID palette, int32_t left, int32_t top, int32_t right, int32_t bottom)
= 0;
+1 -1
View File
@@ -154,7 +154,7 @@ void GfxSetDirtyBlocks(const ScreenRect& rect)
}
}
void GfxClear(RenderTarget& rt, uint8_t paletteIndex)
void GfxClear(RenderTarget& rt, PaletteIndex paletteIndex)
{
auto drawingEngine = rt.DrawingEngine;
if (drawingEngine != nullptr)
+3 -3
View File
@@ -20,13 +20,13 @@ using OpenRCT2::Drawing::IDrawingContext;
namespace OpenRCT2::Drawing::Rectangle
{
void fill(RenderTarget& rt, const ScreenRect& rect, int32_t colour)
void fill(RenderTarget& rt, const ScreenRect& rect, PaletteIndex paletteIndex, bool crossHatch)
{
auto drawingEngine = rt.DrawingEngine;
if (drawingEngine != nullptr)
{
IDrawingContext* dc = drawingEngine->GetDrawingContext();
dc->FillRect(rt, colour, rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom());
dc->FillRect(rt, paletteIndex, rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom(), crossHatch);
}
}
@@ -91,7 +91,7 @@ namespace OpenRCT2::Drawing::Rectangle
}
else
{
uint8_t shadow, fill, hilight;
PaletteIndex shadow, fill, hilight;
if (brightness == FillBrightness::dark)
{
shadow = ColourMapA[colour.colour].dark;
+2 -1
View File
@@ -12,6 +12,7 @@
#include <cstdint>
struct ScreenRect;
enum PaletteIndex : uint8_t;
namespace OpenRCT2
{
@@ -44,7 +45,7 @@ namespace OpenRCT2::Drawing::Rectangle
dontLightenWhenInset,
};
void fill(RenderTarget& rt, const ScreenRect& rect, int32_t colour);
void fill(RenderTarget& rt, const ScreenRect& rect, PaletteIndex paletteIndex, bool crossHatch = false);
void fillInset(
RenderTarget& rt, const ScreenRect& rect, ColourWithFlags colour, BorderStyle borderStyle = BorderStyle::outset,
FillBrightness brightness = FillBrightness::light, FillMode fillMode = FillMode::standard);
+8 -93
View File
@@ -373,7 +373,7 @@ X8DrawingContext::X8DrawingContext(X8DrawingEngine* engine)
_engine = engine;
}
void X8DrawingContext::Clear(RenderTarget& rt, uint8_t paletteIndex)
void X8DrawingContext::Clear(RenderTarget& rt, PaletteIndex paletteIndex)
{
Guard::Assert(_isDrawing == true);
@@ -383,60 +383,13 @@ void X8DrawingContext::Clear(RenderTarget& rt, uint8_t paletteIndex)
for (int32_t y = 0; y < h; y++)
{
std::fill_n(ptr, w, paletteIndex);
std::fill_n(ptr, w, EnumValue(paletteIndex));
ptr += w + rt.pitch;
}
}
/** rct2: 0x0097FF04 */
// clang-format off
static constexpr uint16_t kPattern[] = {
0b0111111110000000,
0b0011111111000000,
0b0001111111100000,
0b0000111111110000,
0b0000011111111000,
0b0000001111111100,
0b0000000111111110,
0b0000000011111111,
0b1000000001111111,
0b1100000000111111,
0b1110000000011111,
0b1111000000001111,
0b1111100000000111,
0b1111110000000011,
0b1111111000000001,
0b1111111100000000,
};
/** rct2: 0x0097FF14 */
static constexpr uint16_t kPatternInverse[] = {
0b1000000001111111,
0b1100000000111111,
0b1110000000011111,
0b1111000000001111,
0b1111100000000111,
0b1111110000000011,
0b1111111000000001,
0b1111111100000000,
0b0111111110000000,
0b0011111111000000,
0b0001111111100000,
0b0000111111110000,
0b0000011111111000,
0b0000001111111100,
0b0000000111111110,
0b0000000011111111,
};
/** rct2: 0x0097FEFC */
static constexpr const uint16_t* kPatterns[] = {
kPattern,
kPatternInverse,
};
// clang-format on
void X8DrawingContext::FillRect(RenderTarget& rt, uint32_t colour, int32_t left, int32_t top, int32_t right, int32_t bottom)
void X8DrawingContext::FillRect(
RenderTarget& rt, PaletteIndex paletteIndex, int32_t left, int32_t top, int32_t right, int32_t bottom, bool crossHatch)
{
Guard::Assert(_isDrawing == true);
@@ -485,7 +438,7 @@ void X8DrawingContext::FillRect(RenderTarget& rt, uint32_t colour, int32_t left,
int32_t width = endX - startX;
int32_t height = endY - startY;
if (colour & 0x1000000)
if (crossHatch)
{
// Cross hatching
uint8_t* dst = startY * rt.LineStride() + startX + rt.bits;
@@ -501,7 +454,7 @@ void X8DrawingContext::FillRect(RenderTarget& rt, uint32_t colour, int32_t left,
p = p ^ 0x80000000;
if (p & 0x80000000)
{
*dst = colour & 0xFF;
*dst = EnumValue(paletteIndex);
}
dst++;
}
@@ -509,50 +462,12 @@ void X8DrawingContext::FillRect(RenderTarget& rt, uint32_t colour, int32_t left,
dst = nextdst;
}
}
else if (colour & 0x2000000)
{
assert(false);
}
else if (colour & 0x4000000)
{
uint8_t* dst = startY * rt.LineStride() + startX + rt.bits;
// The pattern loops every 15 lines this is which
// part the pattern is on.
int32_t patternY = (startY + rt.y) % 16;
// The pattern loops every 15 pixels this is which
// part the pattern is on.
int32_t startkPatternX = (startX + rt.x) % 16;
int32_t patternX = startkPatternX;
const uint16_t* patternsrc = kPatterns[colour >> 28]; // or possibly uint8_t)[esi*4] ?
for (int32_t numLines = height; numLines > 0; numLines--)
{
uint8_t* nextdst = dst + rt.LineStride();
uint16_t pattern = patternsrc[patternY];
for (int32_t numPixels = width; numPixels > 0; numPixels--)
{
if (pattern & (1 << patternX))
{
*dst = colour & 0xFF;
}
patternX = (patternX + 1) % 16;
dst++;
}
patternX = startkPatternX;
patternY = (patternY + 1) % 16;
dst = nextdst;
}
}
else
{
uint8_t* dst = startY * rt.LineStride() + startX + rt.bits;
for (int32_t i = 0; i < height; i++)
{
std::fill_n(dst, width, colour & 0xFF);
std::fill_n(dst, width, EnumValue(paletteIndex));
dst += rt.LineStride();
}
}
@@ -606,7 +521,7 @@ void X8DrawingContext::FilterRect(
uint8_t* dst = rt.bits + (startY * rt.LineStride() + startX);
// Find colour in colour table?
auto paletteMap = GetPaletteMapForColour(EnumValue(palette));
auto paletteMap = GetPaletteMapForColour(palette);
if (paletteMap.has_value())
{
const auto& paletteEntries = paletteMap.value();
+4 -2
View File
@@ -136,8 +136,10 @@ namespace OpenRCT2
void BeginDraw();
void EndDraw();
void Clear(RenderTarget& rt, uint8_t paletteIndex) override;
void FillRect(RenderTarget& rt, uint32_t colour, int32_t x, int32_t y, int32_t w, int32_t h) override;
void Clear(RenderTarget& rt, PaletteIndex paletteIndex) override;
void FillRect(
RenderTarget& rt, PaletteIndex paletteIndex, int32_t x, int32_t y, int32_t w, int32_t h,
bool crossHatch) override;
void FilterRect(
RenderTarget& rt, FilterPaletteID palette, int32_t left, int32_t top, int32_t right, int32_t bottom) override;
void DrawLine(RenderTarget& rt, uint32_t colour, const ScreenLine& line) override;
+3 -3
View File
@@ -852,10 +852,10 @@ namespace OpenRCT2
| VIEWPORT_FLAG_CLIP_VIEW)
&& (~session.ViewFlags & VIEWPORT_FLAG_TRANSPARENT_BACKGROUND))
{
uint8_t colour = COLOUR_AQUAMARINE;
PaletteIndex colour = PaletteIndex::pi10;
if (session.ViewFlags & VIEWPORT_FLAG_HIDE_ENTITIES)
{
colour = COLOUR_BLACK;
colour = PaletteIndex::pi0;
}
GfxClear(session.DPI, colour);
}
@@ -1627,7 +1627,7 @@ namespace OpenRCT2
{
paletteIndex = imageId.GetRemap();
}
if (auto pm = GetPaletteMapForColour(paletteIndex); pm.has_value())
if (auto pm = GetPaletteMapForColour(static_cast<FilterPaletteID>(paletteIndex)); pm.has_value())
{
paletteMap = pm.value();
}