mirror of https://github.com/OpenTTD/OpenTTD
(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.release/0.5
parent
9d24f3df0a
commit
67b88e7ed9
13
widget.c
13
widget.c
|
@ -141,7 +141,7 @@ int GetWidgetFromPos(const Window *w, int x, int y)
|
||||||
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue;
|
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue;
|
||||||
|
|
||||||
if (x >= wi->left && x <= wi->right && y >= wi->top && y <= wi->bottom &&
|
if (x >= wi->left && x <= wi->right && y >= wi->top && y <= wi->bottom &&
|
||||||
!HASBIT(w->hidden_state,index)) {
|
!IsWidgetHidden(wi)) {
|
||||||
found_index = index;
|
found_index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,15 +187,10 @@ void DrawWindowWidgets(const Window *w)
|
||||||
const Widget *wi;
|
const Widget *wi;
|
||||||
const DrawPixelInfo* dpi = _cur_dpi;
|
const DrawPixelInfo* dpi = _cur_dpi;
|
||||||
Rect r;
|
Rect r;
|
||||||
uint32 cur_click, cur_disabled, cur_hidden;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
wi = w->widget;
|
wi = w->widget;
|
||||||
|
|
||||||
cur_click = w->click_state;
|
|
||||||
cur_disabled = w->disabled_state;
|
|
||||||
cur_hidden = w->hidden_state;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
bool clicked = IsWindowWidgetLowered((Window*)w, i);
|
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->left + dpi->width <= (r.left=wi->left/* + w->left*/) ||
|
||||||
dpi->top > (r.bottom=/*w->top +*/ wi->bottom) ||
|
dpi->top > (r.bottom=/*w->top +*/ wi->bottom) ||
|
||||||
dpi->top + dpi->height <= (r.top = /*w->top +*/ wi->top) ||
|
dpi->top + dpi->height <= (r.top = /*w->top +*/ wi->top) ||
|
||||||
cur_hidden & 1) {
|
IsWidgetHidden(wi)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,12 +455,12 @@ void DrawWindowWidgets(const Window *w)
|
||||||
|
|
||||||
DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->data, 0x84);
|
DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->data, 0x84);
|
||||||
draw_default:;
|
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);
|
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) {
|
if (w->flags4 & WF_WHITE_BORDER_MASK) {
|
||||||
|
|
17
window.c
17
window.c
|
@ -57,7 +57,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y)
|
||||||
wi = &w->widget[e.we.click.widget];
|
wi = &w->widget[e.we.click.widget];
|
||||||
|
|
||||||
/* don't allow any interaction if the button has been disabled */
|
/* 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) {
|
if (wi->type & 0xE0) {
|
||||||
/* special widget handling for buttons*/
|
/* special widget handling for buttons*/
|
||||||
|
@ -1068,22 +1068,25 @@ static bool HandleWindowDragging(void)
|
||||||
bool resize_width = false;
|
bool resize_width = false;
|
||||||
|
|
||||||
while (wi->type != WWT_LAST) {
|
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 */
|
/* Resize this widget */
|
||||||
if (wi->resize_flag & RESIZE_LEFT) {
|
if (rsizeflag & RESIZE_LEFT) {
|
||||||
wi->left += x;
|
wi->left += x;
|
||||||
resize_width = true;
|
resize_width = true;
|
||||||
}
|
}
|
||||||
if (wi->resize_flag & RESIZE_RIGHT) {
|
if (rsizeflag & RESIZE_RIGHT) {
|
||||||
wi->right += x;
|
wi->right += x;
|
||||||
resize_width = true;
|
resize_width = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wi->resize_flag & RESIZE_TOP) {
|
if (rsizeflag & RESIZE_TOP) {
|
||||||
wi->top += y;
|
wi->top += y;
|
||||||
resize_height = true;
|
resize_height = true;
|
||||||
}
|
}
|
||||||
if (wi->resize_flag & RESIZE_BOTTOM) {
|
if (rsizeflag & RESIZE_BOTTOM) {
|
||||||
wi->bottom += y;
|
wi->bottom += y;
|
||||||
resize_height = true;
|
resize_height = true;
|
||||||
}
|
}
|
||||||
|
@ -1538,7 +1541,7 @@ void InvalidateWidget(const Window *w, byte widget_index)
|
||||||
const Widget *wi = &w->widget[widget_index];
|
const Widget *wi = &w->widget[widget_index];
|
||||||
|
|
||||||
/* Don't redraw the window if the widget is invisible or of no-type */
|
/* 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);
|
SetDirtyBlocks(w->left + wi->left, w->top + wi->top, w->left + wi->right + 1, w->top + wi->bottom + 1);
|
||||||
}
|
}
|
||||||
|
|
47
window.h
47
window.h
|
@ -52,11 +52,19 @@ enum ResizeFlags {
|
||||||
RESIZE_LRB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_BOTTOM,
|
RESIZE_LRB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_BOTTOM,
|
||||||
RESIZE_LRTB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM,
|
RESIZE_LRTB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM,
|
||||||
RESIZE_RTB = 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;
|
} ResizeFlag;
|
||||||
|
|
||||||
typedef struct Widget {
|
typedef struct Widget {
|
||||||
byte type; ///< Widget type, see @WindowWidgetTypes
|
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
|
byte color; ///< Widget colour, see docs/ottd-colourtext-palette.png
|
||||||
uint16 left, right, top, bottom; ///< The position offsets inside the window
|
uint16 left, right, top, bottom; ///< The position offsets inside the window
|
||||||
uint16 data; ///< The String/Image or special code (list-matrixes) of a widget
|
uint16 data; ///< The String/Image or special code (list-matrixes) of a widget
|
||||||
|
@ -312,7 +320,6 @@ struct Window {
|
||||||
|
|
||||||
byte caption_color;
|
byte caption_color;
|
||||||
|
|
||||||
uint32 click_state, disabled_state, hidden_state;
|
|
||||||
WindowProc *wndproc;
|
WindowProc *wndproc;
|
||||||
ViewPort *viewport;
|
ViewPort *viewport;
|
||||||
const Widget *original_widget;
|
const Widget *original_widget;
|
||||||
|
@ -613,7 +620,7 @@ void DrawWindowViewport(Window *w);
|
||||||
*/
|
*/
|
||||||
static inline void SetWindowWidgetDisabledState(Window *w, byte widget_index, bool disab_stat)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -636,6 +643,17 @@ static inline void EnableWindowWidget(Window *w, byte widget_index)
|
||||||
SetWindowWidgetDisabledState(w, widget_index, false);
|
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.
|
* Gets the enabled/disabled status of a widget.
|
||||||
* @param w : Window on which the widget is located
|
* @param w : Window on which the widget is located
|
||||||
|
@ -644,7 +662,7 @@ static inline void EnableWindowWidget(Window *w, byte widget_index)
|
||||||
*/
|
*/
|
||||||
static inline bool IsWindowWidgetDisabled(Window *w, byte widget_index)
|
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)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -680,6 +698,17 @@ static inline void ShowWindowWidget(Window *w, byte widget_index)
|
||||||
SetWindowWidgetHiddenState(w, widget_index, false);
|
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.
|
* Gets the visibility of a widget.
|
||||||
* @param w : Window on which the widget is located
|
* @param w : Window on which the widget is located
|
||||||
|
@ -688,7 +717,7 @@ static inline void ShowWindowWidget(Window *w, byte widget_index)
|
||||||
*/
|
*/
|
||||||
static inline bool IsWindowWidgetHidden(Window *w, byte widget_index)
|
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)
|
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)
|
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)
|
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);
|
void InitWindowSystem(void);
|
||||||
|
|
Loading…
Reference in New Issue