Progressbar seems to work again

This commit is contained in:
Pere Pujal i Carabantes 2015-04-29 00:34:02 +02:00
parent dd4ec4bd2c
commit 58d202d275
7 changed files with 74 additions and 56 deletions

View file

@ -67,7 +67,7 @@
///////////////// directory walking callers and callbacks ////////////////// ///////////////// directory walking callers and callbacks //////////////////
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale) unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale)
{ {
dirlen = dirlen; dirlen = dirlen;
@ -76,7 +76,7 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
{ {
int loadable = 0; int loadable = 0;
const char *restrict const cp = strchr(files[i].str, '.'); const char *restrict const cp = strchr(files[i].str, '.');
show_progress_bar(screen); show_progress_bar_(screen, texture, renderer);
if (cp) if (cp)
{ {
// need gcc 3.4 for the restrict in this location // need gcc 3.4 for the restrict in this location
@ -261,7 +261,7 @@ int compare_ftw_str(const void *v1, const void *v2)
return -strcmp(s1, s2); /* FIXME: Should we try strcasecmp, to group things together despite uppercase/lowercase in filenames (e.g., Jigsaw* vs jigsaw* Starters)??? -bjk 2009.10.11 */ return -strcmp(s1, s2); /* FIXME: Should we try strcasecmp, to group things together despite uppercase/lowercase in filenames (e.g., Jigsaw* vs jigsaw* Starters)??? -bjk 2009.10.11 */
} }
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen, int rsrc, void (*fn) (SDL_Surface * screen,
const char *restrict const dir, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned dirlen, tp_ftw_str * files,
@ -376,7 +376,7 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
} }
closedir(d); closedir(d);
show_progress_bar(screen); show_progress_bar_(screen, texture, renderer);
dir[dirlen] = '\0'; // repair it (clobbered for stat() call above) dir[dirlen] = '\0'; // repair it (clobbered for stat() call above)
if (1 || file_names) // Now ALWAYS calling callback function, so stamp loader can notice top-level directories (even if there are only subdirs, and no files, inside) -bjk 2007.05.16 if (1 || file_names) // Now ALWAYS calling callback function, so stamp loader can notice top-level directories (even if there are only subdirs, and no files, inside) -bjk 2007.05.16
@ -401,7 +401,7 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
{ {
memcpy(dir + dirlen, dir_names[num_dir_names].str, memcpy(dir + dirlen, dir_names[num_dir_names].str,
dir_names[num_dir_names].len + 1); dir_names[num_dir_names].len + 1);
tp_ftw(screen, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn, locale); tp_ftw(screen, texture, renderer, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn, locale);
free(dir_names[num_dir_names].str); free(dir_names[num_dir_names].str);
} }
free(dir_names); free(dir_names);

View file

@ -45,10 +45,10 @@ typedef struct tp_ftw_str
} tp_ftw_str; } tp_ftw_str;
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale); unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale);
int compare_ftw_str(const void *v1, const void *v2); int compare_ftw_str(const void *v1, const void *v2);
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen, int rsrc, void (*fn) (SDL_Surface * screen,
const char *restrict const dir, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned dirlen, tp_ftw_str * files,

View file

@ -927,79 +927,79 @@ static void groupfonts(void)
} }
static void loadfonts_locale_filter(SDL_Surface * screen, const char *const dir, const char *restrict const locale) static void loadfonts_locale_filter(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *const dir, const char *restrict const locale)
{ {
char buf[TP_FTW_PATHSIZE]; char buf[TP_FTW_PATHSIZE];
unsigned dirlen = strlen(dir); unsigned dirlen = strlen(dir);
memcpy(buf, dir, dirlen); memcpy(buf, dir, dirlen);
tp_ftw(screen, buf, dirlen, 1, loadfont_callback, locale); tp_ftw(screen, texture, renderer, buf, dirlen, 1, loadfont_callback, locale);
} }
static void loadfonts(SDL_Surface * screen, const char *const dir) static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *const dir)
{ {
loadfonts_locale_filter(screen, dir, NULL); loadfonts_locale_filter(screen, texture, renderer, dir, NULL);
} }
/* static */ int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale) /* static */ int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, void *vp, const char *restrict const locale)
{ {
char *homedirdir; char *homedirdir;
(void) vp; // junk passed by threading library (void) vp; // junk passed by threading library
loadfonts_locale_filter(screen, DATA_PREFIX "fonts", locale); loadfonts_locale_filter(screen, texture, renderer, DATA_PREFIX "fonts", locale);
if (!no_system_fonts) if (!no_system_fonts)
{ {
#ifdef WIN32 #ifdef WIN32
homedirdir = GetSystemFontDir(); homedirdir = GetSystemFontDir();
loadfonts(screen, homedirdir); loadfonts(screen, texture, renderer, homedirdir);
free(homedirdir); free(homedirdir);
#elif defined(__BEOS__) #elif defined(__BEOS__)
loadfonts(screen, "/boot/home/config/font/ttffonts"); loadfonts(screen, texture, renderer, "/boot/home/config/font/ttffonts");
loadfonts(screen, "/usr/share/fonts"); loadfonts(screen, texture, renderer, "/usr/share/fonts");
loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); loadfonts(screen, texture, renderer, "/usr/X11R6/lib/X11/fonts");
#elif defined(__HAIKU__) #elif defined(__HAIKU__)
dev_t volume = dev_for_path("/boot"); dev_t volume = dev_for_path("/boot");
char buffer[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; char buffer[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH];
status_t result; status_t result;
result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, buffer); loadfonts(screen, texture, renderer, buffer);
result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, buffer); loadfonts(screen, texture, renderer, buffer);
result = find_directory(B_USER_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer)); result = find_directory(B_USER_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, buffer); loadfonts(screen, texture, renderer, buffer);
#elif defined(__APPLE__) #elif defined(__APPLE__)
loadfonts(screen, "/System/Library/Fonts"); loadfonts(screen, texture, renderer, "/System/Library/Fonts");
loadfonts(screen, "/Library/Fonts"); loadfonts(screen, texture, renderer, "/Library/Fonts");
loadfonts(screen, macosx.fontsPath); loadfonts(screen, texture, renderer, macosx.fontsPath);
loadfonts(screen, "/usr/share/fonts"); loadfonts(screen, texture, renderer, "/usr/share/fonts");
loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); loadfonts(screen, texture, renderer, "/usr/X11R6/lib/X11/fonts");
#elif defined(__sun__) #elif defined(__sun__)
loadfonts(screen, "/usr/openwin/lib/X11/fonts"); loadfonts(screen, texture, renderer, "/usr/openwin/lib/X11/fonts");
loadfonts(screen, "/usr/share/fonts"); loadfonts(screen, texture, renderer, "/usr/share/fonts");
loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); loadfonts(screen, texture, renderer, "/usr/X11R6/lib/X11/fonts");
#else #else
loadfonts(screen, "/usr/share/feh/fonts"); loadfonts(screen, texture, renderer, "/usr/share/feh/fonts");
loadfonts(screen, "/usr/share/fonts"); loadfonts(screen, texture, renderer, "/usr/share/fonts");
loadfonts(screen, "/usr/X11R6/lib/X11/fonts"); loadfonts(screen, texture, renderer, "/usr/X11R6/lib/X11/fonts");
loadfonts(screen, "/usr/share/texmf/fonts"); loadfonts(screen, texture, renderer, "/usr/share/texmf/fonts");
loadfonts(screen, "/usr/share/grace/fonts/type1"); loadfonts(screen, texture, renderer, "/usr/share/grace/fonts/type1");
loadfonts(screen, "/usr/share/hatman/fonts"); loadfonts(screen, texture, renderer, "/usr/share/hatman/fonts");
loadfonts(screen, "/usr/share/icewm/themes/jim-mac"); loadfonts(screen, texture, renderer, "/usr/share/icewm/themes/jim-mac");
loadfonts(screen, "/usr/share/vlc/skins2/fonts"); loadfonts(screen, texture, renderer, "/usr/share/vlc/skins2/fonts");
loadfonts(screen, "/usr/share/xplanet/fonts"); loadfonts(screen, texture, renderer, "/usr/share/xplanet/fonts");
#endif #endif
} }
homedirdir = get_fname("fonts", DIR_DATA); homedirdir = get_fname("fonts", DIR_DATA);
loadfonts(screen, homedirdir); loadfonts(screen, texture, renderer, homedirdir);
free(homedirdir); free(homedirdir);
#ifdef WIN32 #ifdef WIN32
homedirdir = get_fname("data/fonts", DIR_DATA); homedirdir = get_fname("data/fonts", DIR_DATA);
loadfonts(screen, homedirdir); loadfonts(screen, texture, renderer, homedirdir);
free(homedirdir); free(homedirdir);
#endif #endif
@ -1014,7 +1014,7 @@ static void loadfonts(SDL_Surface * screen, const char *const dir)
#ifdef FORKED_FONTS #ifdef FORKED_FONTS
void run_font_scanner(SDL_Surface * screen, const char *restrict const locale) void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const locale)
{ {
int sv[2]; int sv[2];
int size, i; int size, i;
@ -1044,7 +1044,7 @@ void run_font_scanner(SDL_Surface * screen, const char *restrict const locale)
sched_yield(); // try to let the parent run right now sched_yield(); // try to let the parent run right now
SDL_Init(SDL_INIT_NOPARACHUTE); SDL_Init(SDL_INIT_NOPARACHUTE);
TTF_Init(); TTF_Init();
load_user_fonts(screen, NULL, locale); load_user_fonts(screen, texture, renderer, NULL, locale);
size = 0; size = 0;
i = num_font_families; i = num_font_families;
@ -1144,7 +1144,7 @@ void run_font_scanner(SDL_Surface * screen, const char *restrict const locale)
} }
void receive_some_font_info(SDL_Surface * screen) void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer)
{ {
char *buf = NULL; char *buf = NULL;
unsigned buf_size = 0; unsigned buf_size = 0;
@ -1182,7 +1182,7 @@ void receive_some_font_info(SDL_Surface * screen)
p = (struct pollfd) p = (struct pollfd)
{ {
font_socket_fd, POLLIN, 0}; font_socket_fd, POLLIN, 0};
show_progress_bar(screen); show_progress_bar_(screen, texture, renderer);
poll(&p, 1, 29); // try not to burn CPU time poll(&p, 1, 29); // try not to burn CPU time
continue; continue;
case EINTR: case EINTR:
@ -1206,7 +1206,7 @@ void receive_some_font_info(SDL_Surface * screen)
return; return;
} }
show_progress_bar(screen); show_progress_bar_(screen, texture, renderer);
walk = buf; walk = buf;
num_font_families = *(unsigned char *) walk++; num_font_families = *(unsigned char *) walk++;
num_font_families += *(unsigned char *) walk++ << 8u; num_font_families += *(unsigned char *) walk++ << 8u;

View file

@ -114,8 +114,8 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
#ifdef FORKED_FONTS #ifdef FORKED_FONTS
void reliable_write(int fd, const void *buf, size_t count); void reliable_write(int fd, const void *buf, size_t count);
static void reliable_read(int fd, void *buf, size_t count); static void reliable_read(int fd, void *buf, size_t count);
void run_font_scanner(SDL_Surface * screen, const char *restrict const locale); void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const locale);
void receive_some_font_info(SDL_Surface * screen); void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer);
#endif #endif
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -194,6 +194,6 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size);
void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix *pango_color); void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix *pango_color);
#endif #endif
int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale); int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, void *vp, const char *restrict const locale);
#endif #endif

View file

@ -34,9 +34,9 @@
SDL_Surface *img_progress; SDL_Surface *img_progress;
int progress_bar_disabled, prog_bar_ctr; int progress_bar_disabled, prog_bar_ctr;
void show_progress_bar(SDL_Surface * screen) void show_progress_bar_(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer *renderer)
{ {
SDL_Rect dest, src; SDL_Rect dest, src, r;
int x; int x;
static Uint32 oldtime; static Uint32 oldtime;
Uint32 newtime; Uint32 newtime;
@ -64,6 +64,19 @@ void show_progress_bar(SDL_Surface * screen)
// FIXME SDL2 // FIXME SDL2
// SDL_UpdateRect(screen, 0, screen->h - 24, screen->w, 24); // SDL_UpdateRect(screen, 0, screen->h - 24, screen->w, 24);
r.x = 0;
r.y = screen->h - 24;
r.w = screen->w;
r.h = 24;
SDL_UpdateTexture(texture, &r, screen->pixels + ((screen->h - 24) * screen->pitch), screen->pitch);
// NOTE docs says one should clear the renderer, however this means a refresh of the whole thing.
// SDL_RenderClear(renderer);
// SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderCopy(renderer, texture, &r, &r);
SDL_RenderPresent(renderer);
} }
oldtime = newtime; oldtime = newtime;

View file

@ -36,6 +36,6 @@
extern SDL_Surface *img_progress; extern SDL_Surface *img_progress;
extern int progress_bar_disabled, prog_bar_ctr; extern int progress_bar_disabled, prog_bar_ctr;
void show_progress_bar(SDL_Surface * screen); void show_progress_bar_(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer *renderer);
#endif #endif

View file

@ -915,6 +915,11 @@ static void SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Sint32 w, S
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
static void show_progress_bar(SDL_Surface * screen)
{
show_progress_bar_(screen, texture, renderer);
}
/* Update a rect. based on two x/y coords (not necessarly in order): */ /* Update a rect. based on two x/y coords (not necessarly in order): */
static void update_screen(int x1, int y1, int x2, int y2) static void update_screen(int x1, int y1, int x2, int y2)
@ -3129,7 +3134,7 @@ printf("screenrectr_tools %d, %d, %d, %d\n", r_tools.x, r_tools.y, r_tools.w, r_
waiting_for_fonts = 1; waiting_for_fonts = 1;
#ifdef FORKED_FONTS #ifdef FORKED_FONTS
receive_some_font_info(screen); receive_some_font_info(screen, texture, renderer);
#else #else
while (!font_thread_done && !font_thread_aborted) while (!font_thread_done && !font_thread_aborted)
{ {
@ -6608,7 +6613,7 @@ static void load_brush_dir(SDL_Surface * screen, const char *restrict const dir)
unsigned dirlen = strlen(dir); unsigned dirlen = strlen(dir);
memcpy(buf, dir, dirlen); memcpy(buf, dir, dirlen);
tp_ftw(screen, buf, dirlen, 0, loadbrush_callback, NULL); tp_ftw(screen, texture, renderer, buf, dirlen, 0, loadbrush_callback, NULL);
} }
SDL_Surface *mirror_surface(SDL_Surface * s) SDL_Surface *mirror_surface(SDL_Surface * s)
@ -7538,7 +7543,7 @@ static void load_stamp_dir(SDL_Surface * screen, const char *const dir)
unsigned dirlen = strlen(dir); unsigned dirlen = strlen(dir);
memcpy(buf, dir, dirlen); memcpy(buf, dir, dirlen);
load_stamp_basedir = dir; load_stamp_basedir = dir;
tp_ftw(screen, buf, dirlen, 0, loadstamp_callback, NULL); tp_ftw(screen, texture, renderer, buf, dirlen, 0, loadstamp_callback, NULL);
} }
@ -7574,7 +7579,7 @@ static void load_stamps(SDL_Surface * screen)
#ifndef FORKED_FONTS #ifndef FORKED_FONTS
static int load_user_fonts_stub(void *vp) static int load_user_fonts_stub(void *vp)
{ {
return load_user_fonts(screen, vp, NULL); return load_user_fonts(screen, texture, renderer, vp, NULL);
} }
#endif #endif
@ -23568,7 +23573,7 @@ VIDEO_BPP, SDL_SWSURFACE);*/
#ifdef DEBUG #ifdef DEBUG
printf("Now running font scanner\n"); fflush(stdout); printf("Now running font scanner\n"); fflush(stdout);
#endif #endif
run_font_scanner(screen, lang_prefixes[get_current_language()]); run_font_scanner(screen, texture, renderer, lang_prefixes[get_current_language()]);
#endif #endif
#endif #endif
@ -24318,7 +24323,7 @@ int main(int argc, char *argv[])
#ifdef DEBUG #ifdef DEBUG
printf("Running font scanner\n"); fflush(stdout); printf("Running font scanner\n"); fflush(stdout);
#endif #endif
run_font_scanner(screen, lang_prefixes[get_current_language()]); run_font_scanner(screen, texture, renderer, lang_prefixes[get_current_language()]);
#else #else
#ifdef DEBUG #ifdef DEBUG
printf("NOT running font scanner\n"); fflush(stdout); printf("NOT running font scanner\n"); fflush(stdout);