Skip to content

Commit 6e09015

Browse files
committed
Added core_drop_files.py; get_dropped_files() now returns a tuple of
str, instead of CharPtrPtr.
1 parent 14d2e82 commit 6e09015

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

examples/core/core_3d_picking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def main() -> int:
1111

1212
init_window(screen_width, screen_height, b"raylib [core] example - 3d picking")
1313

14-
#
14+
# Define the camera to look into our 3d world
1515
camera: Camera = Camera()
1616
camera.position = Vector3(10., 10., 10.)
1717
camera.target = Vector3(0., 0., 0.)

raylibpy/__init__.py

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,14 @@
968968
# -------------------------------------------------------------------
969969

970970
class Vector2(Structure):
971+
"""
972+
Wrapper for raylib Vector2 struct:
973+
974+
typedef struct Vector2 {
975+
float x;
976+
float y;
977+
} Vector2;
978+
"""
971979
_fields_ = [
972980
('x', c_float),
973981
('y', c_float)
@@ -978,6 +986,15 @@ class Vector2(Structure):
978986

979987

980988
class Vector3(Structure):
989+
"""
990+
Wrapper for raylib Vector3 struct:
991+
992+
typedef struct Vector3 {
993+
float x;
994+
float y;
995+
float z;
996+
} Vector3;
997+
"""
981998
_fields_ = [
982999
('x', c_float),
9831000
('y', c_float),
@@ -989,6 +1006,16 @@ class Vector3(Structure):
9891006

9901007

9911008
class Vector4(Structure):
1009+
"""
1010+
Wrapper for raylib Vector4 struct:
1011+
1012+
typedef struct Vector4 {
1013+
float x;
1014+
float y;
1015+
float z;
1016+
float w;
1017+
} Vector4;
1018+
"""
9921019
_fields_ = [
9931020
('x', c_float),
9941021
('y', c_float),
@@ -1057,7 +1084,6 @@ class Image(Structure):
10571084

10581085
class Texture2D(Structure):
10591086
_fields_ = [
1060-
('data', c_void_p),
10611087
('id', c_uint),
10621088
('width', c_int),
10631089
('height', c_int),
@@ -1454,7 +1480,11 @@ class VrDeviceInfo(Structure):
14541480
_rl.InitWindow.restype = None
14551481
def init_window(width: int, height: int, title: bytes) -> None:
14561482
"""Initialize window and OpenGL context"""
1457-
return _rl.InitWindow(width, height, title)
1483+
return _rl.InitWindow(
1484+
width if isinstance(width, int) else int(width),
1485+
height if isinstance(width, int) else int(width),
1486+
title if isinstance(title, bytes) else title.encode('utf-8', 'ignore')
1487+
)
14581488

14591489

14601490
_rl.CloseWindow.argtypes = _NOARGS
@@ -1510,28 +1540,38 @@ def set_window_title(title: bytes) -> None:
15101540
_rl.SetWindowPosition.restype = None
15111541
def set_window_position(x: int, y: int) -> None:
15121542
"""Set window position on screen (only PLATFORM_DESKTOP)"""
1513-
return _rl.SetWindowPosition(x, y)
1543+
return _rl.SetWindowPosition(
1544+
x if isinstance(x, int) else int(x),
1545+
y if isinstance(y, int) else int(y)
1546+
)
1547+
1548+
def set_window_position_v(pos: Vector2) -> None:
1549+
"""Set window position on screen (only PLATFORM_DESKTOP)"""
1550+
return _rl.SetWindowPosition(
1551+
pos.x if isinstance(pos.x, int) else int(pos.x),
1552+
pos.y if isinstance(pos.y, int) else int(pos.y)
1553+
)
15141554

15151555

15161556
_rl.SetWindowMonitor.argtypes = [Int]
15171557
_rl.SetWindowMonitor.restype = None
15181558
def set_window_monitor(monitor: int) -> None:
15191559
"""Set monitor for the current window (fullscreen mode)"""
1520-
return _rl.SetWindowMonitor(monitor)
1560+
return _rl.SetWindowMonitor(int(monitor))
15211561

15221562

15231563
_rl.SetWindowMinSize.argtypes = [Int, Int]
15241564
_rl.SetWindowMinSize.restype = None
15251565
def set_window_min_size(width: int, height: int) -> None:
15261566
"""Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)"""
1527-
return _rl.SetWindowMinSize(width, height)
1567+
return _rl.SetWindowMinSize(int(width), int(height))
15281568

15291569

15301570
_rl.SetWindowSize.argtypes = [Int, Int]
15311571
_rl.SetWindowSize.restype = None
15321572
def set_window_size(width: int, height: int):
15331573
"""Set window dimensions"""
1534-
return _rl.SetWindowSize(width, height)
1574+
return _rl.SetWindowSize(int(width), int(height))
15351575

15361576

15371577
_rl.GetScreenWidth.argtypes = _NOARGS
@@ -1829,11 +1869,14 @@ def is_file_dropped() -> bool:
18291869

18301870
_rl.GetDroppedFiles.argtypes = [IntPtr]
18311871
_rl.GetDroppedFiles.restype = CharPtrPrt
1832-
def get_dropped_files() -> Tuple[int, bytes]:
1872+
def get_dropped_files() -> Tuple[str, ...]:
18331873
"""Get dropped files names"""
18341874
count = Int(0)
1835-
files: bytes = _rl.GetDroppedFiles(byref(count))
1836-
return count.value, files
1875+
result = _rl.GetDroppedFiles(byref(count))
1876+
files: list = []
1877+
for i in range(count.value):
1878+
files.append(result[i].decode('utf-8'))
1879+
return tuple(files)
18371880

18381881

18391882
_rl.ClearDroppedFiles.argtypes = _NOARGS
@@ -2409,7 +2452,7 @@ def check_collision_point_triangle(point: Vector2, p1: Vector2, p2: Vector2, p3:
24092452
_rl.LoadImage.restype = Image
24102453
def load_image(file_name: bytes) -> Image:
24112454
"""Load image from file into CPU memory (RAM)"""
2412-
return _rl.LoadImage(file_name)
2455+
return _rl.LoadImage(file_name if isinstance(file_name, bytes) else file_name.encode('utf-8', 'ignore'))
24132456

24142457

24152458
_rl.LoadImageEx.argtypes = [ColorPtr, Int, Int]
@@ -2891,7 +2934,8 @@ def draw_fps(pos_x: int, pos_y: int) -> None:
28912934
_rl.DrawText.restype = None
28922935
def draw_text(text: bytes, pos_x: int, pos_y: int, font_size: int, color: Color) -> None:
28932936
"""Draw text (using default font)"""
2894-
return _rl.DrawText(text, pos_x, pos_y, font_size, color)
2937+
return _rl.DrawText(text if isinstance(text, bytes) else text.encode('utf-8', 'ignore'),
2938+
pos_x, pos_y, font_size, color)
28952939

28962940

28972941
_rl.DrawTextEx.argtypes = [Font, CharPtr, Vector2, Float, Float, Color]

0 commit comments

Comments
 (0)