linkgraph_gui.h

Go to the documentation of this file.
00001 /* $Id: linkgraph_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 LINKGRAPH_GUI_H
00013 #define LINKGRAPH_GUI_H
00014 
00015 #include "../company_func.h"
00016 #include "../station_base.h"
00017 #include "../widget_type.h"
00018 #include "linkgraph_base.h"
00019 #include <map>
00020 #include <list>
00021 
00025 struct LinkProperties {
00026   LinkProperties() : capacity(0), usage(0), planned(0), shared(false) {}
00027 
00028   uint capacity; 
00029   uint usage;    
00030   uint planned;  
00031   bool shared;   
00032 };
00033 
00038 class LinkGraphOverlay {
00039 public:
00040   typedef std::map<StationID, LinkProperties> StationLinkMap;
00041   typedef std::map<StationID, StationLinkMap> LinkMap;
00042   typedef std::list<std::pair<StationID, uint> > StationSupplyList;
00043 
00044   static const uint8 LINK_COLOURS[];
00045 
00054   LinkGraphOverlay(const Window *w, uint wid, uint32 cargo_mask, uint32 company_mask, uint scale) :
00055       window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
00056   {}
00057 
00058   void RebuildCache();
00059   void Draw(const DrawPixelInfo *dpi) const;
00060   void SetCargoMask(uint32 cargo_mask);
00061   void SetCompanyMask(uint32 company_mask);
00062 
00064   uint32 GetCargoMask() { return this->cargo_mask; }
00065 
00067   uint32 GetCompanyMask() { return this->company_mask; }
00068 
00069 protected:
00070   const Window *window;              
00071   const uint widget_id;              
00072   uint32 cargo_mask;                 
00073   uint32 company_mask;               
00074   LinkMap cached_links;              
00075   StationSupplyList cached_stations; 
00076   uint scale;                        
00077 
00078   Point GetStationMiddle(const Station *st) const;
00079 
00080   void DrawForwBackLinks(Point pta, StationID sta, Point ptb, StationID stb) const;
00081   void AddLinks(const Station *sta, const Station *stb);
00082   void DrawLinks(const DrawPixelInfo *dpi) const;
00083   void DrawStationDots(const DrawPixelInfo *dpi) const;
00084   void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const;
00085   bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
00086   bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
00087   void GetWidgetDpi(DrawPixelInfo *dpi) const;
00088 
00089   static void AddStats(uint new_cap, uint new_usg, uint new_flow, bool new_shared, LinkProperties &cargo);
00090   static void DrawVertex(int x, int y, int size, int colour, int border_colour);
00091 };
00092 
00093 void ShowLinkGraphLegend();
00094 
00098 struct LinkGraphLegendWindow : Window {
00099 public:
00100   LinkGraphLegendWindow(WindowDesc *desc, int window_number);
00101   void SetOverlay(LinkGraphOverlay *overlay);
00102 
00103   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize);
00104   virtual void DrawWidget(const Rect &r, int widget) const;
00105   virtual void OnClick(Point pt, int widget, int click_count);
00106   virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
00107 
00108 private:
00109   LinkGraphOverlay *overlay;
00110 
00111   void UpdateOverlayCompanies();
00112   void UpdateOverlayCargoes();
00113 };
00114 
00115 #endif /* LINKGRAPH_GUI_H */