how to offset the bar width with its left size

Posted by Maxhrk on Thu 16 Jul 2009 05:16 PM — 4 posts, 19,445 views.

USA #0

        WindowRectOp (win, 2, 0, 0, 0, 0, ColourNameToRGB("sandybrown"))
	WindowRectOp (win, 2, 12, 20, 185 * math.floor((tonumber(stat["H"]["current"]) / tonumber(stat["H"]["max"]))), 40, ColourNameToRGB("darkred"))
	WindowRectOp (win, 1, 12, 20, 186, 40, ColourNameToRGB("black"))
	WindowText(win, "fn", "Health:" .. stat["H"]["current"] .. "/" .. stat["H"]["max"], 14, 24, 0, 0, ColourNameToRGB("black"), false);


this code purpose is to display the bar that show the percent of a certain stat by painting the bar to correct percentage of full size of the bar.

It would be this math formula for above in peusdo code as example:

bar_right_size * (current_hp / max_hp)


When i try to test the bar by set it to 50% as test. however, i saw that does not correctly split bar in neat half. I realized that I should offset the bar's left size. SO how can I do that? thanks!
Amended on Thu 16 Jul 2009 05:17 PM by Maxhrk
Australia Forum Administrator #1
Willfa did a module to do gauges:

http://www.gammon.com.au/forum/bbshowpost.php?id=9097

However your problem is that the WindowRectOp takes a rectangle for the box, not a start and width. So what you need to do is something like:



width = right - left

first_part = width * (current_hp / max_hp)

second_part = width - first_part


Now your first rectangle if from left to left + first_part.
The second one is from left + first_part to left + width.
USA #2
I am still confused with how to put them in WindowRectOp. I thought, i should put Second_part at in the 'right' part of WindowRectOp parameter. However it seem that bar passed the bar. I think i must have doing wrong. Can you clear it up for me how it can be done in the code?

Sorry about that.

About the gauge module, I did took poke at it and it seem fairly interesting, but I want to learn it by hand to see how it can be done and learn by it. :)
Amended on Fri 17 Jul 2009 12:33 AM by Maxhrk
USA #3
I think i got it right after reread your comments and it totally made sense now.


here the link of my interesting experiment of my success(!):

http://img102.imageshack.us/img102/6154/mybetaguimush.png


here the link of my result.. athough you can see most of upper part of tan textRectangle is empty.. i am going to put up something else on it soon when I have good idea how to put it on there.

In any case i am extremely happy with the result. :)