smallmap_gui.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef SMALLMAP_GUI_H
00013 #define SMALLMAP_GUI_H
00014 
00015 #include "industry_type.h"
00016 #include "window_gui.h"
00017 #include "strings_func.h"
00018 #include "blitter/factory.hpp"
00019 #include "linkgraph_gui.h"
00020 #include "widgets/smallmap_widget.h"
00021 
00022 /* set up the cargos to be displayed in the smallmap's route legend */
00023 void BuildLinkStatsLegend();
00024 
00025 void BuildIndustriesLegend();
00026 void ShowSmallMap();
00027 void BuildLandLegend();
00028 void BuildOwnerLegend();
00029 
00031 struct LegendAndColour {
00032   uint8 colour;              
00033   StringID legend;           
00034   IndustryType type;         
00035   uint8 height;              
00036   CompanyID company;         
00037   bool show_on_map;          
00038   bool end;                  
00039   bool col_break;            
00040 };
00041 
00043 class SmallMapWindow : public Window {
00044 protected:
00046   enum SmallMapType {
00047     SMT_CONTOUR,
00048     SMT_VEHICLES,
00049     SMT_INDUSTRY,
00050     SMT_LINKSTATS,
00051     SMT_ROUTES,
00052     SMT_VEGETATION,
00053     SMT_OWNER,
00054   };
00055 
00057   enum ZoomLevelChange {
00058     ZLC_INITIALIZE, 
00059     ZLC_ZOOM_OUT,   
00060     ZLC_ZOOM_IN,    
00061   };
00062 
00063   static SmallMapType map_type; 
00064   static bool show_towns;       
00065 
00066   static const uint LEGEND_BLOB_WIDTH = 8;              
00067   static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; 
00068   static const uint FORCE_REFRESH_PERIOD = 0x1F; 
00069   static const uint BLINK_PERIOD         = 0x0F; 
00070 
00071   uint min_number_of_columns;    
00072   uint min_number_of_fixed_rows; 
00073   uint column_width;             
00074 
00075   int32 scroll_x;  
00076   int32 scroll_y;  
00077   int32 subscroll; 
00078   int zoom;        
00079 
00080   uint8 refresh;   
00081   LinkGraphOverlay *overlay;
00082 
00083   Point SmallmapRemapCoords(int x, int y) const;
00084 
00091   static inline void DrawVertMapIndicator(int x, int y, int y2)
00092   {
00093     GfxFillRect(x, y,      x, y + 3, PC_VERY_LIGHT_YELLOW);
00094     GfxFillRect(x, y2 - 3, x, y2,    PC_VERY_LIGHT_YELLOW);
00095   }
00096 
00103   static inline void DrawHorizMapIndicator(int x, int x2, int y)
00104   {
00105     GfxFillRect(x,      y, x + 3, y, PC_VERY_LIGHT_YELLOW);
00106     GfxFillRect(x2 - 3, y, x2,    y, PC_VERY_LIGHT_YELLOW);
00107   }
00108 
00113   inline uint GetMinLegendWidth() const
00114   {
00115     return WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width;
00116   }
00117 
00122   inline uint GetNumberColumnsLegend(uint width) const
00123   {
00124     return width / this->column_width;
00125   }
00126 
00132   inline uint GetLegendHeight(uint num_columns) const
00133   {
00134     return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM +
00135         this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
00136   }
00137 
00138   uint GetNumberRowsLegend(uint columns) const;
00139   void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
00140   void SwitchMapType(SmallMapType map_type);
00141   void SetNewScroll(int sx, int sy, int sub);
00142 
00143   void DrawMapIndicators() const;
00144   void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const;
00145   void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const;
00146   void DrawTowns(const DrawPixelInfo *dpi) const;
00147   void DrawSmallMap(DrawPixelInfo *dpi) const;
00148 
00149   Point RemapTile(int tile_x, int tile_y) const;
00150   Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const;
00151   Point ComputeScroll(int tx, int ty, int x, int y, int *sub);
00152   void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
00153   void SetOverlayCargoMask();
00154   void SetupWidgetData();
00155   uint32 GetTileColours(const TileArea &ta) const;
00156 
00157   int GetPositionOnLegend(Point pt);
00158 
00159 public:
00160   friend class NWidgetSmallmapDisplay;
00161 
00162   SmallMapWindow(const WindowDesc *desc, int window_number);
00163   virtual ~SmallMapWindow() { delete this->overlay; }
00164 
00165   void SmallMapCenterOnCurrentPos();
00166   Point GetStationMiddle(const Station *st) const;
00167 
00168   virtual void SetStringParameters(int widget) const;
00169   virtual void OnInit();
00170   virtual void OnPaint();
00171   virtual void DrawWidget(const Rect &r, int widget) const;
00172   virtual void OnClick(Point pt, int widget, int click_count);
00173   virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
00174   virtual bool OnRightClick(Point pt, int widget);
00175   virtual void OnMouseWheel(int wheel);
00176   virtual void OnTick();
00177   virtual void OnScroll(Point delta);
00178   virtual void OnMouseOver(Point pt, int widget);
00179 };
00180 
00181 #endif /* SMALLMAP_GUI_H */