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

View File

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