From a50047e190dd7c340d1f8599581fb7b83db5aee9 Mon Sep 17 00:00:00 2001 From: thebest12lines Date: Sat, 24 May 2025 08:43:58 +0600 Subject: [PATCH 1/2] v1.8.0 --- CHANGELOG.md | 6 ++ CMakeLists.txt | 6 +- src/api/cstyle/ReflectC.cpp | 10 +++ src/api/cstyle/ReflectC.h | 3 +- src/api/cstyle/ReflectCExtern.h | 2 + src/api/java/ReflectJava.c | 7 ++ src/api/java/ReflectJava.h | 7 ++ src/api/lua/ReflectLua.h | 6 +- src/common/TypeDefinitions.h | 6 ++ src/core/Main.cpp | 11 ++- src/core/Main.h | 1 + src/core/ReflectAPI.cpp | 21 +++++ src/core/ReflectAPI.h | 4 + src/core/ui/Container.cpp | 68 +++++++++++++-- src/core/ui/Container.h | 3 +- src/core/ui/Image.cpp | 17 ++-- src/core/ui/Label.cpp | 133 ++++++++++++++++++----------- src/core/ui/Label.h | 6 ++ src/core/ui/Window.cpp | 63 ++++++-------- src/core/xml/ProcessorRegistry.cpp | 75 ++++++++++++---- src/core/xml/ProcessorRegistry.h | 9 +- 21 files changed, 335 insertions(+), 129 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8558524..c7380cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.8.0 (2025-05-24) +- Added containers +- Added images +- Added more modular XML processors +- Bug fixes + # v1.7.0 (2025-05-15) - Added custom title bar (not accessible) - Renamed CinnamonToast to Reflect diff --git a/CMakeLists.txt b/CMakeLists.txt index 199c413..08282da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,11 +17,12 @@ if (POLICY CMP0141) endif() # Enable exceptions in MSVC if(MSVC) - add_compile_options(/EHsc /Zc:__cplusplus) + add_compile_options(/EHsc) endif() # Define the project set(TRIPLET "x64-windows") +set(VCPKG_TARGET_TRIPLET "x64-windows") project("cinnamontoast") set(CMAKE_GENERATOR_PLATFORM "x64") @@ -88,6 +89,7 @@ else() add_library(Reflect STATIC ${REFLECT_CSTYLE} ${REFLECT_CRASHHANDLER} ${REFLECT_LUA} + ${REFLECT_JAVA} ${REFLECT_NET} ${REFLECT_CORE} ${REFLECT_COMMONS_CORE} ) target_compile_definitions(Reflect PRIVATE REFLECT_STATIC_LIBRARY=1) @@ -183,7 +185,7 @@ if(DEFINED REFLECT_BUNDLE) target_link_libraries(Reflect PRIVATE tinyxml2::tinyxml2 GLEW::GLEW) target_link_libraries(Reflect PRIVATE ${LUAJIT_LIBRARIES}) - target_link_libraries(Reflect PRIVATE OpenSSL::SSL ws2_32) + target_link_libraries(Reflect PRIVATE OpenSSL::SSL OpenSSL::Crypto ws2_32) else() target_link_libraries(Reflect.CStyleAPI PRIVATE Reflect.Core) diff --git a/src/api/cstyle/ReflectC.cpp b/src/api/cstyle/ReflectC.cpp index 746a773..c839161 100644 --- a/src/api/cstyle/ReflectC.cpp +++ b/src/api/cstyle/ReflectC.cpp @@ -65,4 +65,14 @@ REFLECT_API bool Reflect_setFontSize(ReflectComponent comp, uint8_t fontSize) { // font color sizing??? external::setComponentFontSize(comp.id, fontSize); return true; +}; + +REFLECT_API bool Reflect_run(ReflectComponent comp) { + external::run(comp.id); + return true; +}; + +REFLECT_API bool Reflect_invoke(const char *location) { + external::invoke(location); + return true; }; \ No newline at end of file diff --git a/src/api/cstyle/ReflectC.h b/src/api/cstyle/ReflectC.h index d927169..d8c91d6 100644 --- a/src/api/cstyle/ReflectC.h +++ b/src/api/cstyle/ReflectC.h @@ -161,7 +161,8 @@ REFLECT_API bool Reflect_setFont(ReflectComponent comp, ReflectString font); * @return true if successful, false otherwise. */ REFLECT_API bool Reflect_setFontSize(ReflectComponent comp, uint8_t fontSize); - +REFLECT_API bool Reflect_invoke(const char *location); +REFLECT_API bool Reflect_run(ReflectComponent comp); // why do we need extern c really? #ifdef __cplusplus // end extern "C" diff --git a/src/api/cstyle/ReflectCExtern.h b/src/api/cstyle/ReflectCExtern.h index 950cf7a..213834d 100644 --- a/src/api/cstyle/ReflectCExtern.h +++ b/src/api/cstyle/ReflectCExtern.h @@ -171,6 +171,8 @@ REFLECT_API bool Reflect_setFont(ReflectComponent comp, ReflectString font); * @return true if successful, false otherwise. */ REFLECT_API bool Reflect_setFontSize(ReflectComponent comp, uint8_t fontSize); +REFLECT_API bool Reflect_invoke(const char *location); +REFLECT_API bool Reflect_run(ReflectComponent comp); #ifdef __cplusplus // end extern "C" } diff --git a/src/api/java/ReflectJava.c b/src/api/java/ReflectJava.c index 9b02bd4..612d5f1 100644 --- a/src/api/java/ReflectJava.c +++ b/src/api/java/ReflectJava.c @@ -53,3 +53,10 @@ JNIEXPORT void JNICALL JavaFunction(ReflectNative, addComp)(JNI_PARAM_DECL, comp2.id = (uint8_t)compRef; Reflect_addComponent(comp1, comp2); } + +JNIEXPORT void JNICALL JavaFunction(ReflectNative, run)(JNI_PARAM_DECL, + jint ref) { + ReflectComponent comp1; + comp1.id = ref; + Reflect_run(comp1); +} \ No newline at end of file diff --git a/src/api/java/ReflectJava.h b/src/api/java/ReflectJava.h index b8ed047..2417fed 100644 --- a/src/api/java/ReflectJava.h +++ b/src/api/java/ReflectJava.h @@ -99,6 +99,13 @@ JNIEXPORT void JNICALL Java_reflect4j_ReflectNative_setVisible__II(JNIEnv *, jclass, jint, jint); +/* + * Class: reflect4j_ReflectNative + * Method: run + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_reflect4j_ReflectNative_run(JNIEnv *, jclass, jint); + #ifdef __cplusplus } #endif diff --git a/src/api/lua/ReflectLua.h b/src/api/lua/ReflectLua.h index 9d14ae6..b2584c9 100644 --- a/src/api/lua/ReflectLua.h +++ b/src/api/lua/ReflectLua.h @@ -24,9 +24,9 @@ // Include Lua headers extern "C" { -#include "lauxlib.h" -#include "lua.h" -#include "lualib.h" +#include "luajit/lua.h" +#include "luajit/lualib.h" +#include } // Include C++ headers #include "TypeDefinitions.h" diff --git a/src/common/TypeDefinitions.h b/src/common/TypeDefinitions.h index f88638a..9b20daf 100644 --- a/src/common/TypeDefinitions.h +++ b/src/common/TypeDefinitions.h @@ -83,3 +83,9 @@ namespace reflect { #define REFLECT_API __attribute__((visibility("default"))) #endif #endif + +#if __cplusplus < 202002L && !defined(_MSVC_LANG) +#error "Please use C++20 or a newer standard, or define REFLECT_COMPATIBILITY." +#elif _MSVC_LANG < 202002L +#error "Please use C++20 or a newer standard, or define REFLECT_COMPATIBILITY." +#endif \ No newline at end of file diff --git a/src/core/Main.cpp b/src/core/Main.cpp index d0b0080..0b1ec43 100644 --- a/src/core/Main.cpp +++ b/src/core/Main.cpp @@ -108,6 +108,8 @@ Cleaner cleaner; #include "xml/ProcessorRegistry.h" #include #pragma comment(lib, "Shcore.lib") + +void reflect::addToHeap(void *ptr) { heapAllocations.push_back(ptr); }; /** * Invokes and loads a .xml file and also loads the specific libraries. It will * setup the GUI as well as registering APIs for the libraries to use. @@ -180,6 +182,7 @@ int reflect::invokeExecutable(std::string xmlFile, bool blocking) { reflectDebug("creating window..."); // OpenGLContext ctx; + // WindowCreateInfo info = {true}; win = new Window(hInstance, winId); /*win->setBeforeRenderLoop([](Window &win) { wglSwapIntervalEXT(1); @@ -238,9 +241,11 @@ int reflect::invokeExecutable(std::string xmlFile, bool blocking) { } for (tinyxml2::XMLElement *element = winXml->FirstChildElement(); element != nullptr; element = element->NextSiblingElement()) { - reflect::Component &comp = reflect::ProcessorRegistry::invokeProcessor( - element->Name(), win, element); - heapAllocations.push_back(&comp); + std::pair comp = + reflect::ProcessorRegistry::invokeProcessor(element->Name(), win, + element); + win->add(comp.first, comp.second); + heapAllocations.push_back(&comp.first); } reflectDebug("loading libraries..."); #ifdef REFLECT_LUA diff --git a/src/core/Main.h b/src/core/Main.h index 52315dc..5f6f133 100644 --- a/src/core/Main.h +++ b/src/core/Main.h @@ -27,5 +27,6 @@ namespace reflect { REFLECT_API int invokeExecutable(std::string xmlFile, bool blocking = true); REFLECT_API int cliMain(const uint8_t argc, const std::vector argv); +REFLECT_API void addToHeap(void *ptr); } // namespace reflect // int main(const int argc, const char *argv[]); \ No newline at end of file diff --git a/src/core/ReflectAPI.cpp b/src/core/ReflectAPI.cpp index 0e7ed75..a34d345 100644 --- a/src/core/ReflectAPI.cpp +++ b/src/core/ReflectAPI.cpp @@ -19,6 +19,7 @@ typedef unsigned char byte; #include "ReflectAPI.h" #include "Console.h" +#include "Main.h" #include "ui/Button.h" #include "ui/Component.h" #include "ui/Components.h" @@ -210,3 +211,23 @@ bool external::setComponentFontSize(ComponentId comp_, uint8_t fontSize) { return false; // Return false if the cast fails } } + +bool external::run(ComponentId comp_) { + + // Attempt dynamic_cast to Component* + Window *comp = fastCast(Components::getComponentById(cull[comp_ - 1]), + REFLECT_OBJECT_WINDOW); + if (comp) { + comp->run([](Window &) {}); + return true; + } else { + reflectWarn("cast for component failed! (nullptr)"); + return false; // Return false if the cast fails + } +} + +bool external::invoke(const char *location) { + + reflect::invokeExecutable(location, false); + return true; +} \ No newline at end of file diff --git a/src/core/ReflectAPI.h b/src/core/ReflectAPI.h index 6a69354..d63ed66 100644 --- a/src/core/ReflectAPI.h +++ b/src/core/ReflectAPI.h @@ -38,6 +38,8 @@ struct ReflectAPI { bool (*setVisible)(ComponentId comp, bool flag); bool (*setFont)(ComponentId comp, ReflectString font); bool (*setFontSize)(ComponentId comp, uint8_t fontSize); + bool (*run)(ComponentId comp); + bool (*invoke)(const char *location); bool (*setOnClick)(ComponentId comp, void (*callback)(ComponentId)); }; namespace external { @@ -51,6 +53,8 @@ REFLECT_API bool setComponentVisible(ComponentId comp, bool flag); REFLECT_API bool setComponentFont(ComponentId comp, ReflectString font); REFLECT_API bool setComponentFontSize(ComponentId comp, uint8_t fontSize); REFLECT_API bool setOnClick(ComponentId comp, void (*callback)(ComponentId)); +REFLECT_API bool run(ComponentId comp); +REFLECT_API bool invoke(const char *location); } // namespace external typedef void (*SharedLibraryMain)(ReflectAPI *api); } // namespace reflect \ No newline at end of file diff --git a/src/core/ui/Container.cpp b/src/core/ui/Container.cpp index 7f9d354..2de23a0 100644 --- a/src/core/ui/Container.cpp +++ b/src/core/ui/Container.cpp @@ -13,16 +13,15 @@ void Container::registerClass() { } Container::Container() { initializeObject(REFLECT_OBJECT_CONTAINER, REFLECT_OBJECT_COMPONENT); - registerClass(); - hwnd = CreateWindowEx(0, "ReflectContainer", nullptr, 0, 0, 0, 10, 10, - nullptr, nullptr, GetModuleHandle(nullptr), this); } void Container::render(HWND &parentHWND, HWND &windowHWND_) { windowHWND = windowHWND_; - SetParent(hwnd, parentHWND); - SetWindowLongPtr(hwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE); - - ShowWindow(hwnd, SW_SHOW); + registerClass(); + hwnd = + CreateWindowEx(0, "ReflectContainer", nullptr, + WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, + position.x, position.y, size.x, size.y, parentHWND, + nullptr, GetModuleHandle(nullptr), this); for (Component *comp : componentsQueue) { reflectDebug("added new component"); @@ -57,6 +56,61 @@ void Container::add(reflect::Component &comp) { } LRESULT CALLBACK Container::containerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + if (GetParent(hwnd) != nullptr) { + + reflect::Container *pThis = nullptr; + + if (uMsg == WM_CREATE) { + CREATESTRUCT *pCreate = reinterpret_cast(lParam); + pThis = reinterpret_cast(pCreate->lpCreateParams); + SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast(pThis)); + reflect::Window *win = reinterpret_cast( + GetWindowLongPtr(GetAncestor(hwnd, GA_ROOT), GWLP_USERDATA)); + + RECT rc; + + GetClientRect(hwnd, &rc); + // Initialize Direct2D + ID2D1Factory *pFactory = + win->getProperty("direct2DFactory"); + D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties(); + D2D1_HWND_RENDER_TARGET_PROPERTIES hwndRTProps = + D2D1::HwndRenderTargetProperties( + hwnd, D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top)); + + HRESULT hr = pFactory->CreateHwndRenderTarget( + rtProps, hwndRTProps, + &(pThis->childRenderTarget)); // <--- store it on pThis + + } else { + pThis = reinterpret_cast( + GetWindowLongPtr(hwnd, GWLP_USERDATA)); + } + if (pThis) { + switch (uMsg) { + case WM_PAINT: { + if (pThis->childRenderTarget) { + PAINTSTRUCT ps; + BeginPaint(hwnd, &ps); + pThis->childRenderTarget->BeginDraw(); + ID2D1SolidColorBrush *brush = nullptr; + pThis->childRenderTarget->CreateSolidColorBrush( + D2D1_COLOR_F(pThis->bgColor[0], pThis->bgColor[1], + pThis->bgColor[2]), + &brush); + pThis->childRenderTarget->FillRectangle( + D2D1_RECT_F(0, 0, pThis->size.x, pThis->size.y), brush); + pThis->childRenderTarget->EndDraw(); + + brush->Release(); + EndPaint(hwnd, &ps); + return 0; + } + break; + } + } + } + } return DefWindowProc(hwnd, uMsg, wParam, lParam); }; } // namespace reflect \ No newline at end of file diff --git a/src/core/ui/Container.h b/src/core/ui/Container.h index a58747b..74913b0 100644 --- a/src/core/ui/Container.h +++ b/src/core/ui/Container.h @@ -1,7 +1,7 @@ #pragma once - #include "Component.h" #include "TypeDefinitions.h" +#include namespace reflect { class Container : public Component { @@ -11,6 +11,7 @@ class Container : public Component { void registerClass(); HWND windowHWND = nullptr; std::vector componentsQueue; + ID2D1HwndRenderTarget *childRenderTarget = nullptr; public: REFLECT_API void render(HWND &parentHWND, HWND &windowHWND); diff --git a/src/core/ui/Image.cpp b/src/core/ui/Image.cpp index f3a60c1..0d3e7c6 100644 --- a/src/core/ui/Image.cpp +++ b/src/core/ui/Image.cpp @@ -170,7 +170,7 @@ LRESULT CALLBACK Image::imageProc(HWND hwnd, UINT uMsg, WPARAM wParam, pThis = reinterpret_cast(pCreate->lpCreateParams); SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast(pThis)); reflect::Window *win = reinterpret_cast( - GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA)); + GetWindowLongPtr(GetAncestor(hwnd, GA_ROOT), GWLP_USERDATA)); RECT rc; @@ -192,7 +192,7 @@ LRESULT CALLBACK Image::imageProc(HWND hwnd, UINT uMsg, WPARAM wParam, GetWindowLongPtr(hwnd, GWLP_USERDATA)); } reflect::Window *win = reinterpret_cast( - GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA)); + GetWindowLongPtr(GetAncestor(hwnd, GA_ROOT), GWLP_USERDATA)); ID2D1Factory *pFactory = win->getProperty("direct2DFactory"); if (pThis) { @@ -215,6 +215,9 @@ LRESULT CALLBACK Image::imageProc(HWND hwnd, UINT uMsg, WPARAM wParam, MultiByteToWideChar(CP_UTF8, 0, path.c_str(), -1, &wstr[0], sizeNeeded); getBitmap(wstr, pThis->childRenderTarget, &(bitmap)); + if (bitmap) { + pThis->bitmaps[pThis->activeImage] = bitmap; + } } D2D1_RECT_F rect = {0, 0, pThis->size.x, pThis->size.y}; @@ -225,6 +228,7 @@ LRESULT CALLBACK Image::imageProc(HWND hwnd, UINT uMsg, WPARAM wParam, pThis->childRenderTarget->FillRectangle(rect, pBrush); pThis->childRenderTarget->DrawBitmap(bitmap, rect); + pBrush->Release(); pThis->childRenderTarget->EndDraw(); EndPaint(hwnd, &ps); @@ -239,8 +243,11 @@ LRESULT CALLBACK Image::imageProc(HWND hwnd, UINT uMsg, WPARAM wParam, void Image::render(HWND &parentHWND, HWND &windowHWND) { registerClass(); - hwnd = CreateWindowEx(0, "D2D1BitmapImage", nullptr, WS_CHILD | WS_VISIBLE, - position.x, position.y, size.x, size.y, parentHWND, - nullptr, GetModuleHandle(nullptr), this); + hwnd = CreateWindowEx( + 0, "D2D1BitmapImage", nullptr, WS_CHILD | WS_VISIBLE, position.x, + position.y + reinterpret_cast( + GetWindowLongPtr(windowHWND, GWLP_USERDATA)) + ->getProperty("customTitleBarSize"), + size.x, size.y, parentHWND, nullptr, GetModuleHandle(nullptr), this); }; } // namespace reflect \ No newline at end of file diff --git a/src/core/ui/Label.cpp b/src/core/ui/Label.cpp index c38d4bd..586b662 100644 --- a/src/core/ui/Label.cpp +++ b/src/core/ui/Label.cpp @@ -44,6 +44,34 @@ void reflect::Label::registerClass() { wc.lpfnWndProc = labelProc; RegisterClass(&wc); } +void reflect::Label::createResources(ID2D1RenderTarget *rt, + IDWriteFactory *dwrite, + reflect::Window *win) { + + if (pTextFormat) { + pTextFormat->Release(); + pTextFormat = nullptr; + } + if (pBgBrush) { + pBgBrush->Release(); + pBgBrush = nullptr; + } + if (pTextBrush) { + pTextBrush->Release(); + pTextBrush = nullptr; + } + + std::wstring wfont(fontStr.begin(), fontStr.end()); + dwrite->CreateTextFormat(wfont.c_str(), NULL, DWRITE_FONT_WEIGHT_NORMAL, + DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, + fontSize, L"en-us", &pTextFormat); + + rt->CreateSolidColorBrush(D2D1::ColorF(win->getColor().r / 255.0f, + win->getColor().g / 255.0f, + win->getColor().b / 255.0f), + &pBgBrush); + rt->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), &pTextBrush); +} LRESULT CALLBACK reflect::Label::labelProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { reflect::Label *pThis = nullptr; @@ -53,7 +81,7 @@ LRESULT CALLBACK reflect::Label::labelProc(HWND hwnd, UINT uMsg, WPARAM wParam, pThis = reinterpret_cast(pCreate->lpCreateParams); SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast(pThis)); reflect::Window *win = reinterpret_cast( - GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA)); + GetWindowLongPtr(GetAncestor(hwnd, GA_ROOT), GWLP_USERDATA)); RECT rc; @@ -61,7 +89,8 @@ LRESULT CALLBACK reflect::Label::labelProc(HWND hwnd, UINT uMsg, WPARAM wParam, // Initialize Direct2D ID2D1Factory *pFactory = win->getProperty("direct2DFactory"); - + IDWriteFactory *pDWriteFactory = win->getProperty( + "directWriteFactory"); // get from parent window D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties(); D2D1_HWND_RENDER_TARGET_PROPERTIES hwndRTProps = D2D1::HwndRenderTargetProperties( @@ -70,20 +99,29 @@ LRESULT CALLBACK reflect::Label::labelProc(HWND hwnd, UINT uMsg, WPARAM wParam, HRESULT hr = pFactory->CreateHwndRenderTarget( rtProps, hwndRTProps, &(pThis->childRenderTarget)); // <--- store it on pThis + // std::wstring wtextFont = + // std::wstring(pThis->fontStr.begin(), pThis->fontStr.end()); + //// In WM_CREATE block after creating childRenderTarget: + // hr = pDWriteFactory->CreateTextFormat( + // wtextFont.c_str(), NULL, DWRITE_FONT_WEIGHT_NORMAL, + // DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, + // pThis->fontSize, L"en-us", &pThis->pTextFormat); + + if (SUCCEEDED(hr)) { + pThis->createResources(pThis->childRenderTarget, pDWriteFactory, win); + } } else { pThis = reinterpret_cast( GetWindowLongPtr(hwnd, GWLP_USERDATA)); } reflect::Window *win = reinterpret_cast( - GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA)); + GetWindowLongPtr(GetAncestor(hwnd, GA_ROOT), GWLP_USERDATA)); // Example: In Label::render or Label::paint + // Create text format (font, size, etc.) IDWriteFactory *pDWriteFactory = win->getProperty( "directWriteFactory"); // get from parent window - - // Create text format (font, size, etc.) - ID2D1Factory *pFactory = win->getProperty("direct2DFactory"); if (pThis) { @@ -91,18 +129,16 @@ LRESULT CALLBACK reflect::Label::labelProc(HWND hwnd, UINT uMsg, WPARAM wParam, switch (uMsg) { case WM_SIZE: { - if (pThis->childRenderTarget) { - pThis->childRenderTarget->Release(); - pThis->childRenderTarget = nullptr; - } + RECT rc; GetClientRect(hwnd, &rc); - D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties(); - D2D1_HWND_RENDER_TARGET_PROPERTIES hwndRTProps = - D2D1::HwndRenderTargetProperties( - hwnd, D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top)); - HRESULT hr = pFactory->CreateHwndRenderTarget( - rtProps, hwndRTProps, &(pThis->childRenderTarget)); + if (pThis->childRenderTarget) { + D2D1_SIZE_U newSize = + D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); + pThis->childRenderTarget->Resize(newSize); + } + + pThis->createResources(pThis->childRenderTarget, pDWriteFactory, win); InvalidateRect(hwnd, nullptr, FALSE); // Request redraw break; } @@ -110,46 +146,42 @@ LRESULT CALLBACK reflect::Label::labelProc(HWND hwnd, UINT uMsg, WPARAM wParam, PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); pThis->childRenderTarget->BeginDraw(); - IDWriteTextFormat *pTextFormat = nullptr; - std::wstring wtextFont = - std::wstring(pThis->fontStr.begin(), pThis->fontStr.end()); - HRESULT hr = pDWriteFactory->CreateTextFormat( - wtextFont.c_str(), // Font family name - NULL, // Font collection (NULL sets it to use the system font - // collection) - DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, - DWRITE_FONT_STRETCH_NORMAL, - pThis->fontSize, // Font size - L"en-us", &pTextFormat); + D2D1_RECT_F rect = {0, 0, pThis->size.x, pThis->size.y}; - ID2D1SolidColorBrush *pBrush = nullptr; - hr = pThis->childRenderTarget->CreateSolidColorBrush( - D2D1::ColorF(win->getColor().r / 255.0f, win->getColor().g / 255.0f, - win->getColor().b / 255.0f), - &pBrush); - pThis->childRenderTarget->FillRectangle(rect, pBrush); - pBrush->Release(); + pThis->childRenderTarget->FillRectangle(rect, pThis->pBgBrush); std::wstring wtext = std::wstring(pThis->text.begin(), pThis->text.end()); - D2D1_RECT_F layoutRect = - D2D1::RectF((FLOAT)pThis->position.x, (FLOAT)pThis->position.y, - (FLOAT)(pThis->position.x + pThis->size.x), - (FLOAT)(pThis->position.y + pThis->size.y)); - - pBrush = nullptr; - pThis->childRenderTarget->CreateSolidColorBrush( - D2D1::ColorF(D2D1::ColorF::White), &pBrush); pThis->childRenderTarget->DrawText(wtext.c_str(), (UINT32)wtext.length(), - pTextFormat, rect, pBrush); + pThis->pTextFormat, rect, + pThis->pTextBrush); + + HRESULT hr = pThis->childRenderTarget->EndDraw(); + if (hr == D2DERR_RECREATE_TARGET) { + RECT rc; + + GetClientRect(hwnd, &rc); + pThis->childRenderTarget->Release(); + pThis->childRenderTarget = nullptr; + pThis->createResources(pThis->childRenderTarget, pDWriteFactory, win); + D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties(); + D2D1_HWND_RENDER_TARGET_PROPERTIES hwndRTProps = + D2D1::HwndRenderTargetProperties( + hwnd, D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top)); + + HRESULT hr = pFactory->CreateHwndRenderTarget( + rtProps, hwndRTProps, + &(pThis->childRenderTarget)); // <--- store it on pThis + InvalidateRect(hwnd, nullptr, FALSE); + } - pBrush->Release(); - pTextFormat->Release(); - pThis->childRenderTarget->EndDraw(); EndPaint(hwnd, &ps); - break; return 0; } + case WM_ERASEBKGND: { + // Prevent background erase; Direct2D will handle it. + return 1; + } } } @@ -170,9 +202,10 @@ void reflect::Label::render(HWND &parentHWND, HWND &windowHWND) { GetWindowLongPtr(windowHWND, GWLP_USERDATA)); registerClass(); // Create the label window - hwnd = CreateWindow("D2D1Label", // Predefined class for a label - text.c_str(), // Label text - WS_VISIBLE | WS_CHILD, // Styles: visible and child window + hwnd = CreateWindow("D2D1Label", // Predefined class for a label + text.c_str(), // Label text + WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | + WS_CLIPSIBLINGS, // Styles: visible and child window position.x, position.y + window->getProperty( "customTitleBarSize"), // Position (x, y) diff --git a/src/core/ui/Label.h b/src/core/ui/Label.h index 7662df0..51cfaad 100644 --- a/src/core/ui/Label.h +++ b/src/core/ui/Label.h @@ -21,6 +21,7 @@ #include "TextComponent.h" #include "TypeDefinitions.h" #include +#include #include namespace reflect { @@ -34,7 +35,12 @@ class Label : public TextComponent { void registerClass(); static LRESULT CALLBACK labelProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + void createResources(ID2D1RenderTarget *rt, IDWriteFactory *dwrite, + reflect::Window *win); ID2D1HwndRenderTarget *childRenderTarget; + IDWriteTextFormat *pTextFormat = nullptr; + ID2D1SolidColorBrush *pBgBrush = nullptr; + ID2D1SolidColorBrush *pTextBrush = nullptr; public: friend class Component; diff --git a/src/core/ui/Window.cpp b/src/core/ui/Window.cpp index 580fc93..99997ca 100644 --- a/src/core/ui/Window.cpp +++ b/src/core/ui/Window.cpp @@ -59,7 +59,7 @@ void reflect::Window::addStyle(WindowStyle style) { &cornerPreference, sizeof(cornerPreference)); // Enable Mica background - DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_MAINWINDOW; + DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_TABBEDWINDOW; DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, sizeof(backdropType)); } @@ -112,6 +112,8 @@ void reflect::Window::initializeDirect2D() { reflectDebug("creating d2d1 factory..."); HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &this->pFactory); + + int i = 0; } if (!this->pRenderTarget) { RECT rc; @@ -163,7 +165,7 @@ LRESULT CALLBACK reflect::Window::windowProc(HWND hwnd, UINT uMsg, CREATESTRUCT *pCreate = reinterpret_cast(lParam); pThis = reinterpret_cast(pCreate->lpCreateParams); SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast(pThis)); - + pThis->hwnd = hwnd; // Initialize Direct2D if (!pThis->useGL) { reflectDebug("calling initializeDirect2D..."); @@ -265,14 +267,19 @@ LRESULT CALLBACK reflect::Window::windowProc(HWND hwnd, UINT uMsg, TRUE); // Mark the entire window as needing a repaint break; } - case WM_NCACTIVATE: - InvalidateRect(hwnd, nullptr, false); - return TRUE; // Ensures Windows handles the default behavior + case WM_NCACTIVATE: { + + if (pThis && pThis->customTitleBar) { + InvalidateRect(hwnd, nullptr, false); + return TRUE; + } + break; + } case WM_ACTIVATE: { - InvalidateRect(hwnd, nullptr, false); + if (pThis->customTitleBar) { RECT rc; - + InvalidateRect(hwnd, nullptr, false); GetWindowRect(hwnd, &rc); closeIcon.setPosition( {rc.right - rc.left - (10 + (40 / 2)), ((10 + (40 / 2)) / 2)}); @@ -280,8 +287,10 @@ LRESULT CALLBACK reflect::Window::windowProc(HWND hwnd, UINT uMsg, break; } case WM_MOVE: - InvalidateRect(hwnd, NULL, - TRUE); // Mark the entire window as needing a repaint + if (pThis->customTitleBar) { + InvalidateRect(hwnd, NULL, true); + } + break; case WM_SIZING: { if (pThis->beforeRenderLoop) @@ -417,6 +426,7 @@ LRESULT CALLBACK reflect::Window::windowProc(HWND hwnd, UINT uMsg, case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); + if (!openglRendering && firstUpdate) { glHdc = GetDC(hwnd); if (pThis->useGL) { @@ -451,30 +461,6 @@ LRESULT CALLBACK reflect::Window::windowProc(HWND hwnd, UINT uMsg, // Create a clipping region for the child controls - HRGN hrgnA = nullptr; - int regionType = GetWindowRgn( - hwnd, hrgnA); // Get the window's region (valid or reflectError) - // regionType = GetWindowRgn(hwnd, hrgn); - if (regionType != ERROR) { - RECT controlRect; - HWND hChild = GetWindow(hwnd, GW_CHILD); // Get the first child window - - // while (hChild != NULL) { - // GetWindowRect(hChild, &controlRect); - // MapWindowPoints(NULL, hwnd, (LPPOINT)&controlRect, - // 2); // Convert to client coordinates - - // // Exclude the child control region from the painting area - // ExcludeClipRect(hdc, controlRect.left, controlRect.top, - // controlRect.right, controlRect.bottom); - // // wait, is it a direct2d image? - - // hChild = - // GetNextWindow(hChild, GW_HWNDNEXT); // Get the next child - // window - //} - } - // Start Direct2D rendering pThis->pRenderTarget->BeginDraw(); @@ -547,9 +533,9 @@ LRESULT CALLBACK reflect::Window::windowProc(HWND hwnd, UINT uMsg, // // Handle device loss // pThis->pRenderTarget->Release(); // pThis->pRenderTarget = nullptr; - // // pThis->initializeDirect2D(); + // pThis->initializeDirect2D(); // } - // Clean up + // Clean up } EndPaint(hwnd, &ps); @@ -696,9 +682,10 @@ reflect::Window::Window(HINSTANCE instance, std::string id, customTitleBar = true; } else { - hwnd = CreateWindowEx(0, "WindowClass", wc.lpszClassName, - WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, - 100, 100, nullptr, nullptr, instance, this); + hwnd = CreateWindowEx( + 0, "WindowClass", wc.lpszClassName, + WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, CW_USEDEFAULT, + CW_USEDEFAULT, 100, 100, nullptr, nullptr, instance, this); customTitleBar = false; } RECT rc; diff --git a/src/core/xml/ProcessorRegistry.cpp b/src/core/xml/ProcessorRegistry.cpp index 2d4b3a7..5bbac0e 100644 --- a/src/core/xml/ProcessorRegistry.cpp +++ b/src/core/xml/ProcessorRegistry.cpp @@ -1,5 +1,8 @@ #include "ProcessorRegistry.h" +#include "../Main.h" #include "core/ui/Button.h" +#include "core/ui/Container.h" +#include "core/ui/Image.h" #include "core/ui/Label.h" #include "core/ui/ProgressBar.h" #include "core/ui/TextField.h" @@ -7,7 +10,8 @@ namespace reflect { std::unordered_map ProcessorRegistry::mapOfProcessors = {{"label", - [](Window *win, tinyxml2::XMLElement *label) -> Component & { + [](Window *win, + tinyxml2::XMLElement *label) -> std::pair { // Access attributes std::string c = std::string(label->GetText()); std::string *contents = &c; @@ -17,11 +21,11 @@ std::unordered_map ProcessorRegistry::mapOfProcessors = Label *labelComp = new Label(*contents, position); labelComp->setFont(label->Attribute("font")); labelComp->setFontSize(std::stoi(label->Attribute("fontSize"))); - win->add(*labelComp, id); - return *labelComp; + return {*labelComp, id}; }}, {"button", - [](Window *win, tinyxml2::XMLElement *button) -> Component & { + [](Window *win, + tinyxml2::XMLElement *button) -> std::pair { // Access attributes std::string contents = button->GetText(); std::string id = button->Attribute("id"); @@ -32,11 +36,11 @@ std::unordered_map ProcessorRegistry::mapOfProcessors = buttonComp->setFont(button->Attribute("font")); buttonComp->setFontSize(std::stoi(button->Attribute("fontSize"))); - win->add(*buttonComp, id); - return *buttonComp; + return {*buttonComp, id}; }}, {"progressBar", - [](Window *win, tinyxml2::XMLElement *label) -> Component & { + [](Window *win, + tinyxml2::XMLElement *label) -> std::pair { // Access attributes std::string id = label->Attribute("id"); Vector2 position(std::stoi(label->Attribute("x")), @@ -49,10 +53,26 @@ std::unordered_map ProcessorRegistry::mapOfProcessors = pb->setValue(std::stof(label->Attribute("value"))); pb->setPosition(position); pb->setSize(size); - win->add(*pb, id); - return *pb; + return {*pb, id}; }}, - {"textField", [](Window *win, tinyxml2::XMLElement *field) -> Component & { + {"image", + [](Window *win, + tinyxml2::XMLElement *img) -> std::pair { + // Access attributes + std::string id = img->Attribute("id"); + Vector2 position(std::stoi(img->Attribute("x")), + std::stoi(img->Attribute("y"))); + Vector2 size(std::stoi(img->Attribute("width")), + std::stoi(img->Attribute("height"))); + Image *imgComp = new Image(); + imgComp->setImageLocation(img->Attribute("location")); + imgComp->setPosition(position); + imgComp->setSize(size); + return {*imgComp, id}; + }}, + {"textField", + [](Window *win, + tinyxml2::XMLElement *field) -> std::pair { // Access attributes // Access attributes std::string id = field->Attribute("id"); @@ -62,17 +82,42 @@ std::unordered_map ProcessorRegistry::mapOfProcessors = fieldComp->setSize(Vector2(std::stoi(field->Attribute("width")), std::stoi(field->Attribute("height")))); fieldComp->setPosition(position); - win->add(*fieldComp, id); - return *fieldComp; + return {*fieldComp, id}; + }}, + {"container", + [](Window *win, tinyxml2::XMLElement *container) + -> std::pair { + // Access attributes + // Access attributes + std::string id = container->Attribute("id"); + Vector2 position(std::stoi(container->Attribute("x")), + std::stoi(container->Attribute("y"))); + Container *containerComp = new Container(); + containerComp->setSize( + Vector2(std::stoi(container->Attribute("width")), + std::stoi(container->Attribute("height")))); + containerComp->setPosition(position); + + // recursive stuff + + for (tinyxml2::XMLElement *element = container->FirstChildElement(); + element != nullptr; element = element->NextSiblingElement()) { + std::pair comp = + reflect::ProcessorRegistry::invokeProcessor(element->Name(), win, + element); + containerComp->add(comp.first, comp.second); + addToHeap(&comp); + } + return {*containerComp, id}; }}}; void ProcessorRegistry::createProcessor(Processor processor, const std::string &elementId) { mapOfProcessors[elementId] = processor; } -Component &ProcessorRegistry::invokeProcessor(const std::string &elementId, - Window *win, - tinyxml2::XMLElement *element) { +std::pair +ProcessorRegistry::invokeProcessor(const std::string &elementId, Window *win, + tinyxml2::XMLElement *element) { return mapOfProcessors[elementId](win, element); } diff --git a/src/core/xml/ProcessorRegistry.h b/src/core/xml/ProcessorRegistry.h index 577a16a..c5e114d 100644 --- a/src/core/xml/ProcessorRegistry.h +++ b/src/core/xml/ProcessorRegistry.h @@ -7,8 +7,8 @@ #include #include namespace reflect { -using Processor = - std::function; +using Processor = std::function( + Window *win, tinyxml2::XMLElement *element)>; class ProcessorRegistry { private: static std::unordered_map mapOfProcessors; @@ -16,7 +16,8 @@ class ProcessorRegistry { public: static void createProcessor(Processor processor, const std::string &elementId); - static Component &invokeProcessor(const std::string &elementId, Window *win, - tinyxml2::XMLElement *element); + static std::pair + invokeProcessor(const std::string &elementId, Window *win, + tinyxml2::XMLElement *element); }; } // namespace reflect \ No newline at end of file From 5661524c442642f87c15765850a4dd84e1c20406 Mon Sep 17 00:00:00 2001 From: thebest12lines Date: Sat, 24 May 2025 11:54:32 +0600 Subject: [PATCH 2/2] Final change --- CMakeLists.txt | 17 +++++++++++------ src/api/cstyle/ReflectC.cpp | 1 - src/api/java/ReflectJava.c | 34 +++++++++++++++++++++++++++++++++- src/api/java/ReflectJava.h | 8 ++++++++ src/api/lua/ReflectLua.cpp | 1 - src/common/ConsoleHelper.cpp | 6 ++++++ src/core/ui/Component.cpp | 8 ++++---- 7 files changed, 62 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08282da..1ced57c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) message(STATUS "Generating files...") message(STATUS "vcpkg toolchain location: ${CMAKE_TOOLCHAIN_FILE}") # Enable Hot Reload for MSVC compilers if supported. +# Force static runtime if (POLICY CMP0141) cmake_policy(SET CMP0141 NEW) if (CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -18,16 +19,17 @@ endif() # Enable exceptions in MSVC if(MSVC) add_compile_options(/EHsc) + add_compile_options(/MT /NODEFAULTLIB:libcmt) endif() # Define the project -set(TRIPLET "x64-windows") -set(VCPKG_TARGET_TRIPLET "x64-windows") +set(TRIPLET "x64-windows-static-md") +set(VCPKG_TARGET_TRIPLET "x64-windows-static-md") project("cinnamontoast") set(CMAKE_GENERATOR_PLATFORM "x64") enable_testing() - +set(OPENSSL_USE_STATIC_LIBS TRUE) file(GLOB_RECURSE REFLECT_CORE "src/core/*.cpp" "src/core/*.h") file(GLOB_RECURSE REFLECT_NET "src/net/*.cpp" "src/net/*.h" ) file(GLOB_RECURSE REFLECT_CRASHHANDLER "src/crash/*.cpp" "src/crash/*.h") @@ -58,7 +60,7 @@ endif() get_filename_component(VCPKG_DIR "${CMAKE_TOOLCHAIN_FILE}" DIRECTORY) set(VCPKG_DIR "${VCPKG_DIR}/../../") -set(PKG_CONFIG_EXECUTABLE "${VCPKG_DIR}/installed/${TRIPLET}/tools/pkgconf/pkgconf.exe") +set(PKG_CONFIG_EXECUTABLE "${VCPKG_DIR}/installed/x64-windows/tools/pkgconf/pkgconf.exe") set(LIB_FILE_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed/${TRIPLET}/lib") set(JAVA_VERSION "21") set(JNI_INCLUDE_DIR "$ENV{JAVA_HOME}/include/win32" "$ENV{JAVA_HOME}/include") @@ -161,13 +163,15 @@ set_target_properties(reflectw PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS") add_executable(reflectt ${REFLECT_TEST}) find_package(tinyxml2 CONFIG REQUIRED) find_package(GTest REQUIRED) -find_package(OpenSSL REQUIRED) +# find_package(OpenSSL CONFIG REQUIRED) find_package(GLEW REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(LUAJIT REQUIRED luajit) set(LUAJIT_LIBRARIES "${LIB_FILE_DIR}/${LUAJIT_LIBRARIES}.lib") +set(OPENSSL_LIBRARIES "${LIB_FILE_DIR}/libcrypto.lib" "${LIB_FILE_DIR}/libssl.lib" crypt32) message(STATUS "LuaJIT binaries: ${LUAJIT_LIBRARIES}") +message(STATUS "OpenSSL binaries: ${OPENSSL_LIBRARIES}") file(GLOB DLL_FILE_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed/${TRIPLET}/bin/*") #foreach(file ${DLL_FILE_DIR}) @@ -185,7 +189,8 @@ if(DEFINED REFLECT_BUNDLE) target_link_libraries(Reflect PRIVATE tinyxml2::tinyxml2 GLEW::GLEW) target_link_libraries(Reflect PRIVATE ${LUAJIT_LIBRARIES}) - target_link_libraries(Reflect PRIVATE OpenSSL::SSL OpenSSL::Crypto ws2_32) + target_link_libraries(Reflect PRIVATE ${OPENSSL_LIBRARIES} ws2_32) + else() target_link_libraries(Reflect.CStyleAPI PRIVATE Reflect.Core) diff --git a/src/api/cstyle/ReflectC.cpp b/src/api/cstyle/ReflectC.cpp index c839161..c1c8598 100644 --- a/src/api/cstyle/ReflectC.cpp +++ b/src/api/cstyle/ReflectC.cpp @@ -20,7 +20,6 @@ // Includes #include "ReflectC.h" #include "../../core/ReflectAPI.h" - // why do you need this really? using namespace reflect; diff --git a/src/api/java/ReflectJava.c b/src/api/java/ReflectJava.c index 612d5f1..0ed097f 100644 --- a/src/api/java/ReflectJava.c +++ b/src/api/java/ReflectJava.c @@ -19,8 +19,8 @@ #include "ReflectJava.h" #include "../cstyle/ReflectCExtern.h" #include "ReflectJavaUtil.h" +#include #include - JNIEXPORT jint JNICALL JavaFunction(ReflectNative, getReferenceById)(JNI_PARAM_DECL, jstring id) { @@ -59,4 +59,36 @@ JNIEXPORT void JNICALL JavaFunction(ReflectNative, run)(JNI_PARAM_DECL, ReflectComponent comp1; comp1.id = ref; Reflect_run(comp1); +} + +JNIEXPORT void JNICALL Java_reflect4j_ReflectNative_invoke(JNIEnv *env, + jclass clazz, + jstring location) { + + const char *utfChars = (*env)->GetStringUTFChars(env, location, NULL); + if (utfChars == NULL) + return; // Could not get string + + // Call your real native function here with the C string + Reflect_invoke(utfChars); + + // Don't forget to release memory! + (*env)->ReleaseStringUTFChars(env, location, utfChars); +} +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { + HMODULE hModule = NULL; + + // Get handle to the current module (i.e., the DLL) + if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCSTR)&JNI_OnLoad, // any symbol in this DLL + &hModule)) { + // Manually increase the refcount + wchar_t dllPath[MAX_PATH]; + if (GetModuleFileNameW(hModule, dllPath, MAX_PATH)) { + LoadLibraryW(dllPath); // increments refcount, keeps DLL loaded + } + } + + return JNI_VERSION_1_8; } \ No newline at end of file diff --git a/src/api/java/ReflectJava.h b/src/api/java/ReflectJava.h index 2417fed..9b2dfe1 100644 --- a/src/api/java/ReflectJava.h +++ b/src/api/java/ReflectJava.h @@ -106,6 +106,14 @@ JNIEXPORT void JNICALL Java_reflect4j_ReflectNative_setVisible__II(JNIEnv *, */ JNIEXPORT void JNICALL Java_reflect4j_ReflectNative_run(JNIEnv *, jclass, jint); +/* + * Class: reflect4j_ReflectNative + * Method: invoke + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_reflect4j_ReflectNative_invoke(JNIEnv *, jclass, + jstring); + #ifdef __cplusplus } #endif diff --git a/src/api/lua/ReflectLua.cpp b/src/api/lua/ReflectLua.cpp index b2275ed..4dae5c4 100644 --- a/src/api/lua/ReflectLua.cpp +++ b/src/api/lua/ReflectLua.cpp @@ -1,5 +1,4 @@ #include "ReflectLua.h" - namespace reflect { // Constructor diff --git a/src/common/ConsoleHelper.cpp b/src/common/ConsoleHelper.cpp index 78b5c99..6ce45a8 100644 --- a/src/common/ConsoleHelper.cpp +++ b/src/common/ConsoleHelper.cpp @@ -22,7 +22,13 @@ #include "../core/logging/LogInstance.h" namespace { // Indicates whether debug logging is enabled. + +#ifdef _DEBUG +bool debugEnabled = true; +#else bool debugEnabled = false; +#endif + } // namespace namespace reflect { diff --git a/src/core/ui/Component.cpp b/src/core/ui/Component.cpp index 7aae0ee..8e2a15e 100644 --- a/src/core/ui/Component.cpp +++ b/src/core/ui/Component.cpp @@ -76,7 +76,7 @@ reflect::Vector2 reflect::Component::getSize() { return size; }; namespace reflect { void *Component::operator new(std::size_t size) { if (!getHeapPool()) { - throw std::bad_alloc(); // Handle allocation failure + initializeHeapPool(2 * 1024 * 1024); } void *ptr = getHeapPool()->allocate(size); if (!ptr) { @@ -87,14 +87,14 @@ void *Component::operator new(std::size_t size) { void Component::operator delete(void *ptr) { if (!getHeapPool()) { - throw std::bad_alloc(); // Handle deallocation failure + initializeHeapPool(2 * 1024 * 1024); } getHeapPool()->deallocate(ptr, sizeof(ptr)); } void *Component::operator new[](std::size_t size) { if (!getHeapPool()) { - throw std::bad_alloc(); // Handle deallocation failure + initializeHeapPool(2 * 1024 * 1024); } void *ptr = getHeapPool()->allocate(size); return ptr; @@ -102,7 +102,7 @@ void *Component::operator new[](std::size_t size) { void Component::operator delete[](void *ptr) { if (!getHeapPool()) { - throw std::bad_alloc(); // Handle deallocation failure + initializeHeapPool(2 * 1024 * 1024); } getHeapPool()->deallocate(ptr, sizeof(ptr)); }