Radial menu class

Post your working scripts, libraries and tools for AHK v1.1 and older
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Radial menu class

07 Sep 2019, 03:25

I currently use a lot context-sensitive menus, I find it is the most user friendly to give a script to other people.
So based on the active program, the selection,... a different menu is displayed with different options.
This way, the user just needs to remember one key to press, to get the options of multiple usefull commands.

Here is an alternative radial menu with the focus on speed and efficiency.
It simply returns the result, so you can use that to make a if-statements and put the code there.

Press mbutton to display the menu.
There are 3 ways to activate the buttons:

1. Keep mbutton pressed and move to a button and release mbutton. This is the most recommended way.
2. Just click with the left mouse button.
3. Move outside the radial menu to activate the button.

An alternative key can be added, this will change the buttons you added with Add2.
Reccommended is to use 8 sections.

(Library Gdip_All.ahk is necessary for this script.)
Radial_Menu.png
Radial_Menu.png (11.97 KiB) Viewed 6670 times
This script works quite well currently, but feel free to give me pointers to improve it, or to shorten the code.

Libraries used:
- Gdip_All.ahk

Code: Select all

; Created by ahk_user @ 2019
; Creates radial Mouse menu
; V1.00046
; Changes
; Add function accepts HBitmap or files

#SingleInstance Force
#InstallMouseHook
#NoEnv

; Example Code:
mButton::
G := new Radial_Menu
G.SetSections("8")
G.Add("Save","Images/analysis_meas_distance16.gif", "1")
G.Add("Save2","Images/smt_flat_wall_mt.gif", "2")
G.Add2("Save2special","Images/analysis_meas_distance16.gif", "2")
G.SetKey("mbutton")
G.SetKeySpecial("Ctrl")
G.Add("Save3","Images/smt_flat_wall_mt.gif", "3")
G.Add("Save4","Images/smt_flat_wall_mt.gif", "4")
G.Add("Dimension","Images/dim_entity.gif", "5")
G.Add2("Save5se","Images/fbcp_asm_image.gif", "5")
G.Add("Save6","", "6")
G.Add("","", "7")
G.Add("Save8","Images/smt_flat_wall_mt.gif", "8")
RM_result := G.Show()

if (RM_result="save"){
	MsgBox, You pressed save.
}
else if (RM_result="save2"){
	MsgBox, You pressed save2.
}
else{
	MsgBox, The result is %RM_result%
}

return


Class Radial_Menu{
	static Sections, Sect_Name, Sect_Img
	__New(){
		This.Sections := "4"
		This.RM_Key := "Capslock"
	}
	
	SetSections(Sections){
		This.Sections := Sections
	}
	SetKey(RM_Key){
		This.RM_Key := RM_Key
	}
	SetKeySpecial(RM_Key2){
		This.RM_Key2 := RM_Key2
	}
	
	Add(SectionName,SectionImg,ArcNr){
		if (This.Sections < ArcNr){
			This.Sections := ArcNr
		}
		This.Sect_Name[ArcNr] := SectionName
		This.Sect_Img[ArcNr] := SectionImg
	}
	Add2(SectionName2,SectionImg2,ArcNr){
		if (This.Sections < ArcNr){
			This.Sections := ArcNr
		}
		This.Sect_Name2[ArcNr] := SectionName2
		This.Sect_Img2[ArcNr] := SectionImg2
	}
	
	Show(){
		static
		SectName := ""
		CoordMode, Mouse, Window
		MouseGetPos, X_Center, Y_Center
		WinGetPos, X_Win, Y_Win,,, A
		R_1 := 100
		R_2 := R_1*0.2
		Offset := 2
		R_3 := R_1+Offset*2+10
		
		X_Gui := X_Center - R_3 + X_Win
		Y_Gui := Y_Center - R_3 + Y_Win
		Height_Gui := R_3*2
		Width_Gui := R_3*2
		
		Width := R_3*2
		height := R_3*2
		
		if WinExist("RM_Menu"){
			Gui, 1: Destroy
		}
		
		; Start gdi+
		If !pToken := Gdip_Startup(){
			MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
			ExitApp
		}
		OnExit("ExitFunc")
		
		; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
		Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
		
		; Show the window
		Gui, 1: Show, NA x%X_Gui% y%Y_Gui% w%Width_Gui% h%Height_Gui%, RM_Menu
		
		; Get a handle to this window we have created in order to update it later
		hwnd1 := WinExist()
		
		MouseGetPos, X_Center, Y_Center
		ColorBackGround := "FCFCFC"
		ColorLineBackGround := "C6DFFC"
		ColorSelected := "C6DFFC"
		ColorLineSelected := "F5E5D6"
		
		Loop, % This.Sections { ;Setting Bitmap images of sections
			if FileExist(This.Sect_Img[A_Index]){
				pBitmap_%A_Index% := Gdip_CreateBitmapFromFile(This.Sect_Img[A_Index])
			}
			else if (This.Sect_Img[A_Index] !=""){
				pBitmap_%A_Index% := Gdip_CreateBitmapFromHBITMAP(This.Sect_Img[A_Index])
			}
			
			bWidth_%A_Index% := Gdip_GetImageWidth(pBitmap_%A_Index%)
			bHeight_%A_Index% := Gdip_GetImageHeight(pBitmap_%A_Index%)
			
			if FileExist(This.Sect_Img2[A_Index]){
				pBitmap2_%A_Index% := Gdip_CreateBitmapFromFile(This.Sect_Img2[A_Index])
			}
			else if (This.Sect_Img2[A_Index] !=""){
				pBitmap2_%A_Index% := Gdip_CreateBitmapFromHBITMAP(This.Sect_Img2[A_Index])
			}
			bWidth2_%A_Index% := Gdip_GetImageWidth(pBitmap2_%A_Index%)
			bHeight2_%A_Index% := Gdip_GetImageHeight(pBitmap2_%A_Index%)
		}
		
		Counter := 0
		loop, % This.Sections { ;Calculating Section Points
			SectionAngle := 2*3.141592653589793/This.Sections*(A_Index-1)
			
			X_Bitmap_%A_Index% := R_3+(R_1-30)*cos(SectionAngle)-8
			Y_Bitmap_%A_Index% := R_3+(R_1-30)*sin(SectionAngle)-8
			
			PointsA_%A_Index% := Gdip_GetPointsSection(R_3,R_3,R_1+Offset*2+10,R_1+Offset*2,This.Sections,Offset,A_Index)
			Points_%A_Index% := Gdip_GetPointsSection(R_3,R_3,R_1,R_2,This.Sections,Offset,A_Index)
		}
		
		; Setting brushes and Pens
		pBrush := Gdip_BrushCreateSolid("0xFF" ColorBackGround)
		pBrushA := Gdip_BrushCreateSolid("0xFF" ColorSelected)
		pBrushC := Gdip_BrushCreateSolid("0X01" ColorBackGround)
		pPen := Gdip_CreatePen("0xFF" ColorLineBackGround, 1)
		pPenA := Gdip_CreatePen("0xD2" ColorLineSelected, 1)
		
		Gdip_SetSmoothingMode(G, 4)
		
		RM_KeyState_D := 0
		Gdip_FillEllipse(G, pBrushC, R_3-R_1, R_3-R_1, 2*R_1, 2*R_1)
		
		loop, {
			RM_KeyState := GetKeyState(This.RM_Key,"P")
			RM_KeyState2 := GetKeyState(This.RM_Key2,"P")
			if !WinExist("RM_Menu"){
				Exit
			}
			if (RM_KeyState = 1){
				RM_KeyState_D := 1
			}
			if (RM_KeyState = 0 and RM_KeyState_D = 1){
				Section_Mouse := RM_GetSection(This.Sections, R_2,X_Center,Y_Center)
				if (Section_Mouse != 0){
					break
				}
				RM_KeyState_D := 0
			}
			if (GetKeyState("LButton")){
				Section_Mouse := RM_GetSection(This.Sections, R_2,X_Center,Y_Center)
				if (Section_Mouse != 0){
					break
				}
				if (Section_Mouse = 0){
					SectName := ""
					break
				}
			}
			if GetKeyState("Escape"){
				Section_Mouse := 0 
				SectName := ""
				break
			}
			
			MouseGetPos, X_Mouse, Y_Mouse
			X_Rel := X_Mouse - X_Center
			Y_Rel := Y_Mouse - Y_Center
			Center_Distance := Sqrt(X_Rel*X_Rel+Y_Rel*Y_Rel)
			
			Section_Mouse := RM_GetSection(This.Sections, R_2,X_Center,Y_Center)
			
			if (Center_Distance > R_1){
				break
			}
			if (Section_Mouse = 0){
				ToolTip
				SectName := ""
			}
			if (Section_Mouse > 0){
				Counter++
				SectName_N := This.Sect_Name[Section_Mouse]
				SectName2 := This.Sect_Name2[Section_Mouse]
				if (GetKeyState(This.RM_Key2,"P") and SectName2 !=""){
					SectName_N := This.Sect_Name2[Section_Mouse]
				}
				
				if ((X_Mouse_P != X_Mouse) or (Y_Mouse_P != Y_Mouse) or SectName_N != SectName or Counter > 500) {
					SectName := SectName_N
					CoordMode, Mouse, Window
					MouseGetPos, X_Mouse_P, Y_Mouse_P
					if (Counter > 500 or SectName_N != SectName){
						Tooltip %SectName%
						Counter := 0
					}
				}
			}
			if (Section_Mouse != Section_Mouse_Prev or A_Index = 1 or RM_KeyState2_Prev != RM_KeyState2){ ; Update GDIP   
				
				Gdip_GraphicsClear(G)
				hbm := CreateDIBSection(Width, Height) ; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
				hdc := CreateCompatibleDC() ; Get a device context compatible with the screen
				obm := SelectObject(hdc, hbm) ; Select the bitmap into the device context
				G := Gdip_GraphicsFromHDC(hdc)	; Get a pointer to the graphics of the bitmap, for use with drawing functions
				
				; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
				Gdip_SetSmoothingMode(G, 4)
				Gdip_FillEllipse(G, pBrushC, R_3-R_1, R_3-R_1, 2*R_1, 2*R_1)
				
				loop, % This.Sections {
					SectionAngle := 2*3.141592653589793/This.Sections*(A_Index-1)
					if (This.Sect_Name[A_Index] = ""){
						continue
					}
					If (A_Index = Section_Mouse){
						Gdip_FillPolygon(G, pBrushA, Points_%A_Index%)
						Gdip_DrawLines(G, pPenA, Points_%A_Index%)
						Gdip_FillPolygon(G, pBrushA, PointsA_%A_Index%)
						Gdip_DrawLines(G, pPenA, PointsA_%A_Index%)
					} 
					else {
						Gdip_FillPolygon(G, pBrush, Points_%A_Index%)
						Gdip_DrawLines(G, pPen, Points_%A_Index%)
					}
					if (GetKeyState(This.RM_Key2,"P") and This.Sect_Name2[A_Index] !=""){
						Gdip_DrawImage(G, pBitmap2_%A_Index%, X_Bitmap_%A_Index%, Y_Bitmap_%A_Index%, 16, 16*bHeight2_%A_Index%/bWidth2_%A_Index%, 0, 0, bWidth2_%A_Index%, bHeight2_%A_Index%)
					}
					else {
						Gdip_DrawImage(G, pBitmap_%A_Index%, X_Bitmap_%A_Index%, Y_Bitmap_%A_Index%, 16, 16*bHeight_%A_Index%/bWidth_%A_Index%, 0, 0, bWidth_%A_Index%, bHeight_%A_Index%)
					}
					if(This.Sect_Img[A_Index]=""){
						Gdip_TextToGraphics(G, This.Sect_Name[A_Index], "vCenter x" X_Bitmap_%A_Index% -20+8 " y" Y_Bitmap_%A_Index% -20+8 , "", "40", "40")
					}
				}
				
				; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
				; So this will position our gui at (0,0) with the Width and Height specified earlier
				UpdateLayeredWindow(hwnd1, hdc, X_Gui, Y_Gui, Width, Height)
				SelectObject(hdc, obm) ; Select the object back into the hdc
				DeleteObject(hbm) ; Now the bitmap may be deleted
				DeleteDC(hdc) ; Also the device context related to the bitmap may be deleted
				Gdip_DeleteGraphics(G) ; The graphics may now be deleted
			}
			RM_KeyState2_Prev := RM_KeyState2
			Section_Mouse_Prev := Section_Mouse
		}
		
		Tooltip
		
		SelectObject(hdc, obm) ; Select the object back into the hdc
		DeleteObject(hbm) ; Now the bitmap may be deleted
		DeleteDC(hdc) ; Also the device context related to the bitmap may be deleted
		Gdip_DeleteGraphics(G) ; The graphics may now be deleted
		
		loop, % This.Sections {
			Gdip_DisposeImage(pBitmap_%A_Index%)
			Gdip_DisposeImage(pBitmap2_%A_Index%)
		}
		
		Gdip_DeleteBrush(pBrushC)
		Gdip_DeleteBrush(pBrush)
		Gdip_DeleteBrush(pBrushA)
		Gdip_DeletePen(pPen)
		Gdip_DeletePen(pPenA)
		Gdip_Shutdown(pToken)
		Gui, 1: Destroy
		Section_Mouse := RM_GetSection(This.Sections, R_2,X_Center,Y_Center)
		if (Section_Mouse = 0){
			SectName := ""
		}
		Return % SectName
	}
}


Gdip_GetPointsSection(X_Center,Y_Center,R_1,R_2,Sections,Offset,Section = "1"){
	Section := Section -1
	SectionAngle := 2*3.141592653589793/Sections
	R_2_Min := 4*Offset/Sin(SectionAngle)
	R_2 := R_2 > R_2_Min ? R_2 : R_2_Min
	SweepAngle := ACos((R_1*cos(SectionAngle/2)+Offset*sin(SectionAngle/2))/R_1)*2
	SweepAngle_2 := ACos((R_2*cos(SectionAngle/2)+Offset*sin(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
}

;#######################################################################

RM_GetSection(Sections, R_2,X_Center,Y_Center){
	CoordMode, Mouse, Window
	MouseGetPos, X_Mouse, Y_Mouse
	X_Rel := X_Mouse - X_Center
	Y_Rel := Y_Mouse - Y_Center 
	Distance_Center := Sqrt(X_Rel*X_Rel+Y_Rel*Y_Rel)
	if (X_Rel = 0){ ; (correction to prevent X to be 0)
	   X_Rel = 0.01
	}
	if (Y_Rel = 0){ ; (correction to prevent Y to be 0)
	   Y_Rel = 0.01
	}
	if (Distance_Center < R_2){
		Section_Mouse := "0"
		return Section_Mouse
	}
	else if (Distance_Center > R_2){
		a := X_Rel = 0 ? (Y_Rel = 0 ? 0 : Y_Rel > 0 ? 90 : 270) : atan(Y_Rel/X_Rel)*57.2957795130823209 ; 180/pi
		Angle := X_Rel < 0 ? 180 + a : a < 0 ? 360 + a : a
		Section_Mouse := 1+round(Angle/360*Sections)
		if (Section_Mouse > Sections){
			Section_Mouse := 1
		}
	}
	return Section_Mouse
}

RM_BuildRM(RM_Name){
	global RM_File_Settings := A_ScriptDir "\RM_Settings.ini"
	IniRead, Sections,  %RM_File_Settings%,  %RM_Name%, Sections,  8
	loop, %Sections% {
		IniRead, RM_B%A_Index%_Name,  %RM_File_Settings%,  %RM_Name%,  RM_B%A_Index%_Name, Name
		if (RM_B%A_Index%_Name = "Default"){
			continue
		}
		IniRead, RM_B%A_Index%_img,  %RM_File_Settings%,  %RM_Name%,  RM_B%A_Index%_img, %A_Space%
		IniRead, RM_B%A_Index%_Script,  %RM_File_Settings%,  %RM_Name%,  RM_B%A_Index%_Script, %A_Space%
		StringReplace, RM_B%A_Index%_Script,RM_B%A_Index%_Script,`<br`>,`n,all
		
		G.Add(RM_B%A_Index%_Name,RM_B%A_Index%_img,A_Index)
	}
	G.SetSections(Sections)
	Result := G.Show()
	loop, %Sections% {
		if (Result=RM_B%A_Index%_Name and RM_B%A_Index%_Script = != ""){
			Script := RM_B%A_Index%_Script
			Function := RegExMatch(Script,"([^\(]*)\((.*)\)","$1")
			Var := RegExMatch(Script,"([^\(]*)\((.*)\)","$1")
			%Function%(Var)
		}
	}
	return Result
}

RM_MenuSettings(RM_Name){
	RM_File_Settings :=  A_ScriptDir "\RM_Settings.ini"
	IniRead, Sections,  %RM_File_Settings%,  %RM_Name%, Sections,  8
	G := new Radial_Menu
	loop, %Sections% {
		IniRead, RM_B%A_Index%_Name,  %RM_File_Settings%,  %RM_Name%,  RM_B%A_Index%_Name, Name
		if (RM_B%A_Index%_Name = "Default"){
			continue
		}
		IniRead, RM_B%A_Index%_img,  %RM_File_Settings%,  %RM_Name%,  RM_B%A_Index%_img, %A_Space%
		IniRead, RM_B%A_Index%_Script,  %RM_File_Settings%,  %RM_Name%,  RM_B%A_Index%_Script, %A_Space%
		StringReplace, RM_B%A_Index%_Script,RM_B%A_Index%_Script,`<br`>,`n,all
		G.Add(RM_B%A_Index%_Name, RM_B%A_Index%_img , A_Index)
	}
	G.SetSections(Sections)
	Result := G.Show()
	loop, %Sections% {
		if (RM_B%A_Index%_Name and RM_B%A_Index%_Script){
			if (Result=RM_B%A_Index%_Name){
				return RM_B%A_Index%_Script 
				Exit
			}
		}
	}
	return Result
}

ExitFunc(){
	global
	; gdi+ may now be shutdown on exiting the program
	Gdip_Shutdown(pToken)
	return
}


#IncludeAgain %A_ScriptDir%\Gdip_All.ahk
Last edited by AHK_user on 20 Jul 2021, 06:13, edited 7 times in total.
User avatar
Learning one
Posts: 173
Joined: 04 Oct 2013, 13:59
Location: Croatia
Contact:

Re: Radial menu class

07 Sep 2019, 05:46

Great job AHK_user! I like it ;)
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Radial menu class

07 Sep 2019, 07:41

I like that. Nice code and nice design.

I have two recommendations:

1. this will work better
RM_File_Settings := A_ScriptDir "\RM_Settings.ini
than that
RM_File_Settings := A_MyDocuments "\Q-Vision\RM\RM_Settings.ini

2. It would be nice to give a HBitmap handle instead of a filepath. I like to store small picture as Base64 in my scripts.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Radial menu class

09 Sep 2019, 14:05

Frosti wrote:
07 Sep 2019, 07:41
I like that. Nice code and nice design.

I have two recommendations:

1. this will work better
RM_File_Settings := A_ScriptDir "\RM_Settings.ini
than that
RM_File_Settings := A_MyDocuments "\Q-Vision\RM\RM_Settings.ini

2. It would be nice to give a HBitmap handle instead of a filepath. I like to store small picture as Base64 in my scripts.
Thanks for the responses.

I have modified the add function, It should also accepts Hbitmap now.

The settings file location is also changed.

Is it maybe possible to show me an example of the use of Hbitmap and how to convert a image file to Hbitmap inside the code?
It would be usefull to have the images inside the script.

I haven't posted a lot on the forum, does anybody knows why my image is "Broken Link for safety"?
gregster
Posts: 9012
Joined: 30 Sep 2013, 06:48

Re: Radial menu class

09 Sep 2019, 14:22

AHK_user wrote:
09 Sep 2019, 14:05
I haven't posted a lot on the forum, does anybody knows why my image is "Broken Link for safety"?
Earlier this year, we had a massive spam attack over several weeks (unfortunately, this included, among other things, posts with horrible photos). As a consequence, we (tank, to be more precise) gradually had to tighten posting rules. That's why now new users and older users with very few posts (there were sleeper accounts involved, too) are restricted in posting external links or images (and in quoting, which was also misused heavily to put a strain our server). Sorry for the inconvenience.

I now fixed the image link again (I had it done once before), but the next time you edit he first post, it will probably break again until you reach a certain threshold. I don't mind to fix it again, but...

Let me suggest, that you instead upload the picture via the forum "full editor & preview": please scroll down to 'Attachments' > click 'Add files' (upload up to three pictures per post) > Click 'Place inline' if you want to insert an image somewhere between text instead at the end of the post. You should have the permissions to do this... afaik.

Upload images.png
Upload images.png (6.26 KiB) Viewed 6694 times

This above is a picture that was placed inline.
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Radial menu class

11 Sep 2019, 20:14

Dude, this is really cool thank you for sharing it:)
ahkuser_
Posts: 1
Joined: 11 Feb 2020, 22:25

Re: Radial menu class

11 Feb 2020, 22:36

This is very nice! I like how clean it is. May I ask what the .ini file is for and if you have an example of the ini file? Thanks again.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Radial menu class

12 Feb 2020, 14:56

ahkuser_ wrote:
11 Feb 2020, 22:36
This is very nice! I like how clean it is. May I ask what the .ini file is for and if you have an example of the ini file? Thanks again.
Thanks, I use it every day at my work.

It has been a long time when I wrote the part of the ini file, it was with the intention to build a radial menu by an ini file, so the same script could display different menus with different commands and order depending on the ini file.
I have not used the ini functionality a lot, but these functions should work.

RM_BuildRM(RM_Name) can make a Radial menu that runs a function.
The section in the ini file is the name of the Radial menu, and these are the parameters:
RM_B1_Name (name of the command)
RM_B1_img (path of the image file)
RM_B1_script (this should be a function with one variable like 'msgbox(test)', if you would make a custom function msgbox(var), this would display a msgbox that displays test...)
RM_B2_Name
RM_B2_img
RM_B2_script
....

RM_MenuSettings(RM_Name) works quite similar, but just returns a string with the content of RM_B1_script, so you can catch this result and make if-statements to determine what shoud happen depending on the result.

I've done a little bit of work on a gui userfriendly gui to set up the radial menu with ini file, It was almost ready, but never finalized it because lack of time and interest, If you are interested to finish it, I can post it so you want complete it, or if there is a demand for it, I can finish it if I find some time.
sixtyone
Posts: 6
Joined: 30 Jun 2018, 00:59

Re: Radial menu class

12 May 2020, 01:39

Why is there no text "Save6"?
Image
Attachments
123.png
123.png (13.77 KiB) Viewed 5139 times
thebbandit
Posts: 45
Joined: 02 Jul 2019, 11:34

Re: Radial menu class

26 Oct 2020, 13:31

AHK_user wrote:
12 Feb 2020, 14:56
ahkuser_ wrote:
11 Feb 2020, 22:36
This is very nice! I like how clean it is. May I ask what the .ini file is for and if you have an example of the ini file? Thanks again.
Thanks, I use it every day at my work.

It has been a long time when I wrote the part of the ini file, it was with the intention to build a radial menu by an ini file, so the same script could display different menus with different commands and order depending on the ini file.
I have not used the ini functionality a lot, but these functions should work.

RM_BuildRM(RM_Name) can make a Radial menu that runs a function.
The section in the ini file is the name of the Radial menu, and these are the parameters:
RM_B1_Name (name of the command)
RM_B1_img (path of the image file)
RM_B1_script (this should be a function with one variable like 'msgbox(test)', if you would make a custom function msgbox(var), this would display a msgbox that displays test...)
RM_B2_Name
RM_B2_img
RM_B2_script
....

RM_MenuSettings(RM_Name) works quite similar, but just returns a string with the content of RM_B1_script, so you can catch this result and make if-statements to determine what shoud happen depending on the result.

I've done a little bit of work on a gui userfriendly gui to set up the radial menu with ini file, It was almost ready, but never finalized it because lack of time and interest, If you are interested to finish it, I can post it so you want complete it, or if there is a demand for it, I can finish it if I find some time.
Was really hoping to see any update :) would be happy to help pitch in on development of this if you post your progress.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Radial menu class

31 Jan 2022, 14:59

I created the v2 beta.3 version of this script:
viewtopic.php?f=83&t=99651
User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: Radial menu class

03 May 2023, 20:23

Awesome and light weight script! Can you please finish or explain more about the ini. I want to make many of these menu based on different intentions.
Thanks
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Radial menu class

06 May 2023, 13:53

iilabs wrote:
03 May 2023, 20:23
Awesome and light weight script! Can you please finish or explain more about the ini. I want to make many of these menu based on different intentions.
Thanks
The Ini was an idea to let the users modify their own menu, but I never finished or needed it.
I do however see an advantage, but If I have the time to implement it, I would probably do it in V2.

The function RM_MenuSettings(RM_Name) can be used to call the custom menu, and this will return a string that should be used by the code to exicute the correct action.
just see what the code reads from the ini file

quick example:
ini file:

Code: Select all

["RMExample"]
Sections=2
RM_B1_Name=test 1
RM_B1_img= path to image 1
RM_B1_Script= 1
RM_B2_Name=test 2
RM_B2_img= path to image 2
RM_B2_Script= 2
if you would call RM_MenuSettings("RMExample"), this would display a simle pie menu.
I had some ideas to create a Gui to let the user define the menu, but never finished it.

Maybe I will finish it on the V2 version, but I do not plan any work on the V1 version, but feel free to propose updates.
User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: Radial menu class

06 May 2023, 16:57

That would be awesome. Very useful script.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Radial menu class

22 May 2023, 12:42

I tried to create a gui to let the user set up their own menu, but I get a GDIP error when I use the menu twice (hotkey F1) and afterwards click on the pie button of the gui.

Radial Menu_Example2.ahk

Can anybody tell me what I do wrong and how I can fix it?
JFGukzKVFp.png
JFGukzKVFp.png (21.34 KiB) Viewed 1931 times
maessof
Posts: 2
Joined: 27 Jan 2024, 05:29

Re: Radial menu class

27 Jan 2024, 05:38

To get second section text showing when you hold the special key.

find the below if

Code: Select all

if(This.Sect_Img[A_Index]="")
and adjust to the below

Code: Select all

if(This.Sect_Img[A_Index]="")
{
	if ( !GetKeyState(This.RM_Key2,"P") )
	{
		Gdip_TextToGraphics(G, This.Sect_Name[A_Index] , "vCenter x" X_Bitmap_%A_Index% -20+8 " y" Y_Bitmap_%A_Index% -20+8 , "", "40", "40")
	}
	else
	{
		Gdip_TextToGraphics(G, This.Sect_Name2[A_Index], "vCenter x" X_Bitmap_%A_Index% -20+8 " y" Y_Bitmap_%A_Index% -20+8 , "", "40", "40")
	}
}
its in two places in the file I adjusted the first for now
maessof
Posts: 2
Joined: 27 Jan 2024, 05:29

Re: Radial menu class

27 Jan 2024, 05:43

Also might want to adjust

if (GetKeyState("Escape"))
to
if (GetKeyState("Escape", "P"))
MancioDellaVega
Posts: 83
Joined: 16 May 2020, 12:27
Location: Italy

Re: Radial menu class

25 Feb 2024, 02:32

Amazing work!!! thanks :clap: :clap: :clap:
Courses on AutoHotkey

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 96 guests