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
00019 #include "table/strings.h"
00020
00021 #include <map>
00022 #include <list>
00023
00027 struct LinkProperties {
00028 LinkProperties() : capacity(0), usage(0), planned(0) {}
00029
00030 uint capacity;
00031 uint usage;
00032 uint planned;
00033 };
00034
00039 class LinkGraphOverlay {
00040 public:
00041 typedef std::map<StationID, LinkProperties> StationLinkMap;
00042 typedef std::map<StationID, StationLinkMap> LinkMap;
00043 typedef std::list<std::pair<StationID, uint> > StationSupplyList;
00044
00045 static const uint8 LINK_COLOURS[];
00046
00055 LinkGraphOverlay(const Window *w, uint wid, uint32 cargo_mask = 0xFFFF,
00056 uint32 company_mask = 1 << _local_company, uint scale = 1) :
00057 window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
00058 {}
00059
00060 void RebuildCache();
00061 void Draw(const DrawPixelInfo *dpi) const;
00062 void SetCargoMask(uint32 cargo_mask);
00063 void SetCompanyMask(uint32 company_mask);
00064
00066 uint32 GetCargoMask() {return this->cargo_mask;}
00067
00069 uint32 GetCompanyMask() {return this->company_mask;}
00070
00071 protected:
00072 const Window *window;
00073 const uint widget_id;
00074 uint32 cargo_mask;
00075 uint32 company_mask;
00076 LinkMap cached_links;
00077 StationSupplyList cached_stations;
00078 uint scale;
00079
00080 Point GetStationMiddle(const Station *st) const;
00081
00082 void DrawForwBackLinks(Point pta, StationID sta, Point ptb, StationID stb) const;
00083 void AddLinks(const Station *sta, const Station *stb);
00084 void DrawLinks(const DrawPixelInfo *dpi) const;
00085 void DrawStationDots(const DrawPixelInfo *dpi) const;
00086 void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const;
00087 bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
00088 bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
00089 void GetWidgetDpi(DrawPixelInfo *dpi) const;
00090
00091 static void AddStats(const LinkStat &orig_link, const FlowStat &orig_flow, LinkProperties &cargo);
00092 static void DrawVertex(int x, int y, int size, int colour, int border_colour);
00093 };
00094
00095 void ShowLinkGraphLegend();
00096
00100 struct LinkGraphLegendWindow : Window {
00101 public:
00102 LinkGraphLegendWindow(const WindowDesc *desc, int window_number);
00103 void SetOverlay(LinkGraphOverlay *overlay);
00104
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