mirror of https://github.com/OpenRCT2/OpenRCT2.git
start introducing the IDrawingContext
This commit is contained in:
parent
3e6eb48d4c
commit
6e8cc5469a
|
@ -21,6 +21,7 @@
|
|||
#include <SDL_video.h>
|
||||
|
||||
struct rct_drawpixelinfo;
|
||||
interface IDrawingContext;
|
||||
|
||||
interface IDrawingEngine
|
||||
{
|
||||
|
@ -32,6 +33,8 @@ interface IDrawingEngine
|
|||
|
||||
virtual void Invalidate(sint32 left, sint32 top, sint32 right, sint32 bottom) abstract;
|
||||
virtual void Draw() abstract;
|
||||
|
||||
virtual IDrawingContext * GetDrawingContext(rct_drawpixelinfo * dpi) abstract;
|
||||
};
|
||||
|
||||
namespace DrawingEngineFactory
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "IDrawingContext.h"
|
||||
#include "IDrawingEngine.h"
|
||||
|
||||
extern "C"
|
||||
|
@ -67,6 +68,18 @@ extern "C"
|
|||
|
||||
void gfx_draw_all_dirty_blocks()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the screen with the specified colour.
|
||||
* rct2: 0x00678A9F
|
||||
*/
|
||||
void gfx_clear(rct_drawpixelinfo * dpi, int colour)
|
||||
{
|
||||
if (_drawingEngine != nullptr)
|
||||
{
|
||||
IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi);
|
||||
dc->Clear(colour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,22 +114,6 @@ const uint16 palette_to_g1_offset[PALETTE_TO_G1_OFFSET_COUNT] = {
|
|||
|
||||
static void gfx_draw_dirty_blocks(int x, int y, int columns, int rows);
|
||||
|
||||
/**
|
||||
* Clears the screen with the specified colour.
|
||||
* rct2: 0x00678A9F
|
||||
*/
|
||||
void gfx_clear(rct_drawpixelinfo *dpi, int colour)
|
||||
{
|
||||
int w = dpi->width >> dpi->zoom_level;
|
||||
int h = dpi->height >> dpi->zoom_level;
|
||||
uint8* ptr = dpi->bits;
|
||||
|
||||
for (int y = 0; y < h; y++) {
|
||||
memset(ptr, colour, w);
|
||||
ptr += w + dpi->pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void gfx_draw_pixel(rct_drawpixelinfo *dpi, int x, int y, int colour)
|
||||
{
|
||||
gfx_fill_rect(dpi, x, y, x, y, colour);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "../../core/Math.hpp"
|
||||
#include "../../core/Memory.hpp"
|
||||
#include "../IDrawingContext.h"
|
||||
#include "../IDrawingEngine.h"
|
||||
#include "../Rain.h"
|
||||
|
||||
|
@ -26,6 +27,8 @@ extern "C"
|
|||
#include "../../interface/window.h"
|
||||
}
|
||||
|
||||
class SoftwareDrawingEngine;
|
||||
|
||||
struct DirtyGrid
|
||||
{
|
||||
uint32 BlockShiftX;
|
||||
|
@ -148,6 +151,25 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class SoftwareDrawingContext : public IDrawingContext
|
||||
{
|
||||
private:
|
||||
SoftwareDrawingEngine * _engine;
|
||||
rct_drawpixelinfo * _dpi;
|
||||
|
||||
public:
|
||||
SoftwareDrawingContext(SoftwareDrawingEngine * engine);
|
||||
~SoftwareDrawingContext() override;
|
||||
|
||||
IDrawingEngine * GetEngine() override;
|
||||
|
||||
void Clear(uint32 colour) override;
|
||||
void FillRect(uint32 colour, sint32 x, sint32 y, sint32 w, sint32 h) override;
|
||||
void DrawSprite(uint32 image, sint32 x, sint32 y) override;
|
||||
|
||||
void SetDPI(rct_drawpixelinfo * dpi);
|
||||
};
|
||||
|
||||
class SoftwareDrawingEngine : public IDrawingEngine
|
||||
{
|
||||
private:
|
||||
|
@ -166,16 +188,18 @@ private:
|
|||
|
||||
rct_drawpixelinfo _bitsDPI = { 0 };
|
||||
|
||||
RainDrawer _rainDrawer;
|
||||
RainDrawer _rainDrawer;
|
||||
SoftwareDrawingContext * _drawingContext;
|
||||
|
||||
public:
|
||||
SoftwareDrawingEngine()
|
||||
{
|
||||
|
||||
_drawingContext = new SoftwareDrawingContext(this);
|
||||
}
|
||||
|
||||
~SoftwareDrawingEngine() override
|
||||
{
|
||||
delete _drawingContext;
|
||||
delete _dirtyGrid.Blocks;
|
||||
delete _bits;
|
||||
SDL_FreeSurface(_surface);
|
||||
|
@ -281,6 +305,17 @@ public:
|
|||
Display();
|
||||
}
|
||||
|
||||
IDrawingContext * GetDrawingContext(rct_drawpixelinfo * dpi) override
|
||||
{
|
||||
_drawingContext->SetDPI(dpi);
|
||||
return _drawingContext;
|
||||
}
|
||||
|
||||
rct_drawpixelinfo * GetDPI()
|
||||
{
|
||||
return &_bitsDPI;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void ConfigureBits(uint32 width, uint32 height, uint32 pitch)
|
||||
|
@ -487,3 +522,48 @@ IDrawingEngine * DrawingEngineFactory::CreateSoftware()
|
|||
{
|
||||
return new SoftwareDrawingEngine();
|
||||
}
|
||||
|
||||
SoftwareDrawingContext::SoftwareDrawingContext(SoftwareDrawingEngine * engine)
|
||||
{
|
||||
_engine = engine;
|
||||
}
|
||||
|
||||
SoftwareDrawingContext::~SoftwareDrawingContext()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
IDrawingEngine * SoftwareDrawingContext::GetEngine()
|
||||
{
|
||||
return _engine;
|
||||
}
|
||||
|
||||
void SoftwareDrawingContext::Clear(uint32 colour)
|
||||
{
|
||||
rct_drawpixelinfo * dpi = _dpi;
|
||||
|
||||
int w = dpi->width >> dpi->zoom_level;
|
||||
int h = dpi->height >> dpi->zoom_level;
|
||||
uint8 * ptr = dpi->bits;
|
||||
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
Memory::Set(ptr, colour, w);
|
||||
ptr += w + dpi->pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void SoftwareDrawingContext::FillRect(uint32 colour, sint32 x, sint32 y, sint32 w, sint32 h)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SoftwareDrawingContext::DrawSprite(uint32 image, sint32 x, sint32 y)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SoftwareDrawingContext::SetDPI(rct_drawpixelinfo * dpi)
|
||||
{
|
||||
_dpi = dpi;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue