More basic stuff. Soon we'll get into the actual rendering, but that's not quite yet.

This commit is contained in:
That_One_Nerd 2024-04-29 20:47:00 -04:00
parent 16b1636316
commit 339f8bd602
8 changed files with 129 additions and 2 deletions

View File

@ -1,2 +1,3 @@
#include "basic_types.hpp"
#include "global_misc.hpp"
#include "window_types.hpp"

View File

@ -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);
};
}

View File

@ -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();
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <inttypes.h>
#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);
};
}

View File

@ -8,6 +8,8 @@ void initialize()
{
// Initialize Sharpsoft.
sharp::initialize();
sharp::start();
}
void disabled() { }

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}