(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
authorfrosch
Sat, 28 Jun 2008 15:44:24 +0000
changeset 11092 e4fce2b3cded
parent 11091 6b5352725f43
child 11103 22fda2a0c52f
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
src/engine_gui.cpp
src/gfx.cpp
src/gfx_func.h
src/gfx_type.h
src/news_gui.cpp
src/rail_gui.cpp
src/settings_gui.cpp
src/table/sprites.h
src/texteff.cpp
src/toolbar_gui.cpp
src/widget.cpp
src/widgets/dropdown.cpp
--- a/src/engine_gui.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/engine_gui.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -202,7 +202,7 @@
 	DrawStringMultiCenter(w->width >> 1, 57, STR_NEW_VEHICLE_TYPE, w->width - 2);
 
 	dei->engine_proc(w->width >> 1, 88, engine, 0);
-	GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
+	GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOR);
 	dei->info_proc(engine, w->width >> 1, 129, w->width - 52);
 }
 
--- a/src/gfx.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/gfx.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -89,7 +89,21 @@
 }
 
 
-void GfxFillRect(int left, int top, int right, int bottom, int color)
+/**
+ * Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
+ *
+ * @pre dpi->zoom == ZOOM_LVL_NORMAL, right >= left, bottom >= top
+ * @param left Minimum X (inclusive)
+ * @param top Minimum Y (inclusive)
+ * @param right Maximum X (inclusive)
+ * @param bottom Maximum Y (inclusive)
+ * @param color A 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolor spritenumber (FILLRECT_RECOLOR)
+ * @param mode
+ *         FILLRECT_OPAQUE:   Fill the rectangle with the specified color
+ *         FILLRECT_CHECKER:  Like FILLRECT_OPAQUE, but only draw every second pixel (used to grey out things)
+ *         FILLRECT_RECOLOR:  Apply a recolor sprite to every pixel in the rectangle currently on screen
+ */
+void GfxFillRect(int left, int top, int right, int bottom, int color, FillRectMode mode)
 {
 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 	const DrawPixelInfo *dpi = _cur_dpi;
@@ -116,18 +130,23 @@
 
 	dst = blitter->MoveTo(dpi->dst_ptr, left, top);
 
-	if (!HasBit(color, PALETTE_MODIFIER_GREYOUT)) {
-		if (!HasBit(color, USE_COLORTABLE)) {
+	switch (mode) {
+		default: // FILLRECT_OPAQUE
 			blitter->DrawRect(dst, right, bottom, (uint8)color);
-		} else {
+			break;
+
+		case FILLRECT_RECOLOR:
 			blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
+			break;
+
+		case FILLRECT_CHECKER: {
+			byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
+			do {
+				for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color);
+				dst = blitter->MoveTo(dst, 0, 1);
+			} while (--bottom > 0);
+			break;
 		}
-	} else {
-		byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
-		do {
-			for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color);
-			dst = blitter->MoveTo(dst, 0, 1);
-		} while (--bottom > 0);
 	}
 }
 
--- a/src/gfx_func.h	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/gfx_func.h	Sat Jun 28 15:44:24 2008 +0000
@@ -99,7 +99,7 @@
 
 void DrawCharCentered(uint32 c, int x, int y, uint16 color);
 
-void GfxFillRect(int left, int top, int right, int bottom, int color);
+void GfxFillRect(int left, int top, int right, int bottom, int color, FillRectMode mode = FILLRECT_OPAQUE);
 void GfxDrawLine(int left, int top, int right, int bottom, int color);
 void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
 
--- a/src/gfx_type.h	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/gfx_type.h	Sat Jun 28 15:44:24 2008 +0000
@@ -216,4 +216,11 @@
 	IS_PALETTE_COLOR = 0x100, ///< color value is already a real palette color index, not an index of a StringColor
 };
 
+/** Define the operation GfxFillRect performs */
+enum FillRectMode {
+	FILLRECT_OPAQUE,  ///< Fill rectangle with a single color
+	FILLRECT_CHECKER, ///< Draw only every second pixel, used for greying-out
+	FILLRECT_RECOLOR, ///< Apply a recolor sprite to the screen content
+};
+
 #endif /* GFX_TYPE_H */
--- a/src/news_gui.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/news_gui.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -51,7 +51,7 @@
 {
 	Player *p = GetPlayer((PlayerID)(ni->data_b));
 	DrawPlayerFace(p->face, p->player_color, 2, 23);
-	GfxFillRect(3, 23, 3 + 91, 23 + 118, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
+	GfxFillRect(3, 23, 3 + 91, 23 + 118, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOR);
 
 	SetDParam(0, p->index);
 
@@ -233,7 +233,7 @@
 					ViewPort *vp = this->viewport;
 					GfxFillRect(vp->left - this->left, vp->top - this->top,
 						vp->left - this->left + vp->width - 1, vp->top - this->top + vp->height - 1,
-						(this->ni->flags & NF_INCOLOR ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY) | (1 << USE_COLORTABLE)
+						(this->ni->flags & NF_INCOLOR ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY), FILLRECT_RECOLOR
 					);
 
 					CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
--- a/src/rail_gui.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/rail_gui.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -1070,7 +1070,7 @@
 
 				if (statspec != NULL && statspec->name != 0) {
 					if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
-						GfxFillRect(8, y - 2, 127, y + 10, (1 << PALETTE_MODIFIER_GREYOUT));
+						GfxFillRect(8, y - 2, 127, y + 10, 0, FILLRECT_CHECKER);
 					}
 
 					DrawStringTruncated(9, y, statspec->name, i == _railstation.station_type ? TC_WHITE : TC_BLACK, 118);
@@ -1606,7 +1606,7 @@
 				if (statspec != NULL &&
 						HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
 						GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
-					GfxFillRect(4 + i * 68, 18, 67 + i * 68, 75, (1 << PALETTE_MODIFIER_GREYOUT));
+					GfxFillRect(4 + i * 68, 18, 67 + i * 68, 75, 0, FILLRECT_CHECKER);
 				}
 			}
 		}
--- a/src/settings_gui.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/settings_gui.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -1005,7 +1005,7 @@
  */
 void DrawArrowButtons(int x, int y, int ctab, byte state, bool clickable_left, bool clickable_right)
 {
-	int color = (1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[COLOUR_YELLOW][2];
+	int color = _colour_gradient[COLOUR_YELLOW][2];
 
 	DrawFrameRect(x,      y + 1, x +  9, y + 9, ctab, (state == 1) ? FR_LOWERED : FR_NONE);
 	DrawFrameRect(x + 10, y + 1, x + 19, y + 9, ctab, (state == 2) ? FR_LOWERED : FR_NONE);
@@ -1014,9 +1014,9 @@
 
 	/* Grey out the buttons that aren't clickable */
 	if (!clickable_left)
-		GfxFillRect(x +  1, y + 1, x +  1 + 8, y + 8, color);
+		GfxFillRect(x +  1, y + 1, x +  1 + 8, y + 8, color, FILLRECT_CHECKER);
 	if (!clickable_right)
-		GfxFillRect(x + 11, y + 1, x + 11 + 8, y + 8, color);
+		GfxFillRect(x + 11, y + 1, x + 11 + 8, y + 8, color, FILLRECT_CHECKER);
 }
 
 /** These are not, strickly speaking, widget enums,
--- a/src/table/sprites.h	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/table/sprites.h	Sat Jun 28 15:44:24 2008 +0000
@@ -1471,12 +1471,6 @@
 	PALETTE_MODIFIER_TRANSPARENT  = TRANSPARENT_BIT,
 	///this bit is set when a recoloring process is in action
 	PALETTE_MODIFIER_COLOR        = RECOLOR_BIT,
-
-	//This is used for the GfxFillRect function
-	///Used to draw a "grey out" rectangle. @see GfxFillRect
-	PALETTE_MODIFIER_GREYOUT        = TRANSPARENT_BIT,
-	///Set when a colortable mode is used. @see GfxFillRect
-	USE_COLORTABLE                  = RECOLOR_BIT,
 };
 
 /** Masks needed for sprite operations.
--- a/src/texteff.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/texteff.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -241,7 +241,7 @@
 			_screen.height - _chatmsg_box.y - count * 13 - 2,
 			_chatmsg_box.x + _chatmsg_box.width - 1,
 			_screen.height - _chatmsg_box.y - 2,
-			PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE) // black, but with some alpha for background
+			PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOR // black, but with some alpha for background
 		);
 
 	/* Paint the chat messages starting with the lowest at the bottom */
--- a/src/toolbar_gui.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/toolbar_gui.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -914,7 +914,7 @@
 	{
 		/* Draw brown-red toolbar bg. */
 		GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB2);
-		GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
+		GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB4, FILLRECT_CHECKER);
 
 		/* If spectator, disable all construction buttons
 		* ie : Build road, rail, ships, airports and landscaping
@@ -1118,7 +1118,7 @@
 
 		/* Draw brown-red toolbar bg. */
 		GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB2);
-		GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
+		GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB4, FILLRECT_CHECKER);
 
 		this->DrawWidgets();
 
--- a/src/widget.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/widget.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -162,7 +162,7 @@
 	uint light        = _colour_gradient[ctab][7];
 
 	if (flags & FR_TRANSPARENT) {
-		GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE));
+		GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOR);
 	} else {
 		uint interior;
 
@@ -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 | (1 << PALETTE_MODIFIER_GREYOUT));
+			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1, FILLRECT_CHECKER);
 
 			/* draw shaded lines */
 			GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
@@ -348,7 +348,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 | (1 << PALETTE_MODIFIER_GREYOUT));
+			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1, FILLRECT_CHECKER);
 
 			/* draw shaded lines */
 			GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
@@ -379,7 +379,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 | (1 << PALETTE_MODIFIER_GREYOUT));
+			GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1, FILLRECT_CHECKER);
 
 			/* draw shaded lines */
 			GfxFillRect(r.left + 10, r.top + 2, r.right - 10, r.top + 2, c1);
@@ -490,7 +490,7 @@
 		}
 
 		if (this->IsWidgetDisabled(i)) {
-			GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->color & 0xF][2] | (1 << PALETTE_MODIFIER_GREYOUT));
+			GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->color & 0xF][2], FILLRECT_CHECKER);
 		}
 	}
 
--- a/src/widgets/dropdown.cpp	Fri Jun 27 20:59:30 2008 +0000
+++ b/src/widgets/dropdown.cpp	Sat Jun 28 15:44:24 2008 +0000
@@ -146,7 +146,7 @@
 
 					if (item->masked) {
 						GfxFillRect(x, y, x + width, y + item_height - 1,
-							(1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[this->widget[0].color][5]
+							_colour_gradient[this->widget[0].color][5], FILLRECT_CHECKER
 						);
 					}
 				} else {