Fix window re-rendering when ReInit() called within OnPaint/draw handler
This commit is contained in:
20
src/gfx.cpp
20
src/gfx.cpp
@@ -80,8 +80,10 @@ static const uint DIRTY_BLOCK_WIDTH = 64;
|
||||
|
||||
extern uint _dirty_block_colour;
|
||||
static bool _whole_screen_dirty = false;
|
||||
bool _gfx_draw_active = false;
|
||||
|
||||
static std::vector<Rect> _dirty_blocks;
|
||||
static std::vector<Rect> _pending_dirty_blocks;
|
||||
|
||||
/**
|
||||
* Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
|
||||
@@ -1511,6 +1513,8 @@ void DrawDirtyBlocks()
|
||||
extern void ViewportPrepareVehicleRoute();
|
||||
ViewportPrepareVehicleRoute();
|
||||
|
||||
_gfx_draw_active = true;
|
||||
|
||||
if (_whole_screen_dirty) {
|
||||
RedrawScreenRect(0, 0, _screen.width, _screen.height);
|
||||
Window *w;
|
||||
@@ -1677,6 +1681,17 @@ void DrawDirtyBlocks()
|
||||
}
|
||||
|
||||
_dirty_blocks.clear();
|
||||
while (!_pending_dirty_blocks.empty()) {
|
||||
for (const Rect &r : _pending_dirty_blocks) {
|
||||
SetDirtyBlocks(r.left, r.top, r.right, r.bottom);
|
||||
}
|
||||
_pending_dirty_blocks.clear();
|
||||
for (const Rect &r : _dirty_blocks) {
|
||||
RedrawScreenRect(r.left, r.top, r.right, r.bottom);
|
||||
}
|
||||
_dirty_blocks.clear();
|
||||
}
|
||||
_gfx_draw_active = false;
|
||||
++_dirty_block_colour;
|
||||
|
||||
extern void ClearViewPortCaches();
|
||||
@@ -1816,6 +1831,11 @@ void SetDirtyBlocks(int left, int top, int right, int bottom)
|
||||
AddDirtyBlocks(0, left, top, right, bottom);
|
||||
}
|
||||
|
||||
void SetPendingDirtyBlocks(int left, int top, int right, int bottom)
|
||||
{
|
||||
_pending_dirty_blocks.push_back({ left, top, right, bottom });
|
||||
}
|
||||
|
||||
/**
|
||||
* This function mark the whole screen as dirty. This results in repainting
|
||||
* the whole screen. Use this with care as this function will break the
|
||||
|
Reference in New Issue
Block a user