summaryrefslogtreecommitdiffstats
path: root/src/persp3d.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2013-09-19 22:33:11 +0000
committerJabiertxof <jtx@jtx.marker.es>2013-09-19 22:33:11 +0000
commit4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7 (patch)
treecaeb924426bcc861badc6fa81318b67460b26d47 /src/persp3d.cpp
parentUpdate to trunk (diff)
parentupdates for cmake (diff)
downloadinkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.tar.gz
inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.zip
Update to trunk
(bzr r11950.1.141)
Diffstat (limited to 'src/persp3d.cpp')
-rw-r--r--src/persp3d.cpp90
1 files changed, 32 insertions, 58 deletions
diff --git a/src/persp3d.cpp b/src/persp3d.cpp
index 2744efb75..a0e6f1c02 100644
--- a/src/persp3d.cpp
+++ b/src/persp3d.cpp
@@ -27,12 +27,6 @@
using Inkscape::DocumentUndo;
-static void persp3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
-static void persp3d_release(SPObject *object);
-static void persp3d_set(SPObject *object, unsigned key, gchar const *value);
-static void persp3d_update(SPObject *object, SPCtx *ctx, guint flags);
-static Inkscape::XML::Node *persp3d_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
-
static void persp3d_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
static void persp3d_update_with_point (Persp3DImpl *persp_impl, Proj::Axis const axis, Proj::Pt2 const &new_image);
@@ -40,6 +34,16 @@ static gchar * persp3d_pt_to_str (Persp3DImpl *persp_impl, Proj::Axis const axis
static int global_counter = 0;
+#include "sp-factory.h"
+
+namespace {
+ SPObject* createPersp3D() {
+ return new Persp3D();
+ }
+
+ bool persp3DRegistered = SPFactory::instance().registerObject("inkscape:persp3d", createPersp3D);
+}
+
/* Constructor/destructor for the internal class */
Persp3DImpl::Persp3DImpl() {
@@ -49,8 +53,6 @@ Persp3DImpl::Persp3DImpl() {
my_counter = global_counter++;
}
-G_DEFINE_TYPE(Persp3D, persp3d, SP_TYPE_OBJECT);
-
static Inkscape::XML::NodeEventVector const persp3d_repr_events = {
NULL, /* child_added */
NULL, /* child_removed */
@@ -59,56 +61,37 @@ static Inkscape::XML::NodeEventVector const persp3d_repr_events = {
NULL /* order_changed */
};
-/**
- * Callback to initialize Persp3D vtable.
- */
-static void persp3d_class_init(Persp3DClass *klass)
-{
- SPObjectClass *sp_object_class = (SPObjectClass *) klass;
- sp_object_class->build = persp3d_build;
- sp_object_class->release = persp3d_release;
- sp_object_class->set = persp3d_set;
- sp_object_class->update = persp3d_update;
- sp_object_class->write = persp3d_write;
+Persp3D::Persp3D() : SPObject() {
+ this->perspective_impl = new Persp3DImpl();
}
-/**
- * Callback to initialize Persp3D object.
- */
-static void
-persp3d_init(Persp3D *persp)
-{
- persp->perspective_impl = new Persp3DImpl();
+Persp3D::~Persp3D() {
}
+
/**
* Virtual build: set persp3d attributes from its associated XML node.
*/
-static void persp3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
-{
- if (((SPObjectClass *) persp3d_parent_class)->build)
- (* ((SPObjectClass *) persp3d_parent_class)->build)(object, document, repr);
+void Persp3D::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPObject::build(document, repr);
- /* calls sp_object_set for the respective attributes */
- // The transformation matrix is updated according to the values we read for the VPs
- object->readAttr( "inkscape:vp_x" );
- object->readAttr( "inkscape:vp_y" );
- object->readAttr( "inkscape:vp_z" );
- object->readAttr( "inkscape:persp3d-origin" );
+ this->readAttr( "inkscape:vp_x" );
+ this->readAttr( "inkscape:vp_y" );
+ this->readAttr( "inkscape:vp_z" );
+ this->readAttr( "inkscape:persp3d-origin" );
if (repr) {
- repr->addListener (&persp3d_repr_events, object);
+ repr->addListener (&persp3d_repr_events, this);
}
}
/**
* Virtual release of Persp3D members before destruction.
*/
-static void persp3d_release(SPObject *object) {
- Persp3D *persp = SP_PERSP3D(object);
- delete persp->perspective_impl;
- object->getRepr()->removeListenerByData(object);
+void Persp3D::release() {
+ delete this->perspective_impl;
+ this->getRepr()->removeListenerByData(this);
}
@@ -117,10 +100,8 @@ static void persp3d_release(SPObject *object) {
*/
// FIXME: Currently we only read the finite positions of vanishing points;
// should we move VPs into their own repr (as it's done for SPStop, e.g.)?
-static void
-persp3d_set(SPObject *object, unsigned key, gchar const *value)
-{
- Persp3DImpl *persp_impl = SP_PERSP3D(object)->perspective_impl;
+void Persp3D::set(unsigned key, gchar const *value) {
+ Persp3DImpl *persp_impl = this->perspective_impl;
switch (key) {
case SP_ATTR_INKSCAPE_PERSP3D_VP_X: {
@@ -152,8 +133,7 @@ persp3d_set(SPObject *object, unsigned key, gchar const *value)
}
}
default: {
- if (((SPObjectClass *) persp3d_parent_class)->set)
- (* ((SPObjectClass *) persp3d_parent_class)->set)(object, key, value);
+ SPObject::set(key, value);
break;
}
}
@@ -169,17 +149,14 @@ persp3d_set(SPObject *object, unsigned key, gchar const *value)
}
}
-static void
-persp3d_update(SPObject *object, SPCtx *ctx, guint flags)
-{
+void Persp3D::update(SPCtx *ctx, guint flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
/* TODO: Should we update anything here? */
}
- if (((SPObjectClass *) persp3d_parent_class)->update)
- ((SPObjectClass *) persp3d_parent_class)->update(object, ctx, flags);
+ SPObject::update(ctx, flags);
}
Persp3D *persp3d_create_xml_element(SPDocument *document, Persp3DImpl *dup) {// if dup is given, copy the attributes over
@@ -238,10 +215,8 @@ Persp3D *persp3d_document_first_persp(SPDocument *document)
/**
* Virtual write: write object attributes to repr.
*/
-static Inkscape::XML::Node *
-persp3d_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
-{
- Persp3DImpl *persp_impl = SP_PERSP3D(object)->perspective_impl;
+Inkscape::XML::Node* Persp3D::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
+ Persp3DImpl *persp_impl = this->perspective_impl;
if ((flags & SP_OBJECT_WRITE_BUILD & SP_OBJECT_WRITE_EXT) && !repr) {
// this is where we end up when saving as plain SVG (also in other circumstances?);
@@ -264,8 +239,7 @@ persp3d_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML:
repr->setAttribute("inkscape:persp3d-origin", str);
}
- if (((SPObjectClass *) persp3d_parent_class)->write)
- (* ((SPObjectClass *) persp3d_parent_class)->write)(object, xml_doc, repr, flags);
+ SPObject::write(xml_doc, repr, flags);
return repr;
}