summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-11-19 17:56:03 +0000
committerrubidium <rubidium@openttd.org>2009-11-19 17:56:03 +0000
commit089992ef13310f22923ec65399f5d2bd350ce473 (patch)
tree2a3159aa66ee97837bbc93d899607c4a5f9ae0ec /src
parenta36c258644004932f30322d237e0be7214a2191f (diff)
downloadopenttd-089992ef13310f22923ec65399f5d2bd350ce473.tar.xz
(svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
Diffstat (limited to 'src')
-rw-r--r--src/widget.cpp25
-rw-r--r--src/widget_type.h9
2 files changed, 33 insertions, 1 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index c191d6987..88ecf0e9d 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -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;
diff --git a/src/widget_type.h b/src/widget_type.h
index 18afdbdc2..1dc4fc782 100644
--- a/src/widget_type.h
+++ b/src/widget_type.h
@@ -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.