src/smallmap_gui.cpp
branchcpp_gui
changeset 6308 646711c5feaa
parent 6307 f40e88cff863
--- a/src/smallmap_gui.cpp	Sun Apr 15 17:04:44 2007 +0000
+++ b/src/smallmap_gui.cpp	Sat Apr 21 08:23:57 2007 +0000
@@ -49,12 +49,24 @@
 static int _smallmap_type;
 static bool _smallmap_show_towns = true;
 
-#define MK(a,b) a, b
-#define MKEND() 0xFFFF
-#define MS(a,b) (a | 0x100), b
+/** Macro for ordinary entry of LegendAndColor */
+#define MK(a,b) {a, b, false, false}
+/** Macro for end of list marker in arrays of LegendAndColor */
+#define MKEND() {0, STR_NULL, true, false}
+/** Macro for break marker in arrays of LegendAndColor.
+ * It will have valid data, though */
+#define MS(a,b) {a, b, false, true}
 
-/* Legend text giving the colours to look for on the minimap */
-static const uint16 _legend_land_contours[] = {
+/** Structure for holding relevant data for legends in small map */
+struct LegendAndColour {
+	uint16 colour;     ///< color of the item on the map
+	StringID legend;   ///< string corresponding to the colored item
+	bool end;         ///< this is the end of the list
+	bool col_break;   ///< perform a break and go one collumn further
+};
+
+/** Legend text giving the colours to look for on the minimap */
+static const LegendAndColour _legend_land_contours[] = {
 	MK(0x5A, STR_00F0_100M),
 	MK(0x5C, STR_00F1_200M),
 	MK(0x5E, STR_00F2_300M),
@@ -69,7 +81,7 @@
 	MKEND()
 };
 
-static const uint16 _legend_vehicles[] = {
+static const LegendAndColour _legend_vehicles[] = {
 	MK(0xB8, STR_00F5_TRAINS),
 	MK(0xBF, STR_00F6_ROAD_VEHICLES),
 	MK(0x98, STR_00F7_SHIPS),
@@ -79,7 +91,7 @@
 	MKEND()
 };
 
-static const uint16 _legend_industries_normal[] = {
+static const LegendAndColour _legend_industries_normal[] = {
 	MK(0xD7, STR_00FA_COAL_MINE),
 	MK(0xB8, STR_00FB_POWER_STATION),
 	MK(0x56, STR_00FC_FOREST),
@@ -95,7 +107,7 @@
 	MKEND()
 };
 
-static const uint16 _legend_industries_hilly[] = {
+static const LegendAndColour _legend_industries_hilly[] = {
 	MK(0xD7, STR_00FA_COAL_MINE),
 	MK(0xB8, STR_00FB_POWER_STATION),
 	MK(0x56, STR_00FC_FOREST),
@@ -111,7 +123,7 @@
 	MKEND()
 };
 
-static const uint16 _legend_industries_desert[] = {
+static const LegendAndColour _legend_industries_desert[] = {
 	MK(0xBF, STR_00FE_OIL_REFINERY),
 	MK(0x98, STR_0102_OIL_WELLS),
 	MK(0x0F, STR_0105_BANK),
@@ -129,7 +141,7 @@
 	MKEND()
 };
 
-static const uint16 _legend_industries_candy[] = {
+static const LegendAndColour _legend_industries_candy[] = {
 	MK(0x30, STR_0110_COTTON_CANDY_FOREST),
 	MK(0xAE, STR_0111_CANDY_FACTORY),
 	MK(0x27, STR_0112_BATTERY_FARM),
@@ -145,7 +157,7 @@
 	MKEND()
 };
 
-static const uint16 _legend_routes[] = {
+static const LegendAndColour _legend_routes[] = {
 	MK(0xD7, STR_00EB_ROADS),
 	MK(0x0A, STR_00EC_RAILROADS),
 	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
@@ -158,7 +170,7 @@
 	MKEND()
 };
 
-static const uint16 _legend_vegetation[] = {
+static const LegendAndColour _legend_vegetation[] = {
 	MK(0x52, STR_0120_ROUGH_LAND),
 	MK(0x54, STR_0121_GRASS_LAND),
 	MK(0x37, STR_0122_BARE_LAND),
@@ -174,7 +186,7 @@
 	MKEND()
 };
 
-static const uint16 _legend_land_owners[] = {
+static const LegendAndColour _legend_land_owners[] = {
 	MK(0xCA, STR_0126_WATER),
 	MK(0x54, STR_0127_NO_OWNER),
 	MK(0xB4, STR_0128_TOWNS),
@@ -186,8 +198,9 @@
 #undef MKEND
 
 
-enum { IND_OFFS = 6 };
-static const uint16 * const _legend_table[] = {
+enum { IND_OFFS = 6 };  ///< allow to "jump" to the industries corresponding to the landscape
+
+static const LegendAndColour * const _legend_table[] = {
 	_legend_land_contours,
 	_legend_vehicles,
 	NULL,
@@ -383,7 +396,7 @@
 /**
  * Return the color a tile would be displayed with in the small map in mode "Vehicles".
  *
- * @param t The tile of which we would like to get the color.
+ * @param tile The tile of which we would like to get the color.
  * @return The color of tile in the small map in mode "Vehicles"
  */
 static inline uint32 GetSmallMapVehiclesPixels(TileIndex tile)
@@ -413,7 +426,7 @@
 /**
  * Return the color a tile would be displayed with in the small map in mode "Routes".
  *
- * @param t The tile of which we would like to get the color.
+ * @param tile The tile of which we would like to get the color.
  * @return The color of tile  in the small map in mode "Routes"
  */
 static inline uint32 GetSmallMapRoutesPixels(TileIndex tile)
@@ -489,7 +502,7 @@
 /**
  * Return the color a tile would be displayed with in the small map in mode "Owner".
  *
- * @param t The tile of which we would like to get the color.
+ * @param tile The tile of which we would like to get the color.
  * @return The color of tile in the small map in mode "Owner"
  */
 static inline uint32 GetSmallMapOwnerPixels(TileIndex tile)
@@ -553,7 +566,7 @@
  * are drawn directly into the screen buffer. The final map is drawn in multiple passes.
  * The passes are:
  * <ol><li>The colors of tiles in the different modes.</li>
- * <li>Town names (optional)</li>
+ * <li>Town names (optional)</li></ol>
  *
  * @param dpi pointer to pixel to write onto
  * @param w pointer to BaseWindow struct
@@ -779,7 +792,7 @@
 {
 	switch (e->event) {
 		case WE_PAINT: {
-			const uint16 *tbl;
+			const LegendAndColour *tbl;
 			int x, y, y_org;
 			DrawPixelInfo new_dpi;
 
@@ -794,15 +807,16 @@
 			y = y_org;
 			for (;;) {
 				GfxFillRect(x,     y + 1, x + 8, y + 5, 0);
-				GfxFillRect(x + 1, y + 2, x + 7, y + 4, (byte)tbl[0]);
-				DrawString(x + 11, y, tbl[1], 0);
+				GfxFillRect(x + 1, y + 2, x + 7, y + 4, tbl->colour);
+				DrawString(x + 11, y, tbl->legend, 0);
 
-				tbl += 2;
+				tbl += 1;
 				y += 6;
 
-				if (tbl[0] == 0xFFFF) {
+				if (tbl->end) { // end of the list
 					break;
-				} else if (tbl[0] & 0x100) {
+				} else if (tbl->col_break) {
+					/*  break asked, continue at top, 123 pixels (one "row") to the right */
 					x += 123;
 					y = y_org;
 				}