| Example: Selecting RectangleShape | |
![]() | |
{import * from CURL.GUI.SHAPES}
{let cd:ColorDropdown =
{ColorDropdown}
}
{VBox
spacing = 1mm,
cd,
{DiscreteGraphicSelectionFrame
draw-style = "none",
{Canvas
width = 9cm,
height = 8cm,
background = "#eeeeee",
color = FillPattern.silver,
{ShapeGroup
translation = {Distance2d 0cm, 7cm},
cursor = cursor-hand,
{RectangleShape
{GRect 0cm, 1cm, 1cm, 0cm},
shape-selectable = {ShapeSelectable},
translation = {Distance2d (1.1cm * 1), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 2cm, 0cm},
shape-selectable = {ShapeSelectable},
translation = {Distance2d (1.1cm * 2), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 5cm, 0cm},
shape-selectable = {ShapeSelectable},
translation = {Distance2d (1.1cm * 3), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 4cm, 0cm},
shape-selectable = {ShapeSelectable},
translation = {Distance2d (1.1cm * 4), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 3cm, 0cm},
shape-selectable = {ShapeSelectable},
translation = {Distance2d (1.1cm * 5), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 5cm, 0cm},
shape-selectable = {ShapeSelectable},
translation = {Distance2d (1.1cm * 6), 0cm}
}
}
},
{on event:SelectionChanged at cx:DiscreteGraphicSelectionFrame do
{for s:ShapeSelectable in cx.selection.items do
set s.shape.color = cd.value
}
}
}
}
|
| Example: Selecting a ShapeGroup | |
![]() | |
{import * from CURL.GUI.SHAPES}
{let cd:ColorDropdown =
{ColorDropdown}
}
{VBox
spacing = 1mm,
cd,
{DiscreteGraphicSelectionFrame
draw-style = "mask",
{Canvas
width = 9cm,
height = 8cm,
border-width = 1px,
background = "#eeeeee",
{ShapeGroup
cursor = cursor-hand,
translation = {Distance2d 0cm, 7cm},
color = "#2462a2", || blue
shape-selectable = {ShapeSelectable},
{RectangleShape
{GRect 0cm, 1cm, 2cm, 0cm},
translation = {Distance2d (1.1cm * 2), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 4cm, 0cm},
translation = {Distance2d (1.1cm * 4), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 5cm, 0cm},
translation = {Distance2d (1.1cm * 6), 0cm}
}
},
{ShapeGroup
cursor = cursor-hand,
translation = {Distance2d 0cm, 7cm},
shape-selectable = {ShapeSelectable},
color = "#006968", || green
{RectangleShape
{GRect 0cm, 1cm, 1cm, 0cm},
translation = {Distance2d (1.1cm * 1), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 5cm, 0cm},
translation = {Distance2d (1.1cm * 3), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 3cm, 0cm},
translation = {Distance2d (1.1cm * 5), 0cm}
}
}
},
{on event:SelectionChanged at cx:DiscreteGraphicSelectionFrame do
{for s:ShapeSelectable in cx.selection.items do
set s.shape.color = cd.value
}
}
}
}
|
| Example: Drag and Drop Shapes | |
![]() | |
{import * from CURL.GUI.SHAPES}
{let drag-over-handler:EventHandler =
{on e:DragOver do
{e.will-accept-drop?
{proc {a:Type,
b:Distance,
c:Distance,
d:#DragEffect
}:DragEffect
{return drag-effect-move}
} } }
}
{let drop-handler:EventHandler =
{on e:Drop at c:Canvas do
{e.accept-drop
{proc
{w:any,
x:Distance,
y:Distance,
z:#DragEffect
}:DropResult
{return
{DropResultMove
action =
{proc {}:void
|| As of 7.0, you can use the same technique for computing the
|| drop position with Shapes, Graphics, or any other objects.
let dragee:Dragee = {non-null w.dragee}
|| Compute the new position in the drop container:
let (real-x:Distance, real-y:Distance) =
{dragee.get-drop-position x, y, c}
{c.add w, x = real-x, y = real-y}
}
} } } } }
}
{value
let rectangle-shape:RectangleShape =
{RectangleShape
{GRect 0cm, 3cm, 0cm, 3cm},
cursor = cursor-hand,
color = FillPattern.magenta,
dragee = {ShapeDragee},
translation = {Distance2d 1cm, 1cm}
}
let rectangle-shape1:RectangleShape =
{RectangleShape
{GRect 0cm, 3cm, 0cm, 3cm},
cursor = cursor-hand,
dragee = {ShapeDragee},
color = FillPattern.orange
}
let rectangle-shape2:RectangleShape =
{RectangleShape
{GRect 0cm, 3cm, 0cm, 3cm},
cursor = cursor-hand,
dragee = {ShapeDragee},
color = FillPattern.cyan,
translation = {Distance2d 2cm, 2cm}
}
let can:Canvas =
{Canvas
width = 10cm,
height = 5cm,
border-width = 1px,
opaque-to-events? = true,
drag-over-handler,
drop-handler,
rectangle-shape,
rectangle-shape1,
rectangle-shape2
}
can
}
|
| Example: Drag and Drop a ShapeGroup | |
![]() | |
{import * from CURL.GUI.SHAPES}
{let drag-over-handler:EventHandler =
{on e:DragOver do
{e.will-accept-drop?
{proc {a:Type,
b:Distance,
c:Distance,
d:#DragEffect
}:DragEffect
{return drag-effect-move}
} } }
}
{let drop-handler:EventHandler =
{on e:Drop at c:Canvas do
{e.accept-drop
{proc
{w:any,
x:Distance,
y:Distance,
z:#DragEffect
}:DropResult
{return
{DropResultMove
action =
{proc {}:void
|| As of 7.0, you can use the same technique for computing the
|| drop position with Shapes, Graphics, or any other objects.
let dragee:Dragee = {non-null w.dragee}
|| Compute the new position in the drop container:
let (real-x:Distance, real-y:Distance) =
{dragee.get-drop-position x, y, c}
{c.add w, x = real-x, y = real-y}
} } } } } }
}
{Canvas
width = 9cm,
height = 8cm,
opaque-to-events? = true,
drag-over-handler,
drop-handler,
border-width = 1px,
{ShapeGroup
cursor = cursor-hand,
translation = {Distance2d 0cm, 7cm},
dragee = {ShapeDragee},
shape-selectable = {ShapeSelectable},
color = "#2462a2",
{RectangleShape
{GRect 0cm, 1cm, 2cm, 0cm},
translation = {Distance2d (1.1cm * 2), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 4cm, 0cm},
translation = {Distance2d (1.1cm * 4), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 5cm, 0cm},
translation = {Distance2d (1.1cm * 6), 0cm}
}
},
{ShapeGroup
cursor = cursor-hand,
translation = {Distance2d 0cm, 7cm},
dragee = {ShapeDragee},
shape-selectable = {ShapeSelectable},
color = "#006968",
{RectangleShape
{GRect 0cm, 1cm, 1cm, 0cm},
translation = {Distance2d (1.1cm * 1), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 5cm, 0cm},
translation = {Distance2d (1.1cm * 3), 0cm}
},
{RectangleShape
{GRect 0cm, 1cm, 3cm, 0cm},
translation = {Distance2d (1.1cm * 5), 0cm}
}
}
}
|
| Example: Arrow Follows a Dragged Shape | |
![]() | |
{import * from CURL.GUI.SHAPES}
{let drag-over-handler:EventHandler =
{on e:DragOver do
{e.will-accept-drop?
{proc {a:Type,
b:Distance,
c:Distance,
d:#DragEffect
}:DragEffect
{return drag-effect-move}
}
}
}
}
{let drop-handler:EventHandler =
{on e:Drop at c:Canvas do
{e.accept-drop
{proc
{w:any,
x:Distance,
y:Distance,
z:#DragEffect
}:DropResult
{return
{DropResultMove
action =
{proc {}:void
|| As of 7.0, you can use the same technique for computing the
|| drop position with Shapes, Graphics, or any other objects.
let dragee:Dragee = {non-null w.dragee}
|| Compute the new position in the drop container:
let (real-x:Distance, real-y:Distance) =
{dragee.get-drop-position x, y, c}
{c.add w, x = real-x, y = real-y}
{for s:Shape in c.shape-children do
{if s.name == "arrow" then
def a = s asa ArrowShape
|| Here we assume that a's coordinate system is the same
|| as that of w's parent, as a shortcut.
set a.head = {Distance2d real-x - 2cm, real-y}
}
}
}
}
}
}
}
}
}
{let txt1:TextFlowBox =
{TextFlowBox
width = 2.7cm,
horigin = "center",
vorigin = "center",
{paragraph
paragraph-justify = "center",
This text is contained in a
{monospace TextFlowBox}, which is a
{monospace Graphic} object.
},
color = FillPattern.black
}
}
{let txt2:TextFlowBox =
{TextFlowBox
width = 2.7cm,
horigin = "center",
vorigin = "center",
{paragraph
paragraph-justify = "center",
This text is also contained in a
{monospace TextFlowBox}, which is a
{monospace Graphic} object.
},
color = FillPattern.black
}
}
{let rect1:RectangleShape =
{RectangleShape
{GRect 2cm, 2cm, 2.5cm, 2.5cm},
color = "#ddffff",
font-size = 11pt
}
}
{let rect2:RectangleShape =
{RectangleShape
{GRect 2cm, 2cm, 2.5cm, 2.5cm},
cursor = cursor-hand,
color = "#ffffdd",
dragee = {ShapeDragee},
font-size = 11pt
}
}
{let arr:ArrowShape =
{ArrowShape
{Distance2d 4cm, 2.5cm},
{Distance2d 8cm, 2.5cm},
arrow-body-width = 1px,
arrow-head-width = 11px,
arrow-head-style = ArrowStyle.simple,
arrow-tail-style = ArrowStyle.none,
name = "arrow"
}
}
{value
{rect1.add txt1}
{rect2.add txt2}
{rect1.apply-translation 2cm, 2.5cm}
{rect2.apply-translation 10cm, 2.5cm}
{Canvas
width = 15cm, height = 15cm,
opaque-to-events? = true,
border-width = 1px,
drag-over-handler,
drop-handler,
rect1,
rect2,
arr
}
}
|
| Example: Drag and Drop with Selected Shapes | |
![]() | |
{import * from CURL.GUI.SHAPES}
{let drag-over-handler:EventHandler =
{on e:DragOver do
{e.will-accept-drop?
{proc {a:Type,
b:Distance,
c:Distance,
d:#DragEffect
}:DragEffect
{return drag-effect-move}
} } }
}
{let drop-handler:EventHandler =
{on e:Drop at c:Canvas do
{e.accept-drop
{proc
{w:any,
x:Distance,
y:Distance,
z:#DragEffect
}:DropResult
{return
{DropResultMove
action =
{proc {}:void
|| As of 7.0, you can use the same technique for computing the
|| drop position with Shapes, Graphics, or any other objects.
let dragee:Dragee = {non-null w.dragee}
|| Compute the new position in the drop continer:
let (real-x:Distance, real-y:Distance) =
{dragee.get-drop-position x, y, c}
{c.add w, x = real-x, y = real-y}
} } } } } }
}
{DiscreteGraphicSelectionFrame
draw-style = "mask",
{Canvas
width = 9cm,
height = 8cm,
opaque-to-events? = true,
border-width = 1px,
drag-over-handler,
drop-handler,
{RectangleShape
{GRect 0cm, 1cm, 2cm, 0cm},
dragee = {ShapeDragee},
shape-selectable = {ShapeSelectable},
color = "#2462a2",
translation = {Distance2d (1.1cm * 2), 7cm}
},
{RectangleShape
{GRect 0cm, 1cm, 4cm, 0cm},
dragee = {ShapeDragee},
shape-selectable = {ShapeSelectable},
color = "#2462a2",
translation = {Distance2d (1.1cm * 4), 7cm}
},
{RectangleShape
{GRect 0cm, 1cm, 5cm, 0cm},
dragee = {ShapeDragee},
shape-selectable = {ShapeSelectable},
color = "#2462a2",
translation = {Distance2d (1.1cm * 6), 7cm}
},
{RectangleShape
{GRect 0cm, 1cm, 1cm, 0cm},
dragee = {ShapeDragee},
shape-selectable = {ShapeSelectable},
color = "#006968",
translation = {Distance2d (1.1cm * 1), 7cm}
},
{RectangleShape
{GRect 0cm, 1cm, 5cm, 0cm},
dragee = {ShapeDragee},
shape-selectable = {ShapeSelectable},
color = "#006968",
translation = {Distance2d (1.1cm * 3), 7cm}
},
{RectangleShape
{GRect 0cm, 1cm, 3cm, 0cm},
dragee = {ShapeDragee},
shape-selectable = {ShapeSelectable},
color = "#006968",
translation = {Distance2d (1.1cm * 5), 7cm}
}
}
}
|