From 339f8bd60237604aa1537a06724cc52d3b71f00c Mon Sep 17 00:00:00 2001 From: That_One_Nerd Date: Mon, 29 Apr 2024 20:47:00 -0400 Subject: [PATCH] More basic stuff. Soon we'll get into the actual rendering, but that's not quite yet. --- include/sharpsoft/all.hpp | 1 + include/sharpsoft/basic_types.hpp | 10 ++++++++ include/sharpsoft/global_misc.hpp | 7 +++++- include/sharpsoft/window_types.hpp | 23 +++++++++++++++++++ src/main.cpp | 2 ++ src/sharpsoft/basic_types.cpp | 23 ++++++++++++++++++- src/sharpsoft/global_manager.cpp | 28 ++++++++++++++++++++++ src/sharpsoft/window_base.cpp | 37 ++++++++++++++++++++++++++++++ 8 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 include/sharpsoft/window_types.hpp create mode 100644 src/sharpsoft/window_base.cpp diff --git a/include/sharpsoft/all.hpp b/include/sharpsoft/all.hpp index e4c26bb..c80b831 100644 --- a/include/sharpsoft/all.hpp +++ b/include/sharpsoft/all.hpp @@ -1,2 +1,3 @@ #include "basic_types.hpp" #include "global_misc.hpp" +#include "window_types.hpp" diff --git a/include/sharpsoft/basic_types.hpp b/include/sharpsoft/basic_types.hpp index 7486fa5..a06c136 100644 --- a/include/sharpsoft/basic_types.hpp +++ b/include/sharpsoft/basic_types.hpp @@ -41,4 +41,14 @@ namespace sharp operator int2() const; }; + + struct int_rect + { + int left, top; + int width, height; + + int_rect(); + int_rect(int left, int top, int width, int height); + int_rect(const int2 pos, const int2 size); + }; } diff --git a/include/sharpsoft/global_misc.hpp b/include/sharpsoft/global_misc.hpp index 2adb910..7472981 100644 --- a/include/sharpsoft/global_misc.hpp +++ b/include/sharpsoft/global_misc.hpp @@ -4,6 +4,8 @@ namespace sharp { + constexpr int screen_width = 480, screen_height = 240; + struct global_properties { static const global_properties defaults; @@ -16,6 +18,9 @@ namespace sharp void uninitialize(); void re_initialize(); void re_initialize(const global_properties& flags); - bool is_initialized(); + + void start(); + void end(); + bool is_started(); } diff --git a/include/sharpsoft/window_types.hpp b/include/sharpsoft/window_types.hpp new file mode 100644 index 0000000..020a234 --- /dev/null +++ b/include/sharpsoft/window_types.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include "sharpsoft/basic_types.hpp" + +namespace sharp +{ + class window_base + { + private: + uint16_t posX, posY; + uint16_t width, height; + + public: + const int2 get_pos() const; + const int2 get_size() const; + const int_rect get_window_rect() const; + + void set_pos(const int2& new_pos); + void set_size(const int2& new_size); + void set_window_rect(const int_rect& new_rect); + }; +} diff --git a/src/main.cpp b/src/main.cpp index 3feaeaa..c57e30f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,8 @@ void initialize() { // Initialize Sharpsoft. sharp::initialize(); + + sharp::start(); } void disabled() { } diff --git a/src/sharpsoft/basic_types.cpp b/src/sharpsoft/basic_types.cpp index 9f64610..42431b0 100644 --- a/src/sharpsoft/basic_types.cpp +++ b/src/sharpsoft/basic_types.cpp @@ -3,7 +3,6 @@ using namespace sharp; - sharp::color::color() { r = 0; @@ -87,3 +86,25 @@ sharp::float2::operator int2() const { return int2(x, y); }; + +sharp::int_rect::int_rect() +{ + left = 0; + top = 0; + width = 0; + height = 0; +} +sharp::int_rect::int_rect(int left, int top, int width, int height) +{ + this->left = left; + this->top = top; + this->width = width; + this->height = height; +} +sharp::int_rect::int_rect(const int2 pos, const int2 size) +{ + left = pos.x; + top = pos.y; + width = size.x; + height = size.y; +} diff --git a/src/sharpsoft/global_manager.cpp b/src/sharpsoft/global_manager.cpp index 25cabff..92e3d88 100644 --- a/src/sharpsoft/global_manager.cpp +++ b/src/sharpsoft/global_manager.cpp @@ -8,6 +8,7 @@ const global_properties global_properties::defaults = }; bool init = false; +bool started = false; color back_col; void sharp::initialize() @@ -27,6 +28,7 @@ void sharp::initialize(const global_properties& props) void sharp::uninitialize() { if (!init) return; + if (started) sharp::end(); // TODO @@ -35,18 +37,44 @@ void sharp::uninitialize() void sharp::re_initialize() { + bool restart = started; if (!init) return; uninitialize(); initialize(); + if (restart) start(); } void sharp::re_initialize(const global_properties& props) { + bool restart = started; if (!init) return; uninitialize(); initialize(); + if (restart) start(); } bool sharp::is_initialized() { return init; } + +void sharp::start() +{ + if (!init || started) return; + + // TODO + + started = true; +} +void sharp::end() +{ + if (!init || !started) return; + + // TODO + + started = false; +} + +bool sharp::is_started() +{ + return started; +} diff --git a/src/sharpsoft/window_base.cpp b/src/sharpsoft/window_base.cpp new file mode 100644 index 0000000..48cca11 --- /dev/null +++ b/src/sharpsoft/window_base.cpp @@ -0,0 +1,37 @@ +#include "sharpsoft/window_types.hpp" + +using namespace sharp; + +const int2 sharp::window_base::get_pos() const +{ + return int2(posX, posY); +} +const int2 sharp::window_base::get_size() const +{ + return int2(width, height); +} +const int_rect sharp::window_base::get_window_rect() const +{ + return int_rect(posX, posY, width, height); +} + +void sharp::window_base::set_pos(const int2 &new_pos) +{ + // TODO: I'll have to re-render some parts. + posX = new_pos.x; + posY = new_pos.y; +} +void sharp::window_base::set_size(const int2& new_pos) +{ + // TODO: I'll have to re-render some parts. + width = new_pos.x; + height = new_pos.y; +} +void sharp::window_base::set_window_rect(const int_rect &new_rect) +{ + // TODO: I'll have to re-render some parts. + posX = new_rect.left; + posY = new_rect.top; + width = new_rect.width; + height = new_rect.height; +}