CustomBoxes: a collection of helper functions

Post your working scripts, libraries and tools for AHK v1.1 and older
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

CustomBoxes: a collection of helper functions

02 Aug 2017, 23:30

Hi all,

I have written a bunch of helper functions that give you an alternative to InputBox.
Some are alternatives to MsgBox and I use them for debugging.
Some of the functions I wrote for users in the Ask For Help section, others i have not posted yet.
I took inspiration from many forum members to write these functions.
I recently cleaned up the code and I want to share the result.

I hope that someone will find them useful. Enjoy! :)

Most recent update

BetterBox
BtnBox
EditBox
IconBox
ListBox
LoginBox
MonoBox
MultiBox
NumberBox
PassBox
RadioBox
TreeBox
Last edited by wolf_II on 18 Dec 2018, 11:10, edited 3 times in total.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

02 Aug 2017, 23:31

Here is the collection as a zip-file with some examples:
CustomBoxes.zip
(49.51 KiB) Downloaded 290 times
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: CustomBoxes: a collection of helper functions

03 Aug 2017, 01:36

Thanks for this work
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: CustomBoxes: a collection of helper functions

03 Aug 2017, 05:37

Very nice. 8-)
I'm glad you are collecting your stuff, and sharing it, I know there are quite a few,

Code: Select all

;-------------------------------------------------------------------------------
NiceAndWellWrittenFunctions(...)
;-------------------------------------------------------------------------------
randomly scattered around the forum ;)

Cheers.
Edit: Pasword: 1234 :lol:
Last edited by Helgef on 03 Aug 2017, 06:05, edited 1 time in total.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

03 Aug 2017, 06:01

@ozzii: I'm glad you like the collection.

@Helgef: Thank you very much for your kind words. :D
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

04 Aug 2017, 21:41

Update:
CustomBoxes.zip
(49.52 KiB) Downloaded 180 times
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

14 Oct 2018, 01:28

Update:
Attachments
CustomBoxes.zip
(52.71 KiB) Downloaded 133 times
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: CustomBoxes: a collection of helper functions

14 Oct 2018, 01:43

Hi Wolf,
Thanks for sharing these...good stuff! Minor thing you may want to change...in the ListBox and RadioBox test files, I think you want "vowel", not "vocal". Regards, Joe
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

14 Oct 2018, 02:05

I'm glad you like these little helpers. :D

Thanks for pointing out the missing translations. OOPS.
CustomBoxes.zip
(52.71 KiB) Downloaded 158 times
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: CustomBoxes: a collection of helper functions

14 Oct 2018, 02:21

You're welcome...and thanks to you for the quick fix!
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: CustomBoxes: a collection of helper functions

14 Oct 2018, 19:54

Good job wolf thanks for your sharing and help with my recent questions!!
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

18 Dec 2018, 11:01

Update: I used my collection a bit, turns out there are bugs here and there.
And I noticed a weakness in expression the concept of what is meant as a User-interaction, and what is useful for debugging.
Anyway, I did an other effort to make this useful, or, helpful at least. I encourage everybody to shredder these scripts in the editor.
Turn 'em inside out, remove and add stuff.

:xmas: merry (<insert whatever>) Christmas to all. :xmas:
Attachments
CustomBoxes.2018.zip
(64.16 KiB) Downloaded 153 times
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: CustomBoxes: a collection of helper functions

18 Dec 2018, 15:51

Nice stuff as always, wolf_II. I especially like your resizable EditBox.
(Just FYI, there's a duplicate folder level in the zip. I'm running Win7 64-bit, AHK 1.1.30.01 64-bit, and everything works but the TreeBox test. It flickers and then disappears).
I see you changed, i.e.

Code: Select all

TreeBox(ArrName, X := "", Y := "", Width := 240, Height := 400)
to

Code: Select all

TreeBox(ByRef Obj, Name:="", x:="", y:="", Width:=240, Height:=400)
with the relevant other changes needed, maybe the combo of my system and AHK version is making it not work.
Regards, and happy holidays,
burque505
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

18 Dec 2018, 16:05

Thanks for the feedback, here is the fixed zip with a new Test-file for TreeView: (I hope)
CustomBoxes.2018.zip
(52.96 KiB) Downloaded 209 times
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: CustomBoxes: a collection of helper functions

18 Dec 2018, 16:26

Works like a charm, wolf_II, thank you!
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

07 Jan 2019, 21:20

@burque505: I thought you might be interested in what could become a HtmlBox in the series. I noticed the to-do item in your RTF editor.
@all: same thing applies, even when not writing a RTF editor.

This used to be a test-script for another project. With the maturing of the CustomBoxes series, I might tackle the problem to make this demo fit the scheme later, but there are a few updates for the CustomBoxes coming up first.

What this does: open a gui with ActiveX, interact via AHK GUI buttons with the javascript running in the browser.
I eliminated <html>, and <head> tags, the <meta> tag is dropped after any Gui button click.
Check the source code via right-click in the browser to see it initially.

I am a noob when it comes to Html/JS, this might be a catastrophe of a script from a JS point of view, but I like my experiments. :)

Code: Select all

#NoEnv
#SingleInstance Force
#Warn all


    ; initialize ActiveX object
    Start = <meta http-equiv='x-ua-compatible' content='ie=edge'>
    Gui, Add, ActiveX, w520 h245 vBrowser, about: %Start%

    Gui, Add, Button, w80    gClick, 2
    Gui, Add, Button, x+8 wp gClick, 3
    Gui, Add, Button, x+8 wp gClick, 4
    Gui, Add, Button, x+8 wp gClick, 5
    Gui, Add, Button, x+8 wp gClick, 6
    Gui, Add, Button, x+8 wp gClick, 7
    Gui, Show


    ;---------------------------------------
    ; Html/JS in a AHK GUI
    ;---------------------------------------
    Template =
    ( LTrim
        <body style="margin:0">
        <canvas id='Canvas'>
        <script src="%A_ScriptDir%\Cubes.js"></script>
        <script>draw({}, '{}');</script>
    )


return ; end of auto-execute section

GuiClose:
ExitApp



;-------------------------------------------------------------------------------
Click: ; drawing in the browser
;-------------------------------------------------------------------------------
    HTML := Format(Template, A_GuiControl, getCode(A_GuiControl))

    Browser.Document.Open()
    Browser.Document.Write(HTML)
    Browser.Document.Close()

return



;x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x
;=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=
;x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x

getCode(Order) { ; to fill in the second parameter of Template
    return repeat(1, Order) "," repeat(2, Order) "," repeat(3, Order)
     . "," repeat(4, Order) "," repeat(5, Order) "," repeat(6, Order)
}

repeat(str, n) { ; return str repeated n*n times
    Result := ""
    Loop, % n * n
        Result .= str
    return Result
}

Code: Select all

//------------------------------------------------------------------------------
// Cubes.js
// by wolf_II
//------------------------------------------------------------------------------
// draw two 3D meshes of a Rubik's Cube
// parameterized for the order of the cube
/*------------------------------------------------------------------------------
could take scaling factor and distance from the borders as parameters
"angled lines are hardcoded" as: 8:3, 0:9
*/



//------------------------------------------------------------------------------
var Color = [ // global variable with 7 color definitions
//------------------------------------------------------------------------------
    "#808080",  // 0 = gray
    "#FFFFFF",  // 1 = white
    "#FFAA00",  // 2 = orange
    "#0055FF",  // 3 = blue
    "#FFFF00",  // 4 = yellow
    "#00FF00",  // 5 = green
    "#FF0000"   // 6 = red
];



//------------------------------------------------------------------------------
function get_Gradient(y2) { // gradient for background
//------------------------------------------------------------------------------
    var gradient = ctx.createLinearGradient(0, 0, 0, y2);
    gradient.addColorStop(0.0, "#00A2E8"); // sky
    gradient.addColorStop(0.7, "#FFFFFF"); // horizon
    gradient.addColorStop(1.0, "#1F9F44"); // meadows
    return gradient;
}



//------------------------------------------------------------------------------
function draw(n, code) { // draw 2 cubes next to each other
//------------------------------------------------------------------------------
    // n = order of the cubes
    //--------------------------------------------------------------------------

    // s = scaling factor / size is hardcoded here to be 15
    // it is possible to have s as an additional parameter for this function
    s = 15; // global variable

    // d = distance from borders is hardcoded here to be 10 pixels
    // it is possible to have d as an additional parameter for this function
    d = 10; // global variable
    //--------------------------------------------------------------------------

    // Notbremse
    if (n > 7) {n = 7;}
    if (n < 0) {n = 0;}

    // sn = scaling factor divided by n
    sn = s / n; // global variable

    // canvas
    var canvas = document.getElementById("Canvas");
    canvas.width  = 32*s + 4*d;
    canvas.height = 15*s + 2*d;

    // context is global variable
    ctx = canvas.getContext("2d");

    // background
    ctx.lineWidth = 2; // needed for neat border
    ctx.strokeRect(0, 0, canvas.width, canvas.height);
    ctx.lineWidth = 1; // used from now on
    ctx.fillStyle = get_Gradient(canvas.height);
    ctx.fillRect(1, 1, canvas.width - 2, canvas.height - 2);

    // create 2 empty color array of size 3xNxN
    var LColors = createArray(3, n, n),
        RColors = createArray(3, n, n);

    // fill colors from code into LColors array
    var pos = 0, nextChar = "";
    for (var f = 0; f < 3; f++) {
        for (var r = 0; r < n; r++) {
            for (var c = 0; c < n; c++) {
                nextChar = code.charAt(pos)
                if (nextChar == "," || code.charCodeAt(pos) > 64) {
                    nextChar = code.charAt(++pos)
                }
                LColors[f][r][c] = Color[ nextChar ];
                pos++
            }
        }
    }

    // fill colors from code into RColors array
    for (var f = 0; f < 3; f++) {
        for (var r = 0; r < n; r++) {
            for (var c = 0; c < n; c++) {
                nextChar = code.charAt(pos)
                if (nextChar == "," || code.charCodeAt(pos) > 64) {
                    nextChar = code.charAt(++pos)
                }
                RColors[f][r][c] = Color[ nextChar ];
                pos++
            }
        }
    }

    // draw the individual cubes
    var x = 8 * s + d; // x-coord of the highest point
    draw_Cube( n,   x, LColors );
    draw_Cube( n, 3*x, RColors );
}



//------------------------------------------------------------------------------
function createArray(length) { // multidimensional arrays
//------------------------------------------------------------------------------
    var Arr = new Array(length || 0);
    if (arguments.length > 1) {
        var args = Array.prototype.slice.call(arguments, 1);
        for (var i = 0; i < length; i++) {
            Arr[i] = createArray.apply(this, args);
        }
    }
    return Arr;
}



//------------------------------------------------------------------------------
function draw_Cube(n, x, ColorArray) { // build picture of cube
//------------------------------------------------------------------------------
    // n = order of cube, e.g. 3x3x3: n = 3
    // x = x-coord of the highest point
    // ColorArray = array of colors to use
    //--------------------------------------------------------------------------
    for (var r = 0; r < n; r++) {
        for (var c = 0; c < n; c++) {
            // draw U first, then draw F before R to avoid ugly overlapping
            ctx.fillStyle = ColorArray[0][r][c];
            draw_U( x + 8 * sn * (c-r), d + 3 * (     sn * (c + r) ) );
            ctx.fillStyle = ColorArray[2][r][c];
            draw_F( x - 8 * (s - sn*c), d + 3 * ( s + sn * (c+3*r) ) );
            ctx.fillStyle = ColorArray[1][r][c];
            draw_R( x + 8 * (s - sn*r), d + 3 * ( s + sn * (3*c+r) ) );
        }
    }
}



//------------------------------------------------------------------------------
function draw_U(x, y) { // draw a parallelogram (U)
//------------------------------------------------------------------------------
    // start at the highest point (x, y)
    //--------------------------------------------------------------------------
    ctx.beginPath();
    ctx.moveTo( x         , y          );
    ctx.lineTo( x + 8 * sn, y + 3 * sn );
    ctx.lineTo( x         , y + 6 * sn );
    ctx.lineTo( x - 8 * sn, y + 3 * sn );
    ctx.closePath();
    ctx.stroke();
    ctx.fill();
}



//------------------------------------------------------------------------------
function draw_R(x, y) { // draw a parallelogram (R)
//------------------------------------------------------------------------------
    // start at the highest point (x, y)
    //--------------------------------------------------------------------------
    ctx.beginPath();
    ctx.moveTo( x         , y           );
    ctx.lineTo( x         , y +  9 * sn );
    ctx.lineTo( x - 8 * sn, y + 12 * sn );
    ctx.lineTo( x - 8 * sn, y +  3 * sn );
    ctx.closePath();
    ctx.stroke();
    ctx.fill();
}



//------------------------------------------------------------------------------
function draw_F(x, y) { // draw a parallelogram (F)
//------------------------------------------------------------------------------
    // start at the highest point (x, y)
    //--------------------------------------------------------------------------
    ctx.beginPath();
    ctx.moveTo( x          , y           );
    ctx.lineTo( x +  8 * sn, y +  3 * sn );
    ctx.lineTo( x +  8 * sn, y + 12 * sn );
    ctx.lineTo( x          , y +  9 * sn );
    ctx.closePath();
    ctx.stroke();
    ctx.fill();
}
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: CustomBoxes: a collection of helper functions

07 Jan 2019, 22:05

This rubic cube is crazy. EDIT: and the interaction with HTML-JavaScript together is powerful
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: CustomBoxes: a collection of helper functions

08 Jan 2019, 11:54

Very nice, wolf_II! That should help me out quite a bit. Here's an animated GIF of your script to show it off :)
wolf_II.gif
wolf_II.gif (142.52 KiB) Viewed 5757 times
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: CustomBoxes: a collection of helper functions

08 Jan 2019, 12:07

@burque505: Does my demo really look like that? I notice a discrepency in appaerance of the background color gradient, also some size diff in button size
This is what I get (notice the change of Button 2 is reading "0", which is showing only the background )
20190108180506.png
20190108180506.png (6.58 KiB) Viewed 5757 times
either way, I am glad you find my experiments with the html-tags interesting/useful. :)
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: CustomBoxes: a collection of helper functions

08 Jan 2019, 12:17

@wolf_II, It looks like yours. The problem is me using an animated GIF.
Edit: whoops, there is a little difference. I'm scaled to 125%, that's probably it, I think. The gradient's bad in this screen capture also, looks fine on my screen though.
wolf_ii_ii.GIF
wolf_ii_ii.GIF (40.66 KiB) Viewed 5750 times
Last edited by burque505 on 08 Jan 2019, 12:23, edited 1 time in total.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 114 guests