Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -17,16 +18,18 @@ if (POLICY CMP0141)
endif()
# Enable exceptions in MSVC
if(MSVC)
add_compile_options(/EHsc /Zc:__cplusplus)
add_compile_options(/EHsc)
add_compile_options(/MT /NODEFAULTLIB:libcmt)
endif()

# Define the project
set(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")
Expand Down Expand Up @@ -57,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")
Expand Down Expand Up @@ -88,6 +91,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)
Expand Down Expand Up @@ -159,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})
Expand All @@ -183,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 ws2_32)
target_link_libraries(Reflect PRIVATE ${OPENSSL_LIBRARIES} ws2_32)

else()

target_link_libraries(Reflect.CStyleAPI PRIVATE Reflect.Core)
Expand Down
11 changes: 10 additions & 1 deletion src/api/cstyle/ReflectC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// Includes
#include "ReflectC.h"
#include "../../core/ReflectAPI.h"

// why do you need this really?
using namespace reflect;

Expand Down Expand Up @@ -65,4 +64,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;
};
3 changes: 2 additions & 1 deletion src/api/cstyle/ReflectC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/api/cstyle/ReflectCExtern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
41 changes: 40 additions & 1 deletion src/api/java/ReflectJava.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "ReflectJava.h"
#include "../cstyle/ReflectCExtern.h"
#include "ReflectJavaUtil.h"
#include <Windows.h>
#include <jni.h>

JNIEXPORT jint JNICALL JavaFunction(ReflectNative,
getReferenceById)(JNI_PARAM_DECL,
jstring id) {
Expand Down Expand Up @@ -53,3 +53,42 @@ 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);
}

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;
}
15 changes: 15 additions & 0 deletions src/api/java/ReflectJava.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/api/lua/ReflectLua.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "ReflectLua.h"

namespace reflect {

// Constructor
Expand Down
6 changes: 3 additions & 3 deletions src/api/lua/ReflectLua.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <luajit/lauxlib.h>
}
// Include C++ headers
#include "TypeDefinitions.h"
Expand Down
6 changes: 6 additions & 0 deletions src/common/ConsoleHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/common/TypeDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions src/core/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Cleaner cleaner;
#include "xml/ProcessorRegistry.h"
#include <ShellScalingAPI.h>
#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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Component &, std::string> 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
Expand Down
1 change: 1 addition & 0 deletions src/core/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> argv);
REFLECT_API void addToHeap(void *ptr);
} // namespace reflect
// int main(const int argc, const char *argv[]);
21 changes: 21 additions & 0 deletions src/core/ReflectAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<Window>(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;
}
4 changes: 4 additions & 0 deletions src/core/ReflectAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
8 changes: 4 additions & 4 deletions src/core/ui/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -87,22 +87,22 @@ 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;
}

void Component::operator delete[](void *ptr) {
if (!getHeapPool()) {
throw std::bad_alloc(); // Handle deallocation failure
initializeHeapPool(2 * 1024 * 1024);
}
getHeapPool()->deallocate(ptr, sizeof(ptr));
}
Expand Down
Loading
Loading