#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"

# TigerGraphics Math and Fractal Tools 1.5.2 Copyright (C) 2026, Cora Kohlmeier, Frank Hamberg

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

option add *background #b8b8f8
option add *activeBackground #d8d8ff
option add *borderwidth 2
option add *foreground black

global env exec_dir pwd home toolflag storedir install_dir tclsrc_dir pythonwork pythonexec pythonok tgfcomment
global fracversion

##############################################
set fracversion "1.5.2"
###############################################
set compile 1
set pythonok 0
set tgfcomment ""

# Environment ermitteln
set home $env(HOME)

# so ist es für Linuxe und MacOS
set DOS 0
set install_dir [file dir [info script]]

# Betriebssystem ermitteln
set arch [lindex $tcl_platform(os) 0]

# Settings für Windows
if {[string match Windows* $arch]==1} {
	set DOS 1
    set install_dir .
}
# Settings für MacOS
if {[string match Darwin* $arch]==1} {
	set DOS 2
# auf MacOS Mojave prüfen	
	if {[string match 18* [lindex $tcl_platform(osVersion) 0]]} {set DOS 3}
}

# Pfade setzen
set tclsrc_dir $install_dir/tclsrc
set exec_dir $install_dir/bin
set defaultstoredir $home/mftfiles

##########################################################################
# Preparing fileboxes (not necessary but nice for hidden files)
if {$DOS==0} {
   catch { tk_getOpenFile -w00t } ;# start file dialog with unknown option
       set ::tk::dialog::file::showHiddenBtn 1 
       set ::tk::dialog::file::showHiddenVar 0
} 
##########################################################################
set dirlist "general fractals mandel ifs bifu slope plotter automat"

foreach item $dirlist {
	if {$compile==1} {auto_mkindex $tclsrc_dir/$item *.tcl}
	lappend autopath $tclsrc_dir/$item
	set dir $tclsrc_dir/$item
	set unit [open $tclsrc_dir/$item/tclIndex]
	eval [read $unit]
	close $unit
}
set pythonwork [maskSpace $install_dir/src/slope]

readdefaults

if ![file exist $storedir] {file copy $install_dir/mftfiles $storedir}
if ![file exists $storedir/temp] {file mkdir $storedir/temp}
file delete -force $storedir/temp/reload.tgf
file delete -force $storedir/temp/tempout.tgf
file delete -force $storedir/temp/tempin.tgf
file delete -force $storedir/temp/PyIso.tgf
file delete -force $storedir/temp/PyRes.tgf


 # Global definitions
#-------------------
global colorlist color blue yellow green violet dblue
set colorlist {black red limegreen blue3 gold cyan purple magenta green}

set blue #B8B8F8
set red #DD0000
set yellow #EEEE00
set green #00AA00
set violet #AA00AA
set dblue #0000FF

set color(0) #B8B8F8
set color(1) #DD0000
set color(2) #00AA00
set color(3) #EEEE00
set color(4) #0000FF
set color(5) #AA00AA
set color(6) #eb8000
set color(7) #e623ff
set color(8) #bd4b00
set color(9) #8f7700
set color(10) #659f00
set color(11) #37cb00
set color(12) #0df300
set color(13) #00df26
set color(14) #00b74d
set color(15) #008a77
set color(16) #00629e
set color(17) #0035c8
set color(18) #000def
set color(19) #0000e3
set color(20) #0000bb
set color(21) #00008e
set color(22) #000066
set color(23) #000039
set color(24) #000011


global taglist
set taglist [concat axis $colorlist]
global plotFontN plotFontS plotFontT
global boldFontN boldFontS boldFontT
global textFont
global infoFont

# Listbox height in Zeilen
global lbheight 
set lbheight 10

global can smallscreen
set can 600
set smallscreen 0

global plotcounter
set plotcounter 0
global defaultcan
set sizedetect 0
set can $defaultcan

if {[winfo screenheight .] <=1600} {set sizedetect 4}
if {[winfo screenheight .] <=1024} {set sizedetect 3}
if {[winfo screenheight .] <=800} {set sizedetect 2}
if {[winfo screenheight .] <=600} {set sizedetect 1}
#set sizedetect 2
#if {[winfo screenheight .] <=2000} {set sizedetect 1}

switch $sizedetect {

1 {       set smallscreen 1
            if {$defaultcan > 500} {set can 500}
            set lbheight 5
            set ff 60
            set tt 40
}
2 {       set smallscreen 0
            if {$defaultcan > 600} {set can 600}
            set lbheight 5
             set ff 80
             set tt 60
}

3 {       set smallscreen 0
            if {$defaultcan > 700} {set can 700}
            set lbheight 10
            set ff 100
            set tt 80
}
4 {       set smallscreen 0
            if {$defaultcan > 1500} {set can 1500}
            set lbheight 15
            set ff 120
            set tt 100
}

default {  
            set smallscreen 0
            set can 800
            set lbheight 10
            set ff 100
            set tt 80
}


}
 set plotFontN -*-Helvetica-Medium-R-Normal--*-$ff-*-*-*-*-*-*
 set plotFontS -*-Helvetica-Medium-R-Normal--*-$ff-*-*-*-*-*-*
 set plotFontT -*-Helvetica-Medium-R-Normal--*-$tt-*-*-*-*-*-*
 set boldFontN -*-Helvetica-Bold-R-Normal--*-$ff-*-*-*-*-*-*
 set boldFontS -*-Helvetica-Bold-R-Normal--*-$ff-*-*-*-*-*-*
 set boldFontT -*-Helvetica-Bold-R-Normal--*-$tt-*-*-*-*-*-*
 set textFont -*-Courier-Bold-R-Normal--*-$ff-*-*-*-*-*-*
 set infoFont -*-Helvetica-Bold-R-Normal--*-$ff-*-*-*-*-*-*


#------------------------------
# Window manager configurations
#------------------------------

global tkVersion
wm positionfrom . user
wm sizefrom . ""
wm geometry . "+400+50"

wm title . "Tiger Graphics Mathtools $fracversion"
#wm protocol . WM_DELETE_WINDOW {.top.exit invoke}

wm iconmask . @$install_dir/icons/tinylogo.pic
wm iconbitmap . @$install_dir/icons/tinylogo.pic

create_top

# Für Windows
if {$DOS==1} {console hide}


