Пример #1
0
/**
 * Handle mouse events for one list. Checking whether the mouse is over
 * the list should have been done before calling this.
 * @param list
 * The list.
 * @param event
 * Event.
 * @return
 * 1 if the event was handled, 0 otherwise.
 */
int list_handle_mouse(list_struct *list, SDL_Event *event)
{
    uint32_t row, col, old_highlighted, old_selected;
    int mx, my;

    if (!list) {
        return 0;
    }

    if (event->type != SDL_MOUSEBUTTONDOWN && event->type != SDL_MOUSEBUTTONUP && event->type != SDL_MOUSEMOTION) {
        return 0;
    }

    mx = event->motion.x - list->px;
    my = event->motion.y - list->py;

    if (list->scrollbar_enabled) {
        list->scrollbar.px = list->px;
        list->scrollbar.py = list->py;

        if (scrollbar_event(&list->scrollbar, event)) {
            return 1;
        }
    }

    if (!LIST_MOUSE_OVER(list, mx, my)) {
        return 0;
    }

    old_highlighted = list->row_highlighted;
    old_selected = list->row_selected;

    /* No row is highlighted now. Will be switched back on as needed
     * below. */
    list->row_highlighted = 0;

    if (list_mouse_get_pos(list, event->motion.x, event->motion.y, &row, &col)) {
        if (list->handle_mouse_row_func) {
            list->handle_mouse_row_func(list, row, event);
        }

        /* Mouse click? */
        if (event->type == SDL_MOUSEBUTTONDOWN && event->button.button == SDL_BUTTON_LEFT) {
            /* See if we clicked on this row earlier, and whether this
             * should be considered a double click. */
            if (SDL_GetTicks() - list->click_tick < DOUBLE_CLICK_DELAY) {
                /* Double click, handle it as if enter was used. */
                if (list->handle_enter_func) {
                    list->handle_enter_func(list, event);
                    list->click_tick = 0;
                }

                /* Update selected row (in case enter handling
                 * function did not actually jump to another GUI,
                 * thus removing the need for this list). */
                list->row_selected = row + 1;
            } else { /* Normal click. */
                /* Update selected row and click ticks for above
                 * double click calculation. */
                list->row_selected = row + 1;
                list->click_tick = SDL_GetTicks();
            }
        } else {
            /* Not a mouse click, so update highlighted row. */
            list->row_highlighted = row + 1;
        }
    }

    /* Handle mouse wheel for scrolling. */
    if (event->type == SDL_MOUSEBUTTONDOWN && (event->button.button == SDL_BUTTON_WHEELUP || event->button.button == SDL_BUTTON_WHEELDOWN)) {
        list_scroll(list, event->button.button == SDL_BUTTON_WHEELUP, 1);
        return 1;
    }

    if (old_highlighted != list->row_highlighted || old_selected != list->row_selected) {
        return 1;
    }

    return 0;
}
Пример #2
0
/**
 * Handle event in the main screen.
 * @param event
 * The event to handle.
 * @return
 * 1 if the event was handled, 0 otherwise.
 */
int intro_event(SDL_Event *event)
{
    if (!list_servers) {
        return 0;
    }

    if (event->type == SDL_MOUSEBUTTONDOWN && event->button.button == SDL_BUTTON_LEFT) {
        if (LIST_MOUSE_OVER(list_news, event->motion.x, event->motion.y)) {
            list_news->focus = 1;
            list_servers->focus = 0;
        } else if (LIST_MOUSE_OVER(list_servers, event->motion.x, event->motion.y)) {
            list_servers->focus = 1;
            list_news->focus = 0;
        }
    }

    if (button_event(&button_play, event)) {
        list_handle_enter(list_servers, event);
        return 1;
    } else if (button_event(&button_refresh, event)) {
        if (!ms_connecting(-1)) {
            cpl.state = ST_META;
        }

        return 1;
    } else if (button_event(&button_server, event)) {
        server_add_open();
        return 1;
    } else if (button_event(&button_settings, event)) {
        settings_open();
        return 1;
    } else if (button_event(&button_update, event)) {
        updater_open();
        return 1;
    } else if (button_event(&button_help, event)) {
        help_show("main screen");
        return 1;
    } else if (button_event(&button_credits, event)) {
        credits_show();
        return 1;
    } else if (button_event(&button_quit, event)) {
        exit(0);
        return 1;
    } else if (event->type == SDL_KEYDOWN && event->key.keysym.sym == SDLK_TAB && list_news) {
        int news_focus = 0;

        if (list_servers->focus) {
            news_focus = 1;
        }

        list_news->focus = news_focus;
        list_servers->focus = !news_focus;
    } else if (list_handle_keyboard(list_news && list_news->focus ? list_news : list_servers, event)) {
        return 1;
    } else if (list_handle_mouse(list_news, event)) {
        return 1;
    } else if (list_handle_mouse(list_servers, event)) {
        return 1;
    }

    return 0;
}