summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2012-08-19 20:59:52 +0000
committerMarkus Engel <markus.engel@tum.de>2012-08-19 20:59:52 +0000
commit37eb84dcfa0f0bb84f5e62303ef7288ee922b64d (patch)
tree4cb7a0c2649307cb87f8adb1de45785bb93bc961
parentAdded "virtual pad" to (diff)
downloadinkscape-37eb84dcfa0f0bb84f5e62303ef7288ee922b64d.tar.gz
inkscape-37eb84dcfa0f0bb84f5e62303ef7288ee922b64d.zip
Added "virtual pad" to SPImage.
(bzr r11608.1.25)
-rw-r--r--src/sp-image.cpp156
-rw-r--r--src/sp-image.h31
2 files changed, 147 insertions, 40 deletions
diff --git a/src/sp-image.cpp b/src/sp-image.cpp
index 07885ff4d..15f565bc4 100644
--- a/src/sp-image.cpp
+++ b/src/sp-image.cpp
@@ -602,8 +602,19 @@ static void sp_image_class_init( SPImageClass * klass )
item_class->set_transform = sp_image_set_transform;
}
+CImage::CImage(SPImage* image) : CItem(image) {
+ this->spimage = image;
+}
+
+CImage::~CImage() {
+}
+
static void sp_image_init( SPImage *image )
{
+ image->cimage = new CImage(image);
+ image->citem = image->cimage;
+ image->cobject = image->cimage;
+
image->x.unset();
image->y.unset();
image->width.unset();
@@ -624,11 +635,10 @@ static void sp_image_init( SPImage *image )
image->lastMod = 0;
}
-static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr )
-{
- if (((SPObjectClass *) parent_class)->build) {
- ((SPObjectClass *) parent_class)->build (object, document, repr);
- }
+void CImage::onBuild(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPImage* object = this->spimage;
+
+ CItem::onBuild(document, repr);
object->readAttr( "xlink:href" );
object->readAttr( "x" );
@@ -642,8 +652,14 @@ static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XM
document->addResource("image", object);
}
-static void sp_image_release( SPObject *object )
+static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr )
{
+ ((SPImage*)object)->cimage->onBuild(document, repr);
+}
+
+void CImage::onRelease() {
+ SPImage* object = this->spimage;
+
SPImage *image = SP_IMAGE(object);
if (object->document) {
@@ -677,13 +693,18 @@ static void sp_image_release( SPObject *object )
image->curve = image->curve->unref();
}
- if (((SPObjectClass *) parent_class)->release) {
- ((SPObjectClass *) parent_class)->release (object);
- }
+ CItem::onRelease();
}
-static void sp_image_set( SPObject *object, unsigned int key, const gchar *value )
+static void sp_image_release( SPObject *object )
{
+ ((SPImage*)object)->cimage->onRelease();
+
+}
+
+void CImage::onSet(unsigned int key, const gchar* value) {
+ SPImage* object = this->spimage;
+
SPImage *image = SP_IMAGE (object);
switch (key) {
@@ -796,22 +817,25 @@ static void sp_image_set( SPObject *object, unsigned int key, const gchar *value
break;
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
default:
- if (((SPObjectClass *) (parent_class))->set)
- ((SPObjectClass *) (parent_class))->set (object, key, value);
+ CItem::onSet(key, value);
break;
}
sp_image_set_curve(image); //creates a curve at the image's boundary for snapping
}
-static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags )
+static void sp_image_set( SPObject *object, unsigned int key, const gchar *value )
{
+ ((SPImage*)object)->cimage->onSet(key, value);
+}
+
+void CImage::onUpdate(SPCtx *ctx, unsigned int flags) {
+ SPImage* object = this->spimage;
+
SPImage *image = SP_IMAGE(object);
SPDocument *doc = object->document;
- if (((SPObjectClass *) (parent_class))->update) {
- ((SPObjectClass *) (parent_class))->update (object, ctx, flags);
- }
+ CItem::onUpdate(ctx, flags);
if (flags & SP_IMAGE_HREF_MODIFIED_FLAG) {
if (image->pixbuf) {
@@ -1009,13 +1033,22 @@ static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags )
sp_image_update_canvas_image ((SPImage *) object);
}
-static void sp_image_modified( SPObject *object, unsigned int flags )
+static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags )
{
+ ((SPImage*)object)->cimage->onUpdate(ctx, flags);
+}
+
+void CImage::onModified(unsigned int flags) {
+ SPImage* object = this->spimage;
+
SPImage *image = SP_IMAGE (object);
- if (((SPObjectClass *) (parent_class))->modified) {
- (* ((SPObjectClass *) (parent_class))->modified) (object, flags);
- }
+ // CPPIFY: This doesn't make no sense.
+ // CObject::onModified is pure and CItem doesn't override this method. What was the idea behind these lines?
+// if (((SPObjectClass *) (parent_class))->modified) {
+// (* ((SPObjectClass *) (parent_class))->modified) (object, flags);
+// }
+// CItem::onModified(flags);
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
for (SPItemView *v = image->display; v != NULL; v = v->next) {
@@ -1025,8 +1058,14 @@ static void sp_image_modified( SPObject *object, unsigned int flags )
}
}
-static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags )
+static void sp_image_modified( SPObject *object, unsigned int flags )
{
+ ((SPImage*)object)->cimage->onModified(flags);
+}
+
+Inkscape::XML::Node *CImage::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) {
+ SPImage* object = this->spimage;
+
SPImage *image = SP_IMAGE (object);
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
@@ -1056,27 +1095,37 @@ static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Doc
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
- if (((SPObjectClass *) (parent_class))->write) {
- ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags);
- }
+ CItem::onWrite(xml_doc, repr, flags);
return repr;
}
-static Geom::OptRect sp_image_bbox( SPItem const *item,Geom::Affine const &transform, SPItem::BBoxType /*type*/ )
+static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags )
{
- SPImage const &image = *SP_IMAGE(item);
- Geom::OptRect bbox;
+ return ((SPImage*)object)->cimage->onWrite(xml_doc, repr, flags);
+}
- if ((image.width.computed > 0.0) && (image.height.computed > 0.0)) {
- bbox = Geom::Rect::from_xywh(image.x.computed, image.y.computed, image.width.computed, image.height.computed);
- *bbox *= transform;
- }
- return bbox;
+Geom::OptRect CImage::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) {
+ SPImage* item = this->spimage;
+
+ SPImage const &image = *SP_IMAGE(item);
+ Geom::OptRect bbox;
+
+ if ((image.width.computed > 0.0) && (image.height.computed > 0.0)) {
+ bbox = Geom::Rect::from_xywh(image.x.computed, image.y.computed, image.width.computed, image.height.computed);
+ *bbox *= transform;
+ }
+ return bbox;
}
-static void sp_image_print( SPItem *item, SPPrintContext *ctx )
+static Geom::OptRect sp_image_bbox( SPItem const *item,Geom::Affine const &transform, SPItem::BBoxType type)
{
+ return ((SPImage*)item)->cimage->onBbox(transform, type);
+}
+
+void CImage::onPrint(SPPrintContext *ctx) {
+ SPImage* item = this->spimage;
+
SPImage *image = SP_IMAGE(item);
if (image->pixbuf && (image->width.computed > 0.0) && (image->height.computed > 0.0) ) {
@@ -1122,8 +1171,14 @@ static void sp_image_print( SPItem *item, SPPrintContext *ctx )
}
}
-static gchar *sp_image_description( SPItem *item )
+static void sp_image_print( SPItem *item, SPPrintContext *ctx )
{
+ ((SPImage*)item)->cimage->onPrint(ctx);
+}
+
+gchar* CImage::onDescription() {
+ SPImage* item = this->spimage;
+
SPImage *image = SP_IMAGE(item);
char *href_desc;
if (image->href) {
@@ -1145,8 +1200,14 @@ static gchar *sp_image_description( SPItem *item )
return ret;
}
-static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &drawing, unsigned int /*key*/, unsigned int /*flags*/ )
+static gchar *sp_image_description( SPItem *item )
{
+ return ((SPImage*)item)->cimage->onDescription();
+}
+
+Inkscape::DrawingItem* CImage::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
+ SPImage* item = this->spimage;
+
SPImage * image = SP_IMAGE(item);
Inkscape::DrawingImage *ai = new Inkscape::DrawingImage(drawing);
@@ -1155,6 +1216,11 @@ static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &dr
return ai;
}
+static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags )
+{
+ return ((SPImage*)item)->cimage->onShow(drawing, key, flags);
+}
+
/*
* utility function to try loading image from href
*
@@ -1279,8 +1345,9 @@ static void sp_image_update_canvas_image(SPImage *image)
}
}
-static void sp_image_snappoints( SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs )
-{
+void CImage::onSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
+ SPImage* item = this->spimage;
+
/* An image doesn't have any nodes to snap, but still we want to be able snap one image
to another. Therefore we will create some snappoints at the corner, similar to a rect. If
the image is rotated, then the snappoints will rotate with it. Again, just like a rect.
@@ -1310,13 +1377,19 @@ static void sp_image_snappoints( SPItem const *item, std::vector<Inkscape::SnapC
}
}
+static void sp_image_snappoints( SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs )
+{
+ ((SPImage*)item)->cimage->onSnappoints(p, snapprefs);
+}
+
/*
* Initially we'll do:
* Transform x, y, set x, y, clear translation
*/
-static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xform )
-{
+Geom::Affine CImage::onSetTransform(Geom::Affine const &xform) {
+ SPImage* item = this->spimage;
+
SPImage *image = SP_IMAGE(item);
/* Calculate position in parent coords. */
@@ -1355,6 +1428,11 @@ static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xf
return ret;
}
+static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xform )
+{
+ return ((SPImage*)item)->cimage->onSetTransform(xform);
+}
+
static GdkPixbuf *sp_image_repr_read_dataURI( const gchar * uri_data )
{
GdkPixbuf * pixbuf = NULL;
diff --git a/src/sp-image.h b/src/sp-image.h
index c657d0a2f..c6d36e7de 100644
--- a/src/sp-image.h
+++ b/src/sp-image.h
@@ -22,6 +22,7 @@
class SPImage;
class SPImageClass;
+class CImage;
/* SPImage */
@@ -32,7 +33,10 @@ class SPImageClass;
#define SP_IMAGE_HREF_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A
-struct SPImage : public SPItem {
+class SPImage : public SPItem {
+public:
+ CImage* cimage;
+
SVGLength x;
SVGLength y;
SVGLength width;
@@ -65,6 +69,31 @@ struct SPImageClass {
SPItemClass parent_class;
};
+
+class CImage : public CItem {
+public:
+ CImage(SPImage* image);
+ virtual ~CImage();
+
+ virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr);
+ virtual void onRelease();
+ virtual void onSet(unsigned int key, gchar const* value);
+ virtual void onUpdate(SPCtx *ctx, guint flags);
+ virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
+ virtual void onModified(unsigned int flags);
+
+ virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType type);
+ virtual void onPrint(SPPrintContext *ctx);
+ virtual gchar* onDescription();
+ virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags);
+ virtual void onSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
+ virtual Geom::Affine onSetTransform(Geom::Affine const &transform);
+
+protected:
+ SPImage* spimage;
+};
+
+
GType sp_image_get_type (void);
/* Return duplicate of curve or NULL */