def add_rect(self, new_rect: pygame.Rect): for sheet in Spritesheet.select(): rects = [pygame.Rect(t.x,t.y,t.width,t.height) for t in sheet.thumbnails] sheet_rect = pygame.Rect(0,0,sheet.height, sheet.width) for rect in rects: crects = rects.copy() crects.remove(rect) new_rect.topleft = rect.topright if new_rect.collidelist(crects) == -1: if sheet_rect.contains(new_rect): return sheet, new_rect new_rect.topleft = rect.bottomright if new_rect.collidelist(crects) == -1: if sheet_rect.contains(new_rect): return sheet, new_rect new_rect.topright = rect.topleft if new_rect.collidelist(crects) == -1: if sheet_rect.contains(new_rect): return sheet, new_rect new_rect.topright = rect.bottomleft if new_rect.collidelist(crects) == -1: if sheet_rect.contains(new_rect): return sheet, new_rect sheet = Spritesheet.create(height=DEFAULT_HEIGHT, width=DEFAULT_WIDTH) new_rect.topleft = (0, 0) return sheet, new_rect
def __init__( self, screen: pygame.surface.Surface, manager: pygame_gui.UIManager, rect: pygame.Rect, bg: ty.Tuple[int, int, int] = (150, 150, 150), ) -> None: self.screen = screen self.manager = manager self.rect = rect self.midi_in = SingleNoteInput() self.midi_in.init() self.bg = bg dropdown_rect = (0, 0, 200, MIDI_HEIGHT) rect = pygame.Rect(*dropdown_rect) rect.topleft = (self.rect.x, self.rect.y) keys = list(self.midi_in.apis.keys()) self.api = pygame_gui.elements.UIDropDownMenu( keys, keys[0], rect, self.manager ) rect = pygame.Rect(*dropdown_rect) rect.topright = (self.rect.x + self.rect.width, self.rect.y) keys = list(self.midi_in.ports) self.port = pygame_gui.elements.UIDropDownMenu( keys, keys[0], rect, self.manager )
def test_topright(self): """Changing the bottomleft attribute moves the rect and does not change the rect's size """ r = Rect(1, 2, 3, 4) new_topright = (r.right + 20, r.top + 30) expected_topleft = (r.left + 20, r.top + 30) old_size = r.size r.topright = new_topright self.assertEqual(new_topright, r.topright) self.assertEqual(expected_topleft, r.topleft) self.assertEqual(old_size, r.size)
def test_topright( self ): """Changing the bottomleft attribute moves the rect and does not change the rect's size """ r = Rect( 1, 2, 3, 4 ) new_topright = (r.right+20,r.top+30) expected_topleft = (r.left+20,r.top+30) old_size = r.size r.topright = new_topright self.assertEqual( new_topright, r.topright ) self.assertEqual( expected_topleft, r.topleft ) self.assertEqual( old_size, r.size )