gauge.lua additions

Posted by Fiendish on Sun 24 Feb 2013 02:11 AM — 5 posts, 19,100 views.

USA Global Moderator #0
I have the following changes to my gauge.lua file. I figure they might be useful for others too.

@@ -18,7 +18,8 @@
                 fg_colour, bg_colour,       -- colour for bar, colour for unfilled part
                 ticks, tick_colour,         -- number of ticks to draw, and in what colour
                 frame_colour,               -- colour for frame around bar
-                shadow_colour)              -- colour for shadow, nil for no shadow
+                shadow_colour,              -- colour for shadow, nil for no shadow
+                no_gradient)                -- don't use the gradient fill effect
 
   local Fraction
   
@@ -62,18 +63,22 @@
    -- box size must be > 0 or WindowGradient fills the whole thing 
   if math.floor (gauge_width) > 0 then
     
-    -- top half
-    WindowGradient (win, left, top, 
-                    left + gauge_width, top + height / 2, 
-                    0x000000, -- black
-                    fg_colour, 2)  -- vertical top to bottom
-    
-    -- bottom half
-    WindowGradient (win, left, top + height / 2, 
-                    left + gauge_width, top + height,   
-                    fg_colour,
-                    0x000000, -- black
-                    2) -- vertical top to bottom
+    if no_gradient then
+        WindowRectOp (win, 2, left+1, top, left+1+gauge_width, top+height, fg_colour)
+    else 
+        -- top half
+        WindowGradient (win, left, top-1, 
+                        left + gauge_width, top + height / 2, 
+                        0x000000, -- black
+                        fg_colour, 2)  -- vertical top to bottom
+        
+        -- bottom half
+        WindowGradient (win, left, top + height / 2, 
+                        left + gauge_width, top + height,   
+                        fg_colour,
+                        0x000000, -- black
+                        2) -- vertical top to bottom
+    end
 
   end -- non-zero
   
@@ -166,3 +171,17 @@
   
   return width
 end -- draw_text_box
+
+-- text with a black outline
+function outlined_text(window, font, text, startx, starty, endx, endy, color, utf8)
+    WindowText(window, font, text, startx-1, starty-1, endx, endy, 0x000000, utf8)
+    WindowText(window, font, text, startx-1, starty, endx, endy, 0x000000, utf8)
+    WindowText(window, font, text, startx-1, starty+1, endx, endy, 0x000000, utf8)
+    WindowText(window, font, text, startx, starty-1, endx, endy, 0x000000, utf8)
+    WindowText(window, font, text, startx, starty+1, endx, endy, 0x000000, utf8)
+    WindowText(window, font, text, startx+1, starty-1, endx, endy, 0x000000, utf8)
+    WindowText(window, font, text, startx+1, starty, endx, endy, 0x000000, utf8)
+    WindowText(window, font, text, startx+1, starty+1, endx, endy, 0x000000, utf8)
+    WindowText(window, font, text, startx, starty, endx, endy, color, utf8)
+end
+
Australia Forum Administrator #1
Revisiting this thread:

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

Your suggested change, with this test code:


win = "test"

WindowCreate (win , 
  0, -- left
  0, -- top
  200, -- width
  200, -- height
  miniwin.pos_top_left, -- mode
  0, -- flags
  ColourNameToRGB ("navajowhite"))

 WindowRectOp (win, miniwin.rect_frame, 10, 10, 50, 50, ColourNameToRGB ("red"))
 

 WindowGradient (win, 10, 10, 50, 50, 
                    ColourNameToRGB ("green"),
                    ColourNameToRGB ("blue"), 2)


 WindowRectOp (win, miniwin.rect_frame, 10, 10, 50, 50, ColourNameToRGB ("cyan"))
 

require "gauge"

gauge (win,    
        "hp",                  
        50, 100,              
        10, 60, 40, 20,  
        ColourNameToRGB ("green"), 
        ColourNameToRGB ("red"),       
        0, 0x000000,       
        ColourNameToRGB ("cyan"),           
        nil)             

 WindowShow (win  , true)


Produces this:



You added the "-1" to the top, which appears to cause it:


       -- top half
        WindowGradient (win, left, top-1, 


Is there any reason for that?
USA Global Moderator #2
Oh yeah, good memory, I totally forgot about that thread.

Do this instead:


        -- top half
        WindowGradient (win, left, top, 
                        left + gauge_width, top + height / 2, 
                        0x000000, -- black
                        fg_colour, 2)  -- vertical top to bottom
        
        -- bottom half
        WindowGradient (win, left, top + height / 2, 
                        left + gauge_width, top + height-1,   
                        fg_colour,
                        0x000000, -- black
                        2) -- vertical top to bottom
Amended on Mon 25 Feb 2013 03:23 AM by Fiendish
USA Global Moderator #3
I've been meaning to ask, do you get notified of edits?
Australia Forum Administrator #4
Fiendish said:

I've been meaning to ask, do you get notified of edits?


Edits on the forum? No.