Changeset - r28581:c07444122f9c
[Not reviewed]
master
0 2 0
Peter Nelson - 10 months ago 2024-01-27 18:44:27
peter1138@openttd.org
Fix #11894: Defer window OnResize event to avoid processing multiple times per input tick. (#11900)
2 files changed with 28 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/window.cpp
Show inline comments
 
@@ -1447,8 +1447,8 @@ void Window::FindWindowPlacementAndResiz
 
		ResizeWindow(this, enlarge_x, enlarge_y);
 
		/* ResizeWindow() calls this->OnResize(). */
 
	} else {
 
		/* Always call OnResize; that way the scrollbars and matrices get initialized. */
 
		this->OnResize();
 
		/* Schedule OnResize; that way the scrollbars and matrices get initialized. */
 
		this->ScheduleResize();
 
	}
 

	
 
	int nx = this->left;
 
@@ -2050,8 +2050,8 @@ void ResizeWindow(Window *w, int delta_x
 

	
 
	EnsureVisibleCaption(w, w->left, w->top);
 

	
 
	/* Always call OnResize to make sure everything is initialised correctly if it needs to be. */
 
	w->OnResize();
 
	/* Schedule OnResize to make sure everything is initialised correctly if it needs to be. */
 
	w->ScheduleResize();
 
	w->SetDirty();
 
}
 

	
 
@@ -3054,6 +3054,7 @@ void UpdateWindows()
 

	
 
	/* Process invalidations before anything else. */
 
	for (Window *w : Window::Iterate()) {
 
		w->ProcessScheduledResize();
 
		w->ProcessScheduledInvalidations();
 
		w->ProcessHighlightedInvalidations();
 
	}
 
@@ -3112,6 +3113,26 @@ void SetWindowClassesDirty(WindowClass c
 
}
 

	
 
/**
 
 * Mark this window as resized and in need of OnResize() event.
 
 */
 
void Window::ScheduleResize()
 
{
 
	this->scheduled_resize = true;
 
}
 

	
 
/**
 
 * Process scheduled OnResize() event.
 
 */
 
void Window::ProcessScheduledResize()
 
{
 
	/* Sometimes OnResize() resizes the window again, in which case we can reprocess immediately. */
 
	while (this->scheduled_resize) {
 
		this->scheduled_resize = false;
 
		this->OnResize();
 
	}
 
}
 

	
 
/**
 
 * Mark this window's data as invalid (in need of re-computing)
 
 * @param data The data to invalidate with
 
 * @param gui_scope Whether the function is called from GUI scope.
src/window_gui.h
Show inline comments
 
@@ -274,6 +274,7 @@ protected:
 
	virtual void FindWindowPlacementAndResize(int def_width, int def_height);
 

	
 
	std::vector<int> scheduled_invalidation_data;  ///< Data of scheduled OnInvalidateData() calls.
 
	bool scheduled_resize; ///< Set if window has been resized.
 

	
 
	/* Protected to prevent deletion anywhere outside Window::DeleteClosedWindows(). */
 
	virtual ~Window();
 
@@ -559,6 +560,8 @@ public:
 

	
 
	void SetShaded(bool make_shaded);
 

	
 
	void ScheduleResize();
 
	void ProcessScheduledResize();
 
	void InvalidateData(int data = 0, bool gui_scope = true);
 
	void ProcessScheduledInvalidations();
 
	void ProcessHighlightedInvalidations();
0 comments (0 inline, 0 general)