// File: /workspace/github_cpp_makefile_star2_O2/KellerMartins[P]PDS2-Pacman/source/main.cpp
// Function: OpenConfigWindow()
bool OpenConfigWindow(){ 
    #ifdef NDEBUG
    SetTraceLog(0);
    #endif
    
    SetConfigFlags(FLAG_MSAA_4X_HINT);
    InitWindow(575, 110, "Opções | Pacman Remake - PDS2");
    
    Font font = LoadFont("assets/interface/metropolis/Metropolis.fnt");
    SetTextureFilter(font.texture, FILTER_TRILINEAR);

    int resolution = 3;
    while(1){
        if(WindowShouldClose()){
            //Fecha a janela
            CloseWindow();
            return false;
        }

        //Define os retângulos dos botões da janela
        Rectangle play = { 430, 10, 135, 90 };
        Rectangle fullscr = { 175, 75, 240, 27 };
        Rectangle previousRes = { 175, 5, 20, 30 };
        Rectangle nextRes = { 405, 5, 20, 30 };
        Rectangle previousQual = { 175, 40, 20, 30 };
        Rectangle nextQual = { 405, 40, 20, 30 };

        bool clicked = IsMouseButtonPressed(MOUSE_LEFT_BUTTON);

        //Checa se clicou em um deles ou apertou a tecla correspondente ao comando
        if((CheckCollisionPointRec(GetMousePosition(), previousRes) && clicked) ||  IsKeyReleased(KEY_LEFT))
            resolution -= resolution-1>=0? 1:0;
        
        if((CheckCollisionPointRec(GetMousePosition(), nextRes) && clicked) ||  IsKeyReleased(KEY_RIGHT))
            resolution += resolution+1<=3? 1:0;

        if(CheckCollisionPointRec(GetMousePosition(), previousQual) && clicked)
            quality = (RenderManager::BlurQuality) (quality-1>=0? quality-1:quality);
        
        if(CheckCollisionPointRec(GetMousePosition(), nextQual) && clicked)
            quality = (RenderManager::BlurQuality) (quality+1<=2? quality+1:quality);
        
        if(CheckCollisionPointRec(GetMousePosition(), fullscr) && clicked)
            fullscreen = !fullscreen;
        
        if((CheckCollisionPointRec(GetMousePosition(), play) && clicked) ||  IsKeyReleased(KEY_ENTER))
            break; //Termina o loop da tela de configuraçoes
        
        //Define a resolução a ser usada
        switch(resolution){
            case 3:
                width = 1920;
                height = 1080;
            break;
            case 2:
                width = 1366;
                height = 768;
            break;
            case 1:
                width = 1280;
                height = 720;
            break;
            case 0:
            default:
                width = 800;
                height = 450;
            break;
        }
        
        //> Renderização
        BeginDrawing();

        //Define a cor de fundo
        Color settingsCol = {255,191,0,255};
        ClearBackground({35,45,60,255});
        //Renderiza o texto
        DrawTextEx(font,"Resolução", (Vector2){5,5}, 30, 1, RAYWHITE); 
        DrawTextEx(font,FormatText("%4d x %4d",width,height),(Vector2){195, 5}, 33,2, settingsCol); 

        const char* qualityString = quality==2 ?" Alta " : (quality==1? "Média" : "Baixa ");
        DrawTextEx(font,"Qualidade", (Vector2){5,40}, 30, 1, RAYWHITE); 
        DrawTextEx(font, qualityString, (Vector2){255, 40}, 33, 2, settingsCol); 

        DrawTextEx(font,"Tela cheia", (Vector2){5, 75}, 30, 1, RAYWHITE); 
        DrawTextEx(font, fullscreen? "   Ativado" : "Desativado", (Vector2){205, 75}, 33, 2, settingsCol); 
        
        //Renderiza o botão de jogar
        DrawRectangleRec(play, {255,191,0,255});
        DrawTextEx(font, "Jogar!",(Vector2){455, 40}, 30, 0, WHITE); 
        
        //Renderiza as setas de resolução
        DrawTextEx(font,"<",(Vector2){175, 5}, 33, 2, resolution>0? settingsCol : (Color)DARKGRAY); 
        DrawTextEx(font,">",(Vector2){403, 5}, 33, 2, resolution<3? settingsCol : (Color)DARKGRAY);

        //Renderiza as setas de qualidade
        DrawTextEx(font,"<",(Vector2){175, 40}, 33, 2, quality>0? settingsCol : (Color)DARKGRAY); 
        DrawTextEx(font,">",(Vector2){403, 40}, 33, 2, quality<2? settingsCol : (Color)DARKGRAY);
           
        EndDrawing();
    }
    //Fecha a janela de configurações
    CloseWindow();

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
pushq $0x20
popq %rdi
callq 0x2ec65
leaq 0x8eaa6(%rip), %rdx     # 0x98140
pushq $0x6e
popq %rsi
movl $0x23f, %edi            # imm = 0x23F
callq 0x2c99d
leaq 0x8eab2(%rip), %rsi     # 0x98160
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x5af4d
movl 0x10(%rbx), %eax
movl %eax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
pushq $0x2
popq %rdi
callq 0x76473
pushq $0x3
popq %rbx
movl $0xff00bfff, %r14d      # imm = 0xFF00BFFF
leaq 0x8eb0a(%rip), %r15     # 0x981ea
callq 0x2cabd
movl %eax, %r12d
testb %al, %al
jne 0x9bf2
xorl %edi, %edi
callq 0x2f770
movl %eax, %r13d
callq 0x2f8af
movsd 0x8e909(%rip), %xmm1    # 0x98010
movsd 0x8e911(%rip), %xmm2    # 0x98020
callq 0x4abb9
testb %r13b, %al
jne 0x9727
movl $0x107, %edi            # imm = 0x107
callq 0x2f330
testb %al, %al
je 0x9730
xorl %eax, %eax
testl %ebx, %ebx
setg %al
subl %eax, %ebx
callq 0x2f8af
movsd 0x8e8f3(%rip), %xmm1    # 0x98030
movsd 0x8e8db(%rip), %xmm2    # 0x98020
callq 0x4abb9
testb %r13b, %al
jne 0x975d
movl $0x106, %edi            # imm = 0x106
callq 0x2f330
testb %al, %al
je 0x9767
xorl %eax, %eax
cmpl $0x3, %ebx
setl %al
addl %eax, %ebx
callq 0x2f8af
movsd 0x8e8cc(%rip), %xmm1    # 0x98040
movsd 0x8e8a4(%rip), %xmm2    # 0x98020
callq 0x4abb9
andb %r13b, %al
cmpb $0x1, %al
jne 0x979d
movl 0xcd0aa(%rip), %eax     # 0xd6838
xorl %ecx, %ecx
testl %eax, %eax
setg %cl
subl %ecx, %eax
movl %eax, 0xcd09b(%rip)     # 0xd6838
callq 0x2f8af
movsd 0x8e8a6(%rip), %xmm1    # 0x98050
movsd 0x8e86e(%rip), %xmm2    # 0x98020
callq 0x4abb9
andb %r13b, %al
cmpb $0x1, %al
jne 0x97d4
movl 0xcd074(%rip), %eax     # 0xd6838
xorl %ecx, %ecx
cmpl $0x2, %eax
setl %cl
addl %eax, %ecx
movl %ecx, 0xcd064(%rip)     # 0xd6838
callq 0x2f8af
movsd 0x8e87f(%rip), %xmm1    # 0x98060
movsd 0x8e887(%rip), %xmm2    # 0x98070
callq 0x4abb9
andb %r13b, %al
cmpb $0x1, %al
jne 0x97fc
xorb $0x1, 0xcf625(%rip)     # 0xd8e21
callq 0x2f8af
movsd 0x8e877(%rip), %xmm1    # 0x98080
movsd 0x8e87f(%rip), %xmm2    # 0x98090
callq 0x4abb9
testb %r13b, %al
jne 0x9bf2
movl $0x101, %edi            # imm = 0x101
callq 0x2f330
testb %al, %al
jne 0x9bf2
leal -0x1(%rbx), %eax
cmpl $0x2, %eax
ja 0x9851
movl %eax, %eax
leaq 0x8e9aa(%rip), %rcx     # 0x981ec
movl (%rcx,%rax,4), %ecx
leaq 0x8e9ac(%rip), %rdx     # 0x981f8
movl (%rdx,%rax,4), %eax
jmp 0x985b
movl $0x1c2, %eax            # imm = 0x1C2
movl $0x320, %ecx            # imm = 0x320
movl %ecx, 0xccfcf(%rip)     # 0xd6830
movl %eax, 0xccfcd(%rip)     # 0xd6834
callq 0x2ce22
movl $0xff3c2d23, %edi       # imm = 0xFF3C2D23
callq 0x2cded
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x8e8f4(%rip), %rdi     # 0x9818b
movaps 0x8e802(%rip), %xmm0    # 0x980a0
movss 0x8e88a(%rip), %xmm1    # 0x98130
movss 0x8e886(%rip), %xmm2    # 0x98134
movl $0xfff5f5f5, %esi       # imm = 0xFFF5F5F5
callq 0x5c42f
movq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movaps %xmm1, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movl 0xccf5a(%rip), %esi     # 0xd6830
movl 0xccf58(%rip), %edx     # 0xd6834
leaq 0x8e8b4(%rip), %rdi     # 0x98197
xorl %eax, %eax
callq 0x5c80a
movq -0x60(%rbp), %rcx
movq %rcx, 0x20(%rsp)
movaps -0x80(%rbp), %xmm0
movaps -0x70(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rax, %rdi
movsd 0x8e7a1(%rip), %xmm0    # 0x980b0
movss 0x8e821(%rip), %xmm1    # 0x98138
movss 0x8e81d(%rip), %xmm2    # 0x9813c
movl $0xff00bfff, %esi       # imm = 0xFF00BFFF
callq 0x5c42f
movl 0xccf09(%rip), %eax     # 0xd6838
cmpl $0x1, %eax
leaq 0x8e876(%rip), %r12     # 0x981af
leaq 0x8e868(%rip), %rcx     # 0x981a8
cmoveq %rcx, %r12
cmpl $0x2, %eax
leaq 0x8e853(%rip), %rax     # 0x981a1
cmoveq %rax, %r12
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x8e843(%rip), %rdi     # 0x981b6
movsd 0x8e745(%rip), %xmm0    # 0x980c0
movss 0x8e7ad(%rip), %xmm1    # 0x98130
movss 0x8e7a9(%rip), %xmm2    # 0x98134
movl $0xfff5f5f5, %esi       # imm = 0xFFF5F5F5
callq 0x5c42f
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r12, %rdi
movsd 0x8e716(%rip), %xmm0    # 0x980d0
movss 0x8e776(%rip), %xmm1    # 0x98138
movss 0x8e772(%rip), %xmm2    # 0x9813c
movl $0xff00bfff, %esi       # imm = 0xFF00BFFF
callq 0x5c42f
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x8e7cb(%rip), %rdi     # 0x981c0
movsd 0x8e6e3(%rip), %xmm0    # 0x980e0
movss 0x8e72b(%rip), %xmm1    # 0x98130
movss 0x8e727(%rip), %xmm2    # 0x98134
movl $0xfff5f5f5, %esi       # imm = 0xFFF5F5F5
callq 0x5c42f
cmpb $0x0, 0xcf403(%rip)     # 0xd8e21
leaq 0x8e7b1(%rip), %rdi     # 0x981d6
leaq 0x8e79f(%rip), %rax     # 0x981cb
cmovneq %rax, %rdi
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movsd 0x8e69e(%rip), %xmm0    # 0x980f0
movss 0x8e6de(%rip), %xmm1    # 0x98138
movss 0x8e6da(%rip), %xmm2    # 0x9813c
movl $0xff00bfff, %esi       # imm = 0xFF00BFFF
callq 0x5c42f
movsd 0x8e60c(%rip), %xmm0    # 0x98080
movsd 0x8e614(%rip), %xmm1    # 0x98090
movl $0xff00bfff, %edi       # imm = 0xFF00BFFF
callq 0x49ae9
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
xorps %xmm2, %xmm2
leaq 0x8e737(%rip), %rdi     # 0x981e1
movsd 0x8e64e(%rip), %xmm0    # 0x98100
movss 0x8e676(%rip), %xmm1    # 0x98130
pushq $-0x1
popq %rsi
callq 0x5c42f
testl %ebx, %ebx
movl $0xff505050, %esi       # imm = 0xFF505050
cmovgl %r14d, %esi
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x8e6fa(%rip), %r12     # 0x981e8
movq %r12, %rdi
movsd 0x8e517(%rip), %xmm0    # 0x98010
movss 0x8e637(%rip), %xmm1    # 0x98138
movss 0x8e633(%rip), %xmm2    # 0x9813c
callq 0x5c42f
cmpl $0x3, %ebx
movl $0xff505050, %esi       # imm = 0xFF505050
cmovll %r14d, %esi
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
movsd 0x8e5d1(%rip), %xmm0    # 0x98110
movss 0x8e5f1(%rip), %xmm1    # 0x98138
movss 0x8e5ed(%rip), %xmm2    # 0x9813c
callq 0x5c42f
cmpl $0x0, 0xcccdd(%rip)     # 0xd6838
movl $0xff505050, %esi       # imm = 0xFF505050
cmovgl %r14d, %esi
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r12, %rdi
movsd 0x8e4b7(%rip), %xmm0    # 0x98040
movss 0x8e5a7(%rip), %xmm1    # 0x98138
movss 0x8e5a3(%rip), %xmm2    # 0x9813c
callq 0x5c42f
cmpl $0x2, 0xccc93(%rip)     # 0xd6838
movl $0xff505050, %esi       # imm = 0xFF505050
cmovll %r14d, %esi
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
movsd 0x8e54d(%rip), %xmm0    # 0x98120
movss 0x8e55d(%rip), %xmm1    # 0x98138
movss 0x8e559(%rip), %xmm2    # 0x9813c
callq 0x5c42f
callq 0x2ceea
jmp 0x96e0
callq 0x2ca59
xorb $0x1, %r12b
movl %r12d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq