summaryrefslogtreecommitdiffstats
path: root/src/layer-fns.cpp
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2006-03-15 22:58:35 +0000
committermental <mental@users.sourceforge.net>2006-03-15 22:58:35 +0000
commit6377ae8ca2e597a43d8e9c0b00c3e3f7caed4258 (patch)
tree9114831a899153b3e39e18cb8fc33ee0fc088dcf /src/layer-fns.cpp
parentreadme for legacy icons (diff)
downloadinkscape-6377ae8ca2e597a43d8e9c0b00c3e3f7caed4258.tar.gz
inkscape-6377ae8ca2e597a43d8e9c0b00c3e3f7caed4258.zip
merged patch #1447043 from Andrius "knutux" R. to create sub-layers
(bzr r251)
Diffstat (limited to 'src/layer-fns.cpp')
-rw-r--r--src/layer-fns.cpp95
1 files changed, 62 insertions, 33 deletions
diff --git a/src/layer-fns.cpp b/src/layer-fns.cpp
index c143336cc..2d58796af 100644
--- a/src/layer-fns.cpp
+++ b/src/layer-fns.cpp
@@ -17,42 +17,10 @@
#include "sp-item-group.h"
#include "xml/repr.h"
#include "algorithms/find-last-if.h"
+#include "layer-fns.h"
namespace Inkscape {
-/**
- * Creates a new layer. Advances to the next layer id indicated
- * by the string "layerNN", then creates a new group object of
- * that id with attribute inkscape:groupmode='layer', and finally
- * appends the new group object to \a root after object \a layer.
- *
- * \pre \a root should be either \a layer or an ancestor of it
- */
-SPObject *create_layer(SPObject *root, SPObject *layer) {
- SPDocument *document=SP_OBJECT_DOCUMENT(root);
-
- static int layer_suffix=1;
- gchar *id=NULL;
- do {
- g_free(id);
- id = g_strdup_printf("layer%d", layer_suffix++);
- } while (document->getObjectById(id));
-
- Inkscape::XML::Node *repr=sp_repr_new("svg:g");
- repr->setAttribute("inkscape:groupmode", "layer");
- repr->setAttribute("id", id);
- g_free(id);
-
- if ( root == layer ) {
- SP_OBJECT_REPR(root)->appendChild(repr);
- } else {
- Inkscape::XML::Node *layer_repr=SP_OBJECT_REPR(layer);
- sp_repr_parent(layer_repr)->addChild(repr, layer_repr);
- }
-
- return document->getObjectByRepr(repr);
-}
-
namespace {
bool is_layer(SPObject &object) {
@@ -60,6 +28,10 @@ bool is_layer(SPObject &object) {
SP_GROUP(&object)->layerMode() == SPGroup::LAYER;
}
+/** Finds the next sibling layer for a \a layer
+ *
+ * @returns NULL if there are no further layers under a parent
+ */
SPObject *next_sibling_layer(SPObject *layer) {
using std::find_if;
@@ -68,6 +40,10 @@ SPObject *next_sibling_layer(SPObject *layer) {
);
}
+/** Finds the previous sibling layer for a \a layer
+ *
+ * @returns NULL if there are no further layers under a parent
+ */
SPObject *previous_sibling_layer(SPObject *layer) {
using Inkscape::Algorithms::find_last_if;
@@ -78,6 +54,10 @@ SPObject *previous_sibling_layer(SPObject *layer) {
return ( sibling != layer ) ? sibling : NULL;
}
+/** Finds the first child of a \a layer
+ *
+ * @returns NULL if layer has no sublayers
+ */
SPObject *first_descendant_layer(SPObject *layer) {
using std::find_if;
@@ -94,6 +74,10 @@ SPObject *first_descendant_layer(SPObject *layer) {
return first_descendant;
}
+/** Finds the last (topmost) child of a \a layer
+ *
+ * @returns NULL if layer has no sublayers
+ */
SPObject *last_child_layer(SPObject *layer) {
using Inkscape::Algorithms::find_last_if;
@@ -172,6 +156,51 @@ SPObject *previous_layer(SPObject *root, SPObject *layer) {
return NULL;
}
+/**
+* Creates a new layer. Advances to the next layer id indicated
+ * by the string "layerNN", then creates a new group object of
+ * that id with attribute inkscape:groupmode='layer', and finally
+ * appends the new group object to \a root after object \a layer.
+ *
+ * \pre \a root should be either \a layer or an ancestor of it
+ */
+SPObject *create_layer(SPObject *root, SPObject *layer, LayerRelativePosition position) {
+ SPDocument *document=SP_OBJECT_DOCUMENT(root);
+
+ static int layer_suffix=1;
+ gchar *id=NULL;
+ do {
+ g_free(id);
+ id = g_strdup_printf("layer%d", layer_suffix++);
+ } while (document->getObjectById(id));
+
+ Inkscape::XML::Node *repr=sp_repr_new("svg:g");
+ repr->setAttribute("inkscape:groupmode", "layer");
+ repr->setAttribute("id", id);
+ g_free(id);
+
+ if ( LPOS_CHILD == position ) {
+ root = layer;
+ SPObject *child_layer = Inkscape::last_child_layer(layer);
+ if ( NULL != child_layer ) {
+ layer = child_layer;
+ }
+ }
+
+ if ( root == layer ) {
+ SP_OBJECT_REPR(root)->appendChild(repr);
+ } else {
+ Inkscape::XML::Node *layer_repr=SP_OBJECT_REPR(layer);
+ sp_repr_parent(layer_repr)->addChild(repr, layer_repr);
+
+ if ( LPOS_BELOW == position ) {
+ SP_ITEM(document->getObjectByRepr(repr))->lowerOne();
+ }
+ }
+
+ return document->getObjectByRepr(repr);
+}
+
}
/*