GUI Improvements with fonts and some underlying palette and bitmap code stuff

This commit is contained in:
Justin Scofield
2022-06-11 13:51:02 -04:00
parent ce9ac5383e
commit 0de51934ab
19 changed files with 2842 additions and 224 deletions

View File

@@ -16,25 +16,25 @@ namespace Graphics {
using byte = unsigned char;
class Bitmap {
public:
Bitmap()=default;
Bitmap(int width, int height, byte* data);
public:
Bitmap() = default;
Bitmap(int width, int height, byte *data);
void Create(GLuint* out_texture);
void Create(GLuint *out_texture);
int GetWidth();
int GetHeight();
bool LoadBitmapFromROM(unsigned char* texture_data, GLuint* out_texture,
int* out_width, int* out_height);
bool LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture,
int *out_width, int *out_height);
private:
private:
int width_;
int height_;
byte* pixel_data_;
byte *pixel_data_;
SDL_PixelFormat pixel_format_;
};
} // namespace Graphics
} // namespace Application
} // namespace yaze
} // namespace Graphics
} // namespace Application
} // namespace yaze
#endif

View File

@@ -7,42 +7,36 @@ namespace yaze {
namespace Application {
namespace Graphics {
r_palette* palette_create(const unsigned int size, const unsigned int id)
{
r_palette *new_pal = (r_palette*) malloc(sizeof(r_palette));
new_pal->colors = (m_color*) malloc(sizeof(m_color) * size);
r_palette* palette_create(const unsigned int size, const unsigned int id) {
r_palette* new_pal = (r_palette*)malloc(sizeof(r_palette));
new_pal->colors = (m_color*)malloc(sizeof(m_color) * size);
new_pal->id = id;
new_pal->size = size;
return new_pal;
}
void palette_free(r_palette* tofree)
{
void palette_free(r_palette* tofree) {
free(tofree->colors);
free(tofree);
}
r_palette *palette_extract(const char* data, const unsigned int offset, const unsigned int palette_size)
{
r_palette* palette_extract(const char* data, const unsigned int offset,
const unsigned int palette_size) {
r_palette* toret = palette_create(palette_size, 0);
unsigned colnum = 0;
for (int i = 0; i < palette_size * 2; i += 2)
{
for (int i = 0; i < palette_size * 2; i += 2) {
unsigned short snes_color;
snes_color = ((uchar) data[offset + i + 1]) << 8;
snes_color = snes_color | ((uchar) data[offset + i]);
snes_color = ((uchar)data[offset + i + 1]) << 8;
snes_color = snes_color | ((uchar)data[offset + i]);
toret->colors[colnum] = convertcolor_snes_to_rgb(snes_color);
colnum++;
}
return toret;
}
char* palette_convert(const r_palette pal)
{
char* toret = (char*) malloc(pal.size * 2);
for (unsigned int i = 0; i < pal.size; i++)
{
char* palette_convert(const r_palette pal) {
char* toret = (char*)malloc(pal.size * 2);
for (unsigned int i = 0; i < pal.size; i++) {
unsigned short snes_data = convertcolor_rgb_to_snes(pal.colors[i]);
toret[i * 2] = snes_data & 0xFF;
toret[i * 2 + 1] = snes_data >> 8;
@@ -50,12 +44,11 @@ char* palette_convert(const r_palette pal)
return toret;
}
m_color convertcolor_snes_to_rgb(const unsigned short snes_color)
{
m_color convertcolor_snes_to_rgb(const unsigned short snes_color) {
m_color toret;
toret.red = ((snes_color ) % 32) * 8;
toret.green = ((snes_color / 32) % 32) * 8;
toret.red = ((snes_color) % 32) * 8;
toret.green = ((snes_color / 32) % 32) * 8;
toret.blue = ((snes_color / 1024) % 32) * 8;
toret.red = toret.red + toret.red / 32;
@@ -64,13 +57,12 @@ m_color convertcolor_snes_to_rgb(const unsigned short snes_color)
return toret;
}
unsigned short convertcolor_rgb_to_snes(const m_color color)
{
unsigned short convertcolor_rgb_to_snes(const m_color color) {
return convertcolor_rgb_to_snes2(color.red, color.green, color.blue);
}
unsigned short convertcolor_rgb_to_snes2(const uchar red, const uchar green, const uchar blue)
{
unsigned short convertcolor_rgb_to_snes2(const uchar red, const uchar green,
const uchar blue) {
uchar R = red / 8;
uchar G = green / 8;
uchar B = blue / 8;
@@ -78,6 +70,6 @@ unsigned short convertcolor_rgb_to_snes2(const uchar red, const uchar green, co
return B * 1024 + G * 32 + R;
}
}
}
}
} // namespace Graphics
} // namespace Application
} // namespace yaze