Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
import sys
import os
import colorsys
from pathlib import Path
from math import modf
from enum import IntEnum, IntFlag
from typing import Tuple, List, Union, Sequence, AnyStr, Optional, Iterator, Type
from ctypes import (
c_bool,
c_char_p,
c_byte,
c_ubyte,
c_int,
# c_int32,
c_uint,
# c_uint32,
c_short,
c_ushort,
c_void_p,
# c_ssize_t,
# c_size_t,
c_float,
c_double,
POINTER,
CDLL,
Structure,
byref
)
_lib_filename = {
'win32': 'libraylib_shared.dll', # TODO(pbz): Should this instead be 'raylib_shared.dll' on Windows?
'linux': 'libraylib.so.2.0.0',
'darwin': 'libraylib.2.0.0.dylib',
}
_platform = sys.platform
ENABLE_V2_0_0_FEATURE_DRAWTEXTURENPATCH = False
ENABLE_V2_0_0_FEATURE_CLIPRECT = False
if "ENABLE_V2_0_0_FEATURE_DRAWTEXTURENPATCH" in os.environ:
ENABLE_V2_0_0_FEATURE_DRAWTEXTURENPATCH = True
if "ENABLE_V2_0_0_FEATURE_CLIPRECT" in os.environ:
ENABLE_V2_0_0_FEATURE_CLIPRECT = True
lib_name = _lib_filename[_platform]
main_mod = sys.modules['__main__']
running_from_repl = '__file__' not in dir(main_mod)
env_path = Path(os.environ['RAYLIB_BIN_PATH']) if 'RAYLIB_BIN_PATH' in os.environ else None
file_path = Path(__file__).parent
main_path = Path(main_mod.__file__).parent if not running_from_repl else Path('REPL')
if env_path and env_path.exists():
RAYLIB_BIN_PATH = env_path
elif (file_path / lib_name).exists():
RAYLIB_BIN_PATH = file_path
elif (main_path / lib_name).exists():
RAYLIB_BIN_PATH = main_path
else:
raise Exception(
(
'Cannot find "{}" in these search paths:\n'
'__file__ folder: "{}"\n'
'__main__ folder: "{}"\n'
'os.environ["RAYLIB_BIN_PATH"] -> "{}"'
).format(
lib_name,
str(file_path),
str(main_path),
str(env_path) if env_path else "NOT SET"
)
)
print('INFO: Found "{}" in "{}"'.format(lib_name, str(RAYLIB_BIN_PATH)))
_rl = CDLL(str(RAYLIB_BIN_PATH / lib_name))
__all__ = [
# CONSTANTS
'PI',
'DEG2RAD',
'RAD2DEG',
'FLAG_SHOW_LOGO',
'FLAG_FULLSCREEN_MODE',
'FLAG_WINDOW_RESIZABLE',
'FLAG_WINDOW_UNDECORATED',
'FLAG_WINDOW_TRANSPARENT',
'FLAG_MSAA_4X_HINT',
'FLAG_VSYNC_HINT',
'KEY_SPACE',
'KEY_ESCAPE',
'KEY_ENTER',
'KEY_TAB',
'KEY_BACKSPACE',
'KEY_INSERT',
'KEY_DELETE',
'KEY_RIGHT',
'KEY_LEFT',
'KEY_DOWN',
'KEY_UP',
'KEY_PAGE_UP',
'KEY_PAGE_DOWN',
'KEY_HOME',
'KEY_END',
'KEY_CAPS_LOCK',
'KEY_SCROLL_LOCK',
'KEY_NUM_LOCK',
'KEY_PRINT_SCREEN',
'KEY_PAUSE',
'KEY_F1',
'KEY_F2',
'KEY_F3',
'KEY_F4',
'KEY_F5',
'KEY_F6',
'KEY_F7',
'KEY_F8',
'KEY_F9',
'KEY_F10',
'KEY_F11',
'KEY_F12',
'KEY_LEFT_SHIFT',
'KEY_LEFT_CONTROL',
'KEY_LEFT_ALT',
'KEY_LEFT_SUPER',
'KEY_RIGHT_SHIFT',
'KEY_RIGHT_CONTROL',
'KEY_RIGHT_ALT',
'KEY_RIGHT_SUPER',
'KEY_GRAVE',
'KEY_SLASH',
'KEY_BACKSLASH',
'KEY_ZERO',
'KEY_ONE',
'KEY_TWO',
'KEY_THREE',
'KEY_FOUR',
'KEY_FIVE',
'KEY_SIX',
'KEY_SEVEN',
'KEY_EIGHT',
'KEY_NINE',
'KEY_A',
'KEY_B',
'KEY_C',
'KEY_D',
'KEY_E',
'KEY_F',
'KEY_G',
'KEY_H',
'KEY_I',
'KEY_J',
'KEY_K',
'KEY_L',
'KEY_M',
'KEY_N',
'KEY_O',
'KEY_P',
'KEY_Q',
'KEY_R',
'KEY_S',
'KEY_T',
'KEY_U',
'KEY_V',
'KEY_W',
'KEY_X',
'KEY_Y',
'KEY_Z',
'KEY_BACK',
'KEY_MENU',
'KEY_VOLUME_UP',
'KEY_VOLUME_DOWN',
'MOUSE_LEFT_BUTTON',
'MOUSE_RIGHT_BUTTON',
'MOUSE_MIDDLE_BUTTON',
'MAX_TOUCH_POINTS',
'GAMEPAD_PLAYER1',
'GAMEPAD_PLAYER2',
'GAMEPAD_PLAYER3',
'GAMEPAD_PLAYER4',
'GAMEPAD_PS3_BUTTON_TRIANGLE',
'GAMEPAD_PS3_BUTTON_CIRCLE',
'GAMEPAD_PS3_BUTTON_CROSS',
'GAMEPAD_PS3_BUTTON_SQUARE',
'GAMEPAD_PS3_BUTTON_L1',
'GAMEPAD_PS3_BUTTON_R1',
'GAMEPAD_PS3_BUTTON_L2',
'GAMEPAD_PS3_BUTTON_R2',
'GAMEPAD_PS3_BUTTON_START',
'GAMEPAD_PS3_BUTTON_SELECT',
'GAMEPAD_PS3_BUTTON_UP',
'GAMEPAD_PS3_BUTTON_RIGHT',
'GAMEPAD_PS3_BUTTON_DOWN',
'GAMEPAD_PS3_BUTTON_LEFT',
'GAMEPAD_PS3_BUTTON_PS',
'GAMEPAD_PS3_AXIS_LEFT_X',
'GAMEPAD_PS3_AXIS_LEFT_Y',
'GAMEPAD_PS3_AXIS_RIGHT_X',
'GAMEPAD_PS3_AXIS_RIGHT_Y',
'GAMEPAD_PS3_AXIS_L2',
'GAMEPAD_PS3_AXIS_R2',
'GAMEPAD_XBOX_BUTTON_A',
'GAMEPAD_XBOX_BUTTON_B',
'GAMEPAD_XBOX_BUTTON_X',
'GAMEPAD_XBOX_BUTTON_Y',
'GAMEPAD_XBOX_BUTTON_LB',
'GAMEPAD_XBOX_BUTTON_RB',
'GAMEPAD_XBOX_BUTTON_SELECT',
'GAMEPAD_XBOX_BUTTON_START',
'GAMEPAD_XBOX_BUTTON_UP',
'GAMEPAD_XBOX_BUTTON_RIGHT',
'GAMEPAD_XBOX_BUTTON_DOWN',
'GAMEPAD_XBOX_BUTTON_LEFT',
'GAMEPAD_XBOX_BUTTON_HOME',
'GAMEPAD_ANDROID_DPAD_UP',
'GAMEPAD_ANDROID_DPAD_DOWN',
'GAMEPAD_ANDROID_DPAD_LEFT',
'GAMEPAD_ANDROID_DPAD_RIGHT',
'GAMEPAD_ANDROID_DPAD_CENTER',
'GAMEPAD_ANDROID_BUTTON_A',
'GAMEPAD_ANDROID_BUTTON_B',
'GAMEPAD_ANDROID_BUTTON_C',
'GAMEPAD_ANDROID_BUTTON_X',
'GAMEPAD_ANDROID_BUTTON_Y',
'GAMEPAD_ANDROID_BUTTON_Z',
'GAMEPAD_ANDROID_BUTTON_L1',
'GAMEPAD_ANDROID_BUTTON_R1',
'GAMEPAD_ANDROID_BUTTON_L2',
'GAMEPAD_ANDROID_BUTTON_R2',
'MAX_SHADER_LOCATIONS',
'MAX_MATERIAL_MAPS',
# enumerations
'LogType',
'LOG_INFO',
'LOG_WARNING',
'LOG_ERROR',
'LOG_DEBUG',
'LOG_OTHER',
'ShaderLocationIndex',
'LOC_VERTEX_POSITION',
'LOC_VERTEX_TEXCOORD01',
'LOC_VERTEX_TEXCOORD02',
'LOC_VERTEX_NORMAL',
'LOC_VERTEX_TANGENT',
'LOC_VERTEX_COLOR',
'LOC_MATRIX_MVP',
'LOC_MATRIX_MODEL',
'LOC_MATRIX_VIEW',
'LOC_MATRIX_PROJECTION',
'LOC_VECTOR_VIEW',
'LOC_COLOR_DIFFUSE',
'LOC_COLOR_SPECULAR',
'LOC_COLOR_AMBIENT',
'LOC_MAP_ALBEDO',
'LOC_MAP_METALNESS',
'LOC_MAP_NORMAL',
'LOC_MAP_ROUGHNESS',
'LOC_MAP_OCCLUSION',
'LOC_MAP_EMISSION',
'LOC_MAP_HEIGHT',
'LOC_MAP_CUBEMAP',
'LOC_MAP_IRRADIANCE',
'LOC_MAP_PREFILTER',
'LOC_MAP_BRDF',
'LOC_MAP_DIFFUSE',
'LOC_MAP_SPECULAR',
'TexmapIndex',
'MAP_ALBEDO',
'MAP_METALNESS',
'MAP_NORMAL',
'MAP_ROUGHNESS',
'MAP_OCCLUSION',
'MAP_EMISSION',
'MAP_HEIGHT',
'MAP_CUBEMAP',
'MAP_IRRADIANCE',
'MAP_PREFILTER',
'MAP_BRDF',
'MAP_DIFFUSE',
'MAP_SPECULAR',
'PixelFormat',
'UNCOMPRESSED_GRAYSCALE',
'UNCOMPRESSED_GRAY_ALPHA',
'UNCOMPRESSED_R5G6B5',
'UNCOMPRESSED_R8G8B8',
'UNCOMPRESSED_R5G5B5A1',
'UNCOMPRESSED_R4G4B4A4',
'UNCOMPRESSED_R8G8B8A8',
'UNCOMPRESSED_R32',
'UNCOMPRESSED_R32G32B32',
'UNCOMPRESSED_R32G32B32A32',
'COMPRESSED_DXT1_RGB',
'COMPRESSED_DXT1_RGBA',
'COMPRESSED_DXT3_RGBA',
'COMPRESSED_DXT5_RGBA',
'COMPRESSED_ETC1_RGB',
'COMPRESSED_ETC2_RGB',
'COMPRESSED_ETC2_EAC_RGBA',
'COMPRESSED_PVRT_RGB',
'COMPRESSED_PVRT_RGBA',
'COMPRESSED_ASTC_4x4_RGBA',
'COMPRESSED_ASTC_8x8_RGBA',
'TextureFilterMode',
'FILTER_POINT',
'FILTER_BILINEAR',
'FILTER_TRILINEAR',
'FILTER_ANISOTROPIC_4X',
'FILTER_ANISOTROPIC_8X',
'FILTER_ANISOTROPIC_16X',
'TextureWrapMode',
'WRAP_REPEAT',
'WRAP_CLAMP',
'WRAP_MIRROR',
'BlendMode',
'BLEND_ALPHA',
'BLEND_ADDITIVE',
'BLEND_MULTIPLIED',
'Gestures',
'GESTURE_NONE',
'GESTURE_TAP',
'GESTURE_DOUBLETAP',
'GESTURE_HOLD',
'GESTURE_DRAG',
'GESTURE_SWIPE_RIGHT',
'GESTURE_SWIPE_LEFT',
'GESTURE_SWIPE_UP',
'GESTURE_SWIPE_DOWN',
'GESTURE_PINCH_IN',
'GESTURE_PINCH_OUT',
'CameraMode',
'CAMERA_CUSTOM',
'CAMERA_FREE',
'CAMERA_ORBITAL',
'CAMERA_FIRST_PERSON',
'CAMERA_THIRD_PERSON',
'CameraType',
'CAMERA_PERSPECTIVE',
'CAMERA_ORTHOGRAPHIC',
'VrDeviceType',
'HMD_DEFAULT_DEVICE',
'HMD_OCULUS_RIFT_DK2',
'HMD_OCULUS_RIFT_CV1',
'HMD_OCULUS_GO',
'HMD_VALVE_HTC_VIVE',
'HMD_SONY_PSVR',
'NPatchType',
'NPT_9PATCH',
'NPT_3PATCH_VERTICAL',
'NPT_3PATCH_HORIZONTAL',
# raylib types
'AudioStream',
'BoundingBox',
'Camera',
'CameraPtr',
'Camera2D',
'Camera3D',
'Camera3DPtr',
'CharInfo',
'CharInfoPtr',
'Color',
'ColorPtr',
'Font',
'Image',
'ImagePtr',
'Material',
'MaterialMap',
'Matrix',
'Mesh',
'MeshPtr',
'Model',
'ModelPtr',
'Music',
'MusicData',
'Ray',
'RayHitInfo',
'Rectangle',
'RenderTexture',
'RenderTexture2D',
'NPatchInfo',
'Shader',
'Sound',
'SpriteFont',
'Texture',
'Texture2D',
'Texture2DPtr',
'Vector2',
'Vector2Ptr',
'Vector3',
'Vector3Ptr',
'Vector4',
'Vector4Ptr',
'VrDeviceInfo',
'Wave',
'WavePtr',
# C types
'Bool',
'VoidPtr',
'CharPtr',
'CharPtrPrt',
'UCharPtr',
'IntPtr',
'UIntPtr',
'FloatPtr',
'Char',
'UChar',
'Byte',
'Short',
'Int',
'UInt',
'Float',
'Double',
# Module: CORE
# window
'init_window',
'close_window',
'is_window_ready',
'window_should_close',
'is_window_minimized',
'toggle_fullscreen',
'set_window_icon',
'set_window_title',
'set_window_position',
'set_window_monitor',
'set_window_min_size',
'set_window_size',
'get_screen_width',
'get_screen_height',
'show_cursor',
'hide_cursor',
'is_cursor_hidden',
'enable_cursor',
'disable_cursor',
'clear_background',
'begin_drawing',
'end_drawing',
'begin_mode2d',
'end_mode2d',
'begin_mode3d',
'end_mode3d',
'begin_texture_mode',
'end_texture_mode',
'get_mouse_ray',
'get_world_to_screen',
'get_camera_matrix',
'set_target_fps',
'get_fps',
'get_frame_time',
'get_time',
'color_to_int',
'color_normalize',
'color_to_hsv',
'get_color',
'fade',
'show_logo',
'set_config_flags',
'set_trace_log',
'trace_log',
'take_screenshot',
'get_random_value',
'is_file_extension',
'get_extension',
'get_file_name',
'get_directory_path',
'get_working_directory',
'change_directory',
'is_file_dropped',
'get_dropped_files',
'clear_dropped_files',
'storage_save_value',
'storage_load_value',
# input
'is_key_pressed',
'is_key_down',
'is_key_released',
'is_key_up',
'get_key_pressed',
'set_exit_key',
'is_gamepad_available',
'is_gamepad_name',
'get_gamepad_name',
'is_gamepad_button_pressed',
'is_gamepad_button_down',
'is_gamepad_button_released',
'is_gamepad_button_up',
'get_gamepad_button_pressed',
'get_gamepad_axis_count',
'get_gamepad_axis_movement',
'is_mouse_button_pressed',
'is_mouse_button_down',
'is_mouse_button_released',
'is_mouse_button_up',
'get_mouse_x',
'get_mouse_y',
'get_mouse_position',
'set_mouse_position',
'set_mouse_scale',
'get_mouse_wheel_move',
'get_touch_x',
'get_touch_y',
'get_touch_position',
# Module: GESTURES
'set_gestures_enabled',
'is_gesture_detected',
'get_gesture_detected',
'get_touch_points_count',
'get_gesture_hold_duration',
'get_gesture_drag_vector',
'get_gesture_drag_angle',
'get_gesture_pinch_vector',
'get_gesture_pinch_angle',
# Module: CAMERA
'set_camera_mode',
'update_camera',
'set_camera_pan_control',
'set_camera_alt_control',
'set_camera_smooth_zoom_control',
'set_camera_move_controls',
# Module: SHAPES
'draw_pixel',
'draw_pixel_v',
'draw_line',
'draw_line_v',
'draw_line_ex',
'draw_line_bezier',
'draw_circle',
'draw_circle_gradient',
'draw_circle_v',
'draw_circle_lines',
'draw_rectangle',
'draw_rectangle_v',
'draw_rectangle_rec',
'draw_rectangle_pro',
'draw_rectangle_gradient_v',
'draw_rectangle_gradient_h',
'draw_rectangle_gradient_ex',
'draw_rectangle_lines',
'draw_rectangle_lines_ex',
'draw_triangle',
'draw_triangle_lines',
'draw_poly',
'draw_poly_ex',
'draw_poly_ex_lines',
# Basic shapes collision detection functions
'check_collision_recs',
'check_collision_circles',
'check_collision_circle_rec',
'get_collision_rec',
'check_collision_point_rec',
'check_collision_point_circle',
'check_collision_point_triangle',
# Module: TEXTURES
'load_image',
'load_image_ex',
'load_image_pro',
'load_image_raw',
'export_image',
'load_texture',
'load_texture_from_image',
'load_render_texture',
'unload_image',
'unload_texture',
'unload_render_texture',
'get_image_data',
'get_image_data_normalized',
'get_pixel_data_size',
'get_texture_data',
'update_texture',
'image_copy',
'image_to_pot',
'image_format',
'image_alpha_mask',
'image_alpha_clear',
'image_alpha_crop',
'image_alpha_premultiply',
'image_crop',
'image_resize',
'image_resize_nn',
'image_resize_canvas',
'image_mipmaps',
'image_dither',
'image_text',
'image_text_ex',
'image_draw',
'image_draw_rectangle',
'image_draw_text',
'image_draw_text_ex',
'image_flip_vertical',
'image_flip_horizontal',
'image_rotate_cw',
'image_rotate_ccw',
'image_color_tint',
'image_color_invert',
'image_color_grayscale',
'image_color_contrast',
'image_color_brightness',
'image_color_replace',
'gen_image_color',
'gen_image_gradient_v',
'gen_image_gradient_h',
'gen_image_gradient_radial',
'gen_image_checked',
'gen_image_white_noise',
'gen_image_perlin_noise',
'gen_image_cellular',
'gen_texture_mipmaps',
'set_texture_filter',
'set_texture_wrap',
'draw_texture',
'draw_texture_v',
'draw_texture_ex',
'draw_texture_rec',
'draw_texture_pro',
'draw_texture_npatch',
# Module: TEXT
'get_font_default',
'load_font',
'load_font_ex',
'load_font_data',
'gen_image_font_atlas',
'unload_font',
'draw_fps',
'draw_text',
'draw_text_ex',
'measure_text',
'measure_text_ex',
'format_text',
'sub_text',
'get_glyph_index',
# Module: MODELS
'draw_line3_d',
'draw_circle3_d',
'draw_cube',
'draw_cube_v',
'draw_cube_wires',
'draw_cube_texture',
'draw_sphere',
'draw_sphere_ex',
'draw_sphere_wires',
'draw_cylinder',
'draw_cylinder_wires',
'draw_plane',
'draw_ray',
'draw_grid',
'draw_gizmo',
'load_model',
'load_model_from_mesh',
'unload_model',
'load_mesh',
'unload_mesh',
'export_mesh',
'mesh_bounding_box',
'mesh_tangents',
'mesh_binormals',
'gen_mesh_plane',
'gen_mesh_cube',
'gen_mesh_sphere',
'gen_mesh_hemi_sphere',
'gen_mesh_cylinder',
'gen_mesh_torus',
'gen_mesh_knot',
'gen_mesh_heightmap',
'gen_mesh_cubicmap',
'load_material',
'load_material_default',
'unload_material',
'draw_model',
'draw_model_ex',
'draw_model_wires',
'draw_model_wires_ex',
'draw_bounding_box',
'draw_billboard',
'draw_billboard_rec',
'check_collision_spheres',
'check_collision_boxes',
'check_collision_box_sphere',
'check_collision_ray_sphere',
'check_collision_ray_sphere_ex',
'check_collision_ray_box',
'get_collision_ray_model',
'get_collision_ray_triangle',
'get_collision_ray_ground',
# Module: RLGL
'load_text',
'load_shader',
'load_shader_code',
'unload_shader',
'get_shader_default',
'get_texture_default',
'get_shader_location',
'set_shader_value',
'set_shader_valuei',
'set_shader_value_matrix',
'set_matrix_projection',
'set_matrix_modelview',
'get_matrix_modelview',
'gen_texture_cubemap',
'gen_texture_irradiance',
'gen_texture_prefilter',
'gen_texture_brdf',
'begin_shader_mode',
'end_shader_mode',
'begin_blend_mode',
'begin_clip_rec',
'end_clip_rec',
'end_blend_mode',
'get_vr_device_info',
'init_vr_simulator',
'close_vr_simulator',
'is_vr_simulator_ready',
'set_vr_distortion_shader',
'update_vr_tracking',
'toggle_vr_mode',
'begin_vr_drawing',
'end_vr_drawing',
# Module: AUDIO
'init_audio_device',
'close_audio_device',
'is_audio_device_ready',
'set_master_volume',
'load_wave',
'load_wave_ex',
'load_sound',
'load_sound_from_wave',
'update_sound',
'unload_wave',
'unload_sound',
'play_sound',
'pause_sound',
'resume_sound',
'stop_sound',
'is_sound_playing',
'set_sound_volume',
'set_sound_pitch',
'wave_format',
'wave_copy',
'wave_crop',
'get_wave_data',
'load_music_stream',
'unload_music_stream',
'play_music_stream',
'update_music_stream',
'stop_music_stream',
'pause_music_stream',
'resume_music_stream',
'is_music_playing',
'set_music_volume',
'set_music_pitch',
'set_music_loop_count',
'get_music_time_length',
'get_music_time_played',
'init_audio_stream',
'update_audio_stream',
'close_audio_stream',
'is_audio_buffer_processed',
'play_audio_stream',
'pause_audio_stream',
'resume_audio_stream',
'is_audio_stream_playing',
'stop_audio_stream',
'set_audio_stream_volume',
'set_audio_stream_pitch',
# Colors
'LIGHTGRAY',
'GRAY',
'DARKGRAY',
'YELLOW',
'GOLD',
'ORANGE',
'PINK',
'RED',
'MAROON',
'GREEN',
'LIME',
'DARKGREEN',
'SKYBLUE',
'BLUE',
'DARKBLUE',
'PURPLE',
'VIOLET',
'DARKPURPLE',
'BEIGE',
'BROWN',
'DARKBROWN',
'WHITE',
'BLACK',
'BLANK',
'MAGENTA',
'RAYWHITE',
'byref',
]
# -----------------------------------------------------------------------------------
# Package utility functions and types
# ----------------------------------------------------------------------------------
Bool = c_bool
VoidPtr = c_void_p
CharPtr = c_char_p
CharPtrPrt = POINTER(c_char_p)
UCharPtr = POINTER(c_ubyte)
IntPtr = POINTER(c_int)
UIntPtr = POINTER(c_uint)
FloatPtr = POINTER(c_float)
Char = c_byte
UChar = c_ubyte
Byte = c_byte
Short = c_short
Int = c_int
UInt = c_uint
Float = c_float
Double = c_double
Number = Union[int, float]
Seq = Sequence[Number]
VectorN = Union[Seq, 'Vector4', 'Vector3', 'Vector2']
def _float(value) -> float:
return float(value) if isinstance(value, int) else value
def _int(value) -> int:
return int(value) if isinstance(value, float) else value
def _str_in(value: bytes) -> str:
return value.encode('utf-8', 'ignore') if isinstance(value, str) else value
def _str_out(value: str) -> bytes:
return value.decode('utf-8', 'ignore') if isinstance(value, bytes) else value
def _vec2(seq: Sequence[Number]) -> 'Vector2':
if isinstance(seq, Vector2):
return seq
x, y = seq
return Vector2(_float(x), _float(y))
def _vec3(seq: Sequence[Number]) -> 'Vector3':
if isinstance(seq, Vector3):
return seq
x, y, z = seq
return Vector3(_float(x), _float(y), _float(z))
def _vec4(seq: Sequence[Number]) -> 'Vector3':
if isinstance(seq, Vector4):
return seq
x, y, z, w = seq
return Vector4(_float(x), _float(y), _float(z), _float(w))
def _rect(seq: Sequence[Number]) -> 'Rectangle':
if isinstance(seq, Rectangle):
return seq
x, y, w, h = seq
return Rectangle(_float(x), _float(y), _float(w), _float(h))
def _color(seq: Sequence[Number]) -> 'Color':
if isinstance(seq, Color):
return seq
r, g, b, q = seq
return Color(_float(r), _float(r), _float(b), _float(q))
def _attr_swizzle(attr: str, size: int, write: bool=False) -> Tuple[bool, str]:
if len(attr) not in (1, 2, 3, 4):
return False, "Wrong number of components to swizzle (must be 1, 2, 3 or 4; not {}).".format(len(attr))
if size not in (2, 3, 4):
return False, "Wrong vector size (must be 2, 3 or 4; not {}).".format(size)
groups = ['xyzw', 'uv', 'rgba']
if size == 3:
groups = ['xyz', 'uv', 'rgb']
elif size == 2:
groups = ['xy', 'uv', '']
if attr[0] in groups[0]:
group = 0
elif attr[0] in groups[1]:
group = 1
elif attr[0] in groups[2]:
group = 2
else:
return False, "Invalid component '{}' in swizzled Vector{} attribute.".format(attr[0], size)
already_set = []
result = ''
for i, c in enumerate(attr):
if c not in groups[group]:
return False, "Invalid component '{}' in swizzled attribute.".format(c)
if write and c in already_set:
return False, "Component '{}' in swizzled attribute is set more than once.".format(c)
if write:
already_set.append(c)
result += groups[0][groups[group].index(c)]
return True, result
def _color_swizzle(attr: str, size: int, write: bool=False) -> Tuple[bool, str]:
if len(attr) not in (1, 2, 3, 4):
return False, "Wrong number of components to swizzle (must be 1, 2, 3 or 4; not {}).".format(len(attr))
if size not in (3, 4):
return False, "Wrong vector size (must be 3 or 4; not {}).".format(size)
groups = ['rgba']
if size == 3:
groups = ['rgb']
if attr[0] in groups[0]:
group = 0
else:
return False, "Invalid component '{}' in swizzled Color attribute.".format(attr[0])
already_set = []
result = ''
for i, c in enumerate(attr):
if c not in groups[group]:
return False, "Invalid component '{}' in swizzled attribute.".format(c)
if write and c in already_set:
return False, "Component '{}' in swizzled attribute is set more than once.".format(c)
if write:
already_set.append(c)
result += groups[0][groups[group].index(c)]
return True, result
def _flatten(filter_types: List[Type], *values, map_to: Optional[Type]=None) -> list:
result = []
for v in values:
if isinstance(v, filter_types):
result.append(map_to(v) if map_to is not None else v)
else:
result.extend(_flatten(filter_types, *v, map_to=map_to))
return result
_NOARGS = []
PI = 3.14159265358979323846
DEG2RAD = PI / 180.
RAD2DEG = 180. / PI
FLAG_SHOW_LOGO = 1
FLAG_FULLSCREEN_MODE = 2
FLAG_WINDOW_RESIZABLE = 4