0

I made a menu where you can select options with the keyboard and mouse. The problem is that when I hover an option with the mouse, the option above is selected. To select the bottom option I have to hover outside (under) the menu, so it's not an array index issue but a mouse coordinates issue or something similar.

The font I used: Klein Headline Bold Oblique

Size: 50

Range: 32...255

CREATE EVENT

//#macro SAVEFILE "Save.dat"

gui_width = display_get_gui_width();
gui_height = display_get_gui_height();
gui_margin = 32;
menu_x = gui_width + 400;
menu_y = gui_height - gui_margin;
menu_x_target = gui_width - gui_margin;
menu_speed = 25;
menu_font = fnt_menu;
menu_itemHeight = font_get_size(fnt_menu);
menu_committed = -1;
menu_control = true;

menu[2] = "New game"
menu[1] = "Continue"
menu[0] = "Exit"

menu_items = array_length(menu);
menu_cursor = 2;

menu_top = menu_y - ((menu_itemHeight * 1.5) * menu_items)

DRAW GUI

draw_set_font(menu_font);

draw_set_halign(fa_right);
draw_set_valign(fa_bottom);

for (var i = 0; i < menu_items; i++) {
    var offset = 2;
    var txt = menu[i];
    if(menu_cursor == i){
        txt = string_insert("- ",txt,0);
        var col = c_white;
    }
    else {
        var col = c_gray;
    }
    var xx = menu_x;
    var yy = menu_y - (menu_itemHeight * (i * 1.5));
    draw_set_color(c_black);
    draw_text(xx-offset,yy,txt);
    draw_text(xx+offset,yy,txt);
    draw_text(xx,yy+offset,txt);
    draw_text(xx,yy-offset,txt);
    draw_set_color(col);
    draw_text(xx,yy,txt);
}

STEP EVENT

menu_x += (menu_x_target - menu_x) / menu_speed;

if (menu_control) {
    if(keyboard_check_pressed(vk_up)){
        menu_cursor++;
        if (menu_cursor >= menu_items) menu_cursor = 0;
    }
    if(keyboard_check_pressed(vk_down)){
        menu_cursor--;
        if (menu_cursor < 0) menu_cursor = menu_items - 1;
    }
    if(keyboard_check_pressed(vk_enter)){
        menu_x_target = gui_width + 200;
        menu_committed = menu_cursor;
        //scr_screenShake(4,30);
        menu_control = false;
        //audio_play_sound(sn_hit,10,false);
    }
    var mouse_y_gui = device_mouse_y_to_gui(0);
    var mouse_x_gui = (device_mouse_x_to_gui(0) + 450);
    if (mouse_y_gui < menu_y) && (mouse_y_gui > menu_top) && (mouse_x_gui > menu_x){
        //Here I calculate what option should be highlighted
        menu_cursor = (menu_y - mouse_y_gui) div (menu_itemHeight * 1.5);
        if (mouse_check_button_pressed(mb_left)){
            menu_x_target = gui_width + 200;
            menu_committed = menu_cursor;
            //scr_screenShake(4,30);
            menu_control = false;
            //audio_play_sound(sn_hit,10,false);
        }
    }
}

I found out this only happens when the font size is 50. 51 or 49 (or others) do not behave that way, but the expected way.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
MrJant
  • 27
  • 6

0 Answers0