Window copying works for the most part. Tested on brain.
This commit is contained in:
parent
29aa27267f
commit
7394df0f62
@ -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();
|
||||||
|
|||||||
13
include/sharpsoft/internal.hpp
Normal file
13
include/sharpsoft/internal.hpp
Normal 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
|
||||||
@ -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:
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ class test_window : public sharp::window_base
|
|||||||
protected:
|
protected:
|
||||||
void paint() override
|
void paint() override
|
||||||
{
|
{
|
||||||
|
printf("Printed: %d", test_variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -17,6 +17,8 @@ public:
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user