Changeset - r13652:659b7e4eab91
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2009-11-19 17:56:03
rubidium@openttd.org
(svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
2 files changed with 33 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -1692,12 +1692,13 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, 
 
		case WWT_TEXTBTN_2:
 
		case WWT_LABEL:
 
		case WWT_TEXT:
 
		case WWT_MATRIX:
 
		case WWT_EDITBOX:
 
		case NWID_BUTTON_DRPDOWN:
 
		case NWID_BUTTON_ARROW:
 
			this->SetFill(false, false);
 
			break;
 

	
 
		case WWT_SCROLLBAR:
 
		case WWT_SCROLL2BAR:
 
			this->SetFill(false, true);
 
@@ -1820,12 +1821,22 @@ void NWidgetLeaf::SetupSmallestSize(Wind
 
			if (this->type == WWT_IMGBTN_2) d2 = maxdim(d2, GetSpriteSize(this->widget_data + 1));
 
			d2.width += extra.width;
 
			d2.height += extra.height;
 
			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;
 
			if (NWidgetLeaf::closebox_dimension.width == 0) {
 
				NWidgetLeaf::closebox_dimension = maxdim(GetStringBoundingBox(STR_BLACK_CROSS), GetStringBoundingBox(STR_SILVER_CROSS));
 
				NWidgetLeaf::closebox_dimension.width += extra.width;
 
@@ -1922,12 +1933,24 @@ void NWidgetLeaf::Draw(const Window *w)
 
		case WWT_TEXTBTN_2:
 
			if (this->index >= 0) w->SetStringParameters(this->index);
 
			DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
 
			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);
 
			break;
 

	
 
		case WWT_TEXT:
 
@@ -2174,13 +2197,13 @@ static int MakeNWidget(const NWidgetPart
 
				*biggest_index = max(*biggest_index, (int)parts->u.widget.index);
 
				break;
 
			}
 

	
 
			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;
 
		}
 
		num_used++;
 
		parts++;
src/widget_type.h
Show inline comments
 
@@ -80,12 +80,20 @@ enum MatrixWidgetValues {
 

	
 
	/* Number of row bits of the WWT_MATRIX widget data. */
 
	MAT_ROW_START = 8, ///< Lowest bit of the number of rows.
 
	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.
 
 */
 
enum WidgetType {
 
	/* Window widget types. */
 
	WWT_EMPTY,      ///< Empty widget, place holder to reserve space in widget array
 
@@ -118,12 +126,13 @@ enum WidgetType {
 
	NWID_HORIZONTAL_LTR, ///< Horizontal container that doesn't change the order of the widgets for RTL languages.
 
	NWID_VERTICAL,       ///< Vertical container.
 
	NWID_SPACER,         ///< Invisible widget that takes some space.
 
	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.
 
	WPT_MINSIZE,      ///< Widget part for specifying minimal size.
 
	WPT_MINTEXTLINES, ///< Widget part for specifying minimal number of lines of text.
 
	WPT_FILL,         ///< Widget part for specifying fill.
0 comments (0 inline, 0 general)