diff options
-rw-r--r-- | widget.c | 13 | ||||
-rw-r--r-- | window.c | 17 | ||||
-rw-r--r-- | window.h | 47 |
3 files changed, 52 insertions, 25 deletions
@@ -141,7 +141,7 @@ int GetWidgetFromPos(const Window *w, int x, int y) 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 @@ void DrawWindowWidgets(const Window *w) 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 @@ void DrawWindowWidgets(const Window *w) 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 @@ void DrawWindowWidgets(const Window *w) 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) { @@ -57,7 +57,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y) 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 @@ static bool HandleWindowDragging(void) 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 @@ 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 || 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); } @@ -52,11 +52,19 @@ enum ResizeFlags { 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 @@ struct Window { byte caption_color; - uint32 click_state, disabled_state, hidden_state; WindowProc *wndproc; ViewPort *viewport; const Widget *original_widget; @@ -613,7 +620,7 @@ void DrawWindowViewport(Window *w); */ 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 @@ static inline void EnableWindowWidget(Window *w, byte widget_index) /** * 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 bool IsWindowWidgetDisabled(Window *w, byte widget_index) */ 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 @@ static inline void ShowWindowWidget(Window *w, byte widget_index) /** * 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 bool IsWindowWidgetHidden(Window *w, byte widget_index) */ 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 SetWindowWidgetLoweredState(Window *w, byte widget_index, boo */ 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 void RaiseWindowWidget(Window *w, byte widget_index) */ 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); |