sync pyglet

This commit is contained in:
shenjack 2023-07-28 14:29:50 +08:00
parent 3df29bee64
commit 6887660ee1
Signed by: shenjack
GPG Key ID: 7B1134A979775551
9 changed files with 37 additions and 53 deletions

View File

@ -333,10 +333,10 @@ class _ModuleProxy:
# Lazily load all modules, except if performing
# type checking or code inspection.
if TYPE_CHECKING:
from . import types
from . import app
from . import canvas
from . import clock
from . import customtypes
from . import event
from . import font
from . import gl
@ -354,10 +354,10 @@ if TYPE_CHECKING:
from . import text
from . import window
else:
types = _ModuleProxy('types')
app = _ModuleProxy('app')
canvas = _ModuleProxy('canvas')
clock = _ModuleProxy('clock')
customtypes = _ModuleProxy('customtypes')
event = _ModuleProxy('event')
font = _ModuleProxy('font')
gl = _ModuleProxy('gl')

View File

@ -1,7 +1,9 @@
"""Holds type aliases used throughout the codebase."""
import ctypes
from typing import Union
__all__ = [
"Buffer"
]

View File

@ -68,10 +68,10 @@ class Frame:
widget.on_mouse_drag(x, y, dx, dy, buttons, modifiers)
self._mouse_pos = x, y
def on_mouse_scroll(self, x, y, index, direction):
def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
"""Pass the event to any widgets within range of the mouse"""
for widget in self._cells.get(self._hash(x, y), set()):
widget.on_mouse_scroll(x, y, index, direction)
widget.on_mouse_scroll(x, y, scroll_x, scroll_y)
def on_mouse_motion(self, x, y, dx, dy):
"""Pass the event to any widgets within range of the mouse"""

View File

@ -122,7 +122,7 @@ class WidgetBase(EventDispatcher):
def on_mouse_motion(self, x, y, dx, dy):
pass
def on_mouse_scroll(self, x, y, mouse, direction):
def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
pass
def on_text(self, text):
@ -348,11 +348,11 @@ class Slider(WidgetBase):
if self._in_update:
self._update_knob(x)
def on_mouse_scroll(self, x, y, mouse, direction):
def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
if not self.enabled:
return
if self._check_hit(x, y):
self._update_knob(self._knob_spr.x + self._half_knob_width + direction)
self._update_knob(self._knob_spr.x + self._half_knob_width + scroll_y)
def on_mouse_release(self, x, y, buttons, modifiers):
if not self.enabled:

View File

@ -1427,6 +1427,12 @@ class Texture(AbstractImage):
order = self.tex_coords_order
self.tex_coords_order = (order[bl], order[br], order[tr], order[tl])
@property
def uv(self):
"""Tuple containing the left, bottom, right, top 2D texture coordinates."""
tex_coords = self.tex_coords
return tex_coords[0], tex_coords[1], tex_coords[3], tex_coords[7]
def __repr__(self):
return "{}(id={}, size={}x{})".format(self.__class__.__name__, self.id, self.width, self.height)

View File

@ -145,7 +145,7 @@ class Allocator:
class TextureAtlas:
"""Collection of images within a texture."""
def __init__(self, width: int=2048, height: int=2048) -> None:
def __init__(self, width: int = 2048, height: int = 2048) -> None:
"""Create a texture atlas of the given size.
:Parameters:
@ -252,7 +252,7 @@ class TextureArrayBin:
ones as necessary as the depth is exceeded.
"""
def __init__(self, texture_width: int=2048, texture_height: int=2048, max_depth: Optional[int]=None) -> None:
def __init__(self, texture_width: int = 2048, texture_height: int = 2048, max_depth: Optional[int] = None) -> None:
max_texture_size = pyglet.image.get_max_texture_size()
self.max_depth = max_depth or pyglet.image.get_max_array_texture_layers()
self.texture_width = min(texture_width, max_texture_size)

View File

@ -9,9 +9,9 @@ for creating orthographic and perspective projection matrixes.
Matrices behave just like they do in GLSL: they are specified in column-major
order and multiply on the left of vectors, which are treated as columns.
:note: For performance, Matrixes subclass the `tuple` type. They
are therefore immutable - all operations return a new object;
the object is not updated in-place.
.. note:: For performance reasons, Matrix types subclass `tuple`. They are
therefore immutable. All operations return a new object; the object
is not updated in-place.
"""
from __future__ import annotations
@ -719,29 +719,23 @@ class Mat3(tuple):
class Mat4(tuple):
"""A 4x4 Matrix class
`Mat4` is an immutable 4x4 Matrix, including most common
operators. Matrix multiplication must be performed using
the "@" operator.
Class methods are available for creating orthogonal
and perspective projections matrixes.
"""
def __new__(cls, values: _Iterable[float] = (1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,)) -> Mat4:
"""Create a 4x4 Matrix
"""Create a 4x4 Matrix.
`Mat4` is an immutable 4x4 Matrix, which includs most common
operators. This includes class methods for creating orthogonal
and perspective projection matrixes, to be used by OpenGL.
A Matrix can be created with a list or tuple of 16 values.
If no values are provided, an "identity matrix" will be created
(1.0 on the main diagonal). Matrix objects are immutable, so
all operations return a new Mat4 object.
:Parameters:
`values` : tuple of float or int
A tuple or list containing 16 floats or ints.
.. note:: Matrix multiplication is performed using the "@" operator.
"""
new = super().__new__(Mat4, values)
@ -749,19 +743,12 @@ class Mat4(tuple):
return new
@classmethod
def orthogonal_projection(
cls: type[Mat4T],
left: float,
right: float,
bottom: float,
top: float,
z_near: float,
z_far: float
) -> Mat4T:
def orthogonal_projection(cls: type[Mat4T], left: float, right: float, bottom: float, top: float, z_near: float, z_far: float) -> Mat4T:
"""Create a Mat4 orthographic projection matrix for use with OpenGL.
This matrix doesn't actually perform the projection; it transforms the
space so that OpenGL's vertex processing performs it.
Given left, right, bottom, top values, and near/far z planes,
create a 4x4 Projection Matrix. This is useful for setting
:py:attr:`~pyglet.window.Window.projection`.
"""
width = right - left
height = top - bottom
@ -781,24 +768,12 @@ class Mat4(tuple):
tx, ty, tz, 1.0))
@classmethod
def perspective_projection(
cls: type[Mat4T],
aspect: float,
z_near: float,
z_far: float,
fov: float = 60
) -> Mat4T:
"""
Create a Mat4 perspective projection matrix for use with OpenGL.
def perspective_projection(cls: type[Mat4T], aspect: float, z_near: float, z_far: float, fov: float = 60) -> Mat4T:
"""Create a Mat4 perspective projection matrix for use with OpenGL.
This matrix doesn't actually perform the projection; it transforms the
space so that OpenGL's vertex processing performs it.
:Parameters:
`aspect` : The aspect ratio as a `float`
`z_near` : The near plane as a `float`
`z_far` : The far plane as a `float`
`fov` : Field of view in degrees as a `float`
Given a desired aspect ratio, near/far planes, and fov (field of view),
create a 4x4 Projection Matrix. This is useful for setting
:py:attr:`~pyglet.window.Window.projection`.
"""
xy_max = z_near * _math.tan(fov * _math.pi / 360)
y_min = -xy_max

View File

@ -139,6 +139,7 @@ def parse_obj_file(filename, file=None):
elif values[0] == 'o':
mesh = Mesh(name=values[1])
mesh.material = default_material
mesh_list.append(mesh)
elif values[0] == 'f':

View File

@ -1792,7 +1792,7 @@ class Polygon(ShapeBase):
:Parameters:
`coordinates` : List[[int, int]]
The coordinates for each point in the polygon.
`color` : (int, int, int)
`color` : (int, int, int, int)
The RGB or RGBA color of the polygon, specified as a
tuple of 3 or 4 ints in the range of 0-255. RGB colors
will be treated as having an opacity of 255.