.getBranch(null);
var gStartTime = 0;
var gMbrotBundle;
+var gCurrentImageData;
function Startup() {
updateIterMenu();
document.getElementById("statusLabel").value = gMbrotBundle.getString("statusEmpty");
}
+function adjustCoordsAndDraw(aC_min, aC_max) {
+ let iWidth = 0;
+ try {
+ iWidth = gPref.getIntPref("mandelbrot.image.width");
+ }
+ catch (e) { }
+ if ((iWidth < 10) || (iWidth > 5000)) {
+ iWidth = 300;
+ gPref.setIntPref("mandelbrot.image.width", iWidth);
+ }
+ let iHeight = 0;
+ try {
+ iHeight = gPref.getIntPref("mandelbrot.image.height");
+ }
+ catch (e) { }
+ if ((iHeight < 10) || (iHeight > 5000)) {
+ iHeight = 300;
+ gPref.setIntPref("mandelbrot.image.height", iHeight);
+ }
+
+ // correct coordinates
+ if (aC_min.r < -2)
+ aC_min.r = -2;
+ if (aC_max.r > 2)
+ aC_max.r = 2;
+ if ((aC_min.r > 2) || (aC_max.r < -2) || (aC_min.r >= aC_max.r)) {
+ aC_min.r = -2.0; aC_max.r = 1.0;
+ }
+ if (aC_min.i < -2)
+ aC_min.i = -2;
+ if (aC_max.i > 2)
+ aC_max.i = 2;
+ if ((aC_min.i > 2) || (aC_max.i < -2) || (aC_min.i >= aC_max.i)) {
+ aC_min.i = -1.5; aC_max.i = 1.5;
+ }
+
+ let CWidth = aC_max.r - aC_min.r;
+ let CHeight = aC_max.i - aC_min.i;
+ let C_mid = new complex(aC_min.r + CWidth / 2, aC_min.i + CHeight / 2);
+
+ let CRatio = Math.max(CWidth / iWidth, CHeight / iHeight);
+
+ gPref.setCharPref("mandelbrot.last_image.Cr_min", C_mid.r - iWidth * CRatio / 2);
+ gPref.setCharPref("mandelbrot.last_image.Cr_max", C_mid.r + iWidth * CRatio / 2);
+ gPref.setCharPref("mandelbrot.last_image.Ci_min", C_mid.i - iHeight * CRatio / 2);
+ gPref.setCharPref("mandelbrot.last_image.Ci_max", C_mid.i + iHeight * CRatio / 2);
+
+ drawImage();
+}
+
function drawImage() {
let canvas = document.getElementById("mbrotImage");
let context = canvas.getContext("2d");
catch (e) { }
if ((Ci_min < -2) || (Ci_min > 2) ||
(Ci_max < -2) || (Ci_max > 2) || (Ci_min >= Ci_max)) {
- Ci_min = -2.0; Ci_max = 1.0;
+ Ci_min = -1.5; Ci_max = 1.5;
}
gPref.setCharPref("mandelbrot.last_image.Ci_min", Ci_min);
gPref.setCharPref("mandelbrot.last_image.Ci_max", Ci_max);
gPref.setIntPref("mandelbrot.image.height", iHeight);
}
+ gCurrentImageData = {
+ C_min: new complex(Cr_min, Ci_min),
+ C_max: new complex(Cr_max, Ci_max),
+ iWidth: iWidth,
+ iHeight: iHeight,
+ iterMax: iterMax
+ };
+
canvas.width = iWidth;
canvas.height = iHeight;
break;
case 'up':
if (event.button == 0 && zoomstart) {
+ let zoomend = {x: event.clientX - canvas.offsetLeft,
+ y: event.clientY - canvas.offsetTop};
+
+ // make sure zoomend is bigger than zoomstart
+ if ((zoomend.x == zoomstart.x) || (zoomend.y == zoomstart.y)) {
+ // cannot zoom what has no area, discard it
+ zoomstart = undefined;
+ return;
+ }
+ if (zoomend.x < zoomstart.x)
+ [zoomend.x, zoomstart.x] = [zoomstart.x, zoomend.x];
+ if (zoomend.y < zoomstart.y)
+ [zoomend.y, zoomstart.y] = [zoomstart.y, zoomend.y];
+
let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
let ok = prompts.confirm(null, gMbrotBundle.getString("zoomConfirmTitle"),
- gMbrotBundle.getString("zoomConfirmLabel") + ' --- ' +
- zoomstart.x + ',' + zoomstart.y + '-' +
- (event.clientX - canvas.offsetLeft) + ',' +
- (event.clientY - canvas.offsetTop));
+ gMbrotBundle.getString("zoomConfirmLabel"));
// ok is now true if OK was clicked, and false if cancel was clicked
+ if (ok) {
+ // determine new "coordinates"
+ let CWidth = gCurrentImageData.C_max.r - gCurrentImageData.C_min.r;
+ let CHeight = gCurrentImageData.C_max.i - gCurrentImageData.C_min.i;
+ let newC_min = new complex(
+ gCurrentImageData.C_min.r + zoomstart.x / gCurrentImageData.iWidth * CWidth,
+ gCurrentImageData.C_min.i + zoomstart.y / gCurrentImageData.iHeight * CHeight);
+ let newC_max = new complex(
+ gCurrentImageData.C_min.r + zoomend.x / gCurrentImageData.iWidth * CWidth,
+ gCurrentImageData.C_min.i + zoomend.y / gCurrentImageData.iHeight * CHeight);
+
+ adjustCoordsAndDraw(newC_min, newC_max);
+ }
}
zoomstart = undefined;
break;
(!document.getElementById("drawButton").hidden || (gStartTime > 0));
while (aParent.hasChildNodes() &&
- aParent.lastChild.id != 'bookmarkSeparator')
+ aParent.lastChild.id != "bookmarkSeparator")
aParent.removeChild(aParent.lastChild);
let file = Components.classes["@mozilla.org/file/directory_service;1"]
try {
if (connection.tableExists("bookmarks")) {
let statement = connection.createStatement(
- "SELECT name FROM bookmarks ORDER BY ROWID DESC");
- while (statement.executeStep())
- aParent.appendChild(document.createElement("menuitem"))
- .setAttribute("label", statement.getString(0));
+ "SELECT name,ROWID FROM bookmarks ORDER BY ROWID ASC");
+ while (statement.executeStep()) {
+ let newItem = aParent.appendChild(document.createElement("menuitem"));
+ newItem.setAttribute("label", statement.getString(0));
+ newItem.setAttribute("bmRowID", statement.getString(1));
+ }
statement.reset();
statement.finalize();
return;
}
function callBookmark(evtarget) {
+ if (evtarget.id == "bookmarkSave" || evtarget.id == "bookmarkSeparator")
+ return
+
+ alert(evtarget.getAttribute('label') + ', ' + evtarget.getAttribute('bmRowID'));
+ //gPref.setIntPref("mandelbrot.iteration_max", iterMax);
}
function saveBookmark() {
let statement = connection.createStatement(
"INSERT INTO bookmarks (name,iteration_max,Cr_min,Cr_max,Ci_min,Ci_max) VALUES (?1,?2,?3,?4,?5,?6)");
statement.bindStringParameter(0, bmName);
- statement.bindStringParameter(1, gPref.getIntPref("mandelbrot.iteration_max"));
- statement.bindStringParameter(2, parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_min")));
- statement.bindStringParameter(3, parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_max")));
- statement.bindStringParameter(4, parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_min")));
- statement.bindStringParameter(5, parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_max")));
+ statement.bindStringParameter(1, gCurrentImageData.iterMax);
+ statement.bindStringParameter(2, gCurrentImageData.C_min.r);
+ statement.bindStringParameter(3, gCurrentImageData.C_max.r);
+ statement.bindStringParameter(4, gCurrentImageData.C_min.i);
+ statement.bindStringParameter(5, gCurrentImageData.C_max.i);
statement.execute();
statement.finalize();
connection.commitTransaction();