frontend: Apply shift to analog fields in preview.

This commit is contained in:
Vas Crabb 2020-10-25 05:17:54 +11:00
parent 8dac5448d3
commit 62dbdf7b38
2 changed files with 4 additions and 1 deletions

View File

@ -39,8 +39,10 @@ inline menu_analog::field_data::field_data(ioport_field &f) noexcept
, range(f.maxval() - f.minval())
, neutral(float(f.analog_reverse() ? (f.maxval() - f.defvalue()) : (f.defvalue() - f.minval())) / range)
, origin((f.analog_wraps() && (f.defvalue() != f.minval()) && (f.defvalue() != f.maxval())) ? 0.0f : neutral)
, shift(0U)
, show_neutral((f.defvalue() != f.minval()) && (f.defvalue() != f.maxval()))
{
for (ioport_value m = f.mask(); m && !BIT(m, 0); m >>= 1, ++shift) { }
}
@ -93,7 +95,7 @@ void menu_analog::custom_render(void *selectedref, float top, float bottom, floa
ioport_value cur(0U);
data.field.get().live().analog->read(cur);
cur -= data.field.get().minval();
cur = (cur >> data.shift) - data.field.get().minval();
float fill(float(cur) / data.range);
if (data.field.get().analog_reverse())
fill = 1.0f - fill;

View File

@ -58,6 +58,7 @@ private:
float range;
float neutral;
float origin;
u8 shift;
bool show_neutral;
};