mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-04 05:15:21 +00:00
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
This commit is contained in:
parent
06049563da
commit
ecc5d648df
@ -202,7 +202,7 @@ void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
|
|||||||
DrawStringMultiCenter(w->width >> 1, 57, STR_NEW_VEHICLE_TYPE, w->width - 2);
|
DrawStringMultiCenter(w->width >> 1, 57, STR_NEW_VEHICLE_TYPE, w->width - 2);
|
||||||
|
|
||||||
dei->engine_proc(w->width >> 1, 88, engine, 0);
|
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);
|
dei->info_proc(engine, w->width >> 1, 129, w->width - 52);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
src/gfx.cpp
39
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();
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
||||||
const DrawPixelInfo *dpi = _cur_dpi;
|
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);
|
dst = blitter->MoveTo(dpi->dst_ptr, left, top);
|
||||||
|
|
||||||
if (!HasBit(color, PALETTE_MODIFIER_GREYOUT)) {
|
switch (mode) {
|
||||||
if (!HasBit(color, USE_COLORTABLE)) {
|
default: // FILLRECT_OPAQUE
|
||||||
blitter->DrawRect(dst, right, bottom, (uint8)color);
|
blitter->DrawRect(dst, right, bottom, (uint8)color);
|
||||||
} else {
|
break;
|
||||||
|
|
||||||
|
case FILLRECT_RECOLOR:
|
||||||
blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 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 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);
|
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
|
||||||
|
|
||||||
|
@ -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
|
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 */
|
#endif /* GFX_TYPE_H */
|
||||||
|
@ -51,7 +51,7 @@ static void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
|
|||||||
{
|
{
|
||||||
Player *p = GetPlayer((PlayerID)(ni->data_b));
|
Player *p = GetPlayer((PlayerID)(ni->data_b));
|
||||||
DrawPlayerFace(p->face, p->player_color, 2, 23);
|
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);
|
SetDParam(0, p->index);
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ struct NewsWindow : Window {
|
|||||||
ViewPort *vp = this->viewport;
|
ViewPort *vp = this->viewport;
|
||||||
GfxFillRect(vp->left - this->left, vp->top - this->top,
|
GfxFillRect(vp->left - this->left, vp->top - this->top,
|
||||||
vp->left - this->left + vp->width - 1, vp->top - this->top + vp->height - 1,
|
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));
|
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
|
||||||
|
@ -1070,7 +1070,7 @@ public:
|
|||||||
|
|
||||||
if (statspec != NULL && statspec->name != 0) {
|
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) {
|
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);
|
DrawStringTruncated(9, y, statspec->name, i == _railstation.station_type ? TC_WHITE : TC_BLACK, 118);
|
||||||
@ -1606,7 +1606,7 @@ public:
|
|||||||
if (statspec != NULL &&
|
if (statspec != NULL &&
|
||||||
HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
|
HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
|
||||||
GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1005,7 +1005,7 @@ void ShowPatchesSelection()
|
|||||||
*/
|
*/
|
||||||
void DrawArrowButtons(int x, int y, int ctab, byte state, bool clickable_left, bool clickable_right)
|
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, 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);
|
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 */
|
/* Grey out the buttons that aren't clickable */
|
||||||
if (!clickable_left)
|
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)
|
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,
|
/** These are not, strickly speaking, widget enums,
|
||||||
|
@ -1471,12 +1471,6 @@ enum Modifiers {
|
|||||||
PALETTE_MODIFIER_TRANSPARENT = TRANSPARENT_BIT,
|
PALETTE_MODIFIER_TRANSPARENT = TRANSPARENT_BIT,
|
||||||
///this bit is set when a recoloring process is in action
|
///this bit is set when a recoloring process is in action
|
||||||
PALETTE_MODIFIER_COLOR = RECOLOR_BIT,
|
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.
|
/** Masks needed for sprite operations.
|
||||||
|
@ -241,7 +241,7 @@ void DrawChatMessage()
|
|||||||
_screen.height - _chatmsg_box.y - count * 13 - 2,
|
_screen.height - _chatmsg_box.y - count * 13 - 2,
|
||||||
_chatmsg_box.x + _chatmsg_box.width - 1,
|
_chatmsg_box.x + _chatmsg_box.width - 1,
|
||||||
_screen.height - _chatmsg_box.y - 2,
|
_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 */
|
/* Paint the chat messages starting with the lowest at the bottom */
|
||||||
|
@ -914,7 +914,7 @@ struct MainToolbarWindow : Window {
|
|||||||
{
|
{
|
||||||
/* Draw brown-red toolbar bg. */
|
/* Draw brown-red toolbar bg. */
|
||||||
GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB2);
|
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
|
/* If spectator, disable all construction buttons
|
||||||
* ie : Build road, rail, ships, airports and landscaping
|
* ie : Build road, rail, ships, airports and landscaping
|
||||||
@ -1118,7 +1118,7 @@ public:
|
|||||||
|
|
||||||
/* Draw brown-red toolbar bg. */
|
/* Draw brown-red toolbar bg. */
|
||||||
GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB2);
|
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();
|
this->DrawWidgets();
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlag
|
|||||||
uint light = _colour_gradient[ctab][7];
|
uint light = _colour_gradient[ctab][7];
|
||||||
|
|
||||||
if (flags & FR_TRANSPARENT) {
|
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 {
|
} else {
|
||||||
uint interior;
|
uint interior;
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ void Window::DrawWidgets() const
|
|||||||
|
|
||||||
/* draw "shaded" background */
|
/* 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, 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 */
|
/* draw shaded lines */
|
||||||
GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
|
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 */
|
/* 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, 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 */
|
/* draw shaded lines */
|
||||||
GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
|
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 */
|
/* 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, 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 */
|
/* draw shaded lines */
|
||||||
GfxFillRect(r.left + 10, r.top + 2, r.right - 10, r.top + 2, c1);
|
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)) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ struct DropdownWindow : Window {
|
|||||||
|
|
||||||
if (item->masked) {
|
if (item->masked) {
|
||||||
GfxFillRect(x, y, x + width, y + item_height - 1,
|
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 {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user