# ---------------------------------------------------------------------- # COMPONENT: Radiodial - selector, like the dial on a car radio # # This widget looks like the dial on an old-fashioned car radio. # It draws a series of values along an axis, and allows a selector # to move back and forth to select the values. # ====================================================================== # AUTHOR: Michael McLennan, Purdue University # Copyright (c) 2004-2005 Purdue Research Foundation # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ====================================================================== package require Itk option add *Radiodial.thickness 10 widgetDefault option add *Radiodial.length 2i widgetDefault option add *Radiodial.knobImage knob widgetDefault option add *Radiodial.knobPosition n@middle widgetDefault option add *Radiodial.dialOutlineColor black widgetDefault option add *Radiodial.dialFillColor white widgetDefault option add *Radiodial.lineColor gray widgetDefault option add *Radiodial.activeLineColor black widgetDefault option add *Radiodial.padding 0 widgetDefault option add *Radiodial.valueWidth 10 widgetDefault option add *Radiodial.valuePadding 0.1 widgetDefault option add *Radiodial.foreground black widgetDefault option add *Radiodial.font \ -*-helvetica-medium-r-normal-*-12-* widgetDefault itcl::class Rappture::Radiodial { inherit itk::Widget itk_option define -min min Min "" itk_option define -max max Max "" itk_option define -variable variable Variable "" itk_option define -thickness thickness Thickness 0 itk_option define -length length Length 0 itk_option define -padding padding Padding 0 itk_option define -foreground foreground Foreground "black" itk_option define -dialoutlinecolor dialOutlineColor Color "black" itk_option define -dialfillcolor dialFillColor Color "white" itk_option define -dialprogresscolor dialProgressColor Color "" itk_option define -linecolor lineColor Color "black" itk_option define -activelinecolor activeLineColor Color "black" itk_option define -knobimage knobImage KnobImage "" itk_option define -knobposition knobPosition KnobPosition "" itk_option define -font font Font "" itk_option define -valuewidth valueWidth ValueWidth 0 itk_option define -valuepadding valuePadding ValuePadding 0 constructor {args} { # defined below } destructor { # defined below } public method add {label {value ""}} public method clear {} public method get {args} public method current {args} public method color {value} protected method _setCurrent {val} protected method _redraw {} protected method _click {x y} protected method _navigate {offset} protected method _limits {} protected method _findLabel {str} protected method _fixSize {} protected method _fixValue {args} private variable _values "" ;# list of all values on the dial private variable _val2label ;# maps value => string label(s) private variable _current "" ;# current value (where pointer is) private variable _variable "" ;# variable associated with -variable private variable _knob "" ;# image for knob private variable _spectrum "" ;# width allocated for values private variable _activecolor "" ;# width allocated for values private variable _vwidth 0 ;# width allocated for values } itk::usual Radiodial { keep -background -foreground -cursor -font } # ---------------------------------------------------------------------- # CONSTRUCTOR # ---------------------------------------------------------------------- itcl::body Rappture::Radiodial::constructor {args} { itk_component add dial { canvas $itk_interior.dial } pack $itk_component(dial) -expand yes -fill both bind $itk_component(dial) [itcl::code $this _redraw] bind $itk_component(dial) [itcl::code $this _click %x %y] bind $itk_component(dial) [itcl::code $this _click %x %y] bind $itk_component(dial) [itcl::code $this _click %x %y] bind $itk_component(hull) [itcl::code $this _navigate -1] bind $itk_component(hull) [itcl::code $this _navigate 1] eval itk_initialize $args _fixSize } # ---------------------------------------------------------------------- # DESTRUCTOR # ---------------------------------------------------------------------- itcl::body Rappture::Radiodial::destructor {} { configure -variable "" ;# remove variable trace after cancel [itcl::code $this _redraw] } # ---------------------------------------------------------------------- # USAGE: add