1 /***************************************************************************
2 * Copyright (C) 2011 by Lukáš Karas <lukas.karas@centrum.cz> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
20 Thumbnail
.prototype = SvgCanvas
.prototype.clone();
22 Thumbnail
.prototype.constructor = Thumbnail
;
24 function Thumbnail(canvasWrapper
, canvasWidth
, canvasHeight
, showOutsideCanvas
, callback
){
25 // call super constructor
26 SvgCanvas
.apply(this, arguments
);
29 this.viewportCenter
= {
30 x
: (this.canvasWidth
/ 2),
31 y
: (this.canvasHeight
/ 2)
34 // add viewport svg elem
35 this.viewport
= this.svgdoc
.createElementNS(this.svgns
, "svg");
36 $(this.viewport
).attr({
37 id
: this.idPrefix
+'viewport',
38 width
: this.canvasWidth
,
39 height
: this.canvasHeight
,
44 'viewBox': '0 0 '+this.canvasWidth
+' '+this.canvasHeight
+'',
45 //"xmlns:se": this.se_ns,
46 "xlinkns": this.xlinkns
47 }).appendTo(this.svgroot
);
49 this.viewportRect
= this.addSvgElementFromJson({
52 "id": (this.idPrefix
+"viewportRect" ),
53 "fill": "rgba(255, 255, 255, 0)",
54 "width": this.canvasWidth
,
55 "height": this.canvasHeight
,
60 "style": "cursor: hand;"
63 $( this.viewport
).append( this.viewportRect
);
65 // fit to wrapper (only width)
66 var z
= this.canvasWrapper
.width() / (this.canvasWidth
*1.5);
68 this.registerViewportCallback(callback
);
72 * ...for register callback interface for listen of viewport changes from user
73 * it can be registered only once
75 Thumbnail
.prototype.registerViewportCallback = function(callback
){
76 if (this.viewportCallback
)
78 this.viewportCallback
= callback
;
81 // $( this.canvasWrapper ).mousedown(function(e){inst.wrapperMouseDown(e)});
82 $( this.canvasWrapper
).mousedown(function(e
){inst
.mouseDown(e
)});
83 $( window
).mouseup(function(e
){inst
.mouseUp(e
)})
84 .mousemove(function(e
){inst
.mouseMove(e
)});
87 Thumbnail
.prototype.mouseDown = function(e
){
88 this.mouseIsDown
= true;
90 if (e
.target
.id
!= this.viewportRect
.id
){
91 console
.log("thumbnail click out of viewport...");
92 var xc
= ((this.canvasWrapper
.scrollLeft() / this.zoom
) - this.canvasWidth
) + ((e
.clientX
- this.canvasWrapper
.offset().left
) / this.zoom
);
93 var yc
= ((this.canvasWrapper
.scrollTop() / this.zoom
) - this.canvasHeight
) + ((e
.clientY
- this.canvasWrapper
.offset().top
) / this.zoom
);
94 this.viewportCenter
.x
= xc
;
95 this.viewportCenter
.y
= yc
;
96 this.viewportCallback
.showInCenter( xc
, yc
);
102 viewportCenterX
: this.viewportCenter
.x
,
103 viewportCenterY
: this.viewportCenter
.y
108 Thumbnail
.prototype.mouseUp = function(e
){
109 this.mouseIsDown
= false;
113 Thumbnail
.prototype.mouseMove = function(e
){
114 if (this.mouseIsDown
){
115 var dx
= (e
.clientX
- this.mouseStart
.clientX
) / this.zoom
;
116 var dy
= (e
.clientY
- this.mouseStart
.clientY
) / this.zoom
;
117 // console.log("viewport moved "+dx+"x"+dy);
118 this.viewportCallback
.showInCenter( this.mouseStart
.viewportCenterX
+ dx
, this.mouseStart
.viewportCenterY
+ dy
);
122 Thumbnail
.prototype.viewportChanged = function(x
,y
,w
,h
){
123 this.viewportCenter
= {
127 $( this.viewportRect
).attr({