UI: split UV editor out of the image space
authorCampbell Barton <ideasman42@gmail.com>
Wed, 5 Dec 2018 03:35:45 +0000 (14:35 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 5 Dec 2018 03:38:58 +0000 (14:38 +1100)
release/scripts/startup/bl_ui/space_image.py
source/blender/editors/space_image/space_image.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_space.c

index 836e15ef07bc63d41747bddb9a6c059734a37ac6..d2bd2e1184208da48f068102c31699a8d39a3798 100644 (file)
@@ -523,7 +523,8 @@ class IMAGE_HT_header(Header):
         row = layout.row(align=True)
         row.template_header()
 
-        layout.prop(sima, "mode", text="")
+        if sima.mode != 'UV':
+            layout.prop(sima, "ui_mode", text="")
 
         # UV editing.
         if show_uvedit:
index 01d2fc28c6b0f74ebf59a7084fbe2520fb58bf5a..b5c7657d890ed0409cc0cf8d30019cf14d3e3341 100644 (file)
 #include "BKE_screen.h"
 #include "BKE_workspace.h"
 
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
 #include "DEG_depsgraph.h"
 
 #include "IMB_imbuf_types.h"
@@ -69,8 +73,6 @@
 
 #include "BIF_gl.h"
 
-#include "RNA_access.h"
-
 #include "WM_api.h"
 #include "WM_types.h"
 #include "WM_message.h"
@@ -954,6 +956,37 @@ static void image_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID
        }
 }
 
+/**
+ * \note Used for splitting out a subset of modes is more involved,
+ * The previous non-uv-edit mode is stored so switching back to the
+ * image doesn't always reset the sub-mode.
+ */
+static int image_space_subtype_get(ScrArea *sa)
+{
+       SpaceImage *sima = sa->spacedata.first;
+       return sima->mode == SI_MODE_UV ? SI_MODE_UV : SI_MODE_VIEW;
+}
+
+static void image_space_subtype_set(ScrArea *sa, int value)
+{
+       SpaceImage *sima = sa->spacedata.first;
+       if (value == SI_MODE_UV) {
+               if (sima->mode != SI_MODE_UV) {
+                       sima->mode_prev = sima->mode;
+               }
+               sima->mode = value;
+       }
+       else {
+               sima->mode = sima->mode_prev;
+       }
+}
+
+static void image_space_subtype_item_extend(
+        bContext *UNUSED(C), EnumPropertyItem **item, int *totitem)
+{
+       RNA_enum_items_add(item, totitem, rna_enum_space_image_mode_items);
+}
+
 /**************************** spacetype *****************************/
 
 /* only called once, from space/spacetypes.c */
@@ -977,6 +1010,9 @@ void ED_spacetype_image(void)
        st->context = image_context;
        st->gizmos = image_widgets;
        st->id_remap = image_id_remap;
+       st->space_subtype_item_extend = image_space_subtype_item_extend;
+       st->space_subtype_get = image_space_subtype_get;
+       st->space_subtype_set = image_space_subtype_set;
 
        /* regions: main window */
        art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
index 43781c4782843d7a0d61f3a022a28e2b44648a2a..9c1b999cbd60b538e32fa6b4f63fc9987276c49b 100644 (file)
@@ -909,8 +909,11 @@ typedef struct SpaceImage {
        float centx, centy;             /* storage for offset while render drawing */
 
        char  mode;                     /* view/paint/mask */
+       /* Storage for sub-space types. */
+       char mode_prev;
+
        char  pin;
-       short pad;
+       char _pad;
        short curtile; /* the currently active tile of the image when tile is enabled, is kept in sync with the active faces tile */
        short lock;
        char dt_uv; /* UV draw type */
index e8cda30a5111cd49cd95341fa56340cae868f1c6..c2065548836d4365312001fd9ff514cde5e3e465 100644 (file)
@@ -167,14 +167,42 @@ const EnumPropertyItem rna_enum_space_action_mode_items[] = {
 #undef SACT_ITEM_MASK
 #undef SACT_ITEM_CACHEFILE
 
+
+#define SI_ITEM_VIEW(name, icon) \
+       {SI_MODE_VIEW, "VIEW", icon, name, "View the image"}
+#define SI_ITEM_UV \
+       {SI_MODE_UV, "UV", ICON_GROUP_UVS, "UV Edit", "UV edit in mesh editmode"}
+#define SI_ITEM_PAINT \
+       {SI_MODE_PAINT, "PAINT", ICON_TPAINT_HLT, "Paint", "2D image painting mode"}
+#define SI_ITEM_MASK \
+       {SI_MODE_MASK, "MASK", ICON_MOD_MASK, "Mask", "Mask editing"}
+
+static const EnumPropertyItem rna_enum_space_image_mode_all_items[] = {
+       SI_ITEM_VIEW("View", ICON_FILE_IMAGE),
+       SI_ITEM_UV,
+       SI_ITEM_PAINT,
+       SI_ITEM_MASK,
+       {0, NULL, 0, NULL, NULL}
+};
+
+static const EnumPropertyItem rna_enum_space_image_mode_ui_items[] = {
+       SI_ITEM_VIEW("View", ICON_FILE_IMAGE),
+       SI_ITEM_PAINT,
+       SI_ITEM_MASK,
+       {0, NULL, 0, NULL, NULL}
+};
+
 const EnumPropertyItem rna_enum_space_image_mode_items[] = {
-       {SI_MODE_VIEW, "VIEW", ICON_FILE_IMAGE, "View", "View the image"},
-       {SI_MODE_UV, "UV", ICON_GROUP_UVS, "UV Edit", "UV edit in mesh editmode"},
-       {SI_MODE_PAINT, "PAINT", ICON_TPAINT_HLT, "Paint", "2D image painting mode"},
-       {SI_MODE_MASK, "MASK", ICON_MOD_MASK, "Mask", "Mask editing"},
+       SI_ITEM_VIEW("Image Editor", ICON_IMAGE),
+       SI_ITEM_UV,
        {0, NULL, 0, NULL, NULL}
 };
 
+#undef SI_ITEM_VIEW
+#undef SI_ITEM_UV
+#undef SI_ITEM_PAINT
+#undef SI_ITEM_MASK
+
 #define V3D_S3D_CAMERA_LEFT        {STEREO_LEFT_ID, "LEFT", ICON_RESTRICT_RENDER_OFF, "Left", ""},
 #define V3D_S3D_CAMERA_RIGHT       {STEREO_RIGHT_ID, "RIGHT", ICON_RESTRICT_RENDER_OFF, "Right", ""},
 #define V3D_S3D_CAMERA_S3D         {STEREO_3D_ID, "S3D", ICON_CAMERA_STEREO, "3D", ""},
@@ -3539,10 +3567,16 @@ static void rna_def_space_image(BlenderRNA *brna)
        RNA_def_property_pointer_funcs(prop, "rna_SpaceImageEditor_uvedit_get", NULL, NULL, NULL);
        RNA_def_property_ui_text(prop, "UV Editor", "UV editor settings");
 
-       /* mode */
+       /* mode (hidden in the UI, see 'ui_mode') */
        prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "mode");
-       RNA_def_property_enum_items(prop, rna_enum_space_image_mode_items);
+       RNA_def_property_enum_items(prop, rna_enum_space_image_mode_all_items);
+       RNA_def_property_ui_text(prop, "Mode", "Editing context being displayed");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, "rna_SpaceImageEditor_mode_update");
+
+       prop = RNA_def_property(srna, "ui_mode", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "mode");
+       RNA_def_property_enum_items(prop, rna_enum_space_image_mode_ui_items);
        RNA_def_property_ui_text(prop, "Mode", "Editing context being displayed");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, "rna_SpaceImageEditor_mode_update");