def __init__( self, colour, pos, message, textSize=None, background=None, handler=None, fontFace=None ): #textSize=.75 & fontFace="assets/OpenSansCondensed-Light.ttf"): self.colour = colour self.currcolour = colour self.background = background self.togglevalue = False if textSize == None and fontFace == None: self.font = _defaulttextfont else: if textSize == None: textSize = .75 if fontFace == None: fontFace = "assets/OpenSansCondensed-Light.ttf" self.font = Font(fontFace, int(50.0 * textSize)) self.renderText(message) if (pos[1] < 0): pos = (pos[0], (config.RESOLUTION[0] / 2) - self.image.get_rect().width / 2) LcarsWidget.__init__(self, colour, pos, None, handler) self.beep = Sound("assets/audio/panel/202.wav")
def __init__(self, colour, shape, pos, text, handler=None): self.handler = handler # Load different image for shape if (shape == "nav"): image = pygame.image.load("assets/nav.png").convert() elif (shape == "btn"): image = pygame.image.load("assets/button.png").convert() size = (image.get_rect().width, image.get_rect().height) font = Font("assets/swiss911.ttf", 22) textImage = font.render(text, False, colours.BLACK) # Change text position if (shape == "nav"): image.blit( textImage, (image.get_rect().width - textImage.get_rect().width - 12, image.get_rect().height - textImage.get_rect().height)) elif (shape == "btn"): image.blit( textImage, (image.get_rect().width - textImage.get_rect().width - 10, image.get_rect().height - textImage.get_rect().height - 5)) self.image = image self.colour = colour LcarsWidget.__init__(self, colour, pos, size) self.applyColour(colour) self.highlighted = False self.beep = Sound("assets/audio/panel/202.wav")
def __init__(self, colour, pos, text, handler=None, rectSize=None, icon=None): if rectSize == None: image = pygame.image.load("assets/button.png").convert_alpha() size = (image.get_rect().width, image.get_rect().height) else: size = rectSize image = pygame.Surface(rectSize) image.fill(colour) #image=image.convert_alpha() self.colour = colour self.image = image self.font = Font("assets/YukonTech.ttf", 18) textImage = self.font.render(text, False, colours.BLACK) image = image.blit( textImage, (image.get_rect().width - textImage.get_rect().width - 10, image.get_rect().height - textImage.get_rect().height - 5)) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour) self.highlighted = False self.beep = Sound("assets/audio/panel/202.wav")
def __init__(self, pos, text=None, colour_set=[colours.WHITE, colours.GREY_BLUE, colours.BLUE], image_set=[None, None, None], text_colour=colours.BLACK, font=None, size=(80, 40), handler=None): #Set button attributes #all buttons self.colour = colour_set[0] self.colour_highlighted = colour_set[1] self.colour_pressed = colour_set[2] self.size = size self.text_colour = text_colour #image buttons only if not image_set[0] == None: self.image_normal = image_set[0].convert_alpha() image = self.image_normal self.image = image self.size = (image.get_rect().width, image.get_rect().height) if not image_set[1] == None: self.image_highlighted = image_set[1].convert_alpha() if not image_set[2] == None: self.image_pressed = image_set[2].convert_alpha() self.imageonly = True #Create surface for non-image button if not self.imageonly: if image_set[0] == None: image = pygame.Surface(self.size) image.fill(self.colour) self.image = image #apply colour to white button else: self.image = image self.applyColour(self.colour) #Create text image if text included if not text == None: if font == None: self.font = Font("assets/MicroTech.ttf", 18) else: self.font = font textImage = self.font.render(text, False, self.text_colour) textrect = textImage.get_rect() image = image.blit( textImage, (image.get_rect().width - textImage.get_rect().width - 52, image.get_rect().height - textImage.get_rect().height - 10)) #Make widget LcarsWidget.__init__(self, self.colour, pos, self.size, handler) if image_set[2] == None: self.applyColour(self.colour) else: self.imageonly = True self.highlighted = False self.beep = Sound("assets/audio/panel/202.wav")
def __init__(self, image=None): if image != None: self.image = pygame.image.load(image).convert() else: self.image = pygame.Surface(config.RESOLUTION).convert_alpha() self.image.fill(colours.BLACK) LcarsWidget.__init__(self, None, (0, 0), None)
def __init__(self, colour, style, pos, handler=None): image = pygame.image.load("assets/tab.png").convert() if (style == LcarsTab.STYLE_RIGHT): image = pygame.transform.flip(image, False, True) size = (image.get_rect().width, image.get_rect().height) LcarsWidget.__init__(self, colour, pos, size, handler) self.image = image self.applyColour(colour)
def __init__(self, imagefilename, pos, duration=-1, stretch=None): self.image = GIFImage(imagefilename, duration) self.pos = pos # fixme! Stretch not working if stretch: size = config.RESOLUTION else: size = (self.image.get_rect().width, self.image.get_rect().height) print(size) LcarsWidget.__init__(self, None, pos, size)
def __init__(self, colour, pos, message, size=1.0, background=None, handler=None): self.colour = colour self.background = background self.font = Font("assets/swiss911.ttf", int(19.0 * size)) self.renderText(message) # center the text if needed if (pos[1] < 0): pos = (pos[0], 400 - self.image.get_rect().width / 2) LcarsWidget.__init__(self, colour, pos, None, handler)
def __init__(self, colour, style, pos): script_dir = dirname(__file__) ipath = join(script_dir, '../../assets/tab.png') image = pygame.image.load(ipath).convert() if (style == LcarsTab.STYLE_RIGHT): image = pygame.transform.flip(image, False, True) size = (image.get_rect().width, image.get_rect().height) LcarsWidget.__init__(self, colour, pos, size) self.image = image self.applyColour(colour)
def __init__(self, colour, pos, message, size=1.0, background=None): self.colour = colour self.background = background self.font = Font("assets/swiss911.ttf", int(19.0 * size)) self.renderText(message) # center the text if needed if (pos[1] < 0): pos = (pos[0], 400 - self.image.get_rect().width / 2) LcarsWidget.__init__(self, colour, pos, None)
def handleEvent(self, event, clock): handled = False if (event.type == MOUSEBUTTONDOWN and self.rect.collidepoint(event.pos)): handled = True if (event.type == MOUSEBUTTONUP): if self.handler: self.handler(self, event, clock) handled = True LcarsWidget.handleEvent(self, event, clock) return handled
def __init__(self, colour, style, pos, handler=None): image = pygame.image.load("assets/elbow.png").convert() if (style == LcarsElbow.STYLE_BOTTOM_LEFT): image = pygame.transform.flip(image, False, True) elif (style == LcarsElbow.STYLE_BOTTOM_RIGHT): image = pygame.transform.rotate(image, 180) elif (style == LcarsElbow.STYLE_TOP_RIGHT): image = pygame.transform.flip(image, True, False) self.image = image size = (image.get_rect().width, image.get_rect().height) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour)
def __init__(self, colour, style, pos): script_dir = dirname(__file__) ipath = join(script_dir, '../../assets/elbow.png') image = pygame.image.load(ipath).convert() if (style == LcarsElbow.STYLE_BOTTOM_LEFT): image = pygame.transform.flip(image, False, True) elif (style == LcarsElbow.STYLE_BOTTOM_RIGHT): image = pygame.transform.rotate(image, 180) elif (style == LcarsElbow.STYLE_TOP_RIGHT): image = pygame.transform.flip(image, True, False) self.image = image size = (image.get_rect().width, image.get_rect().height) LcarsWidget.__init__(self, colour, pos, size) self.applyColour(colour)
def __init__(self, colour, style, pos, text, group_number, handler): image = pygame.image.load("assets/elbow_top.png").convert_alpha() # alpha=255 # image.fill((255, 255, 255, alpha), None, pygame.BLEND_RGBA_MULT) if (style == LcarsElbow.STYLE_BOTTOM_LEFT): image = pygame.transform.flip(image, False, True) elif (style == LcarsElbow.STYLE_BOTTOM_RIGHT): image = pygame.transform.rotate(image, 180) elif (style == LcarsElbow.STYLE_TOP_RIGHT): image = pygame.transform.flip(image, True, False) self.image = image size = (image.get_rect().width, image.get_rect().height) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colours.WHITE)
def __init__(self, colour, pos, text, handler=None): self.handler = handler image = pygame.image.load("assets/button.png").convert() size = (image.get_rect().width, image.get_rect().height) font = Font("assets/swiss911.ttf", 19) textImage = font.render(text, False, colours.BLACK) image.blit(textImage, (image.get_rect().width - textImage.get_rect().width - 10, image.get_rect().height - textImage.get_rect().height - 5)) self.image = image self.colour = colour LcarsWidget.__init__(self, colour, pos, size) self.applyColour(colour) self.highlighted = False self.beep = Sound("assets/audio/panel/202.wav")
def __init__(self, colour, pos, message, size=1.0, background=None, resolution=(480, 320)): self.colour = colour self.message = message self.background = background script_dir = dirname(__file__) ipath = join(script_dir, '../../assets/swiss911.ttf') self.font = Font(ipath, int(19.0 * size)) self.renderText(message) # center the text if needed if (pos[1] < 0): # Screen specific magic number below! 240 = half width pos = (pos[0], resolution[0]/2 - self.image.get_rect().width/2) LcarsWidget.__init__(self, colour, pos, None)
def handleEvent(self, event, clock): handled = False if (event.type == MOUSEBUTTONDOWN and self.rect.collidepoint(event.pos)): self.applyColour(colours.WHITE) self.highlighted = True self.beep.play() handled = True if (event.type == MOUSEBUTTONUP and self.highlighted): self.applyColour(self.colour) if self.handler: self.handler(self, event, clock) handled = True LcarsWidget.handleEvent(self, event, clock) return handled
def handleEvent(self, event, clock): if (event.type == MOUSEBUTTONDOWN and self.rect.collidepoint(event.pos) and self.visible == True): self.beep.play() if (event.type == MOUSEBUTTONUP and self.visible == True): self.togglevalue = not self.togglevalue return LcarsWidget.handleEvent(self, event, clock)
def __init__(self, colour, style, pos, handler=None): image = _tabimage.copy() #image = pygame.image.load("assets/tab4.png").convert_alpha() if (style == LcarsTab.STYLE_RIGHT): image = pygame.transform.flip(image, True, False) elif (style == LcarsTab.STYLE_SMALL_LEFT): image = pygame.transform.rotozoom(image, 0, .5) elif (style == LcarsTab.STYLE_SMALL_RIGHT): image = pygame.transform.rotozoom(image, 0, .5) image = pygame.transform.flip(image, True, False) size = (image.get_rect().width, image.get_rect().height) self.colour = colour self.currcolour = colour self.image = image self.togglevalue = False LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour)
def __init__(self, colour, style, pos, size, handler=None): image = pygame.image.load("assets/elbow.png").convert_alpha() image = pygame.transform.smoothscale(image, size) # alpha=255 # image.fill((255, 255, 255, alpha), None, pygame.BLEND_RGBA_MULT) if (style == LcarsElbow.STYLE_BOTTOM_LEFT): image = pygame.transform.flip(image, False, True) elif (style == LcarsElbow.STYLE_BOTTOM_RIGHT): image = pygame.transform.rotate(image, 180) elif (style == LcarsElbow.STYLE_TOP_RIGHT): image = pygame.transform.flip(image, True, False) self.image = image #size = (image.get_rect().width, image.get_rect().height) size = (10, 10) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour) print(self.rect.x , "," , self.rect.y)
def handleEvent(self, event, clock): if (event.type == MOUSEBUTTONDOWN and self.rect.collidepoint(event.pos) and self.visible == True): self.applyColour(colours.WHITE) self.highlighted = True self.beep.play() if (event.type == MOUSEBUTTONUP and self.highlighted and self.visible == True): self.applyColour(self.colour) return LcarsWidget.handleEvent(self, event, clock)
def handleEvent(self, event, clock): handled = False if (event.type == MOUSEBUTTONDOWN and self.rect.collidepoint(event.pos)): self.applyColour(colours.WHITE) self.highlighted = True # NOTE: Should put the sounds behind a global/config param # self.beep.play() handled = True if (event.type == MOUSEBUTTONUP and self.highlighted): self.applyColour(self.colour) if self.handler: self.handler(self, event, clock) handled = True LcarsWidget.handleEvent(self, event, clock) return handled
def __init__(self, colour, pos, text, handler=None, rectSize=None): if rectSize == None: image = pygame.image.load("assets/button.png").convert_alpha() size = (image.get_rect().width, image.get_rect().height) else: size = rectSize image = pygame.Surface(rectSize).convert_alpha() image.fill(colour) self.colour = colour self.image = image font = Font("assets/swiss911.ttf", 19) textImage = font.render(text, False, colours.BLACK) image.blit(textImage, (image.get_rect().width - textImage.get_rect().width - 10, image.get_rect().height - textImage.get_rect().height - 5)) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour) self.highlighted = False self.beep = Sound("assets/audio/panel/202.wav")
def __init__(self, colour, pos, text, handler=None): self.handler = handler script_dir = dirname(__file__) ipath = join(script_dir, '../../assets/betterbutton.png') image = pygame.image.load(ipath).convert() size = (image.get_rect().width, image.get_rect().height) ipath = join(script_dir, '../../assets/swiss911.ttf') font = Font(ipath, 19) textImage = font.render(text, False, colours.BLACK) image.blit(textImage, (image.get_rect().width - textImage.get_rect().width - 10, image.get_rect().height - textImage.get_rect().height - 5)) self.image = image self.colour = colour self.size = size LcarsWidget.__init__(self, colour, pos, size) self.applyColour(colour) self.highlighted = False # self.beep = Sound("assets/audio/panel/202.wav") self.inactiveColor = colour
def __init__(self, colour, pos, text, handler=None, rectSize=None, textSize=None, fontFace=None): if rectSize == None: image = _buttonimage.copy() #image = pygame.image.load("assets/button2.png").convert_alpha() size = (image.get_rect().width, image.get_rect().height) else: size = rectSize image = pygame.Surface(rectSize).convert_alpha() image.fill(colour) self.currcolour = colour self.colour = colour self.image = image self.togglevalue = False if textSize == None and fontFace == None: self.font = _defaultbuttonfont else: if textSize == None: textSize = .75 if fontFace == None: fontFace = "assets/OpenSansCondensed-Bold.ttf" self.font = Font(fontFace, int(50.0 * textSize)) textImage = self.font.render(text, False, colours.BLACK) image.blit(textImage, (image.get_rect().width - textImage.get_rect().width - 21, image.get_rect().height - textImage.get_rect().height - 3)) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour) self.highlighted = False self.beep = Sound("assets/audio/panel/202.wav")
def handleEvent(self, event, clock): if (event.type == MOUSEBUTTONDOWN and self.rect.collidepoint(event.pos) and self.visible == True): cursor = (pygame.mouse.get_pos()[0] - self.pos[1], pygame.mouse.get_pos()[1] - self.pos[0]) for item in self.textList: if item[0].collidepoint(cursor): self.item_selected = item[1] self.beep.play() if (event.type == MOUSEBUTTONUP and self.visible == True): pass return LcarsWidget.handleEvent(self, event, clock)
def handleEvent(self, event, clock): image2 = pygame.image.load("assets/button_modern_down.png") if (event.type == MOUSEBUTTONDOWN and self.rect.collidepoint(event.pos) and self.visible == True): self.highlighted = True self.beep.play() self.image = image2.convert_alpha() image = pygame.image.load("assets/button_modern.png") if (event.type == MOUSEBUTTONUP and self.highlighted and self.visible == True): self.image = image.convert_alpha() return LcarsWidget.handleEvent(self, event, clock)
def __init__(self, colour, pos, message, textSize=1.0, rectSize=(100, 100), background=(0, 0, 0, 0), handler=None, fontFace="assets/OpenSansCondensed-Light.ttf"): self.colour = colour self.currcolour = colour self.background = background self.togglevalue = False self.textList = [] self.place = 0 # self.marker = 0 # self.line_spacing = 0 self.rectSize = rectSize self.font = Font(fontFace, int(50.0 * textSize)) self.item_selected = None if not isinstance(message, list): self.message = message.splitlines() else: self.message = message self.image = pygame.Surface(self.rectSize).convert_alpha() self.image.fill(background) self.renderText(self.message) if (pos[1] < 0): pos = (pos[0], (config.RESOLUTION[0] / 2) - self.image.get_rect().width / 2) self.pos = pos LcarsWidget.__init__(self, colour, pos, rectSize, handler) self.beep = Sound("assets/audio/panel/202.wav")
def __init__(self, colour, pos, text=None, handler=None, rectSize=None, textSize=.75, fontFace="assets/OpenSansCondensed-Bold.ttf"): size = rectSize image = pygame.Surface(rectSize).convert_alpha() image.fill(colour) self.colour = colour self.currcolour = colour self.image = image if text != None: font = Font(fontFace, int(50.0 * textSize)) textImage = font.render(text, False, colours.BLACK) image.blit( textImage, (image.get_rect().width - textImage.get_rect().width - 10, image.get_rect().height - textImage.get_rect().height - 5)) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour)
def __init__(self, colour, pos, text, handler=None, direction="up"): if (direction=="up"): image = pygame.image.load("assets/buttons/half_button_u.png").convert() if (direction == "down"): image = pygame.image.load("assets/buttons/half_button_d.png").convert() if (direction == "left"): image = pygame.image.load("assets/buttons/half_button_l.png").convert() if (direction == "right"): image = pygame.image.load("assets/buttons/half_button_r.png").convert() size = (image.get_rect().width, image.get_rect().height) self.colour = colour self.image = image font = Font("assets/swiss911.ttf", 19) textImage = font.render(text, False, colours.BLACK) image.blit(textImage, (image.get_rect().width - textImage.get_rect().width - 10, image.get_rect().height - textImage.get_rect().height - 5)) LcarsWidget.__init__(self, colour, pos, size, handler) self.applyColour(colour) self.highlighted = False self.beep = Sound("assets/audio/panel/202.wav")
def handleEvent(self, event, clock): if (event.type == MOUSEBUTTONDOWN and self.rect.collidepoint(event.pos) and self.visible == True): if self.imageonly: self.image = self.image_pressed else: self.applyColour(self.colour_pressed) self.highlighted = True self.beep.play() #need to add mouseover highlight functionality here if (event.type == MOUSEBUTTONUP and self.highlighted and self.visible == True): if self.imageonly: self.image = self.image_normal else: self.applyColour(self.colour) return LcarsWidget.handleEvent(self, event, clock)
def __init__(self, image): self.image = pygame.image.load(image).convert() LcarsWidget.__init__(self, None, (0,0), None)
def __init__(self, image, pos, handler=None): self.handler = handler self.image = pygame.image.load(image).convert() LcarsWidget.__init__(self, None, pos, None)
def __init__(self, imagefilename, pos, duration=-1): self.image = GIFImage(imagefilename, duration) self.pos = pos size = (self.image.get_rect().width, self.image.get_rect().height) LcarsWidget.__init__(self, None, pos, size)
def __init__(self, image, pos): self.image = pygame.image.load(image).convert() LcarsWidget.__init__(self, None, pos, None)
def __init__(self, colour, pos): size = (100, 20) LcarsWidget.__init__(self, colour, pos, size)
def __init__(self, colour, pos): size = (160, 45) LcarsWidget.__init__(self, colour, pos, size)