Some color and background stuff. Small stuff for now.
This commit is contained in:
parent
bee1428a35
commit
16b1636316
@ -1 +1,2 @@
|
|||||||
|
#include "basic_types.hpp"
|
||||||
#include "global_misc.hpp"
|
#include "global_misc.hpp"
|
||||||
|
|||||||
44
include/sharpsoft/basic_types.hpp
Normal file
44
include/sharpsoft/basic_types.hpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -1,10 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "sharpsoft/basic_types.hpp"
|
||||||
|
|
||||||
namespace sharp
|
namespace sharp
|
||||||
{
|
{
|
||||||
struct global_properties
|
struct global_properties
|
||||||
{
|
{
|
||||||
static const global_properties defaults;
|
static const global_properties defaults;
|
||||||
|
|
||||||
|
color background_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
89
src/sharpsoft/basic_types.cpp
Normal file
89
src/sharpsoft/basic_types.cpp
Normal file
@ -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);
|
||||||
|
};
|
||||||
52
src/sharpsoft/global_manager.cpp
Normal file
52
src/sharpsoft/global_manager.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user