diff options
| author | Maximilian Albert <maximilian.albert@gmail.com> | 2008-08-18 00:44:51 +0000 |
|---|---|---|
| committer | cilix42 <cilix42@users.sourceforge.net> | 2008-08-18 00:44:51 +0000 |
| commit | a62257d36b6957055ad3ddc0f5573a36f01bdbcc (patch) | |
| tree | 8d11766be4474a0d54ff586f7fa0b5fd93771fbe /src/lpe-tool-context.cpp | |
| parent | Let acceptsNumClicks() distinguish between invalid LPE and valid ones that ex... (diff) | |
| download | inkscape-a62257d36b6957055ad3ddc0f5573a36f01bdbcc.tar.gz inkscape-a62257d36b6957055ad3ddc0f5573a36f01bdbcc.zip | |
Apply a geometric construction directly to selected item if the LPE supports it
(bzr r6678)
Diffstat (limited to 'src/lpe-tool-context.cpp')
| -rw-r--r-- | src/lpe-tool-context.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index 2a6bf5e50..fb252729d 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -239,7 +239,7 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event) bool over_stroke = lc->shape_editor->is_over_stroke(NR::Point(event->button.x, event->button.y), true); g_print ("over_stroke: %s\n", over_stroke ? "true" : "false"); - sp_pen_context_wait_for_LPE_mouse_clicks(lc, type, Effect::acceptsNumClicks(type)); + sp_pen_context_wait_for_LPE_mouse_clicks(lc, type, Inkscape::LivePathEffect::Effect::acceptsNumClicks(type)); // we pass the mouse click on to pen tool as the first click which it should collect ret = ((SPEventContextClass *) lpetool_parent_class)->root_handler(event_context, event); @@ -308,7 +308,11 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event) return ret; } -static int +/* + * Finds the index in the list of geometric subtools corresponding to the given LPE type. + * Returns -1 if no subtool is found. + */ +int lpetool_mode_to_index(Inkscape::LivePathEffect::EffectType const type) { for (int i = 0; i < num_subtools; ++i) { if (lpesubtools[i] == type) { @@ -318,6 +322,24 @@ lpetool_mode_to_index(Inkscape::LivePathEffect::EffectType const type) { return -1; } +/* + * Attempts to perform the construction of the given type (i.e., to apply the corresponding LPE) to + * a single selected item. Returns whether we succeeded. + */ +bool +lpetool_try_construction(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type) +{ + Inkscape::Selection *selection = sp_desktop_selection(lc->desktop); + SPItem *item = selection->singleItem(); + + // TODO: should we check whether type represents a valid geometric construction? + if (item && SP_IS_LPE_ITEM(item) && Inkscape::LivePathEffect::Effect::acceptsNumClicks(type) == 0) { + Inkscape::LivePathEffect::Effect::createAndApply(type, sp_desktop_document(lc->desktop), item); + return true; + } + return false; +} + void lpetool_context_switch_mode(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type) { |
