home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / tcl / 2456 < prev    next >
Encoding:
Internet Message Format  |  1993-01-23  |  2.2 KB

  1. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!henry!mathew
  2. From: mathew@elroy.Jpl.Nasa.Gov (Mathew Yeates)
  3. Newsgroups: comp.lang.tcl
  4. Subject: Re: Can windows be dragged on a canvas?
  5. Date: 22 Jan 93 19:09:04 GMT
  6. Organization: Image Analysis Systems Group, JPL
  7. Lines: 54
  8. Message-ID: <mathew.727729744@henry>
  9. References: <mathew.727663312@henry> <SPENCER.93Jan22105320@guraldi.med.umich.edu>
  10. NNTP-Posting-Host: henry.jpl.nasa.gov
  11.  
  12. spencer@med.umich.edu (Spencer W. Thomas) writes:
  13.  
  14. >I've done this.  You have to make the bindings to the window, not to
  15. >the canvas:
  16.  
  17. >    # Bind the actions ($f is the window name, $theCanvas is the
  18. >    # canvas name).
  19. >    bind $f <B3-Motion> "itemDrag $theCanvas \
  20. >                    \[expr %x+\[winfo x $f]]\
  21. >                    \[expr %y+\[winfo y $f]] $field";
  22. >    bind $f <3> "itemStartDrag $theCanvas \[expr %x+\[winfo x $f]]\
  23. >                    \[expr %y+\[winfo y $f]]";
  24.  
  25. Any idea why the following doesnt work? Source from within wish
  26.  
  27. ------------------------------------------------------------------
  28.  
  29. canvas .canvas -scrollregion {0 0 800 400} -width 800 -height 400
  30. frame .canvas.frame
  31. text .canvas.frame.photo -background black
  32. pack append .canvas.frame .canvas.frame.photo {top}
  33. .canvas create window 0 0 -window .canvas.frame -anchor nw -tags canvasitem
  34. pack append . .canvas {top}
  35.  
  36. bind .canvas.frame.photo <1> "itemStartDrag .canvas \
  37.     \[expr %x+\[winfo x .canvas.frame.photo]]\
  38.     \[expr %y+\[winfo y .canvas.frame.photo]]";
  39.  
  40. bind .canvas.frame.photo <B1-Motion> "itemDrag .canvas \
  41.     \[expr %x+\[winfo x .canvas.frame.photo]]\
  42.     \[expr %y+\[winfo y .canvas.frame.photo]]";
  43.  
  44. proc itemStartDrag {c x y} {
  45.     global lastX lastY
  46.     set lastX [$c canvasx $x]
  47.     set lastY [$c canvasy $y]
  48. puts stdout "start _[$c type current]_ $lastX $lastY"
  49. }
  50. proc itemDrag {c x y} {
  51.     global lastX lastY
  52.     set x [$c canvasx $x]
  53.     set y [$c canvasy $y]
  54.     $c move current [expr $x-$lastX] [expr $y-$lastY]
  55.     puts stdout  "[expr $x-$lastX] [expr $y-$lastY]"
  56.     set lastX $x
  57.     set lastY $y
  58. }    
  59. --------------------------------------------------------
  60. if "current: in itemDrag is replaced by the tag "canvasitem" then
  61. the text window does, indeed, drag. But not correctly. It appears
  62. to lag behind the cursor. What am I doing wrong?
  63.  
  64.  
  65. Mathew Yeates
  66.