Beispiel #1
0
    def draw_sprite_objs(self):
        sprite_batch = Batch()
        self.rendered_sprite = []
        ship = self.model.player
        if ship.is_active:
            colour = self.player_glow_colour
            if self.model.player.is_blown:
                colour = [255, 0, 0]

            elif self.model.q_jam or self.model.e_jam:
                colour = [255, 0, 255]
            self.draw_illumination(self.to_screen_x(ship.x + ship.width // 2),
                                   self.to_screen_y(ship.y), 150 + self.player_glow_intensity,
                                   colour)
            player_batch = Batch()
            player_sprite = self.get_rendered_sprite(ship, player_batch)
            self.rendered_sprite.append(player_sprite)
            self.draw_flame(self.to_screen_x(ship.x), self.to_screen_y(ship.y), self.to_screen_x(ship.width))
            player_batch.draw()
        objs = []
        objs.extend(self.model.objects)
        if hasattr(self.model, 'boxes'):
            objs.extend(self.model.boxes)
        for obj in objs:
            if obj.is_active:
                sprite = self.get_rendered_sprite(obj, sprite_batch)
                self.rendered_sprite.append(sprite)

        sprite_batch.draw()
Beispiel #2
0
class Game:
  bin = TextureBin()
  bin_loaded = {}

  batch = Batch()
  hud_batch = Batch()

  TILE_HEIGHT = 32
  TILE_WIDTH = 32

  CHEST_XP = 5
  KILL_XP = 5

  def __init__(self):
    self.entity_count = 0
    self.cull_sprites = []
    self.dungeon_offset = self.TILE_WIDTH * 512
    self.window = pyglet.window.Window()
    self.camera = Camera(self)
    self.keys = key.KeyStateHandler()
    self.window.push_handlers(self.keys)
    self.world = World(self)
    self.cursor = self.window.CURSOR_DEFAULT
    self.set_cursor = None

  def aabb_intersects(self, hitbox1, hitbox2):
    xa1, ya1, xb1, yb1 = hitbox1
    xa2, ya2, xb2, yb2 = hitbox2

    xt = xa1 < xb2 and xb1 > xa2
    yt = ya1 < yb2 and yb1 > ya2

    return xt and yt
Beispiel #3
0
class AdventureBase(FrameWork):

    adventure = RootProxy()

    # Draw
    screen = Batch()
    overlay = Batch()
    bg = OrderedGroup(0)
    mg = OrderedGroup(1)
    fg = OrderedGroup(2)
Beispiel #4
0
    def __init__(self, sjuan_stack: SjuanCardStack, pos: Vector):
        self._sjuan_stack = sjuan_stack
        self._pos = pos
        self.visible = True

        self._batch_sevens = Batch()
        self._upper_batch = Batch()
        self._lower_batch = Batch()
        self._dotted_draws = {}
        self._seven_draws = {}
        self._upper_draws = {}
        self._lower_draws = {}
        self._create_dotted_draws()
Beispiel #5
0
    def __init__(self, width, height, title=''):
        super().__init__(width, height, title, resizable=True)
        self.width = width
        self.height = height
        glClearColor(0, 0, 0, 1)
        glEnable(GL_DEPTH_TEST)

        self.batch = Batch()
        self.batch2 = Batch()
        self.vlist = None
        self.set_vlist()
        self.testvlist = self.batch2.add(
            3, GL_TRIANGLES, None,
            ('v3f', (50, 0, 100, 100, 0, 100, 50, 75, 100)),
            ('c3B', (255, 255, 255, 255, 255, 255, 255, 255, 255)))
Beispiel #6
0
 def draw_lasers(self):
     batch = Batch()
     inner_colors = (0, 200, 255, 0, 200, 255)
     radius = 3 * SpaceWindow.BULLET_RADIUS_PERCENT * self.width
     for bullet in self.model.bullets:
         # self.draw_illumination(self.to_screen_x(bullet[0]), self.to_screen_y(bullet[1]), radius, inner_colors[:3])
         batch.add(2, GL_LINES, None,
                   ('v2f', [self.to_screen_x(bullet[0]),
                            self.to_screen_y(bullet[1]),
                            self.to_screen_x(bullet[0]),
                            self.to_screen_y(bullet[1] + int(self.BULLET_HEIGHT_PERCENT * self.main_height))]),
                   ('c3B', inner_colors))
     radius = SpaceWindow.BULLET_RADIUS_PERCENT * self.width
     purple = [255, 0, 255]
     for x, y in self.model.alien_bullets:
         self.draw_illumination(self.to_screen_x(x), self.to_screen_y(y), 6 * radius, purple)
         circ_pts = [self.to_screen_x(x), self.to_screen_y(y) + radius]
         for theta in np.linspace(0, 2 * math.pi, 8):
             error = random.randint(-1 * radius // 4, radius // 4)
             circ_pts.extend([circ_pts[0] + (radius + error) * math.sin(theta),
                              circ_pts[1] + (radius + error) * math.cos(theta)])
         num_of_vert = (len(circ_pts) // 2)
         colors = [255, 255, 255]
         colors.extend((num_of_vert - 1) * purple)
         graphics.draw(num_of_vert, GL_TRIANGLE_FAN,
                       ('v2f', circ_pts),
                       ('c3B', colors))
     batch.draw()
Beispiel #7
0
    def __init__(self, initial_level):
        super(World, self).__init__()
        self.space = pymunk.Space()
        self.space.gravity = (0.0, -900.0)
        self.space.damping = 0.9
        self.space.iterations = 20

        self.splash = load_sound('data/sounds/splash.wav')

        self.images = {}
        self.sprites = []
        self.actors = []
        self.batch = Batch()

        self.load_sprite('sprites/susie-destroy')
        components.load_all()
        self.squid = components.Susie(self)

        self.width = None
        self.goal = None

        self.load(initial_level)
        self.particles = ParticleSystem()
        self.crashed = False
        self.won = False
        self.splash_group = None
Beispiel #8
0
 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)
Beispiel #9
0
    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
Beispiel #10
0
 def __init__(self, model: ComponentContainerModel, batch: Batch = None):
     super().__init__(model)
     self._model = model
     self._batch = batch or Batch()
     self._vertex_lists = set()
     self._vertex_list_by_drawable: Dict[Drawable,
                                         vertexdomain.VertexList] = dict()
Beispiel #11
0
 def get_batch(self):
     self.batch = Batch()
     flatverts = self.get_flat_verts()
     numverts = len(flatverts) / 2
     self.batch.add(numverts, self.primtype, None,
                    ('v2f/static', flatverts),
                    ('c4B/static', self.color * numverts))
Beispiel #12
0
 def __init__(self):
     win_width, win_height = get_size()
     self.batch = Batch()
     self._doc = pyglet.text.document.UnformattedDocument('')
     self._doc.set_style(0, len(self._doc.text),
                         dict(color=(255, 255, 255, 255)))
     font = self._doc.get_font()
     self.text_height = font.ascent - font.descent
     self.pad = 2
     self._outline = Rectangle(5,
                               5 + self.pad,
                               get_size()[0] - self.pad - 10,
                               self.text_height + self.pad,
                               color=(0, 0, 0))
     self._outline.opacity = 150
     self._layout = IncrementalTextLayout(self._doc,
                                          get_size()[0] - 14,
                                          self.text_height,
                                          multiline=False,
                                          batch=self.batch)
     self._caret = Caret(self._layout, color=(255, 255, 255))
     self._caret.visible = False
     self._layout.x = 5
     self._layout.y = 5 + self.pad
     self._focus = False
     self._press = False
     self.last_press = [0, 0]
     super().__init__(5, 5 + self.pad,
                      get_size()[0] - self.pad - 10,
                      self.text_height + self.pad)
Beispiel #13
0
    def __init__(self):
        self.event_loop = pyglet.app.EventLoop()
        self.clock = pyglet.clock.Clock()
        self.event_loop.clock = self.clock
        self.window = Window(600, 600, caption="Snake", vsync=False)
        self.main_batch = Batch()

        self.head = Sprite(snake_head, 290, 290, batch=self.main_batch)
        self.snake = [
            Sprite(snake_body, 270, 290, batch=self.main_batch),
            Sprite(snake_cor1, 250, 290, batch=self.main_batch),
            Sprite(snake_body, 250, 270, batch=self.main_batch),
        ]
        self.tail = Sprite(snake_tail, 250, 250, batch=self.main_batch)
        self.head.rotation = 90
        self.snake[0].rotation = 90
        self.snake[1].rotation = 90
        self.apple = Sprite(apple_img, 0, 0, batch=self.main_batch)
        self.gen_apple()  # ensures the apple doesn't overlap with the snake
        self.label = Label("Score: 0", x=10, y=580, batch=self.main_batch)
        self.window.event(self.on_draw)

        self.score = 0
        self.steps = 0
        self.turns = 0
        self.direction = 0
        self.exit_code = 0
        self.current_direction = 0
        self._fps = 0
        self._external = None
        self.fps = 3  # this also schedules the update method
        self.external = None  # this also adds the keyboard listeners
Beispiel #14
0
    def __init__(self,
                 window,
                 bus,
                 title='Welcome to tabulr',
                 draw_waves=False):
        """
        Initialize the Scene object.
        :param window: Pyglet window object. Must be same throughout application.
        :param bus: Event bus. Used for communicating scene changes to main application thread.
        """
        self.window = window
        self.window_title = title
        self.bus = bus
        self.batch = Batch()
        self.margin = 36
        self.sprites = {}
        self.inputs = []

        # Error message
        self.error_msg = Text('',
                              size=12,
                              bold=True,
                              batch=self.batch,
                              x=self.margin,
                              color=(236, 64, 122, 255))
        self.error_elapsed = 0
        self.error_opacity = 0

        # Waves background
        if draw_waves:
            waves_img = image('side-waves.png')
            waves_img.anchor_x = waves_img.width
            waves = Sprite(waves_img, x=window.width, y=0, batch=self.batch)
            waves.opacity = 160
            self.init_sprite('waves', waves, is_button=False)
Beispiel #15
0
    def __init__(self,
                 game: ExpandoGame,
                 cell_size=50,
                 padding=10,
                 ui_font_size=12):
        """
        :param game: The game to render
        :param cell_size: the length of each square in pixels
        :param padding: the padding between cells in pixels
        :param ui_font_size: size of the font, used to show player statistics.
        """
        self.player_colors = [(84, 22, 180), (255, 106, 0), (204, 255, 0),
                              (244, 147, 242)]
        self.padding = padding
        self.cell_size = cell_size
        self.square_size = self.cell_size - self.padding
        self.game = game
        self.board = self.game.board
        self.font_height = ui_font_size * 0.75

        assert len(self.board.grid_size
                   ) == 2, 'only 2d grids can be rendered at the moment'

        h, w = self.game.grid_size
        window_height = h * cell_size + padding
        # extra room for displaying scores
        self.window_height = window_height + 2 * self.font_height * (
            game.n_players + 1) + self.padding
        self.window_width = w * cell_size + padding

        super().__init__(width=self.window_width,
                         height=int(self.window_height))
        self.batch = Batch()
Beispiel #16
0
    def __init__(self,
                 cards: List[Card],
                 pos: Vector,
                 rotation: int = 0,
                 label: str = None,
                 row_size: int = 10,
                 hidden: bool = False,
                 batch=None,
                 group=None):
        self._pos = pos
        self._anchor = pos
        self.rotation = rotation
        self._cards = deepcopy(cards)
        self._label = label
        self._row_size = row_size
        self._offset = 0

        if batch is None:
            self._batch = Batch()
            self._batch_is_own = True
        else:
            self._batch = batch
            self._batch_is_own = False
        self._group = group
        self._hidden = hidden

        self._drawn_offset = 0
        self._card_draws = []
        self._top_labels = []
        self._etc_left = None
        self._etc_right = None
        self._n_displayed = None
        self._bounds_inner = None
        self._update()
Beispiel #17
0
    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")
Beispiel #18
0
class Game:
    bin = TextureBin()
    bin_loaded = {}

    batch = Batch()

    CELL_HEIGHT = 32
    CELL_WIDTH = 64
    CELL_Z = 13

    def __init__(self):
        self.window = pyglet.window.Window()
        self.cull_sprites = []
        self.camera = Camera(self)
        self.world = World(self)
        self.keys_pressed = []

    def register_cull(self, sprite):
        self.cull_sprites.append(sprite)

    def to_screen(self, w, h, z=0):
        x = (w - h) * self.CELL_WIDTH // 2
        y = (w + h) * self.CELL_HEIGHT // 2 + z
        return x, y

    def to_coords(self, x, y, height=0):
        x -= self.CELL_WIDTH // 2
        y -= self.CELL_Z * (height + 1)
        w = y / self.CELL_HEIGHT + x / self.CELL_WIDTH
        h = y / self.CELL_HEIGHT - x / self.CELL_WIDTH
        return math.floor(w), math.floor(h)
Beispiel #19
0
    def __init__(
            self,
            vertices,
            batch,
            group,
            close=False,
            width=1.0,
            color=(0, 0, 0),
            vertex_usage="dynamic",
    ):
        self._draw_mode = gl.GL_LINE_LOOP if close else gl.GL_LINE_STRIP

        self._width = width
        self._rgb = color

        self._batch = batch or Batch()
        self._group = group

        self._vertex_list = self._batch.add(
            len(vertices),
            self._draw_mode,
            self._group,
            f"v2f/{vertex_usage}",
            "c3B/static",
        )
Beispiel #20
0
    def __init__(self, x, y, width, height, color=(255, 255, 255), batch=None, group=None):
        """Create a rectangle or square.

        The rectangles's anchor point defaults to the (x, y) coordinates,
        which are at the bottom left.

        :Parameters:
            `x` : float
                The X coordinate of the rectangle.
            `y` : float
                The Y coordinate of the rectangle.
            `width` : float
                The width of the rectangle.
            `height` : float
                The height of the rectangle.
            `color` : (int, int, int)
                The RGB color of the rectangle, specified as
                a tuple of three ints in the range of 0-255.
            `batch` : `~pyglet.graphics.Batch`
                Optional batch to add the rectangle to.
            `group` : `~pyglet.graphics.Group`
                Optional parent group of the rectangle.
        """
        self._x = x
        self._y = y
        self._width = width
        self._height = height
        self._rotation = 0
        self._rgb = color

        self._batch = batch or Batch()
        self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, group)
        self._vertex_list = self._batch.add(6, GL_TRIANGLES, self._group, 'position2f', 'colors4Bn')
        self._update_position()
        self._update_color()
Beispiel #21
0
    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)
Beispiel #22
0
    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()
Beispiel #23
0
 def __init__(self, text, color, x, y, width):
     win_width, win_height = get_size()
     self.batch = Batch()
     self._doc = pyglet.text.document.UnformattedDocument(text)
     self._doc.set_style(
         0, len(self._doc.text),
         dict(color=(255, 255, 255, 255), font_name='minecraftia'))
     font = self._doc.get_font()
     height = font.ascent - font.descent
     pad = 2
     self._outline = Rectangle(x - pad,
                               y - pad,
                               width + pad,
                               height + pad,
                               color=color[:3])
     self._outline.opacity = color[-1]
     self._layout = IncrementalTextLayout(self._doc,
                                          width,
                                          height,
                                          multiline=False,
                                          batch=self.batch)
     self._caret = Caret(self._layout, color=(255, 255, 255))
     self._caret.visible = False
     self._layout.x = x
     self._layout.y = y
     self._focus = False
     self._press = False
     super().__init__(x, y, width, height)
     self.last_char = ''
Beispiel #24
0
    def __init__(self, world):
        super(MainMenuScene, self).__init__(world)
        self.text_batch = Batch()
        self.cursor = Label(">",
                            font_name='Times New Roman',
                            font_size=36,
                            x=200 + self.camera.offset_x,
                            y=300 + self.camera.offset_y,
                            batch=self.text_batch)
        self.cursor_pos = 0
        self.moogle = self._load_moogle()

        self.menu_items = {
            "Start Game": self._new_game,
            "About": self._launch_about,
            "Quit Program": self.window.close
        }
        self._generate_text()

        self.key_handlers = {
            (key.ESCAPE, 0): self.window.close,
            (key.UP, 0): lambda: self._move_cursor(1),
            (key.DOWN, 0): lambda: self._move_cursor(-1),
            (key.ENTER, 0): self._menu_action
        }
Beispiel #25
0
    def __init__(self, width, height, background=[255, 255, 255]):
        self.width = width
        self.height = height
        self.triangles = []
        self.batch = Batch()
        self.bg_colour = background
        has_fbo = gl.gl_info.have_extension('GL_EXT_framebuffer_object')

        #setup a framebuffer
        self.fb = gl.GLuint()
        gl.glGenFramebuffersEXT(1, ctypes.byref(self.fb))
        gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, self.fb)

        #allocate a texture for the fb to render to
        tex = image.Texture.create_for_size(gl.GL_TEXTURE_2D, width, height,
                                            gl.GL_RGBA)
        gl.glBindTexture(gl.GL_TEXTURE_2D, tex.id)
        gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT,
                                     gl.GL_COLOR_ATTACHMENT0_EXT,
                                     gl.GL_TEXTURE_2D, tex.id, 0)

        status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
        assert status == gl.GL_FRAMEBUFFER_COMPLETE_EXT

        gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0)

        self.bg = self.batch.add(
            6, gl.GL_TRIANGLES, None,
            ("v2i/static",
             (0, 0, 0, height, width, height, width, height, width, 0, 0, 0)),
            ("c3B/static", background * 6))
Beispiel #26
0
 def setup(self):
     buttonType = self.buttonType
     if buttonType == PUSHTEXT_BUTTON:
         self.label = self.create_label(self.font, self.strings[0],
                                        self.fontColor, self.width,
                                        self.height)
         self.label.content_valign = 'center'
         self.label.set_style('align', 'center')
     elif buttonType in (CHECKBOX_BUTTON, RADIO_BUTTON):
         buttonSize = self.height / self.buttonCount
         labels = self.labels = []
         batch = self.batch = Batch()
         if self.flags['TextOnLeft']:
             x = X_MARGIN
         else:
             x = BOX_OFFSET + X_MARGIN
         for i in xrange(self.buttonCount):
             y = -buttonSize * i
             label = self.create_label(self.font,
                                       self.strings[i],
                                       self.fontColor,
                                       self.width - BOX_OFFSET,
                                       buttonSize,
                                       batch=batch)
             label.x = x
             label.y = y
             label.content_valign = 'center'
             label.set_style('align', 'left')
             labels.append(label)
     self.update_lists(NORMAL_RECT, NORMAL_FILL)
Beispiel #27
0
    def __init__(self, window):
        super().__init__(window)
        self.batch = Batch()
        self.menu = 0
        self.main_index = 0
        self.practice_index = 0
        self.config_index = 0
        self.t = 0

        self.background = Sprite(IMAGES['ui']['mainmenu_bg'], -15, -15)
        self.background.opacity = 100
        self.background2 = Sprite(IMAGES['ui']['mainmenu_bg2'], 0, 0, blend_src=774)
        self.left_sprite = Sprite(IMAGES['ui']['mainmenu_left'], 0, 0, batch=self.batch)
        self.left_sprite.opacity = 50

        # Main menu options:
        options_text = ['Start game', 'Practice', 'High scores', 'Config', 'Exit']
        self.main_options_shadow = [Label(text=options_text[i], font_name=MENU_FONT, color=(100, 100, 100, 100), font_size=22, x=199, y=401 - 32*i, batch=self.batch) for i in range(len(options_text))]
        self.main_options = [Label(text=options_text[i], font_name=MENU_FONT, font_size=22, x=200, y=400 - 32*i, batch=self.batch) for i in range(len(options_text))]

        # Practice options:
        options_text = ['Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5']
        self.practice_options_shadow = [Label(text=options_text[i], font_name=MENU_FONT, color=(100, 100, 100, 0), font_size=22, x=499, y=401 - 32*i, batch=self.batch) for i in range(len(options_text))]
        self.practice_options = [Label(text=options_text[i], font_name=MENU_FONT, font_size=22, x=500, y=400 - 32*i, color=(255,255,255,0), batch=self.batch) for i in range(len(options_text))]

        # Config options:
        options_text = ['SFX volume', 'BGM volume', 'Controls']
        self.config_options_shadow = [Label(text=options_text[i], font_name=MENU_FONT, color=(100, 100, 100, 0), font_size=22, x=499, y=401 - 32*i, batch=self.batch) for i in range(len(options_text))]
        self.config_options = [Label(text=options_text[i], font_name=MENU_FONT, font_size=22, x=500, y=400 - 32*i, color=(255,255,255,0), batch=self.batch) for i in range(len(options_text))]
Beispiel #28
0
 def __init__(self, text, color, x, y, width, pad=3):
     win_width, win_height = get_size()
     self.batch = Batch()
     self._doc = pyglet.text.document.UnformattedDocument(text)
     self._doc.set_style(0, len(self._doc.text),
                         dict(color=(255, 255, 255, 255)))
     font = self._doc.get_font()
     self.text_height = font.ascent - font.descent
     self.pad = pad
     self._outline = BorderedRectangle(x - self.pad,
                                       win_height - y - self.pad,
                                       width + self.pad,
                                       self.text_height + self.pad,
                                       color=color[:3],
                                       border_color=(100, 100, 100))
     self._outline.opacity = color[-1]
     self._layout = IncrementalTextLayout(width,
                                          self.text_height,
                                          multiline=False,
                                          batch=self.batch)
     self._caret = Caret(self._layout, color=(255, 255, 255))
     self._caret.visible = False
     self._layout.x = x
     self._layout.y = win_height - y
     self._focus = False
     self._press = False
     super().__init__(x, win_height - y, width, height)
Beispiel #29
0
 def draw(self, current_view):
     batch_to_draw = Batch()
     for c in self.graphic_components:
         if c.current_view == current_view:
             options = c.get_draw_options()
             batch_to_draw.add(*options)
     batch_to_draw.draw()
Beispiel #30
0
    def __init__(self,
                 x,
                 y,
                 radius,
                 segments=25,
                 angle=math.pi * 2,
                 color=(255, 255, 255),
                 batch=None,
                 group=None):
        # TODO: Finish this shape and add docstring.
        self._x = x
        self._y = y
        self._radius = radius
        self._segments = segments
        self._rgb = color
        self._angle = angle

        self._batch = batch or Batch()
        self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, group)

        self._vertex_list = self._batch.add(self._segments * 2, GL_LINES,
                                            self._group, 'position2f',
                                            'colors4Bn')
        self._update_position()
        self._update_color()