4from pathlib
import Path
5from typing
import TYPE_CHECKING, Sequence
7from ._native
import mxvk
29 def __init__(self, path: str | Path, size: int) ->
None:
48 def __init__(self, app:
"App", image: str | Path |
None =
None, *, width: int = 0, height: int = 0, vertex_shader: str =
"", fragment_shader: str =
"") ->
None:
59 self.
native = app.create_sprite(str(image), vertex_shader, fragment_shader)
60 elif width > 0
and height > 0:
61 self.
native = app.create_sprite(width, height, vertex_shader, fragment_shader)
63 raise ValueError(
"provide image or positive width and height")
70 def draw(self, x: int = 0, y: int = 0, *, width: int |
None =
None, height: int |
None =
None, scale: float = 1.0, rotation: float = 0.0) ->
None:
78 if width
is not None or height
is not None:
79 if width
is None or height
is None:
80 raise ValueError(
"width and height must be supplied together")
81 self.
native.draw_rect(x, y, width, height)
83 self.
native.draw_rotated(x, y, scale, scale, rotation)
89 def update(self, pixels: object, width: int, height: int, *, pitch: int = 0) ->
None:
95 self.
native.update_texture(pixels, width, height, pitch)
97 def shader_params(self, first: float = 0.0, second: float = 0.0, third: float = 0.0, fourth: float = 0.0) ->
None:
99 self.
native.set_shader_params(first, second, third, fourth)
103 self.
native.enable_extended_ubo()
105 def set_mouse(self, x: float, y: float, pressed: bool =
False) ->
None:
110 self.
native.set_mouse_state(x, y, 1.0
if pressed
else 0.0)
112 def set_uniform(self, index: int, x: float, y: float, z: float, w: float) ->
None:
119 if index
not in range(4):
120 raise ValueError(
"uniform index must be from 0 through 3")
121 getattr(self.
native, f
"set_uniform{index}")(x, y, z, w)
133 def __init__(self, app:
"App", image: str | Path, *, vertex_shader: str =
"", fragment_shader: str =
"") ->
None:
137 self.
native = app.create_sprite3d(str(image), vertex_shader, fragment_shader)
143 def queue(self, position: Sequence[float], size: Sequence[float], color: Sequence[float] = (1.0, 1.0, 1.0, 1.0), rotation: float = 0.0) ->
None:
145 self.
native.draw(tuple(position), tuple(size), tuple(color), rotation)
149 if self.
native is not None:
157 def __init__(self, app:
"App", path: str | Path, *, textures: str | Path =
"", texture_directory: str | Path =
"", scale: float = 1.0) ->
None:
162 self.
native = mxvk.AbstractModel()
163 self.
native.load(app, str(path), str(textures), str(texture_directory), scale)
170 def shaders(self, app:
"App", vertex: str | Path, fragment: str | Path) ->
None:
172 self.
native.set_shaders(app, str(vertex), str(fragment))
176 if self.
native is not None:
182 if self.
native is not None:
190 def __init__(self, app:
"App", size: int, *, storage: bool =
False) ->
None:
194 self.
native = mxvk.create_storage_buffer(app, size)
if storage
else mxvk.create_uniform_buffer(app, size)
200 def write(self, data: bytes) ->
None:
206 if self.
native is not None:
214 def __init__(self, app:
"App", path: str | Path) ->
None:
218 self.
native = mxvk.load_texture(app, str(path))
226 if self.
native is not None:
Small RAII wrapper for an SDL_ttf font handle.
native
Load a font file at the requested point size.
None __init__(self, str|Path path, int size)
A reusable TrueType font for individual text draw calls.
None write(self, bytes data)
native
Allocate a buffer with size bytes.
None __init__(self, "App" app, int size, *, bool storage=False)
A small host-writable uniform or storage buffer.
native
Load path into an application-owned GPU texture.
None __init__(self, "App" app, str|Path path)
A GPU texture loaded from an image file.
None shaders(self, "App" app, str|Path vertex, str|Path fragment)
_app
Load a model and retain its application lifetime.
None cleanup(self, "App" app)
native
Explicitly free model GPU resources before closing app.
None __init__(self, "App" app, str|Path path, *, str|Path textures="", str|Path texture_directory="", float scale=1.0)
A loadable 3D model with one-call setup.
native
Load a 3D sprite owned by app.
None __init__(self, "App" app, str|Path image, *, str vertex_shader="", str fragment_shader="")
A billboard sprite rendered through MXVK's 3D command callback.
None queue(self, Sequence[float] position, Sequence[float] size, Sequence[float] color=(1.0, 1.0, 1.0, 1.0), float rotation=0.0)
native
Create an image sprite or an empty dynamic texture.
None enable_extended_uniforms(self)
None set_mouse(self, float x, float y, bool pressed=False)
None draw(self, int x=0, int y=0, *, int|None width=None, int|None height=None, float scale=1.0, float rotation=0.0)
None set_uniform(self, int index, float x, float y, float z, float w)
None shader_params(self, float first=0.0, float second=0.0, float third=0.0, float fourth=0.0)
None update(self, object pixels, int width, int height, *, int pitch=0)
None __init__(self, "App" app, str|Path|None image=None, *, int width=0, int height=0, str vertex_shader="", str fragment_shader="")
A 2D image that can be queued for drawing each frame.
None _abort_failed_resource("App" app)