CustomBoxes: a collection of helper functions

Post your working scripts, libraries and tools
wolf_II
Posts: 2588
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

08 Jan 2019, 12:19

Thx, :D
I was not sure if I would need to think about DPIscale. Thinking hurts :( DPI also hurts :(

edit: i noticed your edit
DPIscale is a problem then, is it a problem for all my CustomBoxes I wonder ... :problem:
I should test, or blindly put in -DPIscale and hope. I am not used to swich back and forth DPI :roll:
wolf_II
Posts: 2588
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

08 Jan 2019, 12:38

Your latest pic shows the size of browser matches the size of buttons, that's good. :)
I have hard-coded the drawing in javascript, which also seems to work as expected.:D
DRocks
Posts: 441
Joined: 08 May 2018, 10:20

Re: CustomBoxes: a collection of helper functions

08 Jan 2019, 16:24

and this looks like windows 7 rather than windows 10
burque505
Posts: 959
Joined: 22 Jan 2017, 19:37

Re: CustomBoxes: a collection of helper functions

08 Jan 2019, 18:30

@DRocks, @wolf_II, I am indeed using Win7 :)
DRocks
Posts: 441
Joined: 08 May 2018, 10:20

Re: CustomBoxes: a collection of helper functions

08 Jan 2019, 20:43

burque505 wrote:
08 Jan 2019, 18:30
@DRocks, @wolf_II, I am indeed using Win7 :)
yes I thought so and this is why the GUI is looking slightly different. I know cause I was shoked when I saw my win10 script on Win7 with the big blue title bar, I was like dohhh :D
wolf_II
Posts: 2588
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

12 Jan 2019, 20:42

Try this:
  • No more mass-writing of HTML-code via plugging into Format(Template, ...)
  • Now using static Html, loaded ONCE into the browser.
  • AHK-buttons send clicks to browser buttons.
  • Browser buttons are off-screen (to see them, I used scrolling via Ctrl + Wheel).
  • On my system, resizing is working.
  • Uses a html file and a java-script file
Cube Meshes.ahk
Cube Meshes.html
Cube Meshes.js
burque505
Posts: 959
Joined: 22 Jan 2017, 19:37

Re: CustomBoxes: a collection of helper functions

13 Jan 2019, 08:45

@wolf_II, that's impressive! :bravo:
Everything works for me on Win7 64-bit, AHK_L 1.1.30.01 64-bit, 125% scaling.
Regards,
burque505
wolf_II
Posts: 2588
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

17 Jan 2019, 21:33

Here is the new member of the family: HtmlBox.ahk
But the magic lies in the test script.
There I use WebBrowser and HTMLWindow2 object.
(using javascript variables and functions from AHK)

HtmlBox.ahk

Here is an example which manipulates the background picture in canvas:
Test.HtmlBox.ahk
HtmlBox.html
JScript.js
burque505
Posts: 959
Joined: 22 Jan 2017, 19:37

Re: CustomBoxes: a collection of helper functions

18 Jan 2019, 09:09

@wolf_II, that's great, thank you! Just for fun, I mangled the test script to show - well - the horizon from horseback? :D
(I changed the file paths in it, "HTML Box.html" is in the same folder as the main script, and my #Include has HTML Box.ahk in the same folder also.
Spoiler
PS: I might have to remove this GIF, it's making me dizzy :eh:Edit: Done!
Last edited by burque505 on 29 Mar 2019, 07:31, edited 1 time in total.
wolf_II
Posts: 2588
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

28 Mar 2019, 23:10

see code below
Last edited by wolf_II on 29 Mar 2019, 08:01, edited 1 time in total.
DRocks
Posts: 441
Joined: 08 May 2018, 10:20

Re: CustomBoxes: a collection of helper functions

29 Mar 2019, 05:51

Nice LV Box wolf.
wolf_II
Posts: 2588
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

29 Mar 2019, 06:19

TV_Show

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%
}
Last edited by wolf_II on 29 Mar 2019, 14:12, edited 14 times in total.
wolf_II
Posts: 2588
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

29 Mar 2019, 06:22

LV_Show

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]
    Options := [["#", "Center"], ["x"], ["y"]]
    LV_Show(Points, Options,, 50, 50, 100, 100)

    loop 100 {
        p0.x ++, p0.y --, p1.x += 2, p1.y -= 3
        LV_Show(Points, Options, False)
        leep 50 ; ~5 sec total ime
    }
    MsgBox, done

ExitApp ; end of auto-execute section



;-------------------------------------------------------------------------------
LV_Show( ByRef Table        ; table to show
;-------------------------------------------------------------------------------
    , ByRef Options         ; options for columns
    , WaitEsc := True       ; wait for {Esc}-key ?
    , x := "", y := ""      ; x,y position of the GUI
    , w := "", h := "" )    ; width/height of the GUI
    ;---------------------------------------------------------------------------
    ; Note: The function automatically adds a final column which makes adjusting
    ; the width of the "real" last column independent of the GUI's width.
{
    local ; protect superglobal variables
    static hLV := 0, _X := 0, _Y := 0, _W := 400, _H := 240
    _X := (x = "" ? _X : x), _W := (w = "" ? _W : w)
    _Y := (y = "" ? _Y : y), _H := (h = "" ? _H : h)

    ; headers (column #1)
    Headers := "", Col := []
    for each, Column in Options
        Headers .= (Col[A_Index] := Column[1]) "|"

    ; create GUI
    Saved := A_DefaultGui
    if hLV
        Gui, LV: Default
    else {
        Gui, LV: New, HWNDhLV, Table
        Gui, +Resize -MinimizeBox -MaximizeBox
        Gui, Margin, 0, 0
        Gui, Add, ListView, w%_W% h%_H% Grid, % Headers A_Space
    }

    ; populate ListView
    GuiControl, -Redraw, SysListView321
    LV_Delete()
    for each, Row in Table {
        Private := []
        if IsObject(Row)
            loop % Options.Length() - 1
                Private.Push(Row[Col[A_Index + 1]])
        else
            Private.Push(each, Row)
        LV_Add("", A_Index, Private*)
    }

    ; options (column #2)
    for each, Column in Options
        LV_ModifyCol(A_Index, "AutoHdr " Column[2])
    LV_ModifyCol(LV_GetCount("Col"), 0) ; hide last column
    GuiControl, +Redraw, SysListView321

    ; main loop
    _LV_MOVE(hLV, _X, _Y, "")
    Gui, Show, x%_X% y%_Y%
    Gui, %Saved%: Default
    if WaitEsc
        KeyWait, Escape, D

return ; end of function

    LVGuiSize:
        GuiControl, Move, SysListView321, w%A_GuiWidth% h%A_GuiHeight%
    return
}



;-------------------------------------------------------------------------------
_LV_MOVE(wP, ByRef lP, ByRef msg, hWnd) { ; fires when window's position changes
;-------------------------------------------------------------------------------
    local
    static hGui := OnMessage(0x3, "_LV_MOVE"), _WinX := 0, _WinY := 0
    if (hWnd = "") {
        if (hGui = "_LV_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%
}
Last edited by wolf_II on 29 Mar 2019, 13:58, edited 6 times in total.
DRocks
Posts: 441
Joined: 08 May 2018, 10:20

Re: CustomBoxes: a collection of helper functions

29 Mar 2019, 12:45

TreeView is also very nice.

Is it me or when adding a litteral string between quotes, it doesn't show up?

Code: Select all

p0 := {x: 100, y: 100}
p1 := {x: 500, y: 500}
p2 := {x: 500, y: 100}
p3 := {x: 100, y: 500}
p4 := {x: "Allo", y: "hi"}
wolf_II
Posts: 2588
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

29 Mar 2019, 12:49

Did you put Points := [p0, p1, p2, p3, p4] ?

Thanks for the compliment! :thumbup:

Edit: I commented the examples.
DRocks
Posts: 441
Joined: 08 May 2018, 10:20

Re: CustomBoxes: a collection of helper functions

29 Mar 2019, 23:25

Hmm right on. My bad. No I missed that obvious part. Sry and thanks :)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 37 guests