Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-10-21 08:19:48 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-10-21 08:39:35 +0300
commite1e7b6db2e01d8ea2219d410200a8856d4597222 (patch)
tree521b1c81d53cc05c923e10f9ad8a3bb1887e899d /source/blender/windowmanager
parentb66728d63deee0fc9ef517405466d1139871251d (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/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c35
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c58
2 files changed, 92 insertions, 1 deletions
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);