| 198 | } |
| 199 | |
| 200 | void DrawWidget(const Rect &r, WidgetID widget) const override |
| 201 | { |
| 202 | switch (widget) { |
| 203 | case WID_BO_OBJECT_SPRITE: { |
| 204 | const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class); |
| 205 | const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type); |
| 206 | if (spec == nullptr) break; |
| 207 | |
| 208 | const NWidgetMatrix *matrix = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>(); |
| 209 | |
| 210 | DrawPixelInfo tmp_dpi; |
| 211 | /* Set up a clipping area for the preview. */ |
| 212 | Rect ir = r.Shrink(WidgetDimensions::scaled.bevel); |
| 213 | if (FillDrawPixelInfo(&tmp_dpi, ir)) { |
| 214 | AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); |
| 215 | int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT); |
| 216 | int y = (ir.Height() + ScaleSpriteTrad(PREVIEW_HEIGHT)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM); |
| 217 | |
| 218 | if (!spec->grf_prop.HasGrfFile()) { |
| 219 | extern const DrawTileSpriteSpan _objects[]; |
| 220 | const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id]; |
| 221 | DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE); |
| 222 | } else { |
| 223 | DrawNewObjectTileInGUI(x, y, spec, matrix->GetCurrentElement()); |
| 224 | } |
| 225 | } |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | case WID_BO_INFO: { |
| 230 | const ObjectClass *objclass = ObjectClass::Get(_object_gui.sel_class); |
| 231 | const ObjectSpec *spec = objclass->GetSpec(_object_gui.sel_type); |
| 232 | if (spec == nullptr) break; |
| 233 | |
| 234 | Rect tr = r; |
| 235 | const int bottom = tr.bottom; |
| 236 | /* Use all the available space past the rect, so that we can enlarge the window if needed. */ |
| 237 | tr.bottom = INT16_MAX; |
| 238 | tr.top = DrawBadgeNameList(tr, spec->badges, GSF_OBJECTS); |
| 239 | |
| 240 | /* Get the extra message for the GUI */ |
| 241 | if (spec->callback_mask.Test(ObjectCallbackMask::FundMoreText)) { |
| 242 | std::array<int32_t, 16> regs100; |
| 243 | uint16_t callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, nullptr, INVALID_TILE, regs100, _object_gui.sel_view); |
| 244 | if (callback_res != CALLBACK_FAILED && callback_res != 0x400) { |
| 245 | std::string str; |
| 246 | if (callback_res == 0x40F) { |
| 247 | str = GetGRFStringWithTextStack(spec->grf_prop.grffile, static_cast<GRFStringID>(regs100[0]), std::span{regs100}.subspan(1)); |
| 248 | } else if (callback_res > 0x400) { |
| 249 | ErrorUnknownCallbackResult(spec->grf_prop.grfid, CBID_OBJECT_FUND_MORE_TEXT, callback_res); |
| 250 | } else { |
| 251 | str = GetGRFStringWithTextStack(spec->grf_prop.grffile, GRFSTR_MISC_GRF_TEXT + callback_res, regs100); |
| 252 | } |
| 253 | if (!str.empty()) { |
| 254 | tr.top = DrawStringMultiLine(tr, str, TC_ORANGE); |
| 255 | } |
| 256 | } |
| 257 | } |
nothing calls this directly
no test coverage detected