From 7394df0f62ea79ef169db0517d2c5df04fc9a492 Mon Sep 17 00:00:00 2001 From: That_One_Nerd Date: Thu, 23 May 2024 13:03:07 -0400 Subject: [PATCH] Window copying works for the most part. Tested on brain. --- include/sharpsoft/global_misc.hpp | 11 +++++++++++ include/sharpsoft/internal.hpp | 13 +++++++++++++ include/sharpsoft/window_types.hpp | 3 +++ project.pros | 3 ++- src/main.cpp | 10 +++++++--- src/sharpsoft/global_manager.cpp | 23 +++++++++++++++++++++++ 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 include/sharpsoft/internal.hpp diff --git a/include/sharpsoft/global_misc.hpp b/include/sharpsoft/global_misc.hpp index f77df5d..37142f0 100644 --- a/include/sharpsoft/global_misc.hpp +++ b/include/sharpsoft/global_misc.hpp @@ -3,6 +3,10 @@ #include "sharpsoft/basic_types.hpp" #include "sharpsoft/window_types.hpp" +#define SHARPSOFT_INTERNAL +#include "internal.hpp" +#undef SHARPSOFT_INTERNAL + namespace sharp { constexpr int screen_width = 480, screen_height = 240; @@ -21,6 +25,13 @@ namespace sharp void re_initialize(const global_properties& flags); bool is_initialized(); + template + void add_window(T window) + { + static_assert(std::is_base_of::value); + internal::add_window(&window, sizeof(T)); + } + void start(); void end(); bool is_started(); diff --git a/include/sharpsoft/internal.hpp b/include/sharpsoft/internal.hpp new file mode 100644 index 0000000..4838372 --- /dev/null +++ b/include/sharpsoft/internal.hpp @@ -0,0 +1,13 @@ +#pragma once + +#ifdef SHARPSOFT_INTERNAL +#include "window_types.hpp" + +namespace sharp +{ + namespace internal + { + void add_window(window_base* win_ptr, size_t size); + } +} +#endif diff --git a/include/sharpsoft/window_types.hpp b/include/sharpsoft/window_types.hpp index bb33dff..d95f79b 100644 --- a/include/sharpsoft/window_types.hpp +++ b/include/sharpsoft/window_types.hpp @@ -18,6 +18,9 @@ namespace sharp protected: window_base(const std::string& title, const int2& pos, const int2& size); +#ifdef SHARPSOFT_INTERNAL + public: +#endif virtual void paint() = 0; public: diff --git a/project.pros b/project.pros index cb89b4f..7dc2a93 100644 --- a/project.pros +++ b/project.pros @@ -398,7 +398,8 @@ } }, "upload_options": { - "description": "Demo project for Sharpsoft. Currently contains the library's code. May be moved elsewhere in the future." + "description": "Demo project for Sharpsoft. Currently contains the library's code. May be moved elsewhere in the future.", + "slot": 3 }, "use_early_access": true } diff --git a/src/main.cpp b/src/main.cpp index 17f8e10..896e150 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,18 +5,20 @@ // Including `using namespace sharp;` is not recommended. class test_window : public sharp::window_base -{ +{ protected: void paint() override { - + printf("Printed: %d", test_variable); } public: test_window() : window_base("Testing", sharp::int2(10, 10), sharp::int2(150, 100)) { - + } + + int test_variable; }; void initialize() @@ -25,7 +27,9 @@ void initialize() sharp::initialize(); test_window moment = test_window(); + moment.test_variable = 3; + sharp::add_window(&moment); sharp::start(); } diff --git a/src/sharpsoft/global_manager.cpp b/src/sharpsoft/global_manager.cpp index 92e3d88..f520446 100644 --- a/src/sharpsoft/global_manager.cpp +++ b/src/sharpsoft/global_manager.cpp @@ -1,6 +1,12 @@ +#define SHARPSOFT_INTERNAL + +#include +#include #include "sharpsoft/global_misc.hpp" +#include "sharpsoft/internal.hpp" using namespace sharp; +using std::vector; const global_properties global_properties::defaults = { @@ -11,6 +17,8 @@ bool init = false; bool started = false; color back_col; +vector windows; + void sharp::initialize() { if (init) return; @@ -57,6 +65,21 @@ bool sharp::is_initialized() return init; } +void sharp::internal::add_window(window_base* win_ptr, size_t size) +{ + void* copy_raw = malloc(size); + memcpy(copy_raw, (void*)(win_ptr), size); + + window_base* copy = (window_base*)copy_raw; + windows.push_back(copy); +} + +void sharp::test() +{ + window_base* item = windows.at(0); + item->paint(); +} + void sharp::start() { if (!init || started) return;