Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/SB/Core/gc/iColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ICOLOR_H

#include <types.h>
#include <xHud.h>

struct iColor_tag
{
Expand All @@ -18,6 +19,16 @@ struct iColor_tag
this->a = rhs.a;
return *this;
};

// Conversion constructor instead?
iColor_tag& operator=(const xhud::color32u& rhs)
{
this->r = rhs.r;
this->g = rhs.g;
this->b = rhs.b;
this->a = rhs.a;
return *this;
};
};

#endif
180 changes: 180 additions & 0 deletions src/SB/Core/x/xHudFontMeter.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,183 @@
#include "xHudFontMeter.h"

#include <types.h>
#include <xMath2.h>
#include <PowerPC_EABI_Support\MSL_C\MSL_Common\printf.h>
#include <PowerPC_EABI_Support\MSL_C++\MSL_Common\Include\new.h>

void xhud::font_meter_widget::load(xBase& data, xDynAsset& asset, u32 size_t)
{
// Stubbed out for now for causing build failure. 100% match locally though if method redefined to be nonstatic.
// widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10);
// new (&this->rc.size)
// xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value
}

xhud::font_meter_widget::font_meter_widget(xhud::font_meter_asset& init) : meter_widget(init)
{
basic_rect<F32> screen_bounds;

this->font.id = init.font.id;
this->font.justify = init.font.justify;
this->start_font.id = init.font.id;
this->start_font.justify = init.font.justify;

// No assembly for this operator but bytewise is too many instructions
this->font.c = init.font.c;
this->start_font.c = init.font.c;
this->font.drop_c = init.font.drop_c;
this->start_font.drop_c = init.font.drop_c;

this->last_value = ((S32)(this->value)) - 20;
this->xf.id = 0;
this->xf.width = this->font.w;
this->xf.height = this->font.h;
this->xf.space = this->font.space;

this->xf.color = this->font.c;
this->xf.clip = screen_bounds;
}

void xhud::font_meter_widget::destruct()
{
xhud::meter_widget::destruct();
}

void xhud::font_meter_widget::destroy()
{
this->destruct();
}

U32 xhud::font_meter_widget::type()
{
static S8 init;
static U32 myid;

if (init == 0)
{
myid = xStrHash(((xhud::font_meter_asset*)this)->type_name());
init = 1;
}
return myid;
}

U8 xhud::font_meter_widget::is(U32 id)
{
U8 val = 0;

if ((id == this->type()) || (((xhud::meter_widget*)this->is(id)) != 0))
{
val = 1;
}
return val;
}

void xhud::font_meter_widget::update(F32 dt)

{
char* format_text[3];
format_text[0] = 0;

F32 a;
S32 new_value;
basic_rect<F32> bounds;

U8 flag_1;
U8 flag_2;

this->updater(dt);
this->xf.id = this->font.id;
this->xf.space = this->font.space;
a = this->rc.size.x;
this->font.w = a;
this->xf.width = a;
a = this->rc.size.y;
this->font.h = a;
this->xf.height = a;

a = this->rc.a * (F32)this->start_font.c.a + 0.5;
if (a <= 0.0)
{
flag_1 = 0;
}
else if (a >= 255.0)
{
flag_1 = 255;
}
else if (a < 2.1474836e+09)
{
flag_1 = (U8)(S32)a;
}
else
{
flag_1 = (U8)(S32)(a - 2.1474836e+09);
}
this->font.c.a = flag_1;

a = this->rc.a * (F32)this->start_font.drop_c.a + 0.5;
if (a <= 0.0)
{
flag_1 = 0;
}
else if (a >= 255.0)
{
flag_1 = 255;
}
else if (a < 2.1474836e+09)
{
flag_1 = (U8)(S32)a;
}
else
{
flag_1 = (U8)(S32)(a - 2.1474836e+09);
}
this->font.drop_c.a = flag_1;

new_value = (S32)(this->value + 0.5);
if (this->last_value != new_value)
{
this->last_value = new_value;
a = this->max_value;
if (a < this->min_value)
{
flag_2 = 0;
}
else
{
flag_2 = ((font_meter_asset*)(this->a))->counter_mode;
}
sprintf(this->buffer, format_text[flag_2], new_value, (S32)(a + 0.5));
bounds = this->xf.bounds(this->buffer);
this->offset.x = -bounds.x;
this->offset.y = -bounds.y;
}
return;
}

void xhud::font_meter_widget::render()

{
F32 x;
F32 temp_x;
F32 y;

temp_x = this->offset.x + this->rc.loc.x;
y = this->offset.y + this->rc.loc.y;
if (this->font.drop_c.a != 0)
{
this->xf.color = this->font.drop_c;
x = temp_x + this->font.drop_x;
this->xf.render(this->buffer, x, y + this->font.drop_y);
}
if (this->font.c.a != 0)
{
this->xf.color = this->font.c;
this->xf.render(this->buffer, temp_x, y);
}
return;
}

char* xhud::font_meter_asset::type_name()
{
return "hud:meter:font";
}
35 changes: 22 additions & 13 deletions src/SB/Core/x/xHudFontMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,36 @@ namespace xhud
color32u c;
color32u drop_c;
};

struct font_meter_asset : meter_asset
{
font_context font; // offset 0x4C, size 0x24
U8 counter_mode; // offset 0x70, size 0x1
U8 pad1; // offset 0x71, size 0x1
U8 pad2; // offset 0x72, size 0x1
U8 pad3; // offset 0x73, size 0x1
font_context font; // offset 0x4C, size 0x24
U8 counter_mode; // offset 0x70, size 0x1
U8 pad1; // offset 0x71, size 0x1
U8 pad2; // offset 0x72, size 0x1
U8 pad3; // offset 0x73, size 0x1

char* type_name();
};

struct font_meter_widget : meter_widget
{
font_context font;
font_context start_font;
S32 precision;
xVec2 offset;
char buffer[12];
S32 last_value;
xfont xf;
font_context font; // 0xC4
font_context start_font; // 0xE8
S32 precision; // 0x10C
xVec2 offset; // 0x110
char buffer[12]; // 0x118
S32 last_value; // 0x124
xfont xf; // 0x128

static void load(xBase& data, xDynAsset& asset, size_t);
font_meter_widget(xhud::font_meter_asset& init);
void destruct();
void destroy();
U32 type();
U8 is(U32 id);
void update(F32 dt);
void render();

font_meter_asset* get_asset()
{
Expand Down