Merge branch 'electronstudio:master' into Conventions

This commit is contained in:
Dor Shapira 2022-09-23 23:37:35 +03:00 committed by GitHub
commit c63f203578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 164 additions and 25 deletions

View file

@ -3010,3 +3010,30 @@ rlShaderUniformDataType: int
rlTextureFilter: int
rlTraceLogLevel: int
rlVertexBuffer: struct
LIGHTGRAY =( 200, 200, 200, 255 )
GRAY =( 130, 130, 130, 255 )
DARKGRAY =( 80, 80, 80, 255 )
YELLOW =( 253, 249, 0, 255 )
GOLD =( 255, 203, 0, 255 )
ORANGE =( 255, 161, 0, 255 )
PINK =( 255, 109, 194, 255 )
RED =( 230, 41, 55, 255 )
MAROON =( 190, 33, 55, 255 )
GREEN =( 0, 228, 48, 255 )
LIME =( 0, 158, 47, 255 )
DARKGREEN =( 0, 117, 44, 255 )
SKYBLUE =( 102, 191, 255, 255 )
BLUE =( 0, 121, 241, 255 )
DARKBLUE =( 0, 82, 172, 255 )
PURPLE =( 200, 122, 255, 255 )
VIOLET =( 135, 60, 190, 255 )
DARKPURPLE =( 112, 31, 126, 255 )
BEIGE =( 211, 176, 131, 255 )
BROWN =( 127, 106, 79, 255 )
DARKBROWN =( 76, 63, 47, 255 )
WHITE =( 255, 255, 255, 255 )
BLACK =( 0, 0, 0, 255 )
BLANK =( 0, 0, 0, 0 )
MAGENTA =( 255, 0, 255, 255 )
RAYWHITE =( 245, 245, 245, 255 )

View file

@ -5,9 +5,7 @@ screenHeight = 450
InitWindow(screenWidth, screenHeight, b"raylib [textures] example - image loading")
image = LoadImage(b"resources/raylib_logo.jpg")
image = LoadImage(b"resources/raylib_logo.png")
texture = LoadTextureFromImage(image)
UnloadImage(image)
@ -24,8 +22,6 @@ while not WindowShouldClose():
EndDrawing()
UnloadTexture(texture)
UnloadTexture(texture)
CloseWindow()

View file

@ -13,7 +13,9 @@ python3 create_enums.py > dynamic/raylib/enums.py
pip3 install sphinx-autoapi myst_parser sphinx_rtd_theme
python3 create_stub_pyray.py > pyray/__init__.pyi
python3 create_enums.py >> pyray/__init__.pyi
cat raylib/colors.py >> pyray/__init__.pyi
python3 create_stub_static.py >raylib/__init__.pyi
cat raylib/colors.py >> raylib/__init__.pyi
rm -r docs
cd docs-src
make clean ; make html ; mv _build/html/ ../docs/

View file

@ -14,25 +14,22 @@
from raylib import rl, ffi
from raylib.colors import *
try:
from raylib.defines import *
except AttributeError:
print("sorry deprecated enums dont work on dynamic version")
from inspect import ismethod,getmembers,isbuiltin
from inspect import getmembers, isbuiltin
import inflection
current_module = __import__(__name__)
def pointer(self, struct):
return ffi.addressof(struct)
# I'm concerned that we are doing a lot of string comparisons on every function call to detect types.
# Quickest way would probably be isinstance(result, ffi._backend._CDataBase) but that class name varies
# depending on if binding is static/dynamic
@ -42,11 +39,11 @@ def pointer(self, struct):
# Another way to improve performance might be to special-case simple types before doing the string comparisons
def makefunc(a):
#print("makefunc ",a, ffi.typeof(a).args)
# print("makefunc ",a, ffi.typeof(a).args)
def func(*args):
modified_args = []
for (c_arg, arg) in zip(ffi.typeof(a).args, args):
#print("arg:",str(arg), "c_arg.kind:", c_arg.kind, "c_arg:", c_arg, "type(arg):",str(type(arg)))
# print("arg:",str(arg), "c_arg.kind:", c_arg.kind, "c_arg:", c_arg, "type(arg):",str(type(arg)))
if c_arg.kind == 'pointer':
if type(arg) == str:
arg = arg.encode('utf-8')
@ -56,9 +53,9 @@ def makefunc(a):
arg = ffi.new("int *", arg)
elif type(arg) is float:
arg = ffi.new("float *", arg)
elif str(type(arg)) == "<class '_cffi_backend.__CDataOwn'>" and "*" not in str(arg): #CPython
elif str(type(arg)) == "<class '_cffi_backend.__CDataOwn'>" and "*" not in str(arg): # CPython
arg = ffi.addressof(arg)
elif str(type(arg)) == "<class '_cffi_backend._CDataBase'>" and "*" not in str(arg): #Pypy
elif str(type(arg)) == "<class '_cffi_backend._CDataBase'>" and "*" not in str(arg): # Pypy
arg = ffi.addressof(arg)
elif arg is None:
arg = ffi.NULL
@ -72,28 +69,32 @@ def makefunc(a):
else:
result = ffi.string(result).decode('utf-8')
return result
return func
def makeStructHelper(struct):
def func(*args):
return ffi.new(f"struct {struct} *", args)[0]
return func
for name, attr in getmembers(rl):
#print(name, attr)
uname = inflection.underscore(name).replace('3_d','_3d').replace('2_d','_2d')
if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>" or str(type(attr)) == "<class '_cffi_backend._CDataBase'>":
#print(attr.__call__)
#print(attr.__doc__)
#print(attr.__text_signature__)
#print(dir(attr))
#print(dir(attr.__repr__))
# print(name, attr)
uname = inflection.underscore(name).replace('3_d', '_3d').replace('2_d', '_2d')
if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>" or str(
type(attr)) == "<class '_cffi_backend._CDataBase'>":
# print(attr.__call__)
# print(attr.__doc__)
# print(attr.__text_signature__)
# print(dir(attr))
# print(dir(attr.__repr__))
f = makefunc(attr)
setattr(current_module, uname, f)
#def wrap(*args):
# def wrap(*args):
# print("call to ",attr)
#setattr(PyRay, uname, lambda *args: print("call to ",attr))
# setattr(PyRay, uname, lambda *args: print("call to ",attr))
else:
setattr(current_module, name, attr)

View file

@ -4226,3 +4226,44 @@ class GuiIconName(IntEnum):
ICON_254 = 254
ICON_255 = 255
# Copyright (c) 2021 Richard Smith and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# This Source Code may also be made available under the following Secondary
# licenses when the conditions for such availability set forth in the Eclipse
# Public License, v. 2.0 are satisfied: GNU General Public License, version 2
# with the GNU Classpath Exception which is
# available at https://www.gnu.org/software/classpath/license.html.
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
LIGHTGRAY =( 200, 200, 200, 255 )
GRAY =( 130, 130, 130, 255 )
DARKGRAY =( 80, 80, 80, 255 )
YELLOW =( 253, 249, 0, 255 )
GOLD =( 255, 203, 0, 255 )
ORANGE =( 255, 161, 0, 255 )
PINK =( 255, 109, 194, 255 )
RED =( 230, 41, 55, 255 )
MAROON =( 190, 33, 55, 255 )
GREEN =( 0, 228, 48, 255 )
LIME =( 0, 158, 47, 255 )
DARKGREEN =( 0, 117, 44, 255 )
SKYBLUE =( 102, 191, 255, 255 )
BLUE =( 0, 121, 241, 255 )
DARKBLUE =( 0, 82, 172, 255 )
PURPLE =( 200, 122, 255, 255 )
VIOLET =( 135, 60, 190, 255 )
DARKPURPLE =( 112, 31, 126, 255 )
BEIGE =( 211, 176, 131, 255 )
BROWN =( 127, 106, 79, 255 )
DARKBROWN =( 76, 63, 47, 255 )
WHITE =( 255, 255, 255, 255 )
BLACK =( 0, 0, 0, 255 )
BLANK =( 0, 0, 0, 0 )
MAGENTA =( 255, 0, 255, 255 )
RAYWHITE =( 245, 245, 245, 255 )

View file

@ -3964,3 +3964,44 @@ rlShaderUniformDataType: int
rlTextureFilter: int
rlTraceLogLevel: int
rlVertexBuffer: struct
# Copyright (c) 2021 Richard Smith and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# This Source Code may also be made available under the following Secondary
# licenses when the conditions for such availability set forth in the Eclipse
# Public License, v. 2.0 are satisfied: GNU General Public License, version 2
# with the GNU Classpath Exception which is
# available at https://www.gnu.org/software/classpath/license.html.
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
LIGHTGRAY =( 200, 200, 200, 255 )
GRAY =( 130, 130, 130, 255 )
DARKGRAY =( 80, 80, 80, 255 )
YELLOW =( 253, 249, 0, 255 )
GOLD =( 255, 203, 0, 255 )
ORANGE =( 255, 161, 0, 255 )
PINK =( 255, 109, 194, 255 )
RED =( 230, 41, 55, 255 )
MAROON =( 190, 33, 55, 255 )
GREEN =( 0, 228, 48, 255 )
LIME =( 0, 158, 47, 255 )
DARKGREEN =( 0, 117, 44, 255 )
SKYBLUE =( 102, 191, 255, 255 )
BLUE =( 0, 121, 241, 255 )
DARKBLUE =( 0, 82, 172, 255 )
PURPLE =( 200, 122, 255, 255 )
VIOLET =( 135, 60, 190, 255 )
DARKPURPLE =( 112, 31, 126, 255 )
BEIGE =( 211, 176, 131, 255 )
BROWN =( 127, 106, 79, 255 )
DARKBROWN =( 76, 63, 47, 255 )
WHITE =( 255, 255, 255, 255 )
BLACK =( 0, 0, 0, 255 )
BLANK =( 0, 0, 0, 0 )
MAGENTA =( 255, 0, 255, 255 )
RAYWHITE =( 245, 245, 245, 255 )

View file

@ -0,0 +1,31 @@
from raylib import *
screenWidth = 800
screenHeight = 450
InitWindow(screenWidth, screenHeight, b"raylib [textures] example - image loading")
image = LoadImage(b"examples/textures/resources/raylib_logo.jpg")
texture = LoadTextureFromImage(image)
UnloadImage(image)
while not WindowShouldClose():
BeginDrawing()
ClearBackground(RAYWHITE)
DrawTexture(texture, int(screenWidth/2 - texture.width/2), int(screenHeight/2 - texture.height/2), WHITE)
DrawText(b"this IS a texture loaded from an image!", 300, 370, 10, GRAY)
EndDrawing()
UnloadTexture(texture)
CloseWindow()