summaryrefslogtreecommitdiff
path: root/src/viewport.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-10-05 19:57:20 +0000
committerrubidium <rubidium@openttd.org>2007-10-05 19:57:20 +0000
commit1e73368d4870ca9ab28a7051b7e59e8949001670 (patch)
tree3ae529c48895982a4a93d51be410766805287cc9 /src/viewport.cpp
parentf4721fed8709db7069efb76a160117c4fcdef057 (diff)
downloadopenttd-1e73368d4870ca9ab28a7051b7e59e8949001670.tar.xz
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
Diffstat (limited to 'src/viewport.cpp')
-rw-r--r--src/viewport.cpp69
1 files changed, 39 insertions, 30 deletions
diff --git a/src/viewport.cpp b/src/viewport.cpp
index b23f4d1f2..9c9790a3c 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -685,6 +685,17 @@ static void DrawSelectionSprite(SpriteID image, SpriteID pal, const TileInfo *ti
}
}
+/**
+ * Draws a selection rectangle on a tile.
+ *
+ * @param ti TileInfo Tile that is being drawn
+ * @param pal Palette to apply.
+ */
+static void DrawTileSelectionRect(const TileInfo *ti, SpriteID pal)
+{
+ DrawSelectionSprite(SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh], pal, ti);
+}
+
static bool IsPartOfAutoLine(int px, int py)
{
px -= _thd.selstart.x;
@@ -718,17 +729,38 @@ static const int _AutorailType[6][2] = {
#include "table/autorail.h"
/**
- * Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
+ * Draws autorail highlights.
+ *
* @param *ti TileInfo Tile that is being drawn
+ * @param autorail_type Offset into _AutorailTilehSprite[][]
*/
-static void DrawTileSelection(const TileInfo *ti)
+static void DrawAutorailSelection(const TileInfo *ti, uint autorail_type)
{
SpriteID image;
SpriteID pal;
+ int offset;
+
+ offset = _AutorailTilehSprite[ti->tileh][autorail_type];
+ if (offset >= 0) {
+ image = SPR_AUTORAIL_BASE + offset;
+ pal = PAL_NONE;
+ } else {
+ image = SPR_AUTORAIL_BASE - offset;
+ pal = PALETTE_SEL_TILE_RED;
+ }
+
+ DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti);
+}
+/**
+ * Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
+ * @param *ti TileInfo Tile that is being drawn
+ */
+static void DrawTileSelection(const TileInfo *ti)
+{
/* Draw a red error square? */
if (_thd.redsq != 0 && _thd.redsq == ti->tile) {
- DrawSelectionSprite(SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh], PALETTE_TILE_RED_PULSATING, ti);
+ DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING);
return;
}
@@ -739,8 +771,7 @@ static void DrawTileSelection(const TileInfo *ti)
if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) &&
IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) {
if (_thd.drawstyle & HT_RECT) {
- image = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh];
- DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE, ti);
+ DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE);
} else if (_thd.drawstyle & HT_POINT) {
/* Figure out the Z coordinate for the single dot. */
byte z = ti->z;
@@ -752,25 +783,12 @@ static void DrawTileSelection(const TileInfo *ti)
} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) {
/* autorail highlight piece under cursor */
uint type = _thd.drawstyle & 0xF;
- int offset;
-
assert(type <= 5);
-
- offset = _AutorailTilehSprite[ti->tileh][_AutorailType[type][0]];
- if (offset >= 0) {
- image = SPR_AUTORAIL_BASE + offset;
- pal = PAL_NONE;
- } else {
- image = SPR_AUTORAIL_BASE - offset;
- pal = PALETTE_TO_RED;
- }
-
- DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti);
+ DrawAutorailSelection(ti, _AutorailType[type][0]);
} else if (IsPartOfAutoLine(ti->x, ti->y)) {
/* autorail highlighting long line */
int dir = _thd.drawstyle & ~0xF0;
- int offset;
uint side;
if (dir < 2) {
@@ -780,16 +798,7 @@ static void DrawTileSelection(const TileInfo *ti)
side = delta(delta(TileX(start), TileX(ti->tile)), delta(TileY(start), TileY(ti->tile)));
}
- offset = _AutorailTilehSprite[ti->tileh][_AutorailType[dir][side]];
- if (offset >= 0) {
- image = SPR_AUTORAIL_BASE + offset;
- pal = PAL_NONE;
- } else {
- image = SPR_AUTORAIL_BASE - offset;
- pal = PALETTE_TO_RED;
- }
-
- DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti);
+ DrawAutorailSelection(ti, _AutorailType[dir][side]);
}
return;
}
@@ -800,7 +809,7 @@ static void DrawTileSelection(const TileInfo *ti)
IS_INSIDE_1D(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
IS_INSIDE_1D(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
/* Draw a blue rect. */
- DrawSelectionSprite(SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh], PALETTE_SEL_TILE_BLUE, ti);
+ DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE);
return;
}
}