Spawnova / ShinsOverlayClass

A direct2d overlay for AutoHotkey
MIT License
65 stars 12 forks source link

Can we have some examples? #15

Open ClaireCJS opened 3 weeks ago

ClaireCJS commented 3 weeks ago

I know you have the broad example files, but there are no examples of how to use individual functions. For the life of me, after 45 minutes, I can't draw a single pixel with this, even with all the provided examples and documentation.

I couldn't even get this to run. I'm trying to #include your library, but .... There just don't seem to be any examples on how to do things from outside of the library file, and 100% of the ones i've found don't do anything at all no matter how much I tinker with them.

image

AutoHotKey's error messages aren't that helpful either unfortunately.

I mean this is your verbatim example from the docs, and it just makes an error.

image

Maybe if AHK's error messages were better, I wouldn't need better examples, but like... When the verbatim code you gave doesn't work in my own file, I feel like the examples aren't sufficient. I don't want to load up a ton of AHK files, I like to centralize everything into one autoexec.ahk file.

Sorry!!

Spawnova commented 3 weeks ago

Yeah, I really should add more, I'll try to think of some useful ones, regarding your script above, you are using ahk v1 syntax with a v2 script so it will throw errors like that My class requires an overlay.BeginDraw() before anything can be drawn and it must end with overlay.EndDraw() here is an example with ahk v2 syntax

#include ShinsOverlayClass.ahk
#Requires AutoHotkey v2+

x := a_screenwidth * 0.2
y := a_screenheight * 0.2
w := a_screenwidth * 0.6
h := a_screenheight * 0.6

overlay := ShinsOverlayClass(x, y, w, h, onTop := 0, vsync := 1, clickThrough := 0)

OnMessage(0x201,WM_LBUTTONDOWN) ;handle clicks for moving the window around
OnMessage(0x203,WM_LBUTTONDOWN)

moving := 0

;main loop
loop {

    if (moving) {
        postmessage(0xA1,2,,,"ahk_id " overlay.hwnd)
        while(GetKeyState("lbutton","p")) {
            sleep 100
        }
        moving := 0
    }

    if (overlay.BeginDraw()) { ;needed to begin drawing

        overlay.FillRectangle(0, 0, overlay.width, overlay.height, 0xAA000000) ;draw the background
        overlay.DrawRectangle(1, 1, overlay.width-1, overlay.height-1, 0xFFFFFFFF) ;draw the background

        if (overlay.GetMousePos(&mouseX,&mouseY)) {
            overlay.DrawText("Mouse: " mouseX ", " mouseY, 10, 10, 26)
            overlay.DrawCircle(mouseX, mouseY, 10, 0xFFFF0000)
        } else {
            overlay.DrawText("Mouse outside the overlay", 10, 10, 26, 0xFFFF0000)
        }

        overlay.DrawText("Press F8 to exit", 0, 10, 26, 0xFFFFFFFF, "Arial", "aright")

        overlay.EndDraw() ;must always call to end drawing

    }

    ;vsync is enabled so a sleep in the main loop is not required

}
return

f8::exitapp

WM_LBUTTONDOWN(a,b,*) {
    global moving := 1
}

The overlay is designed to be used in a main loop, but it could be adapted for single calls as well, you just need to add your draws between BeginDraw() and EndDraw()