Dragging an area on the canvas now makes a multiple selection.
Thu Nov 17 18:31:52 WET 2005 Malcolm.Wallace@cs.york.ac.uk
* Dragging an area on the canvas now makes a multiple selection.
Dragging out a rectangle on the background canvas now selects all the
nodes and control points within the dragged area. I haven't worked out
how to display the rectangle itself. The multiple selection can then be
moved by dragging any one of its items.
{
hunk ./src/Document.hs 35
- | MultipleSelection [Int] [(Int,Int)]
+ | MultipleSelection Bool [Int] [(Int,Int)]
hunk ./src/GUIEvents.hs 26
- sel = getSelection doc
hunk ./src/GUIEvents.hs 32
- if leftButton then selectNothing state
+ if leftButton then
+ pickupArea doubleMousePoint state
hunk ./src/GUIEvents.hs 45
- MultipleSelection ns vs | (edgeNr,viaNr) `elem` vs->
+ MultipleSelection _ ns vs
+ | (edgeNr,viaNr) `elem` vs->
hunk ./src/GUIEvents.hs 56
- MultipleSelection ns vs | nodeNr `elem` ns ->
+ MultipleSelection _ ns vs | nodeNr `elem` ns ->
hunk ./src/GUIEvents.hs 99
- NodeSelection i | i == j -> selectNothing state
- | i /= j -> selectMultiple (nub [i,j]) [] state
- ViaSelection e v -> selectMultiple [j] [(e,v)] state
- MultipleSelection ns vs | j `elem` ns ->
- selectMultiple (ns\\[j]) vs state
- | otherwise ->
- selectMultiple (j:ns) vs state
+ NodeSelection i
+ | i == j -> selectNothing state
+ | i /= j -> selectMultiple False (nub [i,j]) [] state
+ ViaSelection e v -> selectMultiple False [j] [(e,v)] state
+ MultipleSelection _ ns vs
+ | j `elem` ns -> selectMultiple False (ns\\[j]) vs state
+ | otherwise -> selectMultiple False (j:ns) vs state
hunk ./src/GUIEvents.hs 111
- NodeSelection i -> selectMultiple [i] [(e,v)] state
+ NodeSelection i -> selectMultiple False [i] [(e,v)] state
hunk ./src/GUIEvents.hs 114
- | otherwise -> selectMultiple [] [via,(e',v')] state
- MultipleSelection ns vs
- | via `elem` vs -> selectMultiple ns (vs\\[via]) state
- | otherwise -> selectMultiple ns (via:vs) state
+ | otherwise -> selectMultiple False [] [via,(e',v')]
+ state
+ MultipleSelection _ ns vs
+ | via `elem` vs -> selectMultiple False ns (vs\\[via])
+ state
+ | otherwise -> selectMultiple False ns (via:vs) state
hunk ./src/GUIEvents.hs 137
- MultipleSelection ns vs ->
+ MultipleSelection False ns vs ->
hunk ./src/GUIEvents.hs 139
+ MultipleSelection True _ _ ->
+ dragArea doubleMousePoint state
hunk ./src/GUIEvents.hs 158
- MultipleSelection ns vs ->
+ MultipleSelection False ns vs ->
hunk ./src/GUIEvents.hs 160
+ MultipleSelection True _ _ ->
+ dropArea offset doubleMousePoint state
hunk ./src/Math.hs 15
+ , enclosedInRectangle
hunk ./src/Math.hs 104
+
+enclosedInRectangle :: DoublePoint -> DoublePoint -> DoublePoint -> Bool
+enclosedInRectangle (DoublePoint x y) (DoublePoint x0 y0) (DoublePoint x1 y1) =
+ between x x0 x1 && between y y0 y1
+ where
+ between i j k | j <= k = j <= i && i <= k
+ | otherwise = k <= i && i <= j
hunk ./src/NetworkControl.hs 9
+ , pickupArea, dragArea, dropArea
hunk ./src/NetworkControl.hs 250
-selectMultiple :: [Int] -> [(Int,Int)] -> State g n e -> IO ()
-selectMultiple nodeNrs viaNrs state = [_$_]
+selectMultiple :: Bool -> [Int] -> [(Int,Int)] -> State g n e -> IO ()
+selectMultiple area nodeNrs viaNrs state = [_$_]
hunk ./src/NetworkControl.hs 254
- (setSelection (MultipleSelection nodeNrs viaNrs))
+ (setSelection (MultipleSelection area nodeNrs viaNrs))
hunk ./src/NetworkControl.hs 262
--- ; selectMultiple nodeNrs viaNrs state -- already selected
+-- ; selectMultiple False nodeNrs viaNrs state -- already selected
hunk ./src/NetworkControl.hs 310
+ }
+
+pickupArea :: DoublePoint -> State g n e -> IO ()
+pickupArea mousePoint state = [_$_]
+ do{ setDragging (Just (False, mousePoint)) state
+ ; selectMultiple True [] [] state
+ }
+
+-- dragArea is not like dragging a selection. It does not move anything.
+-- It only adds items into a multiple selection.
+dragArea :: DoublePoint -> State g n e -> IO ()
+dragArea mousePoint state = [_$_]
+ do{ pDoc <- getDocument state
+ ; doc <- PD.getDocument pDoc
+ ; Just (_, origin) <- getDragging state
+ ; let (ns,vs) = itemsEnclosedWithin mousePoint origin (getNetwork doc)
+ ; selectMultiple True ns vs state
+ }
+ where
+ itemsEnclosedWithin p0 p1 network =
+ ( ( Prelude.map fst
+ . Prelude.filter (\ (_,n)-> enclosedInRectangle (getPosition n) p0 p1)
+ . getNodeAssocs ) network
+ , ( Prelude.concatMap (\ (i,e)-> map (\ (j,_)-> (i,j))
+ (Prelude.filter
+ (\ (_,v)-> enclosedInRectangle
+ v p0 p1)
+ (zip [0..] (getEdgeVia e))))
+ . getEdgeAssocs ) network
+ )
+
+dropArea :: DoublePoint -> DoublePoint -> State g n e -> IO ()
+dropArea _origin mousePoint state = [_$_]
+ do{ dragArea mousePoint state -- calculate enclosure area
+ ; pDoc <- getDocument state
+ ; doc <- PD.getDocument pDoc
+ ; case getSelection doc of
+ MultipleSelection _ [] [] ->
+ PD.superficialUpdateDocument (setSelection NoSelection) pDoc
+ MultipleSelection _ ns vs ->
+ PD.superficialUpdateDocument
+ (setSelection (MultipleSelection False ns vs)) pDoc
+ _ -> return ()
+ ; setDragging Nothing state
+ ; repaintAll state
hunk ./src/NetworkView.hs 63
- MultipleSelection _ viaNrs -> do
+ MultipleSelection _ _ viaNrs -> do
hunk ./src/NetworkView.hs 74
- MultipleSelection nodeNrs _ ->
+ MultipleSelection _ nodeNrs _ ->
}