MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawGroupInfo

Method DrawGroupInfo

src/group_gui.cpp:341–402  ·  view source on GitHub ↗

* Draw a row in the group list. * @param r Rect to draw row in. * @param g_id Group to list. * @param indent Indentation level. * @param protection Whether autoreplace protection is set. * @param has_children Whether the group has children and should have a fold / unfold button. */

Source from the content-addressed store, hash-verified

339 * @param has_children Whether the group has children and should have a fold / unfold button.
340 */
341 void DrawGroupInfo(Rect r, GroupID g_id, uint16_t level_mask = 0, uint8_t indent = 0, bool protection = false, bool has_children = false) const
342 {
343 /* Highlight the group if a vehicle is dragged over it */
344 if (g_id == this->group_over) {
345 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(COLOUR_GREY, SHADE_LIGHTEST));
346 }
347
348 if (g_id == NEW_GROUP) return;
349
350 /* draw the selected group in white, else we draw it in black */
351 TextColour colour = g_id == this->vli.ToGroupID() ? TC_WHITE : TC_BLACK;
352 const GroupStatistics &stats = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype);
353 bool rtl = _current_text_dir == TD_RTL;
354
355 const int offset = (rtl ? -(int)this->column_size[VGC_FOLD].width : (int)this->column_size[VGC_FOLD].width) / 2;
356 const int level_width = rtl ? -WidgetDimensions::scaled.hsep_indent : WidgetDimensions::scaled.hsep_indent;
357 const PixelColour linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL);
358
359 r = r.Shrink(WidgetDimensions::scaled.framerect, RectPadding::zero);
360 if (indent > 0) {
361 /* Draw tree continuation lines. */
362 int tx = (rtl ? r.right : r.left) + offset;
363 for (uint lvl = 1; lvl <= indent; ++lvl) {
364 if (HasBit(level_mask, lvl)) GfxDrawLine(tx, r.top, tx, r.bottom, linecolour, WidgetDimensions::scaled.fullbevel.top);
365 if (lvl < indent) tx += level_width;
366 }
367 /* Draw our node in the tree. */
368 int ycentre = CentreBounds(r.top, r.bottom, WidgetDimensions::scaled.fullbevel.top);
369 if (!HasBit(level_mask, indent)) GfxDrawLine(tx, r.top, tx, ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top);
370 GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top);
371 }
372
373 /* draw fold / unfold button */
374 if (has_children) {
375 DrawSpriteIgnorePadding(Group::Get(g_id)->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, r.WithX(this->column_rects[VGC_FOLD]).Translate(indent * level_width, 0), SA_CENTER);
376 }
377
378 /* draw group name */
379 DrawString(r.WithX(this->column_rects[VGC_NAME]).Indent(indent * WidgetDimensions::scaled.hsep_indent, rtl).CentreToHeight(this->column_size[VGC_NAME].height), this->GetGroupNameString(g_id), colour);
380
381 /* draw autoreplace protection */
382 if (protection) {
383 DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, r.WithX(this->column_rects[VGC_PROTECT]), SA_CENTER);
384 }
385
386 /* draw autoreplace status */
387 if (stats.autoreplace_defined) {
388 DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, stats.autoreplace_finished ? PALETTE_CRASH : PAL_NONE, r.WithX(this->column_rects[VGC_AUTOREPLACE]), SA_CENTER);
389 }
390
391 /* draw the profit icon */
392 DrawSpriteIgnorePadding(this->GetGroupProfitSpriteID(g_id), PAL_NONE, r.WithX(this->column_rects[VGC_PROFIT]), SA_CENTER);
393
394 /* draw the number of vehicles of the group */
395 int num_vehicle_with_subgroups = GetGroupNumVehicle(this->vli.company, g_id, this->vli.vtype);
396 int num_vehicle = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype).num_vehicle;
397 if (IsAllGroupID(g_id) || IsDefaultGroupID(g_id) || num_vehicle_with_subgroups == num_vehicle) {
398 DrawString(r.WithX(this->column_rects[VGC_NUMBER]).CentreToHeight(this->column_size[VGC_NUMBER].height), GetString(STR_JUST_COMMA, num_vehicle), colour, SA_RIGHT | SA_FORCE, false, FS_SMALL);

Callers

nothing calls this directly

Calls 15

GetGroupNameStringMethod · 0.95
GetColourGradientFunction · 0.85
HasBitFunction · 0.85
GfxDrawLineFunction · 0.85
CentreBoundsFunction · 0.85
DrawSpriteIgnorePaddingFunction · 0.85
GetGroupNumVehicleFunction · 0.85
IsAllGroupIDFunction · 0.85
IsDefaultGroupIDFunction · 0.85
ShrinkMethod · 0.80
ToGroupIDMethod · 0.80

Tested by

no test coverage detected