Nice work so far. Internal flags, styles. Runs on V5.

This commit is contained in:
That_One_Nerd 2024-05-24 10:53:56 -04:00
parent ced7886a10
commit 5020e65bbf
9 changed files with 99 additions and 67 deletions

View File

@ -1,6 +1,5 @@
#include "basic_types.hpp"
#include "enums.hpp"
#include "global_misc.hpp"
#include "interop.hpp"
#include "macros.hpp"
#include "window_types.hpp"
#include "windowing.hpp"

View File

@ -1,12 +0,0 @@
#pragma once
#include <inttypes.h>
namespace sharp
{
enum window_flags : uint32_t
{
CONTINUOUS_PAINT = 0x01,
CONTINUOUS_TICK = 0x02,
};
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "sharpsoft/basic_types.hpp"
#include "sharpsoft/window_types.hpp"
#include "sharpsoft/windowing.hpp"
#define SHARPSOFT_INTERNAL
#include "internal.hpp"

View File

@ -2,9 +2,12 @@
#ifdef SHARPSOFT_INTERNAL
#include "basic_types.hpp"
#include "window_types.hpp"
#include "windowing.hpp"
#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
{

View File

@ -4,10 +4,30 @@
#include <inttypes.h>
#include <string>
#include "sharpsoft/basic_types.hpp"
#include "sharpsoft/enums.hpp"
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
{
#ifdef SHARPSOFT_INTERNAL
@ -19,12 +39,11 @@ namespace sharp
uint16_t width, height;
std::string title;
window_flags flags;
bool active, visible;
window_internal_flags int_flags;
window_styles styles;
bool header_validated;
bool content_validated;
void paint_header();
void paint_header() const;
void paint_content_back() const;
#ifndef SHARPSOFT_INTERNAL
protected:
@ -35,6 +54,9 @@ namespace sharp
virtual void tick() = 0;
public:
const window_styles& style() const;
window_styles& style();
bool get_flag(window_flags flag) const;
const int2 get_pos() const;
const int2 get_size() const;

View File

@ -9,20 +9,22 @@ class test_window : public sharp::window_base
protected:
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
{
printf("Tick called.\n");
}
public:
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()
@ -30,10 +32,7 @@ void initialize()
// Initialize Sharpsoft.
sharp::initialize();
test_window moment = test_window();
moment.test_variable = 3;
sharp::add_window(moment);
sharp::add_window(test_window());
sharp::start();
}

View File

@ -2,10 +2,10 @@
#include <string.h>
#include <vector>
#include "sharpsoft/enums.hpp"
#include "sharpsoft/global_misc.hpp"
#include "sharpsoft/internal.hpp"
#include "sharpsoft/interop.hpp"
#include "sharpsoft/windowing.hpp"
using namespace sharp;
using std::vector;
@ -86,18 +86,22 @@ void sharp::internal::render_iter()
if (HAS_WINDOW_FLAG(win, CONTINUOUS_TICK)) win->tick();
// 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.
if (!win->content_validated)
{
win->paint();
win->content_validated = true;
}
if (!win->header_validated)
if (!HAS_INTERNAL_FLAG(win, WINDOW_HEADER_VALIDATED))
{
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;
windows.push_back(copy);
copy->active = true;
ON_INTERNAL_FLAG(copy, WINDOW_ACTIVE);
}
void sharp::start()

View File

@ -2,7 +2,7 @@
#include "sharpsoft/internal.hpp"
#include "sharpsoft/macros.hpp"
#include "sharpsoft/window_types.hpp"
#include "sharpsoft/windowing.hpp"
#ifdef SH_PROS_ACTIVE
#include "pros/screen.hpp"
@ -23,9 +23,13 @@ void internal::fill_global_rectangle(const color& color, const int_rect& rect)
}
#endif
void window_base::paint_header()
void window_base::paint_header() const
{
// Draw outline.
const color outline_color = color(255, 255, 255);
internal::draw_global_rectangle(outline_color, int_rect(posX - 1, posY - 1, width + 1, height + 1));
internal::draw_global_rectangle(styles.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));
}

View File

@ -1,9 +1,17 @@
#include "enums.hpp"
#include "sharpsoft/window_types.hpp"
#define SHARPSOFT_INTERNAL
#include "sharpsoft/internal.hpp"
#include "sharpsoft/windowing.hpp"
using std::string;
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)
{
this->title = title;
@ -12,13 +20,18 @@ sharp::window_base::window_base(const string& title, const int2& pos, const int2
width = size.x;
height = size.y;
flags = (window_flags)0;
active = false;
visible = true;
header_validated = false;
content_validated = false;
int_flags = WINDOW_VISIBLE;
styles = window_styles::defaults;
}
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
{
return (flags & flag) > 0;
@ -41,11 +54,11 @@ const string sharp::window_base::get_title() const
}
bool sharp::window_base::is_active() const
{
return active;
return HAS_INTERNAL_FLAG(this, WINDOW_ACTIVE);
}
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)
@ -66,8 +79,8 @@ void sharp::window_base::set_pos(const int2& new_pos)
posX = new_pos.x;
posY = new_pos.y;
header_validated = false;
content_validated = false;
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
}
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;
height = new_pos.y;
header_validated = false;
content_validated = false;
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
}
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;
width = new_rect.width;
height = new_rect.height;
header_validated = false;
content_validated = false;
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
}
void sharp::window_base::set_title(const std::string& new_title)
{
title = new_title;
header_validated = false;
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
}
void sharp::window_base::invalidate()
{
header_validated = false;
content_validated = false;
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
}
void sharp::window_base::hide()
{
// TODO: This will affect the renderer
visible = false;
OFF_INTERNAL_FLAG(this, WINDOW_VISIBLE);
}
void sharp::window_base::show()
{
// TODO: This will affect the renderer
visible = true;
header_validated = false;
content_validated = false;
ON_INTERNAL_FLAG(this, WINDOW_VISIBLE);
OFF_INTERNAL_FLAG(this, WINDOW_HEADER_VALIDATED);
OFF_INTERNAL_FLAG(this, WINDOW_CONTENT_VALIDATED);
}