source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vrippack-0.31/lib/linux/tk8.4/demos/cscroll.tcl @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 3.1 KB
Line 
1# cscroll.tcl --
2#
3# This demonstration script creates a simple canvas that can be
4# scrolled in two dimensions.
5#
6# RCS: @(#) $Id: cscroll.tcl,v 1.3 2001/06/14 10:56:58 dkf Exp $
7
8if {![info exists widgetDemo]} {
9    error "This script should be run from the \"widget\" demo."
10}
11
12set w .cscroll
13catch {destroy $w}
14toplevel $w
15wm title $w "Scrollable Canvas Demonstration"
16wm iconname $w "cscroll"
17positionWindow $w
18set c $w.c
19
20label $w.msg -font $font -wraplength 4i -justify left -text "This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas.  If you click button 1 on one of the rectangles, its indices will be printed on stdout."
21pack $w.msg -side top
22
23frame $w.buttons
24pack $w.buttons -side bottom -fill x -pady 2m
25button $w.buttons.dismiss -text Dismiss -command "destroy $w"
26button $w.buttons.code -text "See Code" -command "showCode $w"
27pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
28
29frame $w.grid
30scrollbar $w.hscroll -orient horiz -command "$c xview"
31scrollbar $w.vscroll -command "$c yview"
32canvas $c -relief sunken -borderwidth 2 -scrollregion {-11c -11c 50c 20c} \
33        -xscrollcommand "$w.hscroll set" \
34        -yscrollcommand "$w.vscroll set"
35pack $w.grid -expand yes -fill both -padx 1 -pady 1
36grid rowconfig    $w.grid 0 -weight 1 -minsize 0
37grid columnconfig $w.grid 0 -weight 1 -minsize 0
38
39grid $c -padx 1 -in $w.grid -pady 1 \
40    -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
41grid $w.vscroll -in $w.grid -padx 1 -pady 1 \
42    -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
43grid $w.hscroll -in $w.grid -padx 1 -pady 1 \
44    -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
45
46
47set bg [lindex [$c config -bg] 4]
48for {set i 0} {$i < 20} {incr i} {
49    set x [expr {-10 + 3*$i}]
50    for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} {
51        $c create rect ${x}c ${y}c [expr {$x+2}]c [expr {$y+2}]c \
52                -outline black -fill $bg -tags rect
53        $c create text [expr {$x+1}]c [expr {$y+1}]c -text "$i,$j" \
54            -anchor center -tags text
55    }
56}
57
58$c bind all <Any-Enter> "scrollEnter $c"
59$c bind all <Any-Leave> "scrollLeave $c"
60$c bind all <1> "scrollButton $c"
61bind $c <2> "$c scan mark %x %y"
62bind $c <B2-Motion> "$c scan dragto %x %y"
63
64proc scrollEnter canvas {
65    global oldFill
66    set id [$canvas find withtag current]
67    if {[lsearch [$canvas gettags current] text] >= 0} {
68        set id [expr {$id-1}]
69    }
70    set oldFill [lindex [$canvas itemconfig $id -fill] 4]
71    if {[winfo depth $canvas] > 1} {
72        $canvas itemconfigure $id -fill SeaGreen1
73    } else {
74        $canvas itemconfigure $id -fill black
75        $canvas itemconfigure [expr {$id+1}] -fill white
76    }
77}
78
79proc scrollLeave canvas {
80    global oldFill
81    set id [$canvas find withtag current]
82    if {[lsearch [$canvas gettags current] text] >= 0} {
83        set id [expr {$id-1}]
84    }
85    $canvas itemconfigure $id -fill $oldFill
86    $canvas itemconfigure [expr {$id+1}] -fill black
87}
88
89proc scrollButton canvas {
90    global oldFill
91    set id [$canvas find withtag current]
92    if {[lsearch [$canvas gettags current] text] < 0} {
93        set id [expr {$id+1}]
94    }
95    puts stdout "You buttoned at [lindex [$canvas itemconf $id -text] 4]"
96}
Note: See TracBrowser for help on using the repository browser.