OpenTTD Source: src/linkgraph/linkgraph_gui.cpp Source File

OpenTTD Source 13.2.1

linkgraph_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../window_gui.h"
12 #include "../window_func.h"
13 #include "../company_base.h"
14 #include "../company_gui.h"
15 #include "../date_func.h"
16 #include "../viewport_func.h"
17 #include "../zoom_func.h"
18 #include "../smallmap_gui.h"
19 #include "../core/geometry_func.hpp"
20 #include "../widgets/link_graph_legend_widget.h"
21
22 #include "table/strings.h"
23
24 #include "../safeguards.h"
25
30 const uint8 LinkGraphOverlay::LINK_COLOURS[][12] = {
31 {
32 0x0f, 0xd1, 0xd0, 0x57,
33 0x55, 0x53, 0xbf, 0xbd,
34 0xba, 0xb9, 0xb7, 0xb5
35 },
36 {
37 0x0f, 0xd1, 0xd0, 0x57,
38 0x55, 0x53, 0x96, 0x95,
39 0x94, 0x93, 0x92, 0x91
40 },
41 {
42 0x0f, 0x0b, 0x09, 0x07,
43 0x05, 0x03, 0xbf, 0xbd,
44 0xba, 0xb9, 0xb7, 0xb5
45 },
46 {
47 0x0f, 0x0b, 0x0a, 0x09,
48 0x08, 0x07, 0x06, 0x05,
49 0x04, 0x03, 0x02, 0x01
50 }
51 };
52
57 void LinkGraphOverlay::GetWidgetDpi(DrawPixelInfo *dpi) const
58 {
59 const NWidgetBase *wi = this->window->GetWidget<NWidgetBase>(this->widget_id);
60 dpi->left = dpi->top = 0;
61 dpi->width = wi->current_x;
62 dpi->height = wi->current_y;
63 }
64
68 void LinkGraphOverlay::RebuildCache()
69 {
70 this->cached_links.clear();
71 this->cached_stations.clear();
72 if (this->company_mask == 0) return;
73
74 DrawPixelInfo dpi;
75 this->GetWidgetDpi(&dpi);
76
77 for (const Station *sta : Station::Iterate()) {
78 if (sta->rect.IsEmpty()) continue;
79
80 Point pta = this->GetStationMiddle(sta);
81
82 StationID from = sta->index;
83 StationLinkMap &seen_links = this->cached_links[from];
84
85 uint supply = 0;
86 for (CargoID c : SetCargoBitIterator(this->cargo_mask)) {
87 if (!CargoSpec::Get(c)->IsValid()) continue;
88 if (!LinkGraph::IsValidID(sta->goods[c].link_graph)) continue;
89 const LinkGraph &lg = *LinkGraph::Get(sta->goods[c].link_graph);
90
91 ConstNode from_node = lg[sta->goods[c].node];
92 supply += lg.Monthly(from_node.Supply());
93 for (ConstEdgeIterator i = from_node.Begin(); i != from_node.End(); ++i) {
94 StationID to = lg[i->first].Station();
95 assert(from != to);
96 if (!Station::IsValidID(to) || seen_links.find(to) != seen_links.end()) {
97 continue;
98 }
99 const Station *stb = Station::Get(to);
100 assert(sta != stb);
101
102 /* Show links between stations of selected companies or "neutral" ones like oilrigs. */
103 if (stb->owner != OWNER_NONE && sta->owner != OWNER_NONE && !HasBit(this->company_mask, stb->owner)) continue;
104 if (stb->rect.IsEmpty()) continue;
105
106 if (!this->IsLinkVisible(pta, this->GetStationMiddle(stb), &dpi)) continue;
107
108 this->AddLinks(sta, stb);
109 seen_links[to]; // make sure it is created and marked as seen
110 }
111 }
112 if (this->IsPointVisible(pta, &dpi)) {
113 this->cached_stations.push_back(std::make_pair(from, supply));
114 }
115 }
116 }
117
125 inline bool LinkGraphOverlay::IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding) const
126 {
127 return pt.x > dpi->left - padding && pt.y > dpi->top - padding &&
128 pt.x < dpi->left + dpi->width + padding &&
129 pt.y < dpi->top + dpi->height + padding;
130 }
131
140 inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding) const
141 {
142 const int left = dpi->left - padding;
143 const int right = dpi->left + dpi->width + padding;
144 const int top = dpi->top - padding;
145 const int bottom = dpi->top + dpi->height + padding;
146
147 /*
148 * This method is an implementation of the Cohen-Sutherland line-clipping algorithm.
149 * See: https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm
150 */
151
152 const uint8 INSIDE = 0; // 0000
153 const uint8 LEFT = 1; // 0001
154 const uint8 RIGHT = 2; // 0010
155 const uint8 BOTTOM = 4; // 0100
156 const uint8 TOP = 8; // 1000
157
158 int x0 = pta.x;
159 int y0 = pta.y;
160 int x1 = ptb.x;
161 int y1 = ptb.y;
162
163 auto out_code = [&](int x, int y) -> uint8 {
164 uint8 out = INSIDE;
165 if (x < left) {
166 out |= LEFT;
167 } else if (x > right) {
168 out |= RIGHT;
169 }
170 if (y < top) {
171 out |= TOP;
172 } else if (y > bottom) {
173 out |= BOTTOM;
174 }
175 return out;
176 };
177
178 uint8 c0 = out_code(x0, y0);
179 uint8 c1 = out_code(x1, y1);
180
181 while (true) {
182 if (c0 == 0 || c1 == 0) return true;
183 if ((c0 & c1) != 0) return false;
184
185 if (c0 & TOP) { // point 0 is above the clip window
186 x0 = x0 + (int)(((int64) (x1 - x0)) * ((int64) (top - y0)) / ((int64) (y1 - y0)));
187 y0 = top;
188 } else if (c0 & BOTTOM) { // point 0 is below the clip window
189 x0 = x0 + (int)(((int64) (x1 - x0)) * ((int64) (bottom - y0)) / ((int64) (y1 - y0)));
190 y0 = bottom;
191 } else if (c0 & RIGHT) { // point 0 is to the right of clip window
192 y0 = y0 + (int)(((int64) (y1 - y0)) * ((int64) (right - x0)) / ((int64) (x1 - x0)));
193 x0 = right;
194 } else if (c0 & LEFT) { // point 0 is to the left of clip window
195 y0 = y0 + (int)(((int64) (y1 - y0)) * ((int64) (left - x0)) / ((int64) (x1 - x0)));
196 x0 = left;
197 }
198
199 c0 = out_code(x0, y0);
200 }
201
202 NOT_REACHED();
203 }
204
210 void LinkGraphOverlay::AddLinks(const Station *from, const Station *to)
211 {
212 for (CargoID c : SetCargoBitIterator(this->cargo_mask)) {
213 if (!CargoSpec::Get(c)->IsValid()) continue;
214 const GoodsEntry &ge = from->goods[c];
215 if (!LinkGraph::IsValidID(ge.link_graph) ||
216 ge.link_graph != to->goods[c].link_graph) {
217 continue;
218 }
219 const LinkGraph &lg = *LinkGraph::Get(ge.link_graph);
220 ConstEdge edge = lg[ge.node][to->goods[c].node];
221 if (edge.Capacity() > 0) {
222 this->AddStats(c, lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()),
223 ge.flows.GetFlowVia(to->index),
224 edge.TravelTime() / DAY_TICKS,
225 from->owner == OWNER_NONE || to->owner == OWNER_NONE,
226 this->cached_links[from->index][to->index]);
227 }
228 }
229 }
230
241 /* static */ void LinkGraphOverlay::AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, uint32 time, bool new_shared, LinkProperties &cargo)
242 {
243 /* multiply the numbers by 32 in order to avoid comparing to 0 too often. */
244 if (cargo.capacity == 0 ||
245 cargo.Usage() * 32 / (cargo.capacity + 1) < std::max(new_usg, new_plan) * 32 / (new_cap + 1)) {
246 cargo.cargo = new_cargo;
247 cargo.capacity = new_cap;
248 cargo.usage = new_usg;
249 cargo.planned = new_plan;
250 cargo.time = time;
251 }
252 if (new_shared) cargo.shared = true;
253 }
254
259 void LinkGraphOverlay::Draw(const DrawPixelInfo *dpi)
260 {
261 if (this->dirty) {
262 this->RebuildCache();
263 this->dirty = false;
264 }
265 this->DrawLinks(dpi);
266 this->DrawStationDots(dpi);
267 }
268
273 void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const
274 {
275 int width = ScaleGUITrad(this->scale);
276 for (LinkMap::const_iterator i(this->cached_links.begin()); i != this->cached_links.end(); ++i) {
277 if (!Station::IsValidID(i->first)) continue;
278 Point pta = this->GetStationMiddle(Station::Get(i->first));
279 for (StationLinkMap::const_iterator j(i->second.begin()); j != i->second.end(); ++j) {
280 if (!Station::IsValidID(j->first)) continue;
281 Point ptb = this->GetStationMiddle(Station::Get(j->first));
282 if (!this->IsLinkVisible(pta, ptb, dpi, width + 2)) continue;
283 this->DrawContent(pta, ptb, j->second);
284 }
285 }
286 }
287
294 void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const
295 {
296 uint usage_or_plan = std::min(cargo.capacity * 2 + 1, cargo.Usage());
297 int colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS[0]) / (cargo.capacity * 2 + 2)];
298 int width = ScaleGUITrad(this->scale);
299 int dash = cargo.shared ? width * 4 : 0;
300
301 /* Move line a bit 90° against its dominant direction to prevent it from
302 * being hidden below the grey line. */
303 int side = _settings_game.vehicle.road_side ? 1 : -1;
304 if (abs(pta.x - ptb.x) < abs(pta.y - ptb.y)) {
305 int offset_x = (pta.y > ptb.y ? 1 : -1) * side * width;
306 GfxDrawLine(pta.x + offset_x, pta.y, ptb.x + offset_x, ptb.y, colour, width, dash);
307 } else {
308 int offset_y = (pta.x < ptb.x ? 1 : -1) * side * width;
309 GfxDrawLine(pta.x, pta.y + offset_y, ptb.x, ptb.y + offset_y, colour, width, dash);
310 }
311
312 GfxDrawLine(pta.x, pta.y, ptb.x, ptb.y, _colour_gradient[COLOUR_GREY][1], width);
313 }
314
319 void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
320 {
321 int width = ScaleGUITrad(this->scale);
322 for (StationSupplyList::const_iterator i(this->cached_stations.begin()); i != this->cached_stations.end(); ++i) {
323 const Station *st = Station::GetIfValid(i->first);
324 if (st == nullptr) continue;
325 Point pt = this->GetStationMiddle(st);
326 if (!this->IsPointVisible(pt, dpi, 3 * width)) continue;
327
328 uint r = width * 2 + width * 2 * std::min(200U, i->second) / 200;
329
330 LinkGraphOverlay::DrawVertex(pt.x, pt.y, r,
331 _colour_gradient[st->owner != OWNER_NONE ?
332 (Colours)Company::Get(st->owner)->colour : COLOUR_GREY][5],
333 _colour_gradient[COLOUR_GREY][1]);
334 }
335 }
336
345 /* static */ void LinkGraphOverlay::DrawVertex(int x, int y, int size, int colour, int border_colour)
346 {
347 size--;
348 int w1 = size / 2;
349 int w2 = size / 2 + size % 2;
350
351 GfxFillRect(x - w1, y - w1, x + w2, y + w2, colour);
352
353 w1++;
354 w2++;
355 GfxDrawLine(x - w1, y - w1, x + w2, y - w1, border_colour);
356 GfxDrawLine(x - w1, y + w2, x + w2, y + w2, border_colour);
357 GfxDrawLine(x - w1, y - w1, x - w1, y + w2, border_colour);
358 GfxDrawLine(x + w2, y - w1, x + w2, y + w2, border_colour);
359 }
360
361 bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond)
362 {
363 for (auto i(this->cached_links.crbegin()); i != this->cached_links.crend(); ++i) {
364 if (!Station::IsValidID(i->first)) continue;
365 Point pta = this->GetStationMiddle(Station::Get(i->first));
366 for (auto j(i->second.crbegin()); j != i->second.crend(); ++j) {
367 if (!Station::IsValidID(j->first)) continue;
368 if (i->first == j->first) continue;
369
370 /* Check the distance from the cursor to the line defined by the two stations. */
371 Point ptb = this->GetStationMiddle(Station::Get(j->first));
372 float dist = std::abs((ptb.x - pta.x) * (pta.y - pt.y) - (pta.x - pt.x) * (ptb.y - pta.y)) /
373 std::sqrt((ptb.x - pta.x) * (ptb.x - pta.x) + (ptb.y - pta.y) * (ptb.y - pta.y));
374 const auto &link = j->second;
375 if (dist <= 4 && link.Usage() > 0 &&
376 pt.x >= std::min(pta.x, ptb.x) &&
377 pt.x <= std::max(pta.x, ptb.x)) {
378 static char buf[1024];
379 char *buf_end = buf;
380 buf[0] = 0;
381 /* Fill buf with more information if this is a bidirectional link. */
382 uint32 back_time = 0;
383 auto k = this->cached_links[j->first].find(i->first);
384 if (k != this->cached_links[j->first].end()) {
385 const auto &back = k->second;
386 back_time = back.time;
387 if (back.Usage() > 0) {
388 SetDParam(0, back.cargo);
389 SetDParam(1, back.Usage());
390 SetDParam(2, back.Usage() * 100 / (back.capacity + 1));
391 buf_end = GetString(buf, STR_LINKGRAPH_STATS_TOOLTIP_RETURN_EXTENSION, lastof(buf));
392 }
393 }
394 /* Add information about the travel time if known. */
395 const auto time = link.time ? back_time ? ((link.time + back_time) / 2) : link.time : back_time;
396 if (time > 0) {
397 SetDParam(0, time);
398 buf_end = GetString(buf_end, STR_LINKGRAPH_STATS_TOOLTIP_TIME_EXTENSION, lastof(buf));
399 }
400 SetDParam(0, link.cargo);
401 SetDParam(1, link.Usage());
402 SetDParam(2, i->first);
403 SetDParam(3, j->first);
404 SetDParam(4, link.Usage() * 100 / (link.capacity + 1));
405 SetDParamStr(5, buf);
406 GuiShowTooltips(this->window, STR_LINKGRAPH_STATS_TOOLTIP, 7, nullptr, close_cond);
407 return true;
408 }
409 }
410 }
411 GuiShowTooltips(this->window, STR_NULL, 0, nullptr, close_cond);
412 return false;
413 }
414
420 Point LinkGraphOverlay::GetStationMiddle(const Station *st) const
421 {
422 if (this->window->viewport != nullptr) {
423 return GetViewportStationMiddle(this->window->viewport, st);
424 } else {
425 /* assume this is a smallmap */
426 return static_cast<const SmallMapWindow *>(this->window)->GetStationMiddle(st);
427 }
428 }
429
434 void LinkGraphOverlay::SetCargoMask(CargoTypes cargo_mask)
435 {
436 this->cargo_mask = cargo_mask;
437 this->RebuildCache();
438 this->window->GetWidget<NWidgetBase>(this->widget_id)->SetDirty(this->window);
439 }
440
445 void LinkGraphOverlay::SetCompanyMask(uint32 company_mask)
446 {
447 this->company_mask = company_mask;
448 this->RebuildCache();
449 this->window->GetWidget<NWidgetBase>(this->widget_id)->SetDirty(this->window);
450 }
451
453 NWidgetBase *MakeCompanyButtonRowsLinkGraphGUI(int *biggest_index)
454 {
455 return MakeCompanyButtonRows(biggest_index, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST, COLOUR_GREY, 3, STR_NULL);
456 }
457
458 NWidgetBase *MakeSaturationLegendLinkGraphGUI(int *biggest_index)
459 {
460 NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
461 for (uint i = 0; i < lengthof(LinkGraphOverlay::LINK_COLOURS[0]); ++i) {
462 NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST);
463 wid->SetMinimalSize(50, 0);
464 wid->SetMinimalTextLines(1, 0, FS_SMALL);
465 wid->SetFill(1, 1);
466 wid->SetResize(0, 0);
467 panel->Add(wid);
468 }
469 *biggest_index = WID_LGL_SATURATION_LAST;
470 return panel;
471 }
472
473 NWidgetBase *MakeCargoesLegendLinkGraphGUI(int *biggest_index)
474 {
475 static const uint ENTRIES_PER_ROW = CeilDiv(NUM_CARGO, 5);
476 NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
477 NWidgetHorizontal *row = nullptr;
478 for (uint i = 0; i < NUM_CARGO; ++i) {
479 if (i % ENTRIES_PER_ROW == 0) {
480 if (row) panel->Add(row);
481 row = new NWidgetHorizontal(NC_EQUALSIZE);
482 }
483 NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST);
484 wid->SetMinimalSize(25, 0);
485 wid->SetMinimalTextLines(1, 0, FS_SMALL);
486 wid->SetFill(1, 1);
487 wid->SetResize(0, 0);
488 row->Add(wid);
489 }
490 /* Fill up last row */
491 for (uint i = 0; i < 4 - (NUM_CARGO - 1) % 5; ++i) {
492 NWidgetSpacer *spc = new NWidgetSpacer(25, 0);
493 spc->SetMinimalTextLines(1, 0, FS_SMALL);
494 spc->SetFill(1, 1);
495 spc->SetResize(0, 0);
496 row->Add(spc);
497 }
498 panel->Add(row);
499 *biggest_index = WID_LGL_CARGO_LAST;
500 return panel;
501 }
502
503
504 static const NWidgetPart _nested_linkgraph_legend_widgets[] = {
505 NWidget(NWID_HORIZONTAL),
506 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
507 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_LGL_CAPTION), SetDataTip(STR_LINKGRAPH_LEGEND_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
508 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
509 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
510 EndContainer(),
511 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
512 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect), SetPIP(0, WidgetDimensions::unscaled.framerect.Horizontal(), 0),
513 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_LGL_SATURATION),
514 NWidgetFunction(MakeSaturationLegendLinkGraphGUI),
515 EndContainer(),
516 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_LGL_COMPANIES),
517 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
518 NWidgetFunction(MakeCompanyButtonRowsLinkGraphGUI),
519 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_LGL_COMPANIES_ALL), SetDataTip(STR_LINKGRAPH_LEGEND_ALL, STR_NULL),
520 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_LGL_COMPANIES_NONE), SetDataTip(STR_LINKGRAPH_LEGEND_NONE, STR_NULL),
521 EndContainer(),
522 EndContainer(),
523 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_LGL_CARGOES),
524 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
525 NWidgetFunction(MakeCargoesLegendLinkGraphGUI),
526 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_LGL_CARGOES_ALL), SetDataTip(STR_LINKGRAPH_LEGEND_ALL, STR_NULL),
527 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_LGL_CARGOES_NONE), SetDataTip(STR_LINKGRAPH_LEGEND_NONE, STR_NULL),
528 EndContainer(),
529 EndContainer(),
530 EndContainer(),
531 EndContainer()
532 };
533
534 static_assert(WID_LGL_SATURATION_LAST - WID_LGL_SATURATION_FIRST ==
535 lengthof(LinkGraphOverlay::LINK_COLOURS[0]) - 1);
536
537 static WindowDesc _linkgraph_legend_desc(
538 WDP_AUTO, "toolbar_linkgraph", 0, 0,
539 WC_LINKGRAPH_LEGEND, WC_NONE,
540 0,
541 _nested_linkgraph_legend_widgets, lengthof(_nested_linkgraph_legend_widgets)
542 );
543
547 void ShowLinkGraphLegend()
548 {
549 AllocateWindowDescFront<LinkGraphLegendWindow>(&_linkgraph_legend_desc, 0);
550 }
551
552 LinkGraphLegendWindow::LinkGraphLegendWindow(WindowDesc *desc, int window_number) : Window(desc)
553 {
554 this->InitNested(window_number);
555 this->InvalidateData(0);
556 this->SetOverlay(FindWindowById(WC_MAIN_WINDOW, 0)->viewport->overlay);
557 }
558
563 void LinkGraphLegendWindow::SetOverlay(LinkGraphOverlay *overlay) {
564 this->overlay = overlay;
565 uint32 companies = this->overlay->GetCompanyMask();
566 for (uint c = 0; c < MAX_COMPANIES; c++) {
567 if (!this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) {
568 this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, HasBit(companies, c));
569 }
570 }
571 CargoTypes cargoes = this->overlay->GetCargoMask();
572 for (uint c = 0; c < NUM_CARGO; c++) {
573 if (!this->IsWidgetDisabled(WID_LGL_CARGO_FIRST + c)) {
574 this->SetWidgetLoweredState(WID_LGL_CARGO_FIRST + c, HasBit(cargoes, c));
575 }
576 }
577 }
578
579 void LinkGraphLegendWindow::UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
580 {
581 if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
582 StringID str = STR_NULL;
583 if (widget == WID_LGL_SATURATION_FIRST) {
584 str = STR_LINKGRAPH_LEGEND_UNUSED;
585 } else if (widget == WID_LGL_SATURATION_LAST) {
586 str = STR_LINKGRAPH_LEGEND_OVERLOADED;
587 } else if (widget == (WID_LGL_SATURATION_LAST + WID_LGL_SATURATION_FIRST) / 2) {
588 str = STR_LINKGRAPH_LEGEND_SATURATED;
589 }
590 if (str != STR_NULL) {
591 Dimension dim = GetStringBoundingBox(str);
592 dim.width += padding.width;
593 dim.height += padding.height;
594 *size = maxdim(*size, dim);
595 }
596 }
597 if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
598 CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST);
599 if (cargo->IsValid()) {
600 Dimension dim = GetStringBoundingBox(cargo->abbrev);
601 dim.width += padding.width;
602 dim.height += padding.height;
603 *size = maxdim(*size, dim);
604 }
605 }
606 }
607
608 void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
609 {
610 Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
611 if (this->IsWidgetLowered(widget)) br = br.Translate(WidgetDimensions::scaled.pressed, WidgetDimensions::scaled.pressed);
612 if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
613 if (this->IsWidgetDisabled(widget)) return;
614 CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);
615 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
616 DrawCompanyIcon(cid, CenterBounds(br.left, br.right, sprite_size.width), CenterBounds(br.top, br.bottom, sprite_size.height));
617 }
618 if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
619 uint8 colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST];
620 GfxFillRect(br, colour);
621 StringID str = STR_NULL;
622 if (widget == WID_LGL_SATURATION_FIRST) {
623 str = STR_LINKGRAPH_LEGEND_UNUSED;
624 } else if (widget == WID_LGL_SATURATION_LAST) {
625 str = STR_LINKGRAPH_LEGEND_OVERLOADED;
626 } else if (widget == (WID_LGL_SATURATION_LAST + WID_LGL_SATURATION_FIRST) / 2) {
627 str = STR_LINKGRAPH_LEGEND_SATURATED;
628 }
629 if (str != STR_NULL) {
630 DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, FONT_HEIGHT_SMALL), str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER);
631 }
632 }
633 if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
634 if (this->IsWidgetDisabled(widget)) return;
635 CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST);
636 GfxFillRect(br, cargo->legend_colour);
637 DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, FONT_HEIGHT_SMALL), cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), SA_HOR_CENTER);
638 }
639 }
640
641 bool LinkGraphLegendWindow::OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond)
642 {
643 if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
644 if (this->IsWidgetDisabled(widget)) {
645 GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, 0, nullptr, close_cond);
646 } else {
647 uint64 params[2];
648 CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);
649 params[0] = STR_LINKGRAPH_LEGEND_SELECT_COMPANIES;
650 params[1] = cid;
651 GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_COMPANY_TOOLTIP, 2, params, close_cond);
652 }
653 return true;
654 }
655 if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
656 if (this->IsWidgetDisabled(widget)) return false;
657 CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST);
658 uint64 params[1];
659 params[0] = cargo->name;
660 GuiShowTooltips(this, STR_BLACK_STRING, 1, params, close_cond);
661 return true;
662 }
663 return false;
664 }
665
669 void LinkGraphLegendWindow::UpdateOverlayCompanies()
670 {
671 uint32 mask = 0;
672 for (uint c = 0; c < MAX_COMPANIES; c++) {
673 if (this->IsWidgetDisabled(c + WID_LGL_COMPANY_FIRST)) continue;
674 if (!this->IsWidgetLowered(c + WID_LGL_COMPANY_FIRST)) continue;
675 SetBit(mask, c);
676 }
677 this->overlay->SetCompanyMask(mask);
678 }
679
683 void LinkGraphLegendWindow::UpdateOverlayCargoes()
684 {
685 CargoTypes mask = 0;
686 for (uint c = 0; c < NUM_CARGO; c++) {
687 if (this->IsWidgetDisabled(c + WID_LGL_CARGO_FIRST)) continue;
688 if (!this->IsWidgetLowered(c + WID_LGL_CARGO_FIRST)) continue;
689 SetBit(mask, c);
690 }
691 this->overlay->SetCargoMask(mask);
692 }
693
694 void LinkGraphLegendWindow::OnClick(Point pt, int widget, int click_count)
695 {
696 /* Check which button is clicked */
697 if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
698 if (!this->IsWidgetDisabled(widget)) {
699 this->ToggleWidgetLoweredState(widget);
700 this->UpdateOverlayCompanies();
701 }
702 } else if (widget == WID_LGL_COMPANIES_ALL || widget == WID_LGL_COMPANIES_NONE) {
703 for (uint c = 0; c < MAX_COMPANIES; c++) {
704 if (this->IsWidgetDisabled(c + WID_LGL_COMPANY_FIRST)) continue;
705 this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, widget == WID_LGL_COMPANIES_ALL);
706 }
707 this->UpdateOverlayCompanies();
708 this->SetDirty();
709 } else if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
710 if (!this->IsWidgetDisabled(widget)) {
711 this->ToggleWidgetLoweredState(widget);
712 this->UpdateOverlayCargoes();
713 }
714 } else if (widget == WID_LGL_CARGOES_ALL || widget == WID_LGL_CARGOES_NONE) {
715 for (uint c = 0; c < NUM_CARGO; c++) {
716 if (this->IsWidgetDisabled(c + WID_LGL_CARGO_FIRST)) continue;
717 this->SetWidgetLoweredState(WID_LGL_CARGO_FIRST + c, widget == WID_LGL_CARGOES_ALL);
718 }
719 this->UpdateOverlayCargoes();
720 }
721 this->SetDirty();
722 }
723
729 void LinkGraphLegendWindow::OnInvalidateData(int data, bool gui_scope)
730 {
731 /* Disable the companies who are not active */
732 for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
733 this->SetWidgetDisabledState(i + WID_LGL_COMPANY_FIRST, !Company::IsValidID(i));
734 }
735 for (CargoID i = 0; i < NUM_CARGO; i++) {
736 this->SetWidgetDisabledState(i + WID_LGL_CARGO_FIRST, !CargoSpec::Get(i)->IsValid());
737 }
738 }
WID_LGL_COMPANIES
@ WID_LGL_COMPANIES
Company selection widget.
Definition: link_graph_legend_widget.h:22
MakeCompanyButtonRows
NWidgetBase * MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:3323
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:278
LinkGraphOverlay::company_mask
uint32 company_mask
Bitmask of companies to be displayed.
Definition: linkgraph_gui.h:82
IsInsideMM
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:230
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:483
LinkGraphLegendWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: linkgraph_gui.cpp:579
LinkGraph::EdgeWrapper::Usage
uint Usage() const
Get edge's usage.
Definition: linkgraph.h:99
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1261
Pool::PoolItem<&_link_graph_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
FlowStatMap::GetFlowVia
uint GetFlowVia(StationID via) const
Get the sum of flows via a specific station from this FlowStatMap.
Definition: station_cmd.cpp:4681
LinkGraph
A connected component of a link graph.
Definition: linkgraph.h:39
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1143
LinkProperties::cargo
CargoID cargo
Cargo type of the link.
Definition: linkgraph_gui.h:31
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:1261
GetContrastColour
TextColour GetContrastColour(uint8 background, uint8 threshold)
Determine a contrasty text colour for a coloured background.
Definition: gfx.cpp:1432
LinkGraphLegendWindow::UpdateOverlayCompanies
void UpdateOverlayCompanies()
Update the overlay with the new company selection.
Definition: linkgraph_gui.cpp:669
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Station
Station data structure.
Definition: station_base.h:454
LinkGraph::EdgeWrapper::TravelTime
uint32 TravelTime() const
Get edge's average travel time.
Definition: linkgraph.h:105
LinkGraphOverlay::RebuildCache
void RebuildCache()
Rebuild the cache and recalculate which links and stations to be shown.
Definition: linkgraph_gui.cpp:68
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:255
NWidgetResizeBase::SetMinimalTextLines
void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:1106
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
LinkGraph::ConstNode
Constant node class.
Definition: linkgraph.h:345
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1161
LinkGraphLegendWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Invalidate the data of this window if the cargoes or companies have changed.
Definition: linkgraph_gui.cpp:729
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
NWidgetSpacer
Spacer widget.
Definition: widget_type.h:575
LinkGraphLegendWindow::OnTooltip
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition: linkgraph_gui.cpp:641
LinkGraphOverlay::GetCargoMask
CargoTypes GetCargoMask()
Get a bitmask of the currently shown cargoes.
Definition: linkgraph_gui.h:73
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:218
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
LinkGraphLegendWindow::UpdateOverlayCargoes
void UpdateOverlayCargoes()
Update the overlay with the new cargo selection.
Definition: linkgraph_gui.cpp:683
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
SpecializedStation< Station, false >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Definition: base_station_base.h:209
VehicleSettings::road_side
byte road_side
the side of the road vehicles drive on
Definition: settings_type.h:504
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:62
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:55
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
SmallMapWindow
Class managing the smallmap window.
Definition: smallmap_gui.h:52
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
LinkGraph::EdgeWrapper
Wrapper for an edge (const or not) allowing retrieval, but no modification.
Definition: linkgraph.h:77
LinkGraphOverlay::SetCompanyMask
void SetCompanyMask(uint32 company_mask)
Set a new company mask and rebuild the cache.
Definition: linkgraph_gui.cpp:445
LinkGraphOverlay::window
Window * window
Window to be drawn into.
Definition: linkgraph_gui.h:79
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:269
LinkProperties::time
uint32 time
Travel time of the link.
Definition: linkgraph_gui.h:35
WindowDesc
High level window description.
Definition: window_gui.h:102
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
LinkGraphOverlay::cached_links
LinkMap cached_links
Cache for links to reduce recalculation.
Definition: linkgraph_gui.h:83
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:469
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:865
LinkGraphOverlay::cached_stations
StationSupplyList cached_stations
Cache for stations to be drawn.
Definition: linkgraph_gui.h:84
LinkGraphOverlay
Handles drawing of links into some window.
Definition: linkgraph_gui.h:43
LinkGraphOverlay::LINK_COLOURS
static const uint8 LINK_COLOURS[][12]
Colours for the various "load" states of links.
Definition: linkgraph_gui.h:49
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:329
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition: misc_gui.cpp:773
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:168
LinkGraphOverlay::SetCargoMask
void SetCargoMask(CargoTypes cargo_mask)
Set a new cargo mask and rebuild the cache.
Definition: linkgraph_gui.cpp:434
LinkGraphOverlay::AddLinks
void AddLinks(const Station *sta, const Station *stb)
Add all "interesting" links between the given stations to the cache.
Definition: linkgraph_gui.cpp:210
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:75
LinkGraphLegendWindow::SetOverlay
void SetOverlay(LinkGraphOverlay *overlay)
Set the overlay belonging to this menu and import its company/cargo settings.
Definition: linkgraph_gui.cpp:563
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:1130
CargoSpec::IsValid
bool IsValid() const
Tests for validity of this cargospec.
Definition: cargotype.h:99
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
WID_LGL_SATURATION
@ WID_LGL_SATURATION
Saturation legend.
Definition: link_graph_legend_widget.h:19
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
WID_LGL_CAPTION
@ WID_LGL_CAPTION
Caption widget.
Definition: link_graph_legend_widget.h:18
GoodsEntry::node
NodeID node
ID of node in link graph referring to this goods entry.
Definition: station_base.h:255
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
LinkGraphOverlay::IsLinkVisible
bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding=0) const
Determine if a certain link crosses through the area given by the dpi with some lee way.
Definition: linkgraph_gui.cpp:140
LinkGraph::EdgeWrapper::Capacity
uint Capacity() const
Get edge's capacity.
Definition: linkgraph.h:93
LinkProperties::capacity
uint capacity
Capacity of the link.
Definition: linkgraph_gui.h:32
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:116
GoodsEntry::link_graph
LinkGraphID link_graph
Link graph this station belongs to.
Definition: station_base.h:254
WC_LINKGRAPH_LEGEND
@ WC_LINKGRAPH_LEGEND
Linkgraph legend; Window numbers:
Definition: window_type.h:674
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:197
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:335
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
NWidgetResizeBase::SetFill
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:1119
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:203
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:147
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
LinkGraphOverlay::scale
uint scale
Width of link lines.
Definition: linkgraph_gui.h:85
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:167
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
LinkGraphOverlay::dirty
bool dirty
Set if overlay should be rebuilt.
Definition: linkgraph_gui.h:86
LinkGraphOverlay::DrawStationDots
void DrawStationDots(const DrawPixelInfo *dpi) const
Draw dots for stations into the smallmap.
Definition: linkgraph_gui.cpp:319
NWidgetHorizontal
Horizontal container.
Definition: widget_type.h:500
LinkProperties::planned
uint planned
Planned usage of the link.
Definition: linkgraph_gui.h:34
GoodsEntry::flows
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:256
MakeCompanyButtonRowsLinkGraphGUI
NWidgetBase * MakeCompanyButtonRowsLinkGraphGUI(int *biggest_index)
Make a number of rows with buttons for each company for the linkgraph legend window.
Definition: linkgraph_gui.cpp:453
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
LinkGraphLegendWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: linkgraph_gui.cpp:608
LinkGraphOverlay::Draw
void Draw(const DrawPixelInfo *dpi)
Draw the linkgraph overlay or some part of it, in the area given.
Definition: linkgraph_gui.cpp:259
LinkGraphOverlay::GetStationMiddle
Point GetStationMiddle(const Station *st) const
Determine the middle of a station in the current window.
Definition: linkgraph_gui.cpp:420
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
LinkGraph::ConstEdgeIterator
An iterator for const edges.
Definition: linkgraph.h:315
LinkGraphLegendWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: linkgraph_gui.cpp:694
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:422
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
LinkGraphOverlay::IsPointVisible
bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding=0) const
Determine if a certain point is inside the given DPI, with some lee way.
Definition: linkgraph_gui.cpp:125
NWidgetVertical
Vertical container.
Definition: widget_type.h:523
LinkGraphOverlay::AddStats
static void AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_flow, uint32 time, bool new_shared, LinkProperties &cargo)
Add information from a given pair of link stat and flow stat to the given link properties.
Definition: linkgraph_gui.cpp:241
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:71
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:44
LinkProperties::usage
uint usage
Actual usage of the link.
Definition: linkgraph_gui.h:33
LinkProperties::shared
bool shared
If this is a shared link to be drawn dashed.
Definition: linkgraph_gui.h:36
CargoSpec::abbrev
StringID abbrev
Two letter abbreviation for this cargo type.
Definition: cargotype.h:75
ShowLinkGraphLegend
void ShowLinkGraphLegend()
Open a link graph legend window.
Definition: linkgraph_gui.cpp:547
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
LinkGraphOverlay::GetWidgetDpi
void GetWidgetDpi(DrawPixelInfo *dpi) const
Get a DPI for the widget we will be drawing to.
Definition: linkgraph_gui.cpp:57
LinkGraphOverlay::cargo_mask
CargoTypes cargo_mask
Bitmask of cargos to be displayed.
Definition: linkgraph_gui.h:81
LinkGraphOverlay::SetDirty
void SetDirty()
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
Definition: linkgraph_gui.h:70
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:178
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:392
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
WID_LGL_CARGOES
@ WID_LGL_CARGOES
Cargo selection widget.
Definition: link_graph_legend_widget.h:27
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
SpecializedStation< Station, false >::GetIfValid
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
Definition: base_station_base.h:227
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1191
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
LinkGraphOverlay::GetCompanyMask
uint32 GetCompanyMask()
Get a bitmask of the currently shown companies.
Definition: linkgraph_gui.h:76
GUISettings::linkgraph_colours
uint8 linkgraph_colours
linkgraph overlay colours
Definition: settings_type.h:121
LinkGraphOverlay::DrawContent
void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const
Draw one specific link.
Definition: linkgraph_gui.cpp:294
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:280
LinkGraphOverlay::widget_id
const uint widget_id
ID of Widget in Window to be drawn to.
Definition: linkgraph_gui.h:80
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:595
Window
Data structure for an opened window.
Definition: window_gui.h:213
Pool::PoolItem<&_link_graph_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
LinkGraphOverlay::DrawLinks
void DrawLinks(const DrawPixelInfo *dpi) const
Draw the cached links or part of them into the given area.
Definition: linkgraph_gui.cpp:273
NWidgetBackground
Nested widget with a child.
Definition: widget_type.h:591
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Window::IsWidgetDisabled
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:350
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
LinkGraph::ConstNode::End
ConstEdgeIterator End() const
Get an iterator pointing beyond the end of the edges array.
Definition: linkgraph.h:374
LinkGraphOverlay::DrawVertex
static void DrawVertex(int x, int y, int size, int colour, int border_colour)
Draw a square symbolizing a producer of cargo.
Definition: linkgraph_gui.cpp:345
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:196
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
LinkProperties::Usage
uint Usage() const
Return the usage of the link to display.
Definition: linkgraph_gui.h:29
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:1080
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:382
DAY_TICKS
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
LinkGraph::ConstNode::Begin
ConstEdgeIterator Begin() const
Get an iterator pointing to the start of the edges array.
Definition: linkgraph.h:368
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
LinkGraph::Monthly
uint Monthly(uint base) const
Scale a value to its monthly equivalent, based on last compression.
Definition: linkgraph.h:527
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
LinkGraph::NodeWrapper::Supply
uint Supply() const
Get supply of wrapped node.
Definition: linkgraph.h:153
LinkProperties
Monthly statistics for a link between two stations.
Definition: linkgraph_gui.h:25
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62