|
1 | 1 | #include "xHudFontMeter.h" |
2 | 2 |
|
3 | 3 | #include <types.h> |
| 4 | +#include <xMath2.h> |
| 5 | +#include <PowerPC_EABI_Support\MSL_C\MSL_Common\printf.h> |
| 6 | +#include <PowerPC_EABI_Support\MSL_C++\MSL_Common\Include\new.h> |
| 7 | + |
| 8 | +void xhud::font_meter_widget::load(xBase& data, xDynAsset& asset, u32 size_t) |
| 9 | +{ |
| 10 | + // Stubbed out for now for causing build failure. 100% match locally though if method redefined to be nonstatic. |
| 11 | + // widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); |
| 12 | + // new (&this->rc.size) |
| 13 | + // xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value |
| 14 | +} |
| 15 | + |
| 16 | +xhud::font_meter_widget::font_meter_widget(xhud::font_meter_asset& init) : meter_widget(init) |
| 17 | +{ |
| 18 | + basic_rect<F32> screen_bounds; |
| 19 | + |
| 20 | + this->font.id = init.font.id; |
| 21 | + this->font.justify = init.font.justify; |
| 22 | + this->start_font.id = init.font.id; |
| 23 | + this->start_font.justify = init.font.justify; |
| 24 | + |
| 25 | + // No assembly for this operator but bytewise is too many instructions |
| 26 | + this->font.c = init.font.c; |
| 27 | + this->start_font.c = init.font.c; |
| 28 | + this->font.drop_c = init.font.drop_c; |
| 29 | + this->start_font.drop_c = init.font.drop_c; |
| 30 | + |
| 31 | + this->last_value = ((S32)(this->value)) - 20; |
| 32 | + this->xf.id = 0; |
| 33 | + this->xf.width = this->font.w; |
| 34 | + this->xf.height = this->font.h; |
| 35 | + this->xf.space = this->font.space; |
| 36 | + |
| 37 | + this->xf.color = this->font.c; |
| 38 | + this->xf.clip = screen_bounds; |
| 39 | +} |
| 40 | + |
| 41 | +void xhud::font_meter_widget::destruct() |
| 42 | +{ |
| 43 | + xhud::meter_widget::destruct(); |
| 44 | +} |
| 45 | + |
| 46 | +void xhud::font_meter_widget::destroy() |
| 47 | +{ |
| 48 | + this->destruct(); |
| 49 | +} |
| 50 | + |
| 51 | +U32 xhud::font_meter_widget::type() |
| 52 | +{ |
| 53 | + static S8 init; |
| 54 | + static U32 myid; |
| 55 | + |
| 56 | + if (init == 0) |
| 57 | + { |
| 58 | + myid = xStrHash(((xhud::font_meter_asset*)this)->type_name()); |
| 59 | + init = 1; |
| 60 | + } |
| 61 | + return myid; |
| 62 | +} |
| 63 | + |
| 64 | +U8 xhud::font_meter_widget::is(U32 id) |
| 65 | +{ |
| 66 | + U8 val = 0; |
| 67 | + |
| 68 | + if ((id == this->type()) || (((xhud::meter_widget*)this->is(id)) != 0)) |
| 69 | + { |
| 70 | + val = 1; |
| 71 | + } |
| 72 | + return val; |
| 73 | +} |
| 74 | + |
| 75 | +void xhud::font_meter_widget::update(F32 dt) |
| 76 | + |
| 77 | +{ |
| 78 | + char* format_text[3]; |
| 79 | + format_text[0] = 0; |
| 80 | + |
| 81 | + F32 a; |
| 82 | + S32 new_value; |
| 83 | + basic_rect<F32> bounds; |
| 84 | + |
| 85 | + U8 flag_1; |
| 86 | + U8 flag_2; |
| 87 | + |
| 88 | + this->updater(dt); |
| 89 | + this->xf.id = this->font.id; |
| 90 | + this->xf.space = this->font.space; |
| 91 | + a = this->rc.size.x; |
| 92 | + this->font.w = a; |
| 93 | + this->xf.width = a; |
| 94 | + a = this->rc.size.y; |
| 95 | + this->font.h = a; |
| 96 | + this->xf.height = a; |
| 97 | + |
| 98 | + a = this->rc.a * (F32)this->start_font.c.a + 0.5; |
| 99 | + if (a <= 0.0) |
| 100 | + { |
| 101 | + flag_1 = 0; |
| 102 | + } |
| 103 | + else if (a >= 255.0) |
| 104 | + { |
| 105 | + flag_1 = 255; |
| 106 | + } |
| 107 | + else if (a < 2.1474836e+09) |
| 108 | + { |
| 109 | + flag_1 = (U8)(S32)a; |
| 110 | + } |
| 111 | + else |
| 112 | + { |
| 113 | + flag_1 = (U8)(S32)(a - 2.1474836e+09); |
| 114 | + } |
| 115 | + this->font.c.a = flag_1; |
| 116 | + |
| 117 | + a = this->rc.a * (F32)this->start_font.drop_c.a + 0.5; |
| 118 | + if (a <= 0.0) |
| 119 | + { |
| 120 | + flag_1 = 0; |
| 121 | + } |
| 122 | + else if (a >= 255.0) |
| 123 | + { |
| 124 | + flag_1 = 255; |
| 125 | + } |
| 126 | + else if (a < 2.1474836e+09) |
| 127 | + { |
| 128 | + flag_1 = (U8)(S32)a; |
| 129 | + } |
| 130 | + else |
| 131 | + { |
| 132 | + flag_1 = (U8)(S32)(a - 2.1474836e+09); |
| 133 | + } |
| 134 | + this->font.drop_c.a = flag_1; |
| 135 | + |
| 136 | + new_value = (S32)(this->value + 0.5); |
| 137 | + if (this->last_value != new_value) |
| 138 | + { |
| 139 | + this->last_value = new_value; |
| 140 | + a = this->max_value; |
| 141 | + if (a < this->min_value) |
| 142 | + { |
| 143 | + flag_2 = 0; |
| 144 | + } |
| 145 | + else |
| 146 | + { |
| 147 | + flag_2 = ((font_meter_asset*)(this->a))->counter_mode; |
| 148 | + } |
| 149 | + sprintf(this->buffer, format_text[flag_2], new_value, (S32)(a + 0.5)); |
| 150 | + bounds = this->xf.bounds(this->buffer); |
| 151 | + this->offset.x = -bounds.x; |
| 152 | + this->offset.y = -bounds.y; |
| 153 | + } |
| 154 | + return; |
| 155 | +} |
| 156 | + |
| 157 | +void xhud::font_meter_widget::render() |
| 158 | + |
| 159 | +{ |
| 160 | + F32 x; |
| 161 | + F32 temp_x; |
| 162 | + F32 y; |
| 163 | + |
| 164 | + temp_x = this->offset.x + this->rc.loc.x; |
| 165 | + y = this->offset.y + this->rc.loc.y; |
| 166 | + if (this->font.drop_c.a != 0) |
| 167 | + { |
| 168 | + this->xf.color = this->font.drop_c; |
| 169 | + x = temp_x + this->font.drop_x; |
| 170 | + this->xf.render(this->buffer, x, y + this->font.drop_y); |
| 171 | + } |
| 172 | + if (this->font.c.a != 0) |
| 173 | + { |
| 174 | + this->xf.color = this->font.c; |
| 175 | + this->xf.render(this->buffer, temp_x, y); |
| 176 | + } |
| 177 | + return; |
| 178 | +} |
| 179 | + |
| 180 | +char* xhud::font_meter_asset::type_name() |
| 181 | +{ |
| 182 | + return "hud:meter:font"; |
| 183 | +} |
0 commit comments