Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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 = 0xFFFFFFFF,
00055 uint32 company_mask = 1 << _local_company, uint scale = 1) :
00056 window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
00057 {}
00058
00059 void RebuildCache();
00060 void Draw(const DrawPixelInfo *dpi) const;
00061 void SetCargoMask(uint32 cargo_mask);
00062 void SetCompanyMask(uint32 company_mask);
00063
00065 uint32 GetCargoMask() { return this->cargo_mask; }
00066
00068 uint32 GetCompanyMask() { return this->company_mask; }
00069
00070 protected:
00071 const Window *window;
00072 const uint widget_id;
00073 uint32 cargo_mask;
00074 uint32 company_mask;
00075 LinkMap cached_links;
00076 StationSupplyList cached_stations;
00077 uint scale;
00078
00079 Point GetStationMiddle(const Station *st) const;
00080
00081 void DrawForwBackLinks(Point pta, StationID sta, Point ptb, StationID stb) const;
00082 void AddLinks(const Station *sta, const Station *stb);
00083 void DrawLinks(const DrawPixelInfo *dpi) const;
00084 void DrawStationDots(const DrawPixelInfo *dpi) const;
00085 void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const;
00086 bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
00087 bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
00088 void GetWidgetDpi(DrawPixelInfo *dpi) const;
00089
00090 static void AddStats(uint new_cap, uint new_usg, uint new_flow, bool new_shared, LinkProperties &cargo);
00091 static void DrawVertex(int x, int y, int size, int colour, int border_colour);
00092 };
00093
00094 void ShowLinkGraphLegend();
00095
00099 struct LinkGraphLegendWindow : Window {
00100 public:
00101 LinkGraphLegendWindow(WindowDesc *desc, int window_number);
00102 void SetOverlay(LinkGraphOverlay *overlay);
00103
00104 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize);
00105 virtual void DrawWidget(const Rect &r, int widget) const;
00106 virtual void OnClick(Point pt, int widget, int click_count);
00107 virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
00108
00109 private:
00110 LinkGraphOverlay *overlay;
00111
00112 void UpdateOverlayCompanies();
00113 void UpdateOverlayCargoes();
00114 };
00115
00116 #endif