File: canvas_trlines.tcl

package info (click to toggle)
tklib 0.6%2B20190108-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,008 kB
  • sloc: tcl: 75,757; sh: 5,789; ansic: 792; pascal: 359; makefile: 70; sed: 53; exp: 21
file content (95 lines) | stat: -rw-r--r-- 2,195 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
## -*- tcl -*-
# # ## ### ##### ######## ############# #####################
##
# Canvas Behavior Module. Managing semi-crosshair rubber bands when
# dragging. Tracers are lines from fixed points to current location
# Purely visual. Driven from the outside. No bindings of its own.
##

## TODO : Callback to customize the rubberband lines.

# # ## ### ##### ######## ############# #####################
## Requisites

package require Tcl 8.5
package require Tk
package require snit

namespace eval ::canvas::track {
    namespace export lines
    namespace ensemble create
}

# # ## ### ##### ######## ############# #####################
## API

snit::type ::canvas::track::lines {
    # # ## ### ##### ######## ############# #####################
    ## Lifecycle management

    constructor {c} {
	set mycanvas $c
	return
    }

    destructor {
	$self done
    }

    # # ## ### ##### ######## ############# #####################
    ## API.

    method start {center args} {
	if {![llength $args]} return
	$self done

	# args = list of pairs, each pair contains the x- and
	# y-coordinates of a fixed point.
	# center is current location.

	set mycoords $args
	set myitems  {}

	foreach p $mycoords {
	    lappend myitems [$mycanvas create line \
				 {*}$p {*}$center \
				 -width 0 -fill black -dash .]
	}
	return
    }

    method move {center} {
	if {![llength $myitems]} return
	foreach p $mycoords item $myitems {
	    $mycanvas coords $item {*}$p {*}$center
	}
	return
    }

    method done {} {
	if {![llength $myitems]} return
	$mycanvas delete {*}$myitems
	set myitems {}
	set mycoords {}
	return
    }

    # # ## ### ##### ######## ############# #####################
    ## STATE

    variable mycanvas {} ; # The canvas we are working with/on.
    variable mycoords {} ; # List of fixed points for the rubberbands.
    variable myitems  {} ; # Liust of the canvas items representing the rubberbands.

    ##
    # # ## ### ##### ######## ############# #####################
}

# # ## ### ##### ######## ############# #####################
## Ready

package provide canvas::track::lines 0.1
return

# # ## ### ##### ######## ############# #####################
## Scrap yard.