[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  how to offset the bar width with its left size

how to offset the bar width with its left size

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Thu 16 Jul 2009 05:16 PM (UTC)

Amended on Thu 16 Jul 2009 05:17 PM (UTC) by Maxhrk

Message

        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!
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 16 Jul 2009 09:58 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Reply #2 on Fri 17 Jul 2009 12:12 AM (UTC)

Amended on Fri 17 Jul 2009 12:33 AM (UTC) by Maxhrk

Message
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. :)
[Go to top] top

Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Reply #3 on Fri 17 Jul 2009 04:10 AM (UTC)

Amended on Fri 17 Jul 2009 04:43 AM (UTC) by Maxhrk

Message
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. :)
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,834 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]