
%eden

OpenDisplay("observables", 2000, 80);
## OpenDisplay("observables", 1110, 80);
## need to set these parameters appropriately on start up
## first one is good for the big screen, second for a laptop

proc observables_display_screen : observables {
        DisplayScreen(&observables, "observables");
};

%scout

window obsinfobox;

## authentic web definitions from here

integer leftshift;
string obsid, infoobsid, defobsid; 

leftshift = 0;

obsinfobox = {
	type: TEXT
## 	frame:([{10,10}, {(strlen(infoobsid)+2)*12, 10+1.r}])
	frame:([{10,10}, {(strlen(infoobsid)+2).c, 10+1.r}])
	border: 1
	alignment: CENTRE
	string: infoobsid
##	fgcolour: colvardef
	fgcolour: "black"
	bgcolour: "lightgreen"
	sensitive: ON
};

window obsdefnbox;

obsdefnbox = {
	type: TEXT
##	frame: ([{10-leftshift,10+1.r}, {(strlen(defobsid)+2)*12-leftshift, 10+2.r}])
	frame: ([{10-leftshift,10+1.r}, {(strlen(defobsid)+2).c-leftshift, 10+2.r}])
	bgcolour: "white"
	fgcolour: "red"
	string: defobsid
	sensitive: ON
};


observables = <obsdefnbox/obsinfobox>;

%eden

/*
a is b+c;
obsid = "a";
*/

func createdef {
	para ident;
	auto result;
	result = symboldetail(ident)[1] // " is" // symboldetail(ident)[3];
##	result = " " // symboldetail(ident)[1] // " depends on " // str(symboldetail(ident)[5]);
 	if (symboldetail(ident)[3]=="")
 		result = result // " explicitly defined";
 	
	return result;
}

/*

func createdef {
	para ident;
	auto result;
	result = symboldetail(ident)[1] // " is" // symboldetail(ident)[3];
##	result = " " // symboldetail(ident)[1] // " depends on " // str(symboldetail(ident)[5]);
 	if (symboldetail(ident)[3]=="") {
 		result = result // " explicitly defined to be ";
	 	if (current_row*current_col!=0)
		 	result = result // str(eval(`listobs[currobsid%listobs#+1]`));
		else result = result // str(eval(`list0obs[currobsid%list0obs#+1]`));
	}
	return result;
}

func createval {
	para ident;
	auto result;
	result = "";
 	if (symboldetail(ident)[3]=="") {
	 	if (current_row*current_col!=0)
		 	result = result // str(eval(`listobs[currobsid%listobs#+1]`));
		else result = result // str(eval(`list0obs[currobsid%list0obs#+1]`));
	}
	return result;
}

defobsidext is (current_row*current_col!=0)
	? str(eval(`listobs[currobsid%listobs#+1]`))
	: str(eval(`list0obs[currobsid%list0obs#+1]`));
	

*/


proc displayval : obsdefnbox_mouse_1 {
	if ((obsdefnbox_mouse_1[2]==4)
	&& (substr(defobsid,defobsid#-17,defobsid#)=="explicitly defined"))
	writeln((current_row*current_col!=0)
		? `listobs[currobsid%listobs#+1]`
		: `list0obs[currobsid%list0obs#+1]`);
}

proc displayval : obsdefnbox_mouse_1 {
        if ((obsdefnbox_mouse_1[2]==4)
        && (substr(defobsid,defobsid#-17,defobsid#)=="explicitly defined"))
        writeln(obsid, " = ", (current_row*current_col!=0)
                ? `listobs[currobsid%listobs#+1]`
                : `list0obs[currobsid%list0obs#+1]`);
}


defobsid is " " // createdef(obsid, currobsid);
## it may be useful to add a root observable that is universally updated
## when any redefinition is made (such as the sudokugrid observable in the Sudoku model)
## as an extra dummy argument to this function - this guarantees that definitions are updated


currobsid = 1;
infoobsid is listinfoobs[currobsid%listinfoobs# + 1];
obsid is listobs[currobsid%listobs# + 1];

proc nextdefn : obsinfobox_mouse_1 {
	if (obsinfobox_mouse_1[2]==4)
		currobsid = (currobsid+1) % listobs#;
##		currobsid = (currobsid==listobs#) ? 1 : currobsid+1;
}


## speculative way to make a long definition more visible! - but means that leftshiftmult should be reset for other definitions.

tick = 0;
edenclocks = [];
leftshift is leftshiftmult * 12;
leftshiftmult is tick;
maxcharindefn = 80; ## good setting for laptop
maxcharindefn = 164; ## good setting for bigscreen

proc movedefnleft : obsdefnbox_mouse_1 {
	if ((obsdefnbox_mouse_1[2]==4)&&(defobsid#-tick > maxcharindefn)) {
		tick = 0;
		setedenclock(&tick, 200);
	}
}

proc stopclock : tick {
	if (defobsid#-tick == maxcharindefn) {
		todo("edenclocks = [];");
		tick = 0;
	}
}

proc nextdefn : obsinfobox_mouse_1 {
	if (tick>0) {
		todo("removeedenclock(&tick);");
		tick = 0;
	};
	if (obsinfobox_mouse_1[2]==4)
		currobsid = (currobsid+1) % listobs#;
##		currobsid = (currobsid==listobs#) ? 1 : currobsid+1;
}

%eden
FileLoadedOkay = 1;

