コード例 #1
0
 def prepare_map_cache(self):
     w, h = self.widget_size
     size_mul = self.MAP_CACHE_SIZE * 2 + 1
     size = (size_mul * w / self.zoom, size_mul * h / self.zoom)
     if size[0] > 2048: size = (2048, size[1] * 2048 / size[0])
     if size[1] > 2048: size = (size[0] * 2048 / size[1], 2048)
     size = (int(size[0]), int(size[1]))
     if size != self.map_cache.get_size():
         self.client.set_map_size(size)
         self.map_cache = graphics.create_surface(size[0], size[1], alpha=False)
         if self.zoom != 1:
             self.scaled_map_cache = graphics.create_surface(int(size_mul * w), int(size_mul * h))
     self.user_corner = (int(self.MAP_CACHE_SIZE * w), int(self.MAP_CACHE_SIZE * h))
     self.valid_for_origin = freeciv.func.get_map_view_origin()
コード例 #2
0
 def prepare_map_cache(self):
     w, h = self.widget_size
     size_mul = self.MAP_CACHE_SIZE * 2 + 1
     size = (size_mul * w / self.zoom, size_mul * h / self.zoom)
     if size[0] > 2048: size = (2048, size[1] * 2048 / size[0])
     if size[1] > 2048: size = (size[0] * 2048 / size[1], 2048)
     size = (int(size[0]), int(size[1]))
     if size != self.map_cache.get_size():
         self.client.set_map_size(size)
         self.map_cache = graphics.create_surface(size[0], size[1], alpha=False)
         if self.zoom != 1:
             self.scaled_map_cache = graphics.create_surface(int(size_mul * w), int(size_mul * h))
     self.user_corner = (int(self.MAP_CACHE_SIZE * w), int(self.MAP_CACHE_SIZE * h))
     self.valid_for_origin = freeciv.func.get_map_view_origin()
コード例 #3
0
 def draw(self, surf, clip_pos):
     pos = (0, 0)
     cliptex = graphics.create_surface(*self.widget_size)
     if not self.scrolling:
         target = (pos[0] - self.user_corner[0], pos[1] - self.user_corner[1])
         self.maybe_update_whole_canvas()
         if self.zoom == 1:
             self.client.draw_map(cliptex, target)
         else:
             self.client.draw_map(self.map_cache, (0, 0))
             rect = self.user_corner + (self.map_cache.get_width() - self.user_corner[0],
                                        self.map_cache.get_height() - self.user_corner[1])
             #cliptex.blit(scale_by(self.map_cache.suburface(rect), self.zoom), (pos[0], pos[1]))
             cliptex.blit(self.map_cache, src=rect,
                          dest=(pos[0], pos[1], rect[2] * self.zoom, rect[3] * self.zoom))
     else:
         if freeciv.func.get_map_view_origin() != self.valid_for_origin:
             self.reload()
         else:
             if self.does_exceed():
                 self.update_origin()
                 self.reload()
         if self.zoom == 1:
             cliptex.blit(self.map_cache, (pos[0] - self.user_corner[0], pos[1] - self.user_corner[1]))
         else:
             cliptex.blit(self.scaled_map_cache, (int(pos[0] - self.user_corner[0] * self.zoom),
                                               int(pos[1] - self.user_corner[1] * self.zoom)))
     surf.blit(cliptex, clip_pos)
コード例 #4
0
 def draw(self, surf, clip_pos):
     pos = (0, 0)
     cliptex = graphics.create_surface(*self.widget_size)
     if not self.scrolling:
         target = (pos[0] - self.user_corner[0],
                   pos[1] - self.user_corner[1])
         self.maybe_update_whole_canvas()
         if self.zoom == 1:
             self.client.draw_map(cliptex, target)
         else:
             self.client.draw_map(self.map_cache, (0, 0))
             rect = self.user_corner + (
                 self.map_cache.get_width() - self.user_corner[0],
                 self.map_cache.get_height() - self.user_corner[1])
             #cliptex.blit(scale_by(self.map_cache.suburface(rect), self.zoom), (pos[0], pos[1]))
             cliptex.blit(self.map_cache,
                          src=rect,
                          dest=(pos[0], pos[1], rect[2] * self.zoom,
                                rect[3] * self.zoom))
     else:
         if freeciv.func.get_map_view_origin() != self.valid_for_origin:
             self.reload()
         else:
             if self.does_exceed():
                 self.update_origin()
                 self.reload()
         if self.zoom == 1:
             cliptex.blit(self.map_cache, (pos[0] - self.user_corner[0],
                                           pos[1] - self.user_corner[1]))
         else:
             cliptex.blit(self.scaled_map_cache,
                          (int(pos[0] - self.user_corner[0] * self.zoom),
                           int(pos[1] - self.user_corner[1] * self.zoom)))
     surf.blit(cliptex, clip_pos)
コード例 #5
0
ファイル: help.py プロジェクト: zielmicha/freeciv-android
    def draw_text(self, text):
        spacing = self.font.render('l', 1, (0,0,0)).get_width()
        width = self.width
        words = []
        lines = [words]
        current_width = 0
        for word in text.split():
            img = self.font.render(word, 1, self.color)
            if current_width != 0 and img.get_width() + current_width > self.width:
                words = []
                lines.append(words)
                current_width = 0
            words.append(img)
            current_width += img.get_width() + spacing

        height = sum( max([ word.get_height() for word in line ] + [0]) for line in lines )

        surf = graphics.create_surface(width, height)

        y = 0
        for line in lines:
            if not line: continue
            x = 0
            for word in line:
                surf.blit(word, (x, y))
                x += word.get_width() + spacing
            y += max( word.get_height() for word in line )

        return surf
コード例 #6
0
ファイル: help.py プロジェクト: socialloser1/freeciv-android
    def draw_text(self, text):
        spacing = self.font.render('l', 1, (0, 0, 0)).get_width()
        width = self.width
        words = []
        lines = [words]
        current_width = 0
        for word in text.split():
            img = self.font.render(word, 1, self.color)
            if current_width != 0 and img.get_width(
            ) + current_width > self.width:
                words = []
                lines.append(words)
                current_width = 0
            words.append(img)
            current_width += img.get_width() + spacing

        height = sum(
            max([word.get_height() for word in line] + [0]) for line in lines)

        surf = graphics.create_surface(width, height)

        y = 0
        for line in lines:
            if not line: continue
            x = 0
            for word in line:
                surf.blit(word, (x, y))
                x += word.get_width() + spacing
            y += max(word.get_height() for word in line)

        return surf
コード例 #7
0
    def draw_clipped(self, surf, pos, clip):
        rect = graphics.Rect(clip)
        cliptex = graphics.create_surface(rect[2], rect[3])
        relpos = ui.layout._subpoints(pos, (rect[0], rect[1]))

        self.draw(cliptex, relpos)

        surf.blit(cliptex, (rect[0], rect[1]))
コード例 #8
0
    def draw_clipped(self, surf, pos, clip):
        rect = graphics.Rect(clip)
        cliptex = graphics.create_surface(rect[2], rect[3])
        relpos = ui.layout._subpoints(pos, (rect[0], rect[1]))

        self.draw(cliptex, relpos)

        surf.blit(cliptex, (rect[0], rect[1]))
コード例 #9
0
ファイル: maptiles.py プロジェクト: mercury199/FreeCivAndroid
 def draw_fragment(self, rect):
     with self.save_state():
         self.set_map_size((rect[2], rect[3]))
         self.set_map_origin(rect[0], rect[1])
         surf = graphics.create_surface(rect[2], rect[3])
         surf.fill((255, 0, 255, 255), blend=graphics.MODE_NONE)
         self.client.draw_map(surf, (0, 0))
         tile_pos = freeciv.func.py_canvas_to_map(rect[2] / 2, rect[3] / 2)
         return surf, tile_pos
コード例 #10
0
 def draw_fragment(self, rect):
     with self.save_state():
         self.set_map_size((rect[2], rect[3]))
         self.set_map_origin(rect[0], rect[1])
         surf = graphics.create_surface(rect[2], rect[3])
         surf.fill((255, 0, 255, 255), blend=graphics.MODE_NONE)
         self.client.draw_map(surf, (0, 0))
         tile_pos = freeciv.func.py_canvas_to_map(rect[2] / 2, rect[3] / 2)
         return surf, tile_pos
コード例 #11
0
    def draw_clipped(self, surf, pos, rect):
        rect = graphics.Rect(rect)
        cliptex = graphics.create_surface(rect[2], rect[3])
        relpos = _subpoints(pos, (rect[0], rect[1]))
        self.positions = list(self.get_positions())

        for itempos, item in zip(self.positions, self.items):
            item.draw(cliptex, _addpoints(relpos, itempos))

        surf.blit(cliptex, (rect[0], rect[1]))
コード例 #12
0
ファイル: scroll.py プロジェクト: at13/freeciv-android
    def draw(self, surf, pos):
        fx, fy = 0, 0
        if self.use_x:
            fx -= self.x
        if self.use_y:
            fy -= self.y

        cliptex = graphics.create_surface(*self.get_clip())
        self.item.draw(cliptex, (fx, fy))
        surf.blit(cliptex, pos)
コード例 #13
0
ファイル: ui.py プロジェクト: promerum/freeciv-android
    def draw(self, surf, pos):
        fx, fy = 0, 0
        if self.use_x:
            fx -= self.x
        if self.use_y:
            fy -= self.y

        cliptex = graphics.create_surface(*self.get_clip())
        self.item.draw(cliptex, (fx, fy))
        surf.blit(cliptex, pos)
コード例 #14
0
ファイル: layout.py プロジェクト: zielmicha/freeciv-android
    def draw_clipped(self, surf, pos, rect):
        rect = graphics.Rect(rect)
        cliptex = graphics.create_surface(rect[2], rect[3])
        relpos = _subpoints(pos, (rect[0], rect[1]))
        self.positions = list(self.get_positions())

        for itempos, item in zip(self.positions, self.items):
            item.draw(cliptex, _addpoints(relpos, itempos))

        surf.blit(cliptex, (rect[0], rect[1]))
コード例 #15
0
    def __init__(self, client):
        self.client = client

        self.valid_for_origin = None # if get_map_view_origin() returns something else, redraw map
        self.user_corner = (0.0, 0.0) # this point should be painted in top-left corner

        self.map_cache = graphics.create_surface(1, 1)
        self.last_map_size = None
        self.widget_size = (0, 0)
        self.scrolling = False
        self.zoom = 1

        self.MAP_CACHE_SIZE = 0.
コード例 #16
0
    def __init__(self, client):
        self.client = client

        self.valid_for_origin = None # if get_map_view_origin() returns something else, redraw map
        self.user_corner = (0.0, 0.0) # this point should be painted in top-left corner

        self.map_cache = graphics.create_surface(1, 1)
        self.last_map_size = None
        self.widget_size = (0, 0)
        self.scrolling = False
        self.zoom = 1
        self.canvas_last_updated = 0

        self.MAP_CACHE_SIZE = 0.
コード例 #17
0
def render_text(font, text, color=(0, 0, 0)):
    if '\n' in text:
        lines = text.splitlines()
        renders = [ font.render(line, True, color) for line in lines ]
        w = max( render.get_width() for render in renders )
        h = sum( render.get_height() for render in renders )
        surf = graphics.create_surface(w, h)
        y = 0
        for render in renders:
            surf.blit(render, (0, y))
            y += render.get_height()
        return surf
    else:
        return font.render(text, True, color)
コード例 #18
0
ファイル: ui.py プロジェクト: bbqchickenrobot/freeciv-android
def render_text(font, text, color=(0, 0, 0)):
    if '\n' in text:
        lines = text.splitlines()
        renders = [ font.render(line, True, color) for line in lines ]
        w = max( render.get_width() for render in renders )
        h = sum( render.get_height() for render in renders )
        surf = graphics.create_surface(w, h)
        y = 0
        for render in renders:
            surf.blit(render, (0, y))
            y += render.get_height()
        return surf
    else:
        return font.render(text, True, color)
コード例 #19
0
 def do_draw(self, surf, pos, offset, clip, full_texture=None):
     if surf == graphics.get_window() and ui.layer_hooks.is_bound():
         if full_texture:
             tex = full_texture
         else:
             tex = graphics.create_surface(*self.get_content_size())
             self.draw_content(tex, (0, 0))
         ui.layer_hooks.execute(id=id(self),
                                surf=tex,
                                pos=pos,
                                offset=offset,
                                size=clip)
         # not only for decorative purposes - also somehow causes SDL to return right renderer data
         surf.draw_rect((255, 255, 0, 0),
                        pos + clip, blend=graphics.MODE_NONE)
     else:
         if full_texture:
             surf.blit(full_texture, dest=pos, src=offset + clip)
         else:
             cliptex = graphics.create_surface(*clip)
             x, y = offset
             self.draw_content(cliptex, (-x, -y))
             surf.blit(cliptex, pos)
コード例 #20
0
 def do_draw(self, surf, pos, offset, clip, full_texture=None):
     if surf == graphics.get_window() and ui.layer_hooks.is_bound():
         if full_texture:
             tex = full_texture
         else:
             tex = graphics.create_surface(*self.get_content_size())
             self.draw_content(tex, (0, 0))
         ui.layer_hooks.execute(id=id(self),
                                surf=tex,
                                pos=pos,
                                offset=offset,
                                size=clip)
         # not only for decorative purposes - also somehow causes SDL to return right renderer data
         surf.draw_rect((255, 255, 0, 0),
                        pos + clip,
                        blend=graphics.MODE_NONE)
     else:
         if full_texture:
             surf.blit(full_texture, dest=pos, src=offset + clip)
         else:
             cliptex = graphics.create_surface(*clip)
             x, y = offset
             self.draw_content(cliptex, (-x, -y))
             surf.blit(cliptex, pos)
コード例 #21
0
ファイル: common.py プロジェクト: zielmicha/freeciv-android
def create_sprite(width, height, color):
    surf = graphics.create_surface(width, height)
    surf.fill(color)
    return surf
コード例 #22
0
ファイル: common.py プロジェクト: zielmicha/freeciv-android
def canvas_create(w, h):
    return graphics.create_surface(w, h, alpha=False)
コード例 #23
0
def init():
    global screen, surface, overview_surface
    overview_surface = graphics.create_surface(200, 200)
コード例 #24
0
def overview_size_changed():
    global overview_surface
    w, h = freeciv.get_overview_size()
    overview_surface = graphics.create_surface(w, h)
    client.client.overview_size_changed(w, h)
コード例 #25
0
ファイル: window.py プロジェクト: at13/freeciv-android
def overview_size_changed():
    global overview_surface
    w, h = freeciv.get_overview_size()
    overview_surface = graphics.create_surface(w, h)
    client.client.overview_size_changed(w, h)
コード例 #26
0
ファイル: common.py プロジェクト: zekoz/freeciv-android
def canvas_create(w, h):
    return graphics.create_surface(w, h, alpha=False)
コード例 #27
0
ファイル: common.py プロジェクト: zekoz/freeciv-android
def create_sprite(width, height, color):
    surf = graphics.create_surface(width, height)
    surf.fill(color)
    return surf
コード例 #28
0
ファイル: actions.py プロジェクト: zekoz/freeciv-android
 def get_image(self):
     w = 91
     h = 61
     surf = graphics.create_surface(w, h)
     freeciv.func.py_put_unit(self.handle, surf)
     return surf
コード例 #29
0
ファイル: window.py プロジェクト: at13/freeciv-android
def init():
    global screen, surface, overview_surface
    overview_surface = graphics.create_surface(200, 200)