diff options
Diffstat (limited to 'release/scripts/modules/bpy_types.py')
-rw-r--r-- | release/scripts/modules/bpy_types.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index 600b29a6b2b..78c70225a04 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -592,6 +592,102 @@ class OrderedMeta(RNAMeta): return OrderedDictMini() # collections.OrderedDict() +# Same as 'Operator' +# only without 'as_keywords' +class Manipulator(StructRNA, metaclass=OrderedMeta): + __slots__ = () + + def __getattribute__(self, attr): + properties = StructRNA.path_resolve(self, "properties") + bl_rna = getattr(properties, "bl_rna", None) + if (bl_rna is not None) and (attr in bl_rna.properties): + return getattr(properties, attr) + return super().__getattribute__(attr) + + def __setattr__(self, attr, value): + properties = StructRNA.path_resolve(self, "properties") + bl_rna = getattr(properties, "bl_rna", None) + if (bl_rna is not None) and (attr in bl_rna.properties): + return setattr(properties, attr, value) + return super().__setattr__(attr, value) + + def __delattr__(self, attr): + properties = StructRNA.path_resolve(self, "properties") + bl_rna = getattr(properties, "bl_rna", None) + if (bl_rna is not None) and (attr in bl_rna.properties): + return delattr(properties, attr) + return super().__delattr__(attr) + + from _bpy import ( + _rna_manipulator_target_set_handler as target_set_handler, + _rna_manipulator_target_get_value as target_get_value, + _rna_manipulator_target_set_value as target_set_value, + _rna_manipulator_target_get_range as target_get_range, + ) + + # Convenience wrappers around private `_gawain` module. + def draw_custom_shape(self, shape, *, matrix=None, select_id=None): + """ + Draw a shape created form :class:`bpy.types.Manipulator.draw_custom_shape`. + + :arg shape: The cached shape to draw. + :type shape: Undefined. + :arg matrix: 4x4 matrix, when not given + :class:`bpy.types.Manipulator.matrix_world` is used. + :type matrix: :class:`mathutils.Matrix` + :arg select_id: The selection id. + Only use when drawing within :class:`bpy.types.Manipulator.draw_select`. + :type select_it: int + """ + import gpu + + if matrix is None: + matrix = self.matrix_world + + if select_id is not None: + gpu.select.load_id(select_id) + else: + if self.is_highlight: + color = (*self.color_highlight, self.alpha_highlight) + else: + color = (*self.color, self.alpha) + shape.uniform_f32("color", *color) + + with gpu.matrix.push_pop(): + gpu.matrix.multiply_matrix(matrix) + shape.draw() + + @staticmethod + def new_custom_shape(type, verts): + """ + Create a new shape that can be passed to :class:`bpy.types.Manipulator.draw_custom_shape`. + + :arg type: The type of shape to create in (POINTS, LINES, TRIS, LINE_STRIP). + :type type: string + :arg verts: Coordinates. + :type verts: sequence of of 2D or 3D coordinates. + :arg display_name: Optional callback that takes the full path, returns the name to display. + :type display_name: Callable that takes a string and returns a string. + :return: The newly created shape. + :rtype: Undefined (it may change). + """ + from _gawain.types import ( + Gwn_Batch, + Gwn_VertBuf, + Gwn_VertFormat, + ) + dims = len(verts[0]) + if dims not in {2, 3}: + raise ValueError("Expected 2D or 3D vertex") + fmt = Gwn_VertFormat() + pos_id = fmt.attr_add(id="pos", comp_type='F32', len=dims, fetch_mode='FLOAT') + vbo = Gwn_VertBuf(len=len(verts), format=fmt) + vbo.fill(id=pos_id, data=verts) + batch = Gwn_Batch(type=type, buf=vbo) + batch.program_set_builtin('3D_UNIFORM_COLOR' if dims == 3 else '2D_UNIFORM_COLOR') + return batch + + # Only defined so operators members can be used by accessing self.order # with doc generation 'self.properties.bl_rna.properties' can fail class Operator(StructRNA, metaclass=OrderedMeta): |