proc plantex_makeframe {} {

   toplevel .plantex
   wm title .plantex "Plantex"
   wm transient .plantex [winfo toplevel [winfo parent .plantex]]

   set width 6
   set ypad 3

   # Scale X
   frame .plantex.frmscalex
   pack .plantex.frmscalex -side top -fill x

   label .plantex.frmscalex.lblscalex -text "Stretch X (%) "
   pack .plantex.frmscalex.lblscalex -side left -fill x

   spinbox .plantex.frmscalex.scalex -from 0.0 -increment 25.0 -to 800.0 -textvariable txtscalex -width $width
   pack .plantex.frmscalex.scalex -side right -fill x

   add_balloon .plantex.frmscalex.scalex "Scales the texture horizontally by a percentage"

   # Scale Y
   frame .plantex.frmscaley
   pack .plantex.frmscaley -side top -fill x

   label .plantex.frmscaley.lblscaley -text "Stretch Y (%) "
   pack .plantex.frmscaley.lblscaley -side left -fill x

   spinbox .plantex.frmscaley.scaley -from 0.0 -increment 25.0 -to 800.0 -textvariable txtscaley -width $width
   pack .plantex.frmscaley.scaley -side right -fill x

   add_balloon .plantex.frmscaley.scaley "Scales the texture vertically by a percentage"

   # Offset X
   frame .plantex.frmoffsetx
   pack .plantex.frmoffsetx -side top -fill x

   label .plantex.frmoffsetx.lbloffsetx -text "Horizontal shift (%) "
   pack .plantex.frmoffsetx.lbloffsetx -side left -fill x

   spinbox .plantex.frmoffsetx.offsetx -from -100.0 -increment 10.0 -to 100.0 -textvariable txtoffsetx -width $width
   pack .plantex.frmoffsetx.offsetx -side right -fill x

   add_balloon .plantex.frmoffsetx.offsetx "Percentage to offset the texture horizontally"

   # Offset Y
   frame .plantex.frmoffsety
   pack .plantex.frmoffsety -side top -fill x

   label .plantex.frmoffsety.lbloffsety -text "Vertical shift (%) "
   pack .plantex.frmoffsety.lbloffsety -side left -fill x

   spinbox .plantex.frmoffsety.offsety -from -100.0 -increment 10.0 -to 100.0 -textvariable txtoffsety -width $width
   pack .plantex.frmoffsety.offsety -side right -fill x

   add_balloon .plantex.frmoffsety.offsety "Percentage to offset the texture vertically"

   # Rotation
   frame .plantex.frmrot
   pack .plantex.frmrot -side top -fill x

   label .plantex.frmrot.lblrotate -text "Rotate  "
   pack .plantex.frmrot.lblrotate -side left -fill x

   spinbox .plantex.frmrot.rotate -from -360.0 -increment 45.0 -to 360.0 -textvariable txtrot -width $width
   pack .plantex.frmrot.rotate -side right -fill x

   add_balloon .plantex.frmrot.rotate "Degrees to rotate the texture on the surface - normally from -360.0 to 360.0"

   # Apply
   frame .plantex.frmbtn
   pack .plantex.frmbtn -side top -fill x

   button .plantex.frmbtn.btnapply -text "Apply" -command {
      set strarg "\"$txtscalex $txtscaley $txtoffsetx $txtoffsety $txtrot 0 -1 -1\""
      eval ac3d plantex_plugin $strarg
   }
   pack .plantex.frmbtn.btnapply -side left -fill x -expand 1

   # Space
   frame .plantex.frmspace1
   pack .plantex.frmspace1 -side top -fill x -pady $ypad

   # Fit X
   frame .plantex.frmfitx
   pack .plantex.frmfitx -side top -fill x

   label .plantex.frmfitx.lblfitx -text "Horizontal fit  "
   pack .plantex.frmfitx.lblfitx -side left -fill x

   spinbox .plantex.frmfitx.fitx -from 1 -increment 1 -to 32 -textvariable txtfitx -width $width
   pack .plantex.frmfitx.fitx -side right -fill x

   add_balloon .plantex.frmfitx.fitx "Fit texture the specified number of times on the 'X' coordinate"

   # Fit Y
   frame .plantex.frmfity
   pack .plantex.frmfity -side top -fill x

   label .plantex.frmfity.lblfity -text "Vertical fit  "
   pack .plantex.frmfity.lblfity -side left -fill x

   spinbox .plantex.frmfity.fity -from 1 -increment 1 -to 32 -textvariable txtfity -width $width
   pack .plantex.frmfity.fity -side right -fill x

   add_balloon .plantex.frmfity.fity "Fit texture the specified number of times on the 'Y' coordinate"

   # Fit Buttons
   frame .plantex.frmbtn2
   pack .plantex.frmbtn2 -side top -fill x

   button .plantex.frmbtn2.btnapplyfit -text "Apply fit" -command {
      set strarg "\"$txtscalex $txtscaley $txtoffsetx $txtoffsety $txtrot 1 $txtfitx $txtfity\""
      eval ac3d plantex_plugin $strarg
   }
   pack .plantex.frmbtn2.btnapplyfit -side left -fill x -expand 1

   # Space
   frame .plantex.frmspace2
   pack .plantex.frmspace2 -side top -fill x -pady $ypad

   # Fit Buttons
   frame .plantex.frmbtn3
   pack .plantex.frmbtn3 -side top -fill x

   button .plantex.frmbtn3.btnclose -text "Close" -command {
      wm withdraw .plantex
   }
   pack .plantex.frmbtn3.btnclose -side left -fill x -expand 1

}

proc plantex_dialog {} {

   global txtscalex
   global txtscaley
   global txtoffsetx
   global txtoffsety
   global txtrot
   global txtfitx
   global txtfity

   if ![winfo exists .plantex] {
      set txtscalex "100.0"
      set txtscaley "100.0"
      set txtoffsetx "0.0"
      set txtoffsety "0.0"
      set txtrot "0.0"
      set txtfitx "1"
      set txtfity "1"
      plantex_makeframe
   }

   wm deiconify .plantex
   centre_window_on_screen .plantex

}

