diff --git a/include/sharpsoft/all.hpp b/include/sharpsoft/all.hpp index 290f937..e4c26bb 100644 --- a/include/sharpsoft/all.hpp +++ b/include/sharpsoft/all.hpp @@ -1 +1,2 @@ +#include "basic_types.hpp" #include "global_misc.hpp" diff --git a/include/sharpsoft/basic_types.hpp b/include/sharpsoft/basic_types.hpp new file mode 100644 index 0000000..7486fa5 --- /dev/null +++ b/include/sharpsoft/basic_types.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include + +namespace sharp +{ + struct color + { + uint8_t r, g, b, a; + + color(); + color(uint8_t r, uint8_t g, uint8_t b); + color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); + color(uint32_t rgb, uint8_t a); + color(uint32_t argb); + + uint32_t get_value() const; + }; + + struct float2; + + struct int2 + { + int x, y; + + int2(); + int2(int x, int y); + + double magnitude() const; + + operator float2() const; + }; + struct float2 + { + double x, y; + + float2(); + float2(double x, double y); + + double magnitude() const; + + operator int2() const; + }; +} diff --git a/include/sharpsoft/global_misc.hpp b/include/sharpsoft/global_misc.hpp index 4b5b969..2adb910 100644 --- a/include/sharpsoft/global_misc.hpp +++ b/include/sharpsoft/global_misc.hpp @@ -1,10 +1,14 @@ #pragma once +#include "sharpsoft/basic_types.hpp" + namespace sharp { struct global_properties { static const global_properties defaults; + + color background_color; }; void initialize(); diff --git a/include/sharpsoft/src/global_manager.cpp b/include/sharpsoft/src/global_manager.cpp deleted file mode 100644 index 8960e8a..0000000 --- a/include/sharpsoft/src/global_manager.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "sharpsoft/global_misc.hpp" - -using namespace sharp; - -const global_properties global_properties::defaults = { }; // TODO - -bool initialized = false; - -void sharp::initialize() -{ - if (initialized) return; - initialize(global_properties::defaults); -} -void sharp::initialize(const global_properties& flags) -{ - if (initialized) return; - - // TODO - - initialized = true; -} - -void sharp::uninitialize() -{ - if (!initialized) return; - - // TODO - - initialized = false; -} - -void sharp::re_initialize() -{ - if (!initialized) return; - uninitialize(); - initialize(); -} -void sharp::re_initialize(const global_properties& flags) -{ - if (!initialized) return; - uninitialize(); - initialize(); -} - -bool sharp::is_initialized() -{ - return initialized; -} diff --git a/src/sharpsoft/basic_types.cpp b/src/sharpsoft/basic_types.cpp new file mode 100644 index 0000000..9f64610 --- /dev/null +++ b/src/sharpsoft/basic_types.cpp @@ -0,0 +1,89 @@ +#include "math.h" +#include "sharpsoft/basic_types.hpp" + +using namespace sharp; + + +sharp::color::color() +{ + r = 0; + g = 0; + b = 0; + a = 0; +} +sharp::color::color(uint8_t r, uint8_t g, uint8_t b) +{ + this->r = r; + this->g = g; + this->b = b; + a = 0; +} +sharp::color::color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} +sharp::color::color(uint32_t rgb, uint8_t a) +{ + constexpr uint32_t bytemask = 0b11111111; + this->a = a; + r = (rgb >> 16) & bytemask; + g = (rgb >> 8) & bytemask; + b = (rgb ) & bytemask; +} +sharp::color::color(uint32_t argb) +{ + constexpr uint32_t bytemask = 0b11111111; + a = (argb >> 24); // bytemask not needed. + r = (argb >> 16) & bytemask; + g = (argb >> 8) & bytemask; + b = (argb ) & bytemask; +} + +uint32_t sharp::color::get_value() const +{ + return (b ) + + (g << 8) + + (r << 16) + + (a << 24); +} + +sharp::int2::int2() +{ + x = 0; + y = 0; +} +sharp::int2::int2(int x, int y) +{ + this->x = x; + this->y = y; +} +double sharp::int2::magnitude() const +{ + return sqrt(x * x + y * y); +} +sharp::int2::operator float2() const +{ + return float2(x, y); +} + +sharp::float2::float2() +{ + x = 0; + y = 0; +} +sharp::float2::float2(double x, double y) +{ + this->x = x; + this->y = y; +} +double sharp::float2::magnitude() const +{ + return sqrt(x * x + y * y); +} +sharp::float2::operator int2() const +{ + return int2(x, y); +}; diff --git a/src/sharpsoft/global_manager.cpp b/src/sharpsoft/global_manager.cpp new file mode 100644 index 0000000..25cabff --- /dev/null +++ b/src/sharpsoft/global_manager.cpp @@ -0,0 +1,52 @@ +#include "sharpsoft/global_misc.hpp" + +using namespace sharp; + +const global_properties global_properties::defaults = +{ + 0x95d9ed +}; + +bool init = false; +color back_col; + +void sharp::initialize() +{ + if (init) return; + sharp::initialize(global_properties::defaults); +} +void sharp::initialize(const global_properties& props) +{ + if (init) return; + + back_col = props.background_color; + + init = true; +} + +void sharp::uninitialize() +{ + if (!init) return; + + // TODO + + init = false; +} + +void sharp::re_initialize() +{ + if (!init) return; + uninitialize(); + initialize(); +} +void sharp::re_initialize(const global_properties& props) +{ + if (!init) return; + uninitialize(); + initialize(); +} + +bool sharp::is_initialized() +{ + return init; +}