diff --git a/BeefLibs/Beefy2D/src/BFWindow.bf b/BeefLibs/Beefy2D/src/BFWindow.bf index 66793990..f5cbe2a5 100644 --- a/BeefLibs/Beefy2D/src/BFWindow.bf +++ b/BeefLibs/Beefy2D/src/BFWindow.bf @@ -110,7 +110,7 @@ namespace Beefy public virtual void PreDraw(Graphics g) { - g.PushDrawLayer(mDefaultDrawLayer); + g.PushDrawLayer(mDefaultDrawLayer); } public virtual void PostDraw(Graphics g) diff --git a/BeefLibs/Beefy2D/src/gfx/DrawLayer.bf b/BeefLibs/Beefy2D/src/gfx/DrawLayer.bf index ea9d6448..c4de0423 100644 --- a/BeefLibs/Beefy2D/src/gfx/DrawLayer.bf +++ b/BeefLibs/Beefy2D/src/gfx/DrawLayer.bf @@ -13,6 +13,8 @@ namespace Beefy.gfx #if !STUDIO_CLIENT public class DrawLayer { + public static List sDrawLayers = new .() ~ delete _; + [CallingConvention(.Stdcall), CLink] static extern void* DrawLayer_Create(void* window); @@ -33,10 +35,12 @@ namespace Beefy.gfx public this(BFWindow window) { mNativeDrawLayer = DrawLayer_Create((window != null) ? (window.mNativeWindow) : null); + sDrawLayers.Add(this); } public ~this() { + sDrawLayers.Remove(this); DrawLayer_Delete(mNativeDrawLayer); } diff --git a/BeefLibs/Beefy2D/src/gfx/Font.bf b/BeefLibs/Beefy2D/src/gfx/Font.bf index 888b5601..005c00b2 100644 --- a/BeefLibs/Beefy2D/src/gfx/Font.bf +++ b/BeefLibs/Beefy2D/src/gfx/Font.bf @@ -6,6 +6,7 @@ using Beefy.geom; using Beefy.utils; using System.Diagnostics; using System.Threading; +using res; namespace Beefy.gfx { @@ -515,6 +516,14 @@ namespace Beefy.gfx void GetFontPath(StringView fontName, String path) { + if (fontName.StartsWith('[')) + { + path.Set(fontName); + if (FilePackManager.TryMakeMemoryString(path)) + return; + path.Clear(); + } + if (fontName.Contains('.')) { Path.GetAbsolutePath(fontName, BFApp.sApp.mInstallDir, path); @@ -1014,6 +1023,8 @@ namespace Beefy.gfx } CharData charData = GetCharData(c); + if (charData == null) + continue; float drawX = curX + charData.mXOffset; float drawY = curY + charData.mYOffset; diff --git a/BeefLibs/Beefy2D/src/res/FilePack.bf b/BeefLibs/Beefy2D/src/res/FilePack.bf index 973ab024..1e48fcb7 100644 --- a/BeefLibs/Beefy2D/src/res/FilePack.bf +++ b/BeefLibs/Beefy2D/src/res/FilePack.bf @@ -561,9 +561,10 @@ static class FilePackManager { if (TryGetMemory(path) case .Ok(let val)) { + String prevPath = scope .()..Append(path); + var ext = Path.GetExtension(path, .. scope .()); - path.Set(scope $"@{(int)(void*)val.Ptr:X}:{val.Length}"); - path.Append(ext); + path.Set(scope $"@{(int)(void*)val.Ptr:X}:{val.Length}:{prevPath}"); return true; } return false; diff --git a/BeefLibs/Beefy2D/src/theme/dark/DarkButton.bf b/BeefLibs/Beefy2D/src/theme/dark/DarkButton.bf index 46e6e5ed..3f7b7e03 100644 --- a/BeefLibs/Beefy2D/src/theme/dark/DarkButton.bf +++ b/BeefLibs/Beefy2D/src/theme/dark/DarkButton.bf @@ -14,7 +14,7 @@ namespace Beefy.theme.dark public float mLabelYOfs; [DesignEditable(DefaultEditString=true)] - public String Label + public StringView Label { get { diff --git a/BeefLibs/Beefy2D/src/widgets/WidgetWindow.bf b/BeefLibs/Beefy2D/src/widgets/WidgetWindow.bf index 60e3e82a..f0f40ee3 100644 --- a/BeefLibs/Beefy2D/src/widgets/WidgetWindow.bf +++ b/BeefLibs/Beefy2D/src/widgets/WidgetWindow.bf @@ -69,6 +69,7 @@ namespace Beefy.widgets public bool mWantsUpdateF; public bool mTempWantsUpdateF; + public Image mContentRenderTarget ~ delete _; public int32 mContentClientWidth; public int32 mContentClientHeight; @@ -229,11 +230,31 @@ namespace Beefy.widgets public override void PreDraw(Graphics g) { base.PreDraw(g); + + if (mContentRenderTarget != null) + { + g.mMatrix.Set(Matrix.IdentityMatrix); + } + else + { + g.mMatrix.Set(mScaleMatrix); + } - g.mMatrix.Set(mScaleMatrix); g.mMatrixStack[g.mMatrixStackIdx] = g.mMatrix; } + public override void PostDraw(Graphics g) + { + base.PostDraw(g); + + if (mContentRenderTarget != null) + { + for (var drawLayer in DrawLayer.sDrawLayers) + drawLayer.DrawToRenderTarget(mContentRenderTarget); + g.DrawQuad(mContentRenderTarget, 0, 0, 0, 0, mClientWidth, mClientHeight, 1, 1); + } + } + public override void RehupSize() { base.RehupSize(); @@ -880,8 +901,14 @@ namespace Beefy.widgets mMouseFlags = default; } - public void SetContentSize(int width, int height) + public void SetContentSize(int width, int height, bool createRenderTarget = false) { + DeleteAndNullify!(mContentRenderTarget); + if (createRenderTarget) + { + mContentRenderTarget = Image.CreateRenderTarget((.)width, (.)height); + } + mContentClientWidth = (.)width; mContentClientHeight = (.)height; RehupSize(); diff --git a/BeefySysLib/BeefySysLib.cpp b/BeefySysLib/BeefySysLib.cpp index cd552817..1cba869e 100644 --- a/BeefySysLib/BeefySysLib.cpp +++ b/BeefySysLib/BeefySysLib.cpp @@ -446,10 +446,11 @@ BF_EXPORT int BF_CALLTYPE BFWindow_GetDPI(BFWindow* window) BF_EXPORT TextureSegment* BF_CALLTYPE Gfx_CreateRenderTarget(int width, int height, int destAlpha) { - Texture* texture = gBFApp->mRenderDevice->CreateRenderTarget(width, height, destAlpha != 0); + Texture* texture = gBFApp->mRenderDevice->CreateRenderTarget(width, height, destAlpha != 0); + texture->mResetClear = true; TextureSegment* aTextureSegment = new TextureSegment(); - aTextureSegment->InitFromTexture(texture); + aTextureSegment->InitFromTexture(texture); return aTextureSegment; } diff --git a/BeefySysLib/Common.cpp b/BeefySysLib/Common.cpp index 85fae5d5..a8dcb36c 100644 --- a/BeefySysLib/Common.cpp +++ b/BeefySysLib/Common.cpp @@ -1380,9 +1380,11 @@ void Beefy::BFFatalError(const char* message, const char* file, int line) BFFatalError(String(message), String(file), line); } -bool Beefy::ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize) +bool Beefy::ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize, StringImpl* outKey) { #ifndef BF_SMALL + static int anonymousIdx = 0; + if (str.StartsWith("@")) { int colon = (int)str.IndexOf(':'); @@ -1390,6 +1392,21 @@ bool Beefy::ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize) String lenStr = str.Substring(colon + 1); outPtr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16); outSize = (int)strtol(lenStr.c_str(), NULL, 10); + + if (outKey != NULL) + { + int nextColon = (int)str.IndexOf(':', colon + 1); + if (nextColon > 0) + { + *outKey = str.Substring(nextColon + 1); + } + else + { + int dotPos = (int)str.IndexOf('.', colon + 1); + *outKey = StrFormat("ANON_%d", anonymousIdx++) + str.Substring(dotPos); + } + } + return true; } #endif diff --git a/BeefySysLib/Common.h b/BeefySysLib/Common.h index adb6a07b..49a9c4c4 100644 --- a/BeefySysLib/Common.h +++ b/BeefySysLib/Common.h @@ -242,7 +242,7 @@ bool FileExists(const StringImpl& path, String* outActualName = NULL); bool DirectoryExists(const StringImpl& path, String* outActualName = NULL); bool RecursiveCreateDirectory(const StringImpl& dirName); bool RecursiveDeleteDirectory(const StringImpl& dirName); -bool ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize); +bool ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize, StringImpl* outKey = NULL); #define CHARTAG(val) FromBIGEndian(val) diff --git a/BeefySysLib/gfx/FTFont.cpp b/BeefySysLib/gfx/FTFont.cpp index 15821b2a..d783d76c 100644 --- a/BeefySysLib/gfx/FTFont.cpp +++ b/BeefySysLib/gfx/FTFont.cpp @@ -136,13 +136,18 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize) FTFontManager::Face* face = NULL; + String key = fileName; + void* memPtr = NULL; + int memLen = 0; + bool isMemory = ParseMemorySpan(fileName, memPtr, memLen, &key); + FTFontManager::Face** facePtr = NULL; - if (gFTFontManager.mFaces.TryAdd(fileName, NULL, &facePtr)) + if (gFTFontManager.mFaces.TryAdd(key, NULL, &facePtr)) { face = new FTFontManager::Face(); *facePtr = face; - face->mFileName = fileName; + face->mFileName = key; FT_Face ftFace = NULL; String useFileName = fileName; @@ -153,10 +158,8 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize) faceIdx = atoi(useFileName.c_str() + atPos + 1); useFileName.RemoveToEnd(atPos); } - - void* memPtr = NULL; - int memLen = 0; - if (ParseMemorySpan(fileName, memPtr, memLen)) + + if (isMemory) { FT_New_Memory_Face(gFTLibrary, (FT_Byte*)memPtr, memLen, faceIdx, &ftFace); } diff --git a/BeefySysLib/gfx/RenderDevice.cpp b/BeefySysLib/gfx/RenderDevice.cpp index 3eededbf..a33fe10b 100644 --- a/BeefySysLib/gfx/RenderDevice.cpp +++ b/BeefySysLib/gfx/RenderDevice.cpp @@ -34,6 +34,8 @@ RenderTarget::RenderTarget() mHasBeenDrawnTo = false; mHasBeenTargeted = false; mResizeNum = 0; + mWantsClear = true; + mResetClear = false; } RenderWindow::RenderWindow() diff --git a/BeefySysLib/gfx/RenderTarget.h b/BeefySysLib/gfx/RenderTarget.h index fb3435f6..ca2f31d4 100644 --- a/BeefySysLib/gfx/RenderTarget.h +++ b/BeefySysLib/gfx/RenderTarget.h @@ -12,6 +12,8 @@ public: int mResizeNum; bool mHasBeenTargeted; bool mHasBeenDrawnTo; + bool mWantsClear; + bool mResetClear; public: RenderTarget(); diff --git a/BeefySysLib/platform/win/DXRenderDevice.cpp b/BeefySysLib/platform/win/DXRenderDevice.cpp index 096265a7..7a9848cc 100644 --- a/BeefySysLib/platform/win/DXRenderDevice.cpp +++ b/BeefySysLib/platform/win/DXRenderDevice.cpp @@ -648,7 +648,7 @@ void DXTexture::PhysSetAsTarget() mRenderDevice->mD3DDeviceContext->RSSetViewports(1, &viewPort); } - //if (!mHasBeenDrawnTo) + if (mWantsClear) { float bgColor[4] = {1, (rand() % 256) / 256.0f, 0.5, 1}; mRenderDevice->mD3DDeviceContext->ClearRenderTargetView(mD3DRenderTargetView, bgColor); @@ -657,6 +657,8 @@ void DXTexture::PhysSetAsTarget() //mRenderDevice->mD3DDevice->ClearRenderTargetView(mD3DRenderTargetView, D3DXVECTOR4(1, 0.5, 0.5, 1)); mHasBeenDrawnTo = true; + if (mResetClear) + mWantsClear = false; } }