File diff r13023:9f6499c8d4fb → r13024:48c81d0b078a
src/window.cpp
Show inline comments
 
@@ -104,15 +104,15 @@ void SetFocusedWindow(Window *w)
 
	if (_focused_window == w) return;
 

	
 
	/* Invalidate focused widget */
 
	if (_focused_window != NULL) {
 
		if (_focused_window->focused_widget != NULL) {
 
			uint focused_widget_id = _focused_window->focused_widget - _focused_window->widget;
 
			_focused_window->InvalidateWidget(focused_widget_id);
 
			_focused_window->SetWidgetDirty(focused_widget_id);
 
		}
 
		if (_focused_window->nested_focus != NULL) _focused_window->nested_focus->Invalidate(_focused_window);
 
		if (_focused_window->nested_focus != NULL) _focused_window->nested_focus->SetDirty(_focused_window);
 
	}
 

	
 
	/* Remember which window was previously focused */
 
	Window *old_focused = _focused_window;
 
	_focused_window = w;
 

	
 
@@ -149,13 +149,13 @@ bool Window::SetFocusedWidget(byte widge
 
	if (this->widget != NULL) {
 
		/* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */
 
		if (widget_index >= this->widget_count || this->widget + widget_index == this->focused_widget) return false;
 

	
 
		if (this->focused_widget != NULL) {
 
			/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
 
			this->InvalidateWidget(this->focused_widget - this->widget);
 
			this->SetWidgetDirty(this->focused_widget - this->widget);
 
		}
 
		this->focused_widget = &this->widget[widget_index];
 
		return true;
 
	}
 

	
 
	if (this->nested_array != NULL) {
 
@@ -164,13 +164,13 @@ bool Window::SetFocusedWidget(byte widge
 

	
 
		assert(this->nested_array[widget_index] != NULL); // Setting focus to a non-existing widget is a bad idea.
 
		if (this->nested_focus != NULL) {
 
			if (this->nested_array[widget_index] == this->nested_focus) return false;
 

	
 
			/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
 
			this->nested_focus->Invalidate(this);
 
			this->nested_focus->SetDirty(this);
 
		}
 
		this->nested_focus = this->nested_array[widget_index];
 
		return true;
 
	}
 
	NOT_REACHED();
 
}
 
@@ -243,53 +243,53 @@ void CDECL Window::SetWidgetsLoweredStat
 
void Window::RaiseButtons(bool autoraise)
 
{
 
	if (this->widget != NULL) {
 
		for (uint i = 0; i < this->widget_count; i++) {
 
			if ((!autoraise || (this->widget[i].type & WWB_PUSHBUTTON)) && this->IsWidgetLowered(i)) {
 
				this->RaiseWidget(i);
 
				this->InvalidateWidget(i);
 
				this->SetWidgetDirty(i);
 
			}
 
		}
 
	}
 
	if (this->nested_array != NULL) {
 
		for (uint i = 0; i < this->nested_array_size; i++) {
 
			if (this->nested_array[i] != NULL && (!autoraise || (this->nested_array[i]->type & WWB_PUSHBUTTON)) && this->IsWidgetLowered(i)) {
 
				this->RaiseWidget(i);
 
				this->InvalidateWidget(i);
 
				this->SetWidgetDirty(i);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Invalidate a widget, i.e. mark it as being changed and in need of redraw.
 
 * @param widget_index the widget to redraw.
 
 */
 
void Window::InvalidateWidget(byte widget_index) const
 
void Window::SetWidgetDirty(byte widget_index) const
 
{
 
	if (this->widget != NULL) {
 
		const Widget *wi = &this->widget[widget_index];
 

	
 
		/* Don't redraw the window if the widget is invisible or of no-type */
 
		if (wi->type == WWT_EMPTY || IsWidgetHidden(widget_index)) return;
 

	
 
		SetDirtyBlocks(this->left + wi->left, this->top + wi->top, this->left + wi->right + 1, this->top + wi->bottom + 1);
 
	}
 
	if (this->nested_array != NULL) this->nested_array[widget_index]->Invalidate(this);
 
	if (this->nested_array != NULL) this->nested_array[widget_index]->SetDirty(this);
 
}
 

	
 
/**
 
 * Do all things to make a button look clicked and mark it to be
 
 * unclicked in a few ticks.
 
 * @param widget the widget to "click"
 
 */
 
void Window::HandleButtonClick(byte widget)
 
{
 
	this->LowerWidget(widget);
 
	this->flags4 |= WF_TIMEOUT_BEGIN;
 
	this->InvalidateWidget(widget);
 
	this->SetWidgetDirty(widget);
 
}
 

	
 
/**
 
 * Return a widget of the requested type from the window.
 
 * @param widget_type the widget type to look for
 
 */
 
@@ -406,19 +406,19 @@ static void DispatchLeftClickEvent(Windo
 

	
 
		if ((w->desc_flags & WDF_RESIZABLE) && widget_type == WWT_RESIZEBOX) {
 
			/* When the resize widget is on the left size of the window
 
			 * we assume that that button is used to resize to the left. */
 
			int left_pos = (wi != NULL) ? wi->left : nw->pos_x;
 
			StartWindowSizing(w, left_pos < (w->width / 2));
 
			w->InvalidateWidget(widget_index);
 
			w->SetWidgetDirty(widget_index);
 
			return;
 
		}
 

	
 
		if ((w->desc_flags & WDF_STICKY_BUTTON) && widget_type == WWT_STICKYBOX) {
 
			w->flags4 ^= WF_STICKY;
 
			w->InvalidateWidget(widget_index);
 
			w->SetWidgetDirty(widget_index);
 
			return;
 
		}
 
	}
 

	
 
	Point pt = { x, y };
 

	
 
@@ -2437,13 +2437,13 @@ 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)
 
void SetWindowDirty(WindowClass cls, WindowNumber number)
 
{
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls && w->window_number == number) w->SetDirty();
 
	}
 
}
 
@@ -2451,27 +2451,27 @@ void InvalidateWindow(WindowClass cls, W
 
/**
 
 * 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)
 
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
 
{
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls && w->window_number == number) {
 
			w->InvalidateWidget(widget_index);
 
			w->SetWidgetDirty(widget_index);
 
		}
 
	}
 
}
 

	
 
/**
 
 * Mark all windows of a particular class as dirty (in need of repainting)
 
 * @param cls Window class
 
 */
 
void InvalidateWindowClasses(WindowClass cls)
 
void SetWindowClassesDirty(WindowClass cls)
 
{
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls) w->SetDirty();
 
	}
 
}