summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/engine_gui.cpp2
-rw-r--r--src/gfx.cpp39
-rw-r--r--src/gfx_func.h2
-rw-r--r--src/gfx_type.h7
-rw-r--r--src/news_gui.cpp4
-rw-r--r--src/rail_gui.cpp4
-rw-r--r--src/settings_gui.cpp6
-rw-r--r--src/table/sprites.h6
-rw-r--r--src/texteff.cpp2
-rw-r--r--src/toolbar_gui.cpp4
-rw-r--r--src/widget.cpp10
-rw-r--r--src/widgets/dropdown.cpp2
12 files changed, 54 insertions, 34 deletions
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 0461520c4..fbe744c2f 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -202,7 +202,7 @@ void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
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);
}
diff --git a/src/gfx.cpp b/src/gfx.cpp
index b1e7517bf..2fca52bfe 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -89,7 +89,21 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
}
-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 @@ void GfxFillRect(int left, int top, int right, int bottom, int color)
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);
}
}
diff --git a/src/gfx_func.h b/src/gfx_func.h
index c6c633ec2..371645c5f 100644
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -99,7 +99,7 @@ void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color);
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);
diff --git a/src/gfx_type.h b/src/gfx_type.h
index 298513c84..983b95205 100644
--- a/src/gfx_type.h
+++ b/src/gfx_type.h
@@ -216,4 +216,11 @@ enum StringColorFlags {
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 */
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index d35eeced2..68caa9fae 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -51,7 +51,7 @@ static void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
{
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 @@ struct NewsWindow : Window {
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));
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index b6f836ee6..fe053b46a 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -1070,7 +1070,7 @@ public:
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 @@ public:
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);
}
}
}
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index 5ffa1f436..8489af712 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -1005,7 +1005,7 @@ void ShowPatchesSelection()
*/
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 @@ void DrawArrowButtons(int x, int y, int ctab, byte state, bool clickable_left, b
/* 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,
diff --git a/src/table/sprites.h b/src/table/sprites.h
index 7e73cddfc..678831f2a 100644
--- a/src/table/sprites.h
+++ b/src/table/sprites.h
@@ -1471,12 +1471,6 @@ enum Modifiers {
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.
diff --git a/src/texteff.cpp b/src/texteff.cpp
index 74d0b9712..c6b8daa47 100644
--- a/src/texteff.cpp
+++ b/src/texteff.cpp
@@ -241,7 +241,7 @@ void DrawChatMessage()
_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 */
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 055b78cfe..f54508334 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -914,7 +914,7 @@ struct MainToolbarWindow : Window {
{
/* 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 @@ public:
/* 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();
diff --git a/src/widget.cpp b/src/widget.cpp
index 9aa1e42d9..8c1abda6f 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -162,7 +162,7 @@ void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlag
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 @@ void Window::DrawWidgets() const
/* 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 @@ void Window::DrawWidgets() const
/* 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 @@ void Window::DrawWidgets() const
/* 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 @@ void Window::DrawWidgets() const
}
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);
}
}
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
index d0c5d04b7..ff2943214 100644
--- a/src/widgets/dropdown.cpp
+++ b/src/widgets/dropdown.cpp
@@ -146,7 +146,7 @@ struct DropdownWindow : Window {
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 {