Page 1 of 1

using selection handles

Posted: Thu Nov 08, 2012 6:08 pm
by theoGA61d2
Hi,

Is there anyone who can point me in the right direction to use the selection handle in run time.

I am making a workflow application in which I am possible to visualise a workflow graphically with blocks (like visio) and need to draw lines between them. I would be able to select two graphical objects and let the program draw the lines but what I would like is to select an line and show the selection handles and let the user resize the line. So from one side take a selection handle and have the line behave like an elastic.

I can set the selection I see the handles but what now?

Thanks

Theo

Re: using selection handles

Posted: Thu Nov 08, 2012 8:58 pm
by FourthWorld
The key is the tool property - in your case you would want to "set the tool to pointer", or you can also use "choose pointer tool". This is currently a global property (there''s a request to make tool modes specific to groups, but it hasn't been implemented yet), so depending on your layout you may also want to look up the cantSelect property to apply to items outside of your drawing region.

Re: using selection handles

Posted: Thu Nov 08, 2012 11:51 pm
by dunbarx
Hi.

What Richard said.

I made a gadget years ago that ties invisible (not hidden) buttons at the vertices of objects. When you click and drag on those points, the button script allows one to move that button around, and to also move the vertex. Visually, it seems that only the vertex moves, though the button shows itself during the process, so that it appears that a "handle" has come into being, and is hidden when the move ends.

Can you do this? It should be a fun project.

Craig Newman

Re: using selection handles

Posted: Fri Nov 09, 2012 7:11 am
by shaosean
Here is some code that Wouter had written for me many years ago to allow someone to select and resize a control during runtime (browse mode).. Place the code in the card/stack script (could work in a behaviour and/or backScript as well, but never tested)..

Code: Select all

local lObj           -- long id of control 
local lOS            -- offset mouseloc -> loc of control 
local lhS            -- half size of the resizinghandle 
constant cS = 8      -- size of resizing handle 


on mousedown
  local tSelectedHandle
  
  if (word 1 of the target is in "field button scrollbar player image") then
    select the target
    put the long id of the selectedObject into lObj
  else
    select EMPTY
    put EMPTY into lObj
  end if
  
  if (lObj is not EMPTY) AND (the mouseLoc is within the rect of lObj) then
    put whichHandleClicked(the mouseLoc) into tSelectedHandle
    if (tSelectedHandle is not EMPTY) then
      resizeTheObj tSelectedHandle
    else
      put item 1 of the loc of lObj - mouseH(),item 2 of the loc of lObj - mouseV() into lOS
      dragObj
    end if
  end if
end mousedown 

function whichHandleClicked x
  local tList, a, tC
  put cS div 2 into lhS -- half size of resizing handle 
  get the rect of lObj 
  put item 1 of it,item 2 of it,item 1 of it + cS,item 2 of it + cS  & cr after tList -- topleft controlhandle 
  put item 3 of it - cS,item 2 of it,item 3 of it,item 2 of it + cS  & cr after tList -- topright controlhandle 
  put item 1 of it,item 4 of it - cS,item 1 of it + cS,item 4 of it  & cr after tList -- bottomleft controlhandle 
  put item 3 of it - cS,item 4 of it - cS ,item 3 of it,item 4 of it  & cr after tList -- bottomright controlhandle 
  put (item 3 of it - item 1 of it) div 2 into a 
  put item 1 of it + a - lhS,item 2 of it,item 1 of it + a +  lhS,item 2 of it + cS & cr after tList -- top middle controlhandle 
  put item 1 of it + a - lhS,item 4 of it - cS,item 1 of it + a +  lhS,item 4 of it & cr after tList -- bottom middle controlhandle 
  put (item 4 of it - item 2 of it) div 2 into a 
  put item 1 of it,item 2 of it + a - lhS,item 1 of it + cS,item 2  of it + a + lhS & cr after tList -- left middle controlhandle 
  put item 3 of it - cS,item 2 of it + a - lhS,item 3 of it,item 2  of it + a + lhS & cr after tList -- right middle controlhandle 
  put 0 into tC 
  repeat for each line i in tList 
    add 1 to tC 
    if x is within i then return item tC of  "topleft,topright,bottomleft,bottomright,topmiddle,bottommiddle,leftmidd le,rightmiddle" 
  end repeat 
end whichHandleClicked 

on resizeTheObj x 
  if the mouse is down then 
    get the rect of lObj 
    switch x 
    case "topleft" 
      set the rect of lObj to mouseh() - lhS,mousev() - lhS,item 3  of it,item 4 of it 
      break 
    case "topright" 
      set the rect of lObj to item 1 of it,mousev() - lhS,mouseh() +  lhS,item 4 of it 
      break 
    case "bottomleft" 
      set the rect of lObj to mouseh() - lhS,item 2 of it,item 3 of  it,mousev() + lhS 
      break 
    case "bottomright" 
      set the rect of lObj to item 1 of it,item 2 of it,mouseh() +  lhS,mousev() + lhS 
      break 
    case "topmiddle" 
      set the rect of lObj to item 1 of it,mousev() - lhS,item 3 of  it,item 4 of it 
      break 
    case "bottommiddle" 
      set the rect of lObj to item 1 of it,item 2 of it,item 3 of  it,mousev() + lhS 
      break 
    case "leftmiddle" 
      set the rect of lObj to mouseh() - lhS,item 2 of it,item 3 of  it,item 4 of it 
      break 
    case "rightmiddle" 
      set the rect of lObj to item 1 of it,item 2 of it,mouseh() +  lhS,item 4 of it 
      break 
    end switch 
    send "resizeTheObj" && x to me in 50 millisecs 
  end if 
end resizeTheObj 

on dragObj 
  if the mouse is down then 
    set the loc of lObj to mouseh() + item 1 of lOS,mousev() + item 2 of lOS 
    send "dragObj" to me in 50 millisecs 
  end if 
end dragObj 

Re: using selection handles

Posted: Fri Nov 09, 2012 7:57 am
by dave_probertGA6e24
Nice script Shaosean,

Be aware that there is a space in the word 'leftmiddle' in the list of whichHandleClicked which stops the left middle from being returned (drop the space and all is ok)

You can also add 'graphic' to the choice of targets alongside the field button image, etc - it seems to work too.

Hope that helps a bit.

Cheers,
Dave

Re: using selection handles

Posted: Fri Nov 09, 2012 10:06 am
by shaosean
yeah, you can even remove the line for the controls it looks for, I was only using it for a few select controls.. the code is about 10 years old and I have not really looked at it since then, so any errors - sorry.. if you need to know what anything does, feel free to ask and I will explain it..