[Bf-blender-cvs] [2ff393bb981] master: UI: use single column layout for image settings panels

Brecht Van Lommel noreply at git.blender.org
Sun May 19 16:26:18 CEST 2019


Commit: 2ff393bb981078bcdcffafd15719e8817051cf05
Author: Brecht Van Lommel
Date:   Sun May 19 14:51:21 2019 +0200
Branches: master
https://developer.blender.org/rB2ff393bb981078bcdcffafd15719e8817051cf05

UI: use single column layout for image settings panels

===================================================================

M	release/scripts/startup/bl_ui/properties_data_empty.py
M	release/scripts/startup/bl_ui/space_node.py
M	source/blender/editors/space_image/image_buttons.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_empty.py b/release/scripts/startup/bl_ui/properties_data_empty.py
index 8302bc7cd13..ca1ebb0e03f 100644
--- a/release/scripts/startup/bl_ui/properties_data_empty.py
+++ b/release/scripts/startup/bl_ui/properties_data_empty.py
@@ -27,7 +27,8 @@ class DataButtonsPanel:
 
     @classmethod
     def poll(cls, context):
-        return (context.object and context.object.type == 'EMPTY')
+        ob = context.object
+        return (ob and ob.type == 'EMPTY')
 
 
 class DATA_PT_empty(DataButtonsPanel, Panel):
@@ -36,6 +37,7 @@ class DATA_PT_empty(DataButtonsPanel, Panel):
     def draw(self, context):
         layout = self.layout
         layout.use_property_split = True
+        layout.use_property_decorate = False
 
         ob = context.object
 
@@ -43,11 +45,6 @@ class DATA_PT_empty(DataButtonsPanel, Panel):
         layout.prop(ob, "empty_display_size", text="Size")
 
         if ob.empty_display_type == 'IMAGE':
-            layout.template_ID(ob, "data", open="image.open", unlink="object.unlink_data")
-            layout.template_image(ob, "data", ob.image_user, compact=True)
-
-            layout.row(align=True).row(align=True)
-
             layout.prop(ob, "use_empty_image_alpha")
 
             col = layout.column()
@@ -65,8 +62,25 @@ class DATA_PT_empty(DataButtonsPanel, Panel):
             col.prop(ob, "show_empty_image_perspective", text="Display Perspective")
 
 
+class DATA_PT_empty_image(DataButtonsPanel, Panel):
+    bl_label = "Image"
+
+    @classmethod
+    def poll(cls, context):
+        ob = context.object
+        return (ob and ob.type == 'EMPTY' and ob.empty_display_type == 'IMAGE')
+
+    def draw(self, context):
+        layout = self.layout
+        ob = context.object
+        layout.template_ID(ob, "data", open="image.open", unlink="object.unlink_data")
+        layout.separator();
+        layout.template_image(ob, "data", ob.image_user, compact=True)
+
+
 classes = (
     DATA_PT_empty,
+    DATA_PT_empty_image,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index 45ff4ce6c5f..17775105c96 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -490,7 +490,6 @@ class NODE_PT_active_node_properties(Panel):
     bl_category = "Item"
     bl_label = "Properties"
     bl_options = {'DEFAULT_CLOSED'}
-    bl_parent_id = 'NODE_PT_active_node_generic'
 
     @classmethod
     def poll(cls, context):
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 9f429329597..44290a385c4 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -63,81 +63,6 @@
 #define B_NOP -1
 #define MAX_IMAGE_INFO_LEN 128
 
-/* proto */
-
-static void image_info(
-    Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, char *str, size_t len)
-{
-  size_t ofs = 0;
-
-  str[0] = 0;
-  if (ima == NULL) {
-    return;
-  }
-
-  if (ibuf == NULL) {
-    ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Can't Load Image"), len - ofs);
-  }
-  else {
-    if (ima->source == IMA_SRC_MOVIE) {
-      ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Movie"), len - ofs);
-      if (BKE_image_has_anim(ima)) {
-        ofs += BLI_snprintf(
-            str + ofs,
-            len - ofs,
-            IFACE_(" %d frs"),
-            IMB_anim_get_duration(((ImageAnim *)ima->anims.first)->anim, IMB_TC_RECORD_RUN));
-      }
-    }
-    else {
-      ofs += BLI_strncpy_rlen(str, IFACE_("Image"), len - ofs);
-    }
-
-    ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(": size %d x %d,"), ibuf->x, ibuf->y);
-
-    if (ibuf->rect_float) {
-      if (ibuf->channels != 4) {
-        ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_("%d float channel(s)"), ibuf->channels);
-      }
-      else if (ibuf->planes == R_IMF_PLANES_RGBA) {
-        ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA float"), len - ofs);
-      }
-      else {
-        ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB float"), len - ofs);
-      }
-    }
-    else {
-      if (ibuf->planes == R_IMF_PLANES_RGBA) {
-        ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA byte"), len - ofs);
-      }
-      else {
-        ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB byte"), len - ofs);
-      }
-    }
-    if (ibuf->zbuf || ibuf->zbuf_float) {
-      ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" + Z"), len - ofs);
-    }
-
-    if (ima->source == IMA_SRC_SEQUENCE) {
-      const char *file = BLI_last_slash(ibuf->name);
-      if (file == NULL) {
-        file = ibuf->name;
-      }
-      else {
-        file++;
-      }
-      ofs += BLI_snprintf(str + ofs, len - ofs, ", %s", file);
-    }
-  }
-
-  /* the frame number, even if we cant */
-  if (ima->source == IMA_SRC_SEQUENCE) {
-    /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
-    const int framenr = BKE_image_user_frame_get(iuser, CFRA, NULL);
-    ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(", Frame: %d"), framenr);
-  }
-}
-
 /* gets active viewer user */
 struct ImageUser *ntree_get_active_iuser(bNodeTree *ntree)
 {
@@ -823,6 +748,22 @@ static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
   RNA_property_update(C, &cb->ptr, cb->prop);
 }
 
+static bool image_has_alpha(Image *ima, ImageUser *iuser)
+{
+  ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
+  if (ibuf == NULL) {
+    return false;
+  }
+
+  int imtype = BKE_image_ftype_to_imtype(ibuf->ftype, &ibuf->foptions);
+  char valid_channels = BKE_imtype_valid_channels(imtype, false);
+  bool has_alpha = (valid_channels & IMA_CHAN_FLAG_ALPHA) != 0;
+
+  BKE_image_release_ibuf(ima, ibuf, NULL);
+
+  return has_alpha;
+}
+
 void uiTemplateImage(uiLayout *layout,
                      bContext *C,
                      PointerRNA *ptr,
@@ -831,24 +772,11 @@ void uiTemplateImage(uiLayout *layout,
                      bool compact,
                      bool multiview)
 {
-  PropertyRNA *prop;
-  PointerRNA imaptr;
-  RNAUpdateCb *cb;
-  Image *ima;
-  ImageUser *iuser;
-  Scene *scene = CTX_data_scene(C);
-  SpaceImage *space_image = CTX_wm_space_image(C);
-  uiLayout *row, *split, *col;
-  uiBlock *block;
-  char str[MAX_IMAGE_INFO_LEN];
-
-  void *lock;
-
   if (!ptr->data) {
     return;
   }
 
-  prop = RNA_struct_find_property(ptr, propname);
+  PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
   if (!prop) {
     printf(
         "%s: property not found: %s.%s\n", __func__, RNA_struct_identifier(ptr->type), propname);
@@ -863,22 +791,19 @@ void uiTemplateImage(uiLayout *layout,
     return;
   }
 
-  block = uiLayoutGetBlock(layout);
+  uiBlock *block = uiLayoutGetBlock(layout);
 
-  imaptr = RNA_property_pointer_get(ptr, prop);
-  ima = imaptr.data;
-  iuser = userptr->data;
+  PointerRNA imaptr = RNA_property_pointer_get(ptr, prop);
+  Image *ima = imaptr.data;
+  ImageUser *iuser = userptr->data;
 
+  Scene *scene = CTX_data_scene(C);
   BKE_image_user_frame_calc(iuser, (int)scene->r.cfra);
 
-  cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
-  cb->ptr = *ptr;
-  cb->prop = prop;
-  cb->iuser = iuser;
-
   uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
   uiLayoutSetContextPointer(layout, "edit_image_user", userptr);
 
+  SpaceImage *space_image = CTX_wm_space_image(C);
   if (!compact && (space_image == NULL || iuser != &space_image->iuser)) {
     uiTemplateID(layout,
                  C,
@@ -889,165 +814,178 @@ void uiTemplateImage(uiLayout *layout,
                  NULL,
                  UI_TEMPLATE_ID_FILTER_ALL,
                  false);
+
+    if (ima != NULL) {
+      uiItemS(layout);
+    }
   }
 
-  if (ima) {
-    UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), NULL);
+  if (ima == NULL) {
+    return;
+  }
 
-    if (ima->source == IMA_SRC_VIEWER) {
-      ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
-      image_info(scene, iuser, ima, ibuf, str, MAX_IMAGE_INFO_LEN);
-      BKE_image_release_ibuf(ima, ibuf, lock);
+  if (ima->source == IMA_SRC_VIEWER) {
+    /* Viewer images. */
+    uiTemplateImageInfo(layout, C, ima, iuser);
 
-      uiItemL(layout, ima->id.name + 2, ICON_NONE);
-      uiItemL(layout, str, ICON_NONE);
+    if (ima->type == IMA_TYPE_COMPOSITE) {
+    }
+    else if (ima->type == IMA_TYPE_R_RESULT) {
+      /* browse layer/passes */
+      RenderResult *rr;
+      const float dpi_fac = UI_DPI_FAC;
+      const int menus_width = 230 * dpi_fac;
+
+      /* use BKE_image_acquire_renderresult  so we get the correct slot in the menu */
+      rr = BKE_image_acquire_renderresult(scene, ima);
+      uiblock_layer_pass_buttons(layout, ima, rr, iuser, menus_width, &ima->render_slot);
+      BKE_image_release_renderresult(scene, ima);
+    }
 
-      if (ima->type == IMA_TYPE_COMPOSITE) {
-      }
-      else if (ima->type == IMA_TYPE_R_RESULT) {
-        /* browse layer/passes */
-        RenderResult *rr;
-        const float dpi_fac = UI_DPI_FAC;
-        const int menus_width = 230 * dpi_fac;
-
-        /* use BKE_image_acquire_renderresult  so we get the correct slot in the menu */
-        rr = BKE_image_acquire_renderresult(scene, ima);
-        uiblock_layer_pass_buttons(layout, ima, rr, iuser, menus_width, &ima->render_slot);
-        BKE_image_release_renderresult(scene, ima);
-      }
+    return;
+  }
+
+  /* Set custom callback for property updates. */
+  RNAUpdateCb *cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
+  cb->ptr = *ptr;
+  cb->prop = prop;
+  cb->iuser = iuser;
+  UI_block_funcN_set(block, rna_update_cb, cb, NULL);
+
+  /* Disable editing if image was modified, to avoid losing changes. */
+  const bool is_dirty = BKE_image_is_dirty(ima);
+  if (is_dirty) {
+    uiLayout *row = uiLayoutRow(layout, true);
+    uiItemO(row, IFACE_("Save"), ICON_NONE, "image.save");
+    uiItemO(row, IFACE_("Discard Changes"), ICON_NONE, "image.reload");
+    uiItemS(layout);
+  }
+
+  layout = uiLayoutColumn(layout, false);
+  uiLayoutSetEnabled(layout, !is_dirty);
+  uiLa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list