aboutsummaryrefslogtreecommitdiff
path: root/game/menu.cpp
blob: 76913b59375504fdd38928d9abe212d80d8aacd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "menu.h"

void Menu::close () {
    active = false;
}

void Menu::open (vec2 res) {
    active = true;
    pos = vec2 { (float)res.x, (float)res.y };
    float height = options.size() * 20;
    size = vec2 { 120, height+10 };
    pos *= 0.5f;
    pos -= size/2;
}

int Menu::mouse_option (vec2 mouse) {
    int i=0;
    for (Option opt : options) {
        vec2 off { 10, 10.0f + i*20 };
        vec2 sizeopt { 100, 20 };
        off += pos;
        if (off.x < mouse.x && mouse.x < off.x+sizeopt.x 
        && off.y < mouse.y && mouse.y < off.y+sizeopt.y ) {
            return opt.id;
        }
        i++;
    }
    return -1;
}