changeset 4749:957fe32219ca draft

(svn r6661) Feature: Windows are not restricted to 32 widget items anymore. The functions required to do so are to be found in window.h. Rather then use the old deprecated disabled_state, hidden_state and click_state uint32 variables, we now need to use accessors like SetWindowWidgetDisabledState, SetWindowWidgetHiddenState or SetWindowWidgetLoweredState. This is the final commit for the merge of XTDwidget branch.
author belugas <belugas@openttd.org>
date Fri, 06 Oct 2006 01:33:27 +0000
parents 8410cac194d5
children f06a500fb9f5
files widget.c window.c window.h
diffstat 3 files changed, 52 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/widget.c
+++ b/widget.c
@@ -141,7 +141,7 @@
 		if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue;
 
 		if (x >= wi->left && x <= wi->right && y >= wi->top &&  y <= wi->bottom &&
-				!HASBIT(w->hidden_state,index)) {
+				!IsWidgetHidden(wi)) {
 			found_index = index;
 		}
 	}
@@ -187,15 +187,10 @@
 	const Widget *wi;
 	const DrawPixelInfo* dpi = _cur_dpi;
 	Rect r;
-	uint32 cur_click, cur_disabled, cur_hidden;
 	int i = 0;
 
 	wi = w->widget;
 
-	cur_click = w->click_state;
-	cur_disabled = w->disabled_state;
-	cur_hidden = w->hidden_state;
-
 	do {
 		bool clicked = IsWindowWidgetLowered((Window*)w, i);
 
@@ -203,7 +198,7 @@
 				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) ||
-				cur_hidden & 1) {
+				IsWidgetHidden(wi)) {
 			continue;
 		}
 
@@ -460,12 +455,12 @@
 
 			DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->data, 0x84);
 draw_default:;
-			if (cur_disabled & 1) {
+			if (IsWidgetDisabled(wi)) {
 				GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _colour_gradient[wi->color&0xF][2] | PALETTE_MODIFIER_GREYOUT);
 			}
 		}
 		}
-	} while (i++, cur_click>>=1, cur_disabled>>=1, cur_hidden >>= 1, (++wi)->type != WWT_LAST);
+	} while (i++, (++wi)->type != WWT_LAST);
 
 
 	if (w->flags4 & WF_WHITE_BORDER_MASK) {
--- a/window.c
+++ b/window.c
@@ -57,7 +57,7 @@
 		wi = &w->widget[e.we.click.widget];
 
 		/* don't allow any interaction if the button has been disabled */
-		if (HASBIT(w->disabled_state, e.we.click.widget)) return;
+		if (IsWidgetDisabled(wi)) return;
 
 		if (wi->type & 0xE0) {
 			/* special widget handling for buttons*/
@@ -1068,22 +1068,25 @@
 				bool resize_width = false;
 
 				while (wi->type != WWT_LAST) {
-					if (wi->resize_flag != RESIZE_NONE) {
+					/* Isolate the resizing flags */
+					byte rsizeflag = GB(wi->display_flags, 0, 4);
+
+					if (rsizeflag != RESIZE_NONE) {
 						/* Resize this widget */
-						if (wi->resize_flag & RESIZE_LEFT) {
+						if (rsizeflag & RESIZE_LEFT) {
 							wi->left += x;
 							resize_width = true;
 						}
-						if (wi->resize_flag & RESIZE_RIGHT) {
+						if (rsizeflag & RESIZE_RIGHT) {
 							wi->right += x;
 							resize_width = true;
 						}
 
-						if (wi->resize_flag & RESIZE_TOP) {
+						if (rsizeflag & RESIZE_TOP) {
 							wi->top += y;
 							resize_height = true;
 						}
-						if (wi->resize_flag & RESIZE_BOTTOM) {
+						if (rsizeflag & RESIZE_BOTTOM) {
 							wi->bottom += y;
 							resize_height = true;
 						}
@@ -1538,7 +1541,7 @@
 	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 || HASBIT(w->hidden_state, widget_index)) return;
+	if (wi->type == WWT_EMPTY || IsWidgetHidden(wi)) return;
 
 	SetDirtyBlocks(w->left + wi->left, w->top + wi->top, w->left + wi->right + 1, w->top + wi->bottom + 1);
 }
--- a/window.h
+++ b/window.h
@@ -52,11 +52,19 @@
 	RESIZE_LRB    = RESIZE_LEFT  | RESIZE_RIGHT  | RESIZE_BOTTOM,
 	RESIZE_LRTB   = RESIZE_LEFT  | RESIZE_RIGHT  | RESIZE_TOP | RESIZE_BOTTOM,
 	RESIZE_RTB    = RESIZE_RIGHT | RESIZE_TOP    | RESIZE_BOTTOM,
+
+	/* The following flags are used by the system to specify what is disabled, hidden, or clicked
+	 * They are used in the same place as the above RESIZE_x flags, Widget visual_flags.
+	 * These states are used in exceptions. If nothing is specified, they will indicate
+	 * Enabled, visible or unclicked widgets*/
+	WIDG_DISABLED = 4,  // widget is greyed out, not available
+	WIDG_HIDDEN   = 5,  // widget is made invisible
+	WIDG_LOWERED  = 6,  // widget is paint lowered, a pressed button in fact
 } ResizeFlag;
 
 typedef struct Widget {
 	byte type;                        ///< Widget type, see @WindowWidgetTypes
-	byte resize_flag;                 ///< Resize direction, alignment, etc. during resizing, see @ResizeFlags
+	byte display_flags;               ///< Resize direction, alignment, etc. during resizing, see @ResizeFlags
 	byte color;                       ///< Widget colour, see docs/ottd-colourtext-palette.png
 	uint16 left, right, top, bottom;  ///< The position offsets inside the window
 	uint16 data;                      ///< The String/Image or special code (list-matrixes) of a widget
@@ -312,7 +320,6 @@
 
 	byte caption_color;
 
-	uint32 click_state, disabled_state, hidden_state;
 	WindowProc *wndproc;
 	ViewPort *viewport;
 	const Widget *original_widget;
@@ -613,7 +620,7 @@
  */
 static inline void SetWindowWidgetDisabledState(Window *w, byte widget_index, bool disab_stat)
 {
-	SB(w->disabled_state, widget_index, 1, !!disab_stat);
+	SB(w->widget[widget_index].display_flags, WIDG_DISABLED, 1, !!disab_stat);
 }
 
 /**
@@ -638,13 +645,24 @@
 
 /**
  * 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(Window *w, byte widget_index)
 {
-	return HASBIT(w->disabled_state, widget_index);
+	return IsWidgetDisabled(&w->widget[widget_index]);
 }
 
 /**
@@ -657,7 +675,7 @@
  */
 static inline void SetWindowWidgetHiddenState(Window *w, byte widget_index, bool hidden_stat)
 {
-	SB(w->hidden_state, widget_index, 1, !!hidden_stat);
+	SB(w->widget[widget_index].display_flags, WIDG_HIDDEN, 1, !!hidden_stat);
 }
 
 /**
@@ -682,13 +700,24 @@
 
 /**
  * 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(Window *w, byte widget_index)
 {
-	return HASBIT(w->hidden_state, widget_index);
+	return IsWidgetHidden(&w->widget[widget_index]);
 }
 
 /**
@@ -699,7 +728,7 @@
  */
 static inline void SetWindowWidgetLoweredState(Window *w, byte widget_index, bool lowered_stat)
 {
-	SB(w->click_state, widget_index, 1, !!lowered_stat);
+	SB(w->widget[widget_index].display_flags, WIDG_LOWERED, 1, !!lowered_stat);
 }
 
 /**
@@ -709,7 +738,7 @@
  */
 static inline void ToggleWidgetLoweredState(Window *w, byte widget_index)
 {
-	TOGGLEBIT(w->click_state, widget_index);
+	TOGGLEBIT(w->widget[widget_index].display_flags, WIDG_LOWERED);
 }
 
 /**
@@ -740,7 +769,7 @@
  */
 static inline bool IsWindowWidgetLowered(Window *w, byte widget_index)
 {
-	return HASBIT(w->click_state, widget_index);
+	return HASBIT(w->widget[widget_index].display_flags, WIDG_LOWERED);
 }
 
 void InitWindowSystem(void);