/** @copydoc popup_struct::draw_post_func */ static int popup_draw_post_func(popup_struct *popup) { scrollbar_show(&scrollbar, ScreenSurface, popup->x + BOOK_SCROLLBAR_STARTX, popup->y + BOOK_SCROLLBAR_STARTY); surface_show(ScreenSurface, popup->x, popup->y, NULL, TEXTURE_CLIENT("book_border")); return 1; }
/** * 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]; } } }
/** @copydoc widgetdata::draw_func */ static void widget_draw(widgetdata *widget) { SDL_Rect box; char buf[HUGE_BUF]; size_t i; /* The list doesn't exist yet, create it. */ if (!list_mplayer) { char version[MAX_BUF]; /* Create the list and set up settings. */ list_mplayer = list_create(12, 1, 8); list_mplayer->handle_enter_func = list_handle_enter; list_mplayer->text_color_hook = list_text_color_hook; list_mplayer->surface = widget->surface; list_scrollbar_enable(list_mplayer); list_set_column(list_mplayer, 0, 130, 7, NULL, -1); list_set_font(list_mplayer, FONT_ARIAL10); /* Add default media directory songs. */ get_data_dir_file(buf, sizeof(buf), DIRECTORY_MEDIA); mplayer_list_init(list_mplayer, buf, 0); /* Now add custom ones, but ignore duplicates. */ snprintf(buf, sizeof(buf), "%s/.atrinik/%s/"DIRECTORY_MEDIA, get_config_dir(), package_get_version_partial(version, sizeof(version))); mplayer_list_init(list_mplayer, buf, 1); /* If we added any, sort the list alphabetically and add an entry * to disable background music. */ if (list_mplayer->rows) { FILE *fp; /* Allocate the blacklist. + 1 is for the last entry added * further down. It is not actually used by the blacklist as * it's not possible to toggle it on/off using the button, but * it simplifies other logic checks. */ shuffle_blacklist = ecalloc(1, sizeof(*shuffle_blacklist) * (list_mplayer->rows + 1)); /* Sort the list. */ list_sort(list_mplayer, LIST_SORT_ALPHA); /* Read the blacklist file contents. */ fp = path_fopen(FILE_MPLAYER_BLACKLIST, "r"); if (fp) { size_t row; while (fgets(buf, sizeof(buf) - 1, fp)) { for (row = 0; row < list_mplayer->rows; row++) { if (!strncmp(buf, list_mplayer->text[row][0], strlen(buf) - 1)) { shuffle_blacklist[row] = 1; break; } } } fclose(fp); } list_add(list_mplayer, list_mplayer->rows, 0, "Disable music"); } scrollbar_create(&scrollbar_progress, 130, 11, &scrollbar_progress_info.scroll_offset, &scrollbar_progress_info.num_lines, 1); scrollbar_progress.redraw = &scrollbar_progress_info.redraw; } if (widget->redraw) { const char *bg_music; box.h = 0; box.w = widget->w; text_show(widget->surface, FONT_SERIF12, "Music Player", 0, 3, COLOR_HGOLD, TEXT_ALIGN_CENTER, &box); list_set_parent(list_mplayer, widget->x, widget->y); list_show(list_mplayer, 10, 2); box.w /= 2; text_show(widget->surface, FONT_SANS10, "Currently playing:", widget->w / 2, 22, COLOR_WHITE, TEXT_ALIGN_CENTER, &box); bg_music = sound_get_bg_music_basename(); box.h = 0; box.w = widget->w / 2; /* Store the background music file name in temporary buffer and * make sure it won't overflow by truncating it if necessary. */ if (bg_music) { strncpy(buf, bg_music, sizeof(buf) - 1); buf[sizeof(buf) - 1] = '\0'; text_truncate_overflow(FONT_SANS11, buf, 150); } /* Show the music that is being played. */ text_show(widget->surface, FONT_SANS11, bg_music ? buf : "No music", widget->w / 2 - 5, 34, COLOR_HGOLD, TEXT_ALIGN_CENTER, &box); scrollbar_progress.px = widget->x; scrollbar_progress.py = widget->y; scrollbar_show(&scrollbar_progress, widget->surface, 170, 50); box.h = 120; box.w -= 6 * 2; text_show(widget->surface, FONT_ARIAL10, "You can use the music player to play your favorite tunes from the game, or play them all one-by-one in random order (shuffle).\n\nNote that if you use the music player, in-game areas won't change your music until you click [b]Stop[/b].", widget->w / 2 + 6, 62, COLOR_WHITE, TEXT_WORD_WRAP | TEXT_MARKUP, &box); for (i = 0; i < BUTTON_NUM; i++) { buttons[i].surface = widget->surface; button_set_parent(&buttons[i], widget->x, widget->y); } buttons[BUTTON_PLAY].x = 10; buttons[BUTTON_PLAY].y = widget->h - TEXTURE_CLIENT("button")->h - 4; button_show(&buttons[BUTTON_PLAY], sound_map_background(-1) ? "Stop" : "Play"); buttons[BUTTON_SHUFFLE].x = 10 + TEXTURE_CLIENT("button")->w + 5; buttons[BUTTON_SHUFFLE].y = widget->h - TEXTURE_CLIENT("button")->h - 4; buttons[BUTTON_SHUFFLE].pressed_forced = shuffle; button_show(&buttons[BUTTON_SHUFFLE], "Shuffle"); buttons[BUTTON_BLACKLIST].x = 10 + TEXTURE_CLIENT("button")->w * 2 + 5 * 2; buttons[BUTTON_BLACKLIST].y = widget->h - TEXTURE_CLIENT("button_round")->h - 5; buttons[BUTTON_BLACKLIST].disabled = list_mplayer->row_selected == list_mplayer->rows; button_show(&buttons[BUTTON_BLACKLIST], mplayer_blacklisted(list_mplayer) ? "+" : "-"); /* Show close button. */ buttons[BUTTON_CLOSE].x = widget->w - TEXTURE_CLIENT("button_round")->w - 4; buttons[BUTTON_CLOSE].y = 4; button_show(&buttons[BUTTON_CLOSE], "X"); /* Show help button. */ buttons[BUTTON_HELP].x = widget->w - TEXTURE_CLIENT("button_round")->w * 2 - 4; buttons[BUTTON_HELP].y = 4; button_show(&buttons[BUTTON_HELP], "?"); } }