55from typing import TYPE_CHECKING
66
77from pyglet .math import Mat4 , Vec2 , Vec3
8+ from pyglet .window .key import F
89from typing_extensions import Self
910
1011from arcade .types import LBWH , Point , Rect
@@ -40,6 +41,7 @@ def __init__(self, *, context: ArcadeContext | None = None):
4041 self ._viewport : Rect | None = None
4142 self ._scissor : Rect | None = None
4243 self ._matrix : Mat4 | None = None
44+ self ._updating : bool = False
4345
4446 def update_viewport (self ):
4547 """
@@ -49,13 +51,17 @@ def update_viewport(self):
4951 setting the viewport to match the size of the active
5052 framebuffer sets the viewport to None.
5153 """
52- if self ._ctx .current_camera != self :
54+ if self ._ctx .current_camera != self or self . _updating :
5355 return
56+ self ._updating = True
57+
5458 if self ._ctx .viewport [2 ] != self .width or self ._ctx .viewport [3 ] != self .height :
55- self ._viewport = LBWH (* self ._ctx .viewport )
56- self ._viewport = None
59+ self .viewport = LBWH (* self ._ctx .viewport )
60+ else :
61+ self .viewport = None
5762
5863 self .use ()
64+ self ._updating = False
5965
6066 @property
6167 def viewport (self ) -> Rect | None :
@@ -98,24 +104,26 @@ def height(self) -> int:
98104 return int (self ._viewport .height )
99105 return self ._ctx .active_framebuffer .height
100106
107+ def get_current_viewport (self ) -> tuple [int , int , int , int ]:
108+ if self ._viewport is not None :
109+ return self ._viewport .lbwh_int
110+ return (0 , 0 , self ._ctx .active_framebuffer .width , self ._ctx .active_framebuffer .width )
111+
101112 def use (self ) -> None :
102113 """
103114 Set the window's Projection and View matrices.
104115 """
105116
106- viewport = (0 , 0 , self .width , self .height )
107- # If the viewport is correct and the default camera is in use,
108- # then don't waste time resetting the view and projection matrices
109- if self ._ctx .viewport == viewport and self ._ctx .current_camera == self :
110- return
117+ viewport = self .get_current_viewport ()
111118
112119 self ._ctx .current_camera = self
113120 self ._ctx .viewport = viewport
121+ self ._ctx .scissor = None if self ._scissor is None else self ._scissor .lbwh_int
114122
115123 self ._ctx .view_matrix = Mat4 ()
116124 if self ._matrix is None :
117125 self ._matrix = Mat4 .orthogonal_projection (
118- 0 , 0 , viewport [2 ], viewport [3 ], DEFAULT_NEAR_ORTHO , DEFAULT_FAR
126+ 0 , viewport [2 ], 0 , viewport [3 ], DEFAULT_NEAR_ORTHO , DEFAULT_FAR
119127 )
120128 self ._ctx .projection_matrix = self ._matrix
121129
0 commit comments