blob: 11404c302bf52a5d585a727984a528084ba399cb [file] [log] [blame]
<html>
<head>
<script src="resources/repaint.js"></script>
<script language="javascript">
<!--
SVG_NS = 'http://www.w3.org/2000/svg';
function repaintTest() {
var star = document.getElementById("first-star");
setCenterPosition(star, 0, 0);
}
function pathFromStar (radius, innerRadius, sides) {
var path = [];
for (var i = 0; i < sides * 2; ++i) {
var theta = Math.PI * i / sides + (Math.PI / 2);
var r = (i % 2) ? radius : innerRadius;
var x = r * Math.cos(theta);
var y = r * Math.sin(theta);
path.push((i ? 'L' : 'M'), x, y);
}
path.push('Z');
return path.join(' ');
}
function newSvgElement (tagName, parentNode, attrs) {
var node = document.createElementNS(SVG_NS, tagName);
if (attrs) {
for (var k in attrs) {
node.setAttribute(k, attrs[k]);
}
}
if (parentNode) {
parentNode.appendChild(node);
}
return node;
}
function setCenterPosition (node, x, y) {
node.setAttribute('transform', 'translate($1, $2)'
.replace('$1', x)
.replace('$2', y));
}
var armed = null;
window.addEventListener('load', function () {
var svgContainer = newSvgElement('svg', document.body);
svgContainer.setAttribute('width','100%');
svgContainer.setAttribute('height','100%');
var shapes = [
{ pos: [ 100, 100 ], size: 60, hasStroke: false },
{ pos: [ 250, 100 ], size: 60, hasStroke: true },
{ pos: [ 400, 100 ], size: 50, hasStroke: true }
];
svgContainer.style.WebkitSvgShadow = '5px 5px 5px red';
for (var i = 0; i < shapes.length; ++i) {
var shape = shapes[i];
var node = newSvgElement('path', svgContainer, {
d: pathFromStar(shape.size, shape.size / 2, 5),
fill: '#999',
stroke: 'black',
'stroke-width': 10,
});
if (i == 0)
node.id = "first-star";
setCenterPosition(node, shape.pos[0], shape.pos[1]);
if (shapes[i].hasStroke) {
node.setAttribute('stroke-dasharray', 20);
}
node.addEventListener('mousedown', function (ev) {
var e = ev || event;
armed = { node: e.target || e.srcElement };
});
node.addEventListener('mouseup', function () {
armed = null;
});
}
window.addEventListener('mousemove', function (ev) {
if (armed) {
var e = ev || event;
setCenterPosition(armed.node, e.clientX, e.clientY);
}
});
});
//-->
</script>
</head>
<body onload="runRepaintTest();">
</body>
</html>