12 #include "../stdafx.h"
13 #include "../window_gui.h"
14 #include "../window_func.h"
15 #include "../company_base.h"
16 #include "../company_gui.h"
17 #include "../date_func.h"
18 #include "../viewport_func.h"
19 #include "../smallmap_gui.h"
20 #include "../core/geometry_func.hpp"
21 #include "../widgets/link_graph_legend_widget.h"
23 #include "table/strings.h"
25 #include "../safeguards.h"
32 0x0f, 0xd1, 0xd0, 0x57,
33 0x55, 0x53, 0xbf, 0xbd,
34 0xba, 0xb9, 0xb7, 0xb5
44 dpi->left = dpi->top = 0;
62 FOR_ALL_STATIONS(sta) {
63 if (sta->
rect.IsEmpty())
continue;
67 StationID from = sta->
index;
80 StationID to = lg[i->first].Station();
90 if (stb->
rect.IsEmpty())
continue;
113 return pt.x > dpi->left - padding && pt.y > dpi->top - padding &&
114 pt.x < dpi->left + dpi->width + padding &&
115 pt.y < dpi->top + dpi->height + padding;
128 return !((pta.x < dpi->left - padding && ptb.x < dpi->left - padding) ||
129 (pta.y < dpi->top - padding && ptb.y < dpi->top - padding) ||
130 (pta.x > dpi->left + dpi->width + padding &&
131 ptb.x > dpi->left + dpi->width + padding) ||
132 (pta.y > dpi->top + dpi->height + padding &&
133 ptb.y > dpi->top + dpi->height + padding));
177 cargo.
usage = new_usg;
180 if (new_shared) cargo.
shared =
true;
202 for (StationLinkMap::const_iterator j(i->second.begin()); j != i->second.end(); ++j) {
226 if (
abs(pta.x - ptb.x) <
abs(pta.y - ptb.y)) {
227 int offset_x = (pta.y > ptb.y ? 1 : -1) * side * this->
scale;
228 GfxDrawLine(pta.x + offset_x, pta.y, ptb.x + offset_x, ptb.y, colour, this->scale, dash);
230 int offset_y = (pta.x < ptb.x ? 1 : -1) * side * this->
scale;
231 GfxDrawLine(pta.x, pta.y + offset_y, ptb.x, ptb.y + offset_y, colour, this->scale, dash);
234 GfxDrawLine(pta.x, pta.y, ptb.x, ptb.y,
_colour_gradient[COLOUR_GREY][1], this->scale);
245 if (st == NULL)
continue;
249 uint r = this->
scale * 2 + this->
scale * 2 *
min(200, i->second) / 200;
270 int w2 = size / 2 + size % 2;
272 GfxFillRect(x - w1, y - w1, x + w2, y + w2, colour);
276 GfxDrawLine(x - w1, y - w1, x + w2, y - w1, border_colour);
277 GfxDrawLine(x - w1, y + w2, x + w2, y + w2, border_colour);
278 GfxDrawLine(x - w1, y - w1, x - w1, y + w2, border_colour);
279 GfxDrawLine(x + w2, y - w1, x + w2, y + w2, border_colour);
322 return MakeCompanyButtonRows(biggest_index, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST, 3, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES);
325 NWidgetBase *MakeSaturationLegendLinkGraphGUI(
int *biggest_index)
335 *biggest_index = WID_LGL_SATURATION_LAST;
339 NWidgetBase *MakeCargoesLegendLinkGraphGUI(
int *biggest_index)
345 if (i % ENTRIES_PER_ROW == 0) {
346 if (row) panel->
Add(row);
356 for (uint i = 0; i < 4 - (NUM_CARGO - 1) % 5; ++i) {
363 *biggest_index = WID_LGL_CARGO_LAST;
368 static const NWidgetPart _nested_linkgraph_legend_widgets[] = {
401 assert_compile(WID_LGL_SATURATION_LAST - WID_LGL_SATURATION_FIRST ==
405 WDP_AUTO,
"toolbar_linkgraph", 0, 0,
408 _nested_linkgraph_legend_widgets,
lengthof(_nested_linkgraph_legend_widgets)
416 AllocateWindowDescFront<LinkGraphLegendWindow>(&_linkgraph_legend_desc, 0);
419 LinkGraphLegendWindow::LinkGraphLegendWindow(
WindowDesc *desc,
int window_number) :
Window(desc)
421 this->InitNested(window_number);
422 this->InvalidateData(0);
431 this->overlay = overlay;
448 if (
IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
450 if (widget == WID_LGL_SATURATION_FIRST) {
451 str = STR_LINKGRAPH_LEGEND_UNUSED;
452 }
else if (widget == WID_LGL_SATURATION_LAST) {
453 str = STR_LINKGRAPH_LEGEND_OVERLOADED;
454 }
else if (widget == (WID_LGL_SATURATION_LAST + WID_LGL_SATURATION_FIRST) / 2) {
455 str = STR_LINKGRAPH_LEGEND_SATURATED;
457 if (str != STR_NULL) {
461 *size =
maxdim(*size, dim);
464 if (
IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
470 *size =
maxdim(*size, dim);
477 if (
IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
481 DrawCompanyIcon(cid, (r.left + r.right + 1 - sprite_size.width) / 2, (r.top + r.bottom + 1 - sprite_size.height) / 2);
483 if (
IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
486 if (widget == WID_LGL_SATURATION_FIRST) {
487 str = STR_LINKGRAPH_LEGEND_UNUSED;
488 }
else if (widget == WID_LGL_SATURATION_LAST) {
489 str = STR_LINKGRAPH_LEGEND_OVERLOADED;
490 }
else if (widget == (WID_LGL_SATURATION_LAST + WID_LGL_SATURATION_FIRST) / 2) {
491 str = STR_LINKGRAPH_LEGEND_SATURATED;
495 if (
IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
498 GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, cargo->legend_colour);
534 if (
IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
539 }
else if (widget == WID_LGL_COMPANIES_ALL || widget == WID_LGL_COMPANIES_NONE) {
546 }
else if (
IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
551 }
else if (widget == WID_LGL_CARGOES_ALL || widget == WID_LGL_CARGOES_NONE) {