global pieMenu_Tool
global pieMenu_Settings
struct pieMenu_Settings
(
start_pos = [0,0],
slice_amount = 0.0,
counter = 0,
labels = #("index_1", "index_2", "index_3", "index_4", "index_5", "index_6", "index_7", "index_8"),
selected = 0,
radius = 100,
threshold = 200,
color_unsel = (color 197 197 197),
color_box = (color 17 17 17),
fn drawLabels = for i = 1 to labels.count do -- get the point on a circle around the mouse position
(
gw.setTransform(Matrix3 1)
local x = ((Sin (slice_amount * i)) * radius + start_pos.x) -- center text
local y = -(Cos (slice_amount * i)) * radius + start_pos.y
local cbox = (box2 (x - 64) (y-18) 96 97)
cbox.w = 130
cbox.h=20
gw.wrect cbox color_box
print i
gw.wText [x-(gw.getTextExtent labels).x *0.5,y,00] labels color:color_unsel
),
fn update =
(
local curr_pos = start_pos - mouse.pos
local s = slice_amount as integer
local curr_degree = ((atan2 curr_pos.x -curr_pos.y) + 180) as integer
curr_degree = mod ((curr_degree+(s/2))/s*s) 360 -- round off the angle
for i = 1 to labels.count do
(
if curr_degree == slice_amount*(i-1) then
selected = i
if (distance start_pos mouse.pos) > threshold then
stopTool pieMenu_Tool
)
drawLabels()
gw.enlargeUpdateRect #whole
gw.updateScreen()
),
fn start =
(
unRegisterRedrawViewsCallback update
registerRedrawViewsCallback update
selected = 0
start_pos = mouse.pos
slice_amount = 360.0/labels.count
update()
),
fn error =
(
if (pieMenu_Settings.labels.count < 2) or (pieMenu_Settings.labels.count > 8) then
(
messageBox ("pieMenu_Settings() only supports 2 - 8 labels!")
return true
)
else for i in pieMenu_Settings.labels do
if classOf i != String then
(
messageBox ("pieMenu_Settings() One of the pieMenu_Settings.labels is not of class 'string'")
return true
)
return false
),
fn Run =
(
if (not pieMenu_Settings.error()) then
(
startTool pieMenu_Tool numPoints:1 --start tool
completeRedraw() -- clear any artifacts left over from drawing the text
)
pieMenu_Settings.selected
)
)
tool pieMenu_Tool
(
on start do
pieMenu_Settings.start()
on stop do
unRegisterRedrawViewsCallback pieMenu_Settings.update
on freeMove do
pieMenu_Settings.update()
on mousePoint clickno do
stopTool pieMenu_Tool
on mouseAbort clickno do
(
selected = #aborted
stopTool pieMenu_Tool
)
)
pieMenu_Settings = pieMenu_Settings()