On 04-06-12 21:15, Chris Mohler wrote:
Hi there.
I thought it would be nice to add a verb to swap fill and stroke, but alas - I can't figure it out. I've pasted my feeble attempts below in case anyone has pointers. I barely dabble in C/C++ so I might be barking up the wrong tree entirely...
Thanks, Chris
Tried adding something like this to verbs: case SP_VERB_SELECTION_SWAP_FILL_STROKE: Inkscape::UI::Widget::SelectedStyle *ss; ss->on_fillstroke_swap(); break;
But get this: ui/widget/selected-style.h:223:10: error: ‘void Inkscape::UI::Widget::SelectedStyle::on_fillstroke_swap()’ is protected verbs.cpp:1136:27: error: within this context
What you're looking at is an event handler. When the user selects "Swap fill and stroke" (from the right-click context menu on the fill/stroke patches in the lower-left corner) this code gets called to do the actual work. Such methods are usually private or protected, which means that (generally speaking) only the class itself can (and should!) access them.
In your case you essentially want to be able to do the same thing, but as a verb. The best way is probably to break out the required functionality and call it from both places, or to move it to the verb (although you probably still want to encapsulate it in a function) and make on_fillstroke_swap use the verb.
Also, the code you wrote would probably generate a null-pointer exception if it would compile (or worse, would do random things). on_fillstroke_swap is a method of SelectedStyle, and actually uses some members of that class. So calling it on an unitialized pointer is not a good idea. You probably have to rethink where you can get the data from (I'm not sure, maybe someone else knows, or you can try grepping, but since the implementation of on_fillstroke_swap eventually seems to set something on the document, my bet is that that would be a good place to start).
Good luck! Seems like a nice project to get started.