summaryrefslogtreecommitdiff
path: root/src/gfx.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-09-26 19:27:29 +0000
committerrubidium <rubidium@openttd.org>2007-09-26 19:27:29 +0000
commitd464d7587d68abb171a7290acdd62d4aac73079b (patch)
treee849cab170d4976cd9e1c158dde9f23202afd978 /src/gfx.cpp
parenta28b307c952fb4213ec75ad8db602235e84f934e (diff)
downloadopenttd-d464d7587d68abb171a7290acdd62d4aac73079b.tar.xz
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
Note that this is not completely glitch free, bounding boxes sometimes aren't removed properly. This is due to the fact that the bounding boxes sometimes are larger than the sprite, which causes a smaller part than the bounding box to be redrawn. This is NOT a bug, but a known implementation limit as we do not want to slow down normal games so the debug graphics are always 100% correct.
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r--src/gfx.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 8a1b9741c..411267525 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -139,6 +139,50 @@ void GfxDrawLine(int x, int y, int x2, int y2, int color)
blitter->DrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, color);
}
+/**
+ * Draws the projection of a parallelepiped.
+ * This can be used to draw boxes in world coordinates.
+ *
+ * @param x Screen X-coordinate of top front corner.
+ * @param y Screen Y-coordinate of top front corner.
+ * @param dx1 Screen X-length of first edge.
+ * @param dy1 Screen Y-length of first edge.
+ * @param dx2 Screen X-length of second edge.
+ * @param dy2 Screen Y-length of second edge.
+ * @param dx3 Screen X-length of third edge.
+ * @param dy3 Screen Y-length of third edge.
+ */
+void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
+{
+ /* ....
+ * .. ....
+ * .. ....
+ * .. ^
+ * <--__(dx1,dy1) /(dx2,dy2)
+ * : --__ / :
+ * : --__ / :
+ * : *(x,y) :
+ * : | :
+ * : | ..
+ * .... |(dx3,dy3)
+ * .... | ..
+ * ....V.
+ */
+
+ static const byte color = 255;
+
+ GfxDrawLine(x, y, x + dx1, y + dy1, color);
+ GfxDrawLine(x, y, x + dx2, y + dy2, color);
+ GfxDrawLine(x, y, x + dx3, y + dy3, color);
+
+ GfxDrawLine(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, color);
+ GfxDrawLine(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, color);
+ GfxDrawLine(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, color);
+ GfxDrawLine(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, color);
+ GfxDrawLine(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, color);
+ GfxDrawLine(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, color);
+}
+
/** Truncate a given string to a maximum width if neccessary.
* If the string is truncated, add three dots ('...') to show this.