Move getLayerVisibility() and getLayerOpacity() into Drawing and some tests
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1942 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
3e9f1747ff
commit
4190990d69
|
@ -363,4 +363,49 @@ svgedit.draw.Drawing.prototype.createLayer = function(name) {
|
||||||
return new_layer;
|
return new_layer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Function: svgedit.draw.Drawing.getLayerVisibility
|
||||||
|
// Returns whether the layer is visible. If the layer name is not valid, then this function
|
||||||
|
// returns false.
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
// layername - the name of the layer which you want to query.
|
||||||
|
//
|
||||||
|
// Returns:
|
||||||
|
// The visibility state of the layer, or false if the layer name was invalid.
|
||||||
|
svgedit.draw.Drawing.prototype.getLayerVisibility = function(layername) {
|
||||||
|
// find the layer
|
||||||
|
var layer = null;
|
||||||
|
for (var i = 0; i < this.getNumLayers(); ++i) {
|
||||||
|
if (this.getLayerName(i) == layername) {
|
||||||
|
layer = this.all_layers[i][1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!layer) return false;
|
||||||
|
return (layer.getAttribute('display') != 'none');
|
||||||
|
};
|
||||||
|
|
||||||
|
// Function: svgedit.draw.Drawing.getLayerOpacity
|
||||||
|
// Returns the opacity of the given layer. If the input name is not a layer, null is returned.
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
// layername - name of the layer on which to get the opacity
|
||||||
|
//
|
||||||
|
// Returns:
|
||||||
|
// The opacity value of the given layer. This will be a value between 0.0 and 1.0, or null
|
||||||
|
// if layername is not a valid layer
|
||||||
|
svgedit.draw.Drawing.prototype.getLayerOpacity = function(layername) {
|
||||||
|
for (var i = 0; i < this.getNumLayers(); ++i) {
|
||||||
|
if (this.getLayerName(i) == layername) {
|
||||||
|
var g = this.all_layers[i][1];
|
||||||
|
var opacity = g.getAttribute('opacity');
|
||||||
|
if (!opacity) {
|
||||||
|
opacity = '1.0';
|
||||||
|
}
|
||||||
|
return parseFloat(opacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -6994,8 +6994,9 @@ this.cloneLayer = function(name) {
|
||||||
var layer_title = svgdoc.createElementNS(svgns, "title");
|
var layer_title = svgdoc.createElementNS(svgns, "title");
|
||||||
layer_title.textContent = name;
|
layer_title.textContent = name;
|
||||||
new_layer.appendChild(layer_title);
|
new_layer.appendChild(layer_title);
|
||||||
$(current_drawing.current_layer).after(new_layer);
|
var current_layer = getCurrentDrawing().getCurrentLayer();
|
||||||
var childs = current_drawing.current_layer.childNodes;
|
$(current_layer).after(new_layer);
|
||||||
|
var childs = current_layer.childNodes;
|
||||||
for(var i = 0; i < childs.length; i++) {
|
for(var i = 0; i < childs.length; i++) {
|
||||||
var ch = childs[i];
|
var ch = childs[i];
|
||||||
if(ch.localName == 'title') continue;
|
if(ch.localName == 'title') continue;
|
||||||
|
@ -7160,16 +7161,7 @@ this.setCurrentLayerPosition = function(newpos) {
|
||||||
// Returns:
|
// Returns:
|
||||||
// The visibility state of the layer, or false if the layer name was invalid.
|
// The visibility state of the layer, or false if the layer name was invalid.
|
||||||
this.getLayerVisibility = function(layername) {
|
this.getLayerVisibility = function(layername) {
|
||||||
// find the layer
|
return getCurrentDrawing().getLayerVisibility(layername);
|
||||||
var layer = null;
|
|
||||||
for (var i = 0; i < current_drawing.getNumLayers(); ++i) {
|
|
||||||
if (current_drawing.getLayerName(i) == layername) {
|
|
||||||
layer = current_drawing.all_layers[i][1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!layer) return false;
|
|
||||||
return (layer.getAttribute("display") != "none");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: setLayerVisibility
|
// Function: setLayerVisibility
|
||||||
|
@ -7308,18 +7300,7 @@ this.mergeAllLayers = function() {
|
||||||
// The opacity value of the given layer. This will be a value between 0.0 and 1.0, or null
|
// The opacity value of the given layer. This will be a value between 0.0 and 1.0, or null
|
||||||
// if layername is not a valid layer
|
// if layername is not a valid layer
|
||||||
this.getLayerOpacity = function(layername) {
|
this.getLayerOpacity = function(layername) {
|
||||||
for (var i = 0; i < current_drawing.getNumLayers(); ++i) {
|
return getCurrentDrawing().getLayerOpacity(layername);
|
||||||
if (current_drawing.getLayerName(i) == layername) {
|
|
||||||
var g = current_drawing.all_layers[i][1];
|
|
||||||
var opacity = g.getAttribute("opacity");
|
|
||||||
if (!opacity) {
|
|
||||||
opacity = "1.0";
|
|
||||||
}
|
|
||||||
return parseFloat(opacity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: setLayerOpacity
|
// Function: setLayerOpacity
|
||||||
|
|
|
@ -364,6 +364,7 @@
|
||||||
|
|
||||||
var drawing = new svgedit.draw.Drawing(svg);
|
var drawing = new svgedit.draw.Drawing(svg);
|
||||||
setupSvgWith3Layers(svg);
|
setupSvgWith3Layers(svg);
|
||||||
|
drawing.identifyLayers();
|
||||||
|
|
||||||
ok(drawing.createLayer);
|
ok(drawing.createLayer);
|
||||||
equals(typeof drawing.createLayer, typeof function(){});
|
equals(typeof drawing.createLayer, typeof function(){});
|
||||||
|
@ -377,6 +378,34 @@
|
||||||
|
|
||||||
cleanupSvg(svg);
|
cleanupSvg(svg);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test getLayerVisibility()', function() {
|
||||||
|
expect(5);
|
||||||
|
|
||||||
|
var drawing = new svgedit.draw.Drawing(svg);
|
||||||
|
setupSvgWith3Layers(svg);
|
||||||
|
drawing.identifyLayers();
|
||||||
|
|
||||||
|
ok(drawing.getLayerVisibility);
|
||||||
|
equals(typeof drawing.getLayerVisibility, typeof function(){});
|
||||||
|
ok(drawing.getLayerVisibility(LAYER1));
|
||||||
|
ok(drawing.getLayerVisibility(LAYER2));
|
||||||
|
ok(drawing.getLayerVisibility(LAYER3));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Test getLayerOpacity()', function() {
|
||||||
|
expect(5);
|
||||||
|
|
||||||
|
var drawing = new svgedit.draw.Drawing(svg);
|
||||||
|
setupSvgWith3Layers(svg);
|
||||||
|
drawing.identifyLayers();
|
||||||
|
|
||||||
|
ok(drawing.getLayerOpacity);
|
||||||
|
equals(typeof drawing.getLayerOpacity, typeof function(){});
|
||||||
|
ok(drawing.getLayerOpacity(LAYER1) == 1.0);
|
||||||
|
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
|
||||||
|
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue