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

Method AddImage

src/game/editor/editor.cpp:3795–3846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3793}
3794
3795bool CEditor::AddImage(const char *pFilename, int StorageType, void *pUser)
3796{
3797 CEditor *pEditor = (CEditor *)pUser;
3798
3799 // check if we have that image already
3800 char aBuf[128];
3801 IStorage::StripPathAndExtension(pFilename, aBuf, sizeof(aBuf));
3802 for(const auto &pImage : pEditor->Map()->m_vpImages)
3803 {
3804 if(!str_comp(pImage->m_aName, aBuf))
3805 {
3806 pEditor->ShowFileDialogError("Image named '%s' was already added.", pImage->m_aName);
3807 return false;
3808 }
3809 }
3810
3811 if(pEditor->Map()->m_vpImages.size() >= MAX_MAPIMAGES)
3812 {
3813 pEditor->m_PopupEventType = POPEVENT_IMAGE_MAX;
3814 pEditor->m_PopupEventActivated = true;
3815 return false;
3816 }
3817
3818 CImageInfo ImgInfo;
3819 if(!pEditor->Graphics()->LoadPng(ImgInfo, pFilename, StorageType))
3820 {
3821 pEditor->ShowFileDialogError("Failed to load image from file '%s'.", pFilename);
3822 return false;
3823 }
3824
3825 std::shared_ptr<CEditorImage> pImg = std::make_shared<CEditorImage>(pEditor->Map());
3826 pImg->m_Width = ImgInfo.m_Width;
3827 pImg->m_Height = ImgInfo.m_Height;
3828 pImg->m_Format = ImgInfo.m_Format;
3829 pImg->m_pData = ImgInfo.m_pData;
3830 pImg->m_External = IsVanillaImage(aBuf);
3831
3832 ConvertToRgba(*pImg);
3833 DilateImage(*pImg);
3834
3835 int TextureLoadFlag = pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE;
3836 if(pImg->m_Width % 16 != 0 || pImg->m_Height % 16 != 0)
3837 TextureLoadFlag = 0;
3838 pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(*pImg, TextureLoadFlag, pFilename);
3839 str_copy(pImg->m_aName, aBuf);
3840 pImg->m_AutoMapper.Load(pImg->m_aName);
3841 pEditor->Map()->m_vpImages.push_back(pImg);
3842 pEditor->Map()->SortImages();
3843 pEditor->Map()->SelectImage(pImg);
3844 pEditor->OnDialogClose();
3845 return true;
3846}
3847
3848bool CEditor::AddSound(const char *pFilename, int StorageType, void *pUser)
3849{

Callers

nothing calls this directly

Calls 15

str_compFunction · 0.85
ConvertToRgbaFunction · 0.85
DilateImageFunction · 0.85
ShowFileDialogErrorMethod · 0.80
LoadTextureRawMethod · 0.80
SortImagesMethod · 0.80
SelectImageMethod · 0.80
str_copyFunction · 0.50
MapMethod · 0.45
LoadPngMethod · 0.45
GraphicsMethod · 0.45

Tested by

no test coverage detected