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/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<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 end();
|
||||
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:
|
||||
window_base(const std::string& title, const int2& pos, const int2& size);
|
||||
|
||||
#ifdef SHARPSOFT_INTERNAL
|
||||
public:
|
||||
#endif
|
||||
virtual void paint() = 0;
|
||||
|
||||
public:
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
10
src/main.cpp
10
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();
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
#define SHARPSOFT_INTERNAL
|
||||
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#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<window_base*> 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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user