mini-arcade-native-backend 0.4.2__cp39-cp39-win_amd64.whl → 0.4.4__cp39-cp39-win_amd64.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.
@@ -7,6 +7,7 @@ from __future__ import annotations
7
7
  import os
8
8
  import sys
9
9
  from pathlib import Path
10
+ from typing import Union
10
11
 
11
12
  # --- 1) Make sure Windows can find SDL2.dll when using vcpkg ------------------
12
13
 
@@ -48,6 +49,7 @@ from . import _native as native
48
49
 
49
50
  __all__ = ["NativeBackend", "native"]
50
51
 
52
+ Alpha = Union[float, int]
51
53
 
52
54
  _NATIVE_TO_CORE = {
53
55
  native.EventType.Unknown: EventType.UNKNOWN,
@@ -208,6 +210,43 @@ class NativeBackend(Backend):
208
210
  """End the current frame for rendering."""
209
211
  self._engine.end_frame()
210
212
 
213
+ @staticmethod
214
+ def _alpha_to_u8(alpha: Alpha | None) -> int:
215
+ """Convert CSS-like alpha (0..1) to uint8 (0..255)."""
216
+ if alpha is None:
217
+ return 255
218
+
219
+ # disallow booleans (since bool is a subclass of int)
220
+ if isinstance(alpha, bool):
221
+ raise TypeError("alpha must be a float in [0,1], not bool")
222
+
223
+ a = float(alpha)
224
+
225
+ # Enforce “percentage only”
226
+ if a < 0.0 or a > 1.0:
227
+ raise ValueError(f"alpha must be in [0, 1], got {alpha!r}")
228
+
229
+ return int(round(a * 255))
230
+
231
+ @staticmethod
232
+ def _get_color_values(color: tuple[int, ...]) -> int:
233
+ """
234
+ Extract alpha value from color tuple (r,g,b) or (r,g,b,a).
235
+ If missing, returns default.
236
+ """
237
+ if len(color) == 3:
238
+ r, g, b = color
239
+ a_u8 = 255
240
+ elif len(color) == 4:
241
+ r, g, b, a = color
242
+ a_u8 = NativeBackend._alpha_to_u8(a)
243
+ else:
244
+ raise ValueError(
245
+ f"Color must be (r,g,b) or (r,g,b,a), got {color!r}"
246
+ )
247
+
248
+ return (int(r), int(g), int(b), a_u8)
249
+
211
250
  # pylint: disable=too-many-arguments,too-many-positional-arguments
212
251
  def draw_rect(
213
252
  self,
@@ -235,16 +274,8 @@ class NativeBackend(Backend):
235
274
  :param color: Color of the rectangle as (r, g, b) or (r, g, b, a).
236
275
  :type color: tuple[int, ...]
237
276
  """
238
- if len(color) == 3:
239
- r, g, b = color
240
- self._engine.draw_rect(x, y, w, h, r, g, b)
241
- elif len(color) == 4:
242
- r, g, b, a = color
243
- self._engine.draw_rect_rgba(x, y, w, h, r, g, b, a)
244
- else:
245
- raise ValueError(
246
- f"Color must be (r,g,b) or (r,g,b,a), got {color!r}"
247
- )
277
+ r, g, b, a = self._get_color_values(color)
278
+ self._engine.draw_rect(x, y, w, h, r, g, b, a)
248
279
 
249
280
  # pylint: enable=too-many-arguments,too-many-positional-arguments
250
281
 
@@ -271,12 +302,13 @@ class NativeBackend(Backend):
271
302
  :param color: Color of the text as (r, g, b).
272
303
  :type color: tuple[int, int, int]
273
304
  """
274
- # We rely on C++ side to no-op if font is missing
275
- r, g, b = color
305
+ r, g, b, a = self._get_color_values(color)
276
306
  font_id = (
277
307
  self._default_font_id if self._default_font_id is not None else -1
278
308
  )
279
- self._engine.draw_text(text, x, y, int(r), int(g), int(b), font_id)
309
+ self._engine.draw_text(
310
+ text, x, y, int(r), int(g), int(b), int(a), font_id
311
+ )
280
312
 
281
313
  def capture_frame(self, path: str | None = None) -> bool:
282
314
  """
@@ -289,4 +321,18 @@ class NativeBackend(Backend):
289
321
  False otherwise.
290
322
  :rtype: bool
291
323
  """
324
+ if path is None:
325
+ raise ValueError("Path must be provided to capture frame.")
292
326
  return self._engine.capture_frame(path)
327
+
328
+ def measure_text(self, text: str) -> tuple[int, int]:
329
+ """
330
+ Measure text size (width, height) in pixels for the active font.
331
+
332
+ Returns (0,0) if no font is loaded (matches draw_text no-op behavior).
333
+ """
334
+ font_id = (
335
+ self._default_font_id if self._default_font_id is not None else -1
336
+ )
337
+ w, h = self._engine.measure_text(text, font_id)
338
+ return int(w), int(h)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mini-arcade-native-backend
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Native SDL2 backend for mini-arcade-core using SDL2 + pybind11.
5
5
  Author-Email: Santiago Rincon <rincores@gmail.com>
6
6
  License: Copyright (c) 2025 Santiago Rincón
@@ -0,0 +1,6 @@
1
+ mini_arcade_native_backend/__init__.py,sha256=F7grqK1WRo-Of-hW7AJBXSTt0U_omah_13NtPBymE5s,11101
2
+ mini_arcade_native_backend/_native.cp39-win_amd64.pyd,sha256=qDg6KhKHBXoIFUY0y6TUBfE9TJnNO5CmXgvTxdDAsvo,225280
3
+ mini_arcade_native_backend-0.4.4.dist-info/METADATA,sha256=X2xdVGJhP3bTdpchuZuW_kNtRQQF583oTECtJ2OJ34A,10517
4
+ mini_arcade_native_backend-0.4.4.dist-info/WHEEL,sha256=9tsL4JT94eZPTkcS3bNng2riasYJMxXndrO9CxUfJHs,104
5
+ mini_arcade_native_backend-0.4.4.dist-info/licenses/LICENSE,sha256=cZRgTdRJ3YASekMxkGAvylB2nROh4ov228DxAogK3yY,1115
6
+ mini_arcade_native_backend-0.4.4.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- mini_arcade_native_backend/__init__.py,sha256=R6N7QYH4Ez6mmZOtdJd3UcPqo4obAW9um7w9Hjsrv6o,9609
2
- mini_arcade_native_backend/_native.cp39-win_amd64.pyd,sha256=JLEP6P9GwAN5bAqZELyb564bdKecAfhtAS_G4ExEsPg,224768
3
- mini_arcade_native_backend-0.4.2.dist-info/METADATA,sha256=9xVRtkbI96F7nljlKYgChuP6Au-z1jA6-pAhteCitOk,10517
4
- mini_arcade_native_backend-0.4.2.dist-info/WHEEL,sha256=9tsL4JT94eZPTkcS3bNng2riasYJMxXndrO9CxUfJHs,104
5
- mini_arcade_native_backend-0.4.2.dist-info/licenses/LICENSE,sha256=cZRgTdRJ3YASekMxkGAvylB2nROh4ov228DxAogK3yY,1115
6
- mini_arcade_native_backend-0.4.2.dist-info/RECORD,,