Changeset - r11832:0a9347eb1597
[Not reviewed]
master
0 2 0
alberth - 16 years ago 2009-05-04 18:42:49
alberth@openttd.org
(svn r16227) -Codechange: Added nested widgets for error windows, tooltip window, and dropdown window.
2 files changed with 69 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -445,21 +445,58 @@ static const Widget _errmsg_widgets[] = 
 
{      WWT_PANEL,   RESIZE_BOTTOM,  COLOUR_RED,     0,   239,    14,    45, 0x0,                       STR_NULL},
 
{      WWT_EMPTY,   RESIZE_NONE,    COLOUR_RED,     0,     0,     0,     0, 0x0,                       STR_NULL},
 
{      WWT_EMPTY,   RESIZE_NONE,    COLOUR_RED,     2,   237,    14,    45, 0x0,                       STR_NULL},
 
{    WIDGETS_END},
 
};
 

	
 
static const NWidgetPart _nested_errmsg_widgets[] = {
 
	NWidget(NWID_LAYERED),
 
		NWidget(NWID_VERTICAL),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_CLOSEBOX, COLOUR_RED, EMW_CLOSE),
 
				NWidget(WWT_CAPTION, COLOUR_RED, EMW_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION, STR_NULL),
 
			EndContainer(),
 
			NWidget(WWT_PANEL, COLOUR_RED, EMW_PANEL),
 
				NWidget(WWT_EMPTY, COLOUR_RED, EMW_MESSAGE), SetPadding(0, 2, 0, 2), SetMinimalSize(236, 32),
 
				NWidget(NWID_SPACER), SetResize(0, 1),
 
			EndContainer(),
 
		EndContainer(),
 
		NWidget(NWID_VERTICAL),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_EMPTY, COLOUR_RED, EMW_FACE), SetMinimalSize(1, 1), SetFill(false, false),
 
				NWidget(NWID_SPACER), SetFill(1, 0),
 
			EndContainer(),
 
			NWidget(NWID_SPACER), SetFill(1, 1), SetResize(0, 1),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static const Widget _errmsg_face_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,    COLOUR_RED,     0,    10,     0,    13, STR_BLACK_CROSS,                         STR_TOOLTIP_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,    COLOUR_RED,    11,   333,     0,    13, STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_NULL},
 
{      WWT_PANEL,   RESIZE_BOTTOM,  COLOUR_RED,     0,   333,    14,   136, 0x0,                                     STR_NULL},
 
{      WWT_EMPTY,   RESIZE_NONE,    COLOUR_RED,     2,    92,    16,   135, 0x0,                                     STR_NULL},
 
{      WWT_EMPTY,   RESIZE_NONE,    COLOUR_RED,    94,   331,    14,   136, 0x0,                                     STR_NULL},
 
{   WIDGETS_END},
 
};
 

	
 
static const NWidgetPart _nested_errmsg_face_widgets[] = {
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_CLOSEBOX, COLOUR_RED, EMW_CLOSE),
 
			NWidget(WWT_CAPTION, COLOUR_RED, EMW_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_NULL),
 
		EndContainer(),
 
		NWidget(WWT_PANEL, COLOUR_RED, EMW_PANEL),
 
			NWidget(NWID_HORIZONTAL), SetPIP(2, 1, 2),
 
				NWidget(WWT_EMPTY, COLOUR_RED, EMW_FACE), SetMinimalSize(91, 120), SetPadding(2, 0, 1, 0),
 
				NWidget(WWT_EMPTY, COLOUR_RED, EMW_MESSAGE), SetMinimalSize(238, 123),
 
			EndContainer(),
 
			NWidget(NWID_SPACER), SetResize(0, 1),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
struct ErrmsgWindow : public Window {
 
private:
 
	uint duration;
 
	uint64 decode_params[20];
 
	StringID message_1;
 
	StringID message_2;
 
@@ -554,12 +591,15 @@ public:
 
		return ES_HANDLED;
 
	}
 
};
 

	
 
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
 
{
 
	static Widget *generated_errmsg_widgets = NULL;
 
	static Widget *generated_errmsg_face_widgets = NULL;
 

	
 
	DeleteWindowById(WC_ERRMSG, 0);
 

	
 
	if (!_settings_client.gui.errmsg_duration) return;
 

	
 
	if (msg_2 == STR_NULL) msg_2 = STR_EMPTY;
 

	
 
@@ -580,24 +620,30 @@ void ShowErrorMessage(StringID msg_1, St
 
			pt.y = (pt.y < (_screen.height >> 1)) ? _screen.height - 80 : 100;
 

	
 
		} else {
 
			pt.x = (_screen.width - 240) >> 1;
 
			pt.y = (_screen.height - 46) >> 1;
 
		}
 
		new ErrmsgWindow(pt, 240, 46, msg_1, msg_2, _errmsg_widgets, false);
 

	
 
		const Widget *wid = InitializeWidgetArrayFromNestedWidgets(_nested_errmsg_widgets, lengthof(_nested_errmsg_widgets),
 
													_errmsg_widgets, &generated_errmsg_widgets);
 
		new ErrmsgWindow(pt, 240, 46, msg_1, msg_2, wid, false);
 
	} else {
 
		if ((x | y) != 0) {
 
			pt = RemapCoords2(x, y);
 
			vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
 
			pt.x = Clamp(UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left - (334 / 2),  0, _screen.width  - 334);
 
			pt.y = Clamp(UnScaleByZoom(pt.y - vp->virtual_top,  vp->zoom) + vp->top  - (137 / 2), 22, _screen.height - 137);
 
		} else {
 
			pt.x = (_screen.width  - 334) >> 1;
 
			pt.y = (_screen.height - 137) >> 1;
 
		}
 
		new ErrmsgWindow(pt, 334, 137, msg_1, msg_2, _errmsg_face_widgets, true);
 

	
 
		const Widget *wid = InitializeWidgetArrayFromNestedWidgets(_nested_errmsg_face_widgets, lengthof(_nested_errmsg_face_widgets),
 
													_errmsg_face_widgets, &generated_errmsg_face_widgets);
 
		new ErrmsgWindow(pt, 334, 137, msg_1, msg_2, wid, true);
 
	}
 
}
 

	
 
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
 
{
 
	StringID msg = STR_MESSAGE_ESTIMATED_COST;
 
@@ -659,12 +705,16 @@ void HideFillingPercent(TextEffectID *te
 

	
 
static const Widget _tooltips_widgets[] = {
 
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   199,     0,    31, 0x0, STR_NULL},
 
{   WIDGETS_END},
 
};
 

	
 
static const NWidgetPart _nested_tooltips_widgets[] = {
 
	NWidget(WWT_PANEL, COLOUR_GREY, 0), SetMinimalSize(200, 32), EndContainer(),
 
};
 

	
 
struct TooltipsWindow : public Window
 
{
 
	StringID string_id;
 
	byte paramcount;
 
	uint64 params[5];
 
	bool use_left_mouse_button;
 
@@ -711,12 +761,14 @@ struct TooltipsWindow : public Window
 
 * @param paramcount number of params to deal with
 
 * @param params (optional) up to 5 pieces of additional information that may be added to a tooltip
 
 * @param use_left_mouse_button close the tooltip when the left (true) or right (false) mousebutton is released
 
 */
 
void GuiShowTooltips(StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button)
 
{
 
	static Widget *generated_tooltips_widgets = NULL;
 

	
 
	DeleteWindowById(WC_TOOLTIPS, 0);
 

	
 
	if (str == STR_NULL) return;
 

	
 
	for (uint i = 0; i != paramcount; i++) SetDParam(i, params[i]);
 
	char buffer[512];
 
@@ -735,13 +787,15 @@ void GuiShowTooltips(StringID str, uint 
 
	 * Clamp value to below main toolbar and above statusbar. If tooltip would
 
	 * go below window, flip it so it is shown above the cursor */
 
	int y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12);
 
	if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5;
 
	int x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
 

	
 
	new TooltipsWindow(x, y, br.width, br.height, _tooltips_widgets, str, paramcount, params, use_left_mouse_button);
 
	const Widget *wid = InitializeWidgetArrayFromNestedWidgets(_nested_tooltips_widgets, lengthof(_nested_tooltips_widgets),
 
													_tooltips_widgets, &generated_tooltips_widgets);
 
	new TooltipsWindow(x, y, br.width, br.height, wid, str, paramcount, params, use_left_mouse_button);
 
}
 

	
 

	
 
static int DrawStationCoverageText(const AcceptedCargo cargo,
 
	int str_x, int str_y, StationCoverageType sct, bool supplies)
 
{
src/widgets/dropdown.cpp
Show inline comments
 
@@ -66,12 +66,19 @@ static void DeleteDropDownList(DropDownL
 
static const Widget _dropdown_menu_widgets[] = {
 
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_END,     0, 0,     0, 0, 0x0, STR_NULL},
 
{  WWT_SCROLLBAR,   RESIZE_NONE,  COLOUR_END,     0, 0,     0, 0, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST},
 
{   WIDGETS_END},
 
};
 

	
 
static const NWidgetPart _nested_dropdown_menu_widgets[] = {
 
	NWidget(NWID_LAYERED),
 
		NWidget(WWT_PANEL, COLOUR_END, 0), SetMinimalSize(1, 1), EndContainer(),
 
		NWidget(WWT_SCROLLBAR, COLOUR_END, 1), SetMinimalSize(1, 1),
 
	EndContainer(),
 
};
 

	
 
struct DropdownWindow : Window {
 
	WindowClass parent_wnd_class;
 
	WindowNumber parent_wnd_num;
 
	byte parent_button;
 
	DropDownList *list;
 
	int selected_index;
 
@@ -235,12 +242,14 @@ struct DropdownWindow : Window {
 
		}
 
	}
 
};
 

	
 
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
 
{
 
	static Widget *generated_dropdown_menu_widgets = NULL;
 

	
 
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
 

	
 
	w->LowerWidget(button);
 
	w->InvalidateWidget(button);
 

	
 
	/* Our parent's button widget is used to determine where to place the drop
 
@@ -299,18 +308,15 @@ void ShowDropDownList(Window *w, DropDow
 
			max_item_width += 12;
 
		}
 
	}
 

	
 
	if (auto_width) width = max(width, max_item_width);
 

	
 
	DropdownWindow *dw = new DropdownWindow(
 
		w->left + wi->left,
 
		top,
 
		width,
 
		height + 4,
 
		_dropdown_menu_widgets);
 
	const Widget *wid = InitializeWidgetArrayFromNestedWidgets(_nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets),
 
													_dropdown_menu_widgets, &generated_dropdown_menu_widgets);
 
	DropdownWindow *dw = new DropdownWindow(w->left + wi->left, top, width, height + 4, wid);
 

	
 
	dw->widget[0].colour = wi->colour;
 
	dw->widget[0].right = width - 1;
 
	dw->widget[0].bottom = height + 3;
 

	
 
	dw->SetWidgetHiddenState(1, !scroll);
0 comments (0 inline, 0 general)