Mercurial > hg > digilib
comparison client/digitallibrary/greyskin/baselib.js @ 509:8652a5837432
fixed bug with double-zoom (Transform was broken for Rectangles)
author | robcast |
---|---|
date | Thu, 03 Sep 2009 13:10:00 +0200 |
parents | 23195b070d30 |
children |
comparison
equal
deleted
inserted
replaced
508:3713396e43e9 | 509:8652a5837432 |
---|---|
17 Authors: | 17 Authors: |
18 Christian Luginbuehl, 01.05.2003 (first version) | 18 Christian Luginbuehl, 01.05.2003 (first version) |
19 DW 24.03.2004 (Changed for digiLib in Zope) | 19 DW 24.03.2004 (Changed for digiLib in Zope) |
20 Robert Casties, 2.11.2004 (almost complete rewrite) | 20 Robert Casties, 2.11.2004 (almost complete rewrite) |
21 Martin Raspe, 12.12.2005 (changes for Digilib NG) | 21 Martin Raspe, 12.12.2005 (changes for Digilib NG) |
22 | 22 Robert Casties, 3.9.2009 |
23 */ | 23 */ |
24 | 24 |
25 // was: function base_init() { | 25 // was: function base_init() { |
26 baseLibVersion = "2.010"; | 26 baseLibVersion = "2.011"; |
27 browserType = getBrowserType(); | 27 browserType = getBrowserType(); |
28 | 28 |
29 sliders = {}; | 29 sliders = {}; |
30 activeSlider = null; | 30 activeSlider = null; |
31 | 31 |
299 Transform.prototype.transform = function(rect) { | 299 Transform.prototype.transform = function(rect) { |
300 // returns transformed Rectangle or Position with this Transform applied | 300 // returns transformed Rectangle or Position with this Transform applied |
301 var x = this.m00 * rect.x + this.m01 * rect.y + this.m02; | 301 var x = this.m00 * rect.x + this.m01 * rect.y + this.m02; |
302 var y = this.m10 * rect.x + this.m11 * rect.y + this.m12; | 302 var y = this.m10 * rect.x + this.m11 * rect.y + this.m12; |
303 if (rect.width) { | 303 if (rect.width) { |
304 var width = this.m00 * rect.width + this.m01 * rect.height; | 304 // transform the other corner points |
305 var height = this.m10 * rect.width + this.m11 * rect.height; | 305 var pt2 = rect.getPt2(); |
306 var x2 = this.m00 * pt2.x + this.m01 * pt2.y + this.m02; | |
307 var y2 = this.m10 * pt2.x + this.m11 * pt2.y + this.m12; | |
308 var width = x2 - x; | |
309 var height = y2 - y; | |
306 return new Rectangle(x, y, width, height); | 310 return new Rectangle(x, y, width, height); |
307 } | 311 } |
308 return new Position(x, y); | 312 return new Position(x, y); |
309 } | 313 } |
310 Transform.prototype.invtransform = function(pos) { | 314 Transform.prototype.invtransform = function(rect) { |
311 // returns transformed Position pos with the inverse of this Transform applied | 315 // returns transformed Rectangle or Position with the inverse of this Transform applied |
312 var det = this.m00 * this.m11 - this.m01 * this.m10; | 316 var det = this.m00 * this.m11 - this.m01 * this.m10; |
313 var x = (this.m11 * pos.x - this.m01 * pos.y - this.m11 * this.m02 + this.m01 * this.m12) / det; | 317 var x = (this.m11 * rect.x - this.m01 * rect.y - this.m11 * this.m02 + this.m01 * this.m12) / det; |
314 var y = (- this.m10 * pos.x + this.m00 * pos.y + this.m10 * this.m02 - this.m00 * this.m12) / det; | 318 var y = (- this.m10 * rect.x + this.m00 * rect.y + this.m10 * this.m02 - this.m00 * this.m12) / det; |
315 if (pos.width) { | 319 if (rect.width) { |
316 var width = (this.m11 * pos.width - this.m01 * pos.height - this.m11 * this.m02 + this.m01 * this.m12) / det; | 320 /* transforming width and height like points seems to be wrong |
317 var height = (- this.m10 * pos.width + this.m00 * pos.height + this.m10 * this.m02 - this.m00 * this.m12) / det; | 321 var width = (this.m11 * rect.width - this.m01 * rect.height - this.m11 * this.m02 + this.m01 * this.m12) / det; |
318 return new Rectangle(x, y, width, height); | 322 var height = (- this.m10 * rect.width + this.m00 * rect.height + this.m10 * this.m02 - this.m00 * this.m12) / det; |
319 } | 323 */ |
324 // transform the other corner points | |
325 var pt2 = rect.getPt2(); | |
326 var x2 = (this.m11 * pt2.x - this.m01 * pt2.y - this.m11 * this.m02 + this.m01 * this.m12) / det; | |
327 var y2 = (- this.m10 * pt2.x + this.m00 * pt2.y + this.m10 * this.m02 - this.m00 * this.m12) / det; | |
328 var width = x2 - x; | |
329 var height = y2 - y; | |
330 return new Rectangle(x, y, width, height); | |
331 } | |
320 return new Position(x, y); | 332 return new Position(x, y); |
321 } | 333 } |
322 function getRotation(angle, pos) { | 334 function getRotation(angle, pos) { |
323 // returns a Transform that is a rotation by angle degrees around [pos.x, pos.y] | 335 // returns a Transform that is a rotation by angle degrees around [pos.x, pos.y] |
324 var traf = new Transform(); | 336 var traf = new Transform(); |
550 var x = 0; | 562 var x = 0; |
551 var y = 0; | 563 var y = 0; |
552 if (defined(elem.offsetLeft)) { | 564 if (defined(elem.offsetLeft)) { |
553 var e = elem; | 565 var e = elem; |
554 while (e) { | 566 while (e) { |
555 if (defined(e.clientLeft)) { | 567 if (browserType.isIE) { |
556 // special for IE | |
557 if (browserType.isMac) { | 568 if (browserType.isMac) { |
558 if (e.offsetParent.tagName == "BODY") { | 569 if (e.offsetParent.tagName == "BODY") { |
559 // IE for Mac extraspecial | 570 // IE for Mac extraspecial |
560 x += e.clientLeft; | 571 x += e.clientLeft; |
561 y += e.clientTop; | 572 y += e.clientTop; |
571 x += e.offsetLeft; | 582 x += e.offsetLeft; |
572 y += e.offsetTop; | 583 y += e.offsetTop; |
573 e = e.offsetParent; | 584 e = e.offsetParent; |
574 } | 585 } |
575 } else if (defined(elem.x)) { | 586 } else if (defined(elem.x)) { |
587 // use .x for other (which?) | |
576 x = elem.x; | 588 x = elem.x; |
577 y = elem.y; | 589 y = elem.y; |
578 } else if (defined(elem.pageX)) { | 590 } else if (defined(elem.pageX)) { |
591 // use pageX for N4 | |
579 x = elem.pageX; | 592 x = elem.pageX; |
580 y = elem.pageY; | 593 y = elem.pageY; |
581 } else { | 594 } else { |
582 alert("unable to get position of " + elem + " (id:" + elem.id + ")"); | 595 alert("unable to get position of " + elem + " (id:" + elem.id + ")"); |
583 } | 596 } |
756 // returns a Size with the current window size (mostly from www.quirksmode.org) | 769 // returns a Size with the current window size (mostly from www.quirksmode.org) |
757 var wsize = new Size(100, 100); | 770 var wsize = new Size(100, 100); |
758 if (defined(self.innerHeight)) { | 771 if (defined(self.innerHeight)) { |
759 // all except Explorer | 772 // all except Explorer |
760 if ((self.innerWidth == 0)||(self.innerHeight == 0)) { | 773 if ((self.innerWidth == 0)||(self.innerHeight == 0)) { |
761 // Safari 1.2 bug | 774 // Safari 1.2 (and other) bug |
762 if (parent) { | 775 if (parent) { |
763 parent.innerHeight; | 776 wsize.height = parent.innerHeight; |
764 parent.innerWidth; | 777 wsize.width = parent.innerWidth; |
765 } | 778 } |
766 } | 779 } else { |
767 wsize.width = self.innerWidth; | 780 wsize.width = self.innerWidth; |
768 wsize.height = self.innerHeight; | 781 wsize.height = self.innerHeight; |
782 } | |
769 } else if (document.documentElement && document.documentElement.clientHeight) { | 783 } else if (document.documentElement && document.documentElement.clientHeight) { |
770 // Explorer 6 Strict Mode | 784 // Explorer 6 Strict Mode |
771 wsize.width = document.documentElement.clientWidth; | 785 wsize.width = document.documentElement.clientWidth; |
772 wsize.height = document.documentElement.clientHeight; | 786 wsize.height = document.documentElement.clientHeight; |
773 } else if (document.body) { | 787 } else if (document.body) { |