From 98106ccd0820098c63787de20a4fa522a6431654 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 13 Jul 2023 19:38:36 +0800 Subject: [PATCH] sync pyglet --- libs/pyglet/window/__init__.py | 46 +++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/libs/pyglet/window/__init__.py b/libs/pyglet/window/__init__.py index b10b4a0..a68962b 100644 --- a/libs/pyglet/window/__init__.py +++ b/libs/pyglet/window/__init__.py @@ -681,6 +681,21 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)): """ raise NotImplementedError('abstract') + def draw(self, dt: float): + """Redraw the Window contents. + + This method will first call the :py:meth:`~pyglet.window.Window.`switch_to` + method to make the GL context current. It then dispatches the + :py:meth:`~pyglet.window.Window.on_draw` and + :py:meth:`~pyglet.window.Window.on_refresh` + events. Finally, it calls the :py:meth:`~pyglet.window.Window.flip` + method to swap the front and back OpenGL buffers. + """ + self.switch_to() + self.dispatch_event('on_draw') + self.dispatch_event('on_refresh', dt) + self.flip() + def draw_mouse_cursor(self): """Draw the custom mouse cursor. @@ -1411,15 +1426,13 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)): """ def on_draw(self): - """The window contents must be redrawn. + """The window contents should be redrawn. - The `EventLoop` will dispatch this event when the window - should be redrawn. This will happen during idle time after - any window events and after any scheduled functions were called. - - The window will already have the GL context, so there is no - need to call `switch_to`. The window's `flip` method will - be called after this event, so your event handler should not. + The `EventLoop` will dispatch this event when the `draw` + method has been called. The window will already have the + GL context, so there is no need to call `switch_to`. The window's + `flip` method will be called immediately after this event, + so your event handler should not. You should make no assumptions about the window contents when this event is triggered; a resize or expose event may have @@ -1601,11 +1614,11 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)): """ def on_mouse_leave(self, x, y): - """The mouse was moved outside of the window. + """The mouse was moved outside the window. This event will not be triggered if the mouse is currently being dragged. Note that the coordinates of the mouse pointer will be - outside of the window rectangle. + outside the window rectangle. :Parameters: `x` : int @@ -1632,14 +1645,13 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)): """ def on_refresh(self, dt): - """The window contents must be redrawn. + """The window contents should be redrawn. - The `EventLoop` will dispatch this event when the window - should be redrawn. - - The window will already have the GL context, so there is no - need to call `switch_to`. The window's `flip` method will - be called after this event, so your event handler should not. + The `EventLoop` will dispatch this event when the `draw` + method has been called. The window will already have the + GL context, so there is no need to call `switch_to`. The window's + `flip` method will be called immediately after this event, so your + event handler should not. You should make no assumptions about the window contents when this event is triggered; a resize or expose event may have