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
 
@@ -1444,14 +1444,14 @@ void Window::FindWindowPlacementAndResiz
 
		if (this->resize.step_width  > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width;
 
		if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height;
 

	
 
		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;
 
	int ny = this->top;
 

	
 
	if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
 
@@ -2047,14 +2047,14 @@ void ResizeWindow(Window *w, int delta_x
 
		w->width  = w->nested_root->current_x;
 
		w->height = w->nested_root->current_y;
 
	}
 

	
 
	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();
 
}
 

	
 
/**
 
 * Return the top of the main view available for general use.
 
 * @return Uppermost vertical coordinate available.
 
@@ -3051,12 +3051,13 @@ void UpdateWindows()
 

	
 
	TimerManager<TimerWindow>::Elapsed(delta_ms);
 
	CallWindowRealtimeTickEvent(delta_ms.count());
 

	
 
	/* Process invalidations before anything else. */
 
	for (Window *w : Window::Iterate()) {
 
		w->ProcessScheduledResize();
 
		w->ProcessScheduledInvalidations();
 
		w->ProcessHighlightedInvalidations();
 
	}
 

	
 
	/* Skip the actual drawing on dedicated servers without screen.
 
	 * But still empty the invalidation queues above. */
 
@@ -3109,12 +3110,32 @@ void SetWindowClassesDirty(WindowClass c
 
	for (const Window *w : Window::Iterate()) {
 
		if (w->window_class == cls) w->SetDirty();
 
	}
 
}
 

	
 
/**
 
 * 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.
 
 */
 
void Window::InvalidateData(int data, bool gui_scope)
 
{
src/window_gui.h
Show inline comments
 
@@ -271,12 +271,13 @@ private:
 
protected:
 
	void InitializeData(WindowNumber window_number);
 
	void InitializePositionSize(int x, int y, int min_width, int min_height);
 
	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();
 

	
 
public:
 
	Window(WindowDesc *desc);
 
@@ -556,12 +557,14 @@ public:
 
	{
 
		return this->shade_select != nullptr && this->shade_select->shown_plane == SZSP_HORIZONTAL;
 
	}
 

	
 
	void SetShaded(bool make_shaded);
 

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

	
 
	/*** Event handling ***/
 

	
0 comments (0 inline, 0 general)