def __init__(self): graphics.SimpleSprite.__init__(self, 4, 4) self.image.fill(palette.color(0x00)) self.image.fill(palette.color(0x3f), self.rect.inflate(0, -2)) self.position = 0 self.add(graphics.wirelayer) self._old_rect = None
def __init__(self): self.board = Board(self) self.clickables = [] self.cursor = cursor.Cursor() self.toolbar = toolbar.Toolbar() self.toolbar.add_tool(components.display.DisplayTool(self.board)) self.toolbar.add_tool(components.button.ButtonTool(self.board)) self.clickables.append(self.toolbar) infotext = text.render('FlowSID v0.0.1') info = pygame.sprite.Sprite() info.image = pygame.Surface(infotext.rect.inflate(3, 3).size) info.rect = info.image.get_rect() info.image.fill(palette.color(0x10)) pygame.draw.rect(info.image, palette.color(0x20), info.rect, 1) infotext.rect.move_ip(2, 2) info.image.blit(infotext.image, infotext.rect) colors = tuple(palette.color(x) for x in (0x10,0x20,0x30,0x20)) def update_info(frame): info.rect.bottomright = graphics.screen.get_size() for x in range(info.rect.width - 2): color = colors[(x - 16*len(colors)*frame/255)/2%len(colors)] info.image.fill(color, pygame.Rect(x + 1, 1, 1, 1)) info.image.fill(color, pygame.Rect(info.rect.width - x - 2, info.rect.height - 2, 1, 1)) info.update = update_info graphics.uilayer.add(info)
def _tool_down(self, tool): tool_number = self.tools.index(tool) rect = pygame.Rect(self.border, self.border + tool_number*iconsize, iconsize - 1, iconsize - 1) self.image.fill(palette.color(0x15), rect) pygame.draw.lines(self.image, palette.color(0x00), False, (rect.bottomleft, rect.topleft, rect.topright)) pygame.draw.lines(self.image, palette.color(0x2a), False, (rect.topright, rect.bottomright, rect.bottomleft)) tool.rect.topleft = rect.topleft self.image.blit(tool.image, tool.rect)
def render(text, color=palette.color(0x3f), large=False): surface = font.render(text, False, color) if large: surface = pygame.transform.scale2x(surface) sprite = pygame.sprite.Sprite() sprite.image = surface sprite.rect = sprite.image.get_rect() return sprite
def __init__(self): component.Component.__init__(self, 64, 18) self.image.fill(palette.color(0x00)) rect = self.rect.inflate(-3, -3) pygame.draw.lines(self.image, dark_color, False, (rect.topright, rect.bottomright, rect.bottomleft)) pygame.draw.lines(self.image, light_color, False, (rect.bottomleft, rect.topleft, rect.topright)) rect = self.rect.inflate(-5, -5) pygame.draw.lines(self.image, dark_color, False, (rect.bottomleft, rect.topleft, rect.topright)) pygame.draw.lines(self.image, light_color, False, (rect.topright, rect.bottomright, rect.bottomleft)) self.image.set_clip(self.rect.inflate(-6, -6)) inp = connection.Connection() self.inputs.append(inp) self.inp(None)
def draw_button(sprite, size, up=True): if up: color_button = palette.color(0x2a) color_light = palette.color(0x3f) color_dark = palette.color(0x15) else: color_button = palette.color(0x15) color_light = palette.color(0x00) color_dark = palette.color(0x2a) circles = ((color_button, (0, 0), size, 0), (color_dark, (-1, -1), size, 1), (color_light, (1, 1), size, 1), (color_dark, (0, -1), size, 1), (color_light, (0, 1), size, 1), (graphics.transparent, (0, 0), size + 1, 1), (graphics.transparent, (0, -1), size + 1, 1), (graphics.transparent, (0, 1), size + 1, 1), (palette.color(0x00), (0, 0), size, 1)) for c in circles: pygame.draw.circle(sprite.image, c[0], pygame.Rect(c[1], sprite.rect.size).center, c[2], c[3])
import pygame, palette scale = 2 transparent = pygame.Color('white') bg_color = palette.color(0x16) invisible = pygame.sprite.Group() mainlayer = pygame.sprite.Group() wirelayer = pygame.sprite.Group() uilayer = pygame.sprite.Group() toplayer = pygame.sprite.Group() def init(): pygame.display.init() pygame.event.post(pygame.event.Event(pygame.VIDEORESIZE, size=(640, 400))) pygame.mouse.set_visible(False) def render_loop(event_handler): global screen clock = pygame.time.Clock() frame = 0 while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: return elif event.type == pygame.VIDEORESIZE: size = tuple(x/scale for x in event.size) real_size = tuple(x*scale for x in size) real_screen = pygame.display.set_mode(real_size, pygame.RESIZABLE) screen = pygame.Surface(size) else: event_handler(event)
def __init__(self): graphics.SimpleSprite.__init__(self, 6, 8) points = (0, 0), (0, 7), (2, 5), (5, 5) pygame.draw.polygon(self.image, palette.color(0x1D), points) pygame.draw.polygon(self.image, palette.color(0x00), points, 1) self.add(graphics.toplayer)
def __init__(self): graphics.SimpleSprite.__init__(self, self.width, self.height) self.image.fill(palette.color(0x39)) pygame.draw.rect(self.image, palette.color(0x24), self.rect, 1) self.add(graphics.uilayer)
import pygame, palette, text, toolbar, pprint, component, connection bg_color = palette.color(0x04) text_color = palette.color(0x0C) light_color = palette.color(0x2E) dark_color = palette.color(0x19) class DisplayTool(toolbar.Tool): def __init__(self, board): toolbar.Tool.__init__(self) self.board = board pygame.draw.rect(self.image, bg_color, self.rect.inflate(-4, -4)) symbol = text.render("x:", text_color) symbol.rect.topleft = (3, 3) self.image.blit(symbol.image, symbol.rect) def click(self): self.board.add_component(DisplayComponent()) pass class DisplayComponent(component.Component): def __init__(self): component.Component.__init__(self, 64, 18) self.image.fill(palette.color(0x00)) rect = self.rect.inflate(-3, -3) pygame.draw.lines(self.image, dark_color, False, (rect.topright, rect.bottomright, rect.bottomleft)) pygame.draw.lines(self.image, light_color, False, (rect.bottomleft, rect.topleft, rect.topright))