
# JStrack:  copyright 1997/2010 by Jim Graham, N5IAL, all rights reserved.
#

# Plot the home coordinates, if defined

proc plot_home_x {} {
   global home_latt home_long color

   if {[info exists home_latt] && [info exists home_long]} {
      if {![valid_coords $home_latt $home_long]} { return }
      catch { .c delete homeloc }
      set x [set_long $home_long]
      set y [set_latt $home_latt]
      .c create text $x $y -fill $color(homex) -text "X" -tags homeloc
      .c itemconfigure homeloc -font {Helvetica 18 bold}
   }
}


proc image_message {{str ""}} {
   if {[string compare $str ""]} {
      catch {
         toplevel .imgmsg
         wm geometry .imgmsg +200+200
         wm attributes .imgmsg -topmost true
         label .imgmsg.lbl -font {Times 20}
         pack .imgmsg.lbl
      }
      .imgmsg.lbl configure -text $str
      update
   } else {
      catch { destroy .imgmsg }
   }
}


proc read_cmdline {} {
   global map loadlist argc argv
   set loadlist [list]

   if {$argc > 0} {
      set next_is_map 0
      for {set i 0} {$i < $argc} {incr i} {
         set t [lindex $argv $i]
         if {[string compare $t "-map"] == 0} {
            set next_is_map 1
         } elseif {$next_is_map} {
            if {[regexp {^overall} $t] || [regexp {^full} $t]} {
               set map large_js
               puts "Using the overall map"
            } elseif {[regexp {^east} $t]} {
               set map east_coast_js
               puts "Using the map of the East coast"
            } elseif {[regexp {^carib} $t]} {
               set map carib_js
               puts "Using map:  Caribbean and S. Gulf of Mexico"
            } elseif {[regexp {^gulf} $t]} {
               set map gulf_cab2_js
               puts "Using the map of the Gulf coast"
            } else {
               puts "I didn't understand what map you wanted...."
               puts "Please use either \"overall\" or \"full\" for the full map,"
               puts "\"east\" for the map of the East coast,"
               puts "\"caribbean\" or \"carib\" for the map of the Caribbean/S. Gulf,"
               puts "or \"gulf\" for the map of the Gulf coast."
            }
            flush stdout
            set next_is_map 0
         } else {
            lappend loadlist $t
         }
      }
   }
   catch { unset next_is_map }

}


# When the window is resized, figure out the appropriate canvas size
# (basically, take what's left after the other widgets are drawn) and
# resize it.
#
# It also screws up the size of the toplevel.

proc handle_resize {{force 0}} {
   #
   return
   #
   global c_w c_h info_text noreconfig
   if {$noreconfig} { return }
   set root_y_diff [expr {[winfo rooty .c] + [winfo height .ptrloc] + [winfo height .hscroll] + 20}]
   set root_x_diff [expr {[winfo rootx .c] + [winfo width .yscroll]}]
   set neww [winfo width .] ; set newh [winfo height .]
   if {$neww != $c_w || $newh != $c_h || $force} {
      set c_w $neww ; set c_h $newh
#     .c2 delete c2_info_text
      set newh [expr {$newh - $root_y_diff}]
      set neww [expr {$neww - $root_x_diff}]

      .c configure -width $neww -height $newh
      .c2 configure -height 20 -width $neww
      set x1 [expr {$neww - 450}]
      set y 10
      if {$x1 < 545} {
         incr newh -20
         .c configure -width $neww -height $newh
         .c2 configure -height 40
         set x1 10
         set y 30
      }
#     .c2 create text $x1 $y -anchor w -text $info_text -tag c2_info_text
      set oldconfigure [bind . <Configure>]
      bind . <Configure> {} ; update ; bind . <Configure> $oldconfigure
   }
}

