small changes to UI

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@224 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Pavol Rusnak 2009-06-29 14:38:30 +00:00
parent 54e20edef2
commit ece4974a91
4 changed files with 151 additions and 160 deletions

View File

@ -1,5 +1,5 @@
body { body {
background-color: #E8E8E8; background: #E8E8E8;
} }
#svg_editor { #svg_editor {
@ -31,22 +31,15 @@ body {
vertical-align: middle; vertical-align: middle;
width: 640px; width: 640px;
height: 480px; height: 480px;
border-left: 1px solid #FFFFFF;
border-top: 1px solid #FFFFFF;
border-right: 1px solid #808080;
border-bottom: 1px solid #808080;
} }
#svg_editor div#palette_holder { #svg_editor div#palette_holder {
border: 2px solid #808080;
border-top: none;
overflow-x: scroll; overflow-x: scroll;
overflow-y: hidden; overflow-y: hidden;
position: absolute;
left: 75px;
right: 2px;
bottom: 22px;
height: 31px; height: 31px;
border: 1px solid #808080;
border-top: none;
margin-top: 2px;
} }
#svg_editor #fill_color, #svg_editor #stroke_color { #svg_editor #fill_color, #svg_editor #stroke_color {
@ -72,12 +65,12 @@ body {
#svg_editor div#workarea { #svg_editor div#workarea {
position:absolute; position:absolute;
top: 70px; top: 40px;
left: 75px; left: 40px;
right: 2px; right: 2px;
bottom: 53px; bottom: 100px;
background-color: #E8E8E8; background-color: #A0A0A0;
border: 2px solid #808080; border: 1px solid #808080;
overflow: auto; overflow: auto;
} }
@ -87,40 +80,30 @@ body {
float: left; float: left;
} }
#svg_editor .tools_panel { #svg_editor #tools_top {
/* background: #E8E8E8;*/
/* border: 1px solid #808080;*/
}
#svg_editor #context_tools {
position: absolute; position: absolute;
left: 19px; left: 38px;
right: 2px; right: 2px;
top: 2px; top: 2px;
height: 68px; height: 36px;
border-bottom: none; border-bottom: none;
} }
#svg_editor #context_tools div { #svg_editor #tools_top div {
float: left; float: left;
} }
#svg_editor #tools_container { #svg_editor #tools_left {
position: absolute; position: absolute;
left: 2px;
top: 70px;
bottom: 22px;
}
#svg_editor #tools {
border-right: none; border-right: none;
width: 70px; width: 36px;
text-align: center; top: 38px;
left: 2px;
} }
/* TODO: fix this */ /* TODO: fix this */
div.color_block { div.color_block {
display:inline-block; display: inline-block;
} }
#svg_editor #selected_panel { #svg_editor #selected_panel {
@ -204,8 +187,6 @@ div.color_block {
position: absolute; position: absolute;
display: none; display: none;
background: #E8E8E8; background: #E8E8E8;
/* border: 1px solid #808080;
padding: 5px;*/
} }
#svg_editor .tools_flyout { #svg_editor .tools_flyout {
@ -259,21 +240,29 @@ div.color_block {
background-color: #B0B0B0; background-color: #B0B0B0;
} }
#svg_editor #footer { #svg_editor #tools_bottom {
position: absolute; position: absolute;
left: 75px; left: 40px;
right: 2px; right: 2px;
bottom: 2px; bottom: 2px;
height: 20px; height: 100px;
border-top: none;
} }
#svg_editor #footer_left { #svg_editor #tools_bottom_1 {
width: 100px;
height: 100px;
float: left; float: left;
position: absolute;
top: -2px;
} }
#svg_editor #footer_right { #svg_editor #tools_bottom_2 {
float: right; width: 250px;
height: 100px;
float: left;
}
#svg_editor #tools_bottom_3 {
}
#svg_editor #copyright {
text-align: right;
} }

View File

@ -15,14 +15,11 @@
<div id="svg_editor"> <div id="svg_editor">
<div id="workarea"> <div id="workarea">
<style id="styleoverrides" type="text/css"></style> <style id="styleoverrides" type="text/css"></style>
<div id="svgcanvas"> <div id="svgcanvas"></div>
</div> </div>
</div> <div id="tools_top" class="tools_panel">
<div id="context_tools" class="tools_panel">
<!-- File-like buttons: New, Save --> <!-- File-like buttons: New, Save -->
<div> <div>
<img class="tool_button" id="tool_clear" src="images/clear.png" title="New Image [N]" alt="Clear" /> <img class="tool_button" id="tool_clear" src="images/clear.png" title="New Image [N]" alt="Clear" />
@ -78,7 +75,7 @@
<label class="circle_tool">r:</label> <label class="circle_tool">r:</label>
<input id="circle_r" class="circle_tool attr_changer" title="Change circle's radius" alt="r" size="3"/> <input id="circle_r" class="circle_tool attr_changer" title="Change circle's radius" alt="r" size="3"/>
</div> </div>
<div id="ellipse_panel"> <div id="ellipse_panel">
<img class="tool_sep" src="images/sep.png" alt="|"/> <img class="tool_sep" src="images/sep.png" alt="|"/>
<label class="ellipse_tool">cx:</label> <label class="ellipse_tool">cx:</label>
@ -90,7 +87,7 @@
<label class="ellipse_tool">ry:</label> <label class="ellipse_tool">ry:</label>
<input id="ellipse_ry" class="ellipse_tool attr_changer" title="Change ellipse's y radius" alt="ry" size="3"/> <input id="ellipse_ry" class="ellipse_tool attr_changer" title="Change ellipse's y radius" alt="ry" size="3"/>
</div> </div>
<div id="line_panel"> <div id="line_panel">
<img class="tool_sep" src="images/sep.png" alt="|"/> <img class="tool_sep" src="images/sep.png" alt="|"/>
<label class="line_tool">x1:</label> <label class="line_tool">x1:</label>
@ -131,14 +128,20 @@
</select> </select>
<input id="text" class="text_tool" type="text" title="Change text contents" size="35"/> <input id="text" class="text_tool" type="text" title="Change text contents" size="35"/>
</div> </div>
</div> </div> <!-- tools_top -->
<div id="palette_holder"> <div id="tools_left" class="tools_panel">
<div id="palette" title="Click to change fill color, shift-click to change stroke color"></div> <img class="tool_button_current" id="tool_select" src="images/select.png" title="Select Tool [1]" alt="Select"/><br/>
</div> <img class="tool_button" id="tool_path" src="images/path.png" title="Pencil Tool [2]" alt="Pencil"/><br/>
<img class="tool_button" id="tool_line" src="images/line.png" title="Line Tool [3]" alt="Line"/><br/>
<img class="tool_button" id="tools_rect_show" src="images/square.png" title="Square/Rect Tool [4/Shift+4]" alt="Square"/><br/>
<img class="tool_button" id="tools_ellipse_show" src="images/circle.png" title="Ellipse/Circle Tool [5/Shift+5]" alt="Circle"/><br/>
<img class="tool_button" id="tool_text" src="images/text.png" title="Text Tool [6]" alt="Text"/>
</div> <!-- tools_left -->
<div id="footer" class="tools_panel"> <div id="tools_bottom" class="tools_panel">
<div id="footer_left">
<div id="tools_bottom_1">
<select id="resolution"> <select id="resolution">
<option selected="selected">640x480</option> <option selected="selected">640x480</option>
<option>800x600</option> <option>800x600</option>
@ -147,23 +150,14 @@
<option>1600x1200</option> <option>1600x1200</option>
</select> </select>
</div> </div>
<div id ="footer_right">SVG-edit v2.2-preAlpha @ <a href="http://svg-edit.googlecode.com/">http://svg-edit.googlecode.com/</a>
</div>
</div>
<div id="tools_container"> <div id="tools_bottom_2">
<div id="tools" class="tools_panel"> <table>
<img class="tool_button_current" id="tool_select" src="images/select.png" title="Select Tool [1]" alt="Select"/><br/> <tr>
<img class="tool_button" id="tool_path" src="images/path.png" title="Pencil Tool [2]" alt="Pencil"/><br/> <td>fill:</td>
<img class="tool_button" id="tool_line" src="images/line.png" title="Line Tool [3]" alt="Line"/><br/> <td><div id="fill_color" class="color_block" title="Change fill color"></div></td>
<img class="tool_button" id="tools_rect_show" src="images/square.png" title="Square/Rect Tool [4/Shift+4]" alt="Square"/><br/> <td>
<img class="tool_button" id="tools_ellipse_show" src="images/circle.png" title="Ellipse/Circle Tool [5/Shift+5]" alt="Circle"/><br/> <select id="fill_opacity" title="Change fill opacity">
<img class="tool_button" id="tool_text" src="images/text.png" title="Text Tool [6]" alt="Text"/>
<hr/>
<div>opacity<br/>
<select id="group_opacity" title="Change group opacity">
<option selected="selected" value="1">100 %</option> <option selected="selected" value="1">100 %</option>
<option value="0.9">90 %</option> <option value="0.9">90 %</option>
<option value="0.8">80 %</option> <option value="0.8">80 %</option>
@ -174,14 +168,13 @@
<option value="0.3">30 %</option> <option value="0.3">30 %</option>
<option value="0.2">20 %</option> <option value="0.2">20 %</option>
<option value="0.1">10 %</option> <option value="0.1">10 %</option>
</select> </select>
</div> <!-- opacity --> </td>
</tr><tr>
<hr/> <td>stroke:</td>
<td><div id="stroke_color" class="color_block" title="Change stroke color"></div></td>
<div>fill<br/> <td>
<div id="fill_color" class="color_block" title="Change fill color"></div> <select id="stroke_opacity" title="Change stroke opacity">
<select id="fill_opacity" title="Change fill opacity">
<option selected="selected" value="1">100 %</option> <option selected="selected" value="1">100 %</option>
<option value="0.9">90 %</option> <option value="0.9">90 %</option>
<option value="0.8">80 %</option> <option value="0.8">80 %</option>
@ -192,28 +185,31 @@
<option value="0.3">30 %</option> <option value="0.3">30 %</option>
<option value="0.2">20 %</option> <option value="0.2">20 %</option>
<option value="0.1">10 %</option> <option value="0.1">10 %</option>
</select> </select>
</div> <!-- fill --> </td>
<td>
<hr/> <select id="stroke_width" title="Change stroke width">
<div>stroke<br/>
<div id="stroke_color" class="color_block" title="Change stroke color"></div><br/>
<select id="stroke_width" title="Change stroke width">
<option selected="selected" value="1">1</option> <option selected="selected" value="1">1</option>
<option value="2">2</option> <option value="2">2</option>
<option value="3">3</option> <option value="3">3</option>
<option value="5">5</option> <option value="5">5</option>
<option value="7">7</option> <option value="7">7</option>
</select> </select>
<select id="stroke_style" title="Change stroke dash style"> </td>
<td>
<select id="stroke_style" title="Change stroke dash style">
<option selected="selected" value="none">---</option> <option selected="selected" value="none">---</option>
<option value="2,2">...</option> <option value="2,2">...</option>
<option value="5,5">- -</option> <option value="5,5">- -</option>
<option value="5,2,2,2">- .</option> <option value="5,2,2,2">- .</option>
<option value="5,2,2,2,2,2">- ..</option> <option value="5,2,2,2,2,2">- ..</option>
</select> </select>
<select id="stroke_opacity" title="Change stroke opacity"> </td>
</tr><tr>
<td>group:</td>
<td></td>
<td>
<select id="group_opacity" title="Change group opacity">
<option selected="selected" value="1">100 %</option> <option selected="selected" value="1">100 %</option>
<option value="0.9">90 %</option> <option value="0.9">90 %</option>
<option value="0.8">80 %</option> <option value="0.8">80 %</option>
@ -224,23 +220,33 @@
<option value="0.3">30 %</option> <option value="0.3">30 %</option>
<option value="0.2">20 %</option> <option value="0.2">20 %</option>
<option value="0.1">10 %</option> <option value="0.1">10 %</option>
</select> </select>
</div> <!-- stroke --> </td>
</div> <!-- tools --> </tr>
</table>
<div id="color_picker"></div>
<div id="tools_rect" class="tools_flyout">
<div id="tool_square" class="tool_flyout_button" title="Square"></div>
<div id="tool_rect" class="tool_flyout_button" title="Rectangle"></div>
<div id="tool_fhrect" class="tool_flyout_button" title="Free-Hand Rectangle"></div>
</div> </div>
<div id="tools_ellipse" class="tools_flyout"> <div id="tools_bottom_3">
<div id="tool_circle" class="tool_flyout_button" title="Circle"></div> <div id="palette_holder"><div id="palette" title="Click to change fill color, shift-click to change stroke color"></div></div>
<div id="tool_ellipse" class="tool_flyout_button" title="Ellipse"></div> <div id="copyright">SVG-edit v2.2-preAlpha @ <a href="http://svg-edit.googlecode.com/">http://svg-edit.googlecode.com/</a></div>
<div id="tool_fhellipse" class="tool_flyout_button" title="Free-Hand Ellipse"></div>
</div> </div>
</div>
<!-- hidden divs -->
<div id="color_picker"></div>
<div id="tools_rect" class="tools_flyout">
<div id="tool_square" class="tool_flyout_button" title="Square"></div>
<div id="tool_rect" class="tool_flyout_button" title="Rectangle"></div>
<div id="tool_fhrect" class="tool_flyout_button" title="Free-Hand Rectangle"></div>
</div>
<div id="tools_ellipse" class="tools_flyout">
<div id="tool_circle" class="tool_flyout_button" title="Circle"></div>
<div id="tool_ellipse" class="tool_flyout_button" title="Ellipse"></div>
<div id="tool_fhellipse" class="tool_flyout_button" title="Free-Hand Ellipse"></div>
</div>
</div> <!-- tools_container --> </div> <!-- tools_container -->

View File

@ -18,7 +18,7 @@ function svg_edit_setup() {
var textBeingEntered = false; var textBeingEntered = false;
var selectedElement = null; var selectedElement = null;
// called when we've selected a different element // called when we've selected a different element
var selectedChanged = function(window,elem) { var selectedChanged = function(window,elem) {
selectedElement = elem; selectedElement = elem;
@ -35,24 +35,24 @@ function svg_edit_setup() {
updateContextPanel(true); updateContextPanel(true);
} }
// called when any element has changed // called when any element has changed
var elementChanged = function(window,elem) { var elementChanged = function(window,elem) {
// if the element changed was the svg, then it must be a resolution change // if the element changed was the svg, then it must be a resolution change
if (elem && elem.tagName == "svg") { if (elem && elem.tagName == "svg") {
changeResolution(parseInt(elem.getAttribute("width")), changeResolution(parseInt(elem.getAttribute("width")),
parseInt(elem.getAttribute("height"))); parseInt(elem.getAttribute("height")));
} }
// we update the contextual panel with potentially new // we update the contextual panel with potentially new
// positional/sizing information (we DON'T want to update the // positional/sizing information (we DON'T want to update the
// toolbar here as that creates an infinite loop) // toolbar here as that creates an infinite loop)
// also this updates the history buttons // also this updates the history buttons
// we tell it to skip focusing the text control if the // we tell it to skip focusing the text control if the
// text element was previously in focus // text element was previously in focus
updateContextPanel(false); updateContextPanel(false);
} }
// updates the toolbar (colors, opacity, etc) based on the selected element // updates the toolbar (colors, opacity, etc) based on the selected element
function updateToolbar() { function updateToolbar() {
if (selectedElement != null) { if (selectedElement != null) {
@ -78,7 +78,7 @@ function svg_edit_setup() {
$('#stroke_width').val(selectedElement.getAttribute("stroke-width")||1); $('#stroke_width').val(selectedElement.getAttribute("stroke-width")||1);
$('#stroke_style').val(selectedElement.getAttribute("stroke-dasharray")||"none"); $('#stroke_style').val(selectedElement.getAttribute("stroke-dasharray")||"none");
} }
updateToolButtonState(); updateToolButtonState();
} }
@ -136,7 +136,7 @@ function svg_edit_setup() {
break; break;
} }
} }
// update history buttons // update history buttons
if (svgCanvas.getUndoStackSize() > 0) { if (svgCanvas.getUndoStackSize() > 0) {
$('#tool_undo').removeClass( 'tool_button_disabled'); $('#tool_undo').removeClass( 'tool_button_disabled');
@ -166,9 +166,9 @@ function svg_edit_setup() {
$('#palette').append(str); $('#palette').append(str);
var pos = $('#tools_rect_show').position(); var pos = $('#tools_rect_show').position();
$('#tools_rect').css({'left': pos.left+2, 'top': pos.top+2}); $('#tools_rect').css({'left': pos.left+4, 'top': pos.top+40});
pos = $('#tools_ellipse_show').position(); pos = $('#tools_ellipse_show').position();
$('#tools_ellipse').css({'left': pos.left+2, 'top': pos.top+2}); $('#tools_ellipse').css({'left': pos.left+4, 'top': pos.top+40});
$('#stroke_width').change(function(){ $('#stroke_width').change(function(){
svgCanvas.setStrokeWidth(this.options[this.selectedIndex].value); svgCanvas.setStrokeWidth(this.options[this.selectedIndex].value);
@ -205,7 +205,7 @@ function svg_edit_setup() {
$('#rect_radius').change(function(){ $('#rect_radius').change(function(){
svgCanvas.setRectRadius(this.options[this.selectedIndex].value); svgCanvas.setRectRadius(this.options[this.selectedIndex].value);
}); });
$('.attr_changer').change(function() { $('.attr_changer').change(function() {
svgCanvas.changeSelectedAttribute(this.getAttribute("alt"), this.value); svgCanvas.changeSelectedAttribute(this.getAttribute("alt"), this.value);
}); });
@ -342,7 +342,7 @@ function svg_edit_setup() {
var clickSave = function(){ var clickSave = function(){
svgCanvas.save(); svgCanvas.save();
} }
var clickUndo = function(){ var clickUndo = function(){
if (svgCanvas.getUndoStackSize() > 0) if (svgCanvas.getUndoStackSize() > 0)
svgCanvas.undo(); svgCanvas.undo();
@ -521,7 +521,7 @@ function svg_edit_setup() {
$('#tools_rect').mouseleave(function() { $('#tools_rect').mouseleave(function() {
$('#tools_rect').fadeOut(); $('#tools_rect').fadeOut();
}); });
$('#tools_ellipse_show').mousedown(function(evt){ $('#tools_ellipse_show').mousedown(function(evt){
$('#tools_ellipse').show(); $('#tools_ellipse').show();
// this prevents the 'image drag' behavior in Firefox // this prevents the 'image drag' behavior in Firefox
@ -530,23 +530,19 @@ function svg_edit_setup() {
$('#tools_ellipse').mouseleave(function() { $('#tools_ellipse').mouseleave(function() {
$('#tools_ellipse').fadeOut(); $('#tools_ellipse').fadeOut();
}); });
$('.tool_flyout_button').mouseover(function() { $('.tool_flyout_button').mouseover(function() {
$(this).addClass('tool_flyout_button_current'); $(this).addClass('tool_flyout_button_current');
}).mouseout(function() { }).mouseout(function() {
$(this).removeClass('tool_flyout_button_current'); $(this).removeClass('tool_flyout_button_current');
}); });
function changeResolution(x,y) { function changeResolution(x,y) {
$('#resolution').val(x+'x'+y); $('#resolution').val(x+'x'+y);
$('#svgroot').css( { 'width': x, 'height': y } ); $('#svgroot').css( { 'width': x, 'height': y } );
$('#svgcanvas').css( { 'width': x, 'height': y } ); $('#svgcanvas').css( { 'width': x, 'height': y } );
$('div#palette_holder').css('width', x);
$('#context_tools').css('width', x + 65);
$('#tools').css('height', y + 24);
$('#footer').css('width', x + 65);
} }
$('#resolution').change(function(){ $('#resolution').change(function(){
var res = this.value.split('x'); var res = this.value.split('x');
var x = parseInt(res[0]), y = parseInt(res[1]); var x = parseInt(res[0]), y = parseInt(res[1]);

View File

@ -16,7 +16,7 @@ function ChangeElementCommand(elem, attrs, text) {
if (attr == "#text") this.newValues[attr] = elem.textContent; if (attr == "#text") this.newValues[attr] = elem.textContent;
else this.newValues[attr] = elem.getAttribute(attr); else this.newValues[attr] = elem.getAttribute(attr);
} }
this.apply = function() { this.apply = function() {
for( attr in this.newValues ) { for( attr in this.newValues ) {
if (this.newValues[attr]) { if (this.newValues[attr]) {
@ -30,7 +30,7 @@ function ChangeElementCommand(elem, attrs, text) {
} }
return true; return true;
}; };
this.unapply = function() { this.unapply = function() {
for( attr in this.oldValues ) { for( attr in this.oldValues ) {
if (this.oldValues[attr]) { if (this.oldValues[attr]) {
@ -52,7 +52,7 @@ function InsertElementCommand(elem, text) {
this.parent = elem.parentNode; this.parent = elem.parentNode;
this.apply = function() { this.elem = this.parent.insertBefore(this.elem, this.elem.nextSibling); }; this.apply = function() { this.elem = this.parent.insertBefore(this.elem, this.elem.nextSibling); };
this.unapply = function() { this.unapply = function() {
this.parent = this.elem.parentNode; this.parent = this.elem.parentNode;
this.elem = this.elem.parentNode.removeChild(this.elem); this.elem = this.elem.parentNode.removeChild(this.elem);
@ -66,7 +66,7 @@ function RemoveElementCommand(elem, parent, text) {
this.apply = function() { this.apply = function() {
this.parent = this.elem.parentNode; this.parent = this.elem.parentNode;
this.elem = this.parent.removeChild(this.elem); this.elem = this.parent.removeChild(this.elem);
}; };
this.unapply = function() { this.elem = this.parent.insertBefore(this.elem, this.elem.nextSibling); }; this.unapply = function() { this.elem = this.parent.insertBefore(this.elem, this.elem.nextSibling); };
@ -79,12 +79,12 @@ function MoveElementCommand(elem, oldNextSibling, oldParent, text) {
this.oldParent = oldParent; this.oldParent = oldParent;
this.newNextSibling = elem.nextSibling; this.newNextSibling = elem.nextSibling;
this.newParent = elem.parentNode; this.newParent = elem.parentNode;
this.apply = function() { this.apply = function() {
this.elem = this.newParent.insertBefore(this.elem, this.newNextSibling); this.elem = this.newParent.insertBefore(this.elem, this.newNextSibling);
}; };
this.unapply = function() { this.unapply = function() {
this.elem = this.oldParent.insertBefore(this.elem, this.oldNextSibling); this.elem = this.oldParent.insertBefore(this.elem, this.oldNextSibling);
}; };
} }
@ -322,8 +322,8 @@ function SvgCanvas(c)
var events = {}; var events = {};
var undoStackPointer = 0; var undoStackPointer = 0;
var undoStack = []; var undoStack = [];
// FIXME: we MUST compress consecutive text changes to the same element // FIXME: we MUST compress consecutive text changes to the same element
// (right now each keystroke is saved as a separate command that includes the // (right now each keystroke is saved as a separate command that includes the
// entire text contents of the text element) // entire text contents of the text element)
// TODO: consider limiting the history that we store here (need to do some slicing) // TODO: consider limiting the history that we store here (need to do some slicing)
@ -336,7 +336,7 @@ function SvgCanvas(c)
undoStack[undoStack.length] = cmd; undoStack[undoStack.length] = cmd;
undoStackPointer = undoStack.length; undoStackPointer = undoStack.length;
// console.log("after add command, stackPointer=" + undoStackPointer); // console.log("after add command, stackPointer=" + undoStackPointer);
// console.log(undoStack); // console.log(undoStack);
} }
@ -413,8 +413,8 @@ function SvgCanvas(c)
} }
} }
indent--; indent--;
if (!bOneLine) { if (!bOneLine) {
out += "\n"; out += "\n";
for (i=0; i<indent; i++) out += " "; for (i=0; i<indent; i++) out += " ";
} }
out += "</" + elem.nodeName + ">"; out += "</" + elem.nodeName + ">";
@ -427,20 +427,20 @@ function SvgCanvas(c)
function recalculateSelectedDimensions() { function recalculateSelectedDimensions() {
var box = selected.getBBox(); var box = selected.getBBox();
// if we have not moved/resized, then immediately leave // if we have not moved/resized, then immediately leave
if (box.x == selectedBBox.x && box.y == selectedBBox.y && if (box.x == selectedBBox.x && box.y == selectedBBox.y &&
box.width == selectedBBox.width && box.height == selectedBBox.height) { box.width == selectedBBox.width && box.height == selectedBBox.height) {
return; return;
} }
// after this point, we have some change // after this point, we have some change
var remapx = function(x) {return ((x-box.x)/box.width)*selectedBBox.width + selectedBBox.x;} var remapx = function(x) {return ((x-box.x)/box.width)*selectedBBox.width + selectedBBox.x;}
var remapy = function(y) {return ((y-box.y)/box.height)*selectedBBox.height + selectedBBox.y;} var remapy = function(y) {return ((y-box.y)/box.height)*selectedBBox.height + selectedBBox.y;}
var scalew = function(w) {return w*selectedBBox.width/box.width;} var scalew = function(w) {return w*selectedBBox.width/box.width;}
var scaleh = function(h) {return h*selectedBBox.height/box.height;} var scaleh = function(h) {return h*selectedBBox.height/box.height;}
var changes = {}; var changes = {};
selected.removeAttribute("transform"); selected.removeAttribute("transform");
@ -483,7 +483,7 @@ function SvgCanvas(c)
case "circle": case "circle":
changes["cx"] = selected.cx.baseVal.value; changes["cx"] = selected.cx.baseVal.value;
changes["cy"] = selected.cy.baseVal.value; changes["cy"] = selected.cy.baseVal.value;
changes["r"] = selected.r.baseVal.value; changes["r"] = selected.r.baseVal.value;
selected.cx.baseVal.value = remapx(selected.cx.baseVal.value); selected.cx.baseVal.value = remapx(selected.cx.baseVal.value);
selected.cy.baseVal.value = remapy(selected.cy.baseVal.value); selected.cy.baseVal.value = remapy(selected.cy.baseVal.value);
// take the minimum of the new selected box's dimensions for the new circle radius // take the minimum of the new selected box's dimensions for the new circle radius
@ -579,7 +579,7 @@ function SvgCanvas(c)
// in mouseDown : // in mouseDown :
// - when we are in a create mode, the element is added to the canvas // - when we are in a create mode, the element is added to the canvas
// but the action is not recorded until mouseUp // but the action is not recorded until mouseUp
// - when we are in select mode, select the element, remember the position // - when we are in select mode, select the element, remember the position
// and do nothing else // and do nothing else
var mouseDown = function(evt) var mouseDown = function(evt)
{ {
@ -736,7 +736,7 @@ function SvgCanvas(c)
} }
} }
// in mouseMove we do not record any state changes yet (but we do update // in mouseMove we do not record any state changes yet (but we do update
// any elements that are still being created, moved or resized on the canvas) // any elements that are still being created, moved or resized on the canvas)
var mouseMove = function(evt) var mouseMove = function(evt)
{ {
@ -855,10 +855,10 @@ function SvgCanvas(c)
break; break;
} }
// TODO: should we fire the change event here? I'm thinking only fire // TODO: should we fire the change event here? I'm thinking only fire
// this event when the user mouses up. That's when the action (create, // this event when the user mouses up. That's when the action (create,
// move, resize, draw) has finished // move, resize, draw) has finished
// fire changed event // fire changed event
// call("changed", selected); // call("changed", selected);
} }
// in mouseUp, this is where the command is stored for later undo: // in mouseUp, this is where the command is stored for later undo:
@ -1115,7 +1115,7 @@ function SvgCanvas(c)
this.setFontFamily = function(val) { this.setFontFamily = function(val) {
current_font_family = val; current_font_family = val;
this.changeSelectedAttribute("font-family", val); this.changeSelectedAttribute("font-family", val);
} }
this.getFontSize = function() { this.getFontSize = function() {
@ -1147,7 +1147,7 @@ function SvgCanvas(c)
} }
} }
} }
this.changeSelectedAttribute = function(attr, val) { this.changeSelectedAttribute = function(attr, val) {
if (selected != null) { if (selected != null) {
var oldval = (attr == "#text" ? selected.textContent : selected.getAttribute(attr)); var oldval = (attr == "#text" ? selected.textContent : selected.getAttribute(attr));
@ -1208,13 +1208,13 @@ function SvgCanvas(c)
addCommandToHistory(new MoveElementCommand(t, oldNextSibling, oldParent, "bottom")); addCommandToHistory(new MoveElementCommand(t, oldNextSibling, oldParent, "bottom"));
} }
} }
this.moveSelectedElement = function(dx,dy) { this.moveSelectedElement = function(dx,dy) {
if (selected != null) { if (selected != null) {
selectedBBox = selected.getBBox(); selectedBBox = selected.getBBox();
selectedBBox.x += dx; selectedBBox.x += dx;
selectedBBox.y += dy; selectedBBox.y += dy;
recalculateSelectedDimensions(); recalculateSelectedDimensions();
recalculateSelectedOutline(); recalculateSelectedOutline();
} }
@ -1222,16 +1222,16 @@ function SvgCanvas(c)
this.getUndoStackSize = function() { return undoStackPointer; } this.getUndoStackSize = function() { return undoStackPointer; }
this.getRedoStackSize = function() { return undoStack.length - undoStackPointer; } this.getRedoStackSize = function() { return undoStack.length - undoStackPointer; }
this.undo = function() { this.undo = function() {
if (undoStackPointer > 0) { if (undoStackPointer > 0) {
this.selectNone(); this.selectNone();
var cmd = undoStack[--undoStackPointer]; var cmd = undoStack[--undoStackPointer];
cmd.unapply(); cmd.unapply();
call("changed", cmd.elem); call("changed", cmd.elem);
} }
// console.log("after undo, stackPointer=" + undoStackPointer); // console.log("after undo, stackPointer=" + undoStackPointer);
// console.log(undoStack); // console.log(undoStack);
} }
this.redo = function() { this.redo = function() {
if (undoStackPointer < undoStack.length && undoStack.length > 0) { if (undoStackPointer < undoStack.length && undoStack.length > 0) {
@ -1241,7 +1241,7 @@ function SvgCanvas(c)
call("changed", cmd.elem); call("changed", cmd.elem);
} }
// console.log("after redo, stackPointer=" + undoStackPointer); // console.log("after redo, stackPointer=" + undoStackPointer);
// console.log(undoStack); // console.log(undoStack);
} }
} }