Exemplo n.º 1
0
def click_action(replay):
    global backSelected_drawn, infoSelected_drawn

    clicked = False

    for event in pygame.event.get():
        # Check for left click
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1: clicked = True
            else: clicked = False
        else: clicked = False

        mousePos = pygame.mouse.get_pos()

        # If cursor over back_btn
        if backBtn_x + backBtn_w > mousePos[
                0] > backBtn_x and backBtn_y + backBtn_h > mousePos[
                    1] > backBtn_y:
            if not backSelected_drawn:
                window.blit(backSelected_btn, (0, 0))
                update_draw()
                backSelected_drawn = True
            if clicked: return 'back'  # check if back_btn clicked
        else:
            if backSelected_drawn:
                window.blit(backUnselected_btn, (0, 0))
                update_draw()
                backSelected_drawn = False

        # Info button
        if info_btn.x + info_btn.w > mousePos[
                0] > info_btn.x and info_btn.y + info_btn.h > mousePos[
                    1] > info_btn.y:
            if not infoSelected_drawn:
                window.blit(sortInfoSelected_btn, (info_btn.x - 10, 0))
                update_draw()
                infoSelected_drawn = True
            if clicked:
                pause()
                information_run('bubblesort')
                pause()
                draw()
                update_draw()
                return 'next'
        else:
            if infoSelected_drawn:
                window.blit(sortInfoUnselected_btn, (info_btn.x - 10, 0))
                update_draw()
                infoSelected_drawn = False

        # Replay button
        if replayBtn_x + replayBtn_w > mousePos[
                0] > replayBtn_x and replayBtn_y + replayBtn_h > mousePos[
                    1] > replayBtn_y and replay:
            if clicked:
                sort_done = False
                bubblesort_run(runSpeed, listLength, True)
                return 'end'

        if event.type == pygame.QUIT: pygame.quit()
Exemplo n.º 2
0
def moreSelection(sort):
    global scroll_y, helpPage_drawn
    frame = sort.frame
    mousePos = pygame.mouse.get_pos()

    infoSelected_drawn = False
    historySelected_drawn = False

    # Drawn the moreSelection page
    if helpPage_drawn:
        setup()
        window.blit(optionBackground_image, (0, 0))
    window.blit(sort.more_btn, frame)

    # While cursor in box
    while frame[0]+sortingBoxes_size_w > mousePos[0] > frame[0] and frame[1]+sortingBoxes_size_h+scroll_y > mousePos[1] > frame[1]+scroll_y:
        clicked = False

        for event in pygame.event.get():
            # Check for left click
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    clicked = True
                else:
                    clicked = False
            else:
                clicked = False

            # Cursor over info_btn
            if frame[0]+infoBtn_x+infoBtn_w > mousePos[0] > frame[0]+infoBtn_x and frame[1]+infoBtn_y+infoBtn_h+scroll_y > mousePos[1] > frame[1]+infoBtn_y+scroll_y:
                if not infoSelected_drawn:
                    window.blit(infoSelected_btn,
                                (frame[0]+moreFrame_x, frame[1]+moreFrame_y))
                    infoSelected_drawn = True
                # Open infomation page
                if clicked:
                    information_run(sort.name)
            else:
                if infoSelected_drawn:
                    window.blit(sort.more_btn, frame)
                    infoSelected_drawn = False

            # Cursor over history_btn
            if frame[0]+historyBtn_x+historyBtn_w > mousePos[0] > frame[0]+historyBtn_x and frame[1]+historyBtn_y+historyBtn_h+scroll_y > mousePos[1] > frame[1]+historyBtn_y+scroll_y:
                if not historySelected_drawn:
                    window.blit(historySelected_btn,
                                (frame[0]+moreFrame_x, frame[1]+moreFrame_y))
                    historySelected_drawn = True
                # Open history page
                if clicked:
                    history_run(sort.name)
            else:
                if historySelected_drawn:
                    window.blit(sort.more_btn, frame)
                    historySelected_drawn = False

            # If click out of moreFrame
            if not(frame[0]+moreFrame_x+moreFrame_w > mousePos[0] > frame[0]+moreFrame_x and frame[1]+moreFrame_y+moreFrame_h+scroll_y > mousePos[1] > frame[1]+moreFrame_y+scroll_y) and clicked:
                # Show back config page
                if helpPage_drawn:
                    setup()
                    window.blit(optionBackground_image, (0, 0))
                showConfig(sort)
                return True
            scroll(event)

        mousePos = pygame.mouse.get_pos()