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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-11-27 10:15:47 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-11-27 10:36:54 +0300
commitd4161845b28b83e2a49bca24b749afb4d0ab8af6 (patch)
tree200f432f1588ff328996d13e60ae22531c6c0e39 /source
parentee99d1453a5baed844582e35cf4618952b7023b3 (diff)
Tool System: show manipulators at startup
Support duplicating, switching workspaces too.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/screen/workspace_edit.c5
-rw-r--r--source/blender/windowmanager/CMakeLists.txt1
-rw-r--r--source/blender/windowmanager/WM_api.h8
-rw-r--r--source/blender/windowmanager/intern/wm_files.c3
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c33
-rw-r--r--source/blender/windowmanager/intern/wm_toolsystem.c107
6 files changed, 131 insertions, 26 deletions
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index 677f78c6d86..534e6c1bff4 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -202,6 +202,9 @@ bool ED_workspace_change(
BLI_assert(BKE_workspace_view_layer_get(workspace_new) != NULL);
BLI_assert(CTX_wm_workspace(C) == workspace_new);
+ WM_toolsystem_unlink(C, workspace_old);
+ WM_toolsystem_link(C, workspace_new);
+
return true;
}
@@ -229,6 +232,8 @@ WorkSpace *ED_workspace_duplicate(
#endif
BLI_duplicatelist(transform_orientations_new, transform_orientations_old);
+ workspace_new->tool = workspace_old->tool;
+
for (WorkSpaceLayout *layout_old = layouts_old->first; layout_old; layout_old = layout_old->next) {
WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(workspace_new, layout_old, win);
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 464906dad1e..95a0371ba23 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -72,6 +72,7 @@ set(SRC
intern/wm_subwindow.c
intern/wm_window.c
intern/wm_stereo.c
+ intern/wm_toolsystem.c
manipulators/intern/wm_manipulator.c
manipulators/intern/wm_manipulator_group.c
manipulators/intern/wm_manipulator_group_type.c
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 37ff54d4397..7671fbeb926 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -66,6 +66,7 @@ struct ImageFormatData;
struct ARegion;
struct ScrArea;
struct Main;
+struct bToolDef;
#ifdef WITH_INPUT_NDOF
struct wmNDOFMotionData;
@@ -563,6 +564,13 @@ bool WM_event_is_tablet(const struct wmEvent *event);
bool WM_event_is_ime_switch(const struct wmEvent *event);
#endif
+/* wm_toolsystem.c */
+void WM_toolsystem_unlink(struct bContext *C, struct WorkSpace *workspace);
+void WM_toolsystem_link(struct bContext *C, struct WorkSpace *workspace);
+
+void WM_toolsystem_set(struct bContext *C, const struct bToolDef *tool);
+void WM_toolsystem_init(struct bContext *C);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index e1e863fbf8e..372b34f9df2 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -517,6 +517,9 @@ static void wm_file_read_post(bContext *C, const bool is_startup_file, const boo
* a blend file and do anything since the screen
* won't be set to a valid value again */
CTX_wm_window_set(C, NULL); /* exits queues */
+
+ /* Ensure tools are registered. */
+ WM_toolsystem_init(C);
}
if (!G.background) {
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index a8281b7441e..ad1d0730ad2 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -1812,35 +1812,16 @@ static void WM_OT_operator_defaults(wmOperatorType *ot)
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);
- int index = RNA_int_get(op->ptr, "index");
-
- workspace->tool.index = index;
-
- 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;
- }
+ bToolDef tool_def = {0};
- if (workspace->tool.manipulator_group[0]) {
- WM_manipulator_group_type_ensure(workspace->tool.manipulator_group);
- }
+ tool_def.index = RNA_int_get(op->ptr, "index");
+ tool_def.spacetype = sa->spacetype;
+ RNA_string_get(op->ptr, "keymap", tool_def.keymap);
+ RNA_string_get(op->ptr, "manipulator_group", tool_def.manipulator_group);
+
+ WM_toolsystem_set(C, &tool_def);
/* For some reason redraw fails with menus (even though 'ar' isn't the menu's region). */
ED_area_tag_redraw(sa);
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c
new file mode 100644
index 00000000000..5e000489ace
--- /dev/null
+++ b/source/blender/windowmanager/intern/wm_toolsystem.c
@@ -0,0 +1,107 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/intern/wm_toolsystem.c
+ * \ingroup wm
+ *
+ * Experimental tool-system>
+ */
+
+#include <string.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_string.h"
+
+#include "DNA_ID.h"
+#include "DNA_scene_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
+
+#include "BKE_context.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+void WM_toolsystem_unlink(bContext *C, WorkSpace *workspace)
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindowManager *wm = bmain->wm.first;
+
+ if (workspace->tool.manipulator_group[0]) {
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(workspace->tool.manipulator_group, false);
+ if (wgt != NULL) {
+ bool found = false;
+
+ /* Check another workspace isn't using this tool. */
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ const WorkSpace *workspace_iter = WM_window_get_active_workspace(win);
+ if (workspace != workspace_iter) {
+ if (STREQ(workspace->tool.manipulator_group, workspace_iter->tool.manipulator_group)) {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if (!found) {
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wgt->mmap_params);
+ WM_manipulatormaptype_group_unlink(C, bmain, mmap_type, wgt);
+ }
+ }
+ }
+}
+
+void WM_toolsystem_link(bContext *UNUSED(C), WorkSpace *workspace)
+{
+ if (workspace->tool.manipulator_group[0]) {
+ WM_manipulator_group_type_ensure(workspace->tool.manipulator_group);
+ }
+}
+
+void WM_toolsystem_set(bContext *C, const bToolDef *tool)
+{
+ WorkSpace *workspace = CTX_wm_workspace(C);
+
+ WM_toolsystem_unlink(C, workspace);
+
+ workspace->tool.index = tool->index;
+ workspace->tool.spacetype = tool->spacetype;
+
+ if (&workspace->tool != tool) {
+ BLI_strncpy(workspace->tool.keymap, tool->keymap, sizeof(tool->keymap));
+ BLI_strncpy(workspace->tool.manipulator_group, tool->manipulator_group, sizeof(tool->manipulator_group));
+ workspace->tool.spacetype = tool->spacetype;
+ }
+
+ WM_toolsystem_link(C, workspace);
+}
+
+void WM_toolsystem_init(bContext *C)
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindowManager *wm = bmain->wm.first;
+
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ WM_toolsystem_link(C, workspace);
+ }
+}