def update(self, events: list): if len(self.tasks) > 0: if time() >= self.tasks[0][0]: self.tasks[0][1](*self.tasks[0][2], **self.tasks[0][3]) del self.tasks[0] for prop in self.props.array: if prop.deleted: try: self.props.array.remove(prop) except ValueError: pass continue prop.system_update() prop.update(pygame.key.get_pressed()) for event in events: if event.type == pygame.MOUSEBUTTONDOWN: if point_in_rect(event.pos, prop.rect): prop.onclick(event.button, event.pos) else: prop.onnotclick(event.button, event.pos) prop.onmousedown(event.button, event.pos) if event.type == pygame.MOUSEBUTTONUP: if point_in_rect(event.pos, prop.rect): prop.onrelease(event.button, event.pos) prop.onmouseup(event.button, event.pos) if event.type == pygame.MOUSEMOTION: prop.onmousemotion(event.pos, event.rel, event.buttons) if point_in_rect(event.pos, prop.rect): if prop.on_mouse_over_cache is False: prop.on_mouse_over_cache = True prop.onmouseover(event.pos, event.rel, event.buttons) else: if prop.on_mouse_over_cache: prop.on_mouse_over_cache = False prop.onmouseleave(event.pos, event.rel, event.buttons) if event.type == pygame.KEYDOWN: prop.onkeydown(event.unicode, event.key, event.mod, event.scancode) if event.type == pygame.KEYUP: prop.onkeyup(event.key, event.mod, event.scancode) prop.onevent(event)
def is_touching_mouse(self): """ Returns if this object is touching the mouse cursor """ return point_in_rect(pygame.mouse.get_pos(), self.rect)