00001 00007 #include <minimap.h> 00008 #include <zakdef.h> 00009 #include <globals.h> 00010 #include <simcity.h> 00011 #include <ui.h> 00012 #include <logging.h> 00013 #include <resCompat.h> 00014 #include <UIColor.h> 00015 00017 static struct minimap { 00018 RectangleType rect; 00019 RectangleType rout; 00021 Int8 showing:1; 00022 Int8 detailed:1; 00023 } minimap; 00024 00025 Int8 00026 minimapGetShowing(void) 00027 { 00028 return (minimap.showing); 00029 } 00030 00031 void 00032 minimapSetShowing(Int8 show) 00033 { 00034 minimap.showing = show ? 1 : 0; 00035 } 00036 00037 Int8 00038 minimapGetDetailed(void) 00039 { 00040 return (minimap.detailed); 00041 } 00042 00043 void 00044 minimapSetDetailed(Int8 detailed) 00045 { 00046 minimap.detailed = detailed ? 1 : 0; 00047 } 00048 00049 void 00050 minimapPlace(RectangleType *pos) 00051 { 00052 MemMove(&minimap.rect, pos, sizeof (RectangleType)); 00053 00054 if (minimap.rect.extent.x != 0 && minimap.rect.extent.y != 0) { 00055 minimap.rout.extent.x = (Coord)((Int32)minimap.rect.extent.x * 00056 getVisibleX() / getMapWidth()); 00057 minimap.rout.extent.y = (Coord)((Int32)minimap.rect.extent.y * 00058 getVisibleY() / getMapHeight()); 00059 } 00060 } 00061 00062 void 00063 minimapIntersect(const RectangleType *other, RectangleType *dest) 00064 { 00065 RctGetIntersection(&minimap.rect, other, dest); 00066 } 00067 00068 00069 void 00070 minimapPaint(void) 00071 { 00072 if (!minimap.showing) return; 00073 00074 WinEraseRectangle(&minimap.rect, 0); 00075 minimap.rout.topLeft.x = (Coord)(minimap.rect.topLeft.x + 00076 (Int32)getMapXPos() * minimap.rect.extent.x / getMapWidth()); 00077 minimap.rout.topLeft.y = (Coord)(minimap.rect.topLeft.y + 00078 (Int32)getMapYPos() * minimap.rect.extent.y / getMapHeight()); 00079 WriteLog("Minimap rect = (%d,%d) -> (%d,%d)\n", 00080 (int)minimap.rout.topLeft.x, (int)minimap.rout.topLeft.y, 00081 (int)minimap.rout.extent.x, (int)minimap.rout.extent.y); 00082 WinDrawRectangle(&minimap.rout, 0); 00083 } 00084 00085 Int8 00086 minimapIsTapped(PointType *point, PointType *percentage) 00087 { 00088 if (!minimap.showing) return (0); 00089 if (RctPtInRectangle(point->x, point->y, &minimap.rect)) { 00090 percentage->x = (Coord)(((Int32)point->x - 00091 minimap.rect.topLeft.x) * 100 / 00092 minimap.rect.extent.x); 00093 percentage->y = (Coord)(((Int32)point->y - 00094 minimap.rect.topLeft.y) * 100 / 00095 minimap.rect.extent.y); 00096 return (1); 00097 } 00098 return (0); 00099 }