Changeset - r27032:029c610aa2b2
[Not reviewed]
master
0 5 0
PeterN - 14 months ago 2023-03-31 15:06:36
peter1138@openttd.org
Codechange: Use a shared_ptr for viewport overlay. (#10586)
5 files changed with 7 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/linkgraph/linkgraph_gui.cpp
Show inline comments
 
@@ -562,7 +562,7 @@ LinkGraphLegendWindow::LinkGraphLegendWi
 
 * Set the overlay belonging to this menu and import its company/cargo settings.
 
 * @param overlay New overlay for this menu.
 
 */
 
void LinkGraphLegendWindow::SetOverlay(LinkGraphOverlay *overlay) {
 
void LinkGraphLegendWindow::SetOverlay(std::shared_ptr<LinkGraphOverlay> overlay) {
 
	this->overlay = overlay;
 
	uint32 companies = this->overlay->GetCompanyMask();
 
	for (uint c = 0; c < MAX_COMPANIES; c++) {
src/linkgraph/linkgraph_gui.h
Show inline comments
 
@@ -108,7 +108,7 @@ void ShowLinkGraphLegend();
 
struct LinkGraphLegendWindow : Window {
 
public:
 
	LinkGraphLegendWindow(WindowDesc *desc, int window_number);
 
	void SetOverlay(LinkGraphOverlay *overlay);
 
	void SetOverlay(std::shared_ptr<LinkGraphOverlay> overlay);
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override;
 
	void DrawWidget(const Rect &r, int widget) const override;
 
@@ -117,7 +117,7 @@ public:
 
	void OnInvalidateData(int data = 0, bool gui_scope = true) override;
 

	
 
private:
 
	LinkGraphOverlay *overlay;
 
	std::shared_ptr<LinkGraphOverlay> overlay;
 

	
 
	void UpdateOverlayCompanies();
 
	void UpdateOverlayCargoes();
src/main_gui.cpp
Show inline comments
 
@@ -224,7 +224,7 @@ struct MainWindow : Window
 
		NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
 
		nvp->InitializeViewport(this, TileXY(32, 32), ScaleZoomGUI(ZOOM_LVL_VIEWPORT));
 

	
 
		this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 2);
 
		this->viewport->overlay = std::make_shared<LinkGraphOverlay>(this, WID_M_VIEWPORT, 0, 0, 2);
 
		this->refresh.SetInterval(LINKGRAPH_DELAY);
 
	}
 

	
src/viewport.cpp
Show inline comments
 
@@ -203,10 +203,7 @@ static Point MapXYZToViewport(const View
 

	
 
void DeleteWindowViewport(Window *w)
 
{
 
	if (w->viewport == nullptr) return;
 

	
 
	delete w->viewport->overlay;
 
	free(w->viewport);
 
	delete w->viewport;
 
	w->viewport = nullptr;
 
}
 

	
 
@@ -227,7 +224,7 @@ void InitializeWindowViewport(Window *w,
 
{
 
	assert(w->viewport == nullptr);
 

	
 
	ViewportData *vp = CallocT<ViewportData>(1);
 
	ViewportData *vp = new ViewportData();
 

	
 
	vp->left = x + w->left;
 
	vp->top = y + w->top;
src/viewport_type.h
Show inline comments
 
@@ -31,7 +31,7 @@ struct Viewport {
 
	int virtual_height;  ///< height << zoom
 

	
 
	ZoomLevel zoom; ///< The zoom level of the viewport.
 
	LinkGraphOverlay *overlay;
 
	std::shared_ptr<LinkGraphOverlay> overlay;
 
};
 

	
 
/** Location information about a sign as seen on the viewport */
0 comments (0 inline, 0 general)