Ignore:
Timestamp:
Jan 13, 2011 9:15:36 AM (14 years ago)
Author:
dkearney
Message:

fixing keypress in videodial2 by adding focus when user clicks on the currentmark
in videodial2, disable markers from being drawn if they are less than or greater than the displayed min and max on the dial

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/videodial2.tcl

    r2028 r2029  
    4848    public method mark {args}
    4949    public method bball {}
     50    public method loop {action args}
    5051
    5152    protected method _bindings {type args}
     
    6970    private method ms2rel {value}
    7071    private method rel2ms {value}
     72    private method _goToFrame {framenum}
    7173
    7274    private common _click             ;# x,y point where user clicked
     
    8486    private variable _minortick 1
    8587    private variable _majortick 5
    86     private variable _lockdial 0
     88    private variable _lockdial ""
    8789    private variable _displayMin 0
    8890    private variable _displayMax 0
     
    191193
    192194    set updated 0
    193     if {${_lockdial} == 1} {
     195    if {[llength ${_lockdial}] != 0} {
    194196        # the dial is "locked" this means we don't center the dial
    195197        # on the current value. we only move the dial if the
     
    226228
    227229# ----------------------------------------------------------------------
    228 # USAGE: _centerCurrentMark <type> ?args?
     230# USAGE: _bindings <type> ?args?
    229231# ----------------------------------------------------------------------
    230232itcl::body Rappture::Videodial2::_bindings {type args} {
    231 
    232 }
    233 
    234 # ----------------------------------------------------------------------
    235 # USAGE: _bindings <type> ?args?
    236 # ----------------------------------------------------------------------
    237 itcl::body Rappture::Videodial2::_bindings {type args} {
     233    set c $itk_component(minordial)
    238234    switch -- $type {
    239235        "marker" {
    240236            set tag [lindex $args 0]
    241             bind $itk_component(minordial) <ButtonPress-1> [itcl::code $this _marker $tag click %x %y]
    242             bind $itk_component(minordial) <B1-Motion> [itcl::code $this _marker $tag drag %x %y]
    243             bind $itk_component(minordial) <ButtonRelease-1> [itcl::code $this _marker $tag release %x %y]
    244             $itk_component(minordial) configure -cursor sb_h_double_arrow
     237            bind $c <ButtonPress-1> [itcl::code $this _marker $tag click %x %y]
     238            bind $c <B1-Motion> [itcl::code $this _marker $tag drag %x %y]
     239            bind $c <ButtonRelease-1> [itcl::code $this _marker $tag release %x %y]
     240            $c configure -cursor sb_h_double_arrow
    245241        }
    246242        "timeline" {
    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> { }
    253             $itk_component(minordial) configure -cursor ""
     243            # bind $c <ButtonPress-1> [itcl::code $this _move click %x %y]
     244            # bind $c <B1-Motion> [itcl::code $this _move drag %x %y]
     245            # bind $c <ButtonRelease-1> [itcl::code $this _move release %x %y]
     246            bind $c <ButtonPress-1> { }
     247            bind $c <B1-Motion> { }
     248            bind $c <ButtonRelease-1> { }
     249            $c configure -cursor ""
     250        }
     251        "toolmark" {
     252            if {[llength $args] != 2} {
     253                error "wrong # args: should be _bindings toolmark \[enter|leave\] <tag>"
     254            }
     255
     256            foreach {mode tag} $args break
     257
     258            switch -- $mode {
     259                "enter" {
     260                    #$c create rectangle [$c bbox $tag] \
     261                        -outline red \
     262                        -tags "highlight"
     263                    bind $c <ButtonPress-1> [itcl::code $this _goToFrame $_marks($tag)]
     264                }
     265                "leave" {
     266                    #$c delete "highlight"
     267                    _bindings timeline
     268                }
     269                default {
     270                    error "bad argument \"$mode\": should be enter or leave"
     271                }
     272            }
    254273        }
    255274    }
     
    414433            # add start marker
    415434
    416             set smx0 $frx0                              ;# loopstart marker x0
    417             set smy0 $cy0                               ;# loopstart marker y0
    418 
    419             # polygon's outline adds a border to only one
    420             # side of the object? so we have weird +1 in
    421             # the triangle base in loopstart marker
    422 
    423             # marker stem is 3 pixels thick
    424             set smx1 [expr {$smx0+1}]                   ;# triangle top x
    425             set smy1 [expr {$smy0-10}]                  ;# triangle top y
    426             set smx2 $smx1                              ;# stem bottom right x
    427             set smy2 $cy1                               ;# stem bottom right y
    428             set smx3 [expr {$smx0-1}]                   ;# stem bottom left x
    429             set smy3 $smy2                              ;# stem bottom left y
    430             set smx4 $smx3                              ;# stem middle left x
    431             set smy4 $smy0                              ;# stem middle left y
    432             set smx5 [expr {$smx0-10+1}]                ;# triangle bottom left x
    433             set smy5 $smy0                              ;# triangle bottom left y
    434 
    435             set tag $type
    436             $c delete $tag
    437             $c create polygon \
    438                 $smx1 $smy1 \
    439                 $smx2 $smy2 \
    440                 $smx3 $smy3 \
    441                 $smx4 $smy4 \
    442                 $smx5 $smy5 \
    443                 -outline black -fill black -tags [list $tag dialval]
    444 
    445             $c bind $tag <Enter> [itcl::code $this _bindings marker $tag]
    446             $c bind $tag <Leave> [itcl::code $this _bindings timeline]
     435            if {($where >= ${_displayMin}) && ($where < ${_displayMax})} {
     436                set smx0 $frx0                              ;# loopstart marker x0
     437                set smy0 $cy0                               ;# loopstart marker y0
     438
     439                # polygon's outline adds a border to only one
     440                # side of the object? so we have weird +1 in
     441                # the triangle base in loopstart marker
     442
     443                # marker stem is 3 pixels thick
     444                set smx1 [expr {$smx0+1}]                   ;# triangle top x
     445                set smy1 [expr {$smy0-10}]                  ;# triangle top y
     446                set smx2 $smx1                              ;# stem bottom right x
     447                set smy2 $cy1                               ;# stem bottom right y
     448                set smx3 [expr {$smx0-1}]                   ;# stem bottom left x
     449                set smy3 $smy2                              ;# stem bottom left y
     450                set smx4 $smx3                              ;# stem middle left x
     451                set smy4 $smy0                              ;# stem middle left y
     452                set smx5 [expr {$smx0-10+1}]                ;# triangle bottom left x
     453                set smy5 $smy0                              ;# triangle bottom left y
     454
     455                set tag $type
     456                $c delete $tag
     457                $c create polygon \
     458                    $smx1 $smy1 \
     459                    $smx2 $smy2 \
     460                    $smx3 $smy3 \
     461                    $smx4 $smy4 \
     462                    $smx5 $smy5 \
     463                    -outline black -fill black -tags [list $tag dialval]
     464
     465                $c bind $tag <Enter> [itcl::code $this _bindings marker $tag]
     466                $c bind $tag <Leave> [itcl::code $this _bindings timeline]
     467            }
    447468
    448469            if {[string compare "" $where] != 0} {
     
    462483            # add loopend marker
    463484
    464             set emx0 $frx0                              ;# loopend marker x0
    465             set emy0 $cy0                               ;# loopend marker y0
    466 
    467             set emx1 [expr {$emx0-1}]                   ;# triangle top x
    468             set emy1 [expr {$emy0-10}]                  ;# triangle top y
    469             set emx2 $emx1                              ;# stem bottom left x
    470             set emy2 $cy1                               ;# stem bottom left y
    471             set emx3 [expr {$emx0+1}]                   ;# stem bottom right x
    472             set emy3 $emy2                              ;# stem bottom right y
    473             set emx4 $emx3                              ;# stem middle right x
    474             set emy4 $emy0                              ;# stem middle right  y
    475             set emx5 [expr {$emx0+10-1}]                ;# triangle bottom right x
    476             set emy5 $emy0                              ;# triangle bottom right y
    477 
    478             set tag $type
    479             $c delete $tag
    480             $c create polygon \
    481                 $emx1 $emy1 \
    482                 $emx2 $emy2 \
    483                 $emx3 $emy3 \
    484                 $emx4 $emy4 \
    485                 $emx5 $emy5 \
    486                 -outline black -fill black -tags [list $tag dialval]
    487 
    488             $c bind $tag <Enter> [itcl::code $this _bindings marker $tag]
    489             $c bind $tag <Leave> [itcl::code $this _bindings timeline]
     485            if {($where >= ${_displayMin}) && ($where < ${_displayMax})} {
     486                set emx0 $frx0                              ;# loopend marker x0
     487                set emy0 $cy0                               ;# loopend marker y0
     488
     489                set emx1 [expr {$emx0-1}]                   ;# triangle top x
     490                set emy1 [expr {$emy0-10}]                  ;# triangle top y
     491                set emx2 $emx1                              ;# stem bottom left x
     492                set emy2 $cy1                               ;# stem bottom left y
     493                set emx3 [expr {$emx0+1}]                   ;# stem bottom right x
     494                set emy3 $emy2                              ;# stem bottom right y
     495                set emx4 $emx3                              ;# stem middle right x
     496                set emy4 $emy0                              ;# stem middle right  y
     497                set emx5 [expr {$emx0+10-1}]                ;# triangle bottom right x
     498                set emy5 $emy0                              ;# triangle bottom right y
     499
     500                set tag $type
     501                $c delete $tag
     502                $c create polygon \
     503                    $emx1 $emy1 \
     504                    $emx2 $emy2 \
     505                    $emx3 $emy3 \
     506                    $emx4 $emy4 \
     507                    $emx5 $emy5 \
     508                    -outline black -fill black -tags [list $tag dialval]
     509
     510                $c bind $tag <Enter> [itcl::code $this _bindings marker $tag]
     511                $c bind $tag <Leave> [itcl::code $this _bindings timeline]
     512            }
    490513
    491514            if {[string compare "" $where] != 0} {
     
    502525        }
    503526        "particle*" {
    504             set radius 3
    505             set pmx0 $frx0
    506             set pmy0 [expr {$cy1+5}]
    507             set coords [list [expr $pmx0-$radius] [expr $pmy0-$radius] \
    508                              [expr $pmx0+$radius] [expr $pmy0+$radius]]
    509 
    510             set tag $type
    511             $c delete $tag
    512             $c create oval $coords \
    513                 -fill green \
    514                 -outline black \
    515                 -width 1 \
    516                 -tags [list $tag dialval]
    517 
    518             #$c bind $tag <Enter> [itcl::code $this _bindings marker $tag]
    519             #$c bind $tag <Leave> [itcl::code $this _bindings timeline]
     527            if {($where >= ${_displayMin}) && ($where < ${_displayMax})} {
     528                set radius 3
     529                set pmx0 $frx0
     530                set pmy0 [expr {$cy1+5}]
     531                set coords [list [expr $pmx0-$radius] [expr $pmy0-$radius] \
     532                                 [expr $pmx0+$radius] [expr $pmy0+$radius]]
     533
     534                set tag $type
     535                $c delete $tag
     536                $c create oval $coords \
     537                    -fill green \
     538                    -outline black \
     539                    -width 1 \
     540                    -tags [list $tag dialval]
     541
     542                $c bind $tag <Enter> [itcl::code $this _bindings toolmark enter $tag]
     543                $c bind $tag <Leave> [itcl::code $this _bindings toolmark leave $tag]
     544            }
    520545
    521546            if {[string compare "" $where] != 0} {
     
    524549        }
    525550        "measure*" {
    526             set radius 3
    527             set amx0 $frx0
    528             set amy0 [expr {$cy1+15}]
    529             set coords [list [expr $amx0-$radius] [expr $amy0-$radius] \
    530                              [expr $amx0+$radius] [expr $amy0+$radius]]
    531 
    532             set tag $type
    533             $c delete $tag
    534             $c create line $coords \
    535                 -fill red \
    536                 -width 3  \
    537                 -tags [list $tag dialval]
    538 
    539             #$c bind $tag <Enter> [itcl::code $this _bindings marker $tag]
    540             #$c bind $tag <Leave> [itcl::code $this _bindings timeline]
     551            if {($where >= ${_displayMin}) && ($where < ${_displayMax})} {
     552                set radius 3
     553                set amx0 $frx0
     554                set amy0 [expr {$cy1+15}]
     555                set coords [list [expr $amx0-$radius] [expr $amy0-$radius] \
     556                                 [expr $amx0+$radius] [expr $amy0+$radius]]
     557
     558                set tag $type
     559                $c delete $tag
     560                $c create line $coords \
     561                    -fill red \
     562                    -width 3  \
     563                    -tags [list $tag dialval]
     564
     565                $c bind $tag <Enter> [itcl::code $this _bindings toolmark enter $tag]
     566                $c bind $tag <Leave> [itcl::code $this _bindings toolmark leave $tag]
     567            }
    541568
    542569            if {[string compare "" $where] != 0} {
     
    546573        "currentmark" {
    547574
    548             set cmx0 $frx0                              ;# current marker x0
    549             set cmy0 $cy0                               ;# current marker y0
    550 
    551             set cmx1 [expr {$cmx0+5}]                   ;# lower right diagonal edge x
    552             set cmy1 [expr {$cmy0-5}]                   ;# lower right diagonal edge y
    553             set cmx2 $cmx1                              ;# right top x
    554             set cmy2 [expr {$cmy1-5}]                   ;# right top y
    555             set cmx3 [expr {$cmx0-5}]                   ;# left top x
    556             set cmy3 $cmy2                              ;# left top y
    557             set cmx4 $cmx3                              ;# lower left diagonal edge x
    558             set cmy4 $cmy1                              ;# lower left diagonal edge y
    559 
    560             set tag $type
    561             $c delete $tag
    562             $c create polygon \
    563                 $cmx0 $cmy0 \
    564                 $cmx1 $cmy1 \
    565                 $cmx2 $cmy2 \
    566                 $cmx3 $cmy3 \
    567                 $cmx4 $cmy4 \
    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]
     575            if {($where >= ${_displayMin}) && ($where < ${_displayMax})} {
     576                set cmx0 $frx0                              ;# current marker x0
     577                set cmy0 $cy0                               ;# current marker y0
     578
     579                set cmx1 [expr {$cmx0+5}]                   ;# lower right diagonal edge x
     580                set cmy1 [expr {$cmy0-5}]                   ;# lower right diagonal edge y
     581                set cmx2 $cmx1                              ;# right top x
     582                set cmy2 [expr {$cmy1-5}]                   ;# right top y
     583                set cmx3 [expr {$cmx0-5}]                   ;# left top x
     584                set cmy3 $cmy2                              ;# left top y
     585                set cmx4 $cmx3                              ;# lower left diagonal edge x
     586                set cmy4 $cmy1                              ;# lower left diagonal edge y
     587
     588                set tag $type
     589                $c delete $tag
     590                $c create polygon \
     591                    $cmx0 $cmy0 \
     592                    $cmx1 $cmy1 \
     593                    $cmx2 $cmy2 \
     594                    $cmx3 $cmy3 \
     595                    $cmx4 $cmy4 \
     596                    -outline black \
     597                    -fill red \
     598                    -tags [list $tag dialval]
     599                $c create line $cmx0 $cmy0 $cmx0 $cy1 \
     600                    -fill red \
     601                    -tags [list $tag dialval]
     602
     603                $c bind $tag <Enter> [itcl::code $this _bindings marker $tag]
     604                $c bind $tag <Leave> [itcl::code $this _bindings timeline]
     605            }
    577606
    578607            if {[string compare "" $where] != 0} {
     
    605634    puts stderr "bbox all [$c bbox all]"
    606635    puts stderr "parent height [winfo height [winfo parent $c]]"
     636}
     637
     638# ----------------------------------------------------------------------
     639# USAGE: loop
     640#   loop between <start> <end> - setup looping between frames <start> and <end>
     641#   loop disable - disable looping
     642# ----------------------------------------------------------------------
     643itcl::body Rappture::Videodial2::loop {action args} {
     644    switch -- $action {
     645        "between" {
     646            if {[llength $args] != 2} {
     647                error "wrong # args: should be loop between <start> <end>"
     648            }
     649            foreach {startframe endframe} $args break
     650            mark add loopstart $startframe
     651            mark add loopend $endframe
     652            lappend _lockdial "loop"
     653        }
     654        "disable" {
     655            if {[llength $args] != 0} {
     656                error "wrong # args: should be loop disable"
     657            }
     658            mark remove loopstart
     659            mark remove loopend
     660            set idx [lsearch -exact ${_lockdial} "loop"]
     661            set _lockdial [lreplace ${_lockdial} $idx $idx]
     662        }
     663        default {
     664            error "bad value \"$action\": should be \"between\" or \"disable\""
     665        }
     666    }
    607667}
    608668
     
    855915
    856916# ----------------------------------------------------------------------
     917# USAGE: _goToFrame <framenum>
     918#
     919# lock the dial and go to frame <framenum>
     920# ----------------------------------------------------------------------
     921itcl::body Rappture::Videodial2::_goToFrame {framenum} {
     922    lappend _lockdial "_goToFrame"
     923    current $framenum
     924    event generate $itk_component(hull) <<Value>>
     925    set idx [lsearch -exact ${_lockdial} "_goToFrame"]
     926    set _lockdial [lreplace ${_lockdial} $idx $idx]
     927}
     928
     929# ----------------------------------------------------------------------
    857930# USAGE: _offsetx <x>
    858931#
     
    9291002        "click" {
    9301003            if {"currentmark" == $tag} {
    931                 set _lockdial 1
     1004                focus $itk_component(hull)
     1005                lappend _lockdial "currentmark"
    9321006            }
    9331007        }
     
    9491023                set oldfn [expr round([rel2ms ${_current}])]
    9501024                if {$newfn != $oldfn} {
    951                     _current [ms2rel $newfn]
    952                     event generate $itk_component(hull) <<Value>>
     1025                    _goToFrame $newfn
    9531026                }
    9541027            } else {
     
    9611034
    9621035            if {"currentmark" == $tag} {
    963                 set _lockdial 0
     1036                set idx [lsearch -exact ${_lockdial} "currentmark"]
     1037                set _lockdial [lreplace ${_lockdial} $idx $idx]
    9641038            }
    9651039
     
    10821156# ----------------------------------------------------------------------
    10831157itcl::body Rappture::Videodial2::_navigate {offset} {
    1084     _current [ms2rel [expr [rel2ms ${_current}] + $offset]]
    1085     event generate $itk_component(hull) <<Value>>
     1158    _goToFrame [expr [rel2ms ${_current}] + $offset]
    10861159}
    10871160
     
    12061279# ----------------------------------------------------------------------
    12071280itcl::configbody Rappture::Videodial2::offset {
    1208     if {![string is double $itk_option(-offset)]} {
    1209         error "bad value \"$itk_option(-offset)\": should be >= 0.0"
     1281    if {![string is integer $itk_option(-offset)] &&
     1282        ($itk_option(-offset) < 0)} {
     1283        error "bad value \"$itk_option(-offset)\": should be >= 1"
    12101284    }
    12111285    _fixOffsets
Note: See TracChangeset for help on using the changeset viewer.