|
17 | 17 |
|
18 | 18 | import arcade
|
19 | 19 | from arcade import get_display_size
|
20 |
| -from arcade import set_viewport |
21 | 20 | from arcade import set_window
|
22 | 21 | from arcade.color import TRANSPARENT_BLACK
|
23 | 22 | from arcade.context import ArcadeContext
|
24 | 23 | from arcade.types import Color, RGBOrA255, RGBANormalized
|
25 | 24 | from arcade import SectionManager
|
26 | 25 | from arcade.utils import is_raspberry_pi
|
| 26 | +from arcade.camera import Projector |
| 27 | +from arcade.camera.default import DefaultProjector |
27 | 28 |
|
28 | 29 | LOG = logging.getLogger(__name__)
|
29 | 30 |
|
@@ -211,17 +212,17 @@ def __init__(
|
211 | 212 | # self.invalid = False
|
212 | 213 | set_window(self)
|
213 | 214 |
|
| 215 | + self._ctx: ArcadeContext = ArcadeContext(self, gc_mode=gc_mode, gl_api=gl_api) |
| 216 | + self._background_color: Color = TRANSPARENT_BLACK |
| 217 | + |
214 | 218 | self._current_view: Optional[View] = None
|
215 |
| - self.current_camera: Optional[arcade.SimpleCamera] = None |
| 219 | + self._default_camera = DefaultProjector(window=self) |
| 220 | + self.current_camera: Projector = self._default_camera |
216 | 221 | self.textbox_time = 0.0
|
217 | 222 | self.key: Optional[int] = None
|
218 | 223 | self.flip_count: int = 0
|
219 | 224 | self.static_display: bool = False
|
220 | 225 |
|
221 |
| - self._ctx: ArcadeContext = ArcadeContext(self, gc_mode=gc_mode, gl_api=gl_api) |
222 |
| - set_viewport(0, self.width, 0, self.height) |
223 |
| - self._background_color: Color = TRANSPARENT_BLACK |
224 |
| - |
225 | 226 | # See if we should center the window
|
226 | 227 | if center_window:
|
227 | 228 | self.center_window()
|
@@ -606,13 +607,8 @@ def on_resize(self, width: int, height: int):
|
606 | 607 | # The arcade context is not created at that time
|
607 | 608 | if hasattr(self, "_ctx"):
|
608 | 609 | # Retain projection scrolling if applied
|
609 |
| - original_viewport = self._ctx.projection_2d |
610 |
| - self.set_viewport( |
611 |
| - original_viewport[0], |
612 |
| - original_viewport[0] + width, |
613 |
| - original_viewport[2], |
614 |
| - original_viewport[2] + height |
615 |
| - ) |
| 610 | + self._ctx.viewport = (0, 0, width, height) |
| 611 | + self.default_camera.use() |
616 | 612 |
|
617 | 613 | def set_min_size(self, width: int, height: int):
|
618 | 614 | """ Wrap the Pyglet window call to set minimum size
|
@@ -676,30 +672,19 @@ def set_visible(self, visible: bool = True):
|
676 | 672 | """
|
677 | 673 | super().set_visible(visible)
|
678 | 674 |
|
679 |
| - # noinspection PyMethodMayBeStatic |
680 |
| - def set_viewport(self, left: float, right: float, bottom: float, top: float): |
681 |
| - """ |
682 |
| - Set the viewport. (What coordinates we can see. |
683 |
| - Used to scale and/or scroll the screen). |
684 |
| -
|
685 |
| - See :py:func:`arcade.set_viewport` for more detailed information. |
686 |
| -
|
687 |
| - :param left: |
688 |
| - :param right: |
689 |
| - :param bottom: |
690 |
| - :param top: |
691 |
| - """ |
692 |
| - set_viewport(left, right, bottom, top) |
693 |
| - |
694 |
| - # noinspection PyMethodMayBeStatic |
695 |
| - def get_viewport(self) -> Tuple[float, float, float, float]: |
696 |
| - """ Get the viewport. (What coordinates we can see.) """ |
697 |
| - return self.ctx.projection_2d |
698 |
| - |
699 | 675 | def use(self):
|
700 | 676 | """Bind the window's framebuffer for rendering commands"""
|
701 | 677 | self.ctx.screen.use()
|
702 | 678 |
|
| 679 | + @property |
| 680 | + def default_camera(self): |
| 681 | + """ |
| 682 | + Provides a reference to the default arcade camera. |
| 683 | + Automatically sets projection and view to the size |
| 684 | + of the screen. Good for resetting the screen. |
| 685 | + """ |
| 686 | + return self._default_camera |
| 687 | + |
703 | 688 | def test(self, frames: int = 10):
|
704 | 689 | """
|
705 | 690 | Used by unit test cases. Runs the event loop a few times and stops.
|
|
0 commit comments