src/misc_gui.cpp
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6870 ca3fd1fbe311
child 6872 1c4a4a609f85
--- a/src/misc_gui.cpp	Sat Oct 06 21:16:00 2007 +0000
+++ b/src/misc_gui.cpp	Mon Dec 03 23:39:38 2007 +0000
@@ -9,6 +9,7 @@
 #include "functions.h"
 #include "landscape.h"
 #include "newgrf.h"
+#include "newgrf_text.h"
 #include "saveload.h"
 #include "strings.h"
 #include "table/sprites.h"
@@ -59,13 +60,13 @@
 	if (e->event == WE_PAINT) {
 		DrawWindowWidgets(w);
 
-		DoDrawStringCentered(140, 16, _landinfo_data[0], 13);
-		DoDrawStringCentered(140, 27, _landinfo_data[1], 0);
-		DoDrawStringCentered(140, 38, _landinfo_data[2], 0);
-		DoDrawStringCentered(140, 49, _landinfo_data[3], 0);
-		DoDrawStringCentered(140, 60, _landinfo_data[4], 0);
+		DoDrawStringCentered(140, 16, _landinfo_data[0], TC_LIGHT_BLUE);
+		DoDrawStringCentered(140, 27, _landinfo_data[1], TC_FROMSTRING);
+		DoDrawStringCentered(140, 38, _landinfo_data[2], TC_FROMSTRING);
+		DoDrawStringCentered(140, 49, _landinfo_data[3], TC_FROMSTRING);
+		DoDrawStringCentered(140, 60, _landinfo_data[4], TC_FROMSTRING);
 		if (_landinfo_data[5][0] != '\0') DrawStringMultiCenter(140, 76, BindCString(_landinfo_data[5]), w->width - 4);
-		if (_landinfo_data[6][0] != '\0') DoDrawStringCentered(140, 71, _landinfo_data[6], 0);
+		if (_landinfo_data[6][0] != '\0') DoDrawStringCentered(140, 71, _landinfo_data[6], TC_FROMSTRING);
 	}
 }
 
@@ -198,7 +199,7 @@
 		ResetObjectToPlace();
 	} else {
 		_place_proc = Place_LandInfo;
-		SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, 1, WC_MAIN_TOOLBAR, 0);
+		SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, VHM_RECT, WC_MAIN_TOOLBAR, 0);
 	}
 }
 
@@ -222,12 +223,12 @@
 	"  Peter Nelson (peter1138) - Spiritual descendant from newgrf gods",
 	"  Remko Bijker (Rubidium) - THE desync hunter",
 	"  Christoph Mallon (Tron) - Programmer, code correctness police",
-	"  Patric Stout (TrueLight) - Coder, network guru, SVN-, MS- and website host",
 	"",
 	"Retired Developers:",
 	"  Ludvig Strigeus (ludde) - OpenTTD author, main coder (0.1 - 0.3.3)",
 	"  Serge Paquet (vurlix) - Assistant project manager, coder (0.1 - 0.3.3)",
 	"  Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3.0 - 0.3.6)",
+	"  Patric Stout (TrueLight) - Programmer, webhoster (0.3 - pre0.6)",
 	"",
 	"Special thanks go out to:",
 	"  Josef Drexler - For his great work on TTDPatch",
@@ -264,13 +265,13 @@
 		DrawWindowWidgets(w);
 
 		/* Show original copyright and revision version */
-		DrawStringCentered(210, 17, STR_00B6_ORIGINAL_COPYRIGHT, 0);
-		DrawStringCentered(210, 17 + 10, STR_00B7_VERSION, 0);
+		DrawStringCentered(210, 17, STR_00B6_ORIGINAL_COPYRIGHT, TC_FROMSTRING);
+		DrawStringCentered(210, 17 + 10, STR_00B7_VERSION, TC_FROMSTRING);
 
 		/* Show all scrolling credits */
 		for (i = 0; i < lengthof(credits); i++) {
 			if (y >= 50 && y < (w->height - 40)) {
-				DoDrawString(credits[i], 10, y, 0x10);
+				DoDrawString(credits[i], 10, y, TC_BLACK);
 			}
 			y += 10;
 		}
@@ -278,8 +279,8 @@
 		/* If the last text has scrolled start anew from the start */
 		if (y < 50) WP(w, scroller_d).height = w->height - 40;
 
-		DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", 16);
-		DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, 0);
+		DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", TC_BLACK);
+		DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, TC_FROMSTRING);
 	} break;
 	case WE_MOUSELOOP: // Timer to scroll the text and adjust the new top
 		if (WP(w, scroller_d).counter++ % 3 == 0) {
@@ -365,17 +366,17 @@
 		case 11:case 12: case 13: case 14:
 			if (wid - 3 >= WP(w,tree_d).count) break;
 
-			if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, 1, NULL))
+			if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, VHM_RECT, NULL))
 				_tree_to_plant = WP(w,tree_d).base + wid - 3;
 			break;
 
 		case 15: // tree of random type.
-			if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, 1, NULL))
+			if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, VHM_RECT, NULL))
 				_tree_to_plant = -1;
 			break;
 
 		case 16: // place trees randomly over the landscape
-			LowerWindowWidget(w, 16);
+			w->LowerWidget(16);
 			w->flags4 |= 5 << WF_TIMEOUT_SHL;
 			SndPlayFx(SND_15_BEEP);
 			PlaceTreesRandomly();
@@ -401,7 +402,7 @@
 		break;
 
 	case WE_TIMEOUT:
-		RaiseWindowWidget(w, 16);
+		w->RaiseWidget(16);
 		break;
 
 	case WE_ABORT_PLACE_OBJ:
@@ -505,6 +506,13 @@
 		CopyInDParam(0, _errmsg_decode_params, lengthof(_errmsg_decode_params));
 		DrawWindowWidgets(w);
 		CopyInDParam(0, _errmsg_decode_params, lengthof(_errmsg_decode_params));
+
+		/* If the error message comes from a NewGRF, we must use the text ref. stack reserved for error messages.
+		 * If the message doesn't come from a NewGRF, it won't use the TTDP-style text ref. stack, so we won't hurt anything
+		 */
+		SwitchToErrorRefStack();
+		RewindTextRefStack();
+
 		if (!IsWindowOfPrototype(w, _errmsg_face_widgets)) {
 			DrawStringMultiCenter(
 				120,
@@ -533,6 +541,9 @@
 					_errmsg_message_1,
 					w->width - 2);
 		}
+
+		/* Switch back to the normal text ref. stack for NewGRF texts */
+		SwitchToNormalRefStack();
 		break;
 
 	case WE_MOUSELOOP:
@@ -598,8 +609,8 @@
 		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);
+			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;
@@ -735,9 +746,9 @@
 	/* Correctly position the tooltip position, watch out for window and cursor size
 	 * Clamp value to below main toolbar and above statusbar. If tooltip would
 	 * go below window, flip it so it is shown above the cursor */
-	y = clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12);
+	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;
-	x = clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
+	x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
 
 	w = AllocateWindow(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets);
 
@@ -1076,8 +1087,8 @@
 
 	if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
 
-	DoDrawString(tb->buf, delta, 0, 8);
-	if (tb->caret) DoDrawString("_", tb->caretxoffs + delta, 0, 12);
+	DoDrawString(tb->buf, delta, 0, TC_YELLOW);
+	if (tb->caret) DoDrawString("_", tb->caretxoffs + delta, 0, TC_WHITE);
 
 	_cur_dpi = old_dpi;
 }
@@ -1095,7 +1106,7 @@
 
 	switch (e->event) {
 		case WE_CREATE:
-			SETBIT(_no_scroll, SCROLL_EDIT);
+			SetBit(_no_scroll, SCROLL_EDIT);
 			break;
 
 		case WE_PAINT:
@@ -1151,7 +1162,7 @@
 				e.event = WE_ON_EDIT_TEXT_CANCEL;
 				parent->wndproc(parent, &e);
 			}
-			CLRBIT(_no_scroll, SCROLL_EDIT);
+			ClrBit(_no_scroll, SCROLL_EDIT);
 			break;
 		}
 }
@@ -1209,7 +1220,7 @@
 		WP(w, querystr_d).orig = orig_str_buf;
 	}
 
-	LowerWindowWidget(w, QUERY_STR_WIDGET_TEXT);
+	w->LowerWidget(QUERY_STR_WIDGET_TEXT);
 	WP(w, querystr_d).caption = caption;
 	WP(w, querystr_d).afilter = afilter;
 	InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, realmaxlen, maxwidth);
@@ -1359,7 +1370,10 @@
 };
 
 /* Colors for fios types */
-const byte _fios_colors[] = {13, 9, 9, 6, 5, 6, 5, 6, 6, 8};
+const TextColour _fios_colors[] = {
+	TC_LIGHT_BLUE, TC_DARK_GREEN,  TC_DARK_GREEN, TC_ORANGE, TC_LIGHT_BROWN,
+	TC_ORANGE,     TC_LIGHT_BROWN, TC_ORANGE,     TC_ORANGE, TC_YELLOW
+};
 
 void BuildFileList()
 {
@@ -1390,8 +1404,8 @@
 	}
 
 	if (str != STR_4006_UNABLE_TO_READ_DRIVE) SetDParam(0, tot);
-	DrawString(2, 37, str, 0);
-	DoDrawStringTruncated(path, 2, 27, 16, maxw);
+	DrawString(2, 37, str, TC_FROMSTRING);
+	DoDrawStringTruncated(path, 2, 27, TC_BLACK, maxw);
 }
 
 static void MakeSortedSaveGameList()
@@ -1480,7 +1494,7 @@
 		DoDrawString(
 			_savegame_sort_order & SORT_DESCENDING ? DOWNARROW : UPARROW,
 			_savegame_sort_order & SORT_BY_NAME ? w->widget[2].right - 9 : w->widget[3].right - 9,
-			15, 16
+			15, TC_BLACK
 		);
 
 		y = w->widget[7].top + 1;
@@ -1585,7 +1599,7 @@
 		 * in those two saveload mode  */
 		if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) break;
 
-		if (IsWindowWidgetLowered(w, 11)) { // Delete button clicked
+		if (w->IsWidgetLowered(11)) { // Delete button clicked
 			if (!FiosDelete(WP(w, querystr_d).text.buf)) {
 				ShowErrorMessage(INVALID_STRING_ID, STR_4008_UNABLE_TO_DELETE_FILE, 0, 0);
 			} else {
@@ -1596,7 +1610,7 @@
 
 			UpdateTextBufferSize(&WP(w, querystr_d).text);
 			SetWindowDirty(w);
-		} else if (IsWindowWidgetLowered(w, 12)) { // Save button clicked
+		} else if (w->IsWidgetLowered(12)) { // Save button clicked
 			_switch_mode = SM_SAVE;
 			FiosMakeSavegameName(_file_to_saveload.name, WP(w, querystr_d).text.buf, sizeof(_file_to_saveload.name));
 
@@ -1610,7 +1624,7 @@
 			DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 		}
 		FiosFreeSavegameList();
-		CLRBIT(_no_scroll, SCROLL_SAVE);
+		ClrBit(_no_scroll, SCROLL_SAVE);
 		break;
 	case WE_RESIZE: {
 		/* Widget 2 and 3 have to go with halve speed, make it so obiwan */
@@ -1661,12 +1675,12 @@
 	const WindowDesc *sld = &_save_dialog_desc;
 
 
-	SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, 0, WC_MAIN_WINDOW, 0);
+	SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
 	DeleteWindowById(WC_QUERY_STRING, 0);
 	DeleteWindowById(WC_SAVELOAD, 0);
 
 	_saveload_mode = mode;
-	SETBIT(_no_scroll, SCROLL_SAVE);
+	SetBit(_no_scroll, SCROLL_SAVE);
 
 	switch (mode) {
 		case SLD_SAVE_GAME:     GenerateFileName(); break;
@@ -1677,7 +1691,7 @@
 	assert((uint)mode < lengthof(saveload_captions));
 	w = AllocateWindowDesc(sld);
 	w->widget[1].data = saveload_captions[mode];
-	LowerWindowWidget(w, 7);
+	w->LowerWidget(7);
 
 	WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
 	InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 240);
@@ -1889,7 +1903,7 @@
 			} break;
 			}
 
-			DrawString(50, y + 1, ce->str, 0);
+			DrawString(50, y + 1, ce->str, TC_FROMSTRING);
 
 			y += 12;
 		}
@@ -1903,7 +1917,7 @@
 			uint x = e->we.click.pt.x;
 
 			/* not clicking a button? */
-			if (!IS_INT_INSIDE(x, 20, 40) || btn >= lengthof(_cheats_ui)) break;
+			if (!IsInsideMM(x, 20, 40) || btn >= lengthof(_cheats_ui)) break;
 
 			ce = &_cheats_ui[btn];
 			oldvalue = value = (int32)ReadValue(ce->variable, ce->type);
@@ -1924,7 +1938,7 @@
 
 				/* Increase or decrease the value and clamp it to extremes */
 				value += (x >= 30) ? step : -step;
-				value = clamp(value, ce->min, ce->max);
+				value = Clamp(value, ce->min, ce->max);
 
 				/* take whatever the function returns */
 				value = ce->proc(value, (x >= 30) ? 1 : -1);