
%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 querybox;

## authentic web definitions from here

integer leftshift;
string obsid, infoobsid, defobsid; 

leftshift = 0;

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

window bgquerybox;

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


observables = <bgquerybox/querybox>;

%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 : bgquerybox_mouse_1 {
	if ((bgquerybox_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 : bgquerybox_mouse_1 {
        if ((bgquerybox_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, sudokuGrid, currobsid);


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


listobs = ["a_1", "a1", "a1_fixed", "A1_X1", "A1_Y1", "A1_bgcolour", "A1_fgcolour", "A1_bdcolour", "possdig11", "possdigit11"];
listinfoobs = ["The string displayed in square 11", "The digit in square 11, if any", "Whether or not the digit in square 11 is given in the puzzle", "The x-coordinate of square 11", "The y-coordinate of square 11", "The background colour of square 11", "The foreground colour for square 11", "The border colour of square 11", "The digits that would be plausible for square 11 if it is or were to be empty", "The plausible digits for square 11"];

proc nextdefn : querybox_mouse_1 {
	if (querybox_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;
leftshift is leftshiftmult * 12;
leftshiftmult is tick;
maxcharindefn = 80; ## good setting for laptop
maxcharindefn = 164; ## good setting for bigscreen

proc movedefnleft : bgquerybox_mouse_1 {
	if ((bgquerybox_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 : querybox_mouse_1 {
	if (tick>0) {
		todo("removeedenclock(&tick);");
		tick = 0;
	};
	if (querybox_mouse_1[2]==4)
		currobsid = (currobsid+1) % listobs#;
##		currobsid = (currobsid==listobs#) ? 1 : currobsid+1;
}


currentsquare = ["A", "1"];

listobs = ["a_1", "a1", "a1_fixed", "A1_X1", "A1_Y1", "A1_bgcolour", "A1_fgcolour", "A1_bdcolour", "possdig11", "possdigit11"];

listobs1 is char(96+current_col) // "_" // str(current_row);
listobs2 is char(96+current_col) // str(current_row);
listobs3 is char(96+current_col) // str(current_row) // "_fixed";
listobs4 is char(64+current_col) // str(current_row) // "_X1";
listobs5 is char(64+current_col) // str(current_row) // "_Y1";
listobs6 is char(64+current_col) // str(current_row) // "_bgcolour";
listobs7 is char(64+current_col) // str(current_row) // "_fgcolour";
listobs8 is char(64+current_col) // str(current_row) // "_bdcolour";
listobs9 is "possdig" // str(current_row) // str(current_col);
listobs10 is "possdigit" // str(current_row) // str(current_col);
listobs11 is "cntposs" // str(current_row) // str(current_col);
listobs12 is char(96+current_col) // str(current_row) // "_focus";

list0obs is ["currentsquare"];

listobs is (current_row*current_col!=0) ? [listobs1, listobs2, listobs3, listobs4, listobs5, listobs6, listobs7, listobs8, listobs9, listobs10, listobs11, listobs12] : list0obs;

list0infoobs is ["The currently selected square, if any"];

currsqname is char(64+current_col) // str(current_row);

listinfoobs is (current_row*current_col!=0) ? ["The string displayed in square " // currsqname, "The digit in square " // currsqname // ", if any", "Whether or not the digit in square " // currsqname // " is given in the puzzle", "The x-coordinate of square " // currsqname, "The y-coordinate of square " // currsqname, "The background colour of square " // currsqname, "The foreground colour for square " // currsqname, "The border colour of square " // currsqname, "The digits that would be plausible for square " // currsqname // " subject to its being empty", "The plausible digits for square " // currsqname, "The number of plausible digits for the square " // currsqname, "Whether or not square " // currsqname // " is currently selected"] : list0infoobs;

list0infoobs is ["The currently selected square, if any", "The details of the entire Sudoku grid","The colour used to highlight the currently selected square", "The colour used to highlight squares associated with the currently selected square", "The background colour of a squares not associated with the currently selected square", "Width of every grid square", "Height of every grid square", "Colour used to denote given digits", "Colour used to denote digits entered by the solver", "The count of possibilities for squares in the grid displayed as a table", "The digit that the solver currently has in mind", "How eliminating the current digit would affect the number of possibilities for each square", "How the potential impact of eliminating the current digit can be displayed in tabular form"];

list0obs is ["currentsquare", "sudokugrid", "SD_focus_colour", "SD_relevant_colour", "SD_bgcolour", "gridsquare_width", "gridsquare_height", "SD_fixed_fgcolour", "SD_fgcolour", "counttable", "currdigit", "currdiffcountlist", "diffcounttable"];

/*
obsid = "a1";
obsid = "a_1";
obsid = "a_4";
obsid = "a_5";
obsid = "A1_border";
obsid = "A1_bgcolour";
obsid = "SD_fgcolour";
obsid = "A1_fgcolour";
obsid = "a1_fixed";
obsid = "possdigit11";
obsid = "possdig11";
obsid = "row1";

obsid = "A1_X1";
obsid = "B1_X1";
obsid = "spacer_x";
obsid = "grid_startx";
obsid = "rowband1";
*/

%eden
FileLoadedOkay = 1;

