Ejemplo n.º 1
0
/** @copydoc widgetdata::event_func */
static int widget_event(widgetdata *widget, SDL_Event *event)
{
    network_graph_widget_t *network_graph = widget->subwidget;
    network_graph_data_t *data = &network_graph->data[network_graph->type];

    if (event->type == SDL_MOUSEMOTION) {
        int x = event->motion.x - widget->x;
        if (x < 0 || x >= widget->w) {
            return 0;
        }

        char buf[HUGE_BUF];
        snprintf(VS(buf), "Maximum: %" PRIu64 " Bytes/s (%" PRIu64 " kB/s)",
                (uint64_t) data->max, (uint64_t) data->max / 1000);

        for (int i = 0; i < NETWORK_GRAPH_TRAFFIC_MAX; i++) {
            size_t bytes = data->data[x * NETWORK_GRAPH_TRAFFIC_MAX + i];
            snprintfcat(VS(buf), "\n%s: %" PRIu64 " Bytes/s (%" PRIu64 " kB/s)",
                    network_graph_filters[i], (uint64_t) bytes,
                    (uint64_t) bytes / 1000);
        }

        tooltip_create(event->motion.x, event->motion.y, FONT_ARIAL11, buf);
        tooltip_multiline(200);
        tooltip_enable_delay(100);
    }

    return 0;
}
Ejemplo n.º 2
0
/** @copydoc popup_struct::event_func */
static int popup_event_func(popup_struct *popup, SDL_Event *event)
{
    if (scrollbar_event(&scrollbar, event)) {
        return 1;
    }

    if (book_help_history_enabled &&
            BUTTON_CHECK_TOOLTIP(&popup->button_left.button)) {
        tooltip_create(event->motion.x, event->motion.y, FONT_ARIAL11,
                "Go back");
        tooltip_enable_delay(300);
    }

    /* Mouse event and the mouse is inside the book. */
    if (event->type == SDL_MOUSEBUTTONDOWN && event->motion.x >= popup->x && event->motion.x < popup->x + popup->surface->w && event->motion.y >= popup->y && event->motion.y < popup->y + popup->surface->h) {
        /* Scroll the book. */
        if (event->button.button == SDL_BUTTON_WHEELDOWN) {
            scrollbar_scroll_adjust(&scrollbar, 1);
            return 1;
        } else if (event->button.button == SDL_BUTTON_WHEELUP) {
            scrollbar_scroll_adjust(&scrollbar, -1);
            return 1;
        }
    } else if (event->type == SDL_KEYDOWN) {
        /* Scrolling. */
        if (event->key.keysym.sym == SDLK_DOWN) {
            scrollbar_scroll_adjust(&scrollbar, 1);
            return 1;
        } else if (event->key.keysym.sym == SDLK_UP) {
            scrollbar_scroll_adjust(&scrollbar, -1);
            return 1;
        } else if (event->key.keysym.sym == SDLK_PAGEDOWN) {
            scrollbar_scroll_adjust(&scrollbar, book_scroll_lines);
            return 1;
        } else if (event->key.keysym.sym == SDLK_PAGEUP) {
            scrollbar_scroll_adjust(&scrollbar, -book_scroll_lines);
            return 1;
        }
    }

    return -1;
}