Changeset - r28810:dd35d3d734ac
[Not reviewed]
master
0 2 0
Peter Nelson - 2 months ago 2024-02-25 08:35:57
peter1138@openttd.org
Fix d3c673e: Don't defer OnResize() after ReInit() (#12174)

Some windows resize themselves during painting and issue ReInit(). In this case deferred OnResize() causes a visible glitch as the event is handled on the next redraw.
2 files changed with 10 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/window.cpp
Show inline comments
 
@@ -981,13 +981,13 @@ void Window::ReInit(int rx, int ry, bool
 
	if (reposition) {
 
		Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number);
 
		this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
 
		this->FindWindowPlacementAndResize(this->window_desc->GetDefaultWidth(), this->window_desc->GetDefaultHeight());
 
	}
 

	
 
	ResizeWindow(this, dx, dy);
 
	ResizeWindow(this, dx, dy, true, false);
 
	/* ResizeWindow() does this->SetDirty() already, no need to do it again here. */
 
}
 

	
 
/**
 
 * Set the shaded state of the window to \a make_shaded.
 
 * @param make_shaded If \c true, shade the window (roll up until just the title bar is visible), else unshade/unroll the window to its original size.
 
@@ -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 {
 
		/* Schedule OnResize; that way the scrollbars and matrices get initialized. */
 
		this->ScheduleResize();
 
		/* Always call OnResize; that way the scrollbars and matrices get initialized. */
 
		this->OnResize();
 
	}
 

	
 
	int nx = this->left;
 
	int ny = this->top;
 

	
 
	if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
 
@@ -2021,13 +2021,13 @@ static void EnsureVisibleCaption(Window 
 
 * ensuring proper redrawal.
 
 * @param w       Window to resize
 
 * @param delta_x Delta x-size of changed window (positive if larger, etc.)
 
 * @param delta_y Delta y-size of changed window
 
 * @param clamp_to_screen Whether to make sure the whole window stays visible
 
 */
 
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
 
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
 
{
 
	if (delta_x != 0 || delta_y != 0) {
 
		if (clamp_to_screen) {
 
			/* Determine the new right/bottom position. If that is outside of the bounds of
 
			 * the resolution clamp it in such a manner that it stays within the bounds. */
 
			int new_right  = w->left + w->width  + delta_x;
 
@@ -2048,13 +2048,17 @@ void ResizeWindow(Window *w, int delta_x
 
		w->height = w->nested_root->current_y;
 
	}
 

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

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

	
 
/**
 
 * Return the top of the main view available for general use.
 
 * @return Uppermost vertical coordinate available.
src/window_func.h
Show inline comments
 
@@ -23,13 +23,13 @@ void ChangeWindowOwner(Owner old_owner, 
 
template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
 
Window *FindWindowById(WindowClass cls, T number)
 
{
 
	return FindWindowById(cls, number.base());
 
}
 

	
 
void ResizeWindow(Window *w, int x, int y, bool clamp_to_screen = true);
 
void ResizeWindow(Window *w, int x, int y, bool clamp_to_screen = true, bool schedule_resize = true);
 
int PositionMainToolbar(Window *w);
 
int PositionStatusbar(Window *w);
 
int PositionNewsMessage(Window *w);
 
int PositionNetworkChatWindow(Window *w);
 

	
 
int GetMainViewTop();
0 comments (0 inline, 0 general)