def __init__(self, image, position): self.image = image self.position = position # set width and height if self.image: self.width = self.image.get_size()[0] self.height = self.image.get_size()[1] else: self._setsize((0, 0)) Widget.__init__(self, self.position, self.width, self.height)
def __init__(self, text, position, size=12, color=(255, 255, 255), align="left"): self.text = text self.labelfont = pygame.font.Font("dejavusansmono.ttf", size) self.image = None self.color = color self.position = position self.orginal_position = position self.align = align # set width and height self.render_text() self.width = self.image.get_size()[0] self.height = self.image.get_size()[1] self.setposition(self.position) Widget.__init__(self, self.position, self.width, self.height)
def __init__(self, label, position, bgimage=None, labelsize=12, color=(255, 255, 0)): self.bgimage = bgimage self.label = label self.color = color self.position = position self.labelsize = labelsize self.labelfont = pygame.font.Font("dejavusansmono.ttf", self.labelsize) self.buttonbgorg = pygame.image.load(buttonbgpath).convert_alpha() self.buttonbg = self.buttonbgorg.copy() # Setup image if not self.bgimage: self._settextimage() else: self._setsize(self._calculate_size(self.bgimage)) Widget.__init__(self, self.position, self.width, self.height)
def poll_event(self, event): """poll_event :param event: :return: """ Widget.poll_event(self, event) pos = self.parent.get_relative_mousepos() # mouse button down if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and pos\ and self.pointinwidget(pos[0], pos[1]): # on_click event self.call_callback("clicked") self.call_callback("onclick") # make button active if self.parent: self.parent.makeactive(self)
def __init__(self, width, height, position): Widget.__init__(self, position, width, height) self.widgets = [] self.visible = True # last active widget self._lastactivewidget = None