summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-10-10 14:05:39 +0000
committerDarkvater <darkvater@openttd.org>2006-10-10 14:05:39 +0000
commit4d7c5398896acca64a7691bc6dbb7041da1e3e13 (patch)
tree1f5e1b4c77a9a045ee4f5ecc7907215f2960d0f1
parente93222903ab11395683f3b93c9e00b2bea88b9bd (diff)
downloadopenttd-4d7c5398896acca64a7691bc6dbb7041da1e3e13.tar.xz
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
-rw-r--r--viewport.c27
-rw-r--r--viewport.h17
2 files changed, 25 insertions, 19 deletions
diff --git a/viewport.c b/viewport.c
index 3dbd915eb..5db949401 100644
--- a/viewport.c
+++ b/viewport.c
@@ -1990,12 +1990,11 @@ static byte Check2x1AutoRail(int mode)
// while dragging
static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
{
- int d;
- byte b=6;
- uint w,h;
+ HighLightStyle b;
+ uint w, h;
- int dx = thd->selstart.x - (thd->selend.x&~0xF);
- int dy = thd->selstart.y - (thd->selend.y&~0xF);
+ int dx = thd->selstart.x - (thd->selend.x & ~0xF);
+ int dy = thd->selstart.y - (thd->selend.y & ~0xF);
w = myabs(dx) + 16;
h = myabs(dy) + 16;
@@ -2030,7 +2029,7 @@ static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int meth
b = HT_LINE | HT_DIR_Y;
x = thd->selstart.x;
} else { // complicated direction
- d = w - h;
+ int d = w - h;
thd->selend.x = thd->selend.x & ~0xF;
thd->selend.y = thd->selend.y & ~0xF;
@@ -2093,18 +2092,22 @@ static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int meth
thd->next_drawstyle = b;
}
-// while dragging
+/**
+ * Selects tiles while dragging
+ * @param x X coordinate of end of selection
+ * @param y Y coordinate of end of selection
+ * @param method modifies the way tiles are selected. Possible
+ * methods are VPM_* in viewport.h */
void VpSelectTilesWithMethod(int x, int y, int method)
{
- int sx;
- int sy;
+ int sx, sy;
if (x == -1) {
_thd.selend.x = -1;
return;
}
- // allow drag in any rail direction
+ /* Special handling of drag in any (8-way) direction */
if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
_thd.selend.x = x;
_thd.selend.y = y;
@@ -2113,8 +2116,8 @@ void VpSelectTilesWithMethod(int x, int y, int method)
}
if (_thd.next_drawstyle == HT_POINT) {
- x += 8;
- y += 8;
+ x += TILE_SIZE / 2;
+ y += TILE_SIZE / 2;
}
sx = _thd.selstart.x;
diff --git a/viewport.h b/viewport.h
index 26b90a24c..5f1bbb749 100644
--- a/viewport.h
+++ b/viewport.h
@@ -71,7 +71,8 @@ enum {
void VpSelectTilesWithMethod(int x, int y, int method);
// highlighting draw styles
-enum {
+typedef byte HighLightStyle;
+enum HighLightStyles {
HT_NONE = 0x00,
HT_RECT = 0x80,
HT_POINT = 0x40,
@@ -79,15 +80,17 @@ enum {
* (uses lower bits to indicate direction) */
HT_RAIL = 0x10, /* autorail (one piece)
* (uses lower bits to indicate direction) */
+ HT_DRAG_MASK = 0xF0, ///< masks the drag-type
/* lower bits (used with HT_LINE and HT_RAIL):
* (see ASCII art in autorail.h for a visual interpretation) */
- HT_DIR_X = 0, // X direction
- HT_DIR_Y = 1, // Y direction
- HT_DIR_HU = 2, // horizontal upper
- HT_DIR_HL = 3, // horizontal lower
- HT_DIR_VL = 4, // vertical left
- HT_DIR_VR = 5, // vertical right
+ HT_DIR_X = 0, ///< X direction
+ HT_DIR_Y = 1, ///< Y direction
+ HT_DIR_HU = 2, ///< horizontal upper
+ HT_DIR_HL = 3, ///< horizontal lower
+ HT_DIR_VL = 4, ///< vertical left
+ HT_DIR_VR = 5, ///< vertical right
+ HT_DIR_MASK = 0x7 ///< masks the drag-direction
};
typedef struct TileHighlightData {