Many thanks for this reply! I actually got it done before I saw this last post, but yor suggestions are still a big improvement.
I think you need matrix.c[number], or look up in the transformation dialog, transform tab, how that code extracts the values.
Thanks for this valuable tip! _c in NR::Matrix is private, but it seems the class overrides the [] operator, so you can simply access the values with matrix[number]. Found that in ui/dialog/transformation.cpp.
That's impossible. When you scale or rotate, you change the matrix and thus the position of the origin too, unless you scale or rotate it around that origin. Looks like you need something else.
Misunderstanding again, sorry: I meant the combined transform. If you express a rotation that's not around the origin with a single matrix, then it becomes a rotation around the origin with a translation. So, yes, in that case the origin has to change position too.
I guess to get the origin, you just need to take NR::Point(0,0) and multiply it by that item's accumulated transform. To get the latter, use sp_item_i2doc_affine and convert it to desktop coords with matrix_to_desktop (that's offhand, not tested).
I am doing a manual conversion right now, but your suggestion would clearly be the cleaner solution.
Thank you very much for your continuous advice. The code works for me right now, so I'll probably close the file for the time being. I'll post the diff here in case anyone else should ever be interested in this. It's mainly copy and paste from the _chandle code.
Have a nice day! :-) Gerrit
diff for seltrans.cpp:
*** inkscape-0.45.1/src/seltrans.cpp 2007-01-16 03:46:08.000000000 +0100 --- myhandle_inkscape-0.45.1/src/seltrans.cpp 2007-10-31 13:58:32.000000000 +0100 *************** Inkscape::SelTrans::SelTrans(SPDesktop * *** 90,95 **** --- 90,96 ---- _show_handles(true), _box(NR::Point(0,0), NR::Point(0,0)), _chandle(NULL), + _myhandle(NULL), _stamp_cache(NULL), _message_context(desktop->messageStack()) { *************** Inkscape::SelTrans::~SelTrans() *** 171,176 **** --- 172,181 ---- g_object_unref(G_OBJECT(_chandle)); _chandle = NULL; } + if (_myhandle) { + g_object_unref(G_OBJECT(_myhandle)); + _myhandle = NULL; + }
if (_norm) { gtk_object_destroy(GTK_OBJECT(_norm)); *************** void Inkscape::SelTrans::_updateHandles( *** 471,476 **** --- 476,482 ---- sp_remove_handles(_shandle, 8); sp_remove_handles(_rhandle, 8); sp_remove_handles(&_chandle, 1); + sp_remove_handles(&_myhandle, 1); return; }
*************** void Inkscape::SelTrans::_updateHandles( *** 499,504 **** --- 505,540 ---- G_CALLBACK(sp_sel_trans_handle_click), (gpointer) &handle_center); }
+ // start _myhandle: display a new handle at the origin of the selected object + if ( _myhandle == NULL ) { + _myhandle = sp_knot_new(_desktop, _("Origin of the selection")); + _myhandle->setShape (SP_CTRL_SHAPE_CIRCLE); + _myhandle->setSize (10); + _myhandle->setAnchor (handle_center.anchor); + _myhandle->setMode (SP_CTRL_MODE_XOR); + _myhandle->setFill(0x00000000, 0x00000000, 0x00000000); + _myhandle->setStroke(0x000000ff, 0xff0000b0, 0xff0000b0); + _myhandle->setPixbuf(handles[handle_center.control]); + // We don't want to use the standard knot handler, + //since we don't want this knot to be draggable. + g_signal_handler_disconnect(G_OBJECT(_myhandle->item), _myhandle->_event_handler_id); + sp_knot_update_ctrl(_myhandle); + } + const GSList *itemList = _desktop->selection->itemList(); + // If only one item is selected, move the _myhandle knot + // to the translation values of its global transform. + if( g_slist_length( (GSList*) itemList ) == 1 ) { + SPItem *item = (SPItem*)sp_object_ref(SP_OBJECT(itemList->data), NULL); + NR::Matrix globalTransform = sp_item_i2root_affine( item ); + // Knot needs desktop coordinates (origin at LOWER left corner) + NR::Point point( globalTransform[4], -globalTransform[5]+sp_document_height(sp_desktop_document(_desktop)) ); + sp_knot_moveto(_myhandle, &point); + sp_knot_show(_myhandle); + } + else sp_knot_hide(_myhandle); + // end _myhandle + + sp_remove_handles(&_chandle, 1); if ( _state == STATE_SCALE ) { sp_remove_handles(_rhandle, 8);
diff for seltrans.h:
*** inkscape-0.45.1/src/seltrans.h 2007-01-16 03:46:08.000000000 +0100 --- myhandle_inkscape-0.45.1/src/seltrans.h 2007-10-25 18:27:38.000000000 +0200 *************** private: *** 128,133 **** --- 128,134 ---- SPKnot *_shandle[8]; SPKnot *_rhandle[8]; SPKnot *_chandle; + SPKnot *_myhandle; SPCanvasItem *_norm; SPCanvasItem *_grip; SPCanvasItem *_l[4];
_________________________________________________________________ Discover the new Windows Vista http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QB...