Trace function

Posted by Tkl1129 on Mon 11 Jul 2011 05:46 AM — 3 posts, 16,765 views.

Hong Kong #0
I'm getting start to learn about miniwindows...than I have a question about this, the code posted below

Why there is no change without turn on the trace function?
is there anything missing? Thanks.

--------------------------------------
<aliases>
<alias
match="win_cre"
enabled="y"
send_to="12"
sequence="100"
>
<send>win = "test_" .. GetPluginID ()

WindowCreate (win, 0, 0, 200, 200, miniwin.pos_center_all, 0, ColourNameToRGB("white")) -- create window


-- Grid
for i = 1, math.max (WindowInfo (win, 3), WindowInfo (win, 4)) / 10 do
WindowLine (win, i * 10, 0, i * 10, WindowInfo (win, 4), 0xC0C0C0, miniwin.pen_solid, 1)
WindowLine (win, 0, i * 10, WindowInfo (win, 3), i * 10, 0xC0C0C0, miniwin.pen_solid, 1)
end -- for

--[button hot spot]
WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100,
ColourNameToRGB("green")) -- filled

function mouseover (flags, hotspot_id)
WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100,
ColourNameToRGB("red")) -- filled
return 0 -- needed for some languages
end -- mouseover

function cancelmouseover (flags, hotspot_id)
WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100,
ColourNameToRGB("green")) -- filled
return 0 -- needed for some languages
end -- cancelmouseover

function mousedown (flags, hotspot_id)
WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100,
ColourNameToRGB("black")) -- filled
return 0 -- needed for some languages
end -- mousedown

function cancelmousedown (flags, hotspot_id)
WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100,
ColourNameToRGB("green")) -- filled
return 0 -- needed for some languages
end -- cancelmousdown

function mouseup (flags, hotspot_id)
WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100,
ColourNameToRGB("red")) -- filled
return 0 -- needed for some languages
end -- mouseup

WindowAddHotspot(win, "hs1",
50, 50, 100, 100, -- rectangle
"mouseover",
"cancelmouseover",
"mousedown",
"cancelmousedown",
"mouseup",
"Click here to be healed", -- tooltip text
miniwin.cursor_hand, 0) -- hand cursor

-- [Display the window]
WindowShow (win , true)</send>
</alias>
</aliases>
Australia Forum Administrator #1
Changes to window contents are not drawn until the window is redrawn. To force this to happen you need to call the Redraw function. Like this:


<aliases>
  <alias
   match="win_cre"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

win = "test_" .. GetPluginID ()

WindowCreate (win, 0, 0, 200, 200, miniwin.pos_center_all, 0, ColourNameToRGB("white"))  -- create window


-- Grid
  for i = 1, math.max (WindowInfo (win, 3), WindowInfo (win, 4)) / 10 do
    WindowLine (win, i * 10, 0, i * 10, WindowInfo (win, 4), 0xC0C0C0, miniwin.pen_solid, 1)
    WindowLine (win, 0, i * 10, WindowInfo (win, 3), i * 10, 0xC0C0C0, miniwin.pen_solid, 1)
  end -- for

--[button hot spot]
WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100, 
              ColourNameToRGB("green"))  -- filled

function mouseover (flags, hotspot_id)
  WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100, 
              ColourNameToRGB("red"))  -- filled
  Redraw ()
end -- mouseover

function cancelmouseover (flags, hotspot_id)
 WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100, 
              ColourNameToRGB("green"))  -- filled
  Redraw ()
end -- cancelmouseover

function mousedown (flags, hotspot_id)
 WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100, 
              ColourNameToRGB("black"))  -- filled
  Redraw ()
end -- mousedown

function cancelmousedown (flags, hotspot_id)
 WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100, 
              ColourNameToRGB("green"))  -- filled
  Redraw ()
end -- cancelmousdown

function mouseup (flags, hotspot_id)
  WindowRectOp (win, miniwin.rect_fill, 50, 50, 100, 100, 
              ColourNameToRGB("red"))  -- filled
  Redraw ()
end -- mouseup
  
WindowAddHotspot(win, "hs1",  
                 50, 50, 100, 100,   -- rectangle
                 "mouseover", 
                 "cancelmouseover", 
                 "mousedown",
                 "cancelmousedown", 
                 "mouseup", 
                 "Click here to be healed",  -- tooltip text
                 miniwin.cursor_hand, 0)  -- hand cursor

-- [Display the window]
WindowShow (win , true)

</send>
  </alias>
</aliases>


With Trace on, the window is being constantly redrawn, that is why it seemed to work.

Template:function=Redraw
Redraw

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


Amended on Mon 11 Jul 2011 06:21 AM by Nick Gammon
Hong Kong #2
oh, Nice.. :D thanks~