summaryrefslogtreecommitdiffstats
path: root/src/box3d-side.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/box3d-side.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/box3d-side.cpp')
-rw-r--r--src/box3d-side.cpp130
1 files changed, 58 insertions, 72 deletions
diff --git a/src/box3d-side.cpp b/src/box3d-side.cpp
index fc18207b0..d3d3b82a2 100644
--- a/src/box3d-side.cpp
+++ b/src/box3d-side.cpp
@@ -24,54 +24,35 @@
#include "desktop-style.h"
#include "box3d.h"
-struct SPPathClass;
-
-static void box3d_side_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
-static Inkscape::XML::Node *box3d_side_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
-static void box3d_side_set (SPObject *object, unsigned int key, const gchar *value);
-static void box3d_side_update (SPObject *object, SPCtx *ctx, guint flags);
-
-static void box3d_side_set_shape (SPShape *shape);
-
static void box3d_side_compute_corner_ids(Box3DSide *side, unsigned int corners[4]);
-G_DEFINE_TYPE(Box3DSide, box3d_side, SP_TYPE_SHAPE);
+#include "sp-factory.h"
-static void box3d_side_class_init(Box3DSideClass *klass)
-{
- SPObjectClass *sp_object_class = reinterpret_cast<SPObjectClass *>(klass);
- SPShapeClass *shape_class = reinterpret_cast<SPShapeClass *>(klass);
+namespace {
+ SPObject* createBox3DSide() {
+ return new Box3DSide();
+ }
- sp_object_class->build = box3d_side_build;
- sp_object_class->write = box3d_side_write;
- sp_object_class->set = box3d_side_set;
- sp_object_class->update = box3d_side_update;
+ bool box3DSideRegistered = SPFactory::instance().registerObject("inkscape:box3dside", createBox3DSide);
+}
- shape_class->set_shape = box3d_side_set_shape;
+Box3DSide::Box3DSide() : SPPolygon() {
+ this->dir1 = Box3D::NONE;
+ this->dir2 = Box3D::NONE;
+ this->front_or_rear = Box3D::FRONT;
}
-static void
-box3d_side_init (Box3DSide * side)
-{
- side->dir1 = Box3D::NONE;
- side->dir2 = Box3D::NONE;
- side->front_or_rear = Box3D::FRONT;
+Box3DSide::~Box3DSide() {
}
-static void box3d_side_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr)
-{
- if ((SP_OBJECT_CLASS(box3d_side_parent_class))->build) {
- (SP_OBJECT_CLASS(box3d_side_parent_class))->build(object, document, repr);
- }
+void Box3DSide::build(SPDocument * document, Inkscape::XML::Node * repr) {
+ SPPolygon::build(document, repr);
- object->readAttr( "inkscape:box3dsidetype" );
+ this->readAttr( "inkscape:box3dsidetype" );
}
-static Inkscape::XML::Node *
-box3d_side_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
-{
- Box3DSide *side = SP_BOX3D_SIDE (object);
+Inkscape::XML::Node* Box3DSide::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
// this is where we end up when saving as plain SVG (also in other circumstances?)
// thus we don' set "sodipodi:type" so that the box is only saved as an ordinary svg:path
@@ -79,32 +60,29 @@ box3d_side_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::
}
if (flags & SP_OBJECT_WRITE_EXT) {
- sp_repr_set_int(repr, "inkscape:box3dsidetype", side->dir1 ^ side->dir2 ^ side->front_or_rear);
+ sp_repr_set_int(repr, "inkscape:box3dsidetype", this->dir1 ^ this->dir2 ^ this->front_or_rear);
}
- static_cast<SPShape *>(object)->setShape();
+ this->set_shape();
/* Duplicate the path */
- SPCurve const *curve = (SP_SHAPE(object))->_curve;
+ SPCurve const *curve = this->_curve;
+
//Nulls might be possible if this called iteratively
if ( !curve ) {
return NULL;
}
+
char *d = sp_svg_write_path ( curve->get_pathvector() );
repr->setAttribute("d", d);
g_free (d);
- if ((SP_OBJECT_CLASS(box3d_side_parent_class))->write)
- (SP_OBJECT_CLASS(box3d_side_parent_class))->write (object, xml_doc, repr, flags);
+ SPPolygon::write(xml_doc, repr, flags);
return repr;
}
-static void
-box3d_side_set (SPObject *object, unsigned int key, const gchar *value)
-{
- Box3DSide *side = SP_BOX3D_SIDE (object);
-
+void Box3DSide::set(unsigned int key, const gchar* value) {
// TODO: In case the box was recreated (by undo, e.g.) we need to recreate the path
// (along with other info?) from the parent box.
@@ -117,26 +95,25 @@ box3d_side_set (SPObject *object, unsigned int key, const gchar *value)
if (!Box3D::is_face_id(desc)) {
g_print ("desc is not a face id: =%s=\n", value);
}
+
g_return_if_fail (Box3D::is_face_id (desc));
+
Box3D::Axis plane = (Box3D::Axis) (desc & 0x7);
plane = (Box3D::is_plane(plane) ? plane : Box3D::orth_plane_or_axis(plane));
- side->dir1 = Box3D::extract_first_axis_direction(plane);
- side->dir2 = Box3D::extract_second_axis_direction(plane);
- side->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
+ this->dir1 = Box3D::extract_first_axis_direction(plane);
+ this->dir2 = Box3D::extract_second_axis_direction(plane);
+ this->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
break;
default:
- if ((SP_OBJECT_CLASS(box3d_side_parent_class))->set)
- (SP_OBJECT_CLASS(box3d_side_parent_class))->set (object, key, value);
+ SPPolygon::set(key, value);
break;
}
}
-static void
-box3d_side_update (SPObject *object, SPCtx *ctx, guint flags)
-{
+void Box3DSide::update(SPCtx* ctx, guint flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore
}
@@ -144,11 +121,11 @@ box3d_side_update (SPObject *object, SPCtx *ctx, guint flags)
if (flags & (SP_OBJECT_MODIFIED_FLAG |
SP_OBJECT_STYLE_MODIFIED_FLAG |
SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
- static_cast<SPShape *>(object)->setShape ();
+
+ this->set_shape();
}
- if ((SP_OBJECT_CLASS(box3d_side_parent_class))->update)
- (SP_OBJECT_CLASS(box3d_side_parent_class))->update (object, ctx, flags);
+ SPPolygon::update(ctx, flags);
}
/* Create a new Box3DSide and append it to the parent box */
@@ -173,30 +150,30 @@ int Box3DSide::getFaceId()
void
box3d_side_position_set (Box3DSide *side) {
- box3d_side_set_shape (SP_SHAPE (side));
+ side->set_shape();
// This call is responsible for live update of the sides during the initial drag
side->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
-void
-box3d_side_set_shape (SPShape *shape)
-{
- Box3DSide *side = SP_BOX3D_SIDE (shape);
- if (!side->document->getRoot()) {
+void Box3DSide::set_shape() {
+ if (!this->document->getRoot()) {
// avoid a warning caused by sp_document_height() (which is called from sp_item_i2d_affine() below)
// when reading a file containing 3D boxes
return;
}
- SPObject *parent = side->parent;
+ SPObject *parent = this->parent;
+
if (!SP_IS_BOX3D(parent)) {
- g_warning ("Parent of 3D box side is not a 3D box.\n");
+ g_warning("Parent of 3D box side is not a 3D box.\n");
return;
}
+
SPBox3D *box = SP_BOX3D(parent);
- Persp3D *persp = box3d_side_perspective(side);
+ Persp3D *persp = box3d_side_perspective(this);
+
if (!persp) {
return;
}
@@ -207,7 +184,7 @@ box3d_side_set_shape (SPShape *shape)
// resulting path.
unsigned int corners[4];
- box3d_side_compute_corner_ids(side, corners);
+ box3d_side_compute_corner_ids(this, corners);
SPCurve *c = new SPCurve();
@@ -226,17 +203,21 @@ box3d_side_set_shape (SPShape *shape)
c->lineto(box3d_get_corner_screen(box, corners[3]));
c->closepath();
- /* Reset the shape'scurve to the "original_curve"
+ /* Reset the this'scurve to the "original_curve"
* This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/
- shape->setCurveInsync( c, TRUE);
- if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) {
+ this->setCurveInsync( c, TRUE);
+
+ if (sp_lpe_item_has_path_effect(this) && sp_lpe_item_path_effects_enabled(this)) {
SPCurve *c_lpe = c->copy();
- bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe);
+ bool success = sp_lpe_item_perform_path_effect(this, c_lpe);
+
if (success) {
- shape->setCurveInsync( c_lpe, TRUE);
+ this->setCurveInsync(c_lpe, TRUE);
}
+
c_lpe->unref();
}
+
c->unref();
}
@@ -244,19 +225,24 @@ gchar *box3d_side_axes_string(Box3DSide *side)
{
GString *pstring = g_string_new("");
g_string_printf (pstring, "%s", Box3D::string_from_axes ((Box3D::Axis) (side->dir1 ^ side->dir2)));
+
switch ((Box3D::Axis) (side->dir1 ^ side->dir2)) {
case Box3D::XY:
g_string_append_printf (pstring, (side->front_or_rear == Box3D::FRONT) ? "front" : "rear");
break;
+
case Box3D::XZ:
g_string_append_printf (pstring, (side->front_or_rear == Box3D::FRONT) ? "top" : "bottom");
break;
+
case Box3D::YZ:
g_string_append_printf (pstring, (side->front_or_rear == Box3D::FRONT) ? "right" : "left");
break;
+
default:
break;
}
+
return pstring->str;
}