Carl Hetherington a écrit :
My instinct is that you might be better off doing this using additional canvas objects (like you have suggested in some of your comments). In other words, you highlight things by creating a new object to overlay the thing you are highlighting.
I think this would make things much more general; the highlight operation is adding a canvas object, and un-highlight is removing all the "highlight" objects (which you could keep in a list). Otherwise you have a special case for each thing you've highlighted: note which guide line you changed and then change it back, note which grid line(s) you changed and then change them back etc. etc. Also, I think in some cases (e.g. highlighting a snap to a path) you're probably going to want to add new objects (perhaps a little circle, or something) rather than just changing existing ones.
Hi Carl & everyone
I was thinking of using different canvas items, and your comment made me think about it harder :) So I wrote an almost complete (I hope) list of what could be done in order for this highlighting feature to be usable and very open in the future.
Please feel free to comment, I'll have a look at the sources and begin :)
Mtou
I --------------------------------------------------------------------------------------- List of changes to do :
in SPNamedView * a new SPhighlight *o_highlights to handle every highlighting. * a new show_current_highlighting() calling o_highlights to make highlighting item draw on screen * a new reset_highlighting() calling o_highlights to delete every highlight_item
a new class SPhighlight * container for all highlight_groups currently drawn. * a show_all_groups() function - calling all highlight_groups to draw themselves (on the sketch layer or another one ?) - positionning optionnal hint texts to avoid overlap, out of screen, and maybe color similarities with the background - choosing the right colors for the visual feedback of the group depending on where (layer color) and what it is * a hide_all_groups() function, deleting all highlight_groups
a new class SPhighlight_group * prefered color * list of SPhighlight_itemS to draw (segments, dots or hints) * can draw all its items based on their types and delete them * can draw the textual hints, or just some of them if SPhighlight doesn't agree * can give the bbox of textual hints back to SPhighlight for smart placement by the only object who knows everything to show. * can adjust hint placement to respect SPhighlight directives (forbidden bounding boxes on the screen ?, depending on the mouse position) and hints' prefered placement given by the snapping object.
a new class SPhighlight_item * base for all highlight items.
virtual classes from SPhighlight_item * handle specific highlighting parameters * a big draw_highlight() function which instanciate SPCanvasItem objects (old or new ones) * prefered ordering (front/middle/back) ???
* SPhighlight_item_dot - one point - drawing style ("cross", "colored dot", etc...)
* SPhighlight_item_segment - 2 points or a <point/vector> pair - bool for finite or infinite line
* SPhighlight_item_hint - text - prefered placement (along line, horizontal, at point, etc...)
in *-snapper objects * every snapped-to object (guide, gridline, object dot, object segment, object curve) adds himself an SPhighlight_item_xxxx to the namedview's o_highlights when asked to by snapping functions from snap.cpp, because it's the only one who knows what to highlight, what for, and what to write as an hint and where.