MCPcopy Create free account
hub / github.com/ddnet/ddnet / RenderFilePreview

Method RenderFilePreview

src/game/editor/file_browser.cpp:530–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528}
529
530void CFileBrowser::RenderFilePreview(CUIRect Preview)
531{
532 if(m_FileType == CFileBrowser::EFileType::IMAGE)
533 {
534 if(m_PreviewState == EPreviewState::LOADED)
535 {
536 CUIRect PreviewLabel, PreviewImage;
537 Preview.HSplitTop(20.0f, &PreviewLabel, &PreviewImage);
538
539 char aSizeLabel[64];
540 str_format(aSizeLabel, sizeof(aSizeLabel), "Size: %d × %d", m_PreviewImageWidth, m_PreviewImageHeight);
541 Ui()->DoLabel(&PreviewLabel, aSizeLabel, 12.0f, TEXTALIGN_ML);
542
543 int Width = m_PreviewImageWidth;
544 int Height = m_PreviewImageHeight;
545 if(m_PreviewImageWidth > PreviewImage.w)
546 {
547 Height = m_PreviewImageHeight * PreviewImage.w / m_PreviewImageWidth;
548 Width = PreviewImage.w;
549 }
550 if(Height > PreviewImage.h)
551 {
552 Width = Width * PreviewImage.h / Height;
553 Height = PreviewImage.h;
554 }
555
556 Graphics()->TextureSet(m_PreviewImage);
557 Graphics()->BlendNormal();
558 Graphics()->QuadsBegin();
559 IGraphics::CQuadItem QuadItem(PreviewImage.x, PreviewImage.y, Width, Height);
560 Graphics()->QuadsDrawTL(&QuadItem, 1);
561 Graphics()->QuadsEnd();
562 }
563 else if(m_PreviewState == EPreviewState::ERROR)
564 {
565 Ui()->DoLabel(&Preview, "Failed to load the image (check the local console for details).", 12.0f, TEXTALIGN_TL, {.m_MaxWidth = Preview.w});
566 }
567 }
568 else if(m_FileType == CFileBrowser::EFileType::SOUND)
569 {
570 if(m_PreviewState == EPreviewState::LOADED)
571 {
572 Preview.HSplitTop(20.0f, &Preview, nullptr);
573 Preview.VSplitLeft(Preview.h / 4.0f, nullptr, &Preview);
574 Editor()->DoAudioPreview(Preview, &m_ButtonPlayPauseId, &m_ButtonStopId, &m_SeekBarId, m_PreviewSound);
575 }
576 else if(m_PreviewState == EPreviewState::ERROR)
577 {
578 Ui()->DoLabel(&Preview, "Failed to load the sound (check the local console for details). Make sure you enabled sounds in the settings.", 12.0f, TEXTALIGN_TL, {.m_MaxWidth = Preview.w});
579 }
580 }
581}
582
583const char *CFileBrowser::DetermineFileFontIcon(const CFilelistItem *pItem) const
584{

Callers

nothing calls this directly

Calls 12

str_formatFunction · 0.85
UiFunction · 0.85
GraphicsFunction · 0.85
HSplitTopMethod · 0.80
DoLabelMethod · 0.80
TextureSetMethod · 0.80
BlendNormalMethod · 0.80
QuadsBeginMethod · 0.80
QuadsDrawTLMethod · 0.80
QuadsEndMethod · 0.80
VSplitLeftMethod · 0.80
DoAudioPreviewMethod · 0.80

Tested by

no test coverage detected