mirror of https://github.com/OpenTTD/OpenTTD
(svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
parent
a36c258644
commit
089992ef13
|
@ -1695,6 +1695,7 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data,
|
|||
case WWT_MATRIX:
|
||||
case WWT_EDITBOX:
|
||||
case NWID_BUTTON_DRPDOWN:
|
||||
case NWID_BUTTON_ARROW:
|
||||
this->SetFill(false, false);
|
||||
break;
|
||||
|
||||
|
@ -1823,6 +1824,16 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
|||
size = maxdim(size, d2);
|
||||
break;
|
||||
}
|
||||
case NWID_BUTTON_ARROW: {
|
||||
static const Dimension extra = {WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT, WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM};
|
||||
padding = &extra;
|
||||
Dimension d2 = maxdim(GetSpriteSize(SPR_ARROW_LEFT), GetSpriteSize(SPR_ARROW_RIGHT));
|
||||
d2.width += extra.width;
|
||||
d2.height += extra.height;
|
||||
size = maxdim(size, d2);
|
||||
break;
|
||||
}
|
||||
|
||||
case WWT_CLOSEBOX: {
|
||||
static const Dimension extra = {WD_CLOSEBOX_LEFT + WD_CLOSEBOX_RIGHT, WD_CLOSEBOX_TOP + WD_CLOSEBOX_BOTTOM};
|
||||
padding = &extra;
|
||||
|
@ -1925,6 +1936,18 @@ void NWidgetLeaf::Draw(const Window *w)
|
|||
DrawLabel(r, this->type, clicked, this->widget_data);
|
||||
break;
|
||||
|
||||
case NWID_BUTTON_ARROW: {
|
||||
SpriteID sprite;
|
||||
switch (this->widget_data) {
|
||||
case AWV_DECREASE: sprite = _dynlang.text_dir != TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
|
||||
case AWV_INCREASE: sprite = _dynlang.text_dir == TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
|
||||
case AWV_LEFT: sprite = SPR_ARROW_LEFT; break;
|
||||
case AWV_RIGHT: sprite = SPR_ARROW_RIGHT; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
DrawImageButtons(r, WWT_PUSHIMGBTN, this->colour, clicked, sprite);
|
||||
}
|
||||
|
||||
case WWT_LABEL:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawLabel(r, this->type, clicked, this->widget_data);
|
||||
|
@ -2177,7 +2200,7 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
|
|||
|
||||
default:
|
||||
if (*dest != NULL) return num_used;
|
||||
assert((parts->type & WWT_MASK) < WWT_LAST || parts->type == NWID_BUTTON_DRPDOWN);
|
||||
assert((parts->type & WWT_MASK) < WWT_LAST || parts->type == NWID_BUTTON_DRPDOWN || parts->type == NWID_BUTTON_ARROW);
|
||||
*dest = new NWidgetLeaf(parts->type, parts->u.widget.colour, parts->u.widget.index, 0x0, STR_NULL);
|
||||
*biggest_index = max(*biggest_index, (int)parts->u.widget.index);
|
||||
break;
|
||||
|
|
|
@ -83,6 +83,14 @@ enum MatrixWidgetValues {
|
|||
MAT_ROW_BITS = 8, ///< Number of bits for the number of rows in the matrix.
|
||||
};
|
||||
|
||||
/** Values for an arrow widget */
|
||||
enum ArrowWidgetValues {
|
||||
AWV_DECREASE, ///< Arrow to the left or in case of RTL to the right
|
||||
AWV_INCREASE, ///< Arrow to the right or in case of RTL to the left
|
||||
AWV_LEFT, ///< Force the arrow to the left
|
||||
AWV_RIGHT, ///< Force the arrow to the right
|
||||
};
|
||||
|
||||
/**
|
||||
* Window widget types, nested widget types, and nested widget part types.
|
||||
*/
|
||||
|
@ -121,6 +129,7 @@ enum WidgetType {
|
|||
NWID_SELECTION, ///< Stacked widgets, only one visible at a time (eg in a panel with tabs).
|
||||
NWID_VIEWPORT, ///< Nested widget containing a viewport.
|
||||
NWID_BUTTON_DRPDOWN, ///< Button with a drop-down.
|
||||
NWID_BUTTON_ARROW, ///< Button with an arrow
|
||||
|
||||
/* Nested widget part types. */
|
||||
WPT_RESIZE, ///< Widget part for specifying resizing.
|
||||
|
|
Loading…
Reference in New Issue