Changeset - r5236:be42400a9cd6
[Not reviewed]
master
0 3 0
rubidium - 18 years ago 2006-12-04 13:57:04
rubidium@openttd.org
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
-Codechange: use IsWindowWidget(Disabled|Hidden) in favor of IsWidget(Disabled|Hidden).
3 files changed with 18 insertions and 41 deletions:
widget.c
12
13
window.h
2
24
0 comments (0 inline, 0 general)
widget.c
Show inline comments
 
@@ -129,22 +129,23 @@ void ScrollbarClickHandler(Window *w, co
 
 * @param *w Window to look inside
 
 * @param  x,y Window client coordinates
 
 * @return A widget index, or -1 if no widget was found.
 
 */
 
int GetWidgetFromPos(const Window *w, int x, int y)
 
{
 
	const Widget *wi;
 
	int index, found_index = -1;
 
	uint index;
 
	int found_index = -1;
 

	
 
	// Go through the widgets and check if we find the widget that the coordinate is
 
	// inside.
 
	for (index = 0,wi = w->widget; wi->type != WWT_LAST; index++, wi++) {
 
	for (index = 0; index < w->widget_count; index++) {
 
		const Widget *wi = &w->widget[index];
 
		if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue;
 

	
 
		if (x >= wi->left && x <= wi->right && y >= wi->top &&  y <= wi->bottom &&
 
				!IsWidgetHidden(wi)) {
 
				!IsWindowWidgetHidden(w, index)) {
 
			found_index = index;
 
		}
 
	}
 

	
 
	return found_index;
 
}
 
@@ -181,27 +182,25 @@ void DrawFrameRect(int left, int top, in
 
	}
 
}
 

	
 

	
 
void DrawWindowWidgets(const Window *w)
 
{
 
	const Widget *wi;
 
	const DrawPixelInfo* dpi = _cur_dpi;
 
	Rect r;
 
	int i = 0;
 
	uint i;
 

	
 
	wi = w->widget;
 

	
 
	do {
 
		bool clicked = IsWindowWidgetLowered((Window*)w, i);
 
	for (i = 0; i < w->widget_count; i++) {
 
		const Widget *wi = &w->widget[i];
 
		bool clicked = IsWindowWidgetLowered(w, i);
 

	
 
		if (dpi->left > (r.right=/*w->left + */wi->right) ||
 
				dpi->left + dpi->width <= (r.left=wi->left/* + w->left*/) ||
 
				dpi->top > (r.bottom=/*w->top +*/ wi->bottom) ||
 
				dpi->top + dpi->height <= (r.top = /*w->top +*/ wi->top) ||
 
				IsWidgetHidden(wi)) {
 
				IsWindowWidgetHidden(w, i)) {
 
			continue;
 
		}
 

	
 
		switch (wi->type & WWT_MASK) {
 
		case WWT_IMGBTN:
 
		case WWT_IMGBTN_2: {
 
@@ -454,18 +453,18 @@ void DrawWindowWidgets(const Window *w)
 
			if (w->caption_color != 0xFF) {
 
				GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _colour_gradient[_player_colors[w->caption_color]][4]);
 
			}
 

	
 
			DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top+2, wi->data, 0x84);
 
draw_default:;
 
			if (IsWidgetDisabled(wi)) {
 
			if (IsWindowWidgetDisabled(w, i)) {
 
				GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _colour_gradient[wi->color&0xF][2] | PALETTE_MODIFIER_GREYOUT);
 
			}
 
		}
 
		}
 
	} while (i++, (++wi)->type != WWT_LAST);
 
	}
 

	
 

	
 
	if (w->flags4 & WF_WHITE_BORDER_MASK) {
 
		//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
 
		DrawFrameRect(0, 0, w->width-1, w->height-1, 0xF, FR_BORDERONLY);
 
	}
window.c
Show inline comments
 
@@ -97,16 +97,16 @@ static void DispatchLeftClickEvent(Windo
 
	e.event = WE_CLICK;
 

	
 
	if (w->desc_flags & WDF_DEF_WIDGET) {
 
		e.we.click.widget = GetWidgetFromPos(w, x, y);
 
		if (e.we.click.widget < 0) return; /* exit if clicked outside of widgets */
 

	
 
		wi = &w->widget[e.we.click.widget];
 
		/* don't allow any interaction if the button has been disabled */
 
		if (IsWindowWidgetDisabled(w, e.we.click.widget)) return;
 

	
 
		/* don't allow any interaction if the button has been disabled */
 
		if (IsWidgetDisabled(wi)) return;
 
		wi = &w->widget[e.we.click.widget];
 

	
 
		if (wi->type & WWB_MASK) {
 
			/* special widget handling for buttons*/
 
			switch (wi->type) {
 
				case WWT_PANEL   | WWB_PUSHBUTTON: /* WWT_PUSHBTN */
 
				case WWT_IMGBTN  | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */
 
@@ -1738,13 +1738,13 @@ void InvalidateWindow(WindowClass cls, W
 

	
 
void InvalidateWidget(const Window *w, byte widget_index)
 
{
 
	const Widget *wi = &w->widget[widget_index];
 

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

	
 
	SetDirtyBlocks(w->left + wi->left, w->top + wi->top, w->left + wi->right + 1, w->top + wi->bottom + 1);
 
}
 

	
 
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index)
 
{
window.h
Show inline comments
 
@@ -664,31 +664,20 @@ static inline void EnableWindowWidget(Wi
 
{
 
	SetWindowWidgetDisabledState(w, widget_index, false);
 
}
 

	
 
/**
 
 * Gets the enabled/disabled status of a widget.
 
 * This is the same as IsWindowWidgetDisabled, only working on direct widget, instead of an index
 
 * @param wi : Widget to get the status from
 
 * @return status of the widget ie: disabled = true, enabled = false
 
 */
 
static inline bool IsWidgetDisabled(const Widget *wi)
 
{
 
	return HASBIT(wi->display_flags, WIDG_DISABLED);
 
}
 

	
 
/**
 
 * Gets the enabled/disabled status of a widget.
 
 * @param w : Window on which the widget is located
 
 * @param widget_index : index of this widget in the window
 
 * @return status of the widget ie: disabled = true, enabled = false
 
 */
 
static inline bool IsWindowWidgetDisabled(const Window *w, byte widget_index)
 
{
 
	assert(widget_index < w->widget_count);
 
	return IsWidgetDisabled(&w->widget[widget_index]);
 
	return HASBIT(w->widget[widget_index].display_flags, WIDG_DISABLED);
 
}
 

	
 
/**
 
 * Sets the hidden/shown status of a widget.
 
 * By default, widgets are visible.
 
 * On certain conditions, they have to be hidden.
 
@@ -721,31 +710,20 @@ static inline void ShowWindowWidget(Wind
 
{
 
	SetWindowWidgetHiddenState(w, widget_index, false);
 
}
 

	
 
/**
 
 * Gets the visibility of a widget.
 
 * Works directly on a widget, instead of an index
 
 * @param wi Widget to get the status from
 
 * @return status of the widget ie. hidden = true, visible = false
 
 */
 
static inline bool IsWidgetHidden(const Widget *wi)
 
{
 
	return HASBIT(wi->display_flags, WIDG_HIDDEN);
 
}
 

	
 
/**
 
 * Gets the visibility of a widget.
 
 * @param w : Window on which the widget is located
 
 * @param widget_index : index of this widget in the window
 
 * @return status of the widget ie: hidden = true, visible = false
 
 */
 
static inline bool IsWindowWidgetHidden(const Window *w, byte widget_index)
 
{
 
	assert(widget_index < w->widget_count);
 
	return IsWidgetHidden(&w->widget[widget_index]);
 
	return HASBIT(w->widget[widget_index].display_flags, WIDG_HIDDEN);
 
}
 

	
 
/**
 
 * Sets the lowered/raised status of a widget.
 
 * @param w : Window on which the widget is located
 
 * @param widget_index : index of this widget in the window
0 comments (0 inline, 0 general)