Code: Select all
#NoEnv
; make points
p0 := {x: 100, y: 100}
p1 := {x: 500, y: 500}
p2 := {x: 500, y: 100}
p3 := {x: 100, y: 500}
; make Points array with them
Points := [p0, p1, p2, p3]
TV_Show(Points, "Points",, 50, 50, 200)
loop 100 {
p0.x ++, p0.y --, p1.x += 2, p1.y -= 3
TV_Show(Points, "Points", False)
leep 50 ; ~5 sec total ime
}
MsgBox, done
ExitApp ; end of auto-execute section
;-------------------------------------------------------------------------------
TV_Show( ByRef Obj ; object to show
;-------------------------------------------------------------------------------
, Name := "" ; name of the object
, WaitEsc := True ; wait for {Esc}-key ?
, x := "", y := "" ; x,y position of the GUI
, w := "", h := "" ) ; width/height of the GUI
;---------------------------------------------------------------------------
{
local ; protect superglobal variables
static hTV := 0, _X := 0, _Y := 0, _W := 240, _H := 400
_X := (x = "" ? _X : x), _W := (w = "" ? _W : w)
_Y := (y = "" ? _Y : y), _H := (h = "" ? _H : h)
; create GUI
Saved := A_DefaultGui
if hTV
Gui, TV: Default
else {
Gui, TV: New, HWNDhTV, Tree
Gui, +Resize -MinimizeBox -MaximizeBox
Gui, Margin, 0, 0
Gui, Add, TreeView, w%_W% h%_H%
}
; populate TreeView
GuiControl, -Redraw, SysTreeView321
TV_Delete()
if _isCircular(Obj)
TV_Add("Circular reference", TV_Add(Name,, "Expand"))
else ; recurse
_PopulateTree(Obj, Name)
GuiControl, +Redraw, SysTreeView321
; main loop
_TV_MOVE(hTV, _X, _Y, "")
Gui, Show, x%_X% y%_Y%
Gui, %Saved%: Default
if WaitEsc
KeyWait, Escape, D
return ; end of function
TVGuiSize:
GuiControl, Move, SysTreeView321, w%A_GuiWidth% h%A_GuiHeight%
return
}
;-------------------------------------------------------------------------------
_PopulateTree(ByRef Obj, Name, ParentID := 0, Key := "") { ; populate the tree
;-------------------------------------------------------------------------------
local
static Value := ""
Root := TV_Add(Key ? Key : Name, ParentID, "Expand")
for Key, Value in Obj
if IsObject(Value)
_PopulateTree(Value, "Value", Root, Key)
else
TV_Add(Value, TV_Add(Key, Root, "Expand"))
}
;-------------------------------------------------------------------------------
_isCircular(Obj, Objs := 0, dummy := 0) { ; return true if Obj is circular
;-------------------------------------------------------------------------------
local
if not IsObject(Objs)
Objs := []
for each, Value in Obj
if IsObject(Value)
if Objs[&Value] or _isCircular(Value, Objs, Objs[&Value] := True)
return True
return False
}
;-------------------------------------------------------------------------------
_TV_MOVE(wP, ByRef lP, ByRef msg, hWnd) { ; fires when window's position changes
;-------------------------------------------------------------------------------
local
static hGui := OnMessage(0x3, "_TV_MOVE"), _WinX := 0, _WinY := 0
if (hWnd = "") {
if (hGui = "_TV_MOVE" || _WinX = "")
hGui := wP, _WinX := lP, _WinY := msg
else ; send back static vars
lP := _WinX, msg := _WinY
return ; private call
}
if (hWnd != hGui)
return ; only monitor hGui
if not (wP = 1 || wP = 2) ; isMin or isMax
WinGetPos, _WinX, _WinY,,, ahk_id %hGui%
}