@@ -329,16 +329,17 @@ def equalise(self) -> None:
329329 x , y = self ._projection_data .rect .x , self ._projection_data .rect .y
330330 self ._projection_data .rect = XYWH (x , y , self .viewport_width , self .viewport_height )
331331
332- def match_screen (
332+ def match_window (
333333 self ,
334- and_projection : bool = True ,
335- and_scissor : bool = True ,
336- and_position : bool = False ,
334+ viewport : bool = True ,
335+ projection : bool = True ,
336+ scissor : bool = True ,
337+ position : bool = False ,
337338 aspect : float | None = None ,
338339 ) -> None :
339340 """
340- Sets the viewport to the size of the screen .
341- Should be called when the screen is resized.
341+ Sets the viewport to the size of the window .
342+ Should be called when the window is resized.
342343
343344 Args:
344345 and_projection: Flag whether to also equalize the projection to the viewport.
@@ -353,96 +354,102 @@ def match_screen(
353354 compared to the height. i.e. for an aspect ratio of ``4:3`` you should
354355 input ``4.0/3.0`` or ``1.33333...``. Cannot be equal to zero.
355356 """
356- self .update_viewport (
357+ self .update_values (
357358 self ._window .rect ,
358- and_projection = and_projection ,
359- and_scissor = and_scissor ,
360- and_position = and_position ,
359+ viewport = viewport ,
360+ projection = projection ,
361+ scissor = scissor ,
362+ position = position ,
361363 aspect = aspect ,
362364 )
363365
364366 def match_target (
365367 self ,
366- and_projection : bool = True ,
367- and_scissor : bool = True ,
368- and_position : bool = False ,
368+ viewport : bool = True ,
369+ projection : bool = True ,
370+ scissor : bool = True ,
371+ position : bool = False ,
369372 aspect : float | None = None ,
370373 ) -> None :
371374 """
372375 Sets the viewport to the size of the Camera2D's render target.
373376
374377 Args:
375- and_projection: Flag whether to also equalize the projection to the viewport.
376- On by default
377- and_scissor: Flag whether to also equalize the scissor box to the viewport.
378- On by default
379- and_position: Flag whether to also center the camera to the viewport.
378+ viewport: Flag whether to equalise the viewport to the area of the render target
379+ projection: Flag whether to equalise the size of the projection to
380+ match the render target
381+ The projection center stays fixed, and the new projection matches only in size.
382+ scissor: Flag whether to update the scissor value.
383+ position: Flag whether to also center the camera to the value.
380384 Off by default
381- aspect_ratio: The ratio between width and height that the viewport should
382- be constrained to. If unset then the viewport just matches the window
383- size. The aspect ratio describes how much larger the width should be
384- compared to the height. i.e. for an aspect ratio of ``4:3`` you should
385+ aspect_ratio: The ratio between width and height that the value should
386+ be constrained to. i.e. for an aspect ratio of ``4:3`` you should
385387 input ``4.0/3.0`` or ``1.33333...``. Cannot be equal to zero.
388+ If unset then the value will not be updated.
386389 Raises:
387390 ValueError: Will be raised if the Camera2D was has no render target.
388391 """
389392 if self .render_target is None :
390393 raise ValueError (
391- "Tried to match a non-exsistant render target. Please use `match_screen ` instead"
394+ "Tried to match a non-exsistant render target. Please use `match_window ` instead"
392395 )
393396
394- self .update_viewport (
397+ self .update_values (
395398 LRBT (* self .render_target .viewport ),
396- and_projection = and_projection ,
397- and_scissor = and_scissor ,
398- and_position = and_position ,
399+ viewport ,
400+ projection ,
401+ scissor ,
402+ position ,
399403 aspect = aspect ,
400404 )
401405
402- def update_viewport (
406+ def update_values (
403407 self ,
404- new_viewport : Rect ,
405- and_projection : bool = True ,
406- and_scissor : bool = True ,
407- and_position : bool = False ,
408+ value : Rect ,
409+ viewport : bool = True ,
410+ projection : bool = True ,
411+ scissor : bool = True ,
412+ position : bool = False ,
408413 aspect : float | None = None ,
409414 ):
410415 """
411- Convienence method for updating the viewport of the camera. To simply change
412- the viewport you can safely set the projection property .
416+ Convienence method for updating the viewport, projection, position
417+ and a few others with the same value .
413418
414419 Args:
415- and_projection: Flag whether to also equalize the projection to the viewport.
416- On by default
417- and_scissor: Flag whether to also equalize the scissor box to the viewport.
418- On by default
419- and_position: Flag whether to also center the camera to the viewport.
420+ value: The rect that the values will be derived from.
421+ viewport: Flag whether to equalise the viewport to the value.
422+ projection: Flag whether to equalise the size of the projection to match the value.
423+ The projection center stays fixed, and the new projection matches only in size.
424+ scissor: Flag whether to update the scissor value.
425+ position: Flag whether to also center the camera to the value.
420426 Off by default
421- aspect_ratio: The ratio between width and height that the viewport should
422- be constrained to. If unset then the viewport just matches the window
423- size. The aspect ratio describes how much larger the width should be
424- compared to the height. i.e. for an aspect ratio of ``4:3`` you should
427+ aspect_ratio: The ratio between width and height that the value should
428+ be constrained to. i.e. for an aspect ratio of ``4:3`` you should
425429 input ``4.0/3.0`` or ``1.33333...``. Cannot be equal to zero.
430+ If unset then the value will not be updated.
426431 """
427432 if aspect is not None :
428- if new_viewport .height * aspect < new_viewport .width :
429- w = new_viewport .height * aspect
430- h = new_viewport .height
433+ if value .height * aspect < value .width :
434+ w = value .height * aspect
435+ h = value .height
431436 else :
432- w = new_viewport .width
433- h = new_viewport .width / aspect
434- self .viewport = XYWH (new_viewport .x , new_viewport .y , w , h )
435- else :
436- self .viewport = new_viewport
437+ w = value .width
438+ h = value .width / aspect
439+ value = XYWH (value .x , value .y , w , h )
440+
441+ if viewport :
442+ self .viewport = value
437443
438- if and_projection :
439- self .equalise ()
444+ if projection :
445+ x , y = self ._projection_data .rect .x , self ._projection_data .rect .y
446+ self ._projection_data .rect = XYWH (x , y , value .width , value .height )
440447
441- if and_scissor and self .scissor :
442- self .scissor = self . viewport
448+ if scissor and self .scissor :
449+ self .scissor = value
443450
444- if and_position :
445- self .position = self . viewport .center
451+ if position :
452+ self .position = value .center
446453
447454 def aabb (self ) -> Rect :
448455 """
@@ -898,7 +905,6 @@ def top_left(self, new_corner: Point2):
898905 # top_center
899906 @property
900907 def top_center (self ) -> Vec2 :
901- # TODO correct
902908 """Get the top most position the camera can see"""
903909 pos = self .position
904910
@@ -908,7 +914,6 @@ def top_center(self) -> Vec2:
908914
909915 @top_center .setter
910916 def top_center (self , new_top : Point2 ):
911- # TODO correct
912917 ux , uy , * _ = self ._camera_data .up
913918 top = self .top
914919
0 commit comments