changeset 2218:1e5a1e9725ad draft

(svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
author celestar <celestar@openttd.org>
date Thu, 28 Jul 2005 09:17:32 +0000
parents 1ef48a7bd4bf
children a505c7d2759e
files economy.c engine_gui.c gfx.c main_gui.c table/sprites.h texteff.c widget.c
diffstat 7 files changed, 28 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/economy.c
+++ b/economy.c
@@ -5,6 +5,7 @@
 #include "functions.h"
 #include "strings.h" // XXX InjectDParam()
 #include "table/strings.h"
+#include "table/sprites.h"
 #include "map.h"
 #include "news.h"
 #include "player.h"
@@ -491,7 +492,7 @@
 
 	p = GetPlayer(WP(w,news_d).ni->string_id & 15);
 	DrawPlayerFace(p->face, p->player_color, 2, 23);
-	GfxFillRect(3, 23, 3+91, 23+118, 0x4323);
+	GfxFillRect(3, 23, 3+91, 23+118, 0x323 | USE_COLORTABLE);
 
 	SetDParam(0, p->president_name_1);
 	SetDParam(1, p->president_name_2);
--- a/engine_gui.c
+++ b/engine_gui.c
@@ -3,6 +3,7 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "table/strings.h"
+#include "table/sprites.h"
 #include "functions.h"
 #include "window.h"
 #include "gui.h"
@@ -160,7 +161,7 @@
 	DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2);
 
 	DrawTrainEngine(w->width >> 1, 88, engine, 0);
-	GfxFillRect(25, 56, w->width - 56, 112, 0x4323);
+	GfxFillRect(25, 56, w->width - 56, 112, 0x323 | USE_COLORTABLE);
 	DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52);
 }
 
@@ -200,7 +201,7 @@
 	DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2);
 
 	DrawAircraftEngine(w->width >> 1, 93, engine, 0);
-	GfxFillRect(25, 56, w->width - 56, 110, 0x4323);
+	GfxFillRect(25, 56, w->width - 56, 110, 0x323 | USE_COLORTABLE);
 	DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52);
 }
 
@@ -240,7 +241,7 @@
 	DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2);
 
 	DrawRoadVehEngine(w->width >> 1, 88, engine, 0);
-	GfxFillRect(25, 56, w->width - 56, 112, 0x4323);
+	GfxFillRect(25, 56, w->width - 56, 112, 0x323 | USE_COLORTABLE);
 	DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52);
 }
 
@@ -278,7 +279,7 @@
 	DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2);
 
 	DrawShipEngine(w->width >> 1, 93, engine, 0);
-	GfxFillRect(25, 56, w->width - 56, 110, 0x4323);
+	GfxFillRect(25, 56, w->width - 56, 110, 0x323 | USE_COLORTABLE);
 	DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52);
 }
 
--- a/gfx.c
+++ b/gfx.c
@@ -139,15 +139,15 @@
 
 	dst = dpi->dst_ptr + top * dpi->pitch + left;
 
-	if (!(color & 0x8000)) {
-		if (!(color & 0x4000)) {
+	if (!(color & PALETTE_MODIFIER_GREYOUT)) {
+		if (!(color & USE_COLORTABLE)) {
 			do {
 				memset(dst, color, right);
 				dst += dpi->pitch;
 			} while (--bottom);
 		} else {
 			/* use colortable mode */
-			const byte* ctab = GetNonSprite(color & 0x3FFF) + 1;
+			const byte* ctab = GetNonSprite(color & COLORTABLE_MASK) + 1;
 
 			do {
 				int i;
@@ -567,7 +567,7 @@
 		}
 	} else if (flags & 0x1) {
 		// transparency
-		GfxFillRect(left, top, right, bottom, 0x4322);
+		GfxFillRect(left, top, right, bottom, 0x322 | USE_COLORTABLE);
 	} else {
 		GfxFillRect(left, top, right, bottom, color_interior);
 	}
--- a/main_gui.c
+++ b/main_gui.c
@@ -1863,7 +1863,7 @@
 
 		// Draw brown-red toolbar bg.
 		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
-		GfxFillRect(0, 0, w->width-1, w->height-1, 0x80B4);
+		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | PALETTE_MODIFIER_GREYOUT);
 
 		// if spectator, disable things
 		if (_current_player == OWNER_SPECTATOR){
@@ -2089,7 +2089,7 @@
 
 		// Draw brown-red toolbar bg.
 		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
-		GfxFillRect(0, 0, w->width-1, w->height-1, 0x80B4);
+		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | PALETTE_MODIFIER_GREYOUT);
 
 		DrawWindowWidgets(w);
 
--- a/table/sprites.h
+++ b/table/sprites.h
@@ -984,6 +984,12 @@
 	PALETTE_MODIFIER_TRANSPARENT 	= 1 << TRANSPARENT_BIT,
 	///this bit is set when a recoloring process is in action
 	PALETTE_MODIFIER_COLOR 				= 1 << RECOLOR_BIT,
+
+	//This is used for the GfxFillRect function
+	///Used to draw a "grey out" rectangle. @see GfxFillRect
+	PALETTE_MODIFIER_GREYOUT        = 1 << TRANSPARENT_BIT,
+	///Set when a colortable mode is used. @see GfxFillRect
+	USE_COLORTABLE                  = 1 << RECOLOR_BIT,
 };
 
 /** Masks needed for sprite operations.
@@ -997,6 +1003,8 @@
 	SPRITE_MASK = MAX_SPRITES,
 	///The mask for the auxiliary sprite (the one that takes care of recoloring)
 	PALETTE_SPRITE_MASK = ((1 << PALETTE_SPRITE_WIDTH) - 1) << PALETTE_SPRITE_START,
+	///Mask for the auxiliary sprites if it is locate in the LSBs
+	COLORTABLE_MASK = (1 << PALETTE_SPRITE_WIDTH) - 1
 };
 
 assert_compile( (1 << TRANSPARENT_BIT & SPRITE_MASK) == 0 );
--- a/texteff.c
+++ b/texteff.c
@@ -11,6 +11,7 @@
 #include "console.h"
 #include "string.h"
 #include "variables.h"
+#include "table/sprites.h"
 #include <stdarg.h> /* va_list */
 
 typedef struct TextEffect {
@@ -207,7 +208,7 @@
 			continue;
 
 		j++;
-		GfxFillRect(_textmessage_box_left, _screen.height-_textmessage_box_bottom-j*13-2, _textmessage_box_left+_textmessage_width - 1, _screen.height-_textmessage_box_bottom-j*13+10, /* black, but with some alpha */ 0x4322);
+		GfxFillRect(_textmessage_box_left, _screen.height-_textmessage_box_bottom-j*13-2, _textmessage_box_left+_textmessage_width - 1, _screen.height-_textmessage_box_bottom-j*13+10, /* black, but with some alpha */ 0x322 | USE_COLORTABLE);
 
 		DoDrawString(_text_message_list[i].message, _textmessage_box_left + 2, _screen.height - _textmessage_box_bottom - j * 13 - 1, 0x10);
 		DoDrawString(_text_message_list[i].message, _textmessage_box_left + 3, _screen.height - _textmessage_box_bottom - j * 13, _text_message_list[i].color);
--- a/widget.c
+++ b/widget.c
@@ -285,7 +285,7 @@
 
 			// draw "shaded" background
 			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
-			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | 0x8000);
+			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | PALETTE_MODIFIER_GREYOUT);
 
 			// draw shaded lines
 			GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
@@ -317,7 +317,7 @@
 
 			// draw "shaded" background
 			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
-			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | 0x8000);
+			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | PALETTE_MODIFIER_GREYOUT);
 
 			// draw shaded lines
 			GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
@@ -350,7 +350,7 @@
 
 			// draw "shaded" background
 			GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c2);
-			GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c1 | 0x8000);
+			GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c1 | PALETTE_MODIFIER_GREYOUT);
 
 			// draw shaded lines
 			GfxFillRect(r.left+10, r.top+2, r.right-10, r.top+2, c1);
@@ -426,7 +426,7 @@
 			DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->unkA, 0x84);
 draw_default:;
 			if (cur_disabled & 1) {
-				GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _color_list[wi->color&0xF].unk2 | 0x8000);
+				GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _color_list[wi->color&0xF].unk2 | PALETTE_MODIFIER_GREYOUT);
 			}
 		}
 		}
@@ -503,7 +503,7 @@
 					DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16);
 
 					if (HASBIT(_dropdown_disabled, i) && !_dropdown_disabled_items) {
-						GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 +
+						GfxFillRect(x, y, x+w->width-3, y + 9, PALETTE_MODIFIER_GREYOUT |
 									_color_list[_dropdown_menu_widgets[0].color].window_color_bga);
 					}
 				} else {