change dir layout
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@31 eee81c28-f429-11dd-99c0-75d572ba1ddd
50
editor/farbtastic.css
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Farbtastic Color Picker 1.2
|
||||
* © 2008 Steven Wittens
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
.farbtastic {
|
||||
position: relative;
|
||||
}
|
||||
.farbtastic * {
|
||||
position: absolute;
|
||||
cursor: crosshair;
|
||||
}
|
||||
.farbtastic, .farbtastic .wheel {
|
||||
width: 195px;
|
||||
height: 195px;
|
||||
}
|
||||
.farbtastic .color, .farbtastic .overlay {
|
||||
top: 47px;
|
||||
left: 47px;
|
||||
width: 101px;
|
||||
height: 101px;
|
||||
}
|
||||
.farbtastic .wheel {
|
||||
background: url('images/wheel.png') no-repeat;
|
||||
width: 195px;
|
||||
height: 195px;
|
||||
}
|
||||
.farbtastic .overlay {
|
||||
background: url('images/mask.png') no-repeat;
|
||||
}
|
||||
.farbtastic .marker {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
margin: -8px 0 0 -8px;
|
||||
overflow: hidden;
|
||||
background: url('images/marker.png') no-repeat;
|
||||
}
|
||||
348
editor/farbtastic.js
Normal file
@@ -0,0 +1,348 @@
|
||||
/**
|
||||
* Farbtastic Color Picker 1.2
|
||||
* © 2008 Steven Wittens
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
jQuery.fn.farbtastic = function (callback) {
|
||||
$.farbtastic(this, callback);
|
||||
return this;
|
||||
};
|
||||
|
||||
jQuery.farbtastic = function (container, callback) {
|
||||
var container = $(container).get(0);
|
||||
return container.farbtastic || (container.farbtastic = new jQuery._farbtastic(container, callback));
|
||||
}
|
||||
|
||||
jQuery._farbtastic = function (container, callback) {
|
||||
// Store farbtastic object
|
||||
var fb = this;
|
||||
|
||||
// Insert markup
|
||||
$(container).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>');
|
||||
var e = $('.farbtastic', container);
|
||||
fb.wheel = $('.wheel', container).get(0);
|
||||
// Dimensions
|
||||
fb.radius = 84;
|
||||
fb.square = 100;
|
||||
fb.width = 194;
|
||||
|
||||
// Fix background PNGs in IE6
|
||||
if (navigator.appVersion.match(/MSIE [0-6]\./)) {
|
||||
$('*', e).each(function () {
|
||||
if (this.currentStyle.backgroundImage != 'none') {
|
||||
var image = this.currentStyle.backgroundImage;
|
||||
image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
|
||||
$(this).css({
|
||||
'backgroundImage': 'none',
|
||||
'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the given element(s) or callback.
|
||||
*/
|
||||
fb.linkTo = function (callback) {
|
||||
// Unbind previous nodes
|
||||
if (typeof fb.callback == 'object') {
|
||||
$(fb.callback).unbind('keyup', fb.updateValue);
|
||||
}
|
||||
|
||||
// Reset color
|
||||
fb.color = null;
|
||||
|
||||
// Bind callback or elements
|
||||
if (typeof callback == 'function') {
|
||||
fb.callback = callback;
|
||||
}
|
||||
else if (typeof callback == 'object' || typeof callback == 'string') {
|
||||
fb.callback = $(callback);
|
||||
fb.callback.bind('keyup', fb.updateValue);
|
||||
if (fb.callback.get(0).value) {
|
||||
fb.setColor(fb.callback.get(0).value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
fb.updateValue = function (event) {
|
||||
if (this.value && this.value != fb.color) {
|
||||
fb.setColor(this.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change color with HTML syntax #123456
|
||||
*/
|
||||
fb.setColor = function (color) {
|
||||
var unpack = fb.unpack(color);
|
||||
if (fb.color != color && unpack) {
|
||||
fb.rgb = unpack;
|
||||
fb.color = fb.pack(unpack);
|
||||
fb.hsl = fb.RGBToHSL(fb.rgb);
|
||||
fb.updateDisplay();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change color with HSL triplet [0..1, 0..1, 0..1]
|
||||
*/
|
||||
fb.setHSL = function (hsl) {
|
||||
fb.hsl = hsl;
|
||||
fb.rgb = fb.HSLToRGB(hsl);
|
||||
fb.color = fb.pack(fb.rgb);
|
||||
fb.updateDisplay();
|
||||
return this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Retrieve the coordinates of the given event relative to the center
|
||||
* of the widget.
|
||||
*/
|
||||
fb.widgetCoords = function (event) {
|
||||
var x, y;
|
||||
var el = event.target || event.srcElement;
|
||||
var reference = fb.wheel;
|
||||
|
||||
if (typeof event.offsetX != 'undefined') {
|
||||
// Use offset coordinates and find common offsetParent
|
||||
var pos = { x: event.offsetX, y: event.offsetY };
|
||||
|
||||
// Send the coordinates upwards through the offsetParent chain.
|
||||
var e = el;
|
||||
while (e) {
|
||||
e.mouseX = pos.x;
|
||||
e.mouseY = pos.y;
|
||||
pos.x += e.offsetLeft;
|
||||
pos.y += e.offsetTop;
|
||||
e = e.offsetParent;
|
||||
}
|
||||
|
||||
// Look for the coordinates starting from the wheel widget.
|
||||
var e = reference;
|
||||
var offset = { x: 0, y: 0 }
|
||||
while (e) {
|
||||
if (typeof e.mouseX != 'undefined') {
|
||||
x = e.mouseX - offset.x;
|
||||
y = e.mouseY - offset.y;
|
||||
break;
|
||||
}
|
||||
offset.x += e.offsetLeft;
|
||||
offset.y += e.offsetTop;
|
||||
e = e.offsetParent;
|
||||
}
|
||||
|
||||
// Reset stored coordinates
|
||||
e = el;
|
||||
while (e) {
|
||||
e.mouseX = undefined;
|
||||
e.mouseY = undefined;
|
||||
e = e.offsetParent;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Use absolute coordinates
|
||||
var pos = fb.absolutePosition(reference);
|
||||
x = (event.pageX || 0*(event.clientX + $('html').get(0).scrollLeft)) - pos.x;
|
||||
y = (event.pageY || 0*(event.clientY + $('html').get(0).scrollTop)) - pos.y;
|
||||
}
|
||||
// Subtract distance to middle
|
||||
return { x: x - fb.width / 2, y: y - fb.width / 2 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Mousedown handler
|
||||
*/
|
||||
fb.mousedown = function (event) {
|
||||
// Capture mouse
|
||||
if (!document.dragging) {
|
||||
$(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup);
|
||||
document.dragging = true;
|
||||
}
|
||||
|
||||
// Check which area is being dragged
|
||||
var pos = fb.widgetCoords(event);
|
||||
fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square;
|
||||
|
||||
// Process
|
||||
fb.mousemove(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mousemove handler
|
||||
*/
|
||||
fb.mousemove = function (event) {
|
||||
// Get coordinates relative to color picker center
|
||||
var pos = fb.widgetCoords(event);
|
||||
|
||||
// Set new HSL parameters
|
||||
if (fb.circleDrag) {
|
||||
var hue = Math.atan2(pos.x, -pos.y) / 6.28;
|
||||
if (hue < 0) hue += 1;
|
||||
fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]);
|
||||
}
|
||||
else {
|
||||
var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5));
|
||||
var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5));
|
||||
fb.setHSL([fb.hsl[0], sat, lum]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouseup handler
|
||||
*/
|
||||
fb.mouseup = function () {
|
||||
// Uncapture mouse
|
||||
$(document).unbind('mousemove', fb.mousemove);
|
||||
$(document).unbind('mouseup', fb.mouseup);
|
||||
document.dragging = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the markers and styles
|
||||
*/
|
||||
fb.updateDisplay = function () {
|
||||
// Markers
|
||||
var angle = fb.hsl[0] * 6.28;
|
||||
$('.h-marker', e).css({
|
||||
left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px',
|
||||
top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px'
|
||||
});
|
||||
|
||||
$('.sl-marker', e).css({
|
||||
left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px',
|
||||
top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px'
|
||||
});
|
||||
|
||||
// Saturation/Luminance gradient
|
||||
$('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5])));
|
||||
|
||||
// Linked elements or callback
|
||||
if (typeof fb.callback == 'object') {
|
||||
// Set background/foreground color
|
||||
$(fb.callback).css({
|
||||
backgroundColor: fb.color,
|
||||
color: fb.hsl[2] > 0.5 ? '#000' : '#fff'
|
||||
});
|
||||
|
||||
// Change linked value
|
||||
$(fb.callback).each(function() {
|
||||
if (this.value && this.value != fb.color) {
|
||||
this.value = fb.color;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (typeof fb.callback == 'function') {
|
||||
fb.callback.call(fb, fb.color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get absolute position of element
|
||||
*/
|
||||
fb.absolutePosition = function (el) {
|
||||
var r = { x: el.offsetLeft, y: el.offsetTop };
|
||||
// Resolve relative to offsetParent
|
||||
if (el.offsetParent) {
|
||||
var tmp = fb.absolutePosition(el.offsetParent);
|
||||
r.x += tmp.x;
|
||||
r.y += tmp.y;
|
||||
}
|
||||
return r;
|
||||
};
|
||||
|
||||
/* Various color utility functions */
|
||||
fb.pack = function (rgb) {
|
||||
var r = Math.round(rgb[0] * 255);
|
||||
var g = Math.round(rgb[1] * 255);
|
||||
var b = Math.round(rgb[2] * 255);
|
||||
return '#' + (r < 16 ? '0' : '') + r.toString(16) +
|
||||
(g < 16 ? '0' : '') + g.toString(16) +
|
||||
(b < 16 ? '0' : '') + b.toString(16);
|
||||
}
|
||||
|
||||
fb.unpack = function (color) {
|
||||
if (color.length == 7) {
|
||||
return [parseInt('0x' + color.substring(1, 3)) / 255,
|
||||
parseInt('0x' + color.substring(3, 5)) / 255,
|
||||
parseInt('0x' + color.substring(5, 7)) / 255];
|
||||
}
|
||||
else if (color.length == 4) {
|
||||
return [parseInt('0x' + color.substring(1, 2)) / 15,
|
||||
parseInt('0x' + color.substring(2, 3)) / 15,
|
||||
parseInt('0x' + color.substring(3, 4)) / 15];
|
||||
} else if (color.substring(0,4) == 'rgb(') {
|
||||
color = color.substring(4, color.length-1).split(',');
|
||||
return [ parseInt(color[0])/255, parseInt(color[1])/255, parseInt(color[2])/255 ];
|
||||
}
|
||||
}
|
||||
|
||||
fb.HSLToRGB = function (hsl) {
|
||||
var m1, m2, r, g, b;
|
||||
var h = hsl[0], s = hsl[1], l = hsl[2];
|
||||
m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s;
|
||||
m1 = l * 2 - m2;
|
||||
return [this.hueToRGB(m1, m2, h+0.33333),
|
||||
this.hueToRGB(m1, m2, h),
|
||||
this.hueToRGB(m1, m2, h-0.33333)];
|
||||
}
|
||||
|
||||
fb.hueToRGB = function (m1, m2, h) {
|
||||
h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
|
||||
if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
|
||||
if (h * 2 < 1) return m2;
|
||||
if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
|
||||
return m1;
|
||||
}
|
||||
|
||||
fb.RGBToHSL = function (rgb) {
|
||||
var min, max, delta, h, s, l;
|
||||
var r = rgb[0], g = rgb[1], b = rgb[2];
|
||||
min = Math.min(r, Math.min(g, b));
|
||||
max = Math.max(r, Math.max(g, b));
|
||||
delta = max - min;
|
||||
l = (min + max) / 2;
|
||||
s = 0;
|
||||
if (l > 0 && l < 1) {
|
||||
s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
|
||||
}
|
||||
h = 0;
|
||||
if (delta > 0) {
|
||||
if (max == r && max != g) h += (g - b) / delta;
|
||||
if (max == g && max != b) h += (2 + (b - r) / delta);
|
||||
if (max == b && max != r) h += (4 + (r - g) / delta);
|
||||
h /= 6;
|
||||
}
|
||||
return [h, s, l];
|
||||
}
|
||||
|
||||
// Install mousedown handler (the others are set on the document on-demand)
|
||||
$('*', e).mousedown(fb.mousedown);
|
||||
|
||||
// Init color
|
||||
fb.setColor('#000000');
|
||||
|
||||
// Set linked elements/callback
|
||||
if (callback) {
|
||||
fb.linkTo(callback);
|
||||
}
|
||||
}
|
||||
BIN
editor/images/circle.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
editor/images/clear.png
Normal file
|
After Width: | Height: | Size: 812 B |
BIN
editor/images/delete.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
editor/images/ellipse.png
Normal file
|
After Width: | Height: | Size: 811 B |
BIN
editor/images/line.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
editor/images/marker.png
Normal file
|
After Width: | Height: | Size: 652 B |
BIN
editor/images/mask.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
editor/images/none.png
Normal file
|
After Width: | Height: | Size: 136 B |
BIN
editor/images/path.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
editor/images/rect.png
Normal file
|
After Width: | Height: | Size: 404 B |
BIN
editor/images/select.png
Normal file
|
After Width: | Height: | Size: 712 B |
BIN
editor/images/square.png
Normal file
|
After Width: | Height: | Size: 422 B |
BIN
editor/images/submit.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
editor/images/wheel.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
19
editor/jquery.js
vendored
Normal file
116
editor/jquery.rightClick.js
Normal file
@@ -0,0 +1,116 @@
|
||||
// jQuery Right-Click Plugin
|
||||
//
|
||||
// Version 1.01
|
||||
//
|
||||
// Cory S.N. LaViska
|
||||
// A Beautiful Site (http://abeautifulsite.net/)
|
||||
// 20 December 2008
|
||||
//
|
||||
// Visit http://abeautifulsite.net/notebook/68 for more information
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// // Capture right click
|
||||
// $("#selector").rightClick( function(e) {
|
||||
// // Do something
|
||||
// });
|
||||
//
|
||||
// // Capture right mouse down
|
||||
// $("#selector").rightMouseDown( function(e) {
|
||||
// // Do something
|
||||
// });
|
||||
//
|
||||
// // Capture right mouseup
|
||||
// $("#selector").rightMouseUp( function(e) {
|
||||
// // Do something
|
||||
// });
|
||||
//
|
||||
// // Disable context menu on an element
|
||||
// $("#selector").noContext();
|
||||
//
|
||||
// History:
|
||||
//
|
||||
// 1.01 - Updated (20 December 2008)
|
||||
// - References to 'this' now work the same way as other jQuery plugins, thus
|
||||
// the el parameter has been deprecated. Use this or $(this) instead
|
||||
// - The mouse event is now passed to the callback function
|
||||
// - Changed license to GNU GPL
|
||||
//
|
||||
// 1.00 - Released (13 May 2008)
|
||||
//
|
||||
// License:
|
||||
//
|
||||
// This plugin is dual-licensed under the GNU General Public License and the MIT License
|
||||
// and is copyright 2008 A Beautiful Site, LLC.
|
||||
//
|
||||
if(jQuery) (function(){
|
||||
|
||||
$.extend($.fn, {
|
||||
|
||||
rightClick: function(handler) {
|
||||
$(this).each( function() {
|
||||
$(this).mousedown( function(e) {
|
||||
var evt = e;
|
||||
$(this).mouseup( function() {
|
||||
$(this).unbind('mouseup');
|
||||
if( evt.button == 2 ) {
|
||||
handler.call( $(this), evt );
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
$(this)[0].oncontextmenu = function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return $(this);
|
||||
},
|
||||
|
||||
rightMouseDown: function(handler) {
|
||||
$(this).each( function() {
|
||||
$(this).mousedown( function(e) {
|
||||
if( e.button == 2 ) {
|
||||
handler.call( $(this), e );
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
$(this)[0].oncontextmenu = function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return $(this);
|
||||
},
|
||||
|
||||
rightMouseUp: function(handler) {
|
||||
$(this).each( function() {
|
||||
$(this).mouseup( function(e) {
|
||||
if( e.button == 2 ) {
|
||||
handler.call( $(this), e );
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
$(this)[0].oncontextmenu = function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return $(this);
|
||||
},
|
||||
|
||||
noContext: function() {
|
||||
$(this).each( function() {
|
||||
$(this)[0].oncontextmenu = function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return $(this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
168
editor/svg-editor.css
Normal file
@@ -0,0 +1,168 @@
|
||||
#svg_editor {
|
||||
font-size: 8pt;
|
||||
font-family: Verdana, Helvetica, Arial;
|
||||
}
|
||||
|
||||
#svg_editor hr {
|
||||
border: none;
|
||||
border-bottom: 1px solid #808080;
|
||||
}
|
||||
|
||||
#svg_editor select {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
#svg_editor .svgcanvas {
|
||||
width: 640px;
|
||||
height: 480px;
|
||||
border: 1px solid #808080;
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
#svg_editor #svgcanvas {
|
||||
width: 642px;
|
||||
height: 482px;
|
||||
}
|
||||
|
||||
#svg_editor div#palette_holder {
|
||||
border: 1px solid #808080;
|
||||
border-top: none;
|
||||
border-left: none;
|
||||
float: left;
|
||||
width: 640px;
|
||||
overflow-x: scroll;
|
||||
overflow-y: hidden;
|
||||
height: 31px;
|
||||
}
|
||||
|
||||
#fill_color, #stroke_color {
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
border: 1px solid #808080;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#fill_color {
|
||||
background: url('images/none.png');
|
||||
}
|
||||
|
||||
#stroke_color {
|
||||
background: #000000;
|
||||
}
|
||||
|
||||
#svg_editor div#palette {
|
||||
float: left;
|
||||
width: 6848px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
#svg_editor div#tools {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#svg_editor div#workarea {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#svg_editor div.palette_item {
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#tools {
|
||||
background: #E8E8E8;
|
||||
height: 534px;
|
||||
border: 1px solid #808080;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.tool_button, .tool_button_current {
|
||||
height: 24px;
|
||||
width: 24px;
|
||||
border: 1px solid red;
|
||||
margin: 2px;
|
||||
padding: 2px;
|
||||
border-left: 1px solid #FFFFFF;
|
||||
border-top: 1px solid #FFFFFF;
|
||||
border-right: 1px solid #808080;
|
||||
border-bottom: 1px solid #808080;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.tool_button_current {
|
||||
border-left: 1px solid #808080;
|
||||
border-top: 1px solid #808080;
|
||||
border-right: 1px solid #FFFFFF;
|
||||
border-bottom: 1px solid #FFFFFF;
|
||||
background-color: #B0B0B0;
|
||||
}
|
||||
|
||||
#color_pick {
|
||||
position: absolute;
|
||||
display: none;
|
||||
background: #E8E8E8;
|
||||
border: 1px solid #808080;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#color_pick_text, #color_pick_ok {
|
||||
border: 1px solid #808080;
|
||||
width: 90px;
|
||||
height: 20px;
|
||||
float: left;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
#color_pick_ok {
|
||||
background: #E8E8E8;
|
||||
border-left: 1px solid #FFFFFF;
|
||||
border-top: 1px solid #FFFFFF;
|
||||
border-right: 1px solid #808080;
|
||||
border-bottom: 1px solid #808080;
|
||||
}
|
||||
|
||||
.tools_flyout {
|
||||
position: absolute;
|
||||
display: none;
|
||||
height: 28px;
|
||||
width: 90px;
|
||||
background: red;
|
||||
cursor: pointer;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#tool_square {
|
||||
background: 2px 2px url('images/square.png') no-repeat;
|
||||
}
|
||||
|
||||
#tool_rect {
|
||||
background: 2px 2px url('images/rect.png') no-repeat;
|
||||
}
|
||||
|
||||
#tool_fhrect {
|
||||
background: 2px 2px url('images/path.png') no-repeat;
|
||||
}
|
||||
|
||||
#tool_circle {
|
||||
background: 2px 2px url('images/circle.png') no-repeat;
|
||||
}
|
||||
|
||||
#tool_ellipse {
|
||||
background: 2px 2px url('images/ellipse.png') no-repeat;
|
||||
}
|
||||
|
||||
#tool_fhellipse {
|
||||
background: 2px 2px url('images/path.png') no-repeat;
|
||||
}
|
||||
|
||||
#tools_rect div, #tools_ellipse div {
|
||||
float: left;
|
||||
background-color: #E8E8E8;
|
||||
border-left: 1px solid #FFFFFF;
|
||||
border-top: 1px solid #FFFFFF;
|
||||
border-right: 1px solid #808080;
|
||||
border-bottom: 1px solid #808080;
|
||||
height: 28px;
|
||||
width: 28px;
|
||||
}
|
||||
141
editor/svg-editor.html
Normal file
@@ -0,0 +1,141 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="farbtastic.css" type="text/css"/>
|
||||
<link rel="stylesheet" href="svg-editor.css" type="text/css"/>
|
||||
<script type="text/javascript" src="jquery.js"></script>
|
||||
<script type="text/javascript" src="jquery.rightClick.js"></script>
|
||||
<script type="text/javascript" src="farbtastic.js"></script>
|
||||
<script type="text/javascript" src="svg-editor.js"></script>
|
||||
<title>SVG-edit demo</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>SVG-edit @ <a href="http://svg-edit.googlecode.com/">http://svg-edit.googlecode.com/</a></p>
|
||||
|
||||
<div id="svg_editor">
|
||||
|
||||
<div id="color_pick">
|
||||
<div id="color_pick_wheel"></div>
|
||||
<input type="text" id="color_pick_text" />
|
||||
<input type="button" id="color_pick_ok" value="OK" />
|
||||
</div>
|
||||
|
||||
<div id="tools_rect" class="tools_flyout">
|
||||
<div id="tool_square" title="Square"></div>
|
||||
<div id="tool_rect" title="Rectangle"></div>
|
||||
<div id="tool_fhrect" title="Free-Hand Rectangle"></div>
|
||||
</div>
|
||||
|
||||
<div id="tools_ellipse" class="tools_flyout">
|
||||
<div id="tool_circle" title="Circle"></div>
|
||||
<div id="tool_ellipse" title="Ellipse"></div>
|
||||
<div id="tool_fhellipse" title="Free-Hand Ellipse"></div>
|
||||
</div>
|
||||
|
||||
<div id="tools">
|
||||
|
||||
<div>
|
||||
<!--
|
||||
<img class="tool_button" id="tool_select" src="images/select.png" /><br/>
|
||||
-->
|
||||
<img class="tool_button_current" id="tool_path" src="images/path.png" title="Pencil Tool" alt="Path"/><br/>
|
||||
<img class="tool_button" id="tool_line" src="images/line.png" title="Line Tool" alt="Line"/><br/>
|
||||
<img class="tool_button" id="tools_rect_show" src="images/square.png" title="Square/Rect Tool" alt="Square"/><br/>
|
||||
<img class="tool_button" id="tools_ellipse_show" src="images/circle.png" title="Circle/Ellipse Tool" alt="Circle"/><br/>
|
||||
<img class="tool_button" id="tool_delete" src="images/delete.png" title="Delete Element" alt="Delete"/><hr/>
|
||||
<img class="tool_button" id="tool_clear" src="images/clear.png" title="New Image" alt="Clear" /><br/>
|
||||
<img class="tool_button" id="tool_submit" src="images/submit.png" title="View SVG Source" alt="Source"/><br/>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
|
||||
<div>fill
|
||||
<div id="fill_color" title="Change fill color"></div>
|
||||
<select id="fill_opacity" title="Change fill opacity">
|
||||
<option selected="selected" value="1">100 %</option>
|
||||
<option value="0.9">90 %</option>
|
||||
<option value="0.8">80 %</option>
|
||||
<option value="0.7">70 %</option>
|
||||
<option value="0.6">60 %</option>
|
||||
<option value="0.5">50 %</option>
|
||||
<option value="0.4">40 %</option>
|
||||
<option value="0.3">30 %</option>
|
||||
<option value="0.2">20 %</option>
|
||||
<option value="0.1">10 %</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
|
||||
<div>stroke
|
||||
<div id="stroke_color" title="Change stroke color"></div>
|
||||
<div>
|
||||
<select id="stroke_width" title="Change stroke width">
|
||||
<option selected="selected" value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
<option value="5">5</option>
|
||||
<option value="7">7</option>
|
||||
</select>
|
||||
</div><div>
|
||||
<select id="stroke_style" title="Change stroke dash style">
|
||||
<option selected="selected" value="none">---</option>
|
||||
<option value="2,2">...</option>
|
||||
<option value="5,5">- -</option>
|
||||
<option value="5,2,2,2">- .</option>
|
||||
<option value="5,2,2,2,2,2">- ..</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<select id="stroke_opacity" title="Change stroke opacity">
|
||||
<option selected="selected" value="1">100 %</option>
|
||||
<option value="0.9">90 %</option>
|
||||
<option value="0.8">80 %</option>
|
||||
<option value="0.7">70 %</option>
|
||||
<option value="0.6">60 %</option>
|
||||
<option value="0.5">50 %</option>
|
||||
<option value="0.4">40 %</option>
|
||||
<option value="0.3">30 %</option>
|
||||
<option value="0.2">20 %</option>
|
||||
<option value="0.1">10 %</option>
|
||||
</select>
|
||||
</div>
|
||||
<hr/>
|
||||
<div>
|
||||
<select id="group_opacity" title="Change group opacity">
|
||||
<option selected="selected" value="1">100 %</option>
|
||||
<option value="0.9">90 %</option>
|
||||
<option value="0.8">80 %</option>
|
||||
<option value="0.7">70 %</option>
|
||||
<option value="0.6">60 %</option>
|
||||
<option value="0.5">50 %</option>
|
||||
<option value="0.4">40 %</option>
|
||||
<option value="0.3">30 %</option>
|
||||
<option value="0.2">20 %</option>
|
||||
<option value="0.1">10 %</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="workarea">
|
||||
|
||||
<div id="svgcanvas">
|
||||
<object class="svgcanvas" data="svgcanvas.svg" type="image/svg+xml">
|
||||
<embed class="svgcanvas" src="svgcanvas.svg" type="image/svg+xml" />
|
||||
</object>
|
||||
</div>
|
||||
|
||||
<div id="palette_holder">
|
||||
<div id="palette">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
182
editor/svg-editor.js
Normal file
@@ -0,0 +1,182 @@
|
||||
var palette = ["#000000","#202020","#404040","#606060","#808080","#a0a0a0","#c0c0c0","#e0e0e0","#ffffff","#800000","#ff0000","#808000","#ffff00","#008000","#00ff00","#008080","#00ffff","#000080","#0000ff","#800080","#ff00ff","#2b0000","#550000","#800000","#aa0000","#d40000","#ff0000","#ff2a2a","#ff5555","#ff8080","#ffaaaa","#ffd5d5","#280b0b","#501616","#782121","#a02c2c","#c83737","#d35f5f","#de8787","#e9afaf","#f4d7d7","#241c1c","#483737","#6c5353","#916f6f","#ac9393","#c8b7b7","#e3dbdb","#2b1100","#552200","#803300","#aa4400","#d45500","#ff6600","#ff7f2a","#ff9955","#ffb380","#ffccaa","#ffe6d5","#28170b","#502d16","#784421","#a05a2c","#c87137","#d38d5f","#deaa87","#e9c6af","#f4e3d7","#241f1c","#483e37","#6c5d53","#917c6f","#ac9d93","#c8beb7","#e3dedb","#2b2200","#554400","#806600","#aa8800","#d4aa00","#ffcc00","#ffd42a","#ffdd55","#ffe680","#ffeeaa","#fff6d5","#28220b","#504416","#786721","#a0892c","#c8ab37","#d3bc5f","#decd87","#e9ddaf","#f4eed7","#24221c","#484537","#6c6753","#918a6f","#aca793","#c8c4b7","#e3e2db","#222b00","#445500","#668000","#88aa00","#aad400","#ccff00","#d4ff2a","#ddff55","#e5ff80","#eeffaa","#f6ffd5","#22280b","#445016","#677821","#89a02c","#abc837","#bcd35f","#cdde87","#dde9af","#eef4d7","#22241c","#454837","#676c53","#8a916f","#a7ac93","#c4c8b7","#e2e3db","#112b00","#225500","#338000","#44aa00","#55d400","#66ff00","#7fff2a","#99ff55","#b3ff80","#ccffaa","#e5ffd5","#17280b","#2d5016","#447821","#5aa02c","#71c837","#8dd35f","#aade87","#c6e9af","#e3f4d7","#1f241c","#3e4837","#5d6c53","#7c916f","#9dac93","#bec8b7","#dee3db","#002b00","#005500","#008000","#00aa00","#00d400","#00ff00","#2aff2a","#55ff55","#80ff80","#aaffaa","#d5ffd5","#0b280b","#165016","#217821","#2ca02c","#37c837","#5fd35f","#87de87","#afe9af","#d7f4d7","#1c241c","#374837","#536c53","#6f916f","#93ac93","#b7c8b7","#dbe3db","#002b11","#005522","#008033","#00aa44","#00d455","#00ff66","#2aff80","#55ff99","#80ffb3","#aaffcc","#d5ffe6","#0b2817","#16502d","#217844","#2ca05a","#37c871","#5fd38d","#87deaa","#afe9c6","#d7f4e3","#1c241f","#37483e","#536c5d","#6f917c","#93ac9d","#b7c8be","#dbe3de","#002b22","#005544","#008066","#00aa88","#00d4aa","#00ffcc","#2affd5","#55ffdd","#80ffe6","#aaffee","#d5fff6","#0b2822","#165044","#217867","#2ca089","#37c8ab","#5fd3bc","#87decd","#afe9dd","#d7f4ee","#1c2422","#374845","#536c67","#6f918a","#93aca7","#b7c8c4","#dbe3e2","#00222b","#004455","#006680","#0088aa","#00aad4","#00ccff","#2ad4ff","#55ddff","#80e5ff","#aaeeff","#d5f6ff","#0b2228","#164450","#216778","#2c89a0","#37abc8","#5fbcd3","#87cdde","#afdde9","#d7eef4","#1c2224","#374548","#53676c","#6f8a91","#93a7ac","#b7c4c8","#dbe2e3","#00112b","#002255","#003380","#0044aa","#0055d4","#0066ff","#2a7fff","#5599ff","#80b3ff","#aaccff","#d5e5ff","#0b1728","#162d50","#214478","#2c5aa0","#3771c8","#5f8dd3","#87aade","#afc6e9","#d7e3f4","#1c1f24","#373e48","#535d6c","#6f7c91","#939dac","#b7bec8","#dbdee3","#00002b","#000055","#000080","#0000aa","#0000d4","#0000ff","#2a2aff","#5555ff","#8080ff","#aaaaff","#d5d5ff","#0b0b28","#161650","#212178","#2c2ca0","#3737c8","#5f5fd3","#8787de","#afafe9","#d7d7f4","#1c1c24","#373748","#53536c","#6f6f91","#9393ac","#b7b7c8","#dbdbe3","#11002b","#220055","#330080","#4400aa","#5500d4","#6600ff","#7f2aff","#9955ff","#b380ff","#ccaaff","#e5d5ff","#170b28","#2d1650","#442178","#5a2ca0","#7137c8","#8d5fd3","#aa87de","#c6afe9","#e3d7f4","#1f1c24","#3e3748","#5d536c","#7c6f91","#9d93ac","#beb7c8","#dedbe3","#22002b","#440055","#660080","#8800aa","#aa00d4","#cc00ff","#d42aff","#dd55ff","#e580ff","#eeaaff","#f6d5ff","#220b28","#441650","#672178","#892ca0","#ab37c8","#bc5fd3","#cd87de","#ddafe9","#eed7f4","#221c24","#453748","#67536c","#8a6f91","#a793ac","#c4b7c8","#e2dbe3","#2b0022","#550044","#800066","#aa0088","#d400aa","#ff00cc","#ff2ad4","#ff55dd","#ff80e5","#ffaaee","#ffd5f6","#280b22","#501644","#782167","#a02c89","#c837ab","#d35fbc","#de87cd","#e9afdd","#f4d7ee","#241c22","#483745","#6c5367","#916f8a","#ac93a7","#c8b7c4","#e3dbe2","#2b0011","#550022","#800033","#aa0044","#d40055","#ff0066","#ff2a7f","#ff5599","#ff80b2","#ffaacc","#ffd5e5","#280b17","#50162d","#782144","#a02c5a","#c83771","#d35f8d","#de87aa","#e9afc6","#f4d7e3","#241c1f","#48373e","#6c535d","#916f7c","#ac939d","#c8b7be","#e3dbde"]
|
||||
var picker = null;
|
||||
|
||||
$(document).ready(function(){
|
||||
var str = '<div class="palette_item" style="background: url(\'images/none.png\');"></div>'
|
||||
$.each(palette, function(i,item){
|
||||
str += '<div class="palette_item" style="background: ' + item + ';"></div>';
|
||||
});
|
||||
$('#palette').append(str);
|
||||
|
||||
var pos = $('#tools_rect_show').position();
|
||||
$('#tools_rect').css({'left': pos.left+2, 'top': pos.top+2});
|
||||
pos = $('#tools_ellipse_show').position();
|
||||
$('#tools_ellipse').css({'left': pos.left+2, 'top': pos.top+2});
|
||||
|
||||
$('#stroke_width').change(function(){
|
||||
SvgCanvas.setStrokeWidth(this.options[this.selectedIndex].value);
|
||||
});
|
||||
|
||||
$('#stroke_style').change(function(){
|
||||
SvgCanvas.setStrokeStyle(this.options[this.selectedIndex].value);
|
||||
});
|
||||
|
||||
$('#stroke_opacity').change(function(){
|
||||
SvgCanvas.setStrokeOpacity(this.options[this.selectedIndex].value);
|
||||
});
|
||||
|
||||
$('#fill_opacity').change(function(){
|
||||
SvgCanvas.setFillOpacity(this.options[this.selectedIndex].value);
|
||||
});
|
||||
|
||||
$('#group_opacity').change(function(){
|
||||
SvgCanvas.setOpacity(this.options[this.selectedIndex].value);
|
||||
});
|
||||
|
||||
$('.palette_item').click(function(){
|
||||
color = $(this).css('background-color');
|
||||
if (color == 'transparent') {
|
||||
color = 'none';
|
||||
$('#fill_color').css('background', 'url(\'images/none.png\')');
|
||||
} else {
|
||||
$('#fill_color').css('background', color);
|
||||
}
|
||||
SvgCanvas.setFillColor(color);
|
||||
});
|
||||
|
||||
$('.palette_item').rightClick(function(){
|
||||
color = $(this).css('background-color');
|
||||
if (color == 'transparent') {
|
||||
color = 'none';
|
||||
$('#stroke_color').css('background', 'url(\'images/none.png\')');
|
||||
} else {
|
||||
$('#stroke_color').css('background', color);
|
||||
}
|
||||
SvgCanvas.setStrokeColor(color);
|
||||
});
|
||||
|
||||
// This is a common function used when a tool has been clicked (chosen)
|
||||
// It does several common things:
|
||||
// - hides any flyout menus
|
||||
// - removes the tool_button_current class from whatever tool currently has it
|
||||
// - adds the tool_button_current class to the button passed in
|
||||
var toolButtonClick = function(button){
|
||||
$('.tools_flyout').hide();
|
||||
$('.tool_button_current').removeClass('tool_button_current').addClass('tool_button');
|
||||
$(button).addClass('tool_button_current');
|
||||
};
|
||||
|
||||
$('#tool_select').click(function(){
|
||||
toolButtonClick(this);
|
||||
SvgCanvas.setMode('select');
|
||||
});
|
||||
|
||||
$('#tool_path').click(function(){
|
||||
toolButtonClick(this);
|
||||
SvgCanvas.setMode('path');
|
||||
});
|
||||
|
||||
$('#tool_line').click(function(){
|
||||
toolButtonClick(this);
|
||||
SvgCanvas.setMode('line');
|
||||
});
|
||||
|
||||
$('#tool_square').click(function(){
|
||||
toolButtonClick('#tools_rect_show');
|
||||
SvgCanvas.setMode('square');
|
||||
});
|
||||
|
||||
$('#tool_rect').click(function(){
|
||||
toolButtonClick('#tools_rect_show');
|
||||
SvgCanvas.setMode('rect');
|
||||
});
|
||||
|
||||
$('#tool_fhrect').click(function(){
|
||||
toolButtonClick('#tools_rect_show');
|
||||
SvgCanvas.setMode('fhrect');
|
||||
});
|
||||
|
||||
$('#tool_circle').click(function(){
|
||||
toolButtonClick('#tools_ellipse_show');
|
||||
SvgCanvas.setMode('circle');
|
||||
});
|
||||
|
||||
$('#tool_ellipse').click(function(){
|
||||
toolButtonClick('#tools_ellipse_show');
|
||||
SvgCanvas.setMode('ellipse');
|
||||
});
|
||||
|
||||
$('#tool_fhellipse').click(function(){
|
||||
toolButtonClick('#tools_ellipse_show');
|
||||
SvgCanvas.setMode('fhellipse');
|
||||
});
|
||||
|
||||
$('#tool_delete').click(function(){
|
||||
toolButtonClick(this);
|
||||
SvgCanvas.setMode('delete');
|
||||
});
|
||||
|
||||
$('#tool_clear').click(function(){
|
||||
if( confirm('Do you want to clear the drawing?') ) {
|
||||
SvgCanvas.clear();
|
||||
}
|
||||
});
|
||||
|
||||
$('#tool_submit').click(function(){
|
||||
SvgCanvas.serialize(serializeHandler);
|
||||
});
|
||||
|
||||
$('#fill_color').click(function(){
|
||||
var color = $(this).css('background-color');
|
||||
if (color == 'transparent') color = '#ffffff';
|
||||
picker.setColor(color);
|
||||
picker.mode = 'fill';
|
||||
pos = $(this).position();
|
||||
$('#color_pick').css({'left': pos.left, 'top': pos.top}).show();
|
||||
});
|
||||
|
||||
$('#stroke_color').click(function(){
|
||||
var color = $(this).css('background-color');
|
||||
if (color == 'transparent') color = '#ffffff';
|
||||
picker.setColor(color);
|
||||
picker.mode = 'stroke';
|
||||
pos = $(this).position();
|
||||
$('#color_pick').css({'left': pos.left, 'top': pos.top}).show();
|
||||
});
|
||||
|
||||
$('#color_pick_ok').click(function(){
|
||||
$('#color_pick').hide();
|
||||
if (picker.mode == 'stroke') {
|
||||
$('#stroke_color').css('background', picker.color);
|
||||
SvgCanvas.setStrokeColor(picker.color);
|
||||
}
|
||||
if (picker.mode == 'fill') {
|
||||
$('#fill_color').css('background', picker.color);
|
||||
SvgCanvas.setFillColor(picker.color);
|
||||
}
|
||||
});
|
||||
|
||||
picker = $.farbtastic('#color_pick_wheel', function(){
|
||||
$('#color_pick_text').attr('value', this.color);
|
||||
});
|
||||
|
||||
$('#color_pick_text').keyup(function(){
|
||||
picker.setColor($(this).attr('value'));
|
||||
});
|
||||
|
||||
// This hides any flyouts and then shows the rect flyout
|
||||
$('#tools_rect_show').click(function(){
|
||||
$('.tools_flyout').hide();
|
||||
$('#tools_rect').show();
|
||||
});
|
||||
|
||||
// This hides any flyouts and then shows the circle flyout
|
||||
$('#tools_ellipse_show').click(function(){
|
||||
$('.tools_flyout').hide();
|
||||
$('#tools_ellipse').show();
|
||||
});
|
||||
})
|
||||
|
||||
function serializeHandler(svg) {
|
||||
alert(svg);
|
||||
}
|
||||
516
editor/svgcanvas.js
Normal file
@@ -0,0 +1,516 @@
|
||||
var svgcanvas = null;
|
||||
|
||||
function svgCanvasInit(event) {
|
||||
svgcanvas = new SvgCanvas(event.target.ownerDocument);
|
||||
svgcanvas.setup(event);
|
||||
top.SvgCanvas = svgcanvas;
|
||||
}
|
||||
|
||||
function SvgCanvas(doc)
|
||||
{
|
||||
|
||||
// private members
|
||||
|
||||
var svgdoc = doc;
|
||||
var svgroot = svgdoc.documentElement;
|
||||
var svgns = "http://www.w3.org/2000/svg";
|
||||
var d_attr = null;
|
||||
var started = false;
|
||||
var obj_num = 1;
|
||||
var start_x = null;
|
||||
var start_y = null;
|
||||
var current_mode = "path";
|
||||
var current_fill = "none";
|
||||
var current_stroke = "black";
|
||||
var current_stroke_width = 1;
|
||||
var current_stroke_style = "none";
|
||||
var current_opacity = 1;
|
||||
var current_stroke_opacity = 1;
|
||||
var current_fill_opacity = 1;
|
||||
var freehand_min_x = null;
|
||||
var freehand_max_x = null;
|
||||
var freehand_min_y = null;
|
||||
var freehand_max_y = null;
|
||||
var selected = null;
|
||||
|
||||
// private functions
|
||||
|
||||
var assignAttributes = function(node, attrs) {
|
||||
for (i in attrs) {
|
||||
node.setAttributeNS(null, i, attrs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// remove unneeded attributes
|
||||
// makes resulting SVG smaller
|
||||
var cleanupElement = function(element) {
|
||||
if (element.getAttribute('fill-opacity') == '1')
|
||||
element.removeAttribute('fill-opacity');
|
||||
if (element.getAttribute('opacity') == '1')
|
||||
element.removeAttribute('opacity');
|
||||
if (element.getAttribute('stroke') == 'none')
|
||||
element.removeAttribute('stroke');
|
||||
if (element.getAttribute('stroke-dasharray') == 'none')
|
||||
element.removeAttribute('stroke-dasharray');
|
||||
if (element.getAttribute('stroke-opacity') == '1')
|
||||
element.removeAttribute('stroke-opacity');
|
||||
if (element.getAttribute('stroke-width') == '1')
|
||||
element.removeAttribute('stroke-width');
|
||||
}
|
||||
|
||||
var addSvgElementFromJson = function(data) {
|
||||
var shape = svgdoc.createElementNS(svgns, data.element);
|
||||
assignAttributes(shape, data.attr);
|
||||
cleanupElement(shape);
|
||||
svgdoc.documentElement.appendChild(shape);
|
||||
}
|
||||
|
||||
var svgToString = function(elem, indent) {
|
||||
var out = "";
|
||||
if (elem) {
|
||||
var attrs = elem.attributes;
|
||||
var attr;
|
||||
var i;
|
||||
var childs = elem.childNodes;
|
||||
// don't include scripts in output svg
|
||||
if (elem.nodeName == "script") return "";
|
||||
for (i=0; i<indent; i++) out += " ";
|
||||
out += "<" + elem.nodeName;
|
||||
for (i=attrs.length-1; i>=0; i--) {
|
||||
attr = attrs.item(i);
|
||||
// don't include events in output svg
|
||||
if (attr.nodeName == "onload" ||
|
||||
attr.nodeName == "onmousedown" ||
|
||||
attr.nodeName == "onmousemove" ||
|
||||
attr.nodeName == "onmouseup") continue;
|
||||
out += " " + attr.nodeName + "=\"" + attr.nodeValue+ "\"";
|
||||
}
|
||||
if (elem.hasChildNodes()) {
|
||||
out += ">\n";
|
||||
indent++;
|
||||
for (i=0; i<childs.length; i++)
|
||||
{
|
||||
if (childs.item(i).nodeType == 1) { // element node
|
||||
out = out + svgToString(childs.item(i), indent);
|
||||
} else if (childs.item(i).nodeType == 3) { // text node
|
||||
for (j=0; j<indent; j++) out += " ";
|
||||
out += childs.item(i).nodeValue + "\n";
|
||||
}
|
||||
}
|
||||
indent--;
|
||||
for (i=0; i<indent; i++) out += " ";
|
||||
out += "</" + elem.nodeName + ">\n";
|
||||
} else {
|
||||
out += " />\n";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// public events
|
||||
|
||||
this.mouseDown = function(evt)
|
||||
{
|
||||
var x = evt.pageX;
|
||||
var y = evt.pageY;
|
||||
switch (current_mode) {
|
||||
case "select":
|
||||
started = true;
|
||||
start_x = x;
|
||||
start_y = y;
|
||||
if (evt.target != svgroot)
|
||||
selected = evt.target;
|
||||
addSvgElementFromJson({
|
||||
"element": "rect",
|
||||
"attr": {
|
||||
"x": x,
|
||||
"y": y,
|
||||
"width": 0,
|
||||
"height": 0,
|
||||
"id": "rect_" + obj_num,
|
||||
"fill": '#DBEBF9',
|
||||
"stroke": '#CEE2F7',
|
||||
"stroke-width": 1,
|
||||
"fill-opacity": 0.5
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "fhellipse":
|
||||
case "fhrect":
|
||||
case "path":
|
||||
started = true;
|
||||
d_attr = "M" + x + " " + y + " ";
|
||||
addSvgElementFromJson({
|
||||
"element": "path",
|
||||
"attr": {
|
||||
"d": d_attr,
|
||||
"id": "path_" + obj_num,
|
||||
"fill": "none",
|
||||
"stroke": current_stroke,
|
||||
"stroke-width": current_stroke_width,
|
||||
"stroke-dasharray": current_stroke_style,
|
||||
"stroke-opacity": current_stroke_opacity,
|
||||
"opacity": current_opacity / 2
|
||||
}
|
||||
});
|
||||
freehand_min_x = x;
|
||||
freehand_max_x = x;
|
||||
freehand_min_y = y;
|
||||
freehand_max_y = y;
|
||||
break;
|
||||
case "square":
|
||||
case "rect":
|
||||
started = true;
|
||||
start_x = x;
|
||||
start_y = y;
|
||||
addSvgElementFromJson({
|
||||
"element": "rect",
|
||||
"attr": {
|
||||
"x": x,
|
||||
"y": y,
|
||||
"width": 0,
|
||||
"height": 0,
|
||||
"id": "rect_" + obj_num,
|
||||
"fill": current_fill,
|
||||
"stroke": current_stroke,
|
||||
"stroke-width": current_stroke_width,
|
||||
"stroke-dasharray": current_stroke_style,
|
||||
"stroke-opacity": current_stroke_opacity,
|
||||
"fill-opacity": current_fill_opacity,
|
||||
"opacity": current_opacity / 2
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "line":
|
||||
started = true;
|
||||
addSvgElementFromJson({
|
||||
"element": "line",
|
||||
"attr": {
|
||||
"x1": x,
|
||||
"y1": y,
|
||||
"x2": x,
|
||||
"y2": y,
|
||||
"id": "line_" + obj_num,
|
||||
"stroke": current_stroke,
|
||||
"stroke-width": current_stroke_width,
|
||||
"stroke-dasharray": current_stroke_style,
|
||||
"stroke-opacity": current_stroke_opacity,
|
||||
"opacity": current_opacity / 2
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "circle":
|
||||
started = true;
|
||||
addSvgElementFromJson({
|
||||
"element": "circle",
|
||||
"attr": {
|
||||
"cx": x,
|
||||
"cy": y,
|
||||
"r": 0,
|
||||
"id": "circle_" + obj_num,
|
||||
"fill": current_fill,
|
||||
"stroke": current_stroke,
|
||||
"stroke-width": current_stroke_width,
|
||||
"stroke-dasharray": current_stroke_style,
|
||||
"stroke-opacity": current_stroke_opacity,
|
||||
"fill-opacity": current_fill_opacity,
|
||||
"opacity": current_opacity / 2
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "ellipse":
|
||||
started = true;
|
||||
addSvgElementFromJson({
|
||||
"element": "ellipse",
|
||||
"attr": {
|
||||
"cx": x,
|
||||
"cy": y,
|
||||
"rx": 0,
|
||||
"ry": 0,
|
||||
"id": "ellipse_" + obj_num,
|
||||
"fill": current_fill,
|
||||
"stroke": current_stroke,
|
||||
"stroke-width": current_stroke_width,
|
||||
"stroke-dasharray": current_stroke_style,
|
||||
"stroke-opacity": current_stroke_opacity,
|
||||
"fill-opacity": current_fill_opacity,
|
||||
"opacity": current_opacity / 2
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "delete":
|
||||
var t = evt.target;
|
||||
if (t == svgroot) return;
|
||||
t.parentNode.removeChild(t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.mouseMove = function(evt)
|
||||
{
|
||||
if (!started) return;
|
||||
|
||||
var x = evt.pageX;
|
||||
var y = evt.pageY;
|
||||
switch (current_mode)
|
||||
{
|
||||
case "line":
|
||||
var shape = svgdoc.getElementById("line_" + obj_num);
|
||||
shape.setAttributeNS(null, "x2", x);
|
||||
shape.setAttributeNS(null, "y2", y);
|
||||
break;
|
||||
case "square":
|
||||
var shape = svgdoc.getElementById("rect_" + obj_num);
|
||||
var size = Math.max( Math.abs(x - start_x), Math.abs(y - start_y) );
|
||||
shape.setAttributeNS(null, "width", size);
|
||||
shape.setAttributeNS(null, "height", size);
|
||||
if(start_x < x) {
|
||||
shape.setAttributeNS(null, "x", start_x);
|
||||
} else {
|
||||
shape.setAttributeNS(null, "x", start_x - size);
|
||||
}
|
||||
if(start_y < y) {
|
||||
shape.setAttributeNS(null, "y", start_y);
|
||||
} else {
|
||||
shape.setAttributeNS(null, "y", start_y - size);
|
||||
}
|
||||
break;
|
||||
case "select":
|
||||
case "rect":
|
||||
var shape = svgdoc.getElementById("rect_" + obj_num);
|
||||
if (start_x < x) {
|
||||
shape.setAttributeNS(null, "x", start_x);
|
||||
shape.setAttributeNS(null, "width", x - start_x);
|
||||
} else {
|
||||
shape.setAttributeNS(null, "x", x);
|
||||
shape.setAttributeNS(null, "width", start_x - x);
|
||||
}
|
||||
if (start_y < y) {
|
||||
shape.setAttributeNS(null, "y", start_y);
|
||||
shape.setAttributeNS(null, "height", y - start_y);
|
||||
} else {
|
||||
shape.setAttributeNS(null, "y", y);
|
||||
shape.setAttributeNS(null, "height", start_y - y);
|
||||
}
|
||||
break;
|
||||
case "circle":
|
||||
var shape = svgdoc.getElementById("circle_" + obj_num);
|
||||
var cx = shape.getAttributeNS(null, "cx");
|
||||
var cy = shape.getAttributeNS(null, "cy");
|
||||
var rad = Math.sqrt( (x-cx)*(x-cx) + (y-cy)*(y-cy) );
|
||||
shape.setAttributeNS(null, "r", rad);
|
||||
break;
|
||||
case "ellipse":
|
||||
var shape = svgdoc.getElementById("ellipse_" + obj_num);
|
||||
var cx = shape.getAttributeNS(null, "cx");
|
||||
var cy = shape.getAttributeNS(null, "cy");
|
||||
shape.setAttributeNS(null, "rx", Math.abs(x - cx) );
|
||||
shape.setAttributeNS(null, "ry", Math.abs(y - cy) );
|
||||
break;
|
||||
case "fhellipse":
|
||||
case "fhrect":
|
||||
freehand_min_x = Math.min(x, freehand_min_x);
|
||||
freehand_max_x = Math.max(x, freehand_max_x);
|
||||
freehand_min_y = Math.min(y, freehand_min_y);
|
||||
freehand_max_y = Math.max(y, freehand_max_y);
|
||||
// break; missing on purpose
|
||||
case "path":
|
||||
d_attr += "L" + x + " " + y + " ";
|
||||
var shape = svgdoc.getElementById("path_" + obj_num);
|
||||
shape.setAttributeNS(null, "d", d_attr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.mouseUp = function(evt)
|
||||
{
|
||||
if (!started) return;
|
||||
|
||||
started = false;
|
||||
var element = null;
|
||||
switch (current_mode)
|
||||
{
|
||||
case "select":
|
||||
element = svgdoc.getElementById("rect_" + obj_num);
|
||||
if (element.getAttribute('width') == 0 &&
|
||||
element.getAttribute('height') == 0) {
|
||||
// only one element is selected and stored in selected variable (or null)
|
||||
} else {
|
||||
// element.getAttribute('x')
|
||||
// element.getAttribute('y')
|
||||
// should scan elements which are in rect(x,y,width,height) and select them
|
||||
}
|
||||
element.parentNode.removeChild(element);
|
||||
element = null;
|
||||
break;
|
||||
case "path":
|
||||
d_attr = null;
|
||||
element = svgdoc.getElementById("path_" + obj_num);
|
||||
element.setAttribute("opacity", current_opacity);
|
||||
obj_num++;
|
||||
break;
|
||||
case "line":
|
||||
element = svgdoc.getElementById("line_" + obj_num);
|
||||
if (element.getAttribute('x1') == element.getAttribute('x2') &&
|
||||
element.getAttribute('y1') == element.getAttribute('y2')) {
|
||||
element.parentNode.removeChild(element);
|
||||
element = null;
|
||||
} else {
|
||||
element.setAttribute("opacity", current_opacity);
|
||||
obj_num++;
|
||||
}
|
||||
break;
|
||||
case "square":
|
||||
case "rect":
|
||||
element = svgdoc.getElementById("rect_" + obj_num);
|
||||
if (element.getAttribute('width') == 0 &&
|
||||
element.getAttribute('height') == 0) {
|
||||
element.parentNode.removeChild(element);
|
||||
element = null;
|
||||
} else {
|
||||
element.setAttribute("opacity", current_opacity);
|
||||
obj_num++;
|
||||
}
|
||||
break;
|
||||
case "circle":
|
||||
element = svgdoc.getElementById("circle_" + obj_num);
|
||||
if (element.getAttribute('r') == 0) {
|
||||
element.parentNode.removeChild(element);
|
||||
element = null;
|
||||
} else {
|
||||
element.setAttribute("opacity", current_opacity);
|
||||
obj_num++;
|
||||
}
|
||||
break;
|
||||
case "ellipse":
|
||||
element = svgdoc.getElementById("ellipse_" + obj_num);
|
||||
if (element.getAttribute('rx') == 0 &&
|
||||
element.getAttribute('ry') == 0) {
|
||||
element.parentNode.removeChild(element);
|
||||
element = null;
|
||||
} else {
|
||||
element.setAttribute("opacity", current_opacity);
|
||||
obj_num++;
|
||||
}
|
||||
break;
|
||||
case "fhellipse":
|
||||
d_attr = null;
|
||||
element = svgdoc.getElementById("path_" + obj_num);
|
||||
element.parentNode.removeChild(element);
|
||||
if ((freehand_max_x - freehand_min_x) > 0 &&
|
||||
(freehand_max_y - freehand_min_y) > 0) {
|
||||
addSvgElementFromJson({
|
||||
"element": "ellipse",
|
||||
"attr": {
|
||||
"cx": (freehand_min_x + freehand_max_x) / 2,
|
||||
"cy": (freehand_min_y + freehand_max_y) / 2,
|
||||
"rx": (freehand_max_x - freehand_min_x) / 2,
|
||||
"ry": (freehand_max_y - freehand_min_y) / 2,
|
||||
"id": "ellipse_" + obj_num,
|
||||
"fill": current_fill,
|
||||
"stroke": current_stroke,
|
||||
"stroke-width": current_stroke_width,
|
||||
"stroke-dasharray": current_stroke_style,
|
||||
"opacity": current_opacity,
|
||||
"stroke-opacity": current_stroke_opacity,
|
||||
"fill-opacity": current_fill_opacity
|
||||
}
|
||||
});
|
||||
obj_num++;
|
||||
}
|
||||
break;
|
||||
case "fhrect":
|
||||
d_attr = null;
|
||||
element = svgdoc.getElementById("path_" + obj_num);
|
||||
element.parentNode.removeChild(element);
|
||||
if ((freehand_max_x - freehand_min_x) > 0 &&
|
||||
(freehand_max_y - freehand_min_y) > 0) {
|
||||
addSvgElementFromJson({
|
||||
"element": "rect",
|
||||
"attr": {
|
||||
"x": freehand_min_x,
|
||||
"y": freehand_min_y,
|
||||
"width": (freehand_max_x - freehand_min_x),
|
||||
"height": (freehand_max_y - freehand_min_y),
|
||||
"id": "rect_" + obj_num,
|
||||
"fill": current_fill,
|
||||
"stroke": current_stroke,
|
||||
"stroke-width": current_stroke_width,
|
||||
"stroke-dasharray": current_stroke_style,
|
||||
"opacity": current_opacity,
|
||||
"stroke-opacity": current_stroke_opacity,
|
||||
"fill-opacity": current_fill_opacity
|
||||
}
|
||||
});
|
||||
obj_num++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (element != null) {
|
||||
cleanupElement(element);
|
||||
}
|
||||
}
|
||||
|
||||
// public functions
|
||||
|
||||
this.serialize = function(handler) {
|
||||
var str = "<?xml version=\"1.0\" standalone=\"no\"?>\n"
|
||||
str += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||
str += svgToString(svgroot, 0);
|
||||
handler(str);
|
||||
}
|
||||
|
||||
this.clear = function() {
|
||||
var nodes = svgroot.childNodes;
|
||||
var len = svgroot.childNodes.length;
|
||||
var i = 0;
|
||||
for(var rep = 0; rep < len; rep++){
|
||||
if (nodes[i].nodeType == 1) { // element node
|
||||
nodes[i].parentNode.removeChild(nodes[i]);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.setMode = function(name) {
|
||||
current_mode = name;
|
||||
}
|
||||
|
||||
this.setStrokeColor = function(color) {
|
||||
current_stroke = color;
|
||||
}
|
||||
|
||||
this.setFillColor = function(color) {
|
||||
current_fill = color;
|
||||
}
|
||||
|
||||
this.setStrokeWidth = function(val) {
|
||||
current_stroke_width = val;
|
||||
}
|
||||
|
||||
this.setStrokeStyle = function(val) {
|
||||
current_stroke_style = val;
|
||||
}
|
||||
|
||||
this.setOpacity = function(val) {
|
||||
current_opacity = val;
|
||||
}
|
||||
|
||||
this.setFillOpacity = function(val) {
|
||||
current_fill_opacity = val;
|
||||
}
|
||||
|
||||
this.setStrokeOpacity = function(val) {
|
||||
current_stroke_opacity = val;
|
||||
}
|
||||
|
||||
this.setup = function(evt) {
|
||||
assignAttributes(svgroot, {
|
||||
"onmouseup": "svgcanvas.mouseUp(evt)",
|
||||
"onmousedown": "svgcanvas.mouseDown(evt)",
|
||||
"onmousemove": "svgcanvas.mouseMove(evt)"
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
5
editor/svgcanvas.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xml:space="preserve" id="svg_image" onload="svgCanvasInit(evt)" width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<script xlink:href="svgcanvas.js" type="text/ecmascript"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 392 B |