[class] CreateElliptic (v2)

Veröffentliche deine funktionierenden Skripte und Funktionen

Moderator: jNizM

User avatar
Noitalommi_2
Posts: 278
Joined: 16 Aug 2023, 10:58

[class] CreateElliptic (v2)

12 May 2024, 10:52

CreateElliptic zeichnet einen Kreis oder eine Ellipse auf den Bildschirm.
Kann auch in Spielen als Crosshair verwendet werden wenn diese im Fenstermodus laufen.

Code: Select all

Class CreateElliptic {

	__New(CenterX, CenterY, Color, RadiusA, RadiusB, Thickness := 1, Transparency := -1, Fill := false) {

		this.CenterX := CenterX
		this.CenterY := CenterY
		this.Color := Color
		this.RadiusA := RadiusA
		this.RadiusB := RadiusB
		this.Thickness := Thickness
		this.Transparency := Transparency
		this.Fill := Fill

		this.IsVisibel := this.Exist := false
	}

	Hide() => this.IsVisibel ? (this.BackGui.Hide(), this.IsVisibel := false, 1) : 0
	Show(CenterX := this.CenterX, CenterY := this.CenterY, Color := this.Color, RadiusA := this.RadiusA, RadiusB := this.RadiusB, Thickness := this.Thickness, Transparency := this.Transparency, Fill := this.Fill) {

		if !this.Exist {

			this.Create(CenterX, CenterY, Color, RadiusA, RadiusB, Thickness, Transparency, Fill)
			return 1
		}
		else if !this.IsVisibel {

			Props := {CenterX:CenterX, CenterY:CenterY, Color:Color, RadiusA:RadiusA, RadiusB:RadiusB, Thickness:Thickness, Fill:Fill}
			For Name, Value in this.OwnProps()
				if !Props.HasOwnProp(Name)
					continue
				else if Value != Props.%Name% {
					this.Create(CenterX, CenterY, Color, RadiusA, RadiusB, Thickness, Transparency, Fill)
					return 4
				}

			this.BackGui.Show(	" x" CenterX-RadiusA
								" y" CenterY-RadiusB
								" w" RadiusA*2
								" h" RadiusB*2
								" NoActivate" )

			if Transparency <= 255 && Transparency > -1
				WinSetTransparent Transparency, "ahk_id" this.BackGui.Hwnd

			this.CenterX := CenterX
			this.CenterY := CenterY
			this.RadiusA := RadiusA
			this.RadiusB := RadiusB
			this.Thickness := Thickness
			this.Color := Color
			this.Transparency := Transparency
			this.Fill := Fill

			this.IsVisibel := true
			return 2
		}
		else if this.Exist {

			this.Destroy()
			this.Create(CenterX, CenterY, Color, RadiusA, RadiusB, Thickness, Transparency, Fill)
			return 3
		}
		return 0
	}

	Destroy() => this.Exist ? (this.BackGui.Destroy(), this.IsVisibel := this.Exist := false, 1) : 0
	Create(CenterX := this.CenterX, CenterY := this.CenterY, Color := this.Color, RadiusA := this.RadiusA, RadiusB := this.RadiusB, Thickness := this.Thickness, Transparency := this.Transparency, Fill := this.Fill) {

		this.BackGui := Gui("AlwaysOnTop ToolWindow -Caption -DPIScale")
		this.BackGui.BackColor := Color
		Outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", RadiusA*2, "Int", RadiusB*2)
		if !Fill {

			Inner := DllCall("CreateEllipticRgn", "Int", Thickness, "Int", Thickness,
				"Int", RadiusA*2-Thickness, "Int", RadiusB*2-Thickness)
			DllCall("CombineRgn", "UInt", Outer, "UInt", Outer, "UInt", Inner, "Int", RGN_XOR := 3)
		}
		DllCall("SetWindowRgn", "UInt", this.BackGui.Hwnd, "UInt", Outer, "UInt", true)

		this.BackGui.Show(	" x" CenterX-RadiusA
							" y" CenterY-RadiusB
							" w" RadiusA*2
							" h" RadiusB*2
							" NoActivate" )

		if Transparency <= 255 && Transparency > -1
				WinSetTransparent Transparency, "ahk_id" this.BackGui.Hwnd

		if !Fill
			DllCall("DeleteObject", "Ptr", Inner)

		this.CenterX := CenterX
		this.CenterY := CenterY
		this.RadiusA := RadiusA
		this.RadiusB := RadiusB
		this.Thickness := Thickness
		this.Color := Color
		this.Transparency := Transparency
		this.Fill := Fill

		this.IsVisibel := this.Exist := true
	}
}
Beispiel:

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance
#Include "CreateElliptic.ahk"


Kreis := CreateElliptic(Mittelpunkt_X := 100, ; Erstellt einen grünen, transparenten Kreis am Mittelpunkt (100,100) mit einem Radius von 60 und einer Dicke von 5.
						Mittelpunkt_Y := 100,
						Farbe := 0x00FF00,
						Radius := 60,
						Radius,
						Dicke := 5,
						Transparenz := 100) ; Eine Zahl zwischen 0 und 255 für die Transparenzstärke: 0 macht das Fenster durchsichtig und 255 undurchsichtig.


Ellipse := CreateElliptic(	Mittelpunkt_X := 500, ; Erstellt eine blaue Ellipse am Mittelpunkt (500,400) mit einer Breite von 100, einer Höhe von 150 und einer Dicke von 15.
							Mittelpunkt_Y := 400,
							Farbe := 0x0000FF,
							Breite := 100,
							Höhe := 150,
							Dicke := 15)

Punkt := CreateElliptic(200, 700, 0x0000FF, 120, 120,,, true) ; Erstellt einen blauen Punkt.
Punkt.Show() ; Zeigt den blauen Punkt.


F1::Kreis.Show() ; Zeigt den Kreis.
F2::Kreis.Hide() ; Versteckt den Kreis.
F3::Kreis.Show(A_ScreenWidth/2, A_ScreenHeight/2,, Radius := 85, Radius, 10, 255) ; Verschiebt den Kreis in die Bildschirmmitte, vergrößert den Radius auf 85, die Dicke auf 10 und hebt die Transparenz auf.

F5::Ellipse.Show() ; Zeigt die Ellipse.
F6::Ellipse.Hide() ; Versteckt die Ellipse.
F7:: {

	Ellipse.Show(A_ScreenWidth/2, A_ScreenHeight/2, 0xFF0000, 150, 100,, 100) ;  Verschiebt die Ellipse in die Bildschirmmitte, verändert Höhe, Breite, Farbe und macht die Ellipse transparent.
	Punkt.Show(A_ScreenWidth/2, A_ScreenHeight/2,, 150, 150,,, false) ; Verschiebt den blauen Kreis in die Bildschirmmitte, vergrößert ihn und hebt die Füllung auf.
}

Return to “Skripte und Funktionen”

Who is online

Users browsing this forum: No registered users and 2 guests