void text_keypad_thumbscript_draw(GR_GC_ID gc)
{
    char s[2];
    GrLine(text_get_bufwid(), gc, 0, text_get_height()-16, text_get_width(), text_get_height()-16);
    switch (text_keypad_thumbscript_mode) {
    case 1:
        GrText(text_get_bufwid(), gc, text_get_width()/2, text_get_height()-4, "shift", -1, GR_TFASCII);
        break;
    case 3:
    case 2:
    case 4:
    case 5:
    case 6:
        GrText(text_get_bufwid(), gc, text_get_width()/2, text_get_height()-4, "mod", -1, GR_TFASCII);
        break;
    }
    if (text_keypad_thumbscript_last != 0) {
        s[0] = (text_keypad_thumbscript_last + '1');
        s[1] = 0;
        GrText(text_get_bufwid(), gc, (text_get_width()*3)/4, text_get_height()-4, s, -1, GR_TFASCII);
    }
}
Exemple #2
0
/**
 * Render a button.
 * @param button
 * Button to render.
 * @param text
 * Optional text to render.
 */
void button_show(button_struct *button, const char *text)
{
    SDL_Surface *texture;

    (void) button_need_redraw(button);

    if (button->pressed_forced) {
        button->pressed = 1;
    }

    texture = texture_surface(button_determine_texture(button));
    surface_show(button->surface, button->x, button->y, NULL, texture);

    if (text) {
        const char *color, *color_shadow;
        int x, y;

        if (button->disabled) {
            color = COLOR_GRAY;
            color_shadow = COLOR_BLACK;
        } else if (button->mouse_over) {
            color = button->color_over;
            color_shadow = button->color_over_shadow;
        } else {
            color = button->color;
            color_shadow = button->color_shadow;
        }

        x = button->x;
        y = button->y;

        if (button->center) {
            x += texture->w / 2 - text_get_width(button->font, text, button->flags) / 2;
            y += texture->h / 2 - FONT_HEIGHT(button->font) / 2;
        }

        if (!color_shadow) {
            text_show(button->surface, button->font, text, x, y, color, button->flags, NULL);
        } else {
            text_show_shadow(button->surface, button->font, text, x, y - 2, color, color_shadow, button->flags, NULL);
        }
    }

    if (button->repeat_func && button->pressed && SDL_GetTicks() - button->pressed_ticks > button->pressed_repeat_ticks) {
        button->repeat_func(button);
        button->pressed_ticks = SDL_GetTicks();
        button->pressed_repeat_ticks = 150;
    }

    button->redraw = 0;
}
Exemple #3
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];
        }
    }
}