summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-10-20 21:26:56 +0000
committersmatz <smatz@openttd.org>2009-10-20 21:26:56 +0000
commit232d7bc4f49e415775038f13eafac5ef38b2b62b (patch)
tree77dd6097e02f29162e2c36bee58a0f3d7ed2774b
parent21fdc65ce4ed3fd6edd7a066b48e7e5b5af4844c (diff)
downloadopenttd-232d7bc4f49e415775038f13eafac5ef38b2b62b.tar.xz
(svn r17831) -Codechange: move code used for adding map indicators of the smallmap to separate functions
-rw-r--r--src/smallmap_gui.cpp84
1 files changed, 52 insertions, 32 deletions
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 385b1e581..e4fc48ac5 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -532,18 +532,6 @@ static const byte _vehicle_type_colours[6] = {
};
-static void DrawVertMapIndicator(int x, int y, int x2, int y2)
-{
- GfxFillRect(x, y, x2, y + 3, 69);
- GfxFillRect(x, y2 - 3, x2, y2, 69);
-}
-
-static void DrawHorizMapIndicator(int x, int y, int x2, int y2)
-{
- GfxFillRect(x, y, x + 3, y2, 69);
- GfxFillRect(x2 - 3, y, x2, y2, 69);
-}
-
class SmallMapWindow : public Window {
enum SmallMapType {
SMT_CONTOUR,
@@ -715,6 +703,57 @@ class SmallMapWindow : public Window {
}
/**
+ * Draws vertical part of map indicator
+ * @param x X coord of left/right border of main viewport
+ * @param y Y coord of top border of main viewport
+ * @param y2 Y coord of bottom border of main viewport
+ */
+ static inline void DrawVertMapIndicator(int x, int y, int y2)
+ {
+ GfxFillRect(x, y, x, y + 3, 69);
+ GfxFillRect(x, y2 - 3, x, y2, 69);
+ }
+
+ /**
+ * Draws horizontal part of map indicator
+ * @param x X coord of left border of main viewport
+ * @param x2 X coord of right border of main viewport
+ * @param y Y coord of top/bottom border of main viewport
+ */
+ static inline void DrawHorizMapIndicator(int x, int x2, int y)
+ {
+ GfxFillRect(x, y, x + 3, y, 69);
+ GfxFillRect(x2 - 3, y, x2, y, 69);
+ }
+
+ /**
+ * Adds map indicators to the smallmap.
+ */
+ inline void DrawMapIndicators()
+ {
+ /* Find main viewport. */
+ const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
+
+ Point pt = RemapCoords(this->scroll_x, this->scroll_y, 0);
+
+ int x = vp->virtual_left - pt.x;
+ int y = vp->virtual_top - pt.y;
+ int x2 = (x + vp->virtual_width) / TILE_SIZE;
+ int y2 = (y + vp->virtual_height) / TILE_SIZE;
+ x /= TILE_SIZE;
+ y /= TILE_SIZE;
+
+ x -= this->subscroll;
+ x2 -= this->subscroll;
+
+ SmallMapWindow::DrawVertMapIndicator(x, y, y2);
+ SmallMapWindow::DrawVertMapIndicator(x2, y, y2);
+
+ SmallMapWindow::DrawHorizMapIndicator(x, x2, y);
+ SmallMapWindow::DrawHorizMapIndicator(x, x2, y2);
+ }
+
+ /**
* Draws the small map.
*
* Basically, the small map is draw column of pixels by column of pixels. The pixels
@@ -823,27 +862,8 @@ class SmallMapWindow : public Window {
/* Draw town names */
if (this->show_towns) this->DrawTowns(dpi);
- /* Find main viewport. */
- ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
-
- /* Draw map indicators */
- Point pt = RemapCoords(this->scroll_x, this->scroll_y, 0);
-
- x = vp->virtual_left - pt.x;
- y = vp->virtual_top - pt.y;
- int x2 = (x + vp->virtual_width) / TILE_SIZE;
- int y2 = (y + vp->virtual_height) / TILE_SIZE;
- x /= TILE_SIZE;
- y /= TILE_SIZE;
-
- x -= this->subscroll;
- x2 -= this->subscroll;
-
- DrawVertMapIndicator(x, y, x, y2);
- DrawVertMapIndicator(x2, y, x2, y2);
+ this->DrawMapIndicators();
- DrawHorizMapIndicator(x, y, x2, y);
- DrawHorizMapIndicator(x, y2, x2, y2);
_cur_dpi = old_dpi;
}