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

Method DrawWidget

src/graph_gui.cpp:702–749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

700 }
701
702 void DrawWidget(const Rect &r, WidgetID widget) const override
703 {
704 switch (widget) {
705 case WID_GRAPH_GRAPH:
706 this->DrawGraph(r);
707 break;
708
709 case WID_GRAPH_RANGE_MATRIX: {
710 uint line_height = GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical();
711 uint index = 0;
712 Rect line = r.WithHeight(line_height);
713 for (const auto &str : this->ranges) {
714 bool lowered = !HasBit(this->excluded_range, index) && !HasBit(this->masked_range, index);
715
716 /* Redraw frame if lowered */
717 if (lowered) DrawFrameRect(line, COLOUR_BROWN, FrameFlag::Lowered);
718
719 const Rect text = line.Shrink(WidgetDimensions::scaled.framerect);
720 DrawString(text, str, (this->highlight_state && this->highlight_range == index) ? TC_WHITE : TC_BLACK, SA_CENTER, false, FS_SMALL);
721
722 if (HasBit(this->masked_range, index)) {
723 GfxFillRect(line.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(COLOUR_BROWN, SHADE_DARKER), FILLRECT_CHECKER);
724 }
725
726 line = line.Translate(0, line_height);
727 ++index;
728 }
729 break;
730 }
731
732 case WID_GRAPH_SCALE_MATRIX: {
733 uint line_height = GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical();
734 uint8_t selected_month_increment = this->scales[this->selected_scale].month_increment;
735 Rect line = r.WithHeight(line_height);
736 for (const auto &scale : this->scales) {
737 /* Redraw frame if selected */
738 if (selected_month_increment == scale.month_increment) DrawFrameRect(line, COLOUR_BROWN, FrameFlag::Lowered);
739
740 DrawString(line.Shrink(WidgetDimensions::scaled.framerect), scale.label, TC_BLACK, SA_CENTER, false, FS_SMALL);
741
742 line = line.Translate(0, line_height);
743 }
744 break;
745 }
746
747 default: break;
748 }
749 }
750
751 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
752 {

Callers

nothing calls this directly

Calls 11

DrawGraphMethod · 0.95
GetCharacterHeightFunction · 0.85
HasBitFunction · 0.85
GetColourGradientFunction · 0.85
VerticalMethod · 0.80
WithHeightMethod · 0.80
ShrinkMethod · 0.80
TranslateMethod · 0.80
DrawFrameRectFunction · 0.70
DrawStringFunction · 0.70
GfxFillRectFunction · 0.70

Tested by

no test coverage detected