Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
akhan
Posts: 70
Registered: ‎08-10-2009
My Device: Not Specified

GaugeField.getValue() - relation to position [pixel ] on screen

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 ?

 

 

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: GaugeField.getValue() - relation to position [pixel ] on screen

[ Edited ]

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.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.