- Timestamp:
- Jan 12, 2011 10:04:22 PM (14 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/flowdial.tcl
r1924 r2028 61 61 public method clear {} 62 62 public method color {value} 63 63 64 64 protected method _redraw {} 65 65 protected method _click {x y} … … 82 82 public variable max 1.0 83 83 } 84 84 85 85 itk::usual Flowdial { 86 86 keep -background -foreground -cursor -font -
trunk/gui/scripts/pushbutton.tcl
r1929 r2028 80 80 itcl::body Rappture::PushButton::invoke {} { 81 81 if { !$_enabled } { 82 puts "in invoke button not enabled"83 82 return 84 83 } -
trunk/gui/scripts/videodial2.tcl
r2025 r2028 59 59 protected method _fixOffsets {} 60 60 61 private method _calculateDialDimensions {} 62 private method _calculateDisplayRange {args} 63 private method _drawDial {disp_min disp_max} 64 private method _getFramenumFromId {id} 65 private method _nearestFrameMarker {x y} 61 66 private method _current {value} 62 67 private method _see {item} … … 64 69 private method ms2rel {value} 65 70 private method rel2ms {value} 71 66 72 private common _click ;# x,y point where user clicked 67 73 private common _marks ;# list of marks 74 private common _dd ;# holds the dimensions of the dial 68 75 private variable _values "" ;# list of all values on the dial 69 76 private variable _val2label ;# maps value => string label(s) … … 77 84 private variable _minortick 1 78 85 private variable _majortick 5 86 private variable _lockdial 0 87 private variable _displayMin 0 88 private variable _displayMax 0 79 89 } 80 90 … … 100 110 bind $itk_component(minordial) <Configure> [itcl::code $this _redraw] 101 111 102 bind $itk_component(minordial) <ButtonPress-1> [itcl::code $this _move click %x %y] 103 bind $itk_component(minordial) <B1-Motion> [itcl::code $this _move drag %x %y] 104 bind $itk_component(minordial) <ButtonRelease-1> [itcl::code $this _move release %x %y] 112 _bindings timeline 105 113 106 114 # ---------------------------------------------------------------------- … … 118 126 119 127 $itk_component(minordial) configure -background cyan 120 121 #$itk_component(minordial) configure -relief sunken -borderwidth 1122 128 123 129 _fixOffsets … … 144 150 return 145 151 } 152 153 if {$value < ${_min}} { 154 set value ${_min} 155 } 156 157 if {$value > ${_max}} { 158 set value ${_max} 159 } 160 146 161 _current [ms2rel $value] 147 # event generate $itk_component(hull) <<Value>>148 162 } 149 163 … … 157 171 # ---------------------------------------------------------------------- 158 172 itcl::body Rappture::Videodial2::_current {relval} { 173 174 if {[string is double $relval] == 0} { 175 error "bad value \"$relval\": expected relval to be a double" 176 } 177 if {${_current} == $relval} { 178 # nothing to do 179 return 180 } 181 159 182 if { $relval < 0.0 } { 160 183 set relval 0.0 … … 163 186 set relval 1.0 164 187 } 188 165 189 set _current $relval 166 _redraw167 168 # update the current marker and move the canvas so current is centered169 190 set framenum [expr round([rel2ms $_current])] 170 after idle [itcl::code $this _see "frame$framenum"] 171 after idle [_setmark current $framenum] 191 192 set updated 0 193 if {${_lockdial} == 1} { 194 # the dial is "locked" this means we don't center the dial 195 # on the current value. we only move the dial if the 196 # current value is less than or greater than the marks alredy 197 # shown on the dial. 198 if {[expr ${_displayMin}+${_majortick}] >= $framenum} { 199 set newdmin [expr $framenum-${_majortick}] 200 foreach {dmin dmax} [_calculateDisplayRange -min $newdmin] break 201 incr updated 202 } elseif {[expr ${_displayMax}-${_majortick}] <= $framenum} { 203 set newdmax [expr $framenum+${_majortick}] 204 foreach {dmin dmax} [_calculateDisplayRange -max $newdmax] break 205 incr updated 206 } 207 } else { 208 # center the current marker 209 foreach {dmin dmax} [_calculateDisplayRange] break 210 incr updated 211 } 212 213 if {$updated == 1} { 214 _drawDial $dmin $dmax 215 } 216 217 after idle [_setmark currentmark $framenum] 172 218 173 219 # update the upvar variable … … 178 224 } 179 225 226 227 # ---------------------------------------------------------------------- 228 # USAGE: _centerCurrentMark <type> ?args? 229 # ---------------------------------------------------------------------- 230 itcl::body Rappture::Videodial2::_bindings {type args} { 231 232 } 233 180 234 # ---------------------------------------------------------------------- 181 235 # USAGE: _bindings <type> ?args? 182 #183 236 # ---------------------------------------------------------------------- 184 237 itcl::body Rappture::Videodial2::_bindings {type args} { … … 189 242 bind $itk_component(minordial) <B1-Motion> [itcl::code $this _marker $tag drag %x %y] 190 243 bind $itk_component(minordial) <ButtonRelease-1> [itcl::code $this _marker $tag release %x %y] 191 $itk_component(minordial) configure -cursor hand2244 $itk_component(minordial) configure -cursor sb_h_double_arrow 192 245 } 193 246 "timeline" { 194 bind $itk_component(minordial) <ButtonPress-1> [itcl::code $this _move click %x %y] 195 bind $itk_component(minordial) <B1-Motion> [itcl::code $this _move drag %x %y] 196 bind $itk_component(minordial) <ButtonRelease-1> [itcl::code $this _move release %x %y] 247 # bind $itk_component(minordial) <ButtonPress-1> [itcl::code $this _move click %x %y] 248 # bind $itk_component(minordial) <B1-Motion> [itcl::code $this _move drag %x %y] 249 # bind $itk_component(minordial) <ButtonRelease-1> [itcl::code $this _move release %x %y] 250 bind $itk_component(minordial) <ButtonPress-1> { } 251 bind $itk_component(minordial) <B1-Motion> { } 252 bind $itk_component(minordial) <ButtonRelease-1> { } 197 253 $itk_component(minordial) configure -cursor "" 198 254 } … … 240 296 241 297 # ---------------------------------------------------------------------- 298 # USAGE: _getFramenumFromId <id> 299 # ---------------------------------------------------------------------- 300 itcl::body Rappture::Videodial2::_getFramenumFromId {id} { 301 set where 0 302 303 # find the frame# tag to associate with the marker with 304 if {[regexp {frame([0-9]+)} $id] == 0} { 305 foreach tags [$c gettags $id] { 306 if {"" != [set tmp [lsearch -inline -regexp $tags {frame[0-9]+}]]} { 307 set where $tmp 308 break 309 } 310 } 311 } else { 312 set where $id 313 } 314 # store the frame number in where 315 regexp {frame([0-9]+)} $where match where 316 317 # restrict <where> to valid frames between min and max 318 if {$where < ${_min}} { 319 set where ${_min} 320 } 321 if {$where > ${_max}} { 322 set where ${_max} 323 } 324 325 return $where 326 } 327 328 # ---------------------------------------------------------------------- 242 329 # USAGE: _setmark <type> ?[-xcoord|-tag]? <where> 243 330 # 244 331 # Clients use this to add a mark to the timeline 245 # type can be any o ne of loopstart, loopend, particle, measure332 # type can be any of loopstart, loopend, particle, measure, currentmark 246 333 # where is interpreted based on the preceeding flag if available. 247 334 # in the default case, <where> is interpreted as a frame number … … 307 394 "-tag" { 308 395 set id [lindex $args 1] 309 # find the frame# tag to associate with the marker with 310 if {[regexp {frame([0-9]+)} $id] == 0} { 311 foreach tags [$c gettags $id] { 312 if {"" != [set tmp [lsearch -inline -regexp $tags {frame[0-9]+}]]} { 313 set where $tmp 314 break 315 } 316 } 317 } else { 318 set where $id 319 } 320 # store the frame number in where 321 regexp {frame([0-9]+)} $where match where 322 323 # restrict <where> to valid frames between min and max 324 if {$where < ${_min}} { 325 set where ${_min} 326 } 327 if {$where > ${_max}} { 328 set where ${_max} 329 } 330 396 set where [_getFramenumFromId $id] 331 397 foreach {frx0 fry0 frx1 fry1} [$c coords frame$where] break 332 398 } … … 375 441 $smx4 $smy4 \ 376 442 $smx5 $smy5 \ 377 -outline black -fill black -tags $tag443 -outline black -fill black -tags [list $tag dialval] 378 444 379 445 $c bind $tag <Enter> [itcl::code $this _bindings marker $tag] … … 418 484 $emx4 $emy4 \ 419 485 $emx5 $emy5 \ 420 -outline black -fill black -tags $tag486 -outline black -fill black -tags [list $tag dialval] 421 487 422 488 $c bind $tag <Enter> [itcl::code $this _bindings marker $tag] … … 434 500 } 435 501 } 436 437 502 } 438 503 "particle*" { … … 444 509 445 510 set tag $type 511 $c delete $tag 446 512 $c create oval $coords \ 447 513 -fill green \ 448 514 -outline black \ 449 515 -width 1 \ 450 -tags $tag516 -tags [list $tag dialval] 451 517 452 518 #$c bind $tag <Enter> [itcl::code $this _bindings marker $tag] … … 456 522 set _marks($type) $where 457 523 } 458 459 460 524 } 461 525 "measure*" { … … 467 531 468 532 set tag $type 533 $c delete $tag 469 534 $c create line $coords \ 470 535 -fill red \ 471 536 -width 3 \ 472 -tags $tag537 -tags [list $tag dialval] 473 538 474 539 #$c bind $tag <Enter> [itcl::code $this _bindings marker $tag] … … 478 543 set _marks($type) $where 479 544 } 480 481 } 482 "current" { 545 } 546 "currentmark" { 483 547 484 548 set cmx0 $frx0 ;# current marker x0 … … 502 566 $cmx3 $cmy3 \ 503 567 $cmx4 $cmy4 \ 504 -outline black -fill red -tags $tag 505 $c create line $cmx0 $cmy0 $cmx0 $cy1 -fill red -tags $tag 506 507 #$c bind $tag <Enter> [itcl::code $this _bindings marker $tag] 508 #$c bind $tag <Leave> [itcl::code $this _bindings timeline] 568 -outline black \ 569 -fill red \ 570 -tags [list $tag dialval] 571 $c create line $cmx0 $cmy0 $cmx0 $cy1 \ 572 -fill red \ 573 -tags [list $tag dialval] 574 575 $c bind $tag <Enter> [itcl::code $this _bindings marker $tag] 576 $c bind $tag <Leave> [itcl::code $this _bindings timeline] 509 577 510 578 if {[string compare "" $where] != 0} { 511 579 set _marks($type) $where 512 580 } 513 514 581 } 515 582 default { … … 524 591 # debug function to print out the bounding box information for 525 592 # minor dial 526 #527 593 # ---------------------------------------------------------------------- 528 594 itcl::body Rappture::Videodial2::bball {} { … … 541 607 } 542 608 543 itcl::body Rappture::Videodial2::_redraw {args} { 544 545 set disp_min 0 546 set disp_max 0 547 548 if {[llength $args] == 2} { 549 foreach {disp_min disp_max} $args break 550 551 if {[string is integer $disp_min] != 1} { 552 error "bad value \"$disp_min\": should be an integer" 553 } 554 if {($disp_min < ${_min}) || ($disp_min > ${_max})} { 555 error "bad value \"$disp_min\": should be between ${_min} and ${_max}" 556 } 557 558 if {[string is integer $disp_max] != 1} { 559 error "bad value \"$disp_max\": should be an integer" 560 } 561 if {($disp_max < ${_min}) || ($disp_max > ${_max})} { 562 error "bad value \"$disp_max\": should be between ${_min} and ${_max}" 563 } 564 565 if {$disp_min > $disp_max} { 566 set tmp $disp_min 567 set disp_min $disp_max 568 set disp_max $tmp 569 } 570 571 } elseif {[llength $args] != 0} { 572 error "wrong # args: should be \"_redraw ?<disp_min> <disp_max>?\"" 573 } 574 575 609 # ---------------------------------------------------------------------- 610 # USAGE: _calculateDisplayRange 611 # calculate the minimum and maximum values to display on the dial 612 # ---------------------------------------------------------------------- 613 itcl::body Rappture::Videodial2::_calculateDisplayRange {args} { 614 615 Rappture::getopts args params { 616 value -min 0 617 value -max 0 618 } 619 620 set disp_min $params(-min) 621 set disp_max $params(-max) 622 623 if {($disp_min == 0) && ($disp_max == 0)} { 624 # calculate the display min and max by 625 # centering the current value on the dial 626 set framenum [expr round([rel2ms ${_current}])] 627 set disp_min [expr ($framenum-$_dd(ni))] 628 set disp_max [expr ($framenum+$_dd(ni))] 629 } elseif {($disp_min != 0) && ($disp_max == 0)} { 630 # user supplied disp_min value 631 # calculate disp_max 632 set disp_max [expr round($disp_min+($_dd(ni)*2.0))] 633 } elseif {($disp_min == 0) && ($disp_max != 0)} { 634 # user supplied disp_max value 635 # calculate disp_min 636 set disp_min [expr round($disp_max-($_dd(ni)*2.0))] 637 } 638 639 # deal with edge cases 640 641 if {($disp_min < ${_min})} { 642 # don't display marks less than ${_min} 643 set disp_min ${_min} 644 set disp_max [expr round(${_min}+($_dd(ni)*2.0))] 645 if {$disp_max > ${_max}} { 646 set disp_max ${_max} 647 } 648 } 649 650 if {($disp_max > ${_max})} { 651 # don't display marks greater than ${_max} 652 set disp_min [expr round(${_max}-($_dd(ni)*2.0))] 653 if {$disp_min < ${_min}} { 654 set disp_min ${_min} 655 } 656 set disp_max ${_max} 657 } 658 659 return [list $disp_min $disp_max] 660 } 661 662 # ---------------------------------------------------------------------- 663 # USAGE: _calculateDialDimensions 664 # calculate dimensions used to draw the dial 665 # ---------------------------------------------------------------------- 666 itcl::body Rappture::Videodial2::_calculateDialDimensions {} { 576 667 set c $itk_component(minordial) 577 $c delete all578 579 set fg $itk_option(-foreground)580 581 668 set w [winfo width $c] 582 669 set h [winfo height $c] … … 589 676 590 677 678 # add intermediate marks between markers 679 set imw 1.0 ;# intermediate mark width 680 681 set imsh [expr {$t/3.0}] ;# intermediate mark short height 682 set imsy0 [expr {$y0+(($t-$imsh)/2.0)}] ;# precalc'd imark short y0 coord 683 set imsy1 [expr {$imsy0+$imsh}] ;# precalc'd imark short y1 coord 684 685 set imlh [expr {$t*2.0/3.0}] ;# intermediate mark long height 686 set imly0 [expr {$y0+(($t-$imlh)/2.0)}] ;# precalc'd imark long y0 coord 687 set imly1 [expr {$imly0+$imlh}] ;# precalc'd imark long y1 coord 688 689 set imty [expr {$y0-5}] ;# height of marker value 690 691 set x [expr ($x1-$x0)/2.0] 692 set ni [expr int(($x-$x0)/${_imspace})] 693 694 set _dd(x0) $x0 695 set _dd(y0) $y0 696 set _dd(x1) $x1 697 set _dd(y1) $y1 698 set _dd(ni) $ni 699 set _dd(imly0) $imly0 700 set _dd(imly1) $imly1 701 set _dd(imw) $imw 702 set _dd(imty) $imty 703 set _dd(imsy0) $imsy0 704 set _dd(imsy1) $imsy1 705 706 } 707 708 # ---------------------------------------------------------------------- 709 # USAGE: _redraw 710 # calculate dimensions, display range, and draw the dial, again 711 # ---------------------------------------------------------------------- 712 itcl::body Rappture::Videodial2::_redraw {args} { 713 714 _calculateDialDimensions 715 716 foreach {disp_min disp_max} [_calculateDisplayRange] break 717 718 set c $itk_component(minordial) 719 $c delete all 720 591 721 # draw the background rectangle for the minor time line 592 $c create rectangle $ x0 $y0 $x1 $y1\722 $c create rectangle $_dd(x0) $_dd(y0) $_dd(x1) $_dd(y1) \ 593 723 -outline $itk_option(-dialoutlinecolor) \ 594 724 -fill $itk_option(-dialfillcolor) \ 595 725 -tags "imbox" 596 726 597 # add intermediate marks between markers 598 set imw 1.0 ;# intermediate mark width 599 600 set imsh [expr {$t/3.0}] ;# intermediate mark short height 601 set imsy0 [expr {$y0+(($t-$imsh)/2.0)}] ;# precalc'd imark short y0 coord 602 set imsy1 [expr {$imsy0+$imsh}] ;# precalc'd imark short y1 coord 603 604 set imlh [expr {$t*2.0/3.0}] ;# intermediate mark long height 605 set imly0 [expr {$y0+(($t-$imlh)/2.0)}] ;# precalc'd imark long y0 coord 606 set imly1 [expr {$imly0+$imlh}] ;# precalc'd imark long y1 coord 607 608 set imty [expr {$y0-5}] ;# height of marker value 609 610 set imx $x0 611 612 if {($disp_min == 0) && ($disp_max == 0)} { 613 set x [expr ($x1-$x0)/2.0] 614 set ni [expr ($x-$x0)/${_imspace}] 615 616 set framenum [expr round([rel2ms ${_current}])] 617 618 set disp_min [expr ($framenum-$ni)] 619 set disp_max [expr ($framenum+$ni)] 620 621 # deal with edge cases 622 if {($disp_min < ${_min})} { 623 # don't display marks less than ${_min} 624 set disp_min ${_min} 625 set disp_max [expr (${_min}+($ni*2.0))] 626 if {$disp_max > ${_max}} { 627 set disp_max ${_max} 628 } 629 } 630 631 if {($disp_max > ${_max})} { 632 # don't display marks greater than ${_max} 633 set disp_min [expr (${_max}-($ni*2.0))] 634 if {$disp_min < ${_min}} { 635 set disp_min ${_min} 636 } 637 set disp_max ${_max} 638 } 639 } 640 641 for {set i [expr {int($disp_min)}]} {$i <= $disp_max} {incr i} { 642 if {($i%${_majortick}) == 0} { 643 # draw major tick 644 $c create line $imx $imly0 $imx $imly1 \ 645 -fill red \ 646 -width $imw \ 647 -tags [list longmark-c imark-c "frame$i"] 648 649 $c create text $imx $imty -anchor center -text $i \ 650 -font $itk_option(-font) -tags "frame$i" 651 652 set imx [expr $imx+${_imspace}] 653 } elseif {($i%${_minortick}) == 0 } { 654 # draw minor tick 655 $c create line $imx $imsy0 $imx $imsy1 \ 656 -fill blue \ 657 -width $imw \ 658 -tags [list shortmark-c imark-c "frame$i"] 659 660 set imx [expr $imx+${_imspace}] 661 } 662 } 663 727 _drawDial $disp_min $disp_max 664 728 665 729 # calculate the height of the intermediate tick marks … … 672 736 $c coords "imbox" $box 673 737 674 # add an invisible box 15 pixels above and 20 pixelsbelow imbox738 # add an invisible box 20 pixels above and below imbox 675 739 # to keep the canvas from changing sizes when the we add 676 740 # particle, loopstart, loopend, and line markers 677 741 foreach {x0 y0 x1 y1} $box break 678 $c create rectangle $x0 [expr $y0- 15] $x1 [expr $y1+20] \742 $c create rectangle $x0 [expr $y0-20] $x1 [expr $y1+20] \ 679 743 -outline "" \ 680 744 -fill "" \ 681 745 -tags "markerbox" 682 746 747 # re-add any marks that the user previously specified 748 # do it again because we changed the size of imbox 749 foreach n [array names _marks] { 750 if {($_marks($n) > ${_displayMin}) && ($_marks($n) < ${_displayMax})} { 751 _setmark $n $_marks($n) 752 } 753 } 754 755 _fixSize 756 } 757 758 759 # ---------------------------------------------------------------------- 760 # USAGE: _drawDial 761 # draw the dial 762 # ---------------------------------------------------------------------- 763 itcl::body Rappture::Videodial2::_drawDial {dmin dmax} { 764 set c $itk_component(minordial) 765 $c delete dialval 766 767 set _displayMin [expr int($dmin)] 768 set _displayMax [expr int($dmax)] 769 770 set imx [expr $_dd(x0)+5] 771 for {set i ${_displayMin}} {$i <= ${_displayMax}} {incr i} { 772 if {($i%${_majortick}) == 0} { 773 # draw major tick 774 $c create line $imx $_dd(imly0) $imx $_dd(imly1) \ 775 -fill red \ 776 -width $_dd(imw) \ 777 -tags [list dialval longmark imark "frame$i"] 778 779 $c create text $imx $_dd(imty) \ 780 -anchor center \ 781 -text $i \ 782 -font $itk_option(-font) \ 783 -tags [list dialval frame$i frame$i-text] 784 785 set imx [expr $imx+${_imspace}] 786 } elseif {($i%${_minortick}) == 0 } { 787 # draw minor tick 788 $c create line $imx $_dd(imsy0) $imx $_dd(imsy1) \ 789 -fill blue \ 790 -width $_dd(imw) \ 791 -tags [list dialval shortmark imark "frame$i"] 792 793 set imx [expr $imx+${_imspace}] 794 } 795 } 796 797 if {(${_displayMin}%${_majortick}) == 0} { 798 # first tick is numbered, delete the text if 799 # it shows up outside of our desired imbox 800 foreach {dmx0 dmy0 dmx1 dmy1} [$c bbox frame${_displayMin}-text] break 801 # need to check for if dmx0 exists because there 802 # are some cases when the widget is first being 803 # created where _calculateDisplayRange gives 804 # back bad values, dmin > dmax. 805 if {[info exists dmx0] && ($dmx0 < $_dd(x0))} { 806 $c delete frame${_displayMin}-text 807 } 808 } 809 if {(${_displayMax}%${_majortick}) == 0} { 810 # last tick is numbered, delete the text if 811 # it shows up outside of our desired imbox 812 foreach {dmx0 dmy0 dmx1 dmy1} [$c bbox frame${_displayMax}-text] break 813 # need to check for if dmx1 exists because there 814 # are some cases when the widget is first being 815 # created where _calculateDisplayRange gives 816 # back bad values, dmin > dmax. 817 if {[info exists dmx1] && ($dmx1 > $_dd(x1))} { 818 $c delete frame${_displayMax}-text 819 } 820 } 821 683 822 # add any marks that the user previously specified 684 823 foreach n [array names _marks] { 685 if {($_marks($n) > $ disp_min) && ($_marks($n) < $disp_max)} {824 if {($_marks($n) > ${_displayMin}) && ($_marks($n) < ${_displayMax})} { 686 825 _setmark $n $_marks($n) 687 826 } 688 827 } 689 690 _fixSize691 828 } 692 829 … … 732 869 733 870 # ---------------------------------------------------------------------- 871 # USAGE: _nearestFrameMarker <x> <y> 872 # 873 # Called automatically whenever the user clicks or drags on a marker 874 # widget. Moves the selected marker to the next nearest tick mark. 875 # ---------------------------------------------------------------------- 876 itcl::body Rappture::Videodial2::_nearestFrameMarker {x y} { 877 878 set c $itk_component(minordial) 879 880 foreach {junk y0 junk y1} [$c bbox "imark"] break 881 set id "" 882 # FIXME: 883 # the amount added to _imspace should be 1 884 # but for some reason the dial is slightly shifted 885 # on the canvas by 2 or 3 pixels. so we have to 886 # add a larger value like 3 to _imspace to find 887 # the next frame marker 888 set x0 [expr {$x-round((${_imspace}+3)/2.0)}] 889 set x1 [expr {$x+round((${_imspace}+3)/2.0)}] 890 891 #$c delete scrap 892 #$c create rectangle $x0 $y0 $x1 $y1 \ 893 -outline green -tags "scrap" 894 895 foreach item [$c find enclosed $x0 $y0 $x1 $y1] { 896 set itemtags [$c gettags $item] 897 898 foreach {x00 junk x11 junk} [$c bbox $item] break 899 900 if {[lsearch -exact $itemtags "imark"] != -1} { 901 set id [lsearch -inline -regexp $itemtags {frame[0-9]}] 902 break 903 } 904 } 905 if {[string compare "" $id] == 0} { 906 # something went wrong 907 # we should have found an imark with 908 # an associated "frame#" tag to snap to 909 # bailout 910 #error "could not find an intermediate mark to snap marker to" 911 puts stderr "could not find an intermediate mark to snap marker to" 912 } 913 914 return $id 915 916 } 917 918 # ---------------------------------------------------------------------- 734 919 # USAGE: _marker <tag> click <x> <y> 735 920 # _marker <tag> drag <x> <y> … … 741 926 itcl::body Rappture::Videodial2::_marker {tag action x y} { 742 927 set c $itk_component(minordial) 743 set x [_offsetx $x]744 928 switch $action { 745 929 "click" { 930 if {"currentmark" == $tag} { 931 set _lockdial 1 932 } 746 933 } 747 934 "drag" { 748 _setmark $tag -xcoord $x 749 # if we are too close to the edge, scroll the canvas. 750 # $c xview scroll $dist "unit" 935 set x [_offsetx $x] 936 937 # as the marker passes over frame marks, snap to the closest frame mark 938 set id [_nearestFrameMarker $x $y] 939 if {"" == $id} { 940 return 941 } 942 943 if {"currentmark" == $tag} { 944 # update the current frame shown on the screen 945 # this doesn't quite work yet, i think because 946 # the seek requests are buffered until the gui 947 # is idle 948 set newfn [_getFramenumFromId $id] 949 set oldfn [expr round([rel2ms ${_current}])] 950 if {$newfn != $oldfn} { 951 _current [ms2rel $newfn] 952 event generate $itk_component(hull) <<Value>> 953 } 954 } else { 955 _setmark $tag -tag $id 956 } 751 957 } 752 958 "release" { 753 # on release, snap to the closest imark 754 foreach {junk y0 junk y1} [$c bbox "imark-c"] break 755 set id "" 756 foreach item [$c find enclosed [expr {$x-((${_imspace}+1)/2.0)}] $y0 \ 757 [expr {$x+((${_imspace}+1)/2.0)}] $y1] { 758 set itemtags [$c gettags $item] 759 if {[lsearch -exact $itemtags "imark-c"] != -1} { 760 set id [lsearch -inline -regexp $itemtags {frame[0-9]}] 761 break 762 } 763 } 764 if {[string compare "" $id] == 0} { 765 # something went wrong 766 # we should have found an imark with 767 # an associated "frame#" tag to snap to 768 # bailout 769 error "could not find an intermediate mark to snap marker to" 770 } 771 772 _setmark $tag -tag $id 959 960 _marker $tag drag $x $y 961 962 if {"currentmark" == $tag} { 963 set _lockdial 0 964 } 773 965 774 966 # take care of cases where the mouse leaves the marker's boundries … … 777 969 # generate the "Leave" event. 778 970 set leave 1 971 set x [_offsetx $x] 779 972 foreach item [$c find overlapping $x $y $x $y] { 780 973 if {[lsearch -exact [$c gettags $item] $tag] != -1} { … … 788 981 # event generate $c <Leave> 789 982 _bindings timeline 790 }791 if {"current" == $tag} {792 # if we move the current marker, update the frame number793 current [mark position current]794 event generate $itk_component(hull) <<Value>>795 983 } 796 984 } -
trunk/gui/scripts/videodistance.tcl
r2025 r2028 200 200 error "bad value: \"$val\": frame number should be an integer" 201 201 } 202 202 203 set _frame $val 203 204 -
trunk/gui/scripts/videoparticle.tcl
r2025 r2028 408 408 error "bad value: \"$val\": frame number should be an integer" 409 409 } 410 410 411 set _frame $val 411 412 412 413 if {"" != $itk_option(-onframe)} { 413 414 uplevel \#0 $itk_option(-onframe) ${_frame} 415 } 416 417 drawVectors 418 if {[string compare "" ${_prevnode}] != 0} { 419 ${_prevnode} drawVectors 414 420 } 415 421 } elseif {[llength $args] != 0} { -
trunk/gui/scripts/videopreview.tcl
r2024 r2028 122 122 -onimage [Rappture::icon flow-pause] \ 123 123 -offimage [Rappture::icon flow-play] \ 124 -disabledimage [Rappture::icon flow-play] \ 124 125 -variable [itcl::scope _settings($this-play)] \ 125 126 -command [itcl::code $this video play] … … 128 129 Rappture::Tooltip::for $itk_component(play) \ 129 130 "Play/Pause movie" 131 $itk_component(play) disable 130 132 131 133 # Video Dial Major … … 193 195 194 196 $itk_component(main) configure -background black 195 puts "width = [$itk_component(main) cget -width]"196 puts "height = [$itk_component(main) cget -height]"197 197 } 198 198 … … 269 269 # update the dial with video information 270 270 $itk_component(dialmajor) configure -min 0 -max ${_lastFrame} 271 $itk_component(play) enable 271 272 272 273 fixSize … … 351 352 # make the canvas fit the image 352 353 $itk_component(main) configure -width ${_width} -height ${_height} 353 puts "bbox = [$itk_component(main) bbox all]"354 354 } 355 355 -
trunk/gui/scripts/videoscreen.tcl
r2025 r2028 60 60 private method calculateTrajectory {args} 61 61 private method writeText {x y text color tags width} 62 private method clearDrawings {} 62 63 63 64 # video dial tools … … 66 67 private common _settings 67 68 private common _pendings 69 private common _pbvars 70 private common _counters 68 71 69 72 private variable _width -1 ;# start x for rubberbanding … … 78 81 ;# underlying c lib in milliseconds 79 82 private variable _delay 0 ;# milliseconds between play calls 80 private variable _waiting 0 ;# number of frames behind we are81 83 private variable _nextframe 0 ;# 82 84 83 private variable _pbvlist "" ;# list of the pushbutton variables 84 private variable _pcnt 0 ;# counter for naming particles 85 private variable _px2dist 0 ;# conversion for pixels to user specified distance 85 86 private variable _particles "" ;# list of particles 86 private variable _px2dist 0 ;# conversion for pixels to user specified distance 87 private variable _measTags "" ;# tags of measurement lines 88 private variable _measCnt 0 ;# counter for naming measure lines 87 private variable _measurements "" ;# list of all measurement lines 89 88 private variable _obj "" ;# temp var holding the last created object 90 89 } … … 102 101 103 102 array set _settings [subst { 104 $this-framenum 0105 $this-loop 0106 $this-play 0107 $this-speed 1103 framenum 0 104 loop 0 105 play 0 106 speed 1 108 107 }] 109 108 110 array set _pendings [subst{109 array set _pendings { 111 110 seek 0 112 111 play 0 113 }] 114 112 } 113 114 array set _counters { 115 particle 0 116 measure 0 117 } 115 118 116 119 # Create flow controls... … … 153 156 -image [Rappture::icon upload] \ 154 157 -command [itcl::code $this loadcb] 155 #-command [Rappture::filexfer::upload {piv tool} {id label desc} [itcl::code $this Upload]] 156 #-command [itcl::code $this video seek 0] 157 } { 158 usual 159 ignore -borderwidth 160 rename -highlightbackground -controlbackground controlBackground \ 161 Background 158 } { 159 usual 162 160 } 163 161 Rappture::Tooltip::for $itk_component(fileopen) \ … … 170 168 -onimage $measImg \ 171 169 -offimage $measImg \ 172 -command [itcl::code $this togglePtrCtrl measPbVar] \ 173 -variable measPbVar 174 } { 175 usual 176 } 170 -disabledimage $measImg \ 171 -command [itcl::code $this togglePtrCtrl "measure"] \ 172 -variable [itcl::scope _pbvars(measure)] 173 } { 174 usual 175 } 176 $itk_component(measure) disable 177 177 Rappture::Tooltip::for $itk_component(measure) \ 178 178 "Measure the distance of a structure" 179 lappend _pbvlist measPbVar180 179 181 180 # ==== particle mark tool ==== … … 183 182 itk_component add particle { 184 183 Rappture::PushButton $itk_component(moviecontrols).particlepb \ 185 -onimage $particleImg \184 -onimage $particleImg \ 186 185 -offimage $particleImg \ 187 -command [itcl::code $this togglePtrCtrl partPbVar] \ 188 -variable partPbVar 189 } { 190 usual 191 } 186 -disabledimage $particleImg \ 187 -command [itcl::code $this togglePtrCtrl "particle"] \ 188 -variable [itcl::scope _pbvars(particle)] 189 } { 190 usual 191 } 192 $itk_component(particle) disable 192 193 Rappture::Tooltip::for $itk_component(particle) \ 193 194 "Mark the location of a particle to follow" 194 lappend _pbvlist partPbVar195 195 196 196 … … 207 207 Background 208 208 } 209 $itk_component(rewind) configure -state disabled 209 210 Rappture::Tooltip::for $itk_component(rewind) \ 210 211 "Rewind movie" … … 222 223 Background 223 224 } 225 $itk_component(seekback) configure -state disabled 224 226 Rappture::Tooltip::for $itk_component(rewind) \ 225 227 "Seek backwards 1 frame" … … 230 232 -onimage [Rappture::icon flow-pause] \ 231 233 -offimage [Rappture::icon flow-play] \ 232 -variable [itcl::scope _settings($this-play)] \ 234 -disabledimage [Rappture::icon flow-play] \ 235 -variable [itcl::scope _settings(play)] \ 233 236 -command [itcl::code $this video play] 234 237 } 235 set fg [option get $itk_component(hull) font Font]238 $itk_component(play) disable 236 239 Rappture::Tooltip::for $itk_component(play) \ 237 240 "Play/Pause movie" … … 249 252 Background 250 253 } 254 $itk_component(seekforward) configure -state disabled 251 255 Rappture::Tooltip::for $itk_component(seekforward) \ 252 256 "Seek forward 1 frame" … … 257 261 -onimage [Rappture::icon flow-loop] \ 258 262 -offimage [Rappture::icon flow-loop] \ 259 -variable [itcl::scope _settings($this-loop)] \ 263 -disabledimage [Rappture::icon flow-loop] \ 264 -variable [itcl::scope _settings(loop)] \ 260 265 -command [itcl::code $this toggleloop] 261 266 } 267 $itk_component(loop) disable 262 268 Rappture::Tooltip::for $itk_component(loop) \ 263 269 "Play continuously between marked sections" … … 276 282 -linecolor "" -activelinecolor "" \ 277 283 -min 0 -max 1 \ 278 -variable [itcl::scope _settings( $this-framenum)] \284 -variable [itcl::scope _settings(framenum)] \ 279 285 -dialoutlinecolor black \ 280 286 -knobimage [Rappture::icon knob2] -knobposition center@middle … … 293 299 -min 0 -max 1 \ 294 300 -minortick 1 -majortick 5 \ 295 -variable [itcl::scope _settings( $this-framenum)] \301 -variable [itcl::scope _settings(framenum)] \ 296 302 -dialoutlinecolor black 297 303 } { … … 301 307 $itk_component(dialminor) current 0 302 308 bind $itk_component(dialminor) <<Value>> [itcl::code $this video update] 309 310 set fg [option get $itk_component(hull) font Font] 303 311 304 312 itk_component add framenumlabel { … … 315 323 label $itk_component(frnumfr).framenum \ 316 324 -background white -font "arial 9" \ 317 -textvariable [itcl::scope _settings( $this-framenum)]325 -textvariable [itcl::scope _settings(framenum)] 318 326 } { 319 327 usual … … 357 365 0,0 $itk_component(dialmajor) -fill x \ 358 366 1,0 $itk_component(dialminor) -fill x 359 360 367 361 368 blt::table $itk_component(moviecontrols) \ … … 391 398 # ---------------------------------------------------------------------- 392 399 itcl::body Rappture::VideoScreen::destructor {} { 393 array unset _settings $this-* 400 array unset _settings * 401 array unset _pendings * 402 array unset _pbvars * 403 array unset _counters * 404 405 394 406 if {[info exists _imh]} { 395 image delete $_imh 407 image delete ${_imh} 408 set _imh "" 409 } 410 411 if {[info exists measImg]} { 412 image delete $measImg 413 set measImg "" 414 } 415 416 if {[info exists particleImg]} { 417 image delete $particleImg 418 set particleImg "" 419 } 420 421 if {("" != [info commands ${_movie}])} { 422 # clear the movie if it is still open 423 ${_movie} release 424 set _movie "" 425 } 426 427 clearDrawings 428 } 429 430 # ---------------------------------------------------------------------- 431 # clearDrawings - delete all particle and measurement objects 432 # ---------------------------------------------------------------------- 433 itcl::body Rappture::VideoScreen::clearDrawings {} { 434 435 # delete all previously placed particles 436 set obj [lindex ${_particles} end] 437 while {"" != [info commands $obj]} { 438 itcl::delete object $obj 439 set _particles [lreplace ${_particles} end end] 440 if {[llength ${_particles}] == 0} { 441 break 442 } 443 set obj [lindex ${_particles} end] 444 } 445 446 # delete all previously placed measurements 447 set obj [lindex ${_measurements} end] 448 while {"" != [info commands $obj]} { 449 itcl::delete object $obj 450 set _measurements [lreplace ${_measurements} end end] 451 if {[llength ${_measurements}] == 0} { 452 break 453 } 454 set obj [lindex ${_measurements} end] 396 455 } 397 456 } … … 408 467 409 468 # open the file 410 411 469 set fname "" 412 470 switch $type { 413 471 "data" { 472 if {"" == $data} { 473 error "bad value \"$data\": data should be a movie" 474 } 475 414 476 set fname "/tmp/tmpVV[pid].video" 415 477 set fid [open $fname "w"] … … 421 483 } 422 484 "file" { 485 if {"" == $data} { 486 error "bad value \"$data\": data should be a movie file path" 487 } 423 488 # do nothing 424 489 } … … 430 495 video stop 431 496 432 if {([info exists _movie]) && ("" != ${_movie})} { 433 ${_movie} release 497 if {"file" == $type} { 498 if {("" != [info commands ${_movie}])} { 499 # compare the new file name to the name of the file 500 # we already have open in our _movie object. 501 # if they are the same, do not reopen the video. 502 # if they are different, close the old movie 503 # and clear out all old drawings from the canvas. 504 set err [catch {${_movie} get filename} filename] 505 if {($err == 0)&& ($data == $filename)} { 506 # video file already open, don't reopen it. 507 return 508 } else { 509 # clear the old movie 510 ${_movie} release 511 512 # delete drawings objects from canvas 513 clearDrawings 514 } 515 } 434 516 } 435 517 436 518 set _movie [Rappture::Video $type $data] 437 file delete $fname 519 if {"" != $fname} { 520 file delete $fname 521 } 438 522 set _framerate [${_movie} get framerate] 439 523 video speed … … 442 526 443 527 # update the dial and framenum widgets 444 set _settings( $this-framenum) 0528 set _settings(framenum) 0 445 529 446 530 … … 460 544 $itk_component(dialmajor) configure -min 0 -max ${_lastFrame} 461 545 $itk_component(dialminor) configure -min 0 -max ${_lastFrame} 546 547 # turn on the buttons and dials 548 $itk_component(measure) enable 549 $itk_component(particle) enable 550 $itk_component(rewind) configure -state normal 551 $itk_component(seekback) configure -state normal 552 $itk_component(play) enable 553 $itk_component(seekforward) configure -state normal 554 $itk_component(loop) enable 462 555 463 556 fixSize … … 531 624 switch -- $option { 532 625 "play" { 533 if {$_settings( $this-play) == 1} {626 if {$_settings(play) == 1} { 534 627 eventually play 535 628 } else { … … 537 630 after cancel $_id 538 631 set _pendings(play) 0 539 set _settings( $this-play) 0632 set _settings(play) 0 540 633 } 541 634 } … … 545 638 "stop" { 546 639 after cancel $_id 547 set _settings( $this-play) 0640 set _settings(play) 0 548 641 } 549 642 "speed" { … … 554 647 } 555 648 "update" { 556 eventually seek [expr round($_settings( $this-framenum))]557 # Seek [expr round($_settings( $this-framenum))]649 eventually seek [expr round($_settings(framenum))] 650 # Seek [expr round($_settings(framenum))] 558 651 } 559 652 default { … … 618 711 619 712 # update the dial and framenum widgets 620 set _settings( $this-framenum) $cur713 set _settings(framenum) $cur 621 714 622 715 … … 626 719 # if looping is turned on and markers setup, 627 720 # then loop back to loopstart when cur hits loopend 628 if {$_settings( $this-loop)} {721 if {$_settings(loop)} { 629 722 if {$cur == [$itk_component(dialminor) mark position loopend]} { 630 723 Seek [$itk_component(dialminor) mark position loopstart] … … 657 750 if {[string compare $cur $val] == 0} { 658 751 # already at the frame to seek to 752 set _pendings(seek) 0 659 753 return 660 754 } … … 663 757 664 758 # update the dial and framenum widgets 665 set _settings( $this-framenum) [$_movie get position cur]759 set _settings(framenum) [$_movie get position cur] 666 760 event generate $itk_component(main) <<Frame>> 667 761 762 # removing pending 763 set _pendings(seek) 0 668 764 } 669 765 … … 678 774 switch -- $option { 679 775 "seek" { 680 if { $_pendings(seek) == 0} {776 if {0 == $_pendings(seek)} { 681 777 # no seek pending, schedule one 682 set $_pendings(seek) 1778 set _pendings(seek) 1 683 779 after idle [itcl::code $this Seek [lindex $args 1]] 684 780 } else { … … 707 803 # rectangle, measure, particlemark 708 804 # ---------------------------------------------------------------------- 709 itcl::body Rappture::VideoScreen::togglePtrCtrl {pbvar} { 710 711 upvar 1 $pbvar inState 712 if {$inState == 1} { 805 itcl::body Rappture::VideoScreen::togglePtrCtrl {tool} { 806 807 if {[info exists _pbvars($tool)] == 0} { 808 return 809 } 810 811 if {$_pbvars($tool) == 1} { 713 812 # unpush previously pushed buttons 714 foreach pbv $_pbvlist { 715 if {[string compare $pbvar $pbv] != 0} { 716 upvar 1 $pbv var 717 set var 0 718 } 719 } 720 } 721 togglePtrBind $pbvar 813 foreach pbv [array names _pbvars] { 814 if {[string compare $tool $pbv] != 0} { 815 set _pbvars($pbv) 0 816 } 817 } 818 } 819 togglePtrBind $tool 722 820 } 723 821 … … 728 826 # ---------------------------------------------------------------------- 729 827 itcl::body Rappture::VideoScreen::whatPtrCtrl {} { 730 foreach pbv $_pbvlist { 731 upvar #0 $pbv var 732 if {$var != "" && $var != 0} { 828 foreach pbv [array names _pbvars] { 829 if {$_pbvars($pbv) != 0} { 733 830 return $pbv 734 831 } … … 746 843 } 747 844 748 if {[string compare $pbvar rect PbVar] == 0} {845 if {[string compare $pbvar rectangle] == 0} { 749 846 750 847 # Bindings for selecting rectangle … … 758 855 [itcl::code $this Rubberband release %W %x %y] 759 856 760 } elseif {[string compare $pbvar meas PbVar] == 0} {857 } elseif {[string compare $pbvar measure] == 0} { 761 858 762 859 # Bindings for measuring distance … … 770 867 [itcl::code $this Measure release %W %x %y] 771 868 772 } elseif {[string compare $pbvar part PbVar] == 0} {869 } elseif {[string compare $pbvar particle] == 0} { 773 870 774 871 # Bindings for marking particle locations … … 858 955 switch -- $status { 859 956 "new" { 860 incr _measCnt 861 set name "measure${_measCnt}" 862 lappend _measTags $name 957 set name "measure[incr _counters(measure)]" 863 958 864 959 set _obj [Rappture::VideoDistance $itk_component(main).$name $name $win \ … … 875 970 ${_obj} Coords $x $y $x $y 876 971 ${_obj} Show object 972 lappend _measurements ${_obj} 877 973 } 878 974 "drag" { … … 923 1019 switch -- $status { 924 1020 "new" { 925 incr _pcnt 926 set name "particle${_pcnt}" 1021 set name "particle[incr _counters(particle)]" 927 1022 set _obj [Rappture::VideoParticle $itk_component(main).$name $name $win \ 928 1023 -fncallback [itcl::code $this query framenum] \ … … 1115 1210 # ---------------------------------------------------------------------- 1116 1211 itcl::body Rappture::VideoScreen::toggleloop {} { 1117 if {$_settings( $this-loop) == 0} {1212 if {$_settings(loop) == 0} { 1118 1213 $itk_component(dialminor) mark remove loopstart 1119 1214 $itk_component(dialminor) mark remove loopend
Note: See TracChangeset
for help on using the changeset viewer.