Use backup/restore wrappers for various _cur_dpi changes
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "station_func.h"
|
||||
#include "zoom_func.h"
|
||||
#include "sortlist_type.h"
|
||||
#include "core/backup_type.hpp"
|
||||
|
||||
#include "widgets/company_widget.h"
|
||||
|
||||
@@ -2087,8 +2088,7 @@ struct CompanyInfrastructureWindow : Window
|
||||
DrawPixelInfo tmp_dpi;
|
||||
if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, width + 1, r.bottom - r.top + 1)) return;
|
||||
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
_cur_dpi = &tmp_dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||
|
||||
int y = -this->vscroll->GetPosition();
|
||||
|
||||
@@ -2198,9 +2198,6 @@ struct CompanyInfrastructureWindow : Window
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore clipping region. */
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
virtual void OnResize() override
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include "departures_func.h"
|
||||
#include "cargotype.h"
|
||||
#include "zoom_func.h"
|
||||
#include "core/backup_type.hpp"
|
||||
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
@@ -1001,8 +1002,7 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
|
||||
y += this->entry_height;
|
||||
continue;
|
||||
}
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
_cur_dpi = &tmp_dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||
|
||||
/* The scrolling text starts out of view at the right of the screen and finishes when it is out of view at the left of the screen. */
|
||||
int pos = ltr
|
||||
@@ -1011,8 +1011,6 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
|
||||
|
||||
ltr ? DrawString( pos, INT16_MAX, 0, buffer, TC_FROMSTRING, SA_LEFT | SA_FORCE)
|
||||
: DrawString(-INT16_MAX, pos, 0, buffer, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
y += this->entry_height;
|
||||
|
@@ -1752,9 +1752,8 @@ void DrawDirtyBlocks()
|
||||
cleared_overlays = true;
|
||||
};
|
||||
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
DrawPixelInfo bk;
|
||||
_cur_dpi = &bk;
|
||||
Backup dpi_backup(_cur_dpi, &bk, FILE_LINE);
|
||||
|
||||
for (Window *w : Window::IterateFromBack()) {
|
||||
w->flags &= ~WF_DRAG_DIRTIED;
|
||||
@@ -1899,7 +1898,7 @@ void DrawDirtyBlocks()
|
||||
}
|
||||
}
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
dpi_backup.Restore();
|
||||
|
||||
for (const Rect &r : _dirty_blocks) {
|
||||
RedrawScreenRect(r.left, r.top, r.right, r.bottom);
|
||||
|
@@ -34,6 +34,7 @@
|
||||
#include "error.h"
|
||||
#include "tracerestrict.h"
|
||||
#include "scope.h"
|
||||
#include "core/backup_type.hpp"
|
||||
|
||||
#include "widgets/order_widget.h"
|
||||
|
||||
@@ -1171,12 +1172,9 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
|
||||
Dimension lock_d = GetSpriteSize(SPR_LOCK);
|
||||
DrawPixelInfo tmp_dpi;
|
||||
if (FillDrawPixelInfo(&tmp_dpi, rtl ? left : middle, y, rtl ? middle - left : right - middle, lock_d.height)) {
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
_cur_dpi = &tmp_dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||
|
||||
DrawSprite(SPR_LOCK, PAL_NONE, rtl ? edge - 3 - lock_d.width - left : edge + 3 - middle, 0);
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1699,20 +1699,17 @@ void SmallMapWindow::TakeScreenshot()
|
||||
*/
|
||||
void SmallMapWindow::ScreenshotCallbackHandler(void *buf, uint y, uint pitch, uint n)
|
||||
{
|
||||
DrawPixelInfo dpi, *old_dpi;
|
||||
DrawPixelInfo dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &dpi);
|
||||
|
||||
/* We are no longer rendering to the screen */
|
||||
DrawPixelInfo old_screen = _screen;
|
||||
bool old_disable_anim = _screen_disable_anim;
|
||||
AutoRestoreBackup screen_backup(_screen, AutoRestoreBackupNoNewValueTag{});
|
||||
AutoRestoreBackup screen_disable_anim_backup(_screen_disable_anim, true);
|
||||
|
||||
_screen.dst_ptr = buf;
|
||||
_screen.width = pitch;
|
||||
_screen.height = n;
|
||||
_screen.pitch = pitch;
|
||||
_screen_disable_anim = true;
|
||||
|
||||
old_dpi = _cur_dpi;
|
||||
_cur_dpi = &dpi;
|
||||
|
||||
dpi.dst_ptr = buf;
|
||||
dpi.height = n;
|
||||
@@ -1728,12 +1725,6 @@ void SmallMapWindow::ScreenshotCallbackHandler(void *buf, uint y, uint pitch, ui
|
||||
|
||||
/* make the screenshot */
|
||||
this->DrawSmallMap(&dpi, false);
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
|
||||
/* Switch back to rendering to the screen */
|
||||
_screen = old_screen;
|
||||
_screen_disable_anim = old_disable_anim;
|
||||
}
|
||||
|
||||
SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#include "company_base.h"
|
||||
#include "train.h"
|
||||
#include "newgrf_debug.h"
|
||||
#include "core/backup_type.hpp"
|
||||
|
||||
#include "tbtr_template_gui_create.h"
|
||||
#include "tbtr_template_vehicle.h"
|
||||
@@ -298,12 +299,11 @@ public:
|
||||
}
|
||||
case TCW_INFO_PANEL: {
|
||||
if (this->virtual_train) {
|
||||
DrawPixelInfo tmp_dpi, *old_dpi;
|
||||
DrawPixelInfo tmp_dpi;
|
||||
|
||||
if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left, r.bottom - r.top)) break;
|
||||
|
||||
old_dpi = _cur_dpi;
|
||||
_cur_dpi = &tmp_dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||
|
||||
int y = ScaleGUITrad(4) - this->vscroll->GetPosition();
|
||||
bool buildable = true;
|
||||
@@ -380,8 +380,6 @@ public:
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "network/network.h"
|
||||
#include "zoom_func.h"
|
||||
#include "textbuf_gui.h"
|
||||
#include "core/backup_type.hpp"
|
||||
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
@@ -769,14 +770,13 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
DrawPixelInfo tmp_dpi, *old_dpi;
|
||||
DrawPixelInfo tmp_dpi;
|
||||
|
||||
if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left, r.bottom - r.top)) {
|
||||
return;
|
||||
}
|
||||
|
||||
old_dpi = _cur_dpi;
|
||||
_cur_dpi = &tmp_dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||
|
||||
const TemplateVehicle *tmp = this->templates[this->selected_template_index];
|
||||
|
||||
@@ -840,8 +840,6 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
void UpdateButtonState()
|
||||
|
@@ -124,14 +124,13 @@ void DrawTemplate(const TemplateVehicle *tv, int left, int right, int y, int hei
|
||||
{
|
||||
if (!tv) return;
|
||||
|
||||
DrawPixelInfo tmp_dpi, *old_dpi;
|
||||
DrawPixelInfo tmp_dpi;
|
||||
int max_width = right - left + 1;
|
||||
int veh_height = ScaleSpriteTrad(14);
|
||||
int padding = height - veh_height;
|
||||
if (!FillDrawPixelInfo(&tmp_dpi, left, y + (padding / 2), max_width, height)) return;
|
||||
|
||||
old_dpi = _cur_dpi;
|
||||
_cur_dpi = &tmp_dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||
|
||||
const TemplateVehicle *t = tv;
|
||||
int offset = 0;
|
||||
@@ -142,8 +141,6 @@ void DrawTemplate(const TemplateVehicle *tv, int left, int right, int y, int hei
|
||||
offset += t->image_dimensions.GetDisplayImageWidth();
|
||||
t = t->Next();
|
||||
}
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
// copy important stuff from the virtual vehicle to the template
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include "schdispatch.h"
|
||||
#include "vehiclelist.h"
|
||||
#include "tracerestrict.h"
|
||||
#include "core/backup_type.hpp"
|
||||
|
||||
#include "widgets/timetable_widget.h"
|
||||
|
||||
@@ -723,12 +724,9 @@ struct TimetableWindow : GeneralVehicleWindow {
|
||||
Dimension lock_d = GetSpriteSize(SPR_LOCK);
|
||||
DrawPixelInfo tmp_dpi;
|
||||
if (FillDrawPixelInfo(&tmp_dpi, rtl ? tr.left : middle, tr.top, rtl ? middle : tr.right, lock_d.height)) {
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
_cur_dpi = &tmp_dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||
|
||||
DrawSprite(SPR_LOCK, PAL_NONE, rtl ? edge - 3 - lock_d.width - tr.left : edge + 3 - middle, 0);
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -367,8 +367,7 @@ void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom)
|
||||
{
|
||||
DrawPixelInfo tmp_dpi;
|
||||
if (!FillDrawPixelInfo(&tmp_dpi, left, top, right - left + 1, bottom - top + 1)) return;
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
_cur_dpi = &tmp_dpi;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||
|
||||
const HouseSpec *hs = HouseSpec::Get(house_id);
|
||||
|
||||
@@ -412,8 +411,6 @@ void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom)
|
||||
}
|
||||
if (!ground) break;
|
||||
}
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
static int GetSlopePixelZ_Town(TileIndex tile, uint x, uint y)
|
||||
|
@@ -115,6 +115,7 @@
|
||||
#include "tracerestrict.h"
|
||||
#include "worker_thread.h"
|
||||
#include "vehiclelist.h"
|
||||
#include "core/backup_type.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@@ -2482,10 +2483,9 @@ static inline void DrawRouteStep(const Viewport * const vp, const TileIndex tile
|
||||
DrawSprite(SetBit(s, PALETTE_MODIFIER_TRANSPARENT), PALETTE_TO_TRANSPARENT, _cur_dpi->left + x_bottom_spr, _cur_dpi->top + y2);
|
||||
|
||||
/* Fill with the data. */
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
y2 = y + _vp_route_step_height_top;
|
||||
DrawPixelInfo dpi_for_text = _vdd->MakeDPIForText();
|
||||
_cur_dpi = &dpi_for_text;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &dpi_for_text);
|
||||
|
||||
const int x_str = x_centre - (str_width / 2);
|
||||
if (list.size() > max_rank_order_type_count) {
|
||||
@@ -2521,7 +2521,6 @@ static inline void DrawRouteStep(const Viewport * const vp, const TileIndex tile
|
||||
}
|
||||
}
|
||||
}
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
static bool ViewportPrepareVehicleRouteSteps(const Vehicle * const veh)
|
||||
@@ -3325,9 +3324,8 @@ static void ViewportMapDrawScrollingViewportBox(const Viewport * const vp)
|
||||
|
||||
static void ViewportMapDrawSelection(const Viewport * const vp)
|
||||
{
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
DrawPixelInfo dpi_for_text = _vdd->MakeDPIForText();
|
||||
_cur_dpi = &dpi_for_text;
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &dpi_for_text);
|
||||
|
||||
auto draw_line = [&](Point from_pt, Point to_pt) {
|
||||
GfxDrawLine(from_pt.x, from_pt.y, to_pt.x, to_pt.y, PC_WHITE, 2, 0);
|
||||
@@ -3368,8 +3366,6 @@ static void ViewportMapDrawSelection(const Viewport * const vp)
|
||||
} else {
|
||||
draw_line(start_pt, end_pt);
|
||||
}
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
template <bool is_32bpp>
|
||||
@@ -3627,9 +3623,6 @@ void ViewportDoDraw(Viewport *vp, int left, int top, int right, int bottom, uint
|
||||
_spare_viewport_drawers.pop_back();
|
||||
}
|
||||
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
_cur_dpi = &_vdd->dpi;
|
||||
|
||||
_vdd->display_flags = display_flags;
|
||||
_vdd->transparency_opt = _transparency_opt;
|
||||
_vdd->invisibility_opt = _invisibility_opt;
|
||||
@@ -3643,7 +3636,7 @@ void ViewportDoDraw(Viewport *vp, int left, int top, int right, int bottom, uint
|
||||
_vdd->dpi.height = (bottom - top) & mask;
|
||||
_vdd->dpi.left = left & mask;
|
||||
_vdd->dpi.top = top & mask;
|
||||
_vdd->dpi.pitch = old_dpi->pitch;
|
||||
_vdd->dpi.pitch = _cur_dpi->pitch;
|
||||
_vd.last_child = nullptr;
|
||||
|
||||
_vdd->offset_x = UnScaleByZoomLower(_vdd->dpi.left - (vp->virtual_left & mask), vp->zoom);
|
||||
@@ -3651,7 +3644,9 @@ void ViewportDoDraw(Viewport *vp, int left, int top, int right, int bottom, uint
|
||||
int x = _vdd->offset_x + vp->left;
|
||||
int y = _vdd->offset_y + vp->top;
|
||||
|
||||
_vdd->dpi.dst_ptr = BlitterFactory::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
|
||||
_vdd->dpi.dst_ptr = BlitterFactory::GetCurrentBlitter()->MoveTo(_cur_dpi->dst_ptr, x - _cur_dpi->left, y - _cur_dpi->top);
|
||||
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, &_vdd->dpi);
|
||||
|
||||
if (vp->overlay != nullptr && vp->overlay->GetCargoMask() != 0 && vp->overlay->GetCompanyMask() != 0) {
|
||||
vp->overlay->PrepareDraw();
|
||||
@@ -3698,8 +3693,6 @@ void ViewportDoDraw(Viewport *vp, int left, int top, int right, int bottom, uint
|
||||
}, vp, _vdd.release());
|
||||
}
|
||||
}
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
/* This is run in a worker thread */
|
||||
@@ -3776,9 +3769,10 @@ void ViewportDoDrawProcessAllPending()
|
||||
_viewport_drawer_returns.pop_back();
|
||||
lk.unlock();
|
||||
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
ViewportDoDrawPhase3(vp);
|
||||
_cur_dpi = old_dpi;
|
||||
{
|
||||
AutoRestoreBackup dpi_backup(_cur_dpi, AutoRestoreBackupNoNewValueTag{});
|
||||
ViewportDoDrawPhase3(vp);
|
||||
}
|
||||
|
||||
_viewport_drawer_jobs--;
|
||||
if (_viewport_drawer_jobs == 0) return;
|
||||
|
Reference in New Issue
Block a user