thorvg-python 1.0.1__py3-none-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env python3
2
+ import ctypes
3
+ from typing import Optional
4
+
5
+ from ..base import PaintStruct, Result
6
+ from ..engine import Engine
7
+ from . import Paint
8
+
9
+
10
+ class Scene(Paint):
11
+ """
12
+ Scene API
13
+
14
+ A module managing the multiple paints as one group paint.
15
+
16
+ As a group, scene can be transformed, translucent, composited with other target paints,
17
+ its children will be affected by the scene world.
18
+ """
19
+
20
+ def __init__(self, engine: Engine, scene: Optional[PaintStruct] = None):
21
+ self.engine = engine
22
+ self.thorvg_lib = engine.thorvg_lib
23
+ if scene is None:
24
+ self._paint = self._new()
25
+ else:
26
+ self._paint = scene
27
+
28
+ def _new(self) -> PaintStruct:
29
+ """Creates a new scene object.
30
+
31
+ Note that you need not call this method as it is auto called when initializing ``Scene()``.
32
+
33
+ A scene object is used to group many paints into one object, which can be manipulated using TVG APIs.
34
+
35
+ :return: A new scene object.
36
+ :rtype: PaintStruct
37
+ """
38
+ self.thorvg_lib.tvg_scene_new.restype = ctypes.POINTER(PaintStruct)
39
+ return self.thorvg_lib.tvg_scene_new().contents
40
+
41
+ def reserve(
42
+ self,
43
+ size: int,
44
+ ) -> Result:
45
+ """Sets the size of the container, where all the paints pushed into the scene are stored.
46
+
47
+ If the number of objects pushed into the scene is known in advance, calling the function
48
+ prevents multiple memory reallocation, thus improving the performance.
49
+
50
+ :param int size: The number of objects for which the memory is to be reserved.
51
+
52
+ :return:
53
+ - FAILED_ALLOCATION An internal error with a memory allocation.
54
+ - INVALID_ARGUMENT An invalid PaintStruct pointer.
55
+ :rtype: Result
56
+
57
+ .. deprecated:: 0.15
58
+ .. note:: Malfunctional
59
+ """
60
+ self.thorvg_lib.tvg_scene_reserve.argtypes = [
61
+ ctypes.POINTER(PaintStruct),
62
+ ctypes.c_uint32,
63
+ ]
64
+ self.thorvg_lib.tvg_scene_reserve.restype = Result
65
+ return self.thorvg_lib.tvg_scene_reserve(
66
+ ctypes.pointer(self._paint),
67
+ ctypes.c_uint32(size),
68
+ )
69
+
70
+ def push(
71
+ self,
72
+ paint: Paint,
73
+ ) -> Result:
74
+ """Passes drawing elements to the scene using PaintStruct objects.
75
+
76
+ Only the paints pushed into the scene will be the drawn targets.
77
+ The paints are retained by the scene until the tvg_scene_clear() is called.
78
+ If you know the number of pushed objects in advance, please call tvg_scene_reserve().
79
+
80
+ :param PaintStruct paint: A graphical object to be drawn.
81
+
82
+ :return: INVALID_ARGUMENT A ``nullptr`` passed as the argument.
83
+ :rtype: Result
84
+
85
+ .. note::
86
+ The rendering order of the paints is the same as the order as they were pushed. Consider sorting the paints before pushing them if you intend to use layering.
87
+ """
88
+ self.thorvg_lib.tvg_scene_push.argtypes = [
89
+ ctypes.POINTER(PaintStruct),
90
+ ctypes.POINTER(PaintStruct),
91
+ ]
92
+ self.thorvg_lib.tvg_scene_push.restype = Result
93
+ return self.thorvg_lib.tvg_scene_push(
94
+ ctypes.pointer(self._paint),
95
+ ctypes.pointer(paint._paint),
96
+ )
97
+
98
+ def clear(
99
+ self,
100
+ free: bool,
101
+ ) -> Result:
102
+ """Clears a scene objects from pushed paints.
103
+
104
+ PaintStruct objects stored in the scene are released if ``free`` is set to ``true``, otherwise the memory is not deallocated and
105
+ all paints should be released manually in order to avoid memory leaks.
106
+
107
+ :param bool free: If ``true`` the memory occupied by paints is deallocated, otherwise it is not.
108
+
109
+ :return: INVALID_ARGUMENT An invalid CanvasStruct pointer.
110
+ :rtype: Result
111
+
112
+ .. warning::
113
+ Please use the ``free`` argument only when you know how it works, otherwise it's not recommended.
114
+ """
115
+ self.thorvg_lib.tvg_scene_clear.argtypes = [
116
+ ctypes.POINTER(PaintStruct),
117
+ ctypes.c_bool,
118
+ ]
119
+ self.thorvg_lib.tvg_scene_clear.restype = Result
120
+ return self.thorvg_lib.tvg_scene_clear(
121
+ ctypes.pointer(self._paint),
122
+ ctypes.c_bool(free),
123
+ )