Spawnova / ShinsOverlayClass

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

V2 Examples #13

Closed dmtr99 closed 3 months ago

dmtr99 commented 3 months ago

I have experimented with the v2 version, it seems to work well. I converted all the examples and added a new game example.

Spawnova commented 3 months ago

Awesome, I appreciate the effort and the game example you included is fantastic, very impressive! =)

dmtr99 commented 2 months ago

Thanks for the compliment. Maybe I will add a shop to upgrade the plane and a new emeny that shoots in the direction of the plane later.

But now I am working on a more serious example. I wanted to create my own menu to have more control in the colors and behaviours. But It seems that the FillRoundedRectangle does not returns correct rounds, the one in the left upper corner seems perfect, but the other are different and wrong. Do you know what happens? Is there a bug in the code?

image

dmtr99 commented 2 months ago

Here is the result: image

dmtr99 commented 2 months ago

Requires AutoHotkey v2.0

SingleInstance force

Include "shinsoverlayclass.ahk"

x := floor(a_screenwidth 0.2) y := floor(a_screenheight 0.2)

aMenu := Map() aMenu[1] := {text:"Restore", Disabled: 1, Callback: ()=>(MsgBox("Restore"))} aMenu[2] := {text:"Move", Disabled: 0, Callback: ()=>(MsgBox("Move"))} aMenu[3] := {text:"Size", Disabled: 0, Callback: ()=>(MsgBox("Size"))} aMenu[4] := {text:"Minimize", Disabled: 0, Callback: ()=>(MsgBox("Minimize"))} aMenu[5] := {text:"Maximise", Disabled: 0, Callback: ()=>(MsgBox("Maximise"))} aMenu[6] := {text:"", Disabled: 0} aMenu[7] := {text:"Close", Disabled: 0, Callback: ()=>(MsgBox("Close"))} Height := 9

for Key, oMenuItem in aMenu { if (oMenuItem.text = ""){ Height +=9 } else { Height +=22 } }

width := 148

overlay := ShinsOverlayClass(x,y,width,height,0,0,0)

aColors := {} aColors.Dark := {} aColors.Dark.Edge := 0xFF3E3E3E aColors.Dark.Background := 0XFF2c2c2c aColors.Dark.BackgroundSelected := 0XFF353535 aColors.Dark.text := 0XFFD8D8D9 aColors.Dark.textdisabled := 0XFF6B6C6B

aColors.Light := {} aColors.Light.Edge := 0xFFE5E5E5 aColors.Light.Background := 0xFFF9F9F9 aColors.Light.BackgroundSelected := 0xFFF0F0F0 aColors.Light.text := 0xFF380000 aColors.Light.textdisabled := 0xFF9F9F9F

oColor := aColors.Light

overlay.Gui.Hide() yPos := 4 for Key, oMenuItem in aMenu { if (oMenuItem.text = ""){ yPos +=9 } else { overlay.Gui.AddText("x0 y" yPos " w" width " h22 +E0x100", oMenuItem.text).onEvent("Click", ((oMenuItem,*)=>(SetTimer(draw,0), overlay.gui.destroy(),oMenuItem.Callback() )).Bind(oMenuItem)) yPos +=22 } } draw() ; OnMessage(0x201, WindowMove)

overlay.Gui.Show("x" x " y" y) SetTimer(draw,10)

f9::Reload() esc::ExitApp()

return

draw(){ global

if (overlay.BeginDraw()) {

    ;draw background
    overlay.FillRoundedRectangle(2,2,overlay.width-4,overlay.height-4,3,3,oColor.Background)
    overlay.DrawRoundedRectangle(2,2,overlay.width-4,overlay.height-4,3,3,oColor.Edge,1)

    overlay.GetMousePos(&mx,&my)

    ypos := 4
    for Key, oMenuItem in aMenu
    {
        if (oMenuItem.text = ""){
            overlay.DrawLine(9,ypos+5,overlay.width-9,8+22*(A_Index-1),oColor.Edge,1)
            ypos +=9
        } else {

            if (ypos < my and my < ypos+22 and 4 < mx and mx < overlay.width-11){
                overlay.FillRoundedRectangle(7,ypos,overlay.width-14,22,3,3,oColor.BackgroundSelected)
            }

            overlay.DrawText(oMenuItem.text,40,ypos+4,12,oMenuItem.disabled ? oColor.textdisabled : oColor.text)
            ypos +=22
        }
    }

}

overlay.EndDraw()
return

}

Gdip_GetPointsSection(X_Center,Y_Center,R_1,R_2,Sections,Offset,Section := "1"){ Section := Section -1 SectionAngle := 23.141592653589793/Sections R_2_Min := 4Offset/Sin(SectionAngle) R_2 := R_2 > R_2_Min ? R_2 : R_2_Min SweepAngle := ACos((R_1cos(SectionAngle/2)+Offsetsin(SectionAngle/2))/R_1)2 SweepAngle_2 := ACos((R_2cos(SectionAngle/2)+Offsetsin(SectionAngle/2))/R_2)2

Loop_Sections := round(R_1*SweepAngle)
    StartAngle := -SweepAngle/2 + SectionAngle*(Section)
loop Loop_Sections {
    Angle := StartAngle + (A_Index-1)*SweepAngle/(Loop_Sections-1)
    X_Arc := round(X_Center + R_1*cos(Angle))
    Y_Arc := round(Y_Center + R_1*sin(Angle))
    if (A_Index = 1){
        Points := X_Arc "," Y_Arc
        X_Arc_Start := X_Arc
        Y_Arc_Start := Y_Arc
        continue
    }
    Points .= "|" X_Arc "," Y_Arc
}

Loop_Sections := round(R_2*SweepAngle_2)
    StartAngle_2 := SweepAngle_2/2 + SectionAngle*(Section)
loop Loop_Sections {
    Angle := StartAngle_2 - (A_Index-1)*SweepAngle_2/(Loop_Sections-1)
    X_Arc := round(X_Center + R_2*cos(Angle))
    Y_Arc := round(Y_Center + R_2*sin(Angle))
    Points .= "|" X_Arc "," Y_Arc
}

Points .= "|" X_Arc_Start "," Y_Arc_Start

return Points

}

Spawnova commented 2 months ago

I think the direct2d function for rounded rectangles might just be flawed, since I'm just calling the functions with basic parameters supplied all the heavy lifting is being done by the direct2d function itself, it seems to be more noticeable on small corners

a custom function would probably need to be created then drawn with the polygon functions to get perfect rounded edges

for the mean time I added a new function SetAntialias(state) ;0=off, 1=on it can be called once, or changed mid draw to enable alias on specific draws but not others, it should help to smooth out the edges on those small corners