[Bf-blender-cvs] [56ef761381e] master: Image Editor: Initialize Add Tile options from current tile

Lukas Stockner noreply at git.blender.org
Mon Dec 30 19:26:38 CET 2019


Commit: 56ef761381ecdac6c1c379044ccf8b2fb296a9bd
Author: Lukas Stockner
Date:   Mon Dec 30 19:14:56 2019 +0100
Branches: master
https://developer.blender.org/rB56ef761381ecdac6c1c379044ccf8b2fb296a9bd

Image Editor: Initialize Add Tile options from current tile

Previously, non-default alpha or float settings had be set manually.

With this change, the Add Tile and Fill Tile operators initialize
width, height, alpha and float from the currently selected tile
if it has a vaild ImBuf, otherwise from the first tile.

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

M	source/blender/editors/space_image/image_ops.c

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

diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 586d7995ed8..061ed978acd 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -4279,6 +4279,33 @@ static void draw_fill_tile(PointerRNA *ptr, uiLayout *layout)
   uiItemR(col[1], ptr, "float", 0, NULL, ICON_NONE);
 }
 
+static void initialize_fill_tile(PointerRNA *ptr, Image *ima, ImageTile *tile)
+{
+  ImageUser iuser;
+  BKE_imageuser_default(&iuser);
+  if (tile != NULL) {
+    iuser.tile = tile->tile_number;
+  }
+
+  /* Acquire ibuf to get the default values.
+   * If the specified tile has no ibuf, try acquiring the main tile instead
+   * (unless the specified tile already was the main tile).*/
+  ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
+  if (ibuf == NULL && (tile != NULL) && (tile->tile_number != 1001)) {
+    ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
+  }
+
+  if (ibuf != NULL) {
+    /* Initialize properties from reference tile. */
+    RNA_int_set(ptr, "width", ibuf->x);
+    RNA_int_set(ptr, "height", ibuf->y);
+    RNA_boolean_set(ptr, "float", ibuf->rect_float != NULL);
+    RNA_boolean_set(ptr, "alpha", ibuf->planes > 24);
+
+    BKE_image_release_ibuf(ima, ibuf, NULL);
+  }
+}
+
 static void def_fill_tile(StructOrFunctionRNA *srna)
 {
   PropertyRNA *prop;
@@ -4358,6 +4385,9 @@ static int tile_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(ev
     }
   }
 
+  ImageTile *tile = BLI_findlink(&ima->tiles, ima->active_tile_index);
+  initialize_fill_tile(op->ptr, ima, tile);
+
   RNA_int_set(op->ptr, "number", next_number);
   RNA_int_set(op->ptr, "count", 1);
   RNA_string_set(op->ptr, "label", "");
@@ -4487,17 +4517,7 @@ static int tile_fill_exec(bContext *C, wmOperator *op)
 
 static int tile_fill_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
-  Image *ima = CTX_data_edit_image(C);
-
-  /* Acquire first tile to get the defaults. */
-  ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
-  if (ibuf != NULL) {
-    RNA_int_set(op->ptr, "width", ibuf->x);
-    RNA_int_set(op->ptr, "height", ibuf->y);
-    RNA_boolean_set(op->ptr, "float", ibuf->rect_float != NULL);
-    RNA_boolean_set(op->ptr, "alpha", ibuf->planes > 24);
-    BKE_image_release_ibuf(ima, ibuf, NULL);
-  }
+  initialize_fill_tile(op->ptr, CTX_data_edit_image(C), NULL);
 
   return WM_operator_props_dialog_popup(C, op, 15 * UI_UNIT_X, 5 * UI_UNIT_Y);
 }



More information about the Bf-blender-cvs mailing list