Window copying works for the most part. Tested on brain.

This commit is contained in:
That_One_Nerd 2024-05-23 13:03:07 -04:00
parent 29aa27267f
commit 7394df0f62
6 changed files with 59 additions and 4 deletions

View File

@ -3,6 +3,10 @@
#include "sharpsoft/basic_types.hpp" #include "sharpsoft/basic_types.hpp"
#include "sharpsoft/window_types.hpp" #include "sharpsoft/window_types.hpp"
#define SHARPSOFT_INTERNAL
#include "internal.hpp"
#undef SHARPSOFT_INTERNAL
namespace sharp namespace sharp
{ {
constexpr int screen_width = 480, screen_height = 240; constexpr int screen_width = 480, screen_height = 240;
@ -21,6 +25,13 @@ namespace sharp
void re_initialize(const global_properties& flags); void re_initialize(const global_properties& flags);
bool is_initialized(); bool is_initialized();
template<typename T>
void add_window(T window)
{
static_assert(std::is_base_of<window_base, T>::value);
internal::add_window(&window, sizeof(T));
}
void start(); void start();
void end(); void end();
bool is_started(); bool is_started();

View File

@ -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

View File

@ -18,6 +18,9 @@ namespace sharp
protected: protected:
window_base(const std::string& title, const int2& pos, const int2& size); window_base(const std::string& title, const int2& pos, const int2& size);
#ifdef SHARPSOFT_INTERNAL
public:
#endif
virtual void paint() = 0; virtual void paint() = 0;
public: public:

View File

@ -398,7 +398,8 @@
} }
}, },
"upload_options": { "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 "use_early_access": true
} }

View File

@ -5,18 +5,20 @@
// Including `using namespace sharp;` is not recommended. // Including `using namespace sharp;` is not recommended.
class test_window : public sharp::window_base class test_window : public sharp::window_base
{ {
protected: protected:
void paint() override void paint() override
{ {
printf("Printed: %d", test_variable);
} }
public: public:
test_window() : window_base("Testing", sharp::int2(10, 10), sharp::int2(150, 100)) test_window() : window_base("Testing", sharp::int2(10, 10), sharp::int2(150, 100))
{ {
} }
int test_variable;
}; };
void initialize() void initialize()
@ -25,7 +27,9 @@ void initialize()
sharp::initialize(); sharp::initialize();
test_window moment = test_window(); test_window moment = test_window();
moment.test_variable = 3;
sharp::add_window(&moment);
sharp::start(); sharp::start();
} }

View File

@ -1,6 +1,12 @@
#define SHARPSOFT_INTERNAL
#include <string.h>
#include <vector>
#include "sharpsoft/global_misc.hpp" #include "sharpsoft/global_misc.hpp"
#include "sharpsoft/internal.hpp"
using namespace sharp; using namespace sharp;
using std::vector;
const global_properties global_properties::defaults = const global_properties global_properties::defaults =
{ {
@ -11,6 +17,8 @@ bool init = false;
bool started = false; bool started = false;
color back_col; color back_col;
vector<window_base*> windows;
void sharp::initialize() void sharp::initialize()
{ {
if (init) return; if (init) return;
@ -57,6 +65,21 @@ bool sharp::is_initialized()
return init; 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() void sharp::start()
{ {
if (!init || started) return; if (!init || started) return;