summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2014-10-05 21:18:37 +0000
committerpeter1138 <peter1138@openttd.org>2014-10-05 21:18:37 +0000
commit5a924dcbbc25762ec770a32e6f14c2798bf9f92f (patch)
treed7bce9c379945f3c0740f787f1c7cdbb540f2ce6 /src
parent9ab2263fda4bda2477ed6bf69ed26e03bb989155 (diff)
downloadopenttd-5a924dcbbc25762ec770a32e6f14c2798bf9f92f.tar.xz
(svn r26965) -Codechange: Add palette bit to indicate that palette is actually a text colour remap, and draw closebox as a sprite, using said bit. Change news popup to use closebox widget for its closebox.
Diffstat (limited to 'src')
-rw-r--r--src/gfx.cpp12
-rw-r--r--src/news_gui.cpp8
-rw-r--r--src/table/sprites.h6
-rw-r--r--src/widget.cpp14
4 files changed, 26 insertions, 14 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index e90e2babf..5a1f75abc 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -797,7 +797,11 @@ void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSpri
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite);
} else if (pal != PAL_NONE) {
- _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
+ if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
+ SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
+ } else {
+ _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
+ }
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, pal == PALETTE_CRASH ? BM_CRASH_REMAP : BM_COLOUR_REMAP, sub, real_sprite);
} else {
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite);
@@ -820,7 +824,11 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub,
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
} else if (pal != PAL_NONE) {
- _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
+ if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
+ SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
+ } else {
+ _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
+ }
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, pal == PALETTE_CRASH ? BM_CRASH_REMAP : BM_COLOUR_REMAP, sub, real_sprite, zoom);
} else {
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom);
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 75aa007e8..3800af8b5 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -80,7 +80,7 @@ static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
static const NWidgetPart _nested_normal_news_widgets[] = {
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
- NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
+ NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
NWidget(NWID_SPACER), SetFill(1, 0),
NWidget(NWID_VERTICAL),
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
@@ -103,7 +103,7 @@ static const NWidgetPart _nested_vehicle_news_widgets[] = {
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
NWidget(NWID_VERTICAL),
- NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
+ NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
NWidget(NWID_SPACER), SetFill(0, 1),
EndContainer(),
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
@@ -130,7 +130,7 @@ static const NWidgetPart _nested_company_news_widgets[] = {
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
NWidget(NWID_VERTICAL),
- NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
+ NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
NWidget(NWID_SPACER), SetFill(0, 1),
EndContainer(),
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
@@ -157,7 +157,7 @@ static WindowDesc _company_news_desc(
static const NWidgetPart _nested_thin_news_widgets[] = {
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
- NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
+ NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), SetPadding(0, 0, 0, 1),
NWidget(NWID_SPACER), SetFill(1, 0),
NWidget(NWID_VERTICAL),
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
diff --git a/src/table/sprites.h b/src/table/sprites.h
index b5b3321b0..fa687a39f 100644
--- a/src/table/sprites.h
+++ b/src/table/sprites.h
@@ -85,6 +85,8 @@ static const SpriteID SPR_SHARED_ORDERS_ICON = SPR_OPENTTD_BASE + 50;
static const SpriteID SPR_PIN_UP = SPR_OPENTTD_BASE + 51; // pin icon
static const SpriteID SPR_PIN_DOWN = SPR_OPENTTD_BASE + 52;
+static const SpriteID SPR_CLOSEBOX = 143;
+
static const SpriteID SPR_CIRCLE_FOLDED = SPR_OPENTTD_BASE + 147; // (+) icon
static const SpriteID SPR_CIRCLE_UNFOLDED = SPR_OPENTTD_BASE + 148; // (-) icon
@@ -1479,11 +1481,15 @@ static const CursorID ANIMCURSOR_BUILDSIGNALS = ANIMCURSOR_FLAG | 4; ///< 1292 -
* bits used for the recolouring process. For transparency, it must be 0x322.</li></ul>
*/
enum SpriteSetup {
+ /* These bits are applied to sprite ID */
TRANSPARENT_BIT = 31, ///< toggles transparency in the sprite
RECOLOUR_BIT = 30, ///< toggles recolouring in the sprite
CUSTOM_BIT = 29,
OPAQUE_BIT = 28,
+ /* This bit is applied to palette ID */
+ PALETTE_TEXT_RECOLOUR = 31, ///< Set if palette is actually a magic text recolour
+
PALETTE_WIDTH = 24, ///< number of bits of the sprite containing the recolour palette
SPRITE_WIDTH = 24, ///< number of bits for the sprite number
};
diff --git a/src/widget.cpp b/src/widget.cpp
index ab8374646..cfbb6f400 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -522,13 +522,11 @@ static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bo
* Draw a close box.
* @param r Rectangle of the box.
* @param colour Colour of the close box.
- * @param str Cross to draw (#STR_BLACK_CROSS or #STR_SILVER_CROSS).
*/
-static inline void DrawCloseBox(const Rect &r, Colours colour, StringID str)
+static inline void DrawCloseBox(const Rect &r, Colours colour)
{
- assert(str == STR_BLACK_CROSS || str == STR_SILVER_CROSS); // black or silver cross
- DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
- DrawString(r.left, r.right, r.top + WD_CLOSEBOX_TOP, str, TC_FROMSTRING, SA_HOR_CENTER);
+ if (colour != COLOUR_WHITE) DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
+ DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1 << PALETTE_TEXT_RECOLOUR), r.left + WD_CLOSEBOX_LEFT, r.top + WD_CLOSEBOX_TOP);
}
/**
@@ -2182,7 +2180,7 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data,
case WWT_CLOSEBOX:
this->SetFill(0, 0);
this->SetMinimalSize(WD_CLOSEBOX_WIDTH, WD_CAPTION_HEIGHT);
- this->SetDataTip(STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW);
+ this->SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
break;
case WWT_DROPDOWN:
@@ -2320,7 +2318,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
static const Dimension extra = {WD_CLOSEBOX_LEFT + WD_CLOSEBOX_RIGHT, WD_CLOSEBOX_TOP + WD_CLOSEBOX_BOTTOM};
padding = &extra;
if (NWidgetLeaf::closebox_dimension.width == 0) {
- NWidgetLeaf::closebox_dimension = maxdim(GetStringBoundingBox(STR_BLACK_CROSS), GetStringBoundingBox(STR_SILVER_CROSS));
+ NWidgetLeaf::closebox_dimension = GetSpriteSize(SPR_CLOSEBOX);
NWidgetLeaf::closebox_dimension.width += extra.width;
NWidgetLeaf::closebox_dimension.height += extra.height;
}
@@ -2490,7 +2488,7 @@ void NWidgetLeaf::Draw(const Window *w)
break;
case WWT_CLOSEBOX:
- DrawCloseBox(r, this->colour, this->widget_data);
+ DrawCloseBox(r, this->colour);
break;
case WWT_DROPDOWN: