Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Plugins ➜ Improved health bar plugin - can be dragged around

Improved health bar plugin - can be dragged around

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


Pages: 1  2 3  4  5  6  7  

Posted by Keberus   (31 posts)  Bio
Date Reply #15 on Sun 03 Jan 2010 09:55 PM (UTC)
Message
I've been toying with this plugin for a bit, and have my own kinda look to it now. But, I'm having an issue, I would like to change the color of the bar as it decreases, initially I was going to do a gradient fill, but even with that method I ran into troubles. So, if I know that I want it to start as one color, and end as another how would I code this to happen with the plugin?

Thanks in advance,
KeB
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #16 on Sun 03 Jan 2010 10:01 PM (UTC)
Message
If I understand what you're asking, you could draw a gradient between the two colors you want on another window (an invisible one), 100 pixels length, 1 pixel height, and use WindowGetPixel() to get the pixel colour at a certain point of the gradient based on the current status of the gauge.

Basically, if the gate is 100% full, you would take the (100-1)th pixel (the 99th, the right-most) from the gradient, and use its color to fill the gauge. If it's 1% full, you'd take the (1-1)th pixel (the 0th, the left-most) and use its color to fill the gauge. And if it's 0% full, you wouldn't draw anything.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Keberus   (31 posts)  Bio
Date Reply #17 on Sun 03 Jan 2010 10:04 PM (UTC)
Message
Cool, many thanks sir.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #18 on Sun 03 Jan 2010 11:01 PM (UTC)
Message
You shouldn't need to do it pixel by pixel, as WindowGradient does gradients. The plugin already uses that to do a gradient from top to bottom to get a 3D effect, but if you wanted a left-to right gradient, and weren't too picky about the 3D effect, you could just change the direction of it, with a bit of calculating about its limits.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #19 on Sun 03 Jan 2010 11:04 PM (UTC)
Message
I don't think he wanted an actual gradient on-screen, he just wanted to modulate the absolute color of the gauge depending on the gauge's percentage. All green if full, and tending towards red as the percentage drops. It's not really a pixel-by-pixel thing, it's just like, mm, the eyedropper tool on MS Paint. It grabs the appropriate color (based on a gradient) and fills the gauge with that color.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #20 on Sun 03 Jan 2010 11:10 PM (UTC)
Message
Oh, it's just he said he "tried a gradient fill".

If you want to simply modify the colour used in the existing fill, try:

Template:function=FilterPixel FilterPixel

The documentation for the FilterPixel script function is available online. It is also in the MUSHclient help file.



You could take the current colour (eg. green) which is going to be supplied to draw the bar, and apply a modification to it, like gamma, brightness or contrast, and use the resulting colour instead.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Keberus   (31 posts)  Bio
Date Reply #21 on Sun 03 Jan 2010 11:17 PM (UTC)

Amended on Sun 03 Jan 2010 11:18 PM (UTC) by Keberus

Message
A few issues, first of all, it seems that nothing at all happens if I try to make a 1x1 window, secondly I can't seem to pull the right color from the gradient rectangle that I've made, instead it just keeps pulling the background color and setting it. This is the code that I'm currently trying to use:

showing only relevant code because of post length limit:

function DoGauge (sPrompt, Percent, Colour)

  local Fraction = tonumber (Percent)
  
  if Fraction > 1 then Fraction = 1 end
  if Fraction < 0 then Fraction = 0 end
   
  local width = WindowTextWidth (win, font_id, sPrompt)
  
  WindowText (win, font_id, sPrompt,
                             GAUGE_LEFT - width, vertical, 0, 0, FONT_COLOUR)

  WindowCircleOp (win, 3, GAUGE_LEFT, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT, 
                          BACKGROUND_COLOUR, 0, 2, BACKGROUND_COLOUR, 10, 25, 25)  -- fill entire box
 
  
  local gauge_width = (WINDOW_WIDTH - GAUGE_LEFT - 5) * Fraction
  
   -- box size must be > 0 or WindowGradient fills the whole thing 
  if math.floor (gauge_width) > 0 then
 
 -- WindowRectOp (win2, 1, 2, 2, 100, 2, ColourNameToRGB ("lightgrey"))
 
--create the gradient line
    WindowGradient (win2, 50, 1, 50, 1, 
                    ColourNameToRGB ("red"),
                    Colour, 1) 
    
   
    -- top half
--old method commented out
 --   WindowGradient (win, GAUGE_LEFT, vertical, GAUGE_LEFT + gauge_width, vertical + GAUGE_HEIGHT / 2, 
   --                 0x000000, 
     --               Colour, 2) 
     WindowGradient (win, GAUGE_LEFT, vertical, GAUGE_LEFT + gauge_width, vertical + GAUGE_HEIGHT / 2, 
                    0x000000, 
                    WindowGetPixel( win2, Fraction, 1 ), 2) 

    
    -- bottom half
    WindowGradient (win, GAUGE_LEFT, vertical + GAUGE_HEIGHT / 2, 
                    GAUGE_LEFT + gauge_width, vertical +  GAUGE_HEIGHT,   
                    WindowGetPixel( win2, Fraction, 1 ),
                    0x000000, 2) 

  end -- non-zero


function OnPluginInstall ()
  
  win = GetPluginID ()
  win2 = GetPluginID ()
  font_id = "fn"
  
  font_name = "Fixedsys"    -- the actual font

  local x, y, mode, flags = 
      tonumber (GetVariable ("windowx")) or 0,
      tonumber (GetVariable ("windowy")) or 0,
      tonumber (GetVariable ("windowmode")) or 8, -- bottom right
      tonumber (GetVariable ("windowflags")) or 0
    
  -- make miniwindow so I can grab the font info
  check (WindowCreate (win, 
                 x, y, WINDOW_WIDTH, WINDOW_HEIGHT,  
                 mode,   
                 flags,   
                 BACKGROUND_COLOUR) )

  check (WindowCreate (win2, 
                 x, y, WINDOW_WIDTH, WINDOW_HEIGHT,  
                 mode,   
                 flags,   
                 BACKGROUND_COLOUR) )

  -- make a hotspot
  WindowAddHotspot(win, "hs1",  
                   0, 0, 0, 0,   -- whole window
                   "",   -- MouseOver
                   "",   -- CancelMouseOver
                   "mousedown",
                   "",   -- CancelMouseDown
                   "",   -- MouseUp
                   "Drag to move",  -- tooltip text
                   1, 0)  -- hand cursor
   -- make a hotspot
  WindowAddHotspot(win2, "hs2",  
                   0, 0, 0, 0,   -- whole window
                   "",   -- MouseOver
                   "",   -- CancelMouseOver
                   "mousedown",
                   "",   -- CancelMouseDown
                   "",   -- MouseUp
                   "Drag to move",  -- tooltip text
                   1, 0)  -- hand cursor

  WindowShow( win2, false )                  
  WindowDragHandler(win, "hs1", "dragmove", "dragrelease", 0) 
                 
  check (WindowFont (win, font_id, font_name, 9, false, false, false, false, 0, 0))  -- normal
  
  font_height = WindowFontInfo (win, font_id, 1)  -- height
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
    return
  end -- they didn't enable us last time
 
end -- OnPluginInstall

function OnPluginDisable ()
  WindowShow (win, false)
  WindowShow (win2, false )
end -- OnPluginDisable

function OnPluginSaveState ()
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
  SetVariable ("windowx", tostring (WindowInfo (win, 10)))
  SetVariable ("windowy", tostring (WindowInfo (win, 11)))
  SetVariable ("windowmode", tostring (WindowInfo (win, 7)))
  SetVariable ("windowflags", tostring (WindowInfo (win, 8)))
end -- OnPluginSaveState


]]>
</script>

</muclient>


Everything else works, but I can't seem to be able to pull the right color.

Thanks for all the help,
KeB
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #22 on Sun 03 Jan 2010 11:23 PM (UTC)

Amended on Sun 03 Jan 2010 11:45 PM (UTC) by Twisol

Message
Well, first of all, you're using the same ID for both windows. The latter will overwrite the former. (I'll edit in some other suggestions, but I think that's your biggest issue, so I'll submit now.)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Keberus   (31 posts)  Bio
Date Reply #23 on Sun 03 Jan 2010 11:30 PM (UTC)
Message
I guess I'm a bit confused. If you are talking about this line

win2 = GetPluginID ()

I thought GetPluginID() got a unique name/id for the window. If that's not the case, then how do you set the id of the windows?

Thanks,
KeB
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #24 on Sun 03 Jan 2010 11:34 PM (UTC)
Message
GetPluginID() gets the plugin's ID. You know, the part at the very beginning of the plugin's XML, in the <plugin> tag, called id="some stuff here".

You generally get a unique identifier by taking GetPluginID() and tacking something on to the end, like GetPluginID() .. "_gauge".

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #25 on Sun 03 Jan 2010 11:47 PM (UTC)

Amended on Sun 03 Jan 2010 11:50 PM (UTC) by Twisol

Message
Here's an example of the gradient sampling technique from earlier. I've tested it, so it should work if you just paste it straight into Ctrl+I and run it. You'll obviously need to modify it to fit your plugin though.


  -- a unique identifier
  win = GetPluginID() .. "_gradient"
  -- the hidden gradient we take the color from
  WindowCreate(win,
               0, 0, -- location doesn't really matter
               100, 1, -- 100x1 window: a straight line gradient
               0, 2, -- absolute positioning, nothing special
               0x000000) -- black background, doesn't really matter though
  
  -- load the window with our gradient
  WindowGradient(win,
                 0, 0, 0, 0, -- cover the whole window
                 0x0000FF, -- red, the left color
                 0x00FF00, -- green, the right color
                 1) -- horizontal gradient
  
  -- pretend we have a gauge
  -- get the percentage of the gauge that is full
  -- local percentage = WhateverStuffGoesHere() - 1
  local percentage = 75 - 1
  -- subtract 1 because pixel coordinates are 0-based
  
  -- get the color value at that point of the gradient
  local color = WindowGetPixel(win, percentage, 0)
  
  -- another unique identifier
  win2 = GetPluginID() .. "_view"
  -- the window we actually make visible
  WindowCreate(win2,
               0, 0, -- wherever you want
               200, 200, -- whatever you want
               0, 2, -- absolute positioning
               0x000000) -- black background, doesn't really matter
  
  WindowRectOp(win2,
               2, -- fill
               0, 0, percentage * 200 / 100, 200, -- cover everything up to the percentage line
               color, -- fill with the color we sampled from the gradient
               nil) -- color2 doesn't matter for a fill action
  
  WindowShow(win2, true) -- show it

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #26 on Mon 04 Jan 2010 12:02 AM (UTC)
Message
Keberus said:

I guess I'm a bit confused. If you are talking about this line

win2 = GetPluginID ()

I thought GetPluginID() got a unique name/id for the window. If that's not the case, then how do you set the id of the windows?



If you want a whole bunch of unique IDs, you can use:

Template:function=GetUniqueID GetUniqueID

The documentation for the GetUniqueID script function is available online. It is also in the MUSHclient help file.



This is what is used anyway to generate plugin IDs.

So, change:


win2 = GetPluginID ()


to:


win2 = GetUniqueID ()



Of course, Twisol's suggestion is perfectly fine, and is what I normally do anyway.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Keberus   (31 posts)  Bio
Date Reply #27 on Mon 04 Jan 2010 12:06 AM (UTC)
Message
Sweet, you guys are awesome. I got it doing exactly what I wanted now. Thanks for all the help. Was gonna post it all, but it's too big. I'll have to link back to it at some point from my website or something.

Thanks again,
KeB
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #28 on Mon 04 Jan 2010 12:19 AM (UTC)
Message
You could paste it to mushclient.pastebin.com and link it to us here. (It might be helpful if you set its expiry time to forever, because otherwise forum lurkers in the future won't be able to see the plugin.)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Keberus   (31 posts)  Bio
Date Reply #29 on Mon 04 Jan 2010 12:49 AM (UTC)

Amended on Mon 04 Jan 2010 12:56 AM (UTC) by Keberus

Message
Okay, didn't even realize there was a pastebin. Anywho, here's the link http://mushclient.pastebin.com/f66d2a798
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.


296,339 views.

This is page 2, subject is 7 pages long:  [Previous page]  1  2 3  4  5  6  7  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

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