Fix most of Issue 170: Remove undoable fill/stroke/opacity changes upon creation of elements. Fix setting fill/stroke paint opacity.

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@554 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-09-04 06:11:04 +00:00
parent c6847f23ad
commit c9c771392d
2 changed files with 46 additions and 30 deletions

View File

@ -95,13 +95,15 @@ function svg_edit_setup() {
// update fill color and opacity // update fill color and opacity
var fillColor = selectedElement.getAttribute("fill")||"none"; var fillColor = selectedElement.getAttribute("fill")||"none";
svgCanvas.setFillColor(fillColor); // prevent undo on these canvas changes
svgCanvas.setFillOpacity(fillOpacity); svgCanvas.setFillColor(fillColor, true);
svgCanvas.setFillOpacity(fillOpacity, true);
// update stroke color and opacity // update stroke color and opacity
var strokeColor = selectedElement.getAttribute("stroke")||"none"; var strokeColor = selectedElement.getAttribute("stroke")||"none";
svgCanvas.setStrokeColor(strokeColor); // prevent undo on these canvas changes
svgCanvas.setStrokeOpacity(strokeOpacity); svgCanvas.setStrokeColor(strokeColor, true);
svgCanvas.setStrokeOpacity(strokeOpacity, true);
fillOpacity *= 100; fillOpacity *= 100;
strokeOpacity *= 100; strokeOpacity *= 100;
@ -350,15 +352,19 @@ function svg_edit_setup() {
if (evt.shiftKey) { if (evt.shiftKey) {
strokePaint = paint; strokePaint = paint;
if (svgCanvas.getStrokeColor() != color) {
svgCanvas.setStrokeColor(color); svgCanvas.setStrokeColor(color);
if (color != 'none') { }
if (color != 'none' && svgCanvas.getStrokeOpacity() != 1) {
svgCanvas.setStrokeOpacity(1.0); svgCanvas.setStrokeOpacity(1.0);
$("#stroke_opacity").html("100 %"); $("#stroke_opacity").html("100 %");
} }
} else { } else {
fillPaint = paint; fillPaint = paint;
if (svgCanvas.getFillColor() != color) {
svgCanvas.setFillColor(color); svgCanvas.setFillColor(color);
if (color != 'none') { }
if (color != 'none' && svgCanvas.getFillOpacity() != 1) {
svgCanvas.setFillOpacity(1.0); svgCanvas.setFillOpacity(1.0);
$("#fill_opacity").html("100 %"); $("#fill_opacity").html("100 %");
} }

View File

@ -669,6 +669,7 @@ function BatchCommand(text) {
} }
undoStack.push(cmd); undoStack.push(cmd);
undoStackPointer = undoStack.length; undoStackPointer = undoStack.length;
console.log(undoStack);
}; };
// private functions // private functions
@ -2215,7 +2216,6 @@ function BatchCommand(text) {
keep = true; keep = true;
element = null; element = null;
current_mode = "select"; current_mode = "select";
canvas.setRotationAngle(canvas.getRotationAngle(), true);
var batchCmd = canvas.finishUndoableChange(); var batchCmd = canvas.finishUndoableChange();
if (!batchCmd.isEmpty()) { if (!batchCmd.isEmpty()) {
addCommandToHistory(batchCmd); addCommandToHistory(batchCmd);
@ -2381,9 +2381,10 @@ function BatchCommand(text) {
return cur_properties.stroke; return cur_properties.stroke;
}; };
this.setStrokeColor = function(val) { this.setStrokeColor = function(val,preventUndo) {
cur_shape.stroke = val; cur_shape.stroke = val;
cur_properties.stroke_paint = {type:"solidColor"}; cur_properties.stroke_paint = {type:"solidColor"};
if (!preventUndo)
this.changeSelectedAttribute("stroke", val); this.changeSelectedAttribute("stroke", val);
}; };
@ -2391,7 +2392,7 @@ function BatchCommand(text) {
return cur_properties.fill; return cur_properties.fill;
}; };
this.setFillColor = function(val) { this.setFillColor = function(val,preventUndo) {
cur_properties.fill = val; cur_properties.fill = val;
cur_properties.fill_paint = {type:"solidColor"}; cur_properties.fill_paint = {type:"solidColor"};
// take out any path/line elements when setting fill // take out any path/line elements when setting fill
@ -2403,7 +2404,7 @@ function BatchCommand(text) {
elems.push(elem); elems.push(elem);
} }
} }
if (elems.length > 0) if (elems.length > 0 && !preventUndo)
this.changeSelectedAttribute("fill", val, elems); this.changeSelectedAttribute("fill", val, elems);
}; };
@ -2485,34 +2486,41 @@ function BatchCommand(text) {
}; };
this.setStrokePaint = function(p, addGrad) { this.setStrokePaint = function(p, addGrad) {
cur_properties.stroke_paint = new $.jGraduate.Paint(p); // make a copy
if (cur_properties.stroke_paint.type == "solidColor") { var p = new $.jGraduate.Paint(p);
this.setStrokeColor("#"+cur_properties.stroke_paint.solidColor); if (p.type == "solidColor") {
this.setStrokeColor("#"+p.solidColor);
} }
else if(cur_properties.stroke_paint.type == "linearGradient") { else if(p.type == "linearGradient") {
canvas.strokeGrad = cur_properties.stroke_paint.linearGradient; canvas.strokeGrad = p.linearGradient;
if(addGrad) addGradient(); if(addGrad) addGradient();
} }
else { else {
// console.log("none!"); // console.log("none!");
} }
this.setStrokeOpacity(cur_properties.stroke_paint.alpha/100); this.setStrokeOpacity(p.alpha/100);
// now set the current paint object
cur_properties.stroke_paint = p;
}; };
this.setFillPaint = function(p, addGrad) { this.setFillPaint = function(p, addGrad) {
// copy the incoming paint object // make a copy
cur_properties.fill_paint = new $.jGraduate.Paint(p); var p = new $.jGraduate.Paint(p);
if (cur_properties.fill_paint.type == "solidColor") { if (p.type == "solidColor") {
this.setFillColor("#"+cur_properties.fill_paint.solidColor); this.setFillColor("#"+p.solidColor);
} }
else if(cur_properties.fill_paint.type == "linearGradient") { else if(p.type == "linearGradient") {
canvas.fillGrad = cur_properties.fill_paint.linearGradient; canvas.fillGrad = p.linearGradient;
if(addGrad) addGradient(); if(addGrad) addGradient();
} }
else { else {
// console.log("none!"); // console.log("none!");
} }
this.setFillOpacity(cur_properties.fill_paint.alpha/100); this.setFillOpacity(p.alpha/100);
// now set the current paint object
cur_properties.fill_paint = p;
}; };
this.getStrokeWidth = function() { this.getStrokeWidth = function() {
@ -2549,8 +2557,9 @@ function BatchCommand(text) {
return cur_shape.fill_opacity; return cur_shape.fill_opacity;
}; };
this.setFillOpacity = function(val) { this.setFillOpacity = function(val, preventUndo) {
cur_shape.fill_opacity = val; cur_shape.fill_opacity = val;
if (!preventUndo)
this.changeSelectedAttribute("fill-opacity", val); this.changeSelectedAttribute("fill-opacity", val);
}; };
@ -2558,8 +2567,9 @@ function BatchCommand(text) {
return cur_shape.stroke_opacity; return cur_shape.stroke_opacity;
}; };
this.setStrokeOpacity = function(val) { this.setStrokeOpacity = function(val, preventUndo) {
cur_shape.stroke_opacity = val; cur_shape.stroke_opacity = val;
if (!preventUndo)
this.changeSelectedAttribute("stroke-opacity", val); this.changeSelectedAttribute("stroke-opacity", val);
}; };