comparison client/digitallibrary/greyskin/dllib.js @ 451:6b9f375f5073

ongoing experimental intermediary release - calibration and scale modes are working
author robcast
date Mon, 30 Jan 2006 16:02:04 +0100
parents ff63f8ce2039
children 1952462027b6
comparison
equal deleted inserted replaced
450:23195b070d30 451:6b9f375f5073
212 this.scalerDiv = null; 212 this.scalerDiv = null;
213 this.scalerImg = null; 213 this.scalerImg = null;
214 this.buttons1Div = null; 214 this.buttons1Div = null;
215 this.buttons2Div = null; 215 this.buttons2Div = null;
216 /* parse parameters */ 216 /* parse parameters */
217 this.params = new DLParameters();
217 // put the query parameters (sans "?") in the parameters array 218 // put the query parameters (sans "?") in the parameters array
218 this.params = new DLParameters();
219 this.params.parse(location.search.slice(1)); 219 this.params.parse(location.search.slice(1));
220 // treat special parameters 220 // treat special parameters
221 this.area = this.parseArea(); 221 this.area = this.parseArea();
222 this.marks = new Marks(); 222 this.marks = new Marks();
223 this.marks.parse(this.params.get("mk")); 223 this.marks.parse(this.params.get("mk"));
266 Digilib.prototype.parseTrafo = function(elem) { 266 Digilib.prototype.parseTrafo = function(elem) {
267 // returns Transform from current dlArea and picsize 267 // returns Transform from current dlArea and picsize
268 var picsize = getElementRect(elem); 268 var picsize = getElementRect(elem);
269 var trafo = new Transform(); 269 var trafo = new Transform();
270 // subtract area offset and size 270 // subtract area offset and size
271 trafo.concat(getTranslation(new Position(-this.area.x, -this.area.y))); 271 trafo.concat(trafo.getTranslation(new Position(-this.area.x, -this.area.y)));
272 trafo.concat(getScale(new Size(1/this.area.width, 1/this.area.height))); 272 trafo.concat(trafo.getScale(new Size(1/this.area.width, 1/this.area.height)));
273 // scale to screen size 273 // scale to screen size
274 trafo.concat(getScale(picsize)); 274 trafo.concat(trafo.getScale(picsize));
275 trafo.concat(getTranslation(picsize)); 275 trafo.concat(trafo.getTranslation(picsize));
276 // FIX ME: Robert, kannst Du mal nachsehen, ob das folgende tut, was es soll? 276 // FIX ME: Robert, kannst Du mal nachsehen, ob das folgende tut, was es soll?
277 // oder gibt es dafuer neuen Code? -- ROC: Bisher funktioniert es nicht! 277 // oder gibt es dafuer neuen Code? -- ROC: Bisher funktioniert es nicht!
278 // rotate 278 // rotate
279 //var rot = getRotation(- dl.params.get("rot"), new Position(0.5*picsize.width, 0.5*picsize.height)); 279 //var rot = getRotation(- dl.params.get("rot"), new Position(0.5*picsize.width, 0.5*picsize.height));
280 //trafo.concat(rot); 280 //trafo.concat(rot);
345 digilib.trafo = digilib.parseTrafo(digilib.scalerImg); 345 digilib.trafo = digilib.parseTrafo(digilib.scalerImg);
346 // display marks 346 // display marks
347 digilib.renderMarks(); 347 digilib.renderMarks();
348 digilib.showBirdDiv(isBirdDivVisible); 348 digilib.showBirdDiv(isBirdDivVisible);
349 digilib.showArrows(); // show arrow overlays for zoom navigation 349 digilib.showArrows(); // show arrow overlays for zoom navigation
350 digilib.moveCenter(true); // click to move point to center 350 //digilib.moveCenter(true); // click to move point to center
351 // new Slider("sizes", 1, 5, 2); 351 // new Slider("sizes", 1, 5, 2);
352 focus(); 352 focus();
353 } 353 }
354 } 354 }
355 Digilib.prototype.renderMarks = function() { 355 Digilib.prototype.renderMarks = function() {
546 } 546 }
547 } 547 }
548 548
549 Digilib.prototype.isFullArea = function(area) { 549 Digilib.prototype.isFullArea = function(area) {
550 if (!area) area = this.area; 550 if (!area) area = this.area;
551 // pixel by pixel is not always full area 551 return (area.width == 1.0) && (area.height == 1.0);
552 return (area.width == 1.0) && (area.height == 1.0) && ! this.flags.get("clip");
553 } 552 }
554 553
555 Digilib.prototype.canMove = function(movx, movy) { 554 Digilib.prototype.canMove = function(movx, movy) {
556 if (this.isFullArea()) return false; 555 if (this.isFullArea()) return false;
557 var x2 = this.area.x + this.area.width; 556 var x2 = this.area.x + this.area.width;
729 showElement(overlay, false); 728 showElement(overlay, false);
730 return; 729 return;
731 }; 730 };
732 var birdImgRect = getElementRect(birdImg); 731 var birdImgRect = getElementRect(birdImg);
733 var area = this.area; 732 var area = this.area;
734 // scale area down to img size 733 if (this.flags.get("osize") || this.flags.get("clip")) {
735 var birdAreaRect = new Rectangle( 734 // in original-size and pixel-by-pixel mode the area size is not valid
736 // what about borders ?? 735 var birdAreaRect = new Rectangle(
737 birdImgRect.x + birdImgRect.width * area.x, 736 birdImgRect.x + birdImgRect.width * area.x,
738 birdImgRect.y + birdImgRect.height * area.y, 737 birdImgRect.y + birdImgRect.height * area.y,
739 birdImgRect.width * area.width, 738 5,
740 birdImgRect.height * area.height 739 5);
741 ); 740 } else {
741 // scale area down to img size
742 var birdAreaRect = new Rectangle(
743 // what about borders ??
744 birdImgRect.x + birdImgRect.width * area.x,
745 birdImgRect.y + birdImgRect.height * area.y,
746 birdImgRect.width * area.width,
747 birdImgRect.height * area.height);
748 }
742 moveElement(birdArea, birdAreaRect); 749 moveElement(birdArea, birdAreaRect);
743 showElement(birdArea, true); 750 showElement(birdArea, true);
744 moveElement(overlay, birdImgRect); 751 moveElement(overlay, birdImgRect);
745 showElement(overlay, true); 752 showElement(overlay, true);
746 registerEvent("mousedown", overlay, birdAreaStartDrag); 753 registerEvent("mousedown", overlay, birdAreaStartDrag);
821 new Rectangle(r.x + r.width - this.ARROW_WIDTH, r.y, this.ARROW_WIDTH, r.height), 828 new Rectangle(r.x + r.width - this.ARROW_WIDTH, r.y, this.ARROW_WIDTH, r.height),
822 this.canMove(1, 0) 829 this.canMove(1, 0)
823 ); 830 );
824 } 831 }
825 832
826 Digilib.prototype.calibrate = function(direction) { 833 Digilib.prototype.calibrate = function() {
827 // calibrate screen 834 // calibrate screen resolution
828 var startPos; // anchor for dragging
829 var newRect; // position after drag
830 var calDiv = getElement("calibration"); 835 var calDiv = getElement("calibration");
831 var pixel = calDiv.getElementsByTagName("p")[0]; 836 var calRect = getElementRect(calDiv);
832 var overlay = getElement("overlay");
833 moveElement(overlay, getWinRect());
834 showElement(overlay, true);
835 var xDir = direction == "x";
836 moveCenter(false); 837 moveCenter(false);
837 registerEvent("mousedown", document, calibrationStartDrag); 838 var wins = getWinSize();
838 839 calRect.setCenter(new Position(wins.width / 2, wins.height / 2));
839 function calibrationStartDrag(evt) { 840 moveElement(calDiv, calRect);
840 // mousedown handler: start drag 841 showElement(calDiv, true);
841 startPos = evtPosition(evt); 842 var cm = window.prompt("The length of the scale on your screen in centimeter:");
842 unregisterEvent("mousedown", document, calibrationStartDrag); 843 if (cm) {
843 registerEvent("mousemove", document, calibrationMove); 844 var dpi = calRect.width / parseFloat(cm) * 2.54;
844 registerEvent("mouseup", document, calibrationEndDrag); 845 this.params.set("ddpi", cropFloat(dpi));
845 newRect = new Rectangle( 846 }
846 startPos.x, 847 showElement(calDiv, false);
847 startPos.y, 848 }
848 xDir ? 1 : CALIBRATION_WIDTH, 849
849 xDir ? CALIBRATION_WIDTH : 1 850
850 ); 851 Digilib.prototype.setScale = function(scale) {
851 moveElement(calDiv, newRect); 852 // sets original-size, pixel-by-pixel or fit-to-screen scale type
852 showElement(calDiv, true); 853 if (scale == "pixel") {
853 // debugProps(getElementRect(bird)) 854 // pixel by pixel
854 return stopEvent(evt); 855 this.flags.set("clip");
855 } 856 this.flags.reset("osize");
856 857 this.flags.reset("fit");
857 function calibrationMove(evt) { 858 } else if (scale == "original") {
858 // mousemove handler: drag 859 // original size -- needs calibrated screen
859 var pos = evtPosition(evt); 860 if (!this.params.isSet("ddpi")) {
860 var dx = (xDir) ? pos.x - startPos.x : CALIBRATION_WIDTH; 861 var dpi = cookie.get("ddpi");
861 var dy = (xDir) ? CALIBRATION_WIDTH : pos.y - startPos.y; 862 if (dpi == null) {
862 // move birdArea div, keeping size 863 alert("Your screen has not yet been calibrated - using default value of 72 dpi");
863 newRect = new Rectangle(startPos.x, startPos.y, dx, dy); 864 dpi = 72;
864 pixel.innerHTML = (xDir ? dx : dy) + " px"; 865 }
865 moveElement(calDiv, newRect); 866 this.params.set("ddpi", dpi);
866 showElement(calDiv, true); 867 }
867 return stopEvent(evt);
868 }
869
870 function calibrationEndDrag(evt) {
871 // mouseup handler: calibrate
872 unregisterEvent("mousemove", document, calibrationMove);
873 unregisterEvent("mouseup", document, calibrationEndDrag);
874 if (xDir) {
875 var val = newRect.width * 0.254; // ratio dm/inch
876 cookie.add("ddpi", val);
877 cookie.add("ddpix", val);
878 } else {
879 var val = newRect.height * 0.254;
880 cookie.add("ddpiy", val);
881 }
882 showElement(calDiv, false);
883 showElement(overlay, false);
884 moveCenter(true);
885 return stopEvent(evt);
886 }
887 }
888
889 Digilib.prototype.originalSize = function(on) {
890 // set osize flag, needs calibrated screen
891 if (on) {
892 var dpi = cookie.get("ddpi");
893 if (dpi == null) {
894 alert("Screen has not yet been calibrated - using default value of 72 dpi");
895 dpi = 72;
896 }
897 this.params.set("ddpi", dpi);
898 this.flags.set("osize"); 868 this.flags.set("osize");
899 this.display(); 869 this.flags.reset("clip");
870 this.flags.reset("fit");
900 } else { 871 } else {
872 // scale to screen size (default)
873 this.flags.reset("clip");
901 this.flags.reset("osize"); 874 this.flags.reset("osize");
902 } 875 }
903 } 876 this.display();
904 877 }
905 Digilib.prototype.pixelByPixel = function(on) { 878
906 // sets clip flag 879 Digilib.prototype.getScale = function() {
907 if (on) { 880 // returns scale type
908 this.flags.set("clip"); 881 if (this.flags.get("clip")) {
909 this.display(); 882 return "pixel";
910 } 883 } else if (this.flags.get("osize")) {
911 else this.flags.reset("clip"); 884 return "original";
912 } 885 } else {
886 return "fit";
887 }
888 }
913 889
914 Digilib.prototype.pageWidth = function() { 890 Digilib.prototype.pageWidth = function() {
915 this.zoomFullpage('width'); 891 this.zoomFullpage('width');
916 } 892 }
917 893
918 Digilib.prototype.resize = function(factor) { 894 Digilib.prototype.setSize = function(factor) {
919 this.params.set("ws", factor); 895 this.params.set("ws", factor);
920 this.showSizeMenu(false);
921 this.display(); 896 this.display();
922 } 897 }
923 898
924 Digilib.prototype.showSizeMenu = function(show) { 899 Digilib.prototype.showMenu = function(menuId, buttonId, show) {
925 var menu = getElement("sizes"); 900 var menu = getElement(menuId);
926 if (show) { 901 if (show) {
927 // align menu with button 902 // align right side of menu with button
928 var buttonPos = getElementPosition(getElement("size")); 903 var buttonPos = getElementPosition(getElement(buttonId));
929 moveElement(menu, new Position(buttonPos.x - 50, buttonPos.y)); 904 var menusize = getElementSize(menu);
905 moveElement(menu, new Position(buttonPos.x - menusize.width - 3, buttonPos.y));
930 } 906 }
931 showElement(menu, show); 907 showElement(menu, show);
932 } 908 }
933 909
934 910
963 function display(detail, moDetail) {dl.display(detail, moDetail)}; 939 function display(detail, moDetail) {dl.display(detail, moDetail)};
964 function setMark(reload) {dl.setMark(reload)}; 940 function setMark(reload) {dl.setMark(reload)};
965 function removeMark(reload) {dl.removeMark(reload)}; 941 function removeMark(reload) {dl.removeMark(reload)};
966 function zoomArea() {dl.zoomArea()}; 942 function zoomArea() {dl.zoomArea()};
967 function zoomBy(factor) {dl.zoomBy(factor)}; 943 function zoomBy(factor) {dl.zoomBy(factor)};
968 function zoomFullpage() {dl.zoomFullpage()}; 944 function zoomFullpage(a) {dl.zoomFullpage(a)};
969 function moveCenter(on) {dl.moveCenter(on)}; 945 function moveCenter(on) {dl.moveCenter(on)};
970 function isFullArea(area) {dl.isFullArea(area)}; 946 function isFullArea(area) {dl.isFullArea(area)};
971 function canMove(movx, movy) {dl.canMove(movx, movy)}; 947 function canMove(movx, movy) {dl.canMove(movx, movy)};
972 function moveBy(movx, movy) {dl.moveBy(movx, movy)}; 948 function moveBy(movx, movy) {dl.moveBy(movx, movy)};
973 function getRef(baseURL) {dl.getRef(baseURL)}; 949 function getRef(baseURL) {dl.getRef(baseURL)};
981 function setParamWin(param, text, relative) {dl.setParamWin(param, text, relative)}; 957 function setParamWin(param, text, relative) {dl.setParamWin(param, text, relative)};
982 function showOptions(show) {dl.showOptions(show)}; 958 function showOptions(show) {dl.showOptions(show)};
983 function showBirdDiv(show) {dl.showBirdDiv(show)}; 959 function showBirdDiv(show) {dl.showBirdDiv(show)};
984 function showAboutDiv(show) {dl.showAboutDiv(show)}; 960 function showAboutDiv(show) {dl.showAboutDiv(show)};
985 function calibrate(direction) {dl.calibrate(direction)}; 961 function calibrate(direction) {dl.calibrate(direction)};
962 function setScale(a) {dl.setScale(a)};
963 function getScale(a) {dl.getScale(a)};
986 function originalSize(on) {dl.originalSize(on)}; 964 function originalSize(on) {dl.originalSize(on)};
987 function pixelByPixel(on) {dl.pixelByPixel(on)}; 965 function pixelByPixel(on) {dl.pixelByPixel(on)};
988 function pageWidth() {dl.pageWidth()}; 966 function pageWidth() {dl.pageWidth()};
989 function resize(factor) {dl.resize(factor)}; 967 function setSize(factor) {dl.setSize(factor)};
990 function showSizeMenu(show) {dl.showSizeMenu(show)}; 968 function showMenu(a,b,c) {dl.showMenu(a,b,c)};
991 969
992 970
993 // :tabSize=4:indentSize=4:noTabs=true: 971 // :tabSize=4:indentSize=4:noTabs=true:
994 972