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

OpenTTD Source 14.0-beta3

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