08-19-2010 11:42 AM
GaugeField.getValue() - relation to position [pixel ] on screen
How can one correlate the current progress of a gauge field with it's [pixel / x-coordinate] position on Display ?
08-20-2010 10:41 PM - last edited on 08-20-2010 10:41 PM
getValue returns the current GaugeField value, so if you say min: 1, max: 5 and the bar is in the middle then the value should be 3. It does not return the pixel location on the screen.
To figure that out you need the field's X location on the screen, width, number or "ticks" and the current value.
width / tick count = tick width
(value - tick min) * tick width = current relative position
current relative position + GaugeField X location = current absolute position
tick count = getValueMax - getValueMin
width/X = getContentRect (then get X and width from that)
so in the end:
public static int getGaugeFieldBarPos(GaugeField gauge)
{
XYRect rect = gauge = getContentRect();
return rect.x + ((rect.width / (gauge.getValueMax() - gauge.getValueMin())) * (gauge.getValue() - gauge.getValueMin()));
}
That should do the trick though know that I never actually tested it.