Exemple #1
0
def test_window(twm):
    import arcade
    width = 800
    height = 600
    title = "My Title"
    resizable = True
    arcade.open_window(width, height, title, resizable)

    arcade.set_background_color(arcade.color.AMAZON)
    w = arcade.get_window()
    assert w is not None

    # Make sure the arguments get passed to the window
    if not twm:
        assert w.width == width
        assert w.height == height
    assert w.caption == title
    assert w.resizeable is resizable
    assert w.current_view is None

    arcade.set_window(w)

    w.background_color = 255, 255, 255, 255
    assert w.background_color == (255, 255, 255, 255)
    w.set_mouse_visible(True)
    w.set_size(width, height)

    p = arcade.get_projection()
    assert isinstance(p, np.ndarray)

    v = arcade.get_viewport()
    if not twm:
        assert v[0] == 0
        # The lines below fail. Why?
        assert v[1] == width - 1
        assert v[2] == 0
        assert v[3] == height - 1

    factor = arcade.get_scaling_factor()
    assert factor > 0
    factor = arcade.get_scaling_factor(w)
    assert factor > 0

    arcade.start_render()
    arcade.finish_render()

    def f():
        pass

    arcade.schedule(f, 1 / 60)

    arcade.pause(0.01)

    arcade.close_window()

    arcade.open_window(width, height, title, resizable)
    arcade.quick_run(0.01)
 def on_resize(self, width, height):
     """Set up viewport and projection"""
     ratio = arcade.get_scaling_factor(self)
     self.ctx.viewport = 0, 0, int(width * ratio), int(height * ratio)
     aspect_ratio = width / height
     self.program['projection'] = Matrix44.perspective_projection(
         60, aspect_ratio, 0.1, 100).flatten()
Exemple #3
0
    def use(self):
        """Make the camera active"""
        # Calculate aspect ratio from projection
        ar = self.aspect_ratio

        # Apply scrolling
        proj = (
            self._projection[0] + self._scroll_x,
            self._projection[1] + self._scroll_x,
            self._projection[2] + self._scroll_y,
            self._projection[3] + self._scroll_y,
        )

        # Ensure aspect ratio is maintained
        vp = self._adjust_viewport_to_aspect_ratio(ar, self._viewport)

        # Apply pixel ratio scaling
        scale = arcade.get_scaling_factor(self._window)
        vp_scaled = tuple(int(v * scale) for v in vp)

        self._window.ctx.viewport = vp_scaled
        self._window.ctx.projection_2d = proj
Exemple #4
0
 def resize(self, width: int, height: int):
     """Resize the the internal texture"""
     pixel_scale = get_scaling_factor(self.window)
     self._size = width * pixel_scale, height * pixel_scale
     self._fbo = self.ctx.framebuffer(
         color_attachments=self.ctx.texture((width, height), components=4))