Tool System: show manipulators at startup
Support duplicating, switching workspaces too.
This commit is contained in:
@@ -202,6 +202,9 @@ bool ED_workspace_change(
|
|||||||
BLI_assert(BKE_workspace_view_layer_get(workspace_new) != NULL);
|
BLI_assert(BKE_workspace_view_layer_get(workspace_new) != NULL);
|
||||||
BLI_assert(CTX_wm_workspace(C) == workspace_new);
|
BLI_assert(CTX_wm_workspace(C) == workspace_new);
|
||||||
|
|
||||||
|
WM_toolsystem_unlink(C, workspace_old);
|
||||||
|
WM_toolsystem_link(C, workspace_new);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,6 +232,8 @@ WorkSpace *ED_workspace_duplicate(
|
|||||||
#endif
|
#endif
|
||||||
BLI_duplicatelist(transform_orientations_new, transform_orientations_old);
|
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) {
|
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);
|
WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(workspace_new, layout_old, win);
|
||||||
|
|
||||||
|
@@ -72,6 +72,7 @@ set(SRC
|
|||||||
intern/wm_subwindow.c
|
intern/wm_subwindow.c
|
||||||
intern/wm_window.c
|
intern/wm_window.c
|
||||||
intern/wm_stereo.c
|
intern/wm_stereo.c
|
||||||
|
intern/wm_toolsystem.c
|
||||||
manipulators/intern/wm_manipulator.c
|
manipulators/intern/wm_manipulator.c
|
||||||
manipulators/intern/wm_manipulator_group.c
|
manipulators/intern/wm_manipulator_group.c
|
||||||
manipulators/intern/wm_manipulator_group_type.c
|
manipulators/intern/wm_manipulator_group_type.c
|
||||||
|
@@ -66,6 +66,7 @@ struct ImageFormatData;
|
|||||||
struct ARegion;
|
struct ARegion;
|
||||||
struct ScrArea;
|
struct ScrArea;
|
||||||
struct Main;
|
struct Main;
|
||||||
|
struct bToolDef;
|
||||||
|
|
||||||
#ifdef WITH_INPUT_NDOF
|
#ifdef WITH_INPUT_NDOF
|
||||||
struct wmNDOFMotionData;
|
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);
|
bool WM_event_is_ime_switch(const struct wmEvent *event);
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -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
|
* a blend file and do anything since the screen
|
||||||
* won't be set to a valid value again */
|
* won't be set to a valid value again */
|
||||||
CTX_wm_window_set(C, NULL); /* exits queues */
|
CTX_wm_window_set(C, NULL); /* exits queues */
|
||||||
|
|
||||||
|
/* Ensure tools are registered. */
|
||||||
|
WM_toolsystem_init(C);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!G.background) {
|
if (!G.background) {
|
||||||
|
@@ -1812,35 +1812,16 @@ static void WM_OT_operator_defaults(wmOperatorType *ot)
|
|||||||
|
|
||||||
static int wm_operator_tool_set_exec(bContext *C, wmOperator *op)
|
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);
|
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;
|
bToolDef tool_def = {0};
|
||||||
|
|
||||||
if (workspace->tool.manipulator_group[0]) {
|
tool_def.index = RNA_int_get(op->ptr, "index");
|
||||||
wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(workspace->tool.manipulator_group, false);
|
tool_def.spacetype = sa->spacetype;
|
||||||
if (wgt != NULL) {
|
RNA_string_get(op->ptr, "keymap", tool_def.keymap);
|
||||||
wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wgt->mmap_params);
|
RNA_string_get(op->ptr, "manipulator_group", tool_def.manipulator_group);
|
||||||
WM_manipulatormaptype_group_unlink(C, bmain, mmap_type, wgt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NOTE: we may want to move this logic into a function. */
|
WM_toolsystem_set(C, &tool_def);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* For some reason redraw fails with menus (even though 'ar' isn't the menu's region). */
|
/* For some reason redraw fails with menus (even though 'ar' isn't the menu's region). */
|
||||||
ED_area_tag_redraw(sa);
|
ED_area_tag_redraw(sa);
|
||||||
|
107
source/blender/windowmanager/intern/wm_toolsystem.c
Normal file
107
source/blender/windowmanager/intern/wm_toolsystem.c
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user