changeset 675:ca37fb4b1e72 jquery

transformation with mirror works now too!
author robcast
date Tue, 25 Jan 2011 22:04:27 +0100
parents 6ca57779e740
children d1605eb99d74
files client/digitallibrary/jquery/dlGeometry.js client/digitallibrary/jquery/jquery.digilib.js
diffstat 2 files changed, 47 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/client/digitallibrary/jquery/dlGeometry.js	Tue Jan 25 17:50:27 2011 +0100
+++ b/client/digitallibrary/jquery/dlGeometry.js	Tue Jan 25 22:04:27 2011 +0100
@@ -304,6 +304,7 @@
             that.getRotation = transform.getRotation;
             that.getRotationAround = transform.getRotationAround;
             that.getTranslation = transform.getTranslation;
+            that.getMirror = transform.getMirror;
             that.getScale = transform.getScale;
 
             return that;
@@ -326,6 +327,14 @@
            return transform();
        };
 
+       transform.getRotationAround = function (angle, pos) {
+           // returns a Transform that is a rotation by angle degrees around pos
+           var traf = transform.getTranslation({x : -pos.x, y : -pos.y});
+           traf.concat(transform.getRotation(angle));
+           traf.concat(transform.getTranslation(pos));
+           return traf;
+       };
+       
        transform.getTranslation = function (pos) {
            // returns a Transform that is a translation by [pos.x, pos,y]
            var traf = {
@@ -335,14 +344,22 @@
            return transform(traf);
        };
 
-       transform.getRotationAround = function (angle, pos) {
-           // returns a Transform that is a rotation by angle degrees around pos
-           var traf = transform.getTranslation({x : -pos.x, y : -pos.y});
-           traf.concat(transform.getRotation(angle));
-           traf.concat(transform.getTranslation(pos));
-           return traf;
+       transform.getMirror = function (type) {
+           // returns a Transform that is a mirror about the axis type
+           if (type === 'x') {
+               var traf = {
+                       m00 : 1,
+                       m11 : -1
+               };
+           } else {
+               var traf = {
+                       m00 : -1,
+                       m11 : 1
+               };
+           }
+           return transform(traf);
        };
-       
+
        transform.getScale = function (size) {
            // returns a Transform that is a scale by [size.width, size.height]
            var traf = {
--- a/client/digitallibrary/jquery/jquery.digilib.js	Tue Jan 25 17:50:27 2011 +0100
+++ b/client/digitallibrary/jquery/jquery.digilib.js	Tue Jan 25 22:04:27 2011 +0100
@@ -786,18 +786,31 @@
     };
 
     // create Transform from area and $img
-    var getImgTrafo = function ($img, area, data) {
+    var getImgTrafo = function ($img, area, rot, hmir, vmir) {
         var picrect = geom.rectangle($img);
         var trafo = geom.transform();
-        // zoom area offset
+        // move zoom area offset to center
         trafo.concat(trafo.getTranslation(geom.position(-area.x, -area.y)));
-        // zoom area size
+        // scale zoom area size to [1,1]
         trafo.concat(trafo.getScale(geom.size(1/area.width, 1/area.height)));
-        // rotate (around transformed image center i.e. [0.5,0.5])
-        if (data) {
-            var rot = trafo.getRotationAround(parseFloat(data.settings.rot), 
-                    geom.position(0.5, 0.5));
-            trafo.concat(rot);
+        // rotate and mirror (around transformed image center i.e. [0.5,0.5])
+        if (rot || hmir || vmir) {
+            // move [0.5,0.5] to center
+            trafo.concat(trafo.getTranslation(geom.position(-0.5, -0.5)));
+            if (hmir) {
+                // mirror about center
+                trafo.concat(trafo.getMirror('y'));
+            }
+            if (vmir) {
+                // mirror about center
+                trafo.concat(trafo.getMirror('x'));
+            }
+            if (rot) {
+                // rotate around center
+                trafo.concat(trafo.getRotation(parseFloat(rot)));
+            }
+            // move back
+            trafo.concat(trafo.getTranslation(geom.position(0.5, 0.5)));
         }
         // scale to screen position and size
         trafo.concat(trafo.getScale(picrect));
@@ -811,7 +824,8 @@
         return function () {
             console.debug("img loaded! this=", this, " data=", data);
             // create Transform from current area and picsize
-            data.imgTrafo = getImgTrafo($img, data.zoomArea, data);
+            data.imgTrafo = getImgTrafo($img, data.zoomArea,
+                    data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir);
             // display marks
             renderMarks(data);
             //digilib.showArrows(); // show arrow overlays for zoom navigation