Nice work so far. Internal flags, styles. Runs on V5.
This commit is contained in:
parent
ced7886a10
commit
5020e65bbf
@ -1,6 +1,5 @@
|
|||||||
#include "basic_types.hpp"
|
#include "basic_types.hpp"
|
||||||
#include "enums.hpp"
|
|
||||||
#include "global_misc.hpp"
|
#include "global_misc.hpp"
|
||||||
#include "interop.hpp"
|
#include "interop.hpp"
|
||||||
#include "macros.hpp"
|
#include "macros.hpp"
|
||||||
#include "window_types.hpp"
|
#include "windowing.hpp"
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
namespace sharp
|
|
||||||
{
|
|
||||||
enum window_flags : uint32_t
|
|
||||||
{
|
|
||||||
CONTINUOUS_PAINT = 0x01,
|
|
||||||
CONTINUOUS_TICK = 0x02,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sharpsoft/basic_types.hpp"
|
#include "sharpsoft/basic_types.hpp"
|
||||||
#include "sharpsoft/window_types.hpp"
|
#include "sharpsoft/windowing.hpp"
|
||||||
|
|
||||||
#define SHARPSOFT_INTERNAL
|
#define SHARPSOFT_INTERNAL
|
||||||
#include "internal.hpp"
|
#include "internal.hpp"
|
||||||
|
|||||||
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
#ifdef SHARPSOFT_INTERNAL
|
#ifdef SHARPSOFT_INTERNAL
|
||||||
#include "basic_types.hpp"
|
#include "basic_types.hpp"
|
||||||
#include "window_types.hpp"
|
#include "windowing.hpp"
|
||||||
|
|
||||||
#define HAS_WINDOW_FLAG(pwin, flag) ((pwin->flags & flag) > 0)
|
#define HAS_WINDOW_FLAG(pwin, flag) ((pwin->flags & flag) > 0)
|
||||||
|
#define HAS_INTERNAL_FLAG(pwin, flag) ((pwin->int_flags & flag) > 0)
|
||||||
|
#define ON_INTERNAL_FLAG(pwin, flag) pwin->int_flags = (window_internal_flags)(pwin->int_flags | flag)
|
||||||
|
#define OFF_INTERNAL_FLAG(pwin, flag) pwin->int_flags = (window_internal_flags)(pwin->int_flags & ~flag)
|
||||||
|
|
||||||
namespace sharp
|
namespace sharp
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,10 +4,30 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "sharpsoft/basic_types.hpp"
|
#include "sharpsoft/basic_types.hpp"
|
||||||
#include "sharpsoft/enums.hpp"
|
|
||||||
|
|
||||||
namespace sharp
|
namespace sharp
|
||||||
{
|
{
|
||||||
|
enum window_flags : uint32_t
|
||||||
|
{
|
||||||
|
CONTINUOUS_PAINT = 0x01,
|
||||||
|
CONTINUOUS_TICK = 0x02,
|
||||||
|
};
|
||||||
|
enum window_internal_flags : uint32_t
|
||||||
|
{
|
||||||
|
WINDOW_ACTIVE = 0x01,
|
||||||
|
WINDOW_VISIBLE = 0x02,
|
||||||
|
WINDOW_HEADER_VALIDATED = 0x04,
|
||||||
|
WINDOW_CONTENT_VALIDATED = 0x08
|
||||||
|
};
|
||||||
|
|
||||||
|
struct window_styles
|
||||||
|
{
|
||||||
|
static const window_styles defaults;
|
||||||
|
|
||||||
|
color background_color;
|
||||||
|
color outline_color;
|
||||||
|
};
|
||||||
|
|
||||||
class window_base
|
class window_base
|
||||||
{
|
{
|
||||||
#ifdef SHARPSOFT_INTERNAL
|
#ifdef SHARPSOFT_INTERNAL
|
||||||
@ -19,12 +39,11 @@ namespace sharp
|
|||||||
uint16_t width, height;
|
uint16_t width, height;
|
||||||
std::string title;
|
std::string title;
|
||||||
window_flags flags;
|
window_flags flags;
|
||||||
bool active, visible;
|
window_internal_flags int_flags;
|
||||||
|
window_styles styles;
|
||||||
|
|
||||||
bool header_validated;
|
void paint_header() const;
|
||||||
bool content_validated;
|
void paint_content_back() const;
|
||||||
|
|
||||||
void paint_header();
|
|
||||||
|
|
||||||
#ifndef SHARPSOFT_INTERNAL
|
#ifndef SHARPSOFT_INTERNAL
|
||||||
protected:
|
protected:
|
||||||
@ -35,6 +54,9 @@ namespace sharp
|
|||||||
virtual void tick() = 0;
|
virtual void tick() = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
const window_styles& style() const;
|
||||||
|
window_styles& style();
|
||||||
|
|
||||||
bool get_flag(window_flags flag) const;
|
bool get_flag(window_flags flag) const;
|
||||||
const int2 get_pos() const;
|
const int2 get_pos() const;
|
||||||
const int2 get_size() const;
|
const int2 get_size() const;
|
||||||
17
src/main.cpp
17
src/main.cpp
@ -9,20 +9,22 @@ class test_window : public sharp::window_base
|
|||||||
protected:
|
protected:
|
||||||
void paint() override
|
void paint() override
|
||||||
{
|
{
|
||||||
printf("Paint called.\n");
|
static int frame = 0;
|
||||||
|
frame++;
|
||||||
|
|
||||||
|
sharp::color back_col(0, frame % 256, 0);
|
||||||
|
style().background_color = back_col;
|
||||||
}
|
}
|
||||||
void tick() override
|
void tick() override
|
||||||
{
|
{
|
||||||
printf("Tick called.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
||||||
{
|
{
|
||||||
set_flag(sharp::CONTINUOUS_TICK, true);
|
set_flag(sharp::CONTINUOUS_PAINT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_variable;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void initialize()
|
void initialize()
|
||||||
@ -30,10 +32,7 @@ void initialize()
|
|||||||
// Initialize Sharpsoft.
|
// Initialize Sharpsoft.
|
||||||
sharp::initialize();
|
sharp::initialize();
|
||||||
|
|
||||||
test_window moment = test_window();
|
sharp::add_window(test_window());
|
||||||
moment.test_variable = 3;
|
|
||||||
|
|
||||||
sharp::add_window(moment);
|
|
||||||
sharp::start();
|
sharp::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "sharpsoft/enums.hpp"
|
|
||||||
#include "sharpsoft/global_misc.hpp"
|
#include "sharpsoft/global_misc.hpp"
|
||||||
#include "sharpsoft/internal.hpp"
|
#include "sharpsoft/internal.hpp"
|
||||||
#include "sharpsoft/interop.hpp"
|
#include "sharpsoft/interop.hpp"
|
||||||
|
#include "sharpsoft/windowing.hpp"
|
||||||
|
|
||||||
using namespace sharp;
|
using namespace sharp;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
@ -86,18 +86,22 @@ void sharp::internal::render_iter()
|
|||||||
if (HAS_WINDOW_FLAG(win, CONTINUOUS_TICK)) win->tick();
|
if (HAS_WINDOW_FLAG(win, CONTINUOUS_TICK)) win->tick();
|
||||||
|
|
||||||
// Apply any possible invalidations.
|
// Apply any possible invalidations.
|
||||||
if (HAS_WINDOW_FLAG(win, CONTINUOUS_PAINT)) win->content_validated = false;
|
if (HAS_WINDOW_FLAG(win, CONTINUOUS_PAINT))
|
||||||
|
{
|
||||||
|
OFF_INTERNAL_FLAG(win, WINDOW_CONTENT_VALIDATED);
|
||||||
|
}
|
||||||
|
|
||||||
// Now render anything that is invalidated.
|
// Now render anything that is invalidated.
|
||||||
if (!win->content_validated)
|
if (!HAS_INTERNAL_FLAG(win, WINDOW_HEADER_VALIDATED))
|
||||||
{
|
|
||||||
win->paint();
|
|
||||||
win->content_validated = true;
|
|
||||||
}
|
|
||||||
if (!win->header_validated)
|
|
||||||
{
|
{
|
||||||
win->paint_header();
|
win->paint_header();
|
||||||
win->header_validated = true;
|
ON_INTERNAL_FLAG(win, WINDOW_HEADER_VALIDATED);
|
||||||
|
}
|
||||||
|
if (!HAS_INTERNAL_FLAG(win, WINDOW_CONTENT_VALIDATED))
|
||||||
|
{
|
||||||
|
win->paint_content_back();
|
||||||
|
win->paint();
|
||||||
|
ON_INTERNAL_FLAG(win, WINDOW_CONTENT_VALIDATED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +122,7 @@ void sharp::internal::add_window(window_base* win_ptr, size_t size)
|
|||||||
|
|
||||||
window_base* copy = (window_base*)copy_raw;
|
window_base* copy = (window_base*)copy_raw;
|
||||||
windows.push_back(copy);
|
windows.push_back(copy);
|
||||||
copy->active = true;
|
ON_INTERNAL_FLAG(copy, WINDOW_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sharp::start()
|
void sharp::start()
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sharpsoft/internal.hpp"
|
#include "sharpsoft/internal.hpp"
|
||||||
#include "sharpsoft/macros.hpp"
|
#include "sharpsoft/macros.hpp"
|
||||||
#include "sharpsoft/window_types.hpp"
|
#include "sharpsoft/windowing.hpp"
|
||||||
|
|
||||||
#ifdef SH_PROS_ACTIVE
|
#ifdef SH_PROS_ACTIVE
|
||||||
#include "pros/screen.hpp"
|
#include "pros/screen.hpp"
|
||||||
@ -23,9 +23,13 @@ void internal::fill_global_rectangle(const color& color, const int_rect& rect)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void window_base::paint_header()
|
void window_base::paint_header() const
|
||||||
{
|
{
|
||||||
// Draw outline.
|
// Draw outline.
|
||||||
const color outline_color = color(255, 255, 255);
|
internal::draw_global_rectangle(styles.outline_color, int_rect(posX - 1, posY - 1, width + 1, height + 1));
|
||||||
internal::draw_global_rectangle(outline_color, int_rect(posX - 1, posY - 1, width + 1, height + 1));
|
}
|
||||||
|
void window_base::paint_content_back() const
|
||||||
|
{
|
||||||
|
// Draw background.
|
||||||
|
internal::fill_global_rectangle(styles.background_color, int_rect(posX, posY, width, height));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,17 @@
|
|||||||
#include "enums.hpp"
|
#define SHARPSOFT_INTERNAL
|
||||||
#include "sharpsoft/window_types.hpp"
|
|
||||||
|
#include "sharpsoft/internal.hpp"
|
||||||
|
#include "sharpsoft/windowing.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using namespace sharp;
|
using namespace sharp;
|
||||||
|
|
||||||
|
const sharp::window_styles sharp::window_styles::defaults =
|
||||||
|
{
|
||||||
|
color(0, 0, 0),
|
||||||
|
color(255, 255, 255)
|
||||||
|
};
|
||||||
|
|
||||||
sharp::window_base::window_base(const string& title, const int2& pos, const int2& size)
|
sharp::window_base::window_base(const string& title, const int2& pos, const int2& size)
|
||||||
{
|
{
|
||||||
this->title = title;
|
this->title = title;
|
||||||
@ -12,13 +20,18 @@ sharp::window_base::window_base(const string& title, const int2& pos, const int2
|
|||||||
width = size.x;
|
width = size.x;
|
||||||
height = size.y;
|
height = size.y;
|
||||||
flags = (window_flags)0;
|
flags = (window_flags)0;
|
||||||
active = false;
|
int_flags = WINDOW_VISIBLE;
|
||||||
visible = true;
|
styles = window_styles::defaults;
|
||||||
|
|
||||||
header_validated = false;
|
|
||||||
content_validated = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const window_styles& sharp::window_base::style() const
|
||||||
|
{
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
window_styles& sharp::window_base::style()
|
||||||
|
{
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
bool sharp::window_base::get_flag(window_flags flag) const
|
bool sharp::window_base::get_flag(window_flags flag) const
|
||||||
{
|
{
|
||||||
return (flags & flag) > 0;
|
return (flags & flag) > 0;
|
||||||
@ -41,11 +54,11 @@ const string sharp::window_base::get_title() const
|
|||||||
}
|
}
|
||||||
bool sharp::window_base::is_active() const
|
bool sharp::window_base::is_active() const
|
||||||
{
|
{
|
||||||
return active;
|
return HAS_INTERNAL_FLAG(this, WINDOW_ACTIVE);
|
||||||
}
|
}
|
||||||
bool sharp::window_base::is_visible() const
|
bool sharp::window_base::is_visible() const
|
||||||
{
|
{
|
||||||
return visible;
|
return HAS_INTERNAL_FLAG(this, WINDOW_VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sharp::window_base::set_flag(window_flags flag, bool value)
|
void sharp::window_base::set_flag(window_flags flag, bool value)
|
||||||
@ -66,8 +79,8 @@ void sharp::window_base::set_pos(const int2& new_pos)
|
|||||||
|
|
||||||
posX = new_pos.x;
|
posX = new_pos.x;
|
||||||
posY = new_pos.y;
|
posY = new_pos.y;
|
||||||
header_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
|
||||||
content_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
|
||||||
}
|
}
|
||||||
void sharp::window_base::set_size(const int2& new_pos)
|
void sharp::window_base::set_size(const int2& new_pos)
|
||||||
{
|
{
|
||||||
@ -75,8 +88,8 @@ void sharp::window_base::set_size(const int2& new_pos)
|
|||||||
|
|
||||||
width = new_pos.x;
|
width = new_pos.x;
|
||||||
height = new_pos.y;
|
height = new_pos.y;
|
||||||
header_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
|
||||||
content_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
|
||||||
}
|
}
|
||||||
void sharp::window_base::set_window_rect(const int_rect& new_rect)
|
void sharp::window_base::set_window_rect(const int_rect& new_rect)
|
||||||
{
|
{
|
||||||
@ -86,32 +99,32 @@ void sharp::window_base::set_window_rect(const int_rect& new_rect)
|
|||||||
posY = new_rect.top;
|
posY = new_rect.top;
|
||||||
width = new_rect.width;
|
width = new_rect.width;
|
||||||
height = new_rect.height;
|
height = new_rect.height;
|
||||||
header_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
|
||||||
content_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
|
||||||
}
|
}
|
||||||
void sharp::window_base::set_title(const std::string& new_title)
|
void sharp::window_base::set_title(const std::string& new_title)
|
||||||
{
|
{
|
||||||
title = new_title;
|
title = new_title;
|
||||||
header_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sharp::window_base::invalidate()
|
void sharp::window_base::invalidate()
|
||||||
{
|
{
|
||||||
header_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
|
||||||
content_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sharp::window_base::hide()
|
void sharp::window_base::hide()
|
||||||
{
|
{
|
||||||
// TODO: This will affect the renderer
|
// TODO: This will affect the renderer
|
||||||
|
|
||||||
visible = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_VISIBLE);
|
||||||
}
|
}
|
||||||
void sharp::window_base::show()
|
void sharp::window_base::show()
|
||||||
{
|
{
|
||||||
// TODO: This will affect the renderer
|
// TODO: This will affect the renderer
|
||||||
|
|
||||||
visible = true;
|
ON_INTERNAL_FLAG(this, WINDOW_VISIBLE);
|
||||||
header_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
|
||||||
content_validated = false;
|
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user