diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2017-06-01 21:41:18 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2017-06-01 21:46:18 +0300 |
commit | 46fc0bb87ebda166d08b23cbcca799acb2c54158 (patch) | |
tree | 1566d535d93c4fb81b962cdbc1346ca8242460f2 /source/blender/blenkernel | |
parent | 7f564d74f9edaaa41ce27c6e854869096f70b4da (diff) |
Move custom transform orientations to workspace
This commit moves the list of transform orientations from scenes to workspaces.
Main reasons for this are:
* Transform orientations are UI data and should not be stored in the scene.
* Introducion of workspaces caused some (expected) glitches with transform orientations. Mainly when removing one.
* Improves code.
More technically speaking, this commit does:
* Move list of custom transform orientations from Scene to WorkSpace struct.
* Store active transform orientation index separate from View3D.twmode (twmode can only be set to preprocessor defined values now).
* Display custom transform orientation name in header when transforming in it (used to show "global" which isn't really correct).
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_workspace.h | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/screen.c | 36 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/workspace.c | 33 |
5 files changed, 61 insertions, 30 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 645a99d592f..6ff344fea38 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -42,6 +42,7 @@ struct Panel; struct Scene; struct ScrArea; struct SpaceType; +struct TransformOrientation; struct View3D; struct bContext; struct bContextDataResult; @@ -53,6 +54,7 @@ struct wmManipulatorMap; struct wmNotifier; struct wmWindow; struct wmWindowManager; +struct WorkSpace; struct GPUFXSettings; #include "BLI_compiler_attrs.h" @@ -309,8 +311,9 @@ unsigned int BKE_screen_view3d_layer_all(const struct bScreen *sc) ATTR_WARN_UNU void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene); void BKE_screen_view3d_scene_sync(struct bScreen *sc, struct Scene *scene); -void BKE_screen_view3d_twmode_remove(struct View3D *v3d, const int i); -void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, struct Scene *scene, const int i); +void BKE_screen_transform_orientation_remove( + const struct bScreen *screen, const struct WorkSpace *workspace, + const struct TransformOrientation *orientation) ATTR_NONNULL(); void BKE_screen_gpu_fx_validate(struct GPUFXSettings *fx_settings); bool BKE_screen_is_fullscreen_area(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); bool BKE_screen_is_used(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h index e7eaf72dd15..5595c874e27 100644 --- a/source/blender/blenkernel/BKE_workspace.h +++ b/source/blender/blenkernel/BKE_workspace.h @@ -28,6 +28,7 @@ #include "BLI_compiler_attrs.h" struct bScreen; +struct TransformOrientation; typedef struct WorkSpace WorkSpace; typedef struct WorkSpaceInstanceHook WorkSpaceInstanceHook; @@ -66,11 +67,18 @@ void BKE_workspace_layout_remove( /* -------------------------------------------------------------------- */ /* General Utils */ +void BKE_workspace_transform_orientation_remove( + WorkSpace *workspace, struct TransformOrientation *orientation) ATTR_NONNULL(); +struct TransformOrientation *BKE_workspace_transform_orientation_find( + const WorkSpace *workspace, const int index) ATTR_NONNULL(); +int BKE_workspace_transform_orientation_get_index( + const WorkSpace *workspace, const struct TransformOrientation *orientation) ATTR_NONNULL(); + WorkSpaceLayout *BKE_workspace_layout_find( const WorkSpace *workspace, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; WorkSpaceLayout *BKE_workspace_layout_find_global( const struct Main *bmain, const struct bScreen *screen, - WorkSpace **r_workspace) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; + WorkSpace **r_workspace) ATTR_NONNULL(1, 2); WorkSpaceLayout *BKE_workspace_layout_iter_circular( const WorkSpace *workspace, WorkSpaceLayout *start, @@ -95,6 +103,7 @@ enum ObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace) GETTER #ifdef USE_WORKSPACE_MODE void BKE_workspace_object_mode_set(WorkSpace *workspace, const enum ObjectMode mode) SETTER_ATTRS; #endif +struct ListBase *BKE_workspace_transform_orientations_get(WorkSpace *workspace) GETTER_ATTRS; struct SceneLayer *BKE_workspace_render_layer_get(const WorkSpace *workspace) GETTER_ATTRS; void BKE_workspace_render_layer_set(WorkSpace *workspace, struct SceneLayer *layer) SETTER_ATTRS; struct ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) GETTER_ATTRS; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 92f5dade0a5..235d606ff3e 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -261,7 +261,6 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) scen->rigidbody_world = BKE_rigidbody_world_copy(sce->rigidbody_world); BLI_duplicatelist(&(scen->markers), &(sce->markers)); - BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces)); BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers)); BLI_duplicatelist(&(scen->r.views), &(sce->r.views)); BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); @@ -534,10 +533,9 @@ void BKE_scene_free(Scene *sce) } BLI_freelistN(&sce->markers); - BLI_freelistN(&sce->transform_spaces); BLI_freelistN(&sce->r.layers); BLI_freelistN(&sce->r.views); - + if (sce->toolsettings) { if (sce->toolsettings->vpaint) { BKE_paint_free(&sce->toolsettings->vpaint->paint); diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index b1f8f574b7e..91d675535f3 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -53,6 +53,7 @@ #include "BKE_icons.h" #include "BKE_idprop.h" #include "BKE_screen.h" +#include "BKE_workspace.h" /* ************ Spacetype/regiontype handling ************** */ @@ -611,33 +612,20 @@ void BKE_screen_view3d_scene_sync(bScreen *sc, Scene *scene) } } -/* XXX apply D2687 */ -void BKE_screen_view3d_twmode_remove(View3D *v3d, const int i) +void BKE_screen_transform_orientation_remove( + const bScreen *screen, const WorkSpace *workspace, const TransformOrientation *orientation) { - const int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM); - if (selected_index == i) { - v3d->twmode = V3D_MANIP_GLOBAL; - } - else if (selected_index > i) { - v3d->twmode--; - } -} + const int orientation_index = BKE_workspace_transform_orientation_get_index(workspace, orientation); -/* XXX apply D2687 */ -void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, Scene *scene, const int i) -{ - bScreen *sc; + for (ScrArea *area = screen->areabase.first; area; area = area->next) { + for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; - for (sc = screen_lb->first; sc; sc = sc->id.next) { - if (sc->scene == scene) { - ScrArea *sa; - for (sa = sc->areabase.first; sa; sa = sa->next) { - SpaceLink *sl; - for (sl = sa->spacedata.first; sl; sl = sl->next) { - if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d = (View3D *)sl; - BKE_screen_view3d_twmode_remove(v3d, i); - } + if (v3d->custom_orientation_index == orientation_index) { + /* could also use orientation_index-- */ + v3d->twmode = V3D_MANIP_GLOBAL; + v3d->custom_orientation_index = -1; } } } diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c index 8afad317dce..82fface7d06 100644 --- a/source/blender/blenkernel/intern/workspace.c +++ b/source/blender/blenkernel/intern/workspace.c @@ -35,6 +35,7 @@ #include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_screen.h" #include "BKE_workspace.h" #include "DNA_object_types.h" @@ -150,6 +151,7 @@ void BKE_workspace_free(WorkSpace *workspace) workspace_relation_remove(&workspace->hook_layout_relations, relation); } BLI_freelistN(&workspace->layouts); + BLI_freelistN(&workspace->transform_orientations); } void BKE_workspace_remove(Main *bmain, WorkSpace *workspace) @@ -223,6 +225,31 @@ void BKE_workspace_layout_remove( /* -------------------------------------------------------------------- */ /* General Utils */ +void BKE_workspace_transform_orientation_remove( + WorkSpace *workspace, TransformOrientation *orientation) +{ + for (WorkSpaceLayout *layout = workspace->layouts.first; layout; layout = layout->next) { + BKE_screen_transform_orientation_remove(BKE_workspace_layout_screen_get(layout), workspace, orientation); + } + + BLI_freelinkN(&workspace->transform_orientations, orientation); +} + +TransformOrientation *BKE_workspace_transform_orientation_find( + const WorkSpace *workspace, const int index) +{ + return BLI_findlink(&workspace->transform_orientations, index); +} + +/** + * \return the index that \a orientation has within \a workspace's transform-orientation list or -1 if not found. + */ +int BKE_workspace_transform_orientation_get_index( + const WorkSpace *workspace, const TransformOrientation *orientation) +{ + return BLI_findindex(&workspace->transform_orientations, orientation); +} + WorkSpaceLayout *BKE_workspace_layout_find( const WorkSpace *workspace, const bScreen *screen) { @@ -240,6 +267,7 @@ WorkSpaceLayout *BKE_workspace_layout_find( /** * Find the layout for \a screen without knowing which workspace to look in. + * Can also be used to find the workspace that contains \a screen. * * \param r_workspace: Optionally return the workspace that contains the looked up layout (if found). */ @@ -353,6 +381,11 @@ void BKE_workspace_object_mode_set(WorkSpace *workspace, const ObjectMode mode) } #endif +ListBase *BKE_workspace_transform_orientations_get(WorkSpace *workspace) +{ + return &workspace->transform_orientations; +} + SceneLayer *BKE_workspace_render_layer_get(const WorkSpace *workspace) { return workspace->render_layer; |