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

Method DrawWidget

src/newgrf_debug_gui.cpp:901–958  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

899 }
900
901 void DrawWidget(const Rect &r, WidgetID widget) const override
902 {
903 switch (widget) {
904 case WID_SA_SPRITE: {
905 /* Center the sprite ourselves */
906 const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
907 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
908 int x;
909 int y;
910 if (SpriteAlignerWindow::centre) {
911 x = -UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom) + (ir.Width() - UnScaleByZoom(spr->width, SpriteAlignerWindow::zoom)) / 2;
912 y = -UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom) + (ir.Height() - UnScaleByZoom(spr->height, SpriteAlignerWindow::zoom)) / 2;
913 } else {
914 x = ir.Width() / 2;
915 y = ir.Height() / 2;
916 }
917
918 DrawPixelInfo new_dpi;
919 if (!FillDrawPixelInfo(&new_dpi, ir)) break;
920 AutoRestoreBackup dpi_backup(_cur_dpi, &new_dpi);
921
922 DrawSprite(this->current_sprite, PAL_NONE, x, y, nullptr, SpriteAlignerWindow::zoom);
923
924 Rect outline = {0, 0, UnScaleByZoom(spr->width, SpriteAlignerWindow::zoom) - 1, UnScaleByZoom(spr->height, SpriteAlignerWindow::zoom) - 1};
925 outline = outline.Translate(x + UnScaleByZoom(spr->x_offs, SpriteAlignerWindow::zoom), y + UnScaleByZoom(spr->y_offs, SpriteAlignerWindow::zoom));
926 DrawRectOutline(outline.Expand(1), PC_LIGHT_BLUE, 1, 1);
927
928 if (SpriteAlignerWindow::crosshair) {
929 GfxDrawLine(x, 0, x, ir.Height() - 1, PC_WHITE, 1, 1);
930 GfxDrawLine(0, y, ir.Width() - 1, y, PC_WHITE, 1, 1);
931 }
932 break;
933 }
934
935 case WID_SA_LIST: {
936 /* Don't redraw sprite list while it is still being filled by picker. */
937 if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW) break;
938
939 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
940 int step_size = nwid->resize_y;
941
942 const FlatSet<SpriteID> &list = _newgrf_debug_sprite_picker.sprites;
943
944 Rect ir = r.Shrink(WidgetDimensions::scaled.matrix);
945 auto [first, last] = this->vscroll->GetVisibleRangeIterators(list);
946 for (auto it = first; it != last; ++it) {
947 const SpriteFile *file = GetOriginFile(*it);
948 if (file == nullptr) {
949 DrawString(ir, GetString(STR_JUST_COMMA, *it), *it == this->current_sprite ? TC_WHITE : (TC_GREY | TC_NO_SHADE), SA_RIGHT | SA_FORCE);
950 } else {
951 DrawString(ir, GetString(STR_SPRITE_ALIGNER_SPRITE, file->GetSimplifiedFilename(), GetSpriteLocalID(*it)), *it == this->current_sprite ? TC_WHITE : TC_BLACK);
952 }
953 ir.top += step_size;
954 }
955 break;
956 }
957 }
958 }

Callers

nothing calls this directly

Calls 15

GetSpriteFunction · 0.85
UnScaleByZoomFunction · 0.85
DrawSpriteFunction · 0.85
DrawRectOutlineFunction · 0.85
GfxDrawLineFunction · 0.85
GetOriginFileFunction · 0.85
GetSpriteLocalIDFunction · 0.85
ShrinkMethod · 0.80
TranslateMethod · 0.80
ExpandMethod · 0.80

Tested by

no test coverage detected