Intial commit
This commit is contained in:
6
tcl-dp/examples/whiteboard/readme
Normal file
6
tcl-dp/examples/whiteboard/readme
Normal file
@@ -0,0 +1,6 @@
|
||||
This is the Tcl-DP whiteboard example. To use, simply start wish/tclsh
|
||||
and source the wbServer.tcl. Then you can start as many wishes as you need
|
||||
and source wbClient.tcl in each one. Note that the server cannot be a
|
||||
client also.
|
||||
|
||||
|
||||
65
tcl-dp/examples/whiteboard/wbClient.tcl
Normal file
65
tcl-dp/examples/whiteboard/wbClient.tcl
Normal file
@@ -0,0 +1,65 @@
|
||||
package require dp 4.0
|
||||
|
||||
puts "Enter hostname of server:"
|
||||
set host localhost
|
||||
set server [dp_MakeRPCClient $host 4544]
|
||||
|
||||
proc DoCmd {args} {
|
||||
global server
|
||||
eval dp_RDO $server BroadCast $args
|
||||
}
|
||||
|
||||
dp_RDO $server JoinGroup
|
||||
|
||||
wm grid . 1 1 1 1
|
||||
|
||||
# Create menu bar:
|
||||
frame .menubar -relief ridge
|
||||
menubutton .menubar.file -text "File" -menu .menubar.file.menu
|
||||
pack .menubar.file -side left
|
||||
menubutton .menubar.object -text "Objects" -menu .menubar.object.menu
|
||||
pack .menubar.object -side left
|
||||
pack .menubar -side top -fill both
|
||||
|
||||
menu .menubar.file.menu
|
||||
.menubar.file.menu add command -label "Exit" -command exit
|
||||
|
||||
menu .menubar.object.menu
|
||||
.menubar.object.menu add command -label "Clear" -command "DoCmd Clear"
|
||||
.menubar.object.menu add command -label "Circle" -command "DoCmd CreateCircle"
|
||||
|
||||
# Create canvas
|
||||
canvas .c -background blue
|
||||
pack .c -fill both
|
||||
|
||||
proc CreateRect {x y} {
|
||||
DoCmd .c create rectangle $x $y $x $y -width 4 -outline white
|
||||
}
|
||||
|
||||
proc CreateCircle {} {
|
||||
set i [.c create oval 150 150 170 170 -fill skyblue]
|
||||
.c bind $i <Any-Enter> "DoCmd .c itemconfig $i -fill red"
|
||||
.c bind $i <Any-Leave> "DoCmd .c itemconfig $i -fill SkyBlue2"
|
||||
.c bind $i <3> "DoCmd plotDown .c $i %x %y"
|
||||
.c bind $i <B3-Motion> "DoCmd plotMove .c $i %x %y"
|
||||
}
|
||||
|
||||
proc Clear {} {.c delete all}
|
||||
|
||||
proc plotDown {w item x y} {
|
||||
global plot
|
||||
$w raise $item
|
||||
set plot(lastX) $x
|
||||
set plot(lastY) $y
|
||||
}
|
||||
|
||||
proc plotMove {w item x y} {
|
||||
global plot
|
||||
$w move $item [expr $x-$plot(lastX)] [expr $y-$plot(lastY)]
|
||||
set plot(lastX) $x
|
||||
set plot(lastY) $y
|
||||
}
|
||||
|
||||
bind .c <B1-Motion> {CreateRect %x %y}
|
||||
|
||||
|
||||
30
tcl-dp/examples/whiteboard/wbServer.tcl
Normal file
30
tcl-dp/examples/whiteboard/wbServer.tcl
Normal file
@@ -0,0 +1,30 @@
|
||||
#package require dp 4.0
|
||||
|
||||
dp_MakeRPCServer 2002
|
||||
|
||||
set files {}
|
||||
set log {}
|
||||
|
||||
proc JoinGroup {} {
|
||||
global dp_rpcFile files log
|
||||
lappend files $dp_rpcFile
|
||||
foreach cmd $log {
|
||||
eval dp_RDO $dp_rpcFile $cmd
|
||||
}
|
||||
dp_atclose $dp_rpcFile append "dp_Leave $dp_rpcFile"
|
||||
}
|
||||
|
||||
proc dp_Leave {file} {
|
||||
global files
|
||||
set files [ldelete $files $file]
|
||||
}
|
||||
|
||||
proc BroadCast {args} {
|
||||
global files log
|
||||
lappend log $args
|
||||
foreach i $files {
|
||||
eval "dp_RDO $i $args"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user