diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-08-08 20:44:16 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-08-08 20:44:16 +0400 |
commit | bd3ec606517f0ca02d503a1856963b0a2ddc32e1 (patch) | |
tree | 4251dbafb08ca1c88dd1cd5613fa2f623d251dc3 /source | |
parent | a1693168f24c818e3902bd95352aa0c5fb3b7d1c (diff) |
Search option for adding nodes.
The 'Add' menu in the node editor now has an option 'Search' at the top, which opens a separate popup for searching node types by name.
The operator for this is implemented completely in Python (this could also be done for the regular menu-based Add options in the future). There are a few necessary extensions to the RNA as well:
* The View2D struct in regions is now exposed. Currently only contains converter functions for coordinates from the region to the view (i.e. scrolled and zoomed view space). Used for converting mouse location to node space.
* The SpaceNode exposes the existing 'cursor_location' for operators to store mouse position beyond invoke calls. Not used for anything else (transforms) so far.
* The edit_tree in SpaceNode is also exposed, this is needed for operators to work correctly inside node groups.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_node/node_header.c | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_screen.c | 66 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 14 | ||||
-rw-r--r-- | source/blenderplayer/bad_level_call_stubs/stubs.c | 4 |
4 files changed, 86 insertions, 1 deletions
diff --git a/source/blender/editors/space_node/node_header.c b/source/blender/editors/space_node/node_header.c index 27ee6006327..b6bf8d77732 100644 --- a/source/blender/editors/space_node/node_header.c +++ b/source/blender/editors/space_node/node_header.c @@ -235,6 +235,9 @@ static void node_menu_add(const bContext *C, Menu *menu) if (!snode->nodetree) uiLayoutSetActive(layout, FALSE); + uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT); + uiItemO(layout, "Search ...", 0, "NODE_OT_add_search"); + if (ntreetype && ntreetype->foreach_nodeclass) ntreetype->foreach_nodeclass(scene, layout, node_menu_add_foreach_cb); } diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index d405cba6607..a6d4e473df4 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -57,6 +57,8 @@ EnumPropertyItem region_type_items[] = { #include "BKE_global.h" +#include "UI_view2d.h" + static void rna_Screen_scene_set(PointerRNA *ptr, PointerRNA value) { bScreen *sc = (bScreen *)ptr->data; @@ -138,6 +140,19 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr) } } +void rna_View2D_region_to_view(struct View2D *v2d, int x, int y, float result[2]) +{ + UI_view2d_region_to_view(v2d, x, y, &result[0], &result[1]); +} + +void rna_View2D_view_to_region(struct View2D *v2d, float x, float y, int clip, int result[2]) +{ + if (clip) + UI_view2d_view_to_region(v2d, x, y, &result[0], &result[1]); + else + UI_view2d_to_region_no_clip(v2d, x, y, &result[0], &result[1]); +} + #else /* Area.spaces */ @@ -220,6 +235,50 @@ static void rna_def_area(BlenderRNA *brna) RNA_def_string(func, "text", NULL, 0, "Text", "New string for the header, no argument clears the text"); } +static void rna_def_view2d_api(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *parm; + + static const float view_default[2] = {0.0f, 0.0f}; + static const int region_default[2] = {0.0f, 0.0f}; + + func = RNA_def_function(srna, "region_to_view", "rna_View2D_region_to_view"); + RNA_def_function_ui_description(func, "Transform region coordinates to 2D view"); + parm = RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "x", "Region x coordinate", -10000, 10000); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "y", "Region y coordinate", -10000, 10000); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_float_array(func, "result", 2, view_default, -FLT_MAX, FLT_MAX, "Result", "View coordinates", -10000.0f, 10000.0f); + RNA_def_property_flag(parm, PROP_THICK_WRAP); + RNA_def_function_output(func, parm); + + func = RNA_def_function(srna, "view_to_region", "rna_View2D_view_to_region"); + RNA_def_function_ui_description(func, "Transform 2D view coordinates to region"); + parm = RNA_def_float(func, "x", 0.0f, -FLT_MAX, FLT_MAX, "x", "2D View x coordinate", -10000.0f, 10000.0f); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_float(func, "y", 0.0f, -FLT_MAX, FLT_MAX, "y", "2D View y coordinate", -10000.0f, 10000.0f); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_boolean(func, "clip", 1, "Clip", "Clip coordinates to the visible region"); + parm = RNA_def_int_array(func, "result", 2, region_default, INT_MIN, INT_MAX, "Result", "Region coordinates", -10000, 10000); + RNA_def_property_flag(parm, PROP_THICK_WRAP); + RNA_def_function_output(func, parm); +} + +static void rna_def_view2d(BlenderRNA *brna) +{ + StructRNA *srna; + /* PropertyRNA *prop; */ + + srna = RNA_def_struct(brna, "View2D", NULL); + RNA_def_struct_ui_text(srna, "View2D", "Scroll and zoom for a 2D region"); + RNA_def_struct_sdna(srna, "View2D"); + + /* TODO more View2D properties could be exposed here (read-only) */ + + rna_def_view2d_api(srna); +} + static void rna_def_region(BlenderRNA *brna) { StructRNA *srna; @@ -260,6 +319,12 @@ static void rna_def_region(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Height", "Region height"); + prop = RNA_def_property(srna, "view2d", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "v2d"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_NEVER_NULL); + RNA_def_property_ui_text(prop, "View2D", "2D view of the region"); + RNA_def_function(srna, "tag_redraw", "ED_region_tag_redraw"); } @@ -345,6 +410,7 @@ void RNA_def_screen(BlenderRNA *brna) rna_def_screen(brna); rna_def_area(brna); rna_def_region(brna); + rna_def_view2d(brna); } #endif diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 01a58463fb6..b09227a9461 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2961,9 +2961,14 @@ static void rna_def_space_node(BlenderRNA *brna) RNA_def_property_pointer_sdna(prop, NULL, "nodetree"); RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_SpaceNodeEditor_node_tree_poll"); RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Node Tree", "Node tree being displayed and edited"); + RNA_def_property_ui_text(prop, "Node Tree", "Node tree being displayed"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE, "rna_SpaceNodeEditor_node_tree_update"); + prop = RNA_def_property(srna, "edit_tree", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "edittree"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Edit Tree", "Edited node tree"); + prop = RNA_def_property(srna, "show_backdrop", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_BACKDRAW); RNA_def_property_ui_text(prop, "Backdrop", "Use active Viewer Node output as backdrop for compositing nodes"); @@ -3007,6 +3012,13 @@ static void rna_def_space_node(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_USE_HIDDEN_PREVIEW); RNA_def_property_ui_text(prop, "Hide Preview", "Hide preview for newly creating nodes"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL); + + /* the mx/my "cursor" in the node editor is used only by operators to store the mouse position */ + prop = RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "mx"); + RNA_def_property_array(prop, 2); + RNA_def_property_ui_text(prop, "Cursor Location", "Location for adding new nodes"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL); } static void rna_def_space_logic(BlenderRNA *brna) diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c index 69cb0dc619b..9ae2cb0c353 100644 --- a/source/blenderplayer/bad_level_call_stubs/stubs.c +++ b/source/blenderplayer/bad_level_call_stubs/stubs.c @@ -96,6 +96,7 @@ struct Tex; struct TexResult; struct Text; struct ToolSettings; +struct View2D; struct View3D; struct bAction; struct bArmature; @@ -212,6 +213,9 @@ void *ED_region_draw_cb_activate(struct ARegionType *art, void(*draw)(const stru void *ED_region_draw_cb_customdata(void *handle) {return 0;} /* XXX This one looks wrong also */ void ED_region_draw_cb_exit(struct ARegionType *art, void *handle) {} void ED_area_headerprint(struct ScrArea *sa, char *str) {} +void UI_view2d_region_to_view(struct View2D *v2d, int x, int y, float *viewx, float *viewy) {} +void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *regionx, int *regiony) {} +void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, int *regionx, int *region_y) {} struct EditBone *ED_armature_bone_get_mirrored(struct ListBase *edbo, struct EditBone *ebo) {return (struct EditBone *) NULL;} struct EditBone *ED_armature_edit_bone_add(struct bArmature *arm, char *name) {return (struct EditBone*) NULL;} |