Sending "xx" to the stack worked fine, but when I tried to send the "openControl" message, I got:
Is it something particular about that message?Error description: create: error in bad parent or background expression
Craig
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Is it something particular about that message?Error description: create: error in bad parent or background expression
Actually on further experimentation, 'in me' can be used with normal groups as well, so it's not specific to script widgets.dunbarx wrote: ↑Thu Aug 03, 2023 10:36 pmStam.
Aha. I am sure you are right, that the syntax is different for a widget as opposed to the IDE.
And like you, I am excited to be able to make widgets without having to learn LCB. But since I only develop for myself and friends, I will likely never actually need a widget where a group would do.
Craig
Code: Select all
local sHasCreatedVisuals, sMouseX, sClickedIndicator
local sBackroundID, sIndicatorID
########################### PROPERTIES ###########################
// rightColor
getProp rightColor
local tColor
put the rightColor of me into tColor
if tColor is empty then put "#C90076" into tColor
return tColor
end rightColor
setProp rightColor pColor
set the rightColor of me to pColor
updateVisualControls
end rightColor
// leftColor
getProp leftColor
local tColor
put the leftColor of me into tColor
if tColor is empty then put "#2986CC" into tColor
return tColor
end leftColor
setProp leftColor pColor
set the leftColor of me to pColor
updateVisualControls
end leftColor
// centerColor
getProp centerColor
local tColor
put the centerColor of me into tColor
if tColor is empty then put "#F4F6F7" into tColor
return tColor
end centerColor
setProp centerColor pColor
set the centerColor of me to pColor
updateVisualControls
end centerColor
// indicatorColor
getProp indicatorColor
local tColor
put the indicatorColor of me into tColor
if tColor is empty then put "#E6E8E8" into tColor
return tColor
end indicatorColor
setProp indicatorColor pColor
set the indicatorColor of me to pColor
updateVisualControls
end indicatorColor
// switchValue
getProp switchValue
local tValue
put the switchValue of me into tValue
if tValue is empty then put 0 into tValue
return tValue
end switchValue
setProp switchValue pValue
set the switchValue of me to pValue
updateIndicatorForValue pValue
end switchValue
########################### /PROPERTIES ##########################
on openControl
createVisualControls
layoutVisualControls
updateVisualControls
end openControl
on resizeControl
layoutVisualControls
end resizeControl
private command createVisualControls
if sHasCreatedVisuals then exit createVisualControls
lock screen
set the width of me to 70
set the height of me to 35
set the clipsToRect of me to true
if there is not a graphic "background" of me then create graphic "background" in me
put the id of graphic "background" of me into sBackroundID
set the style of control id sBackroundID to "roundRect"
set the opaque of control id sBackroundID to true
set the linesize of control id sBackroundID to 1
if there is not a graphic "indicator" of me then create graphic "indicator" in me
put the id of graphic "indicator" of me into sIndicatorID
set the style of control id sIndicatorID to "oval"
set the opaque of control id sIndicatorID to true
set the linesize of control id sIndicatorID to 1
set the backgroundColor of control id sIndicatorID to "#E6E8E8"
local tInnerGlow
put "normal" into tInnerGlow["blendMode"]
put 255,255,255 into tInnerGlow["color"]
put "gaussian" into tInnerGlow["filter"]
put 255 into tInnerGlow["opacity"]
put 255 into tInnerGlow["range"]
put 20 into tInnerGlow["size"]
put "edge" into tInnerGlow["source"]
put 0 into tInnerGlow["spread"]
set the innerGlow of control id sIndicatorID to tInnerGlow
set the switchValue of me to "center"
put true into sHasCreatedVisuals
layoutVisualControls
end createVisualControls
private command layoutVisualControls
if not sHasCreatedVisuals then exit layoutVisualControls
local tRect, tDiameter, tLength
put the rect of me into tRect
add 2 to item 1 of tRect
add 2 to item 2 of tRect
subtract 2 from item 3 of tRect
subtract 2 from item 4 of tRect
set the rect of control id sBackroundID to tRect
put item 4 of tRect - item 2 of tRect into tDiameter
set the width of control id sIndicatorID to tDiameter - 4
set the height of control id sIndicatorID to tDiameter - 4
set the roundRadius of control id sBackroundID to tDiameter
if the mouse is up then updateIndicatorForValue the switchValue of me
end layoutVisualControls
private command updateVisualControls
if not sHasCreatedVisuals then exit updateVisualControls
switch the switchValue of me
case "Left"
set the backgroundColor of control id sBackroundID to the leftColor of me
break
case "Center"
set the backgroundColor of control id sBackroundID to the centerColor of me
break
case "Right"
set the backgroundColor of control id sBackroundID to the rightColor of me
break
end switch
set the backgroundColor of control id sIndicatorID to the indicatorColor of me
end updateVisualControls
private command updateIndicatorForValue pValue
local tX
switch pValue
case "Left"
set the backgroundColor of control id sBackroundID to the leftColor of me
put the left of control id sBackroundID + 3 + the width of control id sIndicatorID/2 into tX
move control id sIndicatorID to tX, item 2 of the loc of control id sBackroundID in 200 milliseconds
set the left of control id sIndicatorID to the left of control id sBackroundID + 2
break
case "Center"
set the backgroundColor of control id sBackroundID to the centerColor of me
move control id sIndicatorID to the loc of control id sBackroundID in 200 milliseconds
break
case "Right"
set the backgroundColor of control id sBackroundID to the rightColor of me
put the right of control id sBackroundID - 3 - the width of control id sIndicatorID/2 into tX
move control id sIndicatorID to tX, item 2 of the loc of control id sBackroundID in 200 milliseconds
set the right of control id sIndicatorID to the right of control id sBackroundID -2
break
end switch
end updateIndicatorForValue
on mouseDown
if "groupbehavior" is in the long name of the target then exit to top
if the mouseLoc is within the rect of control id sIndicatorID then
put true into sClickedIndicator
put the mouseH into sMouseX
end if
pass mouseDown
end mouseDown
on mouseUp pKey
local tSegmentClicked, tRect, tR1, tR2, tR3, t3
if "groupbehavior" is in the long name of the target then exit to top
if sClickedIndicator then // drag indicator 1 step in drag direction
local tValue
put the switchValue of me into tValue
if the mouseH - sMouseX > 0 and tValue is "Left" then // go right
put "Center" into tValue
else if the mouseH - sMouseX > 0 and tValue is "Center" then // go right
put "Right" into tValue
else if the mouseH - sMouseX < 0 and tValue is "Right" then //go left
put "Center" into tValue
else if the mouseH - sMouseX < 0 and tValue is "Center" then //go left
put "Left" into tValue
end if
set the switchValue of me to tValue
else // establish 3 click zones to see if left, centre or right
put the width of control id sBackroundID / 3 into t3
put the rect of control id sBackroundID into tR1
put item 1 of tR1 + t3 into item 3 of tR1
put tR1 into tR2
add t3 to item 1 of tR2
add t3 to item 3 of tR2
put tR2 into tR3
add t3 to item 1 of tR3
add t3 to item 3 of tR3
// apply value based on click zone
if the mouseLoc is within tR1 then
set the switchValue of me to "Left"
else if the mouseLoc is within tR2 then
set the switchValue of me to "Center"
else if the mouseLoc is within tR3 then
set the switchValue of me to "Right"
end if
end if
put false into sClickedIndicator
put empty into sMouseX
end mouseUp
on mouseRelease
local tValue
if "groupbehavior" is in the long name of the target then exit to top
put the switchValue of me into tValue
if the mouseH - sMouseX > 0 and tValue is "Left" then // go right
put "Center" into tValue
else if the mouseH - sMouseX > 0 and tValue is "Center" then // go right
put "Right" into tValue
else if the mouseH - sMouseX < 0 and tValue is "Right" then //go left
put "Center" into tValue
else if the mouseH - sMouseX < 0 and tValue is "Center" then //go left
put "Left" into tValue
end if
set the switchValue of me to tValue
put false into sClickedIndicator
put empty into sMouseX
end mouseRelease
Code: Select all
on mouseUp pButtonNumber
create group "tristate1"
set the behavior of group "tristate1" to the long id of stack "groupBehavior"
send "openControl" to group "tristate1"
end mouseUp