| 1 |
<?xml version="1.0" standalone="no"?> |
| 2 |
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" |
| 3 |
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> |
| 4 |
|
| 5 |
|
| 6 |
<!-- |
| 7 |
|
| 8 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 9 |
contributor license agreements. See the NOTICE file distributed with |
| 10 |
this work for additional information regarding copyright ownership. |
| 11 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 12 |
(the "License"); you may not use this file except in compliance with |
| 13 |
the License. You may obtain a copy of the License at |
| 14 |
|
| 15 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 16 |
|
| 17 |
Unless required by applicable law or agreed to in writing, software |
| 18 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 19 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 |
See the License for the specific language governing permissions and |
| 21 |
limitations under the License. |
| 22 |
|
| 23 |
--> |
| 24 |
<svg width="655" height="600" viewBox="0 0 655 600" |
| 25 |
xmlns="http://www.w3.org/2000/svg" |
| 26 |
xmlns:xlink="http://www.w3.org/1999/xlink" > |
| 27 |
|
| 28 |
<script type="text/ecmascript"> |
| 29 |
<![CDATA[ |
| 30 |
var svgns = "http://www.w3.org/2000/svg"; |
| 31 |
var xlinkns = "http://www.w3.org/1999/xlink"; |
| 32 |
|
| 33 |
var SCALE="scale"; |
| 34 |
var DRAG="drag"; |
| 35 |
|
| 36 |
var action, actionNode, actionTgt; |
| 37 |
var dx, dy; |
| 38 |
var imgGroup = document.getElementById("imgGroup") |
| 39 |
var filter = imgGroup.getAttribute("style"); |
| 40 |
var dragged=false; |
| 41 |
|
| 42 |
function dragOn(evt) { |
| 43 |
actionNode = evt.target; |
| 44 |
action = DRAG; |
| 45 |
var currX = parseFloat(actionNode.getAttribute("x")); |
| 46 |
var currY = parseFloat(actionNode.getAttribute("y")); |
| 47 |
var nowToX = evt.clientX; |
| 48 |
var nowToY = evt.clientY; |
| 49 |
|
| 50 |
// handle the current zoom and pan |
| 51 |
var trans = document.documentElement.currentTranslate; |
| 52 |
var scale = document.documentElement.currentScale; |
| 53 |
nowToX = (nowToX - trans.x) / scale; |
| 54 |
nowToY = (nowToY - trans.y) / scale; |
| 55 |
|
| 56 |
dx = nowToX-currX; |
| 57 |
dy = nowToY-currY; |
| 58 |
dragged=false; |
| 59 |
} |
| 60 |
|
| 61 |
function scaleOn(evt) { |
| 62 |
actionNode = actionTgt; |
| 63 |
action = SCALE; |
| 64 |
var cW = parseFloat(actionNode.getAttribute("width")); |
| 65 |
var cH = parseFloat(actionNode.getAttribute("height")); |
| 66 |
var nowToX = evt.clientX; |
| 67 |
var nowToY = evt.clientY; |
| 68 |
|
| 69 |
// handle the current zoom and pan |
| 70 |
var trans = document.documentElement.currentTranslate; |
| 71 |
var scale = document.documentElement.currentScale; |
| 72 |
nowToX = (nowToX - trans.x) / scale; |
| 73 |
nowToY = (nowToY - trans.y) / scale; |
| 74 |
|
| 75 |
dx = nowToX-cW; |
| 76 |
dy = nowToY-cH; |
| 77 |
dragged=false; |
| 78 |
} |
| 79 |
|
| 80 |
function dragScaleOff() { |
| 81 |
if (dragged) imgGroup.setAttribute("style",filter); |
| 82 |
|
| 83 |
if (actionNode != null) { |
| 84 |
if (actionNode != imgGroup.lastChild) { |
| 85 |
imgGroup.appendChild(actionNode); |
| 86 |
} |
| 87 |
actionNode = null; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
function dragScaleImgBg(evt) { |
| 92 |
if (actionNode == null) { |
| 93 |
hideOverlay(); |
| 94 |
return; |
| 95 |
} |
| 96 |
dragScaleImg(evt); |
| 97 |
} |
| 98 |
|
| 99 |
function dragScaleImg(evt) { |
| 100 |
if (actionNode == null) return; |
| 101 |
|
| 102 |
dragged = true; |
| 103 |
imgGroup.setAttribute("style",""); |
| 104 |
if (actionNode != imgGroup.lastChild) |
| 105 |
imgGroup.appendChild(actionNode); |
| 106 |
|
| 107 |
var nowToX = evt.clientX; |
| 108 |
var nowToY = evt.clientY; |
| 109 |
|
| 110 |
// handle the current zoom and pan |
| 111 |
var trans = document.documentElement.currentTranslate; |
| 112 |
var scale = document.documentElement.currentScale; |
| 113 |
nowToX = (nowToX - trans.x) / scale; |
| 114 |
nowToY = (nowToY - trans.y) / scale; |
| 115 |
|
| 116 |
if (action == DRAG) { |
| 117 |
actionNode.setAttribute("x",""+(nowToX-dx)); |
| 118 |
actionNode.setAttribute("y",""+(nowToY-dy)); |
| 119 |
} else { |
| 120 |
var cW = parseFloat(actionNode.getAttribute("width")); |
| 121 |
var cH = parseFloat(actionNode.getAttribute("height")); |
| 122 |
|
| 123 |
var ar = cW/cH; |
| 124 |
var nW = nowToX-dx; |
| 125 |
var nH = nowToY-dy; |
| 126 |
|
| 127 |
if (nW/nH < ar) { nW = ar*nH; } |
| 128 |
else { nH = nW/ar; } |
| 129 |
|
| 130 |
actionNode.setAttribute("width", ""+nW); |
| 131 |
actionNode.setAttribute("height",""+nH); |
| 132 |
} |
| 133 |
|
| 134 |
updateOverlay(actionNode); |
| 135 |
} |
| 136 |
|
| 137 |
function updateOverlay(tgt) { |
| 138 |
var cX = parseFloat(tgt.getAttribute("x")); |
| 139 |
var cY = parseFloat(tgt.getAttribute("y")); |
| 140 |
var cW = parseFloat(tgt.getAttribute("width")); |
| 141 |
var cH = parseFloat(tgt.getAttribute("height")); |
| 142 |
|
| 143 |
var over = document.getElementById("overlay"); |
| 144 |
over.setAttribute("transform","translate("+(cX+cW-1)+","+(cY+cH-1)+")"); |
| 145 |
actionTgt = tgt; |
| 146 |
} |
| 147 |
|
| 148 |
function showOverlay(evt) { |
| 149 |
if (actionNode != null) return; |
| 150 |
updateOverlay(evt.target); |
| 151 |
document.getElementById("overlay").setAttribute("visibility","visible"); |
| 152 |
} |
| 153 |
|
| 154 |
function hideOverlay() { |
| 155 |
if (actionNode != null) return; |
| 156 |
document.getElementById("overlay").setAttribute("visibility","hidden"); |
| 157 |
actionTgt=null; |
| 158 |
} |
| 159 |
]]></script> |
| 160 |
|
| 161 |
<filter id="merge" filterUnits="objectBoundingBox" > |
| 162 |
<feMorphology operator="dilate" radius="10" in="SourceAlpha" /> |
| 163 |
<feGaussianBlur stdDeviation="4" /> |
| 164 |
<feOffset dx="3" dy="3"/> |
| 165 |
<feComponentTransfer result="shadow"> |
| 166 |
<feFuncA type="linear" slope=".6" intercept="0" /> |
| 167 |
</feComponentTransfer> |
| 168 |
<feComposite operator="over" in="SourceGraphic" in2="shadow"/> |
| 169 |
</filter> |
| 170 |
|
| 171 |
<rect fill="#88A" x="0%" y="0%" width="100%" height="100%"/> |
| 172 |
<text x="302" y="47" font-size="24" fill="#448" |
| 173 |
>Click and drag to move images</text> |
| 174 |
<text x="300" y="45" font-size="24" fill="white" |
| 175 |
>Click and drag to move images</text> |
| 176 |
<rect fill="none" x="0%" y="0%" width="100%" height="100%" |
| 177 |
pointer-events="fill" |
| 178 |
onmousedown="dragScaleOff()" |
| 179 |
onmouseup="dragScaleOff()" |
| 180 |
onmousemove="dragScaleImgBg(evt)"/> |
| 181 |
|
| 182 |
<g id="imgGroup" style="filter:url(#merge)" |
| 183 |
onmousedown="dragOn(evt)" |
| 184 |
onmouseup="dragScaleOff()" |
| 185 |
onmousemove="dragScaleImg(evt)" |
| 186 |
onmouseover="showOverlay(evt)"> |
| 187 |
|
| 188 |
<image x="25" y="315" width="360" height="240" |
| 189 |
xlink:href="tests/resources/images/operaSteps.jpg"/> |
| 190 |
|
| 191 |
<image x="50" y="40" width="200" height="300" |
| 192 |
xlink:href="tests/resources/images/operaWalk.jpg"/> |
| 193 |
|
| 194 |
<image x="270" y="200" width="360" height="240" |
| 195 |
xlink:href="tests/resources/images/operaBridge.jpg"/> |
| 196 |
</g> |
| 197 |
|
| 198 |
<g id="overlay" visibility="hidden" |
| 199 |
onmousedown="scaleOn(evt)" |
| 200 |
onmouseup="dragScaleOff()" |
| 201 |
onmousemove="dragScaleImg(evt)"> |
| 202 |
<path fill="darkgrey" stroke="white" |
| 203 |
d="M0,0 h-20 l20,-20 z M-12,-3 l9-9 z M-6,-3 l3-3z"/> |
| 204 |
</g> |
| 205 |
|
| 206 |
</svg> |