def get_orientation(self): if isinstance(self._hvbox, HBox): return Vector(1, 0) elif isinstance(self._hvbox, VBox): return Vector(0, -1) else: raise NotImplementedError
def from_actor(cls, actor, board): if actor.id == 2: origin = Vector(0, 0) heading = Vector(1, 1) color = 'white' elif actor.id == 3: origin = Vector(board.width - 1, board.height - 1) heading = Vector(-1, -1) color = 'black' else: # There should only be two players, and their ids should be 2 and # 3. (The referee has id 1). raise ValueError(f"{actor!r} has unexpected id={actor.id}") return cls(origin, heading, color)
def assign_card(self, card): self.card = card # set the position of the card_image x, y = self.rect.center ext = card.get_extension(self.gui_actor) ext.activate(Vector(x, y)) self.draw()
def __init__(self): self.bg_color = (0.75, 0.75, 0.75, 1.0) self.window_shape = Vector(400, 400) self.window = pyglet.window.Window() self.window.set_size(*self.window_shape) self.window.set_visible(True) self.window.set_caption("Cherts") #self.window.set_icon( # pyglet.resource.image('icon_16.png'), # pyglet.resource.image('icon_32.png'), # pyglet.resource.image('icon_64.png'), #) self.batch = pyglet.graphics.Batch() self.load_images()
def _update_vertex_list(self): if self._vertex_list is None: return texture = self._image.get_texture() # Get the actual texture (not just a region of a texture) associated # for this image. This will be used to make sure that try: underlying_texture = texture.owner except AttributeError: underlying_texture = texture # Figure out which texture coordinates are bound to which vertices. # This is not always an intuitive mapping, because textures can be # rotated by changing which texture coordinates are bound to which # vertices. The in-line diagram shows which vertex is represented by # each variable in the case that the image hasn't been rotated. a = Vector(*texture.tex_coords[0:2]) # D┌───┐C b = Vector(*texture.tex_coords[3:5]) # │ │ c = Vector(*texture.tex_coords[6:8]) # │ │ d = Vector(*texture.tex_coords[9:11]) # A└───┘B # Give a really nice error message if the image can't be tiled, because # the restrictions on which images can be tiled don't make sense unless # you really know how OpenGL works. error_template = """\ image can't be tiled {} because it's {} than its underlying texture ({} px vs {} px). The most common way to get this error is to use an image that doesn't have a power-of-two size (e.g. 1, 2, 4, 8, etc.) in each dimension being tiled. OpenGL requires that textures have power-of-two dimensions, so images with non-power-of-two sizes end up in textures with some unused space. This unused space is usually not shown, but tiling requires showing the whole texture in the dimension being tiled, so the unused space would ruin the effect. Another common way to get this error is by loading the image as an `image` rather than a `texture`. Pyglet tries to be smart about packing images into contiguous regions of memory, and sometimes this means putting images in textures that are larger than they need to be. Loading the image as a texture avoids this logic at the expense of less well-organized memory.""" if self._htile: if self._image.width != underlying_texture.width: raise UsageError( error_template.format('horizontally', 'narrower', self._image.width, underlying_texture.width)) w = self._rect.width / self._image.width else: w = a.get_distance(b) if self._vtile: if self._image.height != underlying_texture.height: raise UsageError( error_template.format('vertically', 'shorter', self._image.height, underlying_texture.height)) h = self._rect.height / self._image.height else: h = a.get_distance(d) A = a B = a + (b - a).get_scaled(w) C = a + (c - d).get_scaled(w) + (c - b).get_scaled(h) D = a + (d - a).get_scaled(h) self._vertex_list.tex_coords = A.tuple + B.tuple + C.tuple + D.tuple self._vertex_list.vertices = (self._rect.bottom_left.tuple + self._rect.bottom_right.tuple + self._rect.top_right.tuple + self._rect.top_left.tuple)
def on_mouse_scroll(self, x, y, scroll_x, scroll_y): self._pane.scroll(self.mouse_sensitivity * Vector(scroll_x, scroll_y))
def on_grip_press(self, x, y, button, modifiers): self.reference_point = Vector(x, y)