def __init__( self, label: str, bounds: RectangleShape, on_click = do_nothing, stroke_width: int = 2, font_name: str = "Source Code Pro", font_size: int = 12, text_colour = (255, 255, 255, 255), background_colour = (255, 0, 0, 255), background_colour_2 = (255, 0, 0, 255), outline_colour = (0, 255, 255, 255), batch = None, group = None ): self._label = label self._bounds = bounds self._on_click = on_click self._stroke_width = stroke_width self._font_name = font_name self._font_size = font_size self._text_colour = text_colour self._background_colour = background_colour self._background_colour_2 = background_colour_2 self._outline_colour = outline_colour if batch is None: self._batch = Batch() self._batch_is_own = True else: self._batch = batch self._batch_is_own = False self._group_back = OrderedGroup(0, group) self._group_front = OrderedGroup(1, group) self._text_and_bg = None self._outline = None self._update()
def __init__(self, text='', font_name=None, font_size=None, bold=False, italic=False, colour=(255, 255, 255, 255), background_colour=(0, 0, 0, 128), background_padding=Vector(6, 6), background_bounds=None, pos=Vector(0, 0), size=Vector(None, None), anchor_x='left', anchor_y='baseline', align='left', multiline=False, dpi=None, batch=None, group=None): self._group_bg = OrderedGroup(0, group) self._group_text = OrderedGroup(1, group) super().__init__(text, font_name, font_size, bold, italic, colour, pos.x, pos.y, size.x, size.y, anchor_x, anchor_y, align, multiline, dpi, batch, self._group_text) self._pos = pos self._background_color = background_colour self._background_padding = background_padding self._background_bounds = background_bounds self.bg_draw = None self._update_bg()
def init_box(self): w = self.width h = self.height pos = self.x, self.y bgvx = fix_origin(( pos[0], pos[1], pos[0], pos[1] + h, pos[0] + w, pos[1] + h, pos[0] + w, pos[1] ), self.window_height) bgvx2 = ( bgvx[0] + 2, bgvx[1] - 2, bgvx[2] + 2, bgvx[3] + 2, bgvx[4] - 2, bgvx[5] + 2, bgvx[6] - 2, bgvx[7] - 2 ) self.box_vx.append(self.batch.add(4, GL_QUADS, OrderedGroup(self.groupNumber), ('v2i', bgvx), ('c3B', (0, 0, 0) * 4) )) self.box_vx.append(self.batch.add(4, GL_QUADS, OrderedGroup(self.groupNumber), ('v2i', bgvx2), ('c3B', (255, 255, 255) * 4) ))
def __init__(self, x, y, base, knob, edge=0, batch=None, group=None): super().__init__(x, y, base.width, knob.height) self._edge = edge self._base_img = base self._knob_img = knob self._half_knob_width = knob.width / 2 self._half_knob_height = knob.height / 2 self._knob_img.anchor_y = knob.height / 2 self._min_knob_x = x + edge self._max_knob_x = x + base.width - knob.width - edge self._user_group = group bg_group = OrderedGroup(0, parent=group) fg_group = OrderedGroup(1, parent=group) self._base_spr = pyglet.sprite.Sprite(self._base_img, x, y, batch=batch, group=bg_group) self._knob_spr = pyglet.sprite.Sprite(self._knob_img, x + edge, y + base.height / 2, batch=batch, group=fg_group) self._value = 0 self._in_update = False
def __init__(self, window): super().__init__(window) self.batch = Batch() self.group0 = OrderedGroup(0) self.group1 = OrderedGroup(1) self.group2 = OrderedGroup(2) self.group_labels = OrderedGroup(5)
def __init__( self, card: Card, pos: Vector, transparent: bool = False, targeted: bool = False, hidden: bool = False, batch = None, group = None ): super().__init__(centre = pos, size = CardDrawer.CARD_SIZE) self.card = card self.anchor = pos self._transparent = transparent self._targeted = targeted self._hidden = hidden self._batch = batch self.group_back = OrderedGroup(0, group) self.group_front = OrderedGroup(1, group) self.image = img.load(IMG_DIR.joinpath('card.jpg')) self.image.anchor_x = self.image.width // 2 self.image.anchor_y = self.image.height // 2 self.rect = None self.outline = None self.sym_labels_top = [] self.sym_labels_bottom = [] self.num_label = None self.back = None self._update()
def __init__(self, assets: Assets, window: Window, audio_manager: AudioManager): Scene.__init__(self, assets, window, audio_manager) self.logger = logging.getLogger(__name__) self.batch = Batch() self.background = OrderedGroup(0) self.foreground = OrderedGroup(1) # Logo image and sprite self.logo_image = None self.logo_sprite = None # Version and info labels self.version_label = Label(f"Version: { divineoasis.__version__ }", x=10, y=30, group=self.foreground, batch=self.batch, font_size=16, font_name="Hydrophilia Iced") self.author_label = Label(f"by { divineoasis.__author__ }", x=10, y=10, group=self.foreground, batch=self.batch, font_size=16, font_name="Hydrophilia Iced")
def title_screen(): mp.queue(Resources.audio['title_bgm']) my_logo = OrderedGroup(0) my_button = OrderedGroup(1) # Instantiation section # logo = MyRectangle(name = "logo", curr_state = 'TITLE', img = Resources.sprites['logo'], x = Resources.window_width*0.5, y = Resources.window_height*0.5, batch = title_batch, group = my_logo) logo.opacity = 255 play_button = Button(name = 'start_button', curr_state = 'TITLE', target_state = 'SETUP', world = manager, img = Resources.sprites['play_button'], x = Resources.window_width*0.5+50, y = Resources.window_height*0.5-110, batch = title_batch, group = my_button) # End of Instantiation # # Handler specification # game_window.push_handlers(play_button) # End of specification # # Importation section # manager.add_widget(play_button) manager.add_widget(logo)
def __init__(self, x, y, name=None): self.db_obj = None self.x = x self.y = y self.width = config.window_width self.height = config.window_height self.n_rows = config.window_height // config.block_height self.n_cols = config.window_width // config.block_width self.players = [] self.npcs = [] self.walls = [] self.objects = [] self.sprite = None self.name = name if name else \ f'{self.__class__.__name__}({self.x}, {self.y})' self.grid = [] self.blocks = [] self.draw_batch = Batch() self.background = OrderedGroup(0) self.midground = OrderedGroup(1) self.foreground = OrderedGroup(2)
def __init__(self, x, y, text, batch): self.text = text self.batch = batch self.bgGroup = OrderedGroup(GUI_FG_RENDER_ORDER + 1) self.fgGroup = OrderedGroup(self.bgGroup.order + 1) self.x = x self.y = y
def __init__(self, assets: Assets, window: Window, audio_manager: AudioManager): Scene.__init__(self, assets, window, audio_manager) self.logger = logging.getLogger(__name__) self.batch = Batch() self.background = OrderedGroup(0) self.foreground = OrderedGroup(1)
def do_regroup_children(self): from pyglet.graphics import OrderedGroup # Don't make unnecessary layers, see `Stack.do_regroup_children()`. if self._foreground is None: self._background._regroup(self.group) else: self._foreground._regroup(OrderedGroup(2, self.group)) self._background._regroup(OrderedGroup(1, self.group))
class AdventureBase(FrameWork): adventure = RootProxy() # Draw screen = Batch() overlay = Batch() bg = OrderedGroup(0) mg = OrderedGroup(1) fg = OrderedGroup(2)
class Map(object): LAYERS = { 'soil': OrderedGroup(0), 'ground': OrderedGroup(1), 'bodies': OrderedGroup(2), 'trees': OrderedGroup(3), 'berries': OrderedGroup(4) } def __init__(self, width, height): self.width = width self.height = height self._map = Batch() self._create() self._add_hero() self._add_lost() def _create(self): for x in range(0, self.width, Soil.size()[0]): for y in range(0, self.height, Soil.size()[1]): soil = Soil(x, y) self.add(soil) try: soil.grow(self, x, y) except NotFertileError as e: logger.debug(str(e)) def add(self, thing): thing.vertex_list = self._map.add( len(thing.vertices) // 2, GL_QUADS, self.LAYERS[thing.LAYER], ('v2i/dynamic', thing.vertices), ('c4B/static', thing.colors) ) return thing.vertex_list def _add_body(self, body_name, kind): body = getattr(things, body_name)(*START_POS[kind]) setattr(self, kind, body) self.add(body) return body @info("Adding {}".format(BODY_HERO)) def _add_hero(self): self._add_body(BODY_HERO, 'hero') @info("Hiding {}".format(BODY_LOST)) def _add_lost(self): self._add_body(BODY_LOST, 'lost') # keep a list of every tree to hide him def draw(self): self._map.draw()
def __init__(self, file_path, parent_window, on_close): super().__init__(parent_window, on_close, caption='tabulr | Confirm background image', width=640, height=640) # Layer groups bg = OrderedGroup(0) fg = OrderedGroup(1) # Compute image sprite size, preserving aspect ratio bg_image = load(file_path) bg_image.anchor_x = bg_image.width // 2 bg_image.anchor_y = bg_image.height // 2 if bg_image.height > bg_image.width: scale = 640 / bg_image.height else: scale = 640 / bg_image.width # Background gradient gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.bg_gradient = self.batch.add( 4, gl.GL_QUADS, fg, ('v2i', (0, 0, 640, 0, 640, 80, 0, 80)), ('c4B', (0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0))) # Draw bg image self.bg_sprite = Sprite(bg_image, batch=self.batch, group=bg, x=320, y=320) self.bg_sprite.scale = scale # Confirmation text self.confirm_text = Text('Is this the image you want to use?', group=fg, size=12, x=self.margin, y=self.margin, bold=True, batch=self.batch) # Confirmation buttons self.buttons = [ Button('yes', self, self.batch, x=590, y=30, group=fg), Button('no', self, self.batch, x=550, y=30, group=fg) ]
def render(self) -> None: """ Render the board onto the screen. """ # Clear the old board. self.clear() # Draw the board in a single batch. batch = Batch() obstacle_layer, connection_layer, boid_layer = (OrderedGroup(order) for order in range(3)) if self._show_lines: batch = self.draw_connections(batch, connection_layer, "neighbors", color=GREEN) batch = self.draw_connections(batch, connection_layer, "obstacles", color=RED) batch = self.draw_models(batch, boid_layer, self.system.population, color=WHITE) batch = self.draw_models(batch, obstacle_layer, self.system.obstacles, color=RED) batch.draw() # Send to screen. self.flip()
def __init__(self, position: Vector2, size: Vector2, transparent=False, color=ColorHelper.WHITE): image = pyglet.image.SolidColorImagePattern( color if not transparent else ColorHelper.TRANSPARENT ).create_image(size.x, size.y) super().__init__(image, x=position.x, y=position.y, batch=Renderer.instance.get_batch(), group=Renderer.instance.get_main_group()) self._enabled = True self._current_batch = self.batch self.children: List[UIBase] = [] self.children_batch = Batch() self.children_group = OrderedGroup(self.group.order + 1) self._position = position self._size = size self.custom_data = None # can contain some data to simplify data transfer between scripts self.parent = None self._opacity = 255 self._is_mouse_inside = False Renderer.instance.add_ui_object(self) # event handlers self.on_click_down = None self.on_click_up = None self.on_mouse_enter = None self.on_mouse_leave = None
def set_batch(self, batch, group): sprite_group = NodeGroup(self, group) self.pre_group = NodeGroup(self, OrderedGroup(-1, parent=group)) self.group = OrderedGroup(0, parent=group) self.same_group = NodeGroup(self, self.group) self.post_group = NodeGroup(self, OrderedGroup(1, parent=group)) self.batch = batch for z, child in self.children: if z < 0: group = self.pre_group elif z == 0: group = self.same_group else: group = self.post_group child.set_batch(self.batch, group)
def __init__(self, window_height, textures, batch=None): self.width = self.padding * 2 + self.icon_spacing + 64 super().__init__(20, 20, window_height, batch=batch) self.sprites = [] self.tool_rects = [] self.selected = None self.textures = textures self.tool_indexes = {} # build areas for tools for i, tool in enumerate(self.tools): tex = self.textures[tool] size = (tex.width * 2, tex.height * 2) if i == 0: left = self.padding + self.x top = self.padding + self.y else: prev_rect = self.tool_rects[i - 1] top = prev_rect.top left = prev_rect.right + self.icon_spacing if left + size[0] > self.x + self.width + self.icon_spacing: left = self.padding + self.x top = prev_rect.bottom + self.icon_spacing self.handle_region(tool, self.set_tool, left, top, tex.width * 2, tex.height * 2) np = fix_origin((left, top + tex.height * 2), self.window_height) self.sprites.append( pyglet.sprite.Sprite(self.textures[tool], np[0], np[1], batch=self.batch, group=OrderedGroup(self.groupNumber + 1))) self.tool_indexes[tool] = i self.sprites[-1].scale = 2 r = Rect(left, top, size[0], size[1]) self.tool_rects.append(r)
def __init__(self, *, batch, player): super().__init__() self.batch = batch self.player = player self.enemy_timer = 2 self.enemy_group = OrderedGroup(0) self.pellet_group = OrderedGroup(1) # Keep track of how many enemies of each type we've spawned # so we can keep it under its cap self.spawned_enemies = {enemy.type: 0 for enemy in enemy_data} # Spawn the first pellet # Additional pellets are spawned in the pellet collision callback self.spawn_pellet()
def __init__(self, data, map): self.data = data self.map = map if self.data["visible"]: self.sprites = {} self.group = OrderedGroup(BaseLayer.groups) BaseLayer.groups += 1
def _get_group(self, zindex): """ zindex: drawing order within batch """ # zindex must be an integer assert type(zindex) is int # create group if it does not exist if zindex not in self._draw_groups: self._draw_groups[zindex] = OrderedGroup(zindex) return self._draw_groups[zindex]
def __init__(self, text, x, y, width, color=(255, 255, 255, 255), batch=None, group=None): self._doc = pyglet.text.document.UnformattedDocument(text) self._doc.set_style(0, len(self._doc.text), dict(color=(0, 0, 0, 255))) font = self._doc.get_font() height = font.ascent - font.descent self._user_group = group bg_group = OrderedGroup(0, parent=group) fg_group = OrderedGroup(1, parent=group) # Rectangular outline: pad = 2 x1 = x - pad y1 = y - pad x2 = x + width + pad y2 = y + height + pad self._outline = batch.add(4, pyglet.gl.GL_QUADS, bg_group, ('v2i', [x1, y1, x2, y1, x2, y2, x1, y2]), ('c4B', color * 4)) # Text and Caret: self._layout = IncrementalTextLayout(self._doc, width, height, multiline=False, batch=batch, group=fg_group) self._caret = Caret(self._layout) self._caret.visible = False self._layout.x = x self._layout.y = y self._focus = False super().__init__(x, y, width, height)
def __init__(self, text, pos, batch): self.text = text x, y = self.pos = pos group = OrderedGroup(1) self.label = Label(text, font_name=FONT_NAME, font_size=28, color=COLOUR, x=x + 20, y=y + 15, group=group, batch=batch) w = self.label.content_width + 40 self.bg = ScrollBG(x, x + w, y, batch=batch, group=OrderedGroup(0)) self.left = Sprite(scroll_left, x=x, y=y, group=group, batch=batch) self.right = Sprite(scroll_right, x=x + w, y=y, group=group, batch=batch)
def __init__(self, text, x, y, width, color=(255, 255, 255, 255), batch=None, group=None): self._doc = pyglet.text.document.UnformattedDocument(text) self._doc.set_style(0, len(self._doc.text), dict(color=(0, 0, 0, 255))) font = self._doc.get_font() height = font.ascent - font.descent self._user_group = group bg_group = OrderedGroup(0, parent=group) fg_group = OrderedGroup(1, parent=group) # Rectangular outline with 2-pixel pad: p = 2 self._outline = pyglet.shapes.Rectangle(x - p, y - p, width + p + p, height + p + p, color[:3], batch, bg_group) self._outline.opacity = color[3] # Text and Caret: self._layout = IncrementalTextLayout(self._doc, width, height, multiline=False, batch=batch, group=fg_group) self._layout.x = x self._layout.y = y self._caret = Caret(self._layout) self._caret.visible = False self._focus = False super().__init__(x, y, width, height)
def init_box(self): w = self.width h = self.height x = self.x y = self.y lw = self.line_width sets = self.vx_pos() for s in sets: self.box_vx.append( self.batch.add(4, GL_QUADS, OrderedGroup(self.groupNumber), ('v2i', fix_origin(s, self.window_height)), ('c3B', (0, 0, 0) * 4)))
def __init__(self, image_path: str, position: Vector2, size: Vector2, row: int, col: int, frame_number: int, sprite_size: Vector2, sheet_row: int, sheet_col: int, scale: float, frame_time: float = 0.1): super().__init__(position, size, transparent=True) image = pyglet.image.load('Static/Images/' + image_path) sprite_grid = pyglet.image.ImageGrid(image, sheet_row, sheet_col, item_width=sprite_size.x, item_height=sprite_size.y) row_image_sprite_number = image.width // sprite_size.x col_image_sprite_number = image.height // sprite_size.y sprite_texture = pyglet.image.TextureGrid(sprite_grid) start_sprite = (row * row_image_sprite_number) + col sprite_animation = pyglet.image.Animation.from_image_sequence( sprite_texture[start_sprite: start_sprite + frame_number], frame_time, loop=True) self.sprite = pyglet.sprite.Sprite(sprite_animation, x=position.x, y=position.y, batch=self.batch, group=OrderedGroup(self.group.order + 1)) self.sprite.update(scale=scale)
def __init__(self, caption: str, position: Vector2 = Vector2.zero, size: Vector2 = Vector2.one, document_style=None, font_name: str = 'DisposableDroid BB', font_size: int = 20, color: (int, int, int, int) = ColorHelper.WHITE, hover_color: (int, int, int, int) = ColorHelper.TRANSPARENT): super().__init__(position, size) document_style = {} if document_style is None else document_style document_style.update(dict(font_name=font_name, font_size=font_size)) self._caption = caption self._document = FormattedDocument(caption) self.update_document_style(document_style) self._text_layout = TextLayout(self._document, width=size.x, height=size.y, batch=self.batch, group=OrderedGroup(self.group.order + 1.1), wrap_lines=True, multiline=True) self._text_layout.content_valign = 'center' self.position = position self.color = color self._set_background_color(hover_color) self._set_background_color(self._background_color)
def __init__(self, x, y, window_height, textures, engine, batch=None): super().__init__(x, y, window_height, batch=batch) self.textures = textures self.engine = engine self.rect = Rect(self.x, self.y, self.width, self.height) self.speed_sprites = {} sid = self.speed_icon_dims _sp_pos = (self.x + self.width - sid[0] - 6, self.window_height - (self.y + self.padding + 4 + sid[1])) for speed in self.speeds: self.speed_sprites[speed] = Sprite( self.textures[speed], _sp_pos[0], _sp_pos[1], group=OrderedGroup(self.groupNumber + 1)) self.speed_sprites[speed].scale = 2 self.speed_icon_rect = Rect(_sp_pos[0] + self.x, _sp_pos[1] + self.y, 32, 32) self.set_speed('slow')
def init_box(self): w = self.width h = self.height pos = self.x, self.y group = OrderedGroup(self.groupNumber) bgvx = fix_origin((pos[0], pos[1], pos[0], pos[1] + h, pos[0] + w, pos[1] + h, pos[0] + w, pos[1]), self.window_height) bgvx2 = (bgvx[0] + 2, bgvx[1] - 2, bgvx[2] + 2, bgvx[3] + 2, bgvx[4] - 2, bgvx[5] + 2, bgvx[6] - 2, bgvx[7] - 2) self.box_vx.append( self.batch.add(4, GL_QUADS, group, ('v2i', bgvx), ('c3B', (0, 0, 0) * 4))) self.box_vx.append( self.batch.add(4, GL_QUADS, group, ('v2i', bgvx2), ('c3B', (255, 255, 255) * 4))) bar_start = self.bar_start bar_height = self.bar_height bar_spacing = self.bar_spacing + bar_height bar_start_left = self.bar_start_left bars = [(pos[0] + bar_start_left, pos[1] + bar_start, pos[0] + bar_start_left, pos[1] + bar_start + bar_height, pos[0] + bar_start_left + 1, pos[1] + bar_start + bar_height, pos[0] + bar_start_left + 1, pos[1] + bar_start)] bars.append( (bars[0][0], bars[0][1] + bar_spacing, bars[0][2], bars[0][3] + bar_spacing, bars[0][4], bars[0][5] + bar_spacing, bars[0][6], bars[0][7] + bar_spacing)) bars.append( (bars[1][0], bars[1][1] + bar_spacing, bars[1][2], bars[1][3] + bar_spacing, bars[1][4], bars[1][5] + bar_spacing, bars[1][6], bars[1][7] + bar_spacing)) for bar in bars: self.box_vx.append( self.batch.add(4, GL_QUADS, group, ('v2i', fix_origin(bar, self.window_height)), ('c3B', (0, 0, 0) * 4)))
def __init__(self, order, parent=None): OrderedGroup.__init__(self, order, parent)