Changeset - r10597:17355376f997
[Not reviewed]
master
0 4 0
rubidium - 15 years ago 2009-01-06 22:37:42
rubidium@openttd.org
(svn r14880) -Codechange: make it clear which way the FOR_ALL_WINDOWS goes (from back to front or vice versa) and make it iterate over the Window* instead of Window**.
4 files changed with 90 insertions and 135 deletions:
0 comments (0 inline, 0 general)
src/sound.cpp
Show inline comments
 
@@ -208,18 +208,17 @@ void SndCopyToPool()
 
 * @param right  Right edge of virtual coordinates where the sound is produced
 
 * @param top    Top edge of virtual coordinates where the sound is produced
 
 * @param bottom Bottom edge of virtual coordinates where the sound is produced
 
 */
 
static void SndPlayScreenCoordFx(SoundFx sound, int left, int right, int top, int bottom)
 
{
 
	Window* const *wz;
 

	
 
	if (msf.effect_vol == 0) return;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		const ViewPort *vp = (*wz)->viewport;
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		const ViewPort *vp = w->viewport;
 

	
 
		if (vp != NULL &&
 
				left < vp->virtual_left + vp->virtual_width && right > vp->virtual_left &&
 
				top < vp->virtual_top + vp->virtual_height && bottom > vp->virtual_top) {
 
			int screen_x = (left + right) / 2 - vp->virtual_left;
 
			int width = (vp->virtual_width == 0 ? 1 : vp->virtual_width);
src/viewport.cpp
Show inline comments
 
@@ -1663,16 +1663,15 @@ static void MarkViewportDirty(const View
 
 * @param right  Right edge of area to repaint
 
 * @param bottom Bottom edge of area to repaint
 
 * @ingroup dirty
 
 */
 
void MarkAllViewportsDirty(int left, int top, int right, int bottom)
 
{
 
	Window **wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		ViewPort *vp = (*wz)->viewport;
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		ViewPort *vp = w->viewport;
 
		if (vp != NULL) {
 
			assert(vp->width != 0);
 
			MarkViewportDirty(vp, left, top, right, bottom);
 
		}
 
	}
 
}
src/window.cpp
Show inline comments
 
@@ -358,18 +358,17 @@ static void DrawOverlappedWindow(Window*
 
 * @param top Top edge of the rectangle that should be repainted
 
 * @param right Right edge of the rectangle that should be repainted
 
 * @param bottom Bottom edge of the rectangle that should be repainted
 
 */
 
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
 
{
 
	Window* const *wz;
 
	const Window *w;
 
	DrawPixelInfo bk;
 
	_cur_dpi = &bk;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		const Window *w = *wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (right > w->left &&
 
				bottom > w->top &&
 
				left < w->left + w->width &&
 
				top < w->top + w->height) {
 
			/* Window w intersects with the rectangle => needs repaint */
 
			DrawOverlappedWindow(wz, left, top, right, bottom);
 
@@ -398,16 +397,14 @@ void SetWindowDirty(const Window *w)
 

	
 
/** 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 */
 
static Window *FindChildWindow(const Window *w)
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *v = *wz;
 
	Window *v;
 
	FOR_ALL_WINDOWS_FROM_BACK(v) {
 
		if (v->parent == w) return v;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
@@ -415,16 +412,16 @@ static Window *FindChildWindow(const Win
 
 * or the behaviour is undefined but function should never fail
 
 * @param w window to query Z Position
 
 * @return Pointer into the window-list at the position of \a w
 
 */
 
Window **FindWindowZPosition(const Window *w)
 
{
 
	Window **wz;
 
	const Window *v;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		if (*wz == w) return wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(v) {
 
		if (v == w) return wz;
 
	}
 

	
 
	DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls",
 
		w->window_class, w->window_number);
 
	return NULL;
 
}
 
@@ -483,16 +480,14 @@ Window::~Window()
 
 * @param cls Window class
 
 * @param number Number of the window within the window class
 
 * @return Pointer to the found window, or \c NULL if not available
 
 */
 
Window *FindWindowById(WindowClass cls, WindowNumber number)
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls && w->window_number == number) return w;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
@@ -515,20 +510,19 @@ void DeleteWindowById(WindowClass cls, W
 
/**
 
 * Delete all windows of a given class
 
 * @param cls Window class of windows to delete
 
 */
 
void DeleteWindowByClass(WindowClass cls)
 
{
 
	Window* const *wz;
 
	Window *w;
 

	
 
restart_search:
 
	/* When we find the window to delete, we need to restart the search
 
	 * as deleting this window could cascade in deleting (many) others
 
	 * anywhere in the z-array */
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls) {
 
			delete w;
 
			goto restart_search;
 
		}
 
	}
 
}
 
@@ -536,20 +530,19 @@ restart_search:
 
/** Delete all windows of a company. We identify windows of a company
 
 * by looking at the caption colour. If it is equal to the company ID
 
 * then we say the window belongs to the company and should be deleted
 
 * @param id company identifier */
 
void DeleteCompanyWindows(CompanyID id)
 
{
 
	Window* const *wz;
 
	Window *w;
 

	
 
restart_search:
 
	/* When we find the window to delete, we need to restart the search
 
	 * as deleting this window could cascade in deleting (many) others
 
	 * anywhere in the z-array */
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->caption_color == id) {
 
			delete w;
 
			goto restart_search;
 
		}
 
	}
 

	
 
@@ -561,17 +554,14 @@ restart_search:
 
 * company in the case of a company merger. Do not change ownership of windows
 
 * that need to be deleted once takeover is complete
 
 * @param old_owner original owner of the window
 
 * @param new_owner the new owner of the window */
 
void ChangeWindowOwner(Owner old_owner, Owner new_owner)
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 

	
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->caption_color != old_owner) continue;
 

	
 
		switch (w->window_class) {
 
			case WC_COMPANY_COLOR:
 
			case WC_FINANCES:
 
			case WC_STATION_LIST:
 
@@ -658,16 +648,14 @@ static void BringWindowToFront(const Win
 
 * - News window, Chatbar (when on)
 
 * - Any sticked windows since we wanted to keep these
 
 * @return w pointer to the window that is going to be deleted
 
 */
 
static Window *FindDeletableWindow()
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) {
 
			return w;
 
		}
 
	}
 
	return NULL;
 
}
 
@@ -678,16 +666,14 @@ static Window *FindDeletableWindow()
 
 * Start finding an appropiate candidate from the lowest z-values (bottom)
 
 * @see FindDeletableWindow()
 
 * @return w Pointer to the window that is being deleted
 
 */
 
static Window *ForceFindDeletableWindow()
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w;
 
	}
 
	NOT_REACHED();
 
}
 

	
 
/**
 
@@ -883,22 +869,20 @@ Window::Window(int x, int y, int width, 
 
 * @param height  Height of the rectangle
 
 * @param pos     If rectangle is good, use this parameter to return the top-left corner of the new window
 
 * @return Boolean indication that the rectangle is a good place for the new window
 
 */
 
static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos)
 
{
 
	Window* const *wz;
 

	
 
	int right  = width + left;
 
	int bottom = height + top;
 

	
 
	if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) return false;
 

	
 
	/* Make sure it is not obscured by any window. */
 
	FOR_ALL_WINDOWS(wz) {
 
		const Window *w = *wz;
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == WC_MAIN_WINDOW) continue;
 

	
 
		if (right > w->left &&
 
				w->left + w->width > left &&
 
				bottom > w->top &&
 
				w->top + w->height > top) {
 
@@ -921,24 +905,22 @@ static bool IsGoodAutoPlace1(int left, i
 
 * @param height  Height of the rectangle
 
 * @param pos     If rectangle is good, use this parameter to return the top-left corner of the new window
 
 * @return Boolean indication that the rectangle is a good place for the new window
 
 */
 
static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos)
 
{
 
	Window* const *wz;
 

	
 
	/* Left part of the rectangle may be at most 1/4 off-screen,
 
	 * right part of the rectangle may be at most 1/2 off-screen
 
	 */
 
	if (left < -(width>>2) || left > _screen.width - (width>>1)) return false;
 
	/* Bottom part of the rectangle may be at most 1/4 off-screen */
 
	if (top < 22 || top > _screen.height - (height>>2)) return false;
 

	
 
	/* Make sure it is not obscured by any window. */
 
	FOR_ALL_WINDOWS(wz) {
 
		const Window *w = *wz;
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == WC_MAIN_WINDOW) continue;
 

	
 
		if (left + width > w->left &&
 
				w->left + w->width > left &&
 
				top + height > w->top &&
 
				w->top + w->height > top) {
 
@@ -956,24 +938,23 @@ static bool IsGoodAutoPlace2(int left, i
 
 * @param width  Width of the new window
 
 * @param height Height of the new window
 
 * @return Top-left coordinate of the new window
 
 */
 
static Point GetAutoPlacePosition(int width, int height)
 
{
 
	Window* const *wz;
 
	Point pt;
 

	
 
	/* First attempt, try top-left of the screen */
 
	if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt;
 

	
 
	/* Second attempt, try around all existing windows with a distance of 2 pixels.
 
	 * The new window must be entirely on-screen, and not overlap with an existing window.
 
	 * Eight starting points are tried, two at each corner.
 
	 */
 
	FOR_ALL_WINDOWS(wz) {
 
		const Window *w = *wz;
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == WC_MAIN_WINDOW) continue;
 

	
 
		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt;
 
		if (IsGoodAutoPlace1(w->left - width - 2,    w->top, width, height, pt)) return pt;
 
		if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt;
 
		if (IsGoodAutoPlace1(w->left, w->top - height - 2,    width, height, pt)) return pt;
 
@@ -984,43 +965,38 @@ static Point GetAutoPlacePosition(int wi
 
	}
 

	
 
	/* Third attempt, try around all existing windows with a distance of 2 pixels.
 
	 * The new window may be partly off-screen, and must not overlap with an existing window.
 
	 * Only four starting points are tried.
 
	 */
 
	FOR_ALL_WINDOWS(wz) {
 
		const Window *w = *wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == WC_MAIN_WINDOW) continue;
 

	
 
		if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt;
 
		if (IsGoodAutoPlace2(w->left - width - 2,    w->top, width, height, pt)) return pt;
 
		if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt;
 
		if (IsGoodAutoPlace2(w->left, w->top - height - 2,    width, height, pt)) return pt;
 
	}
 

	
 
	/* Fourth and final attempt, put window at diagonal starting from (0, 24), try multiples
 
	 * of (+5, +5)
 
	 */
 
	{
 
		int left = 0, top = 24;
 
	int left = 0, top = 24;
 

	
 
restart:
 
		FOR_ALL_WINDOWS(wz) {
 
			const Window *w = *wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->left == left && w->top == top) {
 
			left += 5;
 
			top += 5;
 
			goto restart;
 
		}
 
	}
 

	
 
			if (w->left == left && w->top == top) {
 
				left += 5;
 
				top += 5;
 
				goto restart;
 
			}
 
		}
 

	
 
		pt.x = left;
 
		pt.y = top;
 
		return pt;
 
	}
 
	pt.x = left;
 
	pt.y = top;
 
	return pt;
 
}
 

	
 
/**
 
 * Compute the position of the top-left corner of a new window that is opened.
 
 *
 
 * By default position a child window at an offset of 10/10 of its parent.
 
@@ -1113,14 +1089,14 @@ Window::Window(const WindowDesc *desc, W
 
 * at the topmost window, obviously and work our way down to the bottom
 
 * @param x position x to query
 
 * @param y position y to query
 
 * @return a pointer to the found window if any, NULL otherwise */
 
Window *FindWindowFromPt(int x, int y)
 
{
 
	for (Window * const *wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		if (IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
 
			return w;
 
		}
 
	}
 

	
 
	return NULL;
 
@@ -1159,27 +1135,23 @@ void ResetWindowSystem()
 
	_thd.new_pos.x = 0;
 
	_thd.new_pos.y = 0;
 
}
 

	
 
static void DecreaseWindowCounters()
 
{
 
	Window* const *wz;
 

	
 
	for (wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		/* Unclick scrollbar buttons if they are pressed. */
 
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
 
			w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
 
			w->SetDirty();
 
		}
 
		w->OnMouseLoop();
 
	}
 

	
 
	for (wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 

	
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		if (w->flags4 & WF_TIMEOUT_MASK && !(--w->flags4 & WF_TIMEOUT_MASK)) {
 
			w->OnTimeout();
 
			if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons();
 
		}
 
	}
 
}
 
@@ -1306,20 +1278,18 @@ void ResizeWindow(Window *w, int x, int 
 
}
 

	
 
static bool _dragging_window;
 

	
 
static bool HandleWindowDragging()
 
{
 
	Window* const *wz;
 
	/* Get out immediately if no window is being dragged at all. */
 
	if (!_dragging_window) return true;
 

	
 
	/* Otherwise find the window... */
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 

	
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->flags4 & WF_DRAGGING) {
 
			const Widget *t = &w->widget[1]; // the title bar ... ugh
 

	
 
			/* Stop the dragging if the left mouse button was released */
 
			if (!_left_button_down) {
 
				w->flags4 &= ~WF_DRAGGING;
 
@@ -1331,21 +1301,19 @@ static bool HandleWindowDragging()
 
			int x = _cursor.pos.x + _drag_delta.x;
 
			int y = _cursor.pos.y + _drag_delta.y;
 
			int nx = x;
 
			int ny = y;
 

	
 
			if (_settings_client.gui.window_snap_radius != 0) {
 
				Window* const *vz;
 
				const Window *v;
 

	
 
				int hsnap = _settings_client.gui.window_snap_radius;
 
				int vsnap = _settings_client.gui.window_snap_radius;
 
				int delta;
 

	
 
				FOR_ALL_WINDOWS(vz) {
 
					const Window *v = *vz;
 

	
 
				FOR_ALL_WINDOWS_FROM_BACK(v) {
 
					if (v == w) continue; // Don't snap at yourself
 

	
 
					if (y + w->height > v->top && y < v->top + v->height) {
 
						/* Your left border <-> other right border */
 
						delta = abs(v->left + v->width - x);
 
						if (delta <= hsnap) {
 
@@ -1533,21 +1501,19 @@ static void StartWindowSizing(Window *w)
 
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
 
}
 

	
 

	
 
static bool HandleScrollbarScrolling()
 
{
 
	Window* const *wz;
 
	Window *w;
 

	
 
	/* Get out quickly if no item is being scrolled */
 
	if (!_scrolling_scrollbar) return true;
 

	
 
	/* Find the scrolling window */
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 

	
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->flags4 & WF_SCROLL_MIDDLE) {
 
			/* Abort if no button is clicked any more. */
 
			if (!_left_button_down) {
 
				w->flags4 &= ~WF_SCROLL_MIDDLE;
 
				w->SetDirty();
 
				break;
 
@@ -1726,15 +1692,14 @@ void HandleKeypress(uint32 raw_key)
 
			FindWindowById(WC_SAVELOAD,                0) != NULL ||
 
			FindWindowById(WC_COMPANY_PASSWORD_WINDOW, 0) != NULL) {
 
		query_open = true;
 
	}
 

	
 
	/* Call the event, start with the uppermost window. */
 
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 

	
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		/* if a query window is open, only call the event for certain window types */
 
		if (query_open &&
 
				w->window_class != WC_QUERY_STRING &&
 
				w->window_class != WC_SEND_NETWORK_MSG &&
 
				w->window_class != WC_GENERATE_LANDSCAPE &&
 
				w->window_class != WC_CONSOLE &&
 
@@ -1742,25 +1707,25 @@ void HandleKeypress(uint32 raw_key)
 
				w->window_class != WC_COMPANY_PASSWORD_WINDOW) {
 
			continue;
 
		}
 
		if (w->OnKeyPress(key, keycode) == Window::ES_HANDLED) return;
 
	}
 

	
 
	Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
	w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
	/* When there is no toolbar w is null, check for that */
 
	if (w != NULL) w->OnKeyPress(key, keycode);
 
}
 

	
 
/**
 
 * State of CONTROL key has changed
 
 */
 
void HandleCtrlChanged()
 
{
 
	/* Call the event, start with the uppermost window. */
 
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		if (w->OnCTRLStateChange() == Window::ES_HANDLED) return;
 
	}
 
}
 

	
 
/**
 
 * Local counter that is incremented each time an mouse input event is detected.
 
@@ -2028,37 +1993,36 @@ void InputLoop()
 

	
 
/**
 
 * Update the continuously changing contents of the windows, such as the viewports
 
 */
 
void UpdateWindows()
 
{
 
	Window* const *wz;
 
	Window *w;
 
	static int we4_timer = 0;
 
	int t = we4_timer + 1;
 

	
 
	if (t >= 100) {
 
		for (wz = _last_z_window; wz != _z_windows;) {
 
			(*--wz)->OnHundredthTick();
 
		FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
			w->OnHundredthTick();
 
		}
 
		t = 0;
 
	}
 
	we4_timer = t;
 

	
 
	for (wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		if (w->flags4 & WF_WHITE_BORDER_MASK) {
 
			w->flags4 -= WF_WHITE_BORDER_ONE;
 

	
 
			if (!(w->flags4 & WF_WHITE_BORDER_MASK)) w->SetDirty();
 
		}
 
	}
 

	
 
	DrawDirtyBlocks();
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz);
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->viewport != NULL) UpdateViewportPosition(w);
 
	}
 
	NetworkDrawChatMessage();
 
	/* Redraw mouse cursor in case it was hidden */
 
	DrawMouseCursor();
 
}
 

	
 
@@ -2066,48 +2030,43 @@ void UpdateWindows()
 
 * Mark window as dirty (in need of repainting)
 
 * @param cls Window class
 
 * @param number Window number in that class
 
 */
 
void InvalidateWindow(WindowClass cls, WindowNumber number)
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		const Window *w = *wz;
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls && w->window_number == number) w->SetDirty();
 
	}
 
}
 

	
 
/**
 
 * Mark a particular widget in a particular window as dirty (in need of repainting)
 
 * @param cls Window class
 
 * @param number Window number in that class
 
 * @param widget_index Index number of the widget that needs repainting
 
 */
 
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index)
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		const Window *w = *wz;
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls && w->window_number == number) {
 
			w->InvalidateWidget(widget_index);
 
		}
 
	}
 
}
 

	
 
/**
 
 * Mark all windows of a particular class as dirty (in need of repainting)
 
 * @param cls Window class
 
 */
 
void InvalidateWindowClasses(WindowClass cls)
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		if ((*wz)->window_class == cls) (*wz)->SetDirty();
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls) w->SetDirty();
 
	}
 
}
 

	
 
/**
 
 * Mark window data as invalid (in need of re-computing)
 
 * @param w Window with invalid data
 
@@ -2122,30 +2081,28 @@ void InvalidateThisWindowData(Window *w,
 
 * Mark window data of the window of a given class and specific window number as invalid (in need of re-computing)
 
 * @param cls Window class
 
 * @param number Window number within the class
 
 */
 
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data)
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w, data);
 
	}
 
}
 

	
 
/**
 
 * Mark window data of all windows of a given class as invalid (in need of re-computing)
 
 * @param cls Window class
 
 */
 
void InvalidateWindowClassesData(WindowClass cls, int data)
 
{
 
	Window* const *wz;
 
	Window *w;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz, data);
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls) InvalidateThisWindowData(w, data);
 
	}
 
}
 

	
 
/**
 
 * Dispatch WE_TICK event over all windows
 
 */
 
@@ -2154,33 +2111,33 @@ void CallWindowTickEvent()
 
	if (_scroller_click_timeout > 3) {
 
		_scroller_click_timeout -= 3;
 
	} else {
 
		_scroller_click_timeout = 0;
 
	}
 

	
 
	for (Window * const *wz = _last_z_window; wz != _z_windows;) {
 
		(*--wz)->OnTick();
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		w->OnTick();
 
	}
 
}
 

	
 
/**
 
 * Try to delete a non-vital window.
 
 * Non-vital windows are windows other than the game selection, main toolbar,
 
 * status bar, toolbar menu, and tooltip windows. Stickied windows are also
 
 * considered vital.
 
 */
 
void DeleteNonVitalWindows()
 
{
 
	Window* const *wz;
 
	Window *w;
 

	
 
restart_search:
 
	/* When we find the window to delete, we need to restart the search
 
	 * as deleting this window could cascade in deleting (many) others
 
	 * anywhere in the z-array */
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class != WC_MAIN_WINDOW &&
 
				w->window_class != WC_SELECT_GAME &&
 
				w->window_class != WC_MAIN_TOOLBAR &&
 
				w->window_class != WC_STATUS_BAR &&
 
				w->window_class != WC_TOOLBAR_MENU &&
 
				w->window_class != WC_TOOLTIPS &&
 
@@ -2196,24 +2153,24 @@ restart_search:
 
 * 'close' button is outside the gaming area. You cannot close it then; except
 
 * with this function. It closes all windows calling the standard function,
 
 * then, does a little hacked loop of closing all stickied windows. Note
 
 * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
 
void DeleteAllNonVitalWindows()
 
{
 
	Window* const *wz;
 
	Window *w;
 

	
 
	/* Delete every window except for stickied ones, then sticky ones as well */
 
	DeleteNonVitalWindows();
 

	
 
restart_search:
 
	/* When we find the window to delete, we need to restart the search
 
	 * as deleting this window could cascade in deleting (many) others
 
	 * anywhere in the z-array */
 
	FOR_ALL_WINDOWS(wz) {
 
		if ((*wz)->flags4 & WF_STICKY) {
 
			delete *wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->flags4 & WF_STICKY) {
 
			delete w;
 
			goto restart_search;
 
		}
 
	}
 
}
 

	
 
/** Delete all always on-top windows to get an empty screen */
 
@@ -2295,16 +2252,15 @@ void SetHScrollCount(Window *w, int num)
 
 * Relocate all windows to fit the new size of the game application screen
 
 * @param neww New width of the game application screen
 
 * @param newh New height of the game appliction screen
 
 */
 
void RelocateAllWindows(int neww, int newh)
 
{
 
	Window* const *wz;
 
	Window *w;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		int left, top;
 

	
 
		if (w->window_class == WC_MAIN_WINDOW) {
 
			ViewPort *vp = w->viewport;
 
			vp->width = w->width = neww;
 
			vp->height = w->height = newh;
src/window_gui.h
Show inline comments
 
@@ -538,13 +538,14 @@ int GetWidgetFromPos(const Window *w, in
 

	
 
/* window.cpp */
 
extern Window *_z_windows[];
 
extern Window **_last_z_window;
 

	
 
/** Iterate over all windows */
 
#define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++)
 
#define FOR_ALL_WINDOWS_FROM_BACK(w) for (Window **wz = _z_windows; wz != _last_z_window && (w = *wz) != NULL; wz++)
 
#define FOR_ALL_WINDOWS_FROM_FRONT(w) for (Window **wz = _last_z_window; wz != _z_windows && (w = *--wz) != NULL;)
 

	
 
/**
 
 * Disable scrolling of the main viewport when an input-window is active.
 
 * This contains the count of windows with a textbox in them.
 
 */
 
extern byte _no_scroll;
0 comments (0 inline, 0 general)