@Learning one: Thx!!! I really like the concept!
Here is my version of Radial Menu
Main changes:
-Ability to create multiple items during the script running
-Other method to verify the time since the hotkey triggering (more accurate for me)
-Other method to run selected item (tooltips added)
-Settings GUI
Update (20h45 GMT): I added a centered item called Close GUI to cancel launching instead of pressing LButton
Code:
/* ===Description=========================================================================
Original script : RADIAL MENU v2 by Learning one
Find it at AHK forum location: http://www.autohotkey.com/forum/viewtopic.php?p=308352#308352
Remixed by TomXIII (not finished!!!!!!)
*/
;#### Start: Settings and GUI creation
CoordMode, Mouse, Screen
BitmapExist()
If FileExist(A_ScriptDir "\Settings.ini") ;<Read/verify settings values and create them if none>
{
IniRead, wheelRadius, %A_ScriptDir%\Settings.ini, Settings, wheelRadius, NULL
If wheelRadius is not digit
wheelRadius := 50
IniRead, itemsNbr, %A_ScriptDir%\Settings.ini, Settings, itemsNbr, NULL
If itemsNbr is not digit
itemsNbr := 5
IniRead, buildDelay, %A_ScriptDir%\Settings.ini, Settings, buildDelay, NULL
If buildDelay is not digit
buildDelay := 200
If wheelRadius not between 50 and 200
wheelRadius := 100
If itemsNbr not between 1 and 24
itemsNbr := 12
If buildDelay not between 150 and 1000
buildDelay := 200
}
Else
{
wheelRadius := 100
itemsNbr := 12
buildDelay := 200
}
picSize := 48
picRadius := picSize/2
Gosub, CreateItems ;<Create items before for a quick display>
;<Close GUI>
Gui, 98:Add, Picture, x0 y0 w%picSize% h%picSize%, %A_ScriptDir%\bitmap.png
Gui, 98:+AlwaysOnTop +ToolWindow -Caption +LastFound
Gui, 98:Color, White
;<Settings GUI creation>
Gui, 99:Add, Text,, Wheel's Radius :
Gui, 99:Add, Edit, xp+120 yp-3 w35 vRadiusEdit Number, %wheelRadius%
Gui, 99:Add, Slider, xp+35 h20 Range50-200 ToolTip vWRSlider gGetWheelRadius, %wheelRadius%
Gui, 99:Add, Text, xm, Number of items :
Gui, 99:Add, Edit, xp+120 yp-3 w35 vItemsEdit Number, %itemsNbr%
Gui, 99:Add, Slider, xp+35 h20 Range1-24 ToolTip vINSlider gGetItemsNbr, %itemsNbr%
Gui, 99:Add, Text, xm, Building delay (msec) :
Gui, 99:Add, Edit, xp+120 yp-3 w35 vDelayEdit Number, %buildDelay%
Gui, 99:Add, Slider, xp+35 h20 Range150-1000 ToolTip vBDSlider gGetBuildDelay, %buildDelay%
Gui, 99:Add, Button, vBt gGetSettings default, Default
Gui, 99:+AlwaysOnTop +ToolWindow +LastFound
;<Tray context menu creation>
Menu, Tray, Add, Settings, ShowSettingsGUI
Menu, tray, Add,
Menu, tray, Add, Exit, Exit
Menu, tray, NoStandard
Menu, tray, Click, 1
Menu, tray, Default, Settings
Return
CreateItems: ;<Lets create items during the script running>
BitmapExist()
Loop, %itemsNbr%
{
itemNumber := itemsNbr<10 ? "0" . A_Index : A_Index
Gui, %itemNumber%:Add, Picture, x0 y0 w%picSize% h%picSize%, %A_ScriptDir%\bitmap.png
Gui, %itemNumber%: +AlwaysOnTop +ToolWindow -Caption +LastFound
Gui, %itemNumber%:Color, White
}
Return
BitmapExist()
{
IfNotExist, %A_ScriptDir%\bitmap.png
{
TrayTip, Downloading bitmap:, Please wait!
URLDownloadToFile, http://www.autohotkey.net/~TomXIII/bitmap.png, %A_ScriptDir%\bitmap.png
Loop
{
Sleep, 10
IfExist, %A_ScriptDir%\bitmap.png
Break
}
TrayTip
}
}
;########## End: Settings and GUI creation ##########
;########## Hotkey(s) ##########
!g::
GuiControlGet, var,, Pic2
MsgBox, %var%
Return
RButton::
Loop
{
If not GetKeyState("RButton", "P") OR (A_TimeSinceThisHotkey > buildDelay)
Break
}
If (A_TimeSinceThisHotkey < buildDelay)
SendInput, {RButton}
Else
{
MouseGetPos, mouseX, mouseY
deg := 0
Loop, %itemsNbr%
{
SetTimer, RadialMenuClose, 35
deg := deg ? deg+(360/itemsNbr): (360/itemsNbr)+90
pi :=4*Atan(1)
rad := deg*(pi/180)
xOffset := wheelRadius*(-1*Cos(rad))-picRadius
yOffset := wheelRadius*(-1*Sin(rad))-picRadius
itemX := mouseX + xOffset
itemY := mouseY + yOffset
itemNumber := itemsNbr<10 ? "0" . A_Index : A_Index
Gui, %itemNumber%: Show, x%itemX% y%itemY% h%picSize% w%picSize%, Item%A_Index%
WinSet, Transcolor, White 255, Item%A_Index%
}
SetTimer, GetSelectedItem, 15
}
Return
;########## End: Hotkey(s) ##########
;########## Start: Main labels ##########
RadialMenuClose:
If not (GetKeyState("RButton","P"))
{
SetTimer, GetSelectedItem, off
SetTimer, RadialMenuClose, off
Loop, %itemsNbr%
{
itemNumber := itemsNbr<10 ? "0" . A_Index : A_Index
Gui %itemNumber%:Hide
}
Gui 98:Hide
}
Return
GetSelectedItem:
Loop
{
If not GetKeyState("RButton", "P")
Break
MouseGetPos,,, WinID
WinGetTitle, item, ahk_id %WinID%
If InStr(item, "Item")
{
IniRead, itemToLaunch, %A_ScriptDir%\Settings.ini, Items, %item%, NULL
itemToLaunch := (item=="Item98") ? "Cancel" : itemToLaunch
ToolTip, %itemToLaunch%
lastItem := item
closeGuiX := mouseX-picRadius
closeGuiY := mouseY-picRadius
Gui, 98: Show, x%closeGuiX% y%closeGuiY% h%picSize% w%picSize%, Item98 ;Display the close item to cancel launching
WinSet, Transcolor, White 255, Item98
}
Else
{
ToolTip
item := ""
}
}
ToolTip
item := lastItem
If (lastItem and itemToLaunch<>"NULL")
{
If (item="Item98") ;Place mouse over the centered item to cancel launching
{
lastItem := ""
Gui 98:Hide
Exit
}
Run, %itemToLaunch%,, UseErrorLevel
If ErrorLevel
MsgBox, Launching problem for :`n%itemToLaunch%
}
lastItem := ""
Return
;######## End: Main labels ##########
;######## Start: Settings labels ########
ShowSettingsGUI:
lastWheelRadius := wheelRadius ;Stores settings to get them back if they aren't in good ranges
lastItemsNbr := itemsNbr
lastBuildDelay := buildDelay
Gui, 99:Show, h75
Return
GetWheelRadius:
GuiControlGet, wheelRadius,, WRSlider
GuiControl,, RadiusEdit, %wheelRadius%
Gosub, CreateItems
Return
GetItemsNbr:
GuiControlGet, itemsNbr,, INSlider
GuiControl,, ItemsEdit, %itemsNbr%
Gosub, CreateItems
Return
GetBuildDelay:
GuiControlGet, buildDelay,, BDSlider
GuiControl,, DelayEdit, %buildDelay%
Return
GetSettings: ;<Set sliders positions if "Edits" are set manually and verify values>
GuiControlGet, wheelRadius,, RadiusEdit
GuiControlGet, itemsNbr,, ItemsEdit
GuiControlGet, buildDelay,, DelayEdit
If wheelRadius not between 50 and 200
wheelRadius := lastWheelRadius
If itemsNbr not between 1 and 24
itemsNbr := lastItemsNbr
If buildDelay not between 150 and 1000
buildDelay := lastBuildDelay
GuiControl,, WRSlider, %wheelRadius%
GuiControl,, INSlider, %itemsNbr%
GuiControl,, BDSlider, %buildDelay%
GuiControl,, RadiusEdit, %wheelRadius%
GuiControl,, ItemsEdit, %itemsNbr%
GuiControl,, DelayEdit, %buildDelay%
Return
SaveSettings:
IniWrite, %wheelRadius%,% A_ScriptDir "\Settings.ini", Settings, wheelRadius
IniWrite, %itemsNbr%,% A_ScriptDir "\Settings.ini", Settings, itemsNbr
IniWrite, %buildDelay%,% A_ScriptDir "\Settings.ini", Settings, buildDelay
Return
99GuiClose:
Gosub, GetSettings
Sleep, 500
Gui, 99:Submit
Return
;######## End: Settings labels ########
Exit:
Gosub, SaveSettings
ExitApp
Return
The script is not complete but I think/hope it will help someone!