File: scrolledcanvas

package info (click to toggle)
itcl3.0 3.0.1-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 10,124 kB
  • ctags: 3,519
  • sloc: tcl: 32,416; ansic: 12,683; sh: 3,911; makefile: 693; awk: 273; perl: 265
file content (56 lines) | stat: -rw-r--r-- 1,714 bytes parent folder | download | duplicates (14)
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
#!/bin/sh
# ----------------------------------------------------------------------
#  DEMO: scrolledcanvas in [incr Widgets]
# ----------------------------------------------------------------------
#\
exec itkwish -f "$0" ${1+"$@"}
package require -exact Iwidgets 2.2

# itkwish interprets the rest...
# ----------------------------------------------------------------------
option add *textBackground seashell
. configure -background white

iwidgets::scrolledcanvas .canv -labeltext "Scrolledcanvas" \
    -vscrollmode dynamic -hscrollmode dynamic -autoresize yes

pack .canv -expand yes -fill both -padx 4 -pady 4
.canv xview moveto 0
.canv yview moveto 0


button .zoomin -text "Zoom In" -command {
    .canv scale all 0 0 2 2
}
pack .zoomin -side left -expand yes -padx 4 -pady 4

button .zoomout -text "Zoom Out" -command {
    .canv scale all 0 0 0.5 0.5
    .canv xview moveto 0
    .canv yview moveto 0
}
pack .zoomout -side left -expand yes -padx 4 -pady 4


bind [.canv component scrCanvas] <ButtonPress-1> {add_rectangle %W %x %y}
bind [.canv component scrCanvas] <B1-Motion> {add_rectangle %W %x %y}

proc add_rectangle {win x y} {
    set bbox [$win bbox all]
    if {$bbox != ""} {
        set w [expr [lindex $bbox 2]-[lindex $bbox 0]]
        set x0 [lindex [$win cget -scrollregion] 0]
        set x0 [expr $x0+[lindex [$win xview] 0]*$w]
        set h [expr [lindex $bbox 3]-[lindex $bbox 1]]
        set y0 [lindex [$win cget -scrollregion] 1]
        set y0 [expr $y0+[lindex [$win yview] 0]*$h]
    } else {
        set x0 0
        set y0 0
    }

    $win create rectangle \
        [expr $x0+$x-4] [expr $y0+$y-4] \
        [expr $x0+$x+4] [expr $y0+$y+4] \
        -outline "" -fill red
}