mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-16 04:22:43 +01:00
Refactor drawing
This commit is contained in:
@@ -69,8 +69,7 @@ private:
|
||||
int32_t _clipTop = 0;
|
||||
int32_t _clipRight = 0;
|
||||
int32_t _clipBottom = 0;
|
||||
int32_t _spriteOffsetX = 0;
|
||||
int32_t _spriteOffsetY = 0;
|
||||
ScreenCoordsXY _spriteOffset;
|
||||
|
||||
int32_t _drawCount = 0;
|
||||
|
||||
@@ -695,10 +694,10 @@ void OpenGLDrawingContext::DrawSprite(uint32_t image, int32_t x, int32_t y, uint
|
||||
right = right / _dpi->zoom_level;
|
||||
bottom = bottom / _dpi->zoom_level;
|
||||
|
||||
left += _spriteOffsetX;
|
||||
top += _spriteOffsetY;
|
||||
right += _spriteOffsetX;
|
||||
bottom += _spriteOffsetY;
|
||||
left += _spriteOffset.x;
|
||||
top += _spriteOffset.y;
|
||||
right += _spriteOffset.x;
|
||||
bottom += _spriteOffset.y;
|
||||
|
||||
const auto texture = _textureCache->GetOrLoadImageTexture(image);
|
||||
|
||||
@@ -807,10 +806,10 @@ void OpenGLDrawingContext::DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t ma
|
||||
right = right * _dpi->zoom_level;
|
||||
bottom = bottom * _dpi->zoom_level;
|
||||
|
||||
left += _spriteOffsetX;
|
||||
top += _spriteOffsetY;
|
||||
right += _spriteOffsetX;
|
||||
bottom += _spriteOffsetY;
|
||||
left += _spriteOffset.x;
|
||||
top += _spriteOffset.y;
|
||||
right += _spriteOffset.x;
|
||||
bottom += _spriteOffset.y;
|
||||
|
||||
DrawRectCommand& command = _commandBuffers.rects.allocate();
|
||||
|
||||
@@ -911,10 +910,10 @@ void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, const
|
||||
right = right / _dpi->zoom_level;
|
||||
bottom = bottom / _dpi->zoom_level;
|
||||
|
||||
left += _spriteOffsetX;
|
||||
top += _spriteOffsetY;
|
||||
right += _spriteOffsetX;
|
||||
bottom += _spriteOffsetY;
|
||||
left += _spriteOffset.x;
|
||||
top += _spriteOffset.y;
|
||||
right += _spriteOffset.x;
|
||||
bottom += _spriteOffset.y;
|
||||
|
||||
DrawRectCommand& command = _commandBuffers.rects.allocate();
|
||||
|
||||
@@ -1008,22 +1007,22 @@ void OpenGLDrawingContext::HandleTransparency()
|
||||
|
||||
void OpenGLDrawingContext::SetDPI(rct_drawpixelinfo* dpi)
|
||||
{
|
||||
rct_drawpixelinfo* screenDPI = _engine->GetDPI();
|
||||
auto screenDPI = _engine->GetDPI();
|
||||
auto bytesPerRow = screenDPI->GetBytesPerRow();
|
||||
auto bitsOffset = static_cast<size_t>(dpi->bits - screenDPI->bits);
|
||||
# ifndef NDEBUG
|
||||
size_t bitsSize = static_cast<size_t>(screenDPI->height) * static_cast<size_t>(screenDPI->width + screenDPI->pitch);
|
||||
# endif
|
||||
size_t bitsOffset = static_cast<size_t>(dpi->bits - screenDPI->bits);
|
||||
|
||||
auto bitsSize = static_cast<size_t>(screenDPI->height) * bytesPerRow;
|
||||
assert(bitsOffset < bitsSize);
|
||||
# endif
|
||||
|
||||
_clipLeft = static_cast<int32_t>(bitsOffset % (screenDPI->width + screenDPI->pitch)) + dpi->remX;
|
||||
_clipTop = static_cast<int32_t>(bitsOffset / (screenDPI->width + screenDPI->pitch)) + dpi->remY;
|
||||
_clipLeft = static_cast<int32_t>(bitsOffset % bytesPerRow) + dpi->remX;
|
||||
_clipTop = static_cast<int32_t>(bitsOffset / bytesPerRow) + dpi->remY;
|
||||
_clipRight = _clipLeft + (dpi->width / dpi->zoom_level);
|
||||
_clipBottom = _clipTop + (dpi->height / dpi->zoom_level);
|
||||
_offsetX = _clipLeft - dpi->x;
|
||||
_offsetY = _clipTop - dpi->y;
|
||||
_spriteOffsetX = _clipLeft - dpi->remX;
|
||||
_spriteOffsetY = _clipTop - dpi->remY;
|
||||
_spriteOffset.x = _clipLeft - dpi->remX;
|
||||
_spriteOffset.y = _clipTop - dpi->remY;
|
||||
|
||||
_dpi = dpi;
|
||||
}
|
||||
|
||||
@@ -773,14 +773,24 @@ std::optional<PaletteMap> GetPaletteMapForColour(colour_t paletteId)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
rct_drawpixelinfo rct_drawpixelinfo::Crop(int32_t newX, int32_t newY, int32_t newWidth, int32_t newHeight)
|
||||
size_t rct_drawpixelinfo::GetBytesPerRow() const
|
||||
{
|
||||
return static_cast<size_t>(width) + pitch;
|
||||
}
|
||||
|
||||
uint8_t* rct_drawpixelinfo::GetBitsOffset(const ScreenCoordsXY& pos) const
|
||||
{
|
||||
return bits + pos.x + (pos.y * GetBytesPerRow());
|
||||
}
|
||||
|
||||
rct_drawpixelinfo rct_drawpixelinfo::Crop(const ScreenCoordsXY& pos, const ScreenSize& size) const
|
||||
{
|
||||
rct_drawpixelinfo result = *this;
|
||||
result.bits = bits + newX + (((size_t)width + pitch) * newY);
|
||||
result.x = static_cast<int16_t>(newX);
|
||||
result.y = static_cast<int16_t>(newY);
|
||||
result.width = static_cast<int16_t>(newWidth);
|
||||
result.height = static_cast<int16_t>(newHeight);
|
||||
result.pitch = static_cast<int16_t>(width + pitch - newWidth);
|
||||
result.bits = GetBitsOffset(pos);
|
||||
result.x = static_cast<int16_t>(pos.x);
|
||||
result.y = static_cast<int16_t>(pos.y);
|
||||
result.width = static_cast<int16_t>(size.width);
|
||||
result.height = static_cast<int16_t>(size.height);
|
||||
result.pitch = static_cast<int16_t>(width + pitch - size.width);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "../common.h"
|
||||
#include "../interface/Colour.h"
|
||||
#include "../interface/ZoomLevel.hpp"
|
||||
#include "../world/Location.hpp"
|
||||
#include "Text.h"
|
||||
|
||||
#include <optional>
|
||||
@@ -114,7 +115,9 @@ struct rct_drawpixelinfo
|
||||
|
||||
OpenRCT2::Drawing::IDrawingEngine* DrawingEngine{};
|
||||
|
||||
rct_drawpixelinfo Crop(int32_t newX, int32_t newY, int32_t newWidth, int32_t newHeight);
|
||||
size_t GetBytesPerRow() const;
|
||||
uint8_t* GetBitsOffset(const ScreenCoordsXY& pos) const;
|
||||
rct_drawpixelinfo Crop(const ScreenCoordsXY& pos, const ScreenSize& size) const;
|
||||
};
|
||||
|
||||
struct rct_g1_element_32bit
|
||||
|
||||
@@ -2019,7 +2019,7 @@ bool window_is_visible(rct_window* w)
|
||||
*/
|
||||
void window_draw_all(rct_drawpixelinfo* dpi, int16_t left, int16_t top, int16_t right, int16_t bottom)
|
||||
{
|
||||
auto windowDPI = dpi->Crop(left, top, right - left, bottom - top);
|
||||
auto windowDPI = dpi->Crop({ left, top }, { right - left, bottom - top });
|
||||
window_visit_each([&windowDPI, left, top, right, bottom](rct_window* w) {
|
||||
if (w->flags & WF_TRANSPARENT)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user