Ejemplo n.º 1
0
int list_mouse_get_pos(list_struct *list, int mx, int my, uint32_t *row, uint32_t *col)
{
    uint32_t w;

    mx -= list->px;
    my -= list->py;

    /* See which row the mouse is over. */
    for (*row = list->row_offset; *row < list->rows; (*row)++) {
        /* Stop if we reached maximum number of visible rows. */
        if (LIST_ROW_OFFSET(*row, list) == list->max_rows) {
            break;
        }

        /* Is the mouse over this row? */
        if ((uint32_t) my >= (LIST_ROWS_START(list) + LIST_ROW_OFFSET(*row, list) * LIST_ROW_HEIGHT(list)) && (uint32_t) my < LIST_ROWS_START(list) + (LIST_ROW_OFFSET(*row, list) + 1) * LIST_ROW_HEIGHT(list)) {
            w = 0;

            for (*col = 0; *col < list->cols; (*col)++) {
                if ((uint32_t) mx >= list->x + list->frame_offset + w && (uint32_t) mx < list->x + list->frame_offset + w + list->col_widths[*col] + list->col_spacings[*col]) {
                    return 1;
                }

                w += list->col_widths[*col] + list->col_spacings[*col];
            }
        }
    }

    return 0;
}
Ejemplo n.º 2
0
/** @copydoc list_struct::post_column_func */
static void list_post_column(list_struct *list, uint32_t row, uint32_t col)
{
    size_t skill_id;
    SDL_Rect box;

    skill_id = row * list->cols + col;

    if (skill_id >= skill_list_num) {
        return;
    }

    if (!FaceList[skill_list[skill_id]->skill->face].sprite) {
        return;
    }

    box.x = list->x + list->frame_offset + INVENTORY_ICON_SIZE * col;
    box.y = LIST_ROWS_START(list) + (LIST_ROW_OFFSET(row, list) * LIST_ROW_HEIGHT(list));
    box.w = INVENTORY_ICON_SIZE;
    box.h = INVENTORY_ICON_SIZE;

    surface_show(list->surface, box.x, box.y, NULL, FaceList[skill_list[skill_id]->skill->face].sprite->bitmap);

    if (selected_skill != skill_id) {
        return;
    }
    border_create_color(list->surface, &box, 1, "ff0000");

    char buf[MAX_BUF];
    snprintf(VS(buf), "%s", skill_list[skill_id]->skill->s_name);
    string_title(buf);

    box.w = 160;
    text_show(list->surface,
              FONT_SERIF12,
              buf,
              150,
              18,
              COLOR_HGOLD,
              TEXT_ALIGN_CENTER | TEXT_OUTLINE,
              &box);

    box.h = 100;
    text_show(list->surface,
              FONT_ARIAL11,
              skill_list[skill_id]->msg,
              150,
              38,
              COLOR_WHITE,
              TEXT_WORD_WRAP,
              &box);

    if (skill_list[skill_id]->level == 0) {
        return;
    }

    widgetdata *widget = widget_find(NULL, -1, NULL, list->surface);
    SOFT_ASSERT(widget != NULL, "Could not find widget");

    text_show(list->surface, FONT("arial", 10), "[b]Experience[/b]", 167, widget->h - 47, COLOR_WHITE, TEXT_MARKUP, NULL);
    player_draw_exp_progress(list->surface, 160, widget->h - 32, skill_list[skill_id]->exp, skill_list[skill_id]->level);

    box.h = 30;
    box.w = 35;
    text_show(list->surface,
              FONT("arial", 10),
              "[b]Level[/b]",
              widget->w - 45,
              widget->h - 47,
              COLOR_WHITE,
              TEXT_MARKUP | TEXT_ALIGN_CENTER,
              &box);
    text_show_format(list->surface,
                     FONT_SERIF18,
                     widget->w - 45,
                     widget->h - 30,
                     COLOR_HGOLD,
                     TEXT_MARKUP | TEXT_OUTLINE | TEXT_ALIGN_CENTER,
                     &box,
                     "%" PRIu8,
                     skill_list[skill_id]->level);
}
Ejemplo n.º 3
0
/**
 * Draw a frame in which the rows will be drawn.
 * @param list
 * List to draw the frame for.
 */
static void list_draw_frame(list_struct *list)
{
    draw_frame(list->surface, list->x + list->frame_offset, LIST_ROWS_START(list), list->width, LIST_ROWS_HEIGHT(list));
}
Ejemplo n.º 4
0
/**
 * Show one list.
 * @param list
 * List to show.
 * @param x
 * X position.
 * @param y
 * Y position.
 */
void list_show(list_struct *list, int x, int y)
{
    uint32_t row, col;
    int w = 0, extra_width = 0;
    SDL_Rect box;

    if (!list) {
        return;
    }

    list->x = x;
    list->y = y;

    /* Draw a frame, if needed. */
    if (list->draw_frame_func) {
        list->draw_frame_func(list);
    }

    /* Draw the column names. */
    for (col = 0; col < list->cols; col++) {
        extra_width = 0;

        /* Center it? */
        if (list->col_centered[col]) {
            extra_width = list->col_widths[col] / 2 - text_get_width(list->font, list->col_names[col], 0) / 2;
        }

        /* Actually draw the column name. */
        if (list->col_names[col]) {
            text_show_shadow(list->surface, list->font, list->col_names[col], list->x + w + extra_width, list->y, list->focus ? COLOR_WHITE : COLOR_GRAY, COLOR_BLACK, 0, NULL);
        }

        w += list->col_widths[col] + list->col_spacings[col];
    }

    /* Initialize default values for coloring rows. */
    box.x = list->x + list->frame_offset;
    box.w = list->width;
    box.h = LIST_ROW_HEIGHT(list);

    if (list->scrollbar_enabled) {
        scrollbar_show(&list->scrollbar, list->surface, list->x + list->frame_offset + 1 + w, LIST_ROWS_START(list));
    }

    /* Doing coloring of each row? */
    if (list->row_color_func) {
        for (row = 0; row < list->max_rows; row++) {
            box.y = LIST_ROWS_START(list) + (row * LIST_ROW_HEIGHT(list));
            list->row_color_func(list, row, box);
        }
    }

    /* Start printing out rows from the offset to the maximum. */
    for (row = list->row_offset; row < list->rows; row++) {
        /* Stop if we reached maximum number of visible rows. */
        if (LIST_ROW_OFFSET(row, list) == list->max_rows) {
            break;
        }

        if (list->row_selected_func && (row + 1) == list->row_selected) {
            /* Color selected row. */
            box.y = LIST_ROWS_START(list) + (LIST_ROW_OFFSET(row, list) * LIST_ROW_HEIGHT(list));
            list->row_selected_func(list, box);
        } else if (list->row_highlight_func && (row + 1) == list->row_highlighted) {
            /* Color highlighted row. */
            box.y = LIST_ROWS_START(list) + (LIST_ROW_OFFSET(row, list) * LIST_ROW_HEIGHT(list));
            list->row_highlight_func(list, box);
        }

        w = 0;

        /* Show all the columns. */
        for (col = 0; col < list->cols; col++) {
            /* Is there any text to show? */
            if (list->text[row][col] && list->font != NULL) {
                const char *text_color, *text_color_shadow;
                SDL_Rect text_rect;

                extra_width = 0;

                /* Center it. */
                if (list->col_centered[col]) {
                    extra_width = list->col_widths[col] / 2 - text_get_width(list->font, list->text[row][col], TEXT_WORD_WRAP) / 2;
                }

                text_color = list->focus ? COLOR_WHITE : COLOR_GRAY;
                text_color_shadow = COLOR_BLACK;

                if (list->text_color_hook) {
                    list->text_color_hook(list, row, col, &text_color, &text_color_shadow);
                }

                /* Add width limit on the string. */
                text_rect.x = list->x + w + extra_width;
                text_rect.y = LIST_ROWS_START(list) + (LIST_ROW_OFFSET(row, list) * LIST_ROW_HEIGHT(list));
                text_rect.w = list->col_widths[col] + list->col_spacings[col];
                text_rect.h = LIST_ROW_HEIGHT(list);

                /* Output the text. */
                if (text_color_shadow) {
                    text_show_shadow(list->surface, list->font, list->text[row][col], text_rect.x, text_rect.y, text_color, text_color_shadow, TEXT_WORD_WRAP | list->text_flags, &text_rect);
                } else if (text_color) {
                    text_show(list->surface, list->font, list->text[row][col], text_rect.x, text_rect.y, text_color, TEXT_WORD_WRAP | list->text_flags, &text_rect);
                }
            }

            if (list->post_column_func) {
                list->post_column_func(list, row, col);
            }

            w += list->col_widths[col] + list->col_spacings[col];
        }
    }
}