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/linkgraph.h"
00019 #include <map>
00020 #include <list>
00021
00025 struct LinkProperties {
00026 LinkProperties() : capacity(0), usage(0), planned(0) {}
00027
00028 uint capacity;
00029 uint usage;
00030 uint planned;
00031 };
00032
00037 class LinkGraphOverlay {
00038 public:
00039 typedef std::map<StationID, LinkProperties> StationLinkMap;
00040 typedef std::map<StationID, StationLinkMap> LinkMap;
00041 typedef std::list<std::pair<StationID, uint> > StationSupplyList;
00042
00043 static const uint8 LINK_COLOURS[];
00044
00053 LinkGraphOverlay(const Window *w, uint wid, uint32 cargo_mask = 0xFFFFFFFF,
00054 uint32 company_mask = 1 << _local_company, uint scale = 1) :
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, 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(const WindowDesc *desc, int window_number);
00101 void SetOverlay(LinkGraphOverlay *overlay);
00102
00103 virtual void DrawWidget(const Rect &r, int widget) const;
00104 virtual void OnClick(Point pt, int widget, int click_count);
00105 virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
00106
00107 private:
00108 LinkGraphOverlay *overlay;
00109
00110 void UpdateOverlayCompanies();
00111 void UpdateOverlayCargoes();
00112 };
00113
00114 #endif