Exemplo n.º 1
0
 def get_style_attributes(self):
     style = self.entity.style
     border_images = style["border_images"]
     h_side, v_side, corner = border_images
     self.h_side_image = load_resource(h_side)
     self.v_side_image = load_resource(v_side)
     self.corner_image = load_resource(corner)
     self.border_size = self.corner_image.get_size()
Exemplo n.º 2
0
    def get_environment(self, name):
        env = Environment(name)
        cfg = load_resource(name)

        self.set_environment_context(cfg, env, p=True)

        return env
Exemplo n.º 3
0
    def tile(image_name, surface):
        # PYGAME CHOKE POINT

        if image_name not in Graphics.PRE_RENDERS:
            bg_image = load_resource(image_name)
            sx, sy = Settings.SCREEN_SIZE  # pre render the tiled background
            sx *= 2  # to the size of a full screen
            sy *= 2
            pr_surface = Surface((sx, sy), SRCALPHA, 32)

            w, h = pr_surface.get_size()
            img_w, img_h = bg_image.get_size()

            for x in range(0, w + img_w, img_w):
                for y in range(0, h + img_h, img_h):
                    pr_surface.blit(bg_image, (x, y))

            Graphics.PRE_RENDERS[image_name] = pr_surface

        full_bg = Graphics.PRE_RENDERS[
            image_name]  # return a subsection of the full
        #                                               # pre rendered background
        r = surface.get_rect().clip(full_bg.get_rect())
        blit_region = full_bg.subsurface(r)
        surface.blit(blit_region, (0, 0))

        return surface
Exemplo n.º 4
0
    def make_image(self, bg_color=False):
        entity = self.entity
        size = entity.size
        style = entity.style

        if not bg_color:
            # BG COLOR
            if style["bg_color"]:
                bg_color = style["bg_color"]
            else:
                bg_color = 0, 0, 0

        image = self.make_color_image(size, bg_color)

        # BG TILE IMAGE
        if style.get("bg_image", None):
            self.bg_image = load_resource(style["bg_image"])
            image = self.tile(style["bg_image"], image)

        # BORDERS
        if style.get("border", None):
            border_images = style["border_images"]
            sides = style["border_sides"]
            corners = style["border_corners"]

            image = self.make_border_image(border_images, image, sides,
                                           corners)

        # BORDER ALPHA TRIM
        if style.get("alpha_color", None):
            image = self.convert_colorkey(image, (255, 0, 0))

        return image
Exemplo n.º 5
0
    def draw_corners(image_name, surface, corners):
        corner_image = load_resource(image_name)
        w, h = surface.get_size()
        cw, ch = corner_image.get_size()
        a, b, c, d = DefaultUI.BORDER_CORNER_CHOICES
        locations = {
            a: (0, 0),
            b: (w - cw, 0),
            c: (0, h - ch),
            d: (w - cw, h - ch)
        }

        for corner in corners:
            surface.blit(ContainerGraphics.get_corner(corner_image, corner),
                         locations[corner])
Exemplo n.º 6
0
    def apply_interfaces(self, entity, data, p=False):
        for interface in self.interfaces:
            gui_data = data.get(interface.name, None)

            if gui_data:
                if ".json" in gui_data:
                    section = load_resource(gui_data)
                else:
                    section = self.model[gui_data]
            else:
                section = {}

            if hasattr(entity, interface.name):
                section.update(getattr(entity, interface.name))

            interface.apply_to_entity(entity, section, p=p)
Exemplo n.º 7
0
    def make_image(self):
        image = load_resource(self.file_name)
        scale = self.scale
        if scale != 1:
            image = self.scale_image(image, scale)

        if not self.sub:
            return image

        else:
            (x, y), (w, h) = self.sub
            x *= scale
            y *= scale
            w *= scale
            h *= scale
            return self.make_sub_image(image, (x, y), (w, h))
Exemplo n.º 8
0
    def get_full_side_image(image_name, orientation):
        if image_name not in ContainerGraphics.PRE_RENDERS:
            image = load_resource(image_name)
            iw, ih = image.get_size()

            h, v = "hv"
            size = {
                h: (iw, Settings.SCREEN_SIZE[1]),
                v: (Settings.SCREEN_SIZE[0], iw)
            }[orientation]
            pr_surface = Surface(size, SRCALPHA, 32)

            span = {
                h: range(0, size[1], ih),
                v: range(0, size[0], iw)
            }[orientation]

            for i in span:
                position = {h: (0, i), v: (i, 0)}[orientation]
                pr_surface.blit(image, position)

            ContainerGraphics.PRE_RENDERS[image_name] = pr_surface

        return ContainerGraphics.PRE_RENDERS[image_name]
Exemplo n.º 9
0
    def load_controller(file_name):
        devices = load_resource(file_name + ".cfg")["devices"]

        return ControllerIO.make_controller(file_name, devices)