smallmap_gui.h

Go to the documentation of this file.
00001 /* $Id: smallmap_gui.h 26266 2014-01-19 09:26:56Z fonsinchen $ */
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 "company_base.h"
00017 #include "window_gui.h"
00018 #include "strings_func.h"
00019 #include "blitter/factory.hpp"
00020 #include "linkgraph/linkgraph_gui.h"
00021 #include "widgets/smallmap_widget.h"
00022 
00023 /* set up the cargos to be displayed in the smallmap's route legend */
00024 void BuildLinkStatsLegend();
00025 
00026 void BuildIndustriesLegend();
00027 void ShowSmallMap();
00028 void BuildLandLegend();
00029 void BuildOwnerLegend();
00030 
00032 struct LegendAndColour {
00033   uint8 colour;              
00034   StringID legend;           
00035   IndustryType type;         
00036   uint8 height;              
00037   CompanyID company;         
00038   bool show_on_map;          
00039   bool end;                  
00040   bool col_break;            
00041 };
00042 
00044 class SmallMapWindow : public Window {
00045 protected:
00047   enum SmallMapType {
00048     SMT_CONTOUR,
00049     SMT_VEHICLES,
00050     SMT_INDUSTRY,
00051     SMT_LINKSTATS,
00052     SMT_ROUTES,
00053     SMT_VEGETATION,
00054     SMT_OWNER,
00055   };
00056 
00058   enum ZoomLevelChange {
00059     ZLC_INITIALIZE, 
00060     ZLC_ZOOM_OUT,   
00061     ZLC_ZOOM_IN,    
00062   };
00063 
00064   static SmallMapType map_type; 
00065   static bool show_towns;       
00066 
00067   static const uint LEGEND_BLOB_WIDTH = 8;              
00068   static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; 
00069   static const uint FORCE_REFRESH_PERIOD = 0x1F; 
00070   static const uint BLINK_PERIOD         = 0x0F; 
00071 
00072   uint min_number_of_columns;    
00073   uint min_number_of_fixed_rows; 
00074   uint column_width;             
00075 
00076   int32 scroll_x;  
00077   int32 scroll_y;  
00078   int32 subscroll; 
00079   int zoom;        
00080 
00081   uint8 refresh;   
00082   LinkGraphOverlay *overlay;
00083 
00084   Point SmallmapRemapCoords(int x, int y) const;
00085 
00092   static inline void DrawVertMapIndicator(int x, int y, int y2)
00093   {
00094     GfxFillRect(x, y,      x, y + 3, PC_VERY_LIGHT_YELLOW);
00095     GfxFillRect(x, y2 - 3, x, y2,    PC_VERY_LIGHT_YELLOW);
00096   }
00097 
00104   static inline void DrawHorizMapIndicator(int x, int x2, int y)
00105   {
00106     GfxFillRect(x,      y, x + 3, y, PC_VERY_LIGHT_YELLOW);
00107     GfxFillRect(x2 - 3, y, x2,    y, PC_VERY_LIGHT_YELLOW);
00108   }
00109 
00114   inline uint GetMinLegendWidth() const
00115   {
00116     return WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width;
00117   }
00118 
00123   inline uint GetNumberColumnsLegend(uint width) const
00124   {
00125     return width / this->column_width;
00126   }
00127 
00133   inline uint GetLegendHeight(uint num_columns) const
00134   {
00135     return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM +
00136         this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
00137   }
00138 
00144   inline uint32 GetOverlayCompanyMask() const
00145   {
00146     return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff;
00147   }
00148 
00149   uint GetNumberRowsLegend(uint columns) const;
00150   void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
00151   void SwitchMapType(SmallMapType map_type);
00152   void SetNewScroll(int sx, int sy, int sub);
00153 
00154   void DrawMapIndicators() const;
00155   void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const;
00156   void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const;
00157   void DrawTowns(const DrawPixelInfo *dpi) const;
00158   void DrawSmallMap(DrawPixelInfo *dpi) const;
00159 
00160   Point RemapTile(int tile_x, int tile_y) const;
00161   Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const;
00162   Point ComputeScroll(int tx, int ty, int x, int y, int *sub);
00163   void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
00164   void SetOverlayCargoMask();
00165   void SetupWidgetData();
00166   uint32 GetTileColours(const TileArea &ta) const;
00167 
00168   int GetPositionOnLegend(Point pt);
00169 
00170 public:
00171   friend class NWidgetSmallmapDisplay;
00172 
00173   SmallMapWindow(WindowDesc *desc, int window_number);
00174   virtual ~SmallMapWindow() { delete this->overlay; }
00175 
00176   void SmallMapCenterOnCurrentPos();
00177   Point GetStationMiddle(const Station *st) const;
00178 
00179   virtual void SetStringParameters(int widget) const;
00180   virtual void OnInit();
00181   virtual void OnPaint();
00182   virtual void DrawWidget(const Rect &r, int widget) const;
00183   virtual void OnClick(Point pt, int widget, int click_count);
00184   virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
00185   virtual bool OnRightClick(Point pt, int widget);
00186   virtual void OnMouseWheel(int wheel);
00187   virtual void OnTick();
00188   virtual void OnScroll(Point delta);
00189   virtual void OnMouseOver(Point pt, int widget);
00190 };
00191 
00192 #endif /* SMALLMAP_GUI_H */