diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-10-21 08:19:48 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-10-21 08:39:35 +0300 |
commit | e1e7b6db2e01d8ea2219d410200a8856d4597222 (patch) | |
tree | 521b1c81d53cc05c923e10f9ad8a3bb1887e899d /source | |
parent | b66728d63deee0fc9ef517405466d1139871251d (diff) |
WM: Initial Tool System
The tool-system it's self is primitive and may be changed.
Adding to 2.8 to develop operators and manipulators as tools.
Currently this is exposed in the toolbar, collapsed by default.
Work-flow remains unchanged if you don't change the active tool.
Placing the 3D cursor is now a Click instead of a Press event,
this allows tweak events to be mapped to tools such as border select,
keeping click for 3D cursor placement when selection tools are set.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_ops.c | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_workspace_types.h | 13 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_workspace.c | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 35 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 58 |
5 files changed, 116 insertions, 2 deletions
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 6f05dd353d7..ddba3c69320 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -238,7 +238,7 @@ void view3d_keymap(wmKeyConfig *keyconf) /* only for region 3D window */ keymap = WM_keymap_find(keyconf, "3D View", SPACE_VIEW3D, 0); - WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_PRESS, 0, 0); + WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_CLICK, 0, 0); WM_keymap_verify_item(keymap, "VIEW3D_OT_rotate", MIDDLEMOUSE, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "VIEW3D_OT_move", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0); diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h index 272d0cd110a..172903fe312 100644 --- a/source/blender/makesdna/DNA_workspace_types.h +++ b/source/blender/makesdna/DNA_workspace_types.h @@ -50,6 +50,16 @@ # endif #endif +/* Currently testing, allow to disable. */ +#define USE_WORKSPACE_TOOL + +typedef struct bToolDef { + /* either the keymap AND/OR manipulator_group must be defined. */ + char keymap[64]; + char manipulator_group[64]; + int spacetype; + int _pad; +} bToolDef; /** * \brief Wrapper for bScreen. @@ -80,6 +90,9 @@ typedef struct WorkSpace { int object_mode DNA_PRIVATE_WORKSPACE; /* enum eObjectMode */ int flags DNA_PRIVATE_WORKSPACE; /* enum eWorkSpaceFlags */ + /* should be: '#ifdef USE_WORKSPACE_TOOL'. */ + bToolDef tool; + struct SceneLayer *render_layer DNA_PRIVATE_WORKSPACE; char engine_id[32]; /* Render Engine. */ diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c index 4e04581a0a8..8cf5e3e8eaf 100644 --- a/source/blender/makesrna/intern/rna_workspace.c +++ b/source/blender/makesrna/intern/rna_workspace.c @@ -146,6 +146,16 @@ static void rna_def_workspace(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Mode", "Object interaction mode"); #endif + prop = RNA_def_property(srna, "tool_keymap", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "tool.keymap"); + RNA_def_property_ui_text(prop, "Active Tool", "Currently active tool keymap"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + + prop = RNA_def_property(srna, "tool_manipulator_group", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "tool.manipulator_group"); + RNA_def_property_ui_text(prop, "Active Tool", "Currently active tool manipulator"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + prop = RNA_def_property(srna, "orientations", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "transform_orientations", NULL); RNA_def_property_struct_type(prop, "TransformOrientation"); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 2852b1b4d24..5f69f928eb5 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2722,9 +2722,42 @@ void wm_event_do_handlers(bContext *C) wm_drags_check_ops(C, event); } } - + +#ifdef USE_WORKSPACE_TOOL + /* How to solve properly? + * + * Handlers are stored in each region, + * however the tool-system swaps keymaps often and isn't stored + * per region. + * + * Need to investigate how this could be done better. + * We might need to add a more dynamic handler type that uses a callback + * to fetch its current keymap. + */ + wmEventHandler sneaky_handler = {NULL}; + if (ar->regiontype == RGN_TYPE_WINDOW) { + WorkSpace *workspace = WM_window_get_active_workspace(win); + if (workspace->tool.keymap[0] && + workspace->tool.spacetype == sa->spacetype) + { + wmKeyMap *km = WM_keymap_find_all( + C, workspace->tool.keymap, sa->spacetype, RGN_TYPE_WINDOW); + if (km != NULL) { + sneaky_handler.keymap = km; + BLI_addhead(&ar->handlers, &sneaky_handler); + } + } + } +#endif /* USE_WORKSPACE_TOOL */ + action |= wm_handlers_do(C, event, &ar->handlers); +#ifdef USE_WORKSPACE_TOOL + if (sneaky_handler.keymap) { + BLI_remlink(&ar->handlers, &sneaky_handler); + } +#endif /* USE_WORKSPACE_TOOL */ + /* fileread case (python), [#29489] */ if (CTX_wm_window(C) == NULL) return; diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 970b6ebf51d..a5c4228cd2e 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -52,6 +52,7 @@ #include "DNA_scene_types.h" #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" +#include "DNA_workspace_types.h" #include "BLT_translation.h" @@ -1743,6 +1744,60 @@ static void WM_OT_operator_defaults(wmOperatorType *ot) ot->flag = OPTYPE_INTERNAL; } +#ifdef USE_WORKSPACE_TOOL +/* ***************** Set Active Tool ************************* */ + +/* Developers note: in it's current form this doesn't need to be an operator, + * keep this as-is for now since it may end up setting an active key-map. + */ + +static int wm_operator_tool_set_exec(bContext *C, wmOperator *op) +{ + Main *bmain = CTX_data_main(C); + WorkSpace *workspace = CTX_wm_workspace(C); + ScrArea *sa = CTX_wm_area(C); + char id_keymap[sizeof(workspace->tool.keymap)]; + char id_manipulator_group[sizeof(workspace->tool.manipulator_group)]; + RNA_string_get(op->ptr, "keymap", id_keymap); + RNA_string_get(op->ptr, "manipulator_group", id_manipulator_group); + + if (workspace->tool.manipulator_group[0]) { + wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(workspace->tool.manipulator_group, false); + if (wgt != NULL) { + wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wgt->mmap_params); + WM_manipulatormaptype_group_unlink(C, bmain, mmap_type, wgt); + } + } + + /* NOTE: we may want to move this logic into a function. */ + { + BLI_strncpy(workspace->tool.keymap, id_keymap, sizeof(workspace->tool.keymap)); + BLI_strncpy(workspace->tool.manipulator_group, id_manipulator_group, sizeof(workspace->tool.manipulator_group)); + workspace->tool.spacetype = sa->spacetype; + } + + if (workspace->tool.manipulator_group[0]) { + WM_manipulator_group_type_ensure(workspace->tool.manipulator_group); + } + + return OPERATOR_FINISHED; +} + +static void WM_OT_tool_set(wmOperatorType *ot) +{ + ot->name = "Set Active Tool"; + ot->idname = "WM_OT_tool_set"; + ot->description = "Set the active tool"; + + ot->exec = wm_operator_tool_set_exec; + + ot->flag = OPTYPE_INTERNAL; + + RNA_def_string(ot->srna, "keymap", NULL, KMAP_MAX_NAME, "Key Map", ""); + RNA_def_string(ot->srna, "manipulator_group", NULL, MAX_NAME, "Manipulator Group", ""); +} +#endif /* USE_WORKSPACE_TOOL */ + /* ***************** Splash Screen ************************* */ static void wm_block_splash_close(bContext *C, void *arg_block, void *UNUSED(arg)) @@ -3604,6 +3659,9 @@ void wm_operatortype_init(void) WM_operatortype_append(WM_OT_memory_statistics); WM_operatortype_append(WM_OT_debug_menu); WM_operatortype_append(WM_OT_operator_defaults); +#ifdef USE_WORKSPACE_TOOL + WM_operatortype_append(WM_OT_tool_set); +#endif WM_operatortype_append(WM_OT_splash); WM_operatortype_append(WM_OT_search_menu); WM_operatortype_append(WM_OT_call_menu); |