home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2006 April / SGP.iso / dema / Keepsake-Demo-en-li-v1.0.exe / res / bin / prime / oz'button.tcl < prev    next >
Text File  |  2005-10-29  |  4KB  |  122 lines

  1. class oz'button {
  2.     proc oz'button {this name} oz'widget {button$name} {
  3.         set ($this,name) $name
  4.         
  5.         set filename "$name/[file tail $name]"
  6.         set ($this,enable)  [new oz'sprite $filename.enable]
  7.         set ($this,target)  [new oz'sprite $filename.target]
  8.         set ($this,disable) [new oz'sprite $filename.disable]
  9.         set ($this,select)  [new oz'sprite $filename.select]
  10.         set ($this,p_click) ""
  11.         set ($this,s_click) "sound/interface/switchClic.ogg"
  12.         set ($this,s_over)  ""
  13.  
  14.         oz'widget::bind $this enter oz'button::enter $this
  15.         oz'widget::bind $this leave oz'button::leave $this
  16.         oz'widget::bind $this click oz'button::click $this
  17.  
  18.         oz'widget::child $this $($this,disable) 1
  19.         oz'widget::child $this $($this,enable)  0.75
  20.         oz'widget::child $this $($this,target)  0.50
  21.         oz'widget::child $this $($this,select)  0.25
  22.  
  23.         oz'widget::property $($this,disable) -alpha 0
  24.         oz'widget::property $($this,enable)  -alpha 1
  25.         oz'widget::property $($this,target)  -alpha 0
  26.         oz'widget::property $($this,select)  -alpha 0
  27.  
  28.         set ($this,state.enable) 1
  29.         set ($this,state.target) 0
  30.         set ($this,state.select) 0
  31.  
  32.         oz'widget::property $this -isize [oz'widget::width $($this,enable)] [oz'widget::height $($this,enable)]
  33.     }
  34.  
  35.     proc ~oz'button {this} {
  36.         delete $($this,enable)
  37.         delete $($this,target)
  38.         delete $($this,disable)
  39.         delete $($this,select)
  40.     }
  41.         
  42.     proc property {this args} {
  43.         set optstring {
  44.             {click "*"}
  45.             {disable}
  46.             {nodisablecursor}
  47.             {sclick "sound/interface/switchClic.ogg"}
  48.             {sover  ""}
  49.         }
  50.  
  51.         array set v [cmdline::getopt $args $optstring]
  52.         
  53.         if $v(click?)   {set ($this,p_click) $v(click)}
  54.         if $v(disable?) {disable $this}
  55.         
  56.         set ($this,s_click) $v(sclick)
  57.         set ($this,s_over)  $v(sover)
  58.         
  59.         eval "oz'widget::property $this $args"
  60.     }
  61.     
  62.     proc enter {this} {
  63.         if $($this,state.enable) {
  64.             set ($this,state.target) 1
  65.             if {$($this,s_over) != ""} {
  66.                 ozqSound::NewFX $($this,s_over)
  67.             }
  68.             oz'widget::fadeto $($this,target) 1
  69.             oz'mouse::cursor +1
  70.         } else {
  71.             oz'mouse::cursor +100
  72.         }
  73.     }
  74.  
  75.     proc leave {this} {
  76.         if $($this,state.enable) {
  77.             set ($this,state.target) 0
  78.             oz'widget::fadeto $($this,target) 0
  79.             oz'mouse::cursor -1
  80.         } else {
  81.             oz'mouse::cursor -100
  82.         }
  83.     }
  84.  
  85.     proc click {this} {
  86.         if !$($this,state.enable) return
  87.         ozqSound::NewFX $($this,s_click)
  88.         eval $($this,p_click)
  89.         select $this
  90.     }
  91.  
  92.     proc select {this} {
  93.         if !$($this,state.enable) return
  94.         set ($this,state.select) 1
  95.         oz'widget::fadeto $($this,select) 1
  96.     }
  97.  
  98.     proc unselect {this} {
  99.         if !$($this,state.enable) return
  100.         set ($this,state.select) 0
  101.         oz'widget::fadeto $($this,select) 0
  102.     }
  103.     
  104.     proc enable {this} {
  105.         set ($this,state.enable) 1
  106.         oz'widget::fadeto $($this,disable) 0
  107.         oz'widget::fadeto $($this,enable)  1
  108.     }
  109.  
  110.     proc disable {this} {
  111.         set ($this,state.enable) 0
  112.         set ($this,state.target) 0
  113.         set ($this,state.select) 0
  114.  
  115.         oz'widget::fadeto $($this,disable) 1
  116.         oz'widget::fadeto $($this,enable)  0
  117.         oz'widget::fadeto $($this,target)  0
  118.         oz'widget::fadeto $($this,select)  0
  119.     }
  120. }
  121.  
  122.