Changeset - r12262:8e175bd7b32c
[Not reviewed]
master
0 4 0
alberth - 15 years ago 2009-06-28 20:09:40
alberth@openttd.org
(svn r16687) -Codechange: Perform re-initialization of windows with nested widgets after a language change.
4 files changed with 56 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -323,6 +323,7 @@ struct GameOptionsWindow : Window {
 
				CheckForMissingGlyphsInLoadedLanguagePack();
 
				UpdateAllStationVirtCoord();
 
				UpdateAllWaypointSigns();
 
				ReInitAllWindows();
 
				MarkWholeScreenDirty();
 
				break;
 

	
src/window.cpp
Show inline comments
 
@@ -560,6 +560,48 @@ void SetWindowDirty(const Window *w)
 
	if (w != NULL) w->SetDirty();
 
}
 

	
 
/** Re-initialize a window.
 
 * @todo Extend the function to handle viewports.
 
 */
 
void Window::ReInit()
 
{
 
	if (this->nested_root == NULL) return; // Only nested widget windows can re-initialize.
 

	
 
	this->SetDirty(); // Mark whole current window as dirty.
 

	
 
	/* Save current size. */
 
	int window_width  = this->width;
 
	int window_height = this->height;
 

	
 
	/* Re-initialize the window from the ground up. No need to change the nested_array, as all widgets stay where they are. */
 
	this->nested_root->SetupSmallestSize();
 
	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, false);
 
	this->width  = this->nested_root->smallest_x;
 
	this->height = this->nested_root->smallest_y;
 
	this->resize.width  = this->nested_root->smallest_x;
 
	this->resize.height = this->nested_root->smallest_y;
 
	this->resize.step_width  = this->nested_root->resize_x;
 
	this->resize.step_height = this->nested_root->resize_y;
 

	
 
	/* Resize as close to the original size as possible. */
 
	window_width  = max(window_width,  this->width);
 
	window_height = max(window_height, this->height);
 
	int dx = (this->resize.step_width  == 0) ? 0 : window_width  - this->width;
 
	int dy = (this->resize.step_height == 0) ? 0 : window_height - this->height;
 
	/* dx and dy has to go by step.. calculate it.
 
	 * The cast to int is necessary else dx/dy are implicitly casted to unsigned int, which won't work. */
 
	if (this->resize.step_width  > 1) dx -= dx % (int)this->resize.step_width;
 
	if (this->resize.step_height > 1) dy -= dy % (int)this->resize.step_height;
 

	
 
	if (dx == 0 && dy == 0) return; // No resize needed.
 

	
 
	ResizeWindow(this, dx, dy); // Sets post-resize dirty blocks.
 
	Point diff;
 
	diff.x = dx;
 
	diff.y = dy;
 
	this->OnResize(diff);
 
}
 

	
 
/** Find the Window whose parent pointer points to this window
 
 * @param w parent Window to find child of
 
 * @return a Window pointer that is the child of w, or NULL otherwise */
 
@@ -2488,6 +2530,16 @@ void HideVitalWindows()
 
	DeleteWindowById(WC_STATUS_BAR, 0);
 
}
 

	
 
/** Re-initialize all windows. */
 
void ReInitAllWindows()
 
{
 
	Window *w;
 

	
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		w->ReInit();
 
	}
 
}
 

	
 
/**
 
 * (Re)position main toolbar window at the screen
 
 * @param w Window structure of the main toolbar window, may also be \c NULL
src/window_func.h
Show inline comments
 
@@ -32,6 +32,8 @@ void DeleteConstructionWindows();
 
void HideVitalWindows();
 
void ShowVitalWindows();
 

	
 
void ReInitAllWindows();
 

	
 
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index);
 
void InvalidateWindow(WindowClass cls, WindowNumber number);
 
void InvalidateWindowClasses(WindowClass cls);
src/window_gui.h
Show inline comments
 
@@ -429,6 +429,7 @@ public:
 
	void DeleteChildWindows() const;
 

	
 
	void SetDirty() const;
 
	void ReInit();
 

	
 
	/*** Event handling ***/
 

	
0 comments (0 inline, 0 general)