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

Method DrawWidget

src/framerate_gui.cpp:859–973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

857 }
858
859 void DrawWidget(const Rect &r, WidgetID widget) const override
860 {
861 if (widget == WID_FGW_GRAPH) {
862 const auto &durations = _pf_data[this->element].durations;
863 const auto &timestamps = _pf_data[this->element].timestamps;
864 int point = _pf_data[this->element].prev_index;
865
866 const int x_zero = r.right - (int)this->graph_size.width;
867 const int x_max = r.right;
868 const int y_zero = r.top + (int)this->graph_size.height;
869 const int y_max = r.top;
870 const PixelColour c_grid = PC_DARK_GREY;
871 const PixelColour c_lines = PC_BLACK;
872 const PixelColour c_peak = PC_DARK_RED;
873
874 const TimingMeasurement draw_horz_scale = (TimingMeasurement)this->horizontal_scale * TIMESTAMP_PRECISION / 2;
875 const TimingMeasurement draw_vert_scale = (TimingMeasurement)this->vertical_scale;
876
877 /* Number of \c horizontal_scale units in each horizontal division */
878 const uint horz_div_scl = (this->horizontal_scale <= 20) ? 1 : 10;
879 /* Number of divisions of the horizontal axis */
880 const uint horz_divisions = this->horizontal_scale / horz_div_scl;
881 /* Number of divisions of the vertical axis */
882 const uint vert_divisions = 10;
883
884 /* Draw division lines and labels for the vertical axis */
885 for (uint division = 0; division < vert_divisions; division++) {
886 int y = Scinterlate(y_zero, y_max, 0, (int)vert_divisions, (int)division);
887 GfxDrawLine(x_zero, y, x_max, y, c_grid);
888 if (division % 2 == 0) {
889 if ((TimingMeasurement)this->vertical_scale > TIMESTAMP_PRECISION) {
890 DrawString(r.left, x_zero - WidgetDimensions::scaled.hsep_normal, y - GetCharacterHeight(FS_SMALL),
891 GetString(STR_FRAMERATE_GRAPH_SECONDS, this->vertical_scale * division / 10 / TIMESTAMP_PRECISION),
892 TC_GREY, SA_RIGHT | SA_FORCE, false, FS_SMALL);
893 } else {
894 DrawString(r.left, x_zero - WidgetDimensions::scaled.hsep_normal, y - GetCharacterHeight(FS_SMALL),
895 GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, this->vertical_scale * division / 10 * 1000 / TIMESTAMP_PRECISION),
896 TC_GREY, SA_RIGHT | SA_FORCE, false, FS_SMALL);
897 }
898 }
899 }
900 /* Draw division lines and labels for the horizontal axis */
901 for (uint division = horz_divisions; division > 0; division--) {
902 int x = Scinterlate(x_zero, x_max, 0, (int)horz_divisions, (int)horz_divisions - (int)division);
903 GfxDrawLine(x, y_max, x, y_zero, c_grid);
904 if (division % 2 == 0) {
905 DrawString(x, x_max, y_zero + WidgetDimensions::scaled.vsep_normal,
906 GetString(STR_FRAMERATE_GRAPH_SECONDS, division * horz_div_scl / 2),
907 TC_GREY, SA_LEFT | SA_FORCE, false, FS_SMALL);
908 }
909 }
910
911 /* Position of last rendered data point */
912 Point lastpoint = {
913 x_max,
914 (int)Scinterlate<int64_t>(y_zero, y_max, 0, this->vertical_scale, durations[point])
915 };
916 /* Timestamp of last rendered data point */

Callers

nothing calls this directly

Calls 6

GfxDrawLineFunction · 0.85
GetCharacterHeightFunction · 0.85
ToTextColourMethod · 0.80
DrawStringFunction · 0.70
GetStringFunction · 0.70
GfxFillRectFunction · 0.70

Tested by

no test coverage detected