Ran source code through "indent -nbfda -npcs -npsl -bli0".

This commit is contained in:
William Kendrick 2006-08-27 21:00:52 +00:00
parent 51355bce43
commit 7716a05281
38 changed files with 10816 additions and 10710 deletions

View file

@ -9,7 +9,7 @@ http://www.newbreedsoftware.com/tuxpaint/
$Id$ $Id$
2006.August.26 (0.9.16) 2006.August.27 (0.9.16)
* Interface improvements: * Interface improvements:
----------------------- -----------------------
* Modified "Text" tool so that it correctly handles the 16-bit unicode * Modified "Text" tool so that it correctly handles the 16-bit unicode
@ -143,6 +143,8 @@ $Id$
* Compiling, porting and packaging updates: * Compiling, porting and packaging updates:
----------------------------------------- -----------------------------------------
* Ran source code through "indent -nbfda -npcs -npsl -bli0".
* "DESTDIR" patch is no longer needed. * "DESTDIR" patch is no longer needed.
TOYAMA Shin-ichi <shin1@wmail.plala.or.jp> TOYAMA Shin-ichi <shin1@wmail.plala.or.jp>

View file

@ -1,8 +1,8 @@
/* BeOS_print.h */ /* BeOS_print.h */
/* printing support for Tux Paint */ /* printing support for Tux Paint */
/* Marcin 'Shard' Konicki <shard@beosjournal.org> */ /* Marcin 'Shard' Konicki <shard@beosjournal.org> */
/* /*
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -18,26 +18,26 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt) (See COPYING.txt)
*/ */
/* Jan. 17, 2003 */ /* Jan. 17, 2003 */
/* $Id$ */ /* $Id$ */
#ifndef __BEOS_PRINT_H__ #ifndef __BEOS_PRINT_H__
#define __BEOS_PRINT_H__ #define __BEOS_PRINT_H__
#include "SDL.h" #include "SDL.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
#endif {
extern int SurfacePrint( SDL_Surface *surf ); #endif /* */
extern int IsPrinterAvailable(); extern int SurfacePrint(SDL_Surface * surf);
extern int IsPrinterAvailable();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif /* */
#endif #endif /* */

View file

@ -31,7 +31,8 @@
/* What colors are available: */ /* What colors are available: */
enum { enum
{
COLOR_BLACK, COLOR_BLACK,
COLOR_DARKGREY, COLOR_DARKGREY,
COLOR_LIGHTGREY, COLOR_LIGHTGREY,
@ -56,29 +57,29 @@ enum {
/* Hex codes: */ /* Hex codes: */
const int color_hexes[NUM_COLORS][3] = { const int color_hexes[NUM_COLORS][3] = {
{0, 0, 0}, /* Black */ {0, 0, 0}, /* Black */
{128, 128, 128}, /* Dark grey */ {128, 128, 128}, /* Dark grey */
{192, 192, 192}, /* Light grey */ {192, 192, 192}, /* Light grey */
{255, 255, 255}, /* White */ {255, 255, 255}, /* White */
{255, 0, 0}, /* Red */ {255, 0, 0}, /* Red */
{255, 128, 0}, /* Orange */ {255, 128, 0}, /* Orange */
{255, 255, 0}, /* Yellow */ {255, 255, 0}, /* Yellow */
{160, 228, 128}, /* Light green */ {160, 228, 128}, /* Light green */
{ 33, 148, 70}, /* Dark green */ {33, 148, 70}, /* Dark green */
{138, 168, 205}, /* Sky blue */ {138, 168, 205}, /* Sky blue */
{ 50, 100, 255}, /* Blue */ {50, 100, 255}, /* Blue */
{186, 157, 255}, /* Lavender */ {186, 157, 255}, /* Lavender */
{128, 0, 128}, /* Purple */ {128, 0, 128}, /* Purple */
{255, 165, 211}, /* Pink */ {255, 165, 211}, /* Pink */
{128, 80, 0}, /* Brown */ {128, 80, 0}, /* Brown */
{226, 189, 166}, /* Tan */ {226, 189, 166}, /* Tan */
{247, 228, 219} /* Beige */ {247, 228, 219} /* Beige */
}; };
/* Color names: */ /* Color names: */
const char * const color_names[NUM_COLORS] = { const char *const color_names[NUM_COLORS] = {
gettext_noop("Black!"), gettext_noop("Black!"),
gettext_noop("Dark grey! Some people spell it “dark gray”."), gettext_noop("Dark grey! Some people spell it “dark gray”."),
gettext_noop("Light grey! Some people spell it “light gray”."), gettext_noop("Light grey! Some people spell it “light gray”."),

View file

@ -83,7 +83,7 @@
// since gcc-2.5 // since gcc-2.5
#ifdef __GNUC__ #ifdef __GNUC__
#define NORETURN __attribute__((__noreturn__)) #define NORETURN __attribute__((__noreturn__))
#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect #define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect
#else #else
#define NORETURN #define NORETURN
#define FUNCTION #define FUNCTION
@ -150,4 +150,3 @@
#undef CLOCK_ASM #undef CLOCK_ASM
#define CLOCK_ASM(x) x=42 #define CLOCK_ASM(x) x=42
#endif #endif

View file

@ -30,11 +30,11 @@
#include "cursor.h" #include "cursor.h"
#include "debug.h" #include "debug.h"
#define UNUSED(arg) ((void)(arg)) #define UNUSED(arg) ((void)(arg))
SDL_Cursor * cursor_hand, * cursor_arrow, * cursor_watch, SDL_Cursor *cursor_hand, *cursor_arrow, *cursor_watch,
* cursor_up, * cursor_down, * cursor_tiny, * cursor_crosshair, *cursor_up, *cursor_down, *cursor_tiny, *cursor_crosshair,
* cursor_brush, * cursor_wand, * cursor_insertion, * cursor_rotate; *cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate;
int no_fancy_cursors; int no_fancy_cursors;
@ -73,8 +73,8 @@ void do_setcursor(SDL_Cursor * c)
void free_cursor(SDL_Cursor ** cursor) void free_cursor(SDL_Cursor ** cursor)
{ {
if (*cursor) if (*cursor)
{ {
SDL_FreeCursor(*cursor); SDL_FreeCursor(*cursor);
*cursor = NULL; *cursor = NULL;
} }
} }

View file

@ -65,9 +65,9 @@
#include "arrow.xbm" #include "arrow.xbm"
#include "arrow-mask.xbm" #include "arrow-mask.xbm"
extern SDL_Cursor * cursor_hand, * cursor_arrow, * cursor_watch, extern SDL_Cursor *cursor_hand, *cursor_arrow, *cursor_watch,
* cursor_up, * cursor_down, * cursor_tiny, * cursor_crosshair, *cursor_up, *cursor_down, *cursor_tiny, *cursor_crosshair,
* cursor_brush, * cursor_wand, * cursor_insertion, * cursor_rotate; *cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate;
extern int no_fancy_cursors; extern int no_fancy_cursors;

View file

@ -1,2 +1 @@
#define DEBUG //#define DEBUG

View file

@ -4,7 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define __USE_GNU /* for strcasestr() */ #define __USE_GNU /* for strcasestr() */
#include <string.h> #include <string.h>
#include <locale.h> #include <locale.h>
#include <libintl.h> #include <libintl.h>
@ -25,123 +25,123 @@
///////////////// directory walking callers and callbacks ////////////////// ///////////////// directory walking callers and callbacks //////////////////
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, unsigned dirlen, tp_ftw_str *files, unsigned i) void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i)
{ {
dirlen = dirlen; dirlen = dirlen;
while(i--) while (i--)
{
int loadable = 0;
const char *restrict const cp = strchr(files[i].str, '.');
show_progress_bar(screen);
if (cp)
{ {
int loadable = 0; // need gcc 3.4 for the restrict in this location
const char *restrict const cp = strchr(files[i].str, '.'); const char * /*restrict */ const suffixes[] =
show_progress_bar(screen); { "ttc", "dfont", "pfa", "pfb", "otf", "ttf", };
if(cp) int j = sizeof suffixes / sizeof suffixes[0];
{ while (j--)
// need gcc 3.4 for the restrict in this location {
const char * /*restrict*/ const suffixes[] = {"ttc", "dfont", "pfa", "pfb", "otf", "ttf",}; // only check part, because of potential .gz or .bz2 suffix
int j = sizeof suffixes / sizeof suffixes[0]; if (!strncasecmp(cp + 1, suffixes[j], strlen(suffixes[j])))
while(j--) {
{ loadable = 1;
// only check part, because of potential .gz or .bz2 suffix break;
if(!strncasecmp(cp+1,suffixes[j],strlen(suffixes[j]))) }
{ }
loadable = 1; }
break; if (!loadable)
} {
} if (strcasestr(files[i].str, "/rsrc"))
} loadable = 1;
if(!loadable) }
{ // Loadable: TrueType (.ttf), OpenType (.otf), Type1 (.pfa and .pfb),
if(strcasestr(files[i].str, "/rsrc")) // and various useless bitmap fonts. Compressed files (with .gz or .bz2)
loadable = 1; // should also work. A *.dfont is pretty much a Mac resource fork in a normal
} // file, and may load with some library versions.
// Loadable: TrueType (.ttf), OpenType (.otf), Type1 (.pfa and .pfb), if (loadable)
// and various useless bitmap fonts. Compressed files (with .gz or .bz2) {
// should also work. A *.dfont is pretty much a Mac resource fork in a normal char fname[512];
// file, and may load with some library versions. TTF_Font *font;
if (loadable) snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
{
char fname[512];
TTF_Font *font;
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
//printf("Loading font: %s\n", fname); //printf("Loading font: %s\n", fname);
font = TTF_OpenFont(fname, text_sizes[text_size]); font = TTF_OpenFont(fname, text_sizes[text_size]);
if(font) if (font)
{ {
const char *restrict const family = TTF_FontFaceFamilyName(font); const char *restrict const family = TTF_FontFaceFamilyName(font);
const char *restrict const style = TTF_FontFaceStyleName(font); const char *restrict const style = TTF_FontFaceStyleName(font);
#ifdef DEBUG #ifdef DEBUG
int numfaces = TTF_FontFaces(font); int numfaces = TTF_FontFaces(font);
if (numfaces != 1) if (numfaces != 1)
printf("Found %d faces in %s, %s, %s\n", numfaces, files[i].str, family, style); printf("Found %d faces in %s, %s, %s\n", numfaces, files[i].str,
family, style);
#endif #endif
// First, the blacklist. We list font families that can crash Tux Paint // First, the blacklist. We list font families that can crash Tux Paint
// via bugs in the SDL_ttf library. We also test fonts to be sure that // via bugs in the SDL_ttf library. We also test fonts to be sure that
// they have both uppercase and lowercase letters. Note that we do not // they have both uppercase and lowercase letters. Note that we do not
// test for "Aa", because it is OK if uppercase and lowercase are the // test for "Aa", because it is OK if uppercase and lowercase are the
// same. (but not nice -- such fonts get a low score later) // same. (but not nice -- such fonts get a low score later)
// //
// We test the alphabet twice, to help with translation. If the users // We test the alphabet twice, to help with translation. If the users
// will be unable to type ASCII letters, then both lines should be // will be unable to type ASCII letters, then both lines should be
// translated. Otherwise, only Line X should be translated and the // translated. Otherwise, only Line X should be translated and the
// ASCII-only fonts should be given bad scores in the scoring code below. // ASCII-only fonts should be given bad scores in the scoring code below.
// (the best scores going to fonts that support both) // (the best scores going to fonts that support both)
if if (strcmp("Zapfino", family) && strcmp("Elvish Ring NFI", family) && ((charset_works(font, gettext("qx")) && charset_works(font, gettext("QX"))) // Line X
( || (charset_works(font, gettext("qy")) && charset_works(font, gettext("QY"))) // Line Y
strcmp("Zapfino",family) && strcmp("Elvish Ring NFI",family) ))
&& {
( if (num_font_styles == num_font_styles_max)
(charset_works(font, gettext("qx")) && charset_works(font, gettext("QX"))) // Line X {
|| num_font_styles_max = num_font_styles_max * 5 / 4 + 30;
(charset_works(font, gettext("qy")) && charset_works(font, gettext("QY"))) // Line Y user_font_styles =
) realloc(user_font_styles,
) num_font_styles_max * sizeof *user_font_styles);
{ }
if (num_font_styles==num_font_styles_max) user_font_styles[num_font_styles] =
{ malloc(sizeof *user_font_styles[num_font_styles]);
num_font_styles_max = num_font_styles_max * 5 / 4 + 30; user_font_styles[num_font_styles]->directory = strdup(dir);
user_font_styles = realloc(user_font_styles, num_font_styles_max * sizeof *user_font_styles); user_font_styles[num_font_styles]->filename = files[i].str; // steal it (mark NULL below)
} user_font_styles[num_font_styles]->family = strdup(family);
user_font_styles[num_font_styles] = malloc(sizeof *user_font_styles[num_font_styles]); user_font_styles[num_font_styles]->style = strdup(style);
user_font_styles[num_font_styles]->directory = strdup(dir); // Now we score fonts to ensure that the best ones will be placed at
user_font_styles[num_font_styles]->filename = files[i].str; // steal it (mark NULL below) // the top of the list. The user will see them first. This sorting is
user_font_styles[num_font_styles]->family = strdup(family); // especially important for users who have scroll buttons disabled.
user_font_styles[num_font_styles]->style = strdup(style); // Translators should do whatever is needed to put crummy fonts last.
// Now we score fonts to ensure that the best ones will be placed at user_font_styles[num_font_styles]->score = charset_works(font, gettext("oO")); // distinct uppercase and lowercase
// the top of the list. The user will see them first. This sorting is user_font_styles[num_font_styles]->score += charset_works(font, gettext("`\%_@$~#{}<>^&*")); // uncommon punctuation
// especially important for users who have scroll buttons disabled. user_font_styles[num_font_styles]->score += charset_works(font, gettext(",.?!")); // common punctuation
// Translators should do whatever is needed to put crummy fonts last. user_font_styles[num_font_styles]->score += charset_works(font, gettext("017")); // digits
user_font_styles[num_font_styles]->score = charset_works(font, gettext("oO")); // distinct uppercase and lowercase user_font_styles[num_font_styles]->score += charset_works(font, gettext("O0")); // distinct circle-like characters
user_font_styles[num_font_styles]->score += charset_works(font, gettext("`\%_@$~#{}<>^&*")); // uncommon punctuation user_font_styles[num_font_styles]->score += charset_works(font, gettext("1Il|")); // distinct line-like characters
user_font_styles[num_font_styles]->score += charset_works(font, gettext(",.?!")); // common punctuation num_font_styles++;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("017")); // digits
user_font_styles[num_font_styles]->score += charset_works(font, gettext("O0")); // distinct circle-like characters
user_font_styles[num_font_styles]->score += charset_works(font, gettext("1Il|")); // distinct line-like characters
num_font_styles++;
//printf("Accepted: %s, %s, %s, score(%d)\n", files[i].str, family, style, user_font_styles[num_font_styles]->score); //printf("Accepted: %s, %s, %s, score(%d)\n", files[i].str, family, style, user_font_styles[num_font_styles]->score);
files[i].str = NULL; // so free() won't crash -- we stole the memory files[i].str = NULL; // so free() won't crash -- we stole the memory
} }
else else
{ {
#if 0 #if 0
// THREADED_FONTS // THREADED_FONTS
printf("Font is too defective: %s, %s, %s\n", files[i].str, family, style); printf("Font is too defective: %s, %s, %s\n", files[i].str, family,
style);
#endif #endif
} }
TTF_CloseFont(font); TTF_CloseFont(font);
} }
else else
{ {
#if 0 #if 0
// THREADED_FONTS // THREADED_FONTS
printf("could not open %s\n", files[i].str); printf("could not open %s\n", files[i].str);
#endif #endif
} }
}
free(files[i].str);
} }
free(files[i].str);
}
free(files); free(files);
} }
@ -149,14 +149,16 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, uns
// For qsort() // For qsort()
int compare_ftw_str(const void *v1, const void *v2) int compare_ftw_str(const void *v1, const void *v2)
{ {
const char *restrict const s1 = ((tp_ftw_str*)v1)->str; const char *restrict const s1 = ((tp_ftw_str *) v1)->str;
const char *restrict const s2 = ((tp_ftw_str*)v2)->str; const char *restrict const s2 = ((tp_ftw_str *) v2)->str;
return -strcmp(s1, s2); return -strcmp(s1, s2);
} }
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, int rsrc, void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
void (*fn)(SDL_Surface * screen, const char *restrict const dir, unsigned dirlen, tp_ftw_str *files, unsigned count) int rsrc, void (*fn) (SDL_Surface * screen,
) const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count))
{ {
DIR *d; DIR *d;
unsigned num_file_names = 0; unsigned num_file_names = 0;
@ -176,124 +178,124 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen, int
if (!d) if (!d)
return; return;
for(;;) for (;;)
{ {
struct dirent * f = readdir(d); struct dirent *f = readdir(d);
int filetype = TP_FTW_UNKNOWN; int filetype = TP_FTW_UNKNOWN;
if(!f) if (!f)
break; break;
if(f->d_name[0]=='.') if (f->d_name[0] == '.')
continue; continue;
// Linux and BSD can often provide file type info w/o the stat() call // Linux and BSD can often provide file type info w/o the stat() call
#ifdef DT_UNKNOWN #ifdef DT_UNKNOWN
switch(f->d_type) switch (f->d_type)
{ {
default: default:
continue; continue;
case DT_REG: case DT_REG:
if(!rsrc) // if maybe opening resource files, need st_size if (!rsrc) // if maybe opening resource files, need st_size
filetype = TP_FTW_NORMAL; filetype = TP_FTW_NORMAL;
break; break;
case DT_DIR: case DT_DIR:
filetype = TP_FTW_DIRECTORY; filetype = TP_FTW_DIRECTORY;
break; break;
case DT_UNKNOWN: case DT_UNKNOWN:
case DT_LNK: case DT_LNK:
; ;
} }
#else #else
#warning Failed to see DT_UNKNOWN #warning Failed to see DT_UNKNOWN
#endif #endif
#if defined(_DIRENT_HAVE_D_NAMLEN) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) #if defined(_DIRENT_HAVE_D_NAMLEN) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
d_namlen = f->d_namlen; d_namlen = f->d_namlen;
#else #else
d_namlen = strlen(f->d_name); d_namlen = strlen(f->d_name);
#endif #endif
add_rsrc = 0; add_rsrc = 0;
if(filetype == TP_FTW_UNKNOWN) if (filetype == TP_FTW_UNKNOWN)
{ {
struct stat sbuf; struct stat sbuf;
memcpy(dir+dirlen, f->d_name, d_namlen+1); memcpy(dir + dirlen, f->d_name, d_namlen + 1);
if(stat(dir, &sbuf)) if (stat(dir, &sbuf))
continue; // oh well... try the next one continue; // oh well... try the next one
if(S_ISDIR(sbuf.st_mode)) if (S_ISDIR(sbuf.st_mode))
filetype = TP_FTW_DIRECTORY; filetype = TP_FTW_DIRECTORY;
else if(S_ISREG(sbuf.st_mode)) else if (S_ISREG(sbuf.st_mode))
{ {
filetype = TP_FTW_NORMAL; filetype = TP_FTW_NORMAL;
if(rsrc && !sbuf.st_size) if (rsrc && !sbuf.st_size)
add_rsrc = 5; // 5 is length of "/rsrc" add_rsrc = 5; // 5 is length of "/rsrc"
} }
else else
continue; // was a device file or somesuch continue; // was a device file or somesuch
}
if(filetype==TP_FTW_NORMAL)
{
char *cp;
if(num_file_names==max_file_names)
{
max_file_names = max_file_names * 5 / 4 + 30;
file_names = realloc(file_names, max_file_names * sizeof *file_names);
}
cp = malloc(d_namlen + add_rsrc + 1);
memcpy(cp, f->d_name, d_namlen);
if(add_rsrc)
memcpy(cp+d_namlen, "/rsrc", 6);
else
cp[d_namlen] = '\0';
file_names[num_file_names].str = cp;
file_names[num_file_names].len = d_namlen;
num_file_names++;
}
if(filetype==TP_FTW_DIRECTORY)
{
char * cp;
if(num_dir_names==max_dir_names)
{
max_dir_names = max_dir_names * 5 / 4 + 3;
dir_names = realloc(dir_names, max_dir_names * sizeof *dir_names);
}
cp = malloc(d_namlen + 1);
memcpy(cp, f->d_name, d_namlen + 1);
dir_names[num_dir_names].str = cp;
dir_names[num_dir_names].len = d_namlen;
num_dir_names++;
}
} }
if (filetype == TP_FTW_NORMAL)
{
char *cp;
if (num_file_names == max_file_names)
{
max_file_names = max_file_names * 5 / 4 + 30;
file_names = realloc(file_names, max_file_names * sizeof *file_names);
}
cp = malloc(d_namlen + add_rsrc + 1);
memcpy(cp, f->d_name, d_namlen);
if (add_rsrc)
memcpy(cp + d_namlen, "/rsrc", 6);
else
cp[d_namlen] = '\0';
file_names[num_file_names].str = cp;
file_names[num_file_names].len = d_namlen;
num_file_names++;
}
if (filetype == TP_FTW_DIRECTORY)
{
char *cp;
if (num_dir_names == max_dir_names)
{
max_dir_names = max_dir_names * 5 / 4 + 3;
dir_names = realloc(dir_names, max_dir_names * sizeof *dir_names);
}
cp = malloc(d_namlen + 1);
memcpy(cp, f->d_name, d_namlen + 1);
dir_names[num_dir_names].str = cp;
dir_names[num_dir_names].len = d_namlen;
num_dir_names++;
}
}
closedir(d); closedir(d);
show_progress_bar(screen); show_progress_bar(screen);
dir[dirlen] = '\0'; // repair it (clobbered for stat() call above) dir[dirlen] = '\0'; // repair it (clobbered for stat() call above)
if(file_names) if (file_names)
{ {
// let callee sort and keep the string // let callee sort and keep the string
#if 0 #if 0
qsort(file_names, num_file_names, sizeof *file_names, compare_ftw_str); qsort(file_names, num_file_names, sizeof *file_names, compare_ftw_str);
while(num_file_names--) while (num_file_names--)
{
free(file_names[num_file_names].str);
}
free(file_names);
#else
fn(screen, dir, dirlen, file_names, num_file_names);
#endif
}
if(dir_names)
{ {
qsort(dir_names, num_dir_names, sizeof *dir_names, compare_ftw_str); free(file_names[num_file_names].str);
while(num_dir_names--)
{
memcpy(dir+dirlen, dir_names[num_dir_names].str, dir_names[num_dir_names].len+1);
tp_ftw(screen, dir, dirlen+dir_names[num_dir_names].len, rsrc, fn);
free(dir_names[num_dir_names].str);
}
free(dir_names);
} }
} free(file_names);
#else
fn(screen, dir, dirlen, file_names, num_file_names);
#endif
}
if (dir_names)
{
qsort(dir_names, num_dir_names, sizeof *dir_names, compare_ftw_str);
while (num_dir_names--)
{
memcpy(dir + dirlen, dir_names[num_dir_names].str,
dir_names[num_dir_names].len + 1);
tp_ftw(screen, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn);
free(dir_names[num_dir_names].str);
}
free(dir_names);
}
}

View file

@ -17,17 +17,21 @@
#define TP_FTW_PATHSIZE 400 #define TP_FTW_PATHSIZE 400
typedef struct tp_ftw_str { typedef struct tp_ftw_str
{
char *str; char *str;
unsigned char len; unsigned char len;
// unsigned char is_rsrc; // unsigned char is_rsrc;
} tp_ftw_str; } tp_ftw_str;
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir, unsigned dirlen, tp_ftw_str *files, unsigned i); void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i);
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, int rsrc, void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
void (*fn)(SDL_Surface * screen, const char *restrict const dir, unsigned dirlen, tp_ftw_str *files, unsigned count)); int rsrc, void (*fn) (SDL_Surface * screen,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count));
#endif #endif

View file

@ -45,51 +45,52 @@ static int colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2)
#ifdef LOW_QUALITY_FLOOD_FILL #ifdef LOW_QUALITY_FLOOD_FILL
return (c1 == c2); return (c1 == c2);
#else #else
Uint8 r1, g1, b1, Uint8 r1, g1, b1, r2, g2, b2;
r2, g2, b2;
if (c1 == c2) if (c1 == c2)
{ {
/* Get it over with quick, if possible! */ /* Get it over with quick, if possible! */
return 1; return 1;
} }
else else
{ {
double r, g, b; double r, g, b;
SDL_GetRGB(c1, canvas->format, &r1, &g1, &b1); SDL_GetRGB(c1, canvas->format, &r1, &g1, &b1);
SDL_GetRGB(c2, canvas->format, &r2, &g2, &b2); SDL_GetRGB(c2, canvas->format, &r2, &g2, &b2);
// use distance in linear RGB space // use distance in linear RGB space
r = sRGB_to_linear_table[r1] - sRGB_to_linear_table[r2]; r = sRGB_to_linear_table[r1] - sRGB_to_linear_table[r2];
r *= r; r *= r;
g = sRGB_to_linear_table[g1] - sRGB_to_linear_table[g2]; g = sRGB_to_linear_table[g1] - sRGB_to_linear_table[g2];
g *= g; g *= g;
b = sRGB_to_linear_table[b1] - sRGB_to_linear_table[b2]; b = sRGB_to_linear_table[b1] - sRGB_to_linear_table[b2];
b *= b; b *= b;
// easy to confuse: // easy to confuse:
// dark grey, brown, purple // dark grey, brown, purple
// light grey, tan // light grey, tan
// red, orange // red, orange
return r+g+b < 0.04; return r + g + b < 0.04;
} }
#endif #endif
} }
/* Flood fill! */ /* Flood fill! */
void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr) void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y,
Uint32 cur_colr, Uint32 old_colr)
{ {
int fillL, fillR, i, in_line; int fillL, fillR, i, in_line;
static unsigned char prog_anim; static unsigned char prog_anim;
Uint32 (*getpixel)(SDL_Surface *, int, int) = getpixels[canvas->format->BytesPerPixel]; Uint32(*getpixel) (SDL_Surface *, int, int) =
void (*putpixel)(SDL_Surface *, int, int, Uint32) = putpixels[canvas->format->BytesPerPixel]; getpixels[canvas->format->BytesPerPixel];
void (*putpixel) (SDL_Surface *, int, int, Uint32) =
putpixels[canvas->format->BytesPerPixel];
if (cur_colr == old_colr || if (cur_colr == old_colr || colors_close(canvas, cur_colr, old_colr))
colors_close(canvas, cur_colr, old_colr))
return; return;
@ -98,10 +99,10 @@ void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uin
prog_anim++; prog_anim++;
if ((prog_anim % 4) == 0) if ((prog_anim % 4) == 0)
{ {
show_progress_bar(screen); show_progress_bar(screen);
playsound(screen, 0, SND_BUBBLE, 0, x, SNDDIST_NEAR); playsound(screen, 0, SND_BUBBLE, 0, x, SNDDIST_NEAR);
} }
/* Find left side, filling along the way */ /* Find left side, filling along the way */
@ -109,13 +110,14 @@ void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uin
in_line = 1; in_line = 1;
while (in_line) while (in_line)
{ {
putpixel(canvas, fillL, y, cur_colr); putpixel(canvas, fillL, y, cur_colr);
fillL--; fillL--;
in_line = (fillL < 0) ? 0 : colors_close(canvas, getpixel(canvas, fillL, y), in_line =
old_colr); (fillL < 0) ? 0 : colors_close(canvas, getpixel(canvas, fillL, y),
} old_colr);
}
fillL++; fillL++;
@ -124,14 +126,15 @@ void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uin
in_line = 1; in_line = 1;
while (in_line) while (in_line)
{ {
putpixel(canvas, fillR, y, cur_colr); putpixel(canvas, fillR, y, cur_colr);
fillR++; fillR++;
in_line = (fillR >= canvas->w) ? 0 : colors_close(canvas, getpixel(canvas, in_line = (fillR >= canvas->w) ? 0 : colors_close(canvas, getpixel(canvas,
fillR, y), fillR,
old_colr); y),
} old_colr);
}
fillR--; fillR--;
@ -139,12 +142,12 @@ void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uin
/* Search top and bottom */ /* Search top and bottom */
for (i = fillL; i <= fillR; i++) for (i = fillL; i <= fillR; i++)
{ {
if (y > 0 && colors_close(canvas, getpixel(canvas, i, y - 1), old_colr)) if (y > 0 && colors_close(canvas, getpixel(canvas, i, y - 1), old_colr))
do_flood_fill(screen, canvas, i, y - 1, cur_colr, old_colr); do_flood_fill(screen, canvas, i, y - 1, cur_colr, old_colr);
if (y < canvas->h && colors_close(canvas, getpixel(canvas, i, y + 1), old_colr)) if (y < canvas->h
do_flood_fill(screen, canvas, i, y + 1, cur_colr, old_colr); && colors_close(canvas, getpixel(canvas, i, y + 1), old_colr))
} do_flood_fill(screen, canvas, i, y + 1, cur_colr, old_colr);
}
} }

View file

@ -33,7 +33,7 @@
#include "SDL.h" #include "SDL.h"
void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr); void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y,
Uint32 cur_colr, Uint32 old_colr);
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -31,10 +31,10 @@
#define SDL_WaitThread(tid,rcp) do{(void)tid;(void)rcp;}while(0) #define SDL_WaitThread(tid,rcp) do{(void)tid;(void)rcp;}while(0)
#define SDL_Thread int #define SDL_Thread int
#define SDL_mutex int #define SDL_mutex int
#define SDL_CreateMutex() 0 // creates in released state #define SDL_CreateMutex() 0 // creates in released state
#define SDL_DestroyMutex(lock) #define SDL_DestroyMutex(lock)
#define SDL_mutexP(lock) // take lock #define SDL_mutexP(lock) // take lock
#define SDL_mutexV(lock) // release lock #define SDL_mutexV(lock) // release lock
#endif #endif
extern SDL_Thread *font_thread; extern SDL_Thread *font_thread;
@ -48,11 +48,11 @@ extern int no_system_fonts;
extern int was_bad_font; extern int was_bad_font;
TTF_Font *BUGFIX_TTF_OpenFont206(const char * const file, int ptsize); TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize);
#define TTF_OpenFont BUGFIX_TTF_OpenFont206 #define TTF_OpenFont BUGFIX_TTF_OpenFont206
TTF_Font *try_alternate_font(int size); TTF_Font *try_alternate_font(int size);
TTF_Font *load_locale_font(TTF_Font *fallback, int size); TTF_Font *load_locale_font(TTF_Font * fallback, int size);
int load_user_fonts(SDL_Surface * screen, void *vp); int load_user_fonts(SDL_Surface * screen, void *vp);
#ifdef FORKED_FONTS #ifdef FORKED_FONTS
@ -78,25 +78,29 @@ extern unsigned text_size;
// nice progression (alternating 33% and 25%) 9 12 18 24 36 48 72 96 144 192 // nice progression (alternating 33% and 25%) 9 12 18 24 36 48 72 96 144 192
// commonly hinted sizes seem to be: 9, 10, 12, 14, 18, 20 (less so), 24 // commonly hinted sizes seem to be: 9, 10, 12, 14, 18, 20 (less so), 24
// reasonable: 9,12,18... and 10,14,18... // reasonable: 9,12,18... and 10,14,18...
static int text_sizes[] = {9, 12, 18, 24, 36, 48, static int text_sizes[] = { 9, 12, 18, 24, 36, 48,
56, 64, 96, 112, 128, 160}; // point sizes 56, 64, 96, 112, 128, 160
}; // point sizes
#define MIN_TEXT_SIZE 0u #define MIN_TEXT_SIZE 0u
#define MAX_TEXT_SIZE (sizeof text_sizes / sizeof text_sizes[0] - 1) #define MAX_TEXT_SIZE (sizeof text_sizes / sizeof text_sizes[0] - 1)
// for sorting through the font files at startup // for sorting through the font files at startup
typedef struct style_info { typedef struct style_info
{
char *filename; char *filename;
char *directory; char *directory;
char *family; // name like "FooCorp Thunderstruck" char *family; // name like "FooCorp Thunderstruck"
char *style; // junk like "Oblique Demi-Bold" char *style; // junk like "Oblique Demi-Bold"
int italic; int italic;
int boldness; int boldness;
int score; int score;
int truetype; // Is it? (TrueType gets priority) int truetype; // Is it? (TrueType gets priority)
} style_info; } style_info;
// user's notion of a font // user's notion of a font
typedef struct family_info { typedef struct family_info
{
char *directory; char *directory;
char *family; char *family;
char *filename[4]; char *filename[4];
@ -104,7 +108,7 @@ typedef struct family_info {
int score; int score;
} family_info; } family_info;
extern TTF_Font * medium_font, * small_font, * large_font, * locale_font; extern TTF_Font *medium_font, *small_font, *large_font, *locale_font;
extern family_info **user_font_families; extern family_info **user_font_families;
extern int num_font_families; extern int num_font_families;
@ -118,17 +122,16 @@ extern int num_font_styles_max;
int compar_fontgroup(const void *v1, const void *v2); int compar_fontgroup(const void *v1, const void *v2);
int compar_fontkiller(const void *v1, const void *v2); int compar_fontkiller(const void *v1, const void *v2);
int compar_fontscore(const void *v1, const void *v2); int compar_fontscore(const void *v1, const void *v2);
void parse_font_style(style_info *si); void parse_font_style(style_info * si);
void groupfonts_range(style_info **base, int count); void groupfonts_range(style_info ** base, int count);
void dupe_markdown_range(family_info **base, int count); void dupe_markdown_range(family_info ** base, int count);
void groupfonts(void); void groupfonts(void);
TTF_Font *getfonthandle(int desire); TTF_Font *getfonthandle(int desire);
void loadfonts(SDL_Surface * screen, const char * const dir); void loadfonts(SDL_Surface * screen, const char *const dir);
int do_surfcmp(const SDL_Surface *const *const v1, const SDL_Surface *const *const v2); int do_surfcmp(const SDL_Surface * const *const v1,
const SDL_Surface * const *const v2);
int surfcmp(const void *s1, const void *s2); int surfcmp(const void *s1, const void *s2);
int charset_works(TTF_Font *font, const char *s); int charset_works(TTF_Font * font, const char *s);
#endif #endif

View file

@ -9,15 +9,15 @@
#include "get_fname.h" #include "get_fname.h"
#include "debug.h" #include "debug.h"
char * savedir; char *savedir;
/* The filename for the current image: */ /* The filename for the current image: */
char * get_fname(const char * const name) char *get_fname(const char *const name)
{ {
char f[512]; char f[512];
const char * tux_settings_dir; const char *tux_settings_dir;
/* Where is the user's data directory? /* Where is the user's data directory?
@ -54,46 +54,45 @@ char * get_fname(const char * const name)
/* Put together home directory path + settings directory + filename... */ /* Put together home directory path + settings directory + filename... */
if (savedir == NULL) if (savedir == NULL)
{
/* Save directory not overridden: */
if (getenv("HOME") != NULL)
{ {
/* Save directory not overridden: */ if (*name == '\0')
{
/* (Some mkdir()'s don't like trailing slashes) */
if (getenv("HOME") != NULL) snprintf(f, sizeof(f), "%s/%s", getenv("HOME"), tux_settings_dir);
{ }
if (*name == '\0')
{
/* (Some mkdir()'s don't like trailing slashes) */
snprintf(f, sizeof(f), "%s/%s", getenv("HOME"), tux_settings_dir);
}
else
{
snprintf(f, sizeof(f), "%s/%s/%s",
getenv("HOME"), tux_settings_dir, name);
}
}
else else
{ {
/* WOAH! Don't know where HOME directory is! Last resort, use '.'! */ snprintf(f, sizeof(f), "%s/%s/%s",
getenv("HOME"), tux_settings_dir, name);
strcpy(f, name); }
}
} }
else
{
/* WOAH! Don't know where HOME directory is! Last resort, use '.'! */
strcpy(f, name);
}
}
else else
{
/* User had overridden save directory with "--savedir" option: */
if (*name != '\0')
{ {
/* User had overridden save directory with "--savedir" option: */ /* (Some mkdir()'s don't like trailing slashes) */
if (*name != '\0') snprintf(f, sizeof(f), "%s/%s", savedir, name);
{
/* (Some mkdir()'s don't like trailing slashes) */
snprintf(f, sizeof(f), "%s/%s", savedir, name);
}
else
{
snprintf(f, sizeof(f), "%s", savedir);
}
} }
else
{
snprintf(f, sizeof(f), "%s", savedir);
}
}
return strdup(f); return strdup(f);
} }

View file

@ -5,10 +5,9 @@
#ifndef GET_FNAME_H #ifndef GET_FNAME_H
#define GET_FNAME_H #define GET_FNAME_H
extern char * savedir; extern char *savedir;
char * get_fname(const char * const name); char *get_fname(const char *const name);
#endif #endif

View file

@ -32,7 +32,7 @@
#define GREAT_H #define GREAT_H
const char * const great_strs[] = { const char *const great_strs[] = {
gettext_noop("Great!"), gettext_noop("Great!"),
gettext_noop("Cool!"), gettext_noop("Cool!"),
gettext_noop("Keep it up!"), gettext_noop("Keep it up!"),

View file

@ -41,7 +41,7 @@
/* Globals: */ /* Globals: */
const char * lang_prefixes[NUM_LANGS] = { const char *lang_prefixes[NUM_LANGS] = {
"af", "af",
"ar", "ar",
"be", "be",
@ -132,117 +132,117 @@ int lang_use_right_to_left[] = {
}; };
char * langstr; char *langstr;
int need_own_font; int need_own_font;
int need_right_to_left; int need_right_to_left;
const char * lang_prefix; const char *lang_prefix;
const language_to_locale_struct language_to_locale_array[] = { const language_to_locale_struct language_to_locale_array[] = {
{"english", "C"}, {"english", "C"},
{"american-english", "C"}, {"american-english", "C"},
{"arabic", "ar_SA.UTF-8"}, {"arabic", "ar_SA.UTF-8"},
{"croatian", "hr_HR.UTF-8"}, {"croatian", "hr_HR.UTF-8"},
{"hrvatski", "hr_HR.UTF-8"}, {"hrvatski", "hr_HR.UTF-8"},
{"catalan", "ca_ES.UTF-8"}, {"catalan", "ca_ES.UTF-8"},
{"catala", "ca_ES.UTF-8"}, {"catala", "ca_ES.UTF-8"},
{"belarusian", "be_BY.UTF-8"}, {"belarusian", "be_BY.UTF-8"},
{"bielaruskaja", "be_BY.UTF-8"}, {"bielaruskaja", "be_BY.UTF-8"},
{"czech", "cs_CZ.UTF-8"}, {"czech", "cs_CZ.UTF-8"},
{"cesky", "cs_CZ.UTF-8"}, {"cesky", "cs_CZ.UTF-8"},
{"danish", "da_DK.UTF-8"}, {"danish", "da_DK.UTF-8"},
{"dansk", "da_DK.UTF-8"}, {"dansk", "da_DK.UTF-8"},
{"german", "de_DE.UTF-8"}, {"german", "de_DE.UTF-8"},
{"deutsch", "de_DE.UTF-8"}, {"deutsch", "de_DE.UTF-8"},
{"estonian", "et_EE.UTF-8"}, {"estonian", "et_EE.UTF-8"},
{"greek", "el_GR.UTF-8"}, {"greek", "el_GR.UTF-8"},
{"gronings", "gos_NL.UTF-8"}, {"gronings", "gos_NL.UTF-8"},
{"zudelk-veenkelonioals","gos_NL.UTF-8"}, {"zudelk-veenkelonioals", "gos_NL.UTF-8"},
{"gujarati", "gu_IN.UTF-8"}, {"gujarati", "gu_IN.UTF-8"},
{"british-english", "en_GB.UTF-8"}, {"british-english", "en_GB.UTF-8"},
{"british", "en_GB.UTF-8"}, {"british", "en_GB.UTF-8"},
{"spanish", "es_ES.UTF-8"}, {"spanish", "es_ES.UTF-8"},
{"mexican", "es_MX.UTF-8"}, {"mexican", "es_MX.UTF-8"},
{"mexican-spanish", "es_MX.UTF-8"}, {"mexican-spanish", "es_MX.UTF-8"},
{"espanol-mejicano", "es_MX.UTF-8"}, {"espanol-mejicano", "es_MX.UTF-8"},
{"espanol", "es_ES.UTF-8"}, {"espanol", "es_ES.UTF-8"},
{"finnish", "fi_FI.UTF-8"}, {"finnish", "fi_FI.UTF-8"},
{"suomi", "fi_FI.UTF-8"}, {"suomi", "fi_FI.UTF-8"},
{"faroese", "fo_FO.UTF-8"}, {"faroese", "fo_FO.UTF-8"},
{"french", "fr_FR.UTF-8"}, {"french", "fr_FR.UTF-8"},
{"francais", "fr_FR.UTF-8"}, {"francais", "fr_FR.UTF-8"},
{"gaelic", "ga_IE.UTF-8"}, {"gaelic", "ga_IE.UTF-8"},
{"irish-gaelic", "ga_IE.UTF-8"}, {"irish-gaelic", "ga_IE.UTF-8"},
{"gaidhlig", "ga_IE.UTF-8"}, {"gaidhlig", "ga_IE.UTF-8"},
{"scottish", "gd_GB.UTF-8"}, {"scottish", "gd_GB.UTF-8"},
{"ghaidhlig", "gd_GB.UTF-8"}, {"ghaidhlig", "gd_GB.UTF-8"},
{"scottish-gaelic", "gd_GB.UTF-8"}, {"scottish-gaelic", "gd_GB.UTF-8"},
{"galician", "gl_ES.UTF-8"}, {"galician", "gl_ES.UTF-8"},
{"galego", "gl_ES.UTF-8"}, {"galego", "gl_ES.UTF-8"},
{"hebrew", "he_IL.UTF-8"}, {"hebrew", "he_IL.UTF-8"},
{"hindi", "hi_IN.UTF-8"}, {"hindi", "hi_IN.UTF-8"},
{"hungarian", "hu_HU.UTF-8"}, {"hungarian", "hu_HU.UTF-8"},
{"magyar", "hu_HU.UTF-8"}, {"magyar", "hu_HU.UTF-8"},
{"indonesian", "id_ID.UTF-8"}, {"indonesian", "id_ID.UTF-8"},
{"bahasa-indonesia", "id_ID.UTF-8"}, {"bahasa-indonesia", "id_ID.UTF-8"},
{"icelandic", "is_IS.UTF-8"}, {"icelandic", "is_IS.UTF-8"},
{"islenska", "is_IS.UTF-8"}, {"islenska", "is_IS.UTF-8"},
{"italian", "it_IT.UTF-8"}, {"italian", "it_IT.UTF-8"},
{"italiano", "it_IT.UTF-8"}, {"italiano", "it_IT.UTF-8"},
{"japanese", "ja_JP.UTF-8"}, {"japanese", "ja_JP.UTF-8"},
{"vietnamese", "vi_VN.UTF-8"}, {"vietnamese", "vi_VN.UTF-8"},
{"afrikaans", "af_ZA.UTF-8"}, {"afrikaans", "af_ZA.UTF-8"},
{"albanian", "sq_AL.UTF-8"}, {"albanian", "sq_AL.UTF-8"},
{"breton", "br_FR.UTF-8"}, {"breton", "br_FR.UTF-8"},
{"brezhoneg", "br_FR.UTF-8"}, {"brezhoneg", "br_FR.UTF-8"},
{"bulgarian", "bg_BG.UTF-8"}, {"bulgarian", "bg_BG.UTF-8"},
{"welsh", "cy_GB.UTF-8"}, {"welsh", "cy_GB.UTF-8"},
{"cymraeg", "cy_GB.UTF-8"}, {"cymraeg", "cy_GB.UTF-8"},
{"bokmal", "nb_NO.UTF-8"}, {"bokmal", "nb_NO.UTF-8"},
{"basque", "eu_ES.UTF-8"}, {"basque", "eu_ES.UTF-8"},
{"euskara", "eu_ES.UTF-8"}, {"euskara", "eu_ES.UTF-8"},
{"georgian", "ka_GE"}, {"georgian", "ka_GE"},
{"kinyarwanda", "rw_RW.UTF-8"}, {"kinyarwanda", "rw_RW.UTF-8"},
{"klingon", "tlh.UTF-8"}, {"klingon", "tlh.UTF-8"},
{"tlhIngan", "tlh.UTF-8"}, {"tlhIngan", "tlh.UTF-8"},
{"tlhingan", "tlh.UTF-8"}, {"tlhingan", "tlh.UTF-8"},
{"korean", "ko_KR.UTF-8"}, {"korean", "ko_KR.UTF-8"},
{"kurdish", "ku_TR.UTF-8"}, {"kurdish", "ku_TR.UTF-8"},
{"tamil", "ta_IN.UTF-8"}, {"tamil", "ta_IN.UTF-8"},
{"lithuanian", "lt_LT.UTF-8"}, {"lithuanian", "lt_LT.UTF-8"},
{"lietuviu", "lt_LT.UTF-8"}, {"lietuviu", "lt_LT.UTF-8"},
{"malay", "ms_MY.UTF-8"}, {"malay", "ms_MY.UTF-8"},
{"dutch", "nl_NL.UTF-8"}, {"dutch", "nl_NL.UTF-8"},
{"nederlands", "nl_NL.UTF-8"}, {"nederlands", "nl_NL.UTF-8"},
{"norwegian", "nn_NO.UTF-8"}, {"norwegian", "nn_NO.UTF-8"},
{"nynorsk", "nn_NO.UTF-8"}, {"nynorsk", "nn_NO.UTF-8"},
{"norsk", "nn_NO.UTF-8"}, {"norsk", "nn_NO.UTF-8"},
{"polish", "pl_PL.UTF-8"}, {"polish", "pl_PL.UTF-8"},
{"polski", "pl_PL.UTF-8"}, {"polski", "pl_PL.UTF-8"},
{"brazilian-portuguese", "pt_BR.UTF-8"}, {"brazilian-portuguese", "pt_BR.UTF-8"},
{"portugues-brazilian", "pt_BR.UTF-8"}, {"portugues-brazilian", "pt_BR.UTF-8"},
{"brazilian", "pt_BR.UTF-8"}, {"brazilian", "pt_BR.UTF-8"},
{"portuguese", "pt_PT.UTF-8"}, {"portuguese", "pt_PT.UTF-8"},
{"portugues", "pt_PT.UTF-8"}, {"portugues", "pt_PT.UTF-8"},
{"romanian", "ro_RO.UTF-8"}, {"romanian", "ro_RO.UTF-8"},
{"russian", "ru_RU.UTF-8"}, {"russian", "ru_RU.UTF-8"},
{"russkiy", "ru_RU.UTF-8"}, {"russkiy", "ru_RU.UTF-8"},
{"slovak", "sk_SK.UTF-8"}, {"slovak", "sk_SK.UTF-8"},
{"slovenian", "sl_SI.UTF-8"}, {"slovenian", "sl_SI.UTF-8"},
{"slovensko", "sl_SI.UTF-8"}, {"slovensko", "sl_SI.UTF-8"},
{"serbian", "sr_YU.UTF-8"}, {"serbian", "sr_YU.UTF-8"},
{"swedish", "sv_SE.UTF-8"}, {"swedish", "sv_SE.UTF-8"},
{"svenska", "sv_SE.UTF-8"}, {"svenska", "sv_SE.UTF-8"},
{"swahili", "sw_TZ.UTF-8"}, {"swahili", "sw_TZ.UTF-8"},
{"tagalog", "tl_PH.UTF-8"}, {"tagalog", "tl_PH.UTF-8"},
{"thai", "th_TH.UTF-8"}, {"thai", "th_TH.UTF-8"},
{"tibetan", "bo_CN.UTF-8"}, /* Based on: http://texinfo.org/pipermail/texinfo-pretest/2005-April/000334.html */ {"tibetan", "bo_CN.UTF-8"}, /* Based on: http://texinfo.org/pipermail/texinfo-pretest/2005-April/000334.html */
{"turkish", "tr_TR.UTF-8"}, {"turkish", "tr_TR.UTF-8"},
{"ukrainian", "uk_UA.UTF-8"}, {"ukrainian", "uk_UA.UTF-8"},
{"walloon", "wa_BE.UTF-8"}, {"walloon", "wa_BE.UTF-8"},
{"walon", "wa_BE.UTF-8"}, {"walon", "wa_BE.UTF-8"},
{"chinese", "zh_CN.UTF-8"}, {"chinese", "zh_CN.UTF-8"},
{"simplified-chinese", "zh_CN.UTF-8"}, {"simplified-chinese", "zh_CN.UTF-8"},
{"traditional-chinese", "zh_TW.UTF-8"}, {"traditional-chinese", "zh_TW.UTF-8"},
}; };
@ -251,10 +251,10 @@ static int search_int_array(int l, int *array)
int i; int i;
for (i = 0; array[i] != -1; i++) for (i = 0; array[i] != -1; i++)
{ {
if (array[i] == l) if (array[i] == l)
return 1; return 1;
} }
return 0; return 0;
} }
@ -270,7 +270,7 @@ void set_langstr(const char *s)
void set_current_language(void) void set_current_language(void)
{ {
char * loc; char *loc;
int lang, i, found; int lang, i, found;
bindtextdomain("tuxpaint", LOCALEDIR); bindtextdomain("tuxpaint", LOCALEDIR);
@ -288,53 +288,53 @@ void set_current_language(void)
#ifndef WIN32 #ifndef WIN32
loc = setlocale(LC_MESSAGES, NULL); loc = setlocale(LC_MESSAGES, NULL);
if (loc != NULL) if (loc != NULL)
{ {
if (strstr(loc, "LC_MESSAGES") != NULL) if (strstr(loc, "LC_MESSAGES") != NULL)
loc = getenv("LANG"); loc = getenv("LANG");
} }
#else #else
bind_textdomain_codeset("tuxpaint", "UTF-8"); bind_textdomain_codeset("tuxpaint", "UTF-8");
loc = getenv("LANGUAGE"); loc = getenv("LANGUAGE");
if (!loc) if (!loc)
{
loc = _nl_locale_name(LC_MESSAGES, "");
if (loc)
{ {
loc = _nl_locale_name(LC_MESSAGES, ""); char *s;
if (loc) int len;
{ len = strlen("LANGUAGE=") + strlen(loc) + 1;
char *s; s = malloc(len);
int len; snprintf(s, len, "LANGUAGE=%s", loc);
len = strlen("LANGUAGE=")+strlen(loc)+1; putenv(s);
s = malloc(len);
snprintf(s, len, "LANGUAGE=%s", loc);
putenv(s);
}
} }
}
#endif #endif
//debug(loc); //debug(loc);
if (loc != NULL) if (loc != NULL)
{
/* Which, if any, of the locales is it? */
found = 0;
for (i = 0; i < NUM_LANGS && found == 0; i++)
{ {
/* Which, if any, of the locales is it? */ // Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (strncasecmp(loc, lang_prefixes[i], strlen(lang_prefixes[i])) == 0)
found = 0; {
lang = i;
for (i = 0; i < NUM_LANGS && found == 0; i++) found = 1;
{ }
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (strncasecmp(loc, lang_prefixes[i], strlen(lang_prefixes[i])) == 0)
{
lang = i;
found = 1;
}
}
} }
}
lang_prefix = lang_prefixes[lang]; lang_prefix = lang_prefixes[lang];
need_own_font = search_int_array(lang,lang_use_own_font); need_own_font = search_int_array(lang, lang_use_own_font);
need_right_to_left = search_int_array(lang,lang_use_right_to_left); need_right_to_left = search_int_array(lang, lang_use_right_to_left);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"DEBUG: Language is %s (%d)\n", lang_prefix, lang); fprintf(stderr, "DEBUG: Language is %s (%d)\n", lang_prefix, lang);
fflush(stderr); fflush(stderr);
#endif #endif
@ -343,228 +343,226 @@ void set_current_language(void)
/* FIXME: All this should REALLY be array-based!!! */ /* FIXME: All this should REALLY be array-based!!! */
/* Show available languages: */ /* Show available languages: */
void show_lang_usage(FILE * f, const char * const prg) void show_lang_usage(FILE * f, const char *const prg)
{ {
fprintf(f, fprintf(f,
"\n" "\n"
"Usage: %s [--lang LANGUAGE]\n" "Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
"\n" /* C */ " english american-english\n"
"LANGUAGE may be one of:\n" /* af */ " afrikaans\n"
/* C */ " english american-english\n" /* sq */ " albanian\n"
/* af */ " afrikaans\n" /* ar */ " arabic\n"
/* sq */ " albanian\n" /* eu */ " basque euskara\n"
/* ar */ " arabic\n" /* be */ " belarusian bielaruskaja\n"
/* eu */ " basque euskara\n" /* nb */ " bokmal\n"
/* be */ " belarusian bielaruskaja\n" /* pt_BR */
/* nb */ " bokmal\n" " brazilian brazilian-portuguese portugues-brazilian\n"
/* pt_BR */ " brazilian brazilian-portuguese portugues-brazilian\n" /* br */ " breton brezhoneg\n"
/* br */ " breton brezhoneg\n" /* en_GB */ " british british-english\n"
/* en_GB */ " british british-english\n" /* bg_BG */ " bulgarian\n"
/* bg_BG */ " bulgarian\n" /* ca */ " catalan catala\n"
/* ca */ " catalan catala\n" /* zh_CN */ " chinese simplified-chinese\n"
/* zh_CN */ " chinese simplified-chinese\n" /* zh_TW */ " traditional-chinese\n"
/* zh_TW */ " traditional-chinese\n" /* hr */ " croatian hrvatski\n"
/* hr */ " croatian hrvatski\n" /* cs */ " czech cesky\n"
/* cs */ " czech cesky\n" /* da */ " danish dansk\n"
/* da */ " danish dansk\n" /* nl */ " dutch nederlands\n"
/* nl */ " dutch nederlands\n" /* et */ " estonian\n"
/* et */ " estonian\n" /* fo */ " faroese\n"
/* fo */ " faroese\n" /* fi */ " finnish suomi\n"
/* fi */ " finnish suomi\n" /* fr */ " french francais\n"
/* fr */ " french francais\n" /* ga */ " gaelic irish-gaelic gaidhlig\n"
/* ga */ " gaelic irish-gaelic gaidhlig\n" /* gl */ " galician galego\n"
/* gl */ " galician galego\n" /* ka */ " georgian\n"
/* ka */ " georgian\n" /* de */ " german deutsch\n"
/* de */ " german deutsch\n" /* el */ " greek\n"
/* el */ " greek\n" /* gos */ " gronings zudelk-veenkelonioals\n"
/* gos */ " gronings zudelk-veenkelonioals\n" /* gu */ " gujarati\n"
/* gu */ " gujarati\n" /* he */ " hebrew\n"
/* he */ " hebrew\n" /* hi */ " hindi\n"
/* hi */ " hindi\n" /* hu */ " hungarian magyar\n"
/* hu */ " hungarian magyar\n" /* is */ " icelandic islenska\n"
/* is */ " icelandic islenska\n" /* id */ " indonesian bahasa-indonesia\n"
/* id */ " indonesian bahasa-indonesia\n" /* it */ " italian italiano\n"
/* it */ " italian italiano\n" /* ja */ " japanese\n"
/* ja */ " japanese\n" /* rw */ " kinyarwanda\n"
/* rw */ " kinyarwanda\n" /* tlh */ " klingon tlhIngan\n"
/* tlh */ " klingon tlhIngan\n" /* ko */ " korean\n"
/* ko */ " korean\n" /* ku */ " kurdish\n"
/* ku */ " kurdish\n" /* lt */ " lithuanian lietuviu\n"
/* lt */ " lithuanian lietuviu\n" /* ms */ " malay\n"
/* ms */ " malay\n" /* es_MX */
/* es_MX */ " mexican mexican-spanish espanol-mejicano\n" " mexican mexican-spanish espanol-mejicano\n"
/* nn */ " norwegian nynorsk norsk\n" /* nn */ " norwegian nynorsk norsk\n"
/* pl */ " polish polski\n" /* pl */ " polish polski\n"
/* pt_PT */ " portuguese portugues\n" /* pt_PT */ " portuguese portugues\n"
/* ro */ " romanian\n" /* ro */ " romanian\n"
/* ru */ " russian russkiy\n" /* ru */ " russian russkiy\n"
/* gd */ " scottish scottish-gaelic ghaidhlig\n" /* gd */ " scottish scottish-gaelic ghaidhlig\n"
/* sr */ " serbian\n" /* sr */ " serbian\n"
/* sk */ " slovak\n" /* sk */ " slovak\n"
/* sl */ " slovenian slovensko\n" /* sl */ " slovenian slovensko\n"
/* es */ " spanish espanol\n" /* es */ " spanish espanol\n"
/* sw */ " swahili\n" /* sw */ " swahili\n"
/* sv */ " swedish svenska\n" /* sv */ " swedish svenska\n"
/* tl */ " tagalog\n" /* tl */ " tagalog\n"
/* ta */ " tamil\n" /* ta */ " tamil\n"
/* bo */ " tibetan\n" /* bo */ " tibetan\n"
/* th */ " thai\n" /* th */ " thai\n"
/* tr */ " turkish\n" /* tr */ " turkish\n"
/* uk */ " ukrainian\n" /* uk */ " ukrainian\n"
/* vi */ " vietnamese\n" /* vi */ " vietnamese\n"
/* wa */ " walloon walon\n" /* wa */ " walloon walon\n"
/* cy */ " welsh cymraeg\n" /* cy */ " welsh cymraeg\n"
"\n", "\n", prg);
prg);
} }
/* FIXME: Add accented characters to the descriptions */ /* FIXME: Add accented characters to the descriptions */
/* Show available locales: */ /* Show available locales: */
void show_locale_usage(FILE * f, const char * const prg) void show_locale_usage(FILE * f, const char *const prg)
{ {
fprintf(f, fprintf(f,
"\n" "\n"
"Usage: %s [--locale LOCALE]\n" "Usage: %s [--locale LOCALE]\n"
"\n" "\n"
"LOCALE may be one of:\n" "LOCALE may be one of:\n"
" C (English American English)\n" " C (English American English)\n"
" af_ZA (Afrikaans)\n" " af_ZA (Afrikaans)\n"
" ar_SA (Arabic)\n" " ar_SA (Arabic)\n"
" eu_ES (Baque Euskara)\n" " eu_ES (Baque Euskara)\n"
" be_BY (Belarusian Bielaruskaja)\n" " be_BY (Belarusian Bielaruskaja)\n"
" nb_NO (Bokmal)\n" " nb_NO (Bokmal)\n"
" pt_BR (Brazilian Brazilian Portuguese Portugues Brazilian)\n" " pt_BR (Brazilian Brazilian Portuguese Portugues Brazilian)\n"
" br_FR (Breton Brezhoneg)\n" " br_FR (Breton Brezhoneg)\n"
" en_GB (British British English)\n" " en_GB (British British English)\n"
" bg_BG (Bulgarian)\n" " bg_BG (Bulgarian)\n"
" ca_ES (Catalan Catala)\n" " ca_ES (Catalan Catala)\n"
" zh_CN (Chinese-Simplified)\n" " zh_CN (Chinese-Simplified)\n"
" zh_TW (Chinese-Traditional)\n" " zh_TW (Chinese-Traditional)\n"
" cs_CZ (Czech Cesky)\n" " cs_CZ (Czech Cesky)\n"
" da_DK (Danish Dansk)\n" " da_DK (Danish Dansk)\n"
" nl_NL (Dutch)\n" " nl_NL (Dutch)\n"
" fi_FI (Finnish Suomi)\n" " fi_FI (Finnish Suomi)\n"
" fo_FO (Faroese)\n" " fo_FO (Faroese)\n"
" fr_FR (French Francais)\n" " fr_FR (French Francais)\n"
" ga_IE (Irish Gaelic Gaidhlig)\n" " ga_IE (Irish Gaelic Gaidhlig)\n"
" gd_GB (Scottish Gaelic Ghaidhlig)\n" " gd_GB (Scottish Gaelic Ghaidhlig)\n"
" gl_ES (Galician Galego)\n" " gl_ES (Galician Galego)\n"
" gos_NL (Gronings Zudelk Veenkelonioals)\n" " gos_NL (Gronings Zudelk Veenkelonioals)\n"
" gu_IN (Gujarati)\n" " gu_IN (Gujarati)\n"
" de_DE (German Deutsch)\n" " de_DE (German Deutsch)\n"
" et_EE (Estonian)\n" " et_EE (Estonian)\n"
" el_GR (Greek)\n" " el_GR (Greek)\n"
" he_IL (Hebrew)\n" " he_IL (Hebrew)\n"
" hi_IN (Hindi)\n" " hi_IN (Hindi)\n"
" hr_HR (Croatian Hrvatski)\n" " hr_HR (Croatian Hrvatski)\n"
" hu_HU (Hungarian Magyar)\n" " hu_HU (Hungarian Magyar)\n"
" tlh (Klingon tlhIngan)\n" " tlh (Klingon tlhIngan)\n"
" is_IS (Icelandic Islenska)\n" " is_IS (Icelandic Islenska)\n"
" id_ID (Indonesian Bahasa Indonesia)\n" " id_ID (Indonesian Bahasa Indonesia)\n"
" it_IT (Italian Italiano)\n" " it_IT (Italian Italiano)\n"
" ja_JP (Japanese)\n" " ja_JP (Japanese)\n"
" ka_GE (Georgian)\n" " ka_GE (Georgian)\n"
" ko_KR (Korean)\n" " ko_KR (Korean)\n"
" ku_TR (Kurdish)\n" " ku_TR (Kurdish)\n"
" ms_MY (Malay)\n" " ms_MY (Malay)\n"
" lt_LT (Lithuanian Lietuviu)\n" " lt_LT (Lithuanian Lietuviu)\n"
" nn_NO (Norwegian Nynorsk Norsk)\n" " nn_NO (Norwegian Nynorsk Norsk)\n"
" pl_PL (Polish Polski)\n" " pl_PL (Polish Polski)\n"
" pt_PT (Portuguese Portugues)\n" " pt_PT (Portuguese Portugues)\n"
" ro_RO (Romanian)\n" " ro_RO (Romanian)\n"
" ru_RU (Russian Russkiy)\n" " ru_RU (Russian Russkiy)\n"
" rw_RW (Kinyarwanda)\n" " rw_RW (Kinyarwanda)\n"
" sk_SK (Slovak)\n" " sk_SK (Slovak)\n"
" sl_SI (Slovenian)\n" " sl_SI (Slovenian)\n"
" sq_AL (Albanian)\n" " sq_AL (Albanian)\n"
" sr_YU (Serbian)\n" " sr_YU (Serbian)\n"
" es_ES (Spanish Espanol)\n" " es_ES (Spanish Espanol)\n"
" es_MX (Mexican Mexican Spanish Espanol Mejicano)\n" " es_MX (Mexican Mexican Spanish Espanol Mejicano)\n"
" sw_TZ (Swahili)\n" " sw_TZ (Swahili)\n"
" sv_SE (Swedish Svenska)\n" " sv_SE (Swedish Svenska)\n"
" tl_PH (Tagalog)\n" " tl_PH (Tagalog)\n"
" bo_CN (Tibetan)\n" " bo_CN (Tibetan)\n"
" th_TH (Thai)\n" " th_TH (Thai)\n"
" tr_TR (Turkish)\n" " tr_TR (Turkish)\n"
" uk_UA (Ukrainian)\n" " uk_UA (Ukrainian)\n"
" vi_VN (Vietnamese)\n" " vi_VN (Vietnamese)\n"
" wa_BE (Walloon)\n" " wa_BE (Walloon)\n"
" cy_GB (Welsh Cymraeg)\n" " cy_GB (Welsh Cymraeg)\n" "\n", prg);
"\n",
prg);
} }
void setup_language(const char * const prg) void setup_language(const char *const prg)
{ {
// Justify this or delete it. It seems to make Tux Paint // Justify this or delete it. It seems to make Tux Paint
// violate the behavior documented by "man 7 locale". // violate the behavior documented by "man 7 locale".
#if 0 #if 0
if (langstr == NULL && getenv("LANG")) if (langstr == NULL && getenv("LANG"))
{ {
if(!strncasecmp(getenv("LANG"), "lt_LT", 5)) if (!strncasecmp(getenv("LANG"), "lt_LT", 5))
set_langstr("lithuanian"); set_langstr("lithuanian");
if(!strncasecmp(getenv("LANG"), "pl_PL", 5)) if (!strncasecmp(getenv("LANG"), "pl_PL", 5))
set_langstr("polish"); set_langstr("polish");
} }
#endif #endif
if (langstr != NULL) if (langstr != NULL)
{
int i =
sizeof language_to_locale_array / sizeof language_to_locale_array[0];
const char *locale = NULL;
while (i--)
{ {
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0]; if (strcmp(langstr, language_to_locale_array[i].language))
const char *locale = NULL; continue;
locale = language_to_locale_array[i].locale;
while(i--) break;
{
if (strcmp(langstr, language_to_locale_array[i].language))
continue;
locale = language_to_locale_array[i].locale;
break;
}
if (!locale)
{
if (strcmp(langstr, "help") == 0 || strcmp(langstr, "list") == 0)
{
show_lang_usage(stdout, prg);
//free(langstr); // pointless
exit(0);
}
else
{
fprintf(stderr, "%s is an invalid language\n", langstr);
show_lang_usage(stderr, prg);
//free(langstr); // pointless
exit(1);
}
}
{
char *s;
ssize_t len;
len = strlen("LANGUAGE=")+strlen(locale)+1;
s = malloc(len);
snprintf(s, len, "LANGUAGE=%s", locale);
putenv(s);
len = strlen("LC_ALL=")+strlen(locale)+1;
s = malloc(len);
snprintf(s, len, "LC_ALL=%s", locale);
putenv(s);
}
setlocale(LC_ALL, "");
free(langstr);
} }
if (!locale)
{
if (strcmp(langstr, "help") == 0 || strcmp(langstr, "list") == 0)
{
show_lang_usage(stdout, prg);
//free(langstr); // pointless
exit(0);
}
else
{
fprintf(stderr, "%s is an invalid language\n", langstr);
show_lang_usage(stderr, prg);
//free(langstr); // pointless
exit(1);
}
}
{
char *s;
ssize_t len;
len = strlen("LANGUAGE=") + strlen(locale) + 1;
s = malloc(len);
snprintf(s, len, "LANGUAGE=%s", locale);
putenv(s);
len = strlen("LC_ALL=") + strlen(locale) + 1;
s = malloc(len);
snprintf(s, len, "LC_ALL=%s", locale);
putenv(s);
}
setlocale(LC_ALL, "");
free(langstr);
}
set_current_language(); set_current_language();
} }
// handle --locale arg // handle --locale arg
void do_locale_option(const char * const arg) void do_locale_option(const char *const arg)
{ {
int len = strlen(arg) + 6; int len = strlen(arg) + 6;
char *str = malloc(len); char *str = malloc(len);
@ -573,5 +571,5 @@ void do_locale_option(const char * const arg)
// We leak "str" because it can not be freed. It is now part // We leak "str" because it can not be freed. It is now part
// of the environment. If it were local, the environment would // of the environment. If it were local, the environment would
// get corrupted. // get corrupted.
setlocale(LC_ALL, ""); /* use arg ? */ setlocale(LC_ALL, ""); /* use arg ? */
} }

View file

@ -18,78 +18,80 @@
/* Possible languages: */ /* Possible languages: */
enum { enum
LANG_AF, /* Afrikaans */ {
LANG_AR, /* Arabic */ LANG_AF, /* Afrikaans */
LANG_BE, /* Belarusian */ LANG_AR, /* Arabic */
LANG_BG, /* Bulgarian */ LANG_BE, /* Belarusian */
LANG_BO, /* Tibetan */ LANG_BG, /* Bulgarian */
LANG_BR, /* Breton */ LANG_BO, /* Tibetan */
LANG_CA, /* Catalan */ LANG_BR, /* Breton */
LANG_CS, /* Czech */ LANG_CA, /* Catalan */
LANG_CY, /* Welsh */ LANG_CS, /* Czech */
LANG_DA, /* Danish */ LANG_CY, /* Welsh */
LANG_DE, /* German */ LANG_DA, /* Danish */
LANG_EL, /* Greek */ LANG_DE, /* German */
LANG_EN, /* English (American) (DEFAULT) */ LANG_EL, /* Greek */
LANG_EN_GB, /* English (British) */ LANG_EN, /* English (American) (DEFAULT) */
LANG_ES, /* Spanish */ LANG_EN_GB, /* English (British) */
LANG_ES_MX, /* Spanish (Mexican) */ LANG_ES, /* Spanish */
LANG_ET, /* Estonian */ LANG_ES_MX, /* Spanish (Mexican) */
LANG_EU, /* Basque */ LANG_ET, /* Estonian */
LANG_FI, /* Finnish */ LANG_EU, /* Basque */
LANG_FO, /* Faroese */ LANG_FI, /* Finnish */
LANG_FR, /* French */ LANG_FO, /* Faroese */
LANG_GA, /* Irish Gaelic */ LANG_FR, /* French */
LANG_GD, /* Scottish Gaelic */ LANG_GA, /* Irish Gaelic */
LANG_GL, /* Galician */ LANG_GD, /* Scottish Gaelic */
LANG_GR, /* Gronings */ LANG_GL, /* Galician */
LANG_GU, /* Gujarati */ LANG_GR, /* Gronings */
LANG_HE, /* Hebrew */ LANG_GU, /* Gujarati */
LANG_HI, /* Hindi */ LANG_HE, /* Hebrew */
LANG_HR, /* Croatian */ LANG_HI, /* Hindi */
LANG_HU, /* Hungarian */ LANG_HR, /* Croatian */
LANG_I_KLINGON_ROMANIZED, /* Klingon (Romanized) */ LANG_HU, /* Hungarian */
LANG_ID, /* Indonesian */ LANG_I_KLINGON_ROMANIZED, /* Klingon (Romanized) */
LANG_IS, /* Icelandic */ LANG_ID, /* Indonesian */
LANG_IT, /* Italian */ LANG_IS, /* Icelandic */
LANG_JA, /* Japanese */ LANG_IT, /* Italian */
LANG_KA, /* Georgian */ LANG_JA, /* Japanese */
LANG_KO, /* Korean */ LANG_KA, /* Georgian */
LANG_KU, /* Kurdish */ LANG_KO, /* Korean */
LANG_LT, /* Lithuanian */ LANG_KU, /* Kurdish */
LANG_MS, /* Malay */ LANG_LT, /* Lithuanian */
LANG_NB, /* Norwegian Bokmal */ LANG_MS, /* Malay */
LANG_NL, /* Dutch */ LANG_NB, /* Norwegian Bokmal */
LANG_NN, /* Norwegian Nynorsk */ LANG_NL, /* Dutch */
LANG_PL, /* Polish */ LANG_NN, /* Norwegian Nynorsk */
LANG_PT_BR, /* Portuguese (Brazilian) */ LANG_PL, /* Polish */
LANG_PT_PT, /* Portuguese (Portugal) */ LANG_PT_BR, /* Portuguese (Brazilian) */
LANG_RO, /* Romanian */ LANG_PT_PT, /* Portuguese (Portugal) */
LANG_RU, /* Russian */ LANG_RO, /* Romanian */
LANG_RW, /* Kinyarwanda */ LANG_RU, /* Russian */
LANG_SK, /* Slovak */ LANG_RW, /* Kinyarwanda */
LANG_SL, /* Slovenian */ LANG_SK, /* Slovak */
LANG_SQ, /* Albanian */ LANG_SL, /* Slovenian */
LANG_SR, /* Serbian */ LANG_SQ, /* Albanian */
LANG_SV, /* Swedish */ LANG_SR, /* Serbian */
LANG_SW, /* Swahili */ LANG_SV, /* Swedish */
LANG_TA, /* Tamil */ LANG_SW, /* Swahili */
LANG_TH, /* Thai */ LANG_TA, /* Tamil */
LANG_TL, /* Tagalog */ LANG_TH, /* Thai */
LANG_TR, /* Turkish */ LANG_TL, /* Tagalog */
LANG_UK, /* Ukrainian */ LANG_TR, /* Turkish */
LANG_VI, /* Vietnamese */ LANG_UK, /* Ukrainian */
LANG_WA, /* Walloon */ LANG_VI, /* Vietnamese */
LANG_ZH_CN, /* Chinese (Simplified) */ LANG_WA, /* Walloon */
LANG_ZH_TW, /* Chinese (Traditional) */ LANG_ZH_CN, /* Chinese (Simplified) */
LANG_ZH_TW, /* Chinese (Traditional) */
NUM_LANGS NUM_LANGS
}; };
/* Types: */ /* Types: */
typedef struct language_to_locale_struct { typedef struct language_to_locale_struct
{
const char *language; const char *language;
const char *locale; const char *locale;
} language_to_locale_struct; } language_to_locale_struct;
@ -97,13 +99,13 @@ typedef struct language_to_locale_struct {
/* Globals: */ /* Globals: */
extern const char * lang_prefixes[NUM_LANGS]; extern const char *lang_prefixes[NUM_LANGS];
extern int lang_use_own_font[]; extern int lang_use_own_font[];
extern int lang_use_right_to_left[]; extern int lang_use_right_to_left[];
extern char * langstr; extern char *langstr;
extern int need_own_font; extern int need_own_font;
extern int need_right_to_left; extern int need_right_to_left;
extern const char * lang_prefix; extern const char *lang_prefix;
extern const language_to_locale_struct language_to_locale_array[]; extern const language_to_locale_struct language_to_locale_array[];
@ -112,11 +114,10 @@ extern const language_to_locale_struct language_to_locale_array[];
void set_langstr(const char *s); void set_langstr(const char *s);
void set_current_language(void); void set_current_language(void);
void show_lang_usage(FILE * f, const char * const prg); void show_lang_usage(FILE * f, const char *const prg);
void show_locale_usage(FILE * f, const char * const prg); void show_locale_usage(FILE * f, const char *const prg);
void setup_language(const char * const prg); void setup_language(const char *const prg);
void do_locale_option(const char * const arg); void do_locale_option(const char *const arg);
#endif #endif

View file

@ -24,6 +24,4 @@
#include "SDL.h" #include "SDL.h"
const char* SurfacePrint (SDL_Surface *surface, int showDialog); const char *SurfacePrint(SDL_Surface * surface, int showDialog);

View file

@ -30,25 +30,26 @@
/* What tools are available: */ /* What tools are available: */
enum { enum
{
MAGIC_FILL, MAGIC_FILL,
MAGIC_GRASS, MAGIC_GRASS,
MAGIC_LARGEBRICK, MAGIC_LARGEBRICK,
MAGIC_SMALLBRICK, MAGIC_SMALLBRICK,
MAGIC_RAINBOW, MAGIC_RAINBOW,
MAGIC_SPARKLES, MAGIC_SPARKLES,
MAGIC_BLUR, MAGIC_BLUR,
MAGIC_SMUDGE, MAGIC_SMUDGE,
MAGIC_FADE, MAGIC_FADE,
MAGIC_DARKEN, MAGIC_DARKEN,
MAGIC_CHALK, MAGIC_CHALK,
MAGIC_BLOCKS, MAGIC_BLOCKS,
MAGIC_NEGATIVE, MAGIC_NEGATIVE,
MAGIC_TINT, MAGIC_TINT,
@ -65,14 +66,14 @@ enum {
/* Need for the color selector: */ /* Need for the color selector: */
const int magic_colors[] = { const int magic_colors[] = {
COLORSEL_ENABLE, // fill COLORSEL_ENABLE, // fill
COLORSEL_ENABLE, // grass COLORSEL_ENABLE, // grass
COLORSEL_ENABLE, // large bricks COLORSEL_ENABLE, // large bricks
COLORSEL_ENABLE, // small bricks COLORSEL_ENABLE, // small bricks
COLORSEL_DISABLE, COLORSEL_DISABLE,
COLORSEL_ENABLE, // sparkles COLORSEL_ENABLE, // sparkles
COLORSEL_DISABLE, COLORSEL_DISABLE,
COLORSEL_DISABLE, COLORSEL_DISABLE,
@ -84,7 +85,7 @@ const int magic_colors[] = {
COLORSEL_DISABLE, COLORSEL_DISABLE,
COLORSEL_DISABLE, COLORSEL_DISABLE,
COLORSEL_ENABLE, // tint COLORSEL_ENABLE, // tint
COLORSEL_DISABLE, COLORSEL_DISABLE,
COLORSEL_DISABLE, COLORSEL_DISABLE,
@ -95,7 +96,7 @@ const int magic_colors[] = {
/* Magic tool names: */ /* Magic tool names: */
const char * const magic_names[NUM_MAGICS] = { const char *const magic_names[NUM_MAGICS] = {
gettext_noop("Fill"), gettext_noop("Fill"),
gettext_noop("Grass"), gettext_noop("Grass"),
@ -127,30 +128,33 @@ const char * const magic_names[NUM_MAGICS] = {
/* Some text to write when each tool is selected: */ /* Some text to write when each tool is selected: */
const char * const magic_tips[NUM_MAGICS] = { const char *const magic_tips[NUM_MAGICS] = {
gettext_noop("Click in the picture to fill that area with color."), gettext_noop("Click in the picture to fill that area with color."),
gettext_noop("Click and move to draw grass. Dont forget the dirt!"), gettext_noop("Click and move to draw grass. Dont forget the dirt!"),
gettext_noop("Click and move to draw large bricks."), gettext_noop("Click and move to draw large bricks."),
gettext_noop("Click and move to draw small bricks."), gettext_noop("Click and move to draw small bricks."),
gettext_noop("You can draw in rainbow colors!"), gettext_noop("You can draw in rainbow colors!"),
gettext_noop("Click and move to draw sparkles."), gettext_noop("Click and move to draw sparkles."),
gettext_noop("Click and move the mouse around to blur the picture."), gettext_noop("Click and move the mouse around to blur the picture."),
gettext_noop("Click and move the mouse around to smudge the picture."), gettext_noop("Click and move the mouse around to smudge the picture."),
gettext_noop("Click and move to fade the colors."), gettext_noop("Click and move to fade the colors."),
gettext_noop("Click and move to darken the colors."), gettext_noop("Click and move to darken the colors."),
gettext_noop("Click and move the mouse around to turn the picture into a chalk drawing."), gettext_noop
("Click and move the mouse around to turn the picture into a chalk drawing."),
gettext_noop("Click and move the mouse around to make the picture blocky."), gettext_noop("Click and move the mouse around to make the picture blocky."),
gettext_noop("Click and move the mouse around to draw a negative."), gettext_noop("Click and move the mouse around to draw a negative."),
gettext_noop("Click and move the mouse around to change the pictures color."), gettext_noop
("Click and move the mouse around to change the pictures color."),
gettext_noop("Click and move the mouse around to make the picture drip."), gettext_noop("Click and move the mouse around to make the picture drip."),
gettext_noop("Click and move the mouse around to turn the picture into a cartoon."), gettext_noop
("Click and move the mouse around to turn the picture into a cartoon."),
gettext_noop("Click to make a mirror image."), gettext_noop("Click to make a mirror image."),
gettext_noop("Click to flip the picture upside-down."), gettext_noop("Click to flip the picture upside-down."),
@ -159,16 +163,16 @@ const char * const magic_tips[NUM_MAGICS] = {
/* Tool icon filenames: */ /* Tool icon filenames: */
const char * const magic_img_fnames[NUM_MAGICS] = { const char *const magic_img_fnames[NUM_MAGICS] = {
DATA_PREFIX "images/magic/fill.png", DATA_PREFIX "images/magic/fill.png",
DATA_PREFIX "images/magic/grass.png", DATA_PREFIX "images/magic/grass.png",
DATA_PREFIX "images/magic/largebrick.png", DATA_PREFIX "images/magic/largebrick.png",
DATA_PREFIX "images/magic/smallbrick.png", DATA_PREFIX "images/magic/smallbrick.png",
DATA_PREFIX "images/magic/rainbow.png", DATA_PREFIX "images/magic/rainbow.png",
DATA_PREFIX "images/magic/sparkles.png", DATA_PREFIX "images/magic/sparkles.png",
DATA_PREFIX "images/magic/blur.png", DATA_PREFIX "images/magic/blur.png",
DATA_PREFIX "images/magic/smudge.png", DATA_PREFIX "images/magic/smudge.png",
@ -177,10 +181,10 @@ const char * const magic_img_fnames[NUM_MAGICS] = {
DATA_PREFIX "images/magic/chalk.png", DATA_PREFIX "images/magic/chalk.png",
DATA_PREFIX "images/magic/blocks.png", DATA_PREFIX "images/magic/blocks.png",
DATA_PREFIX "images/magic/negative.png", DATA_PREFIX "images/magic/negative.png",
DATA_PREFIX "images/magic/tint.png", DATA_PREFIX "images/magic/tint.png",
DATA_PREFIX "images/magic/drip.png", DATA_PREFIX "images/magic/drip.png",
DATA_PREFIX "images/magic/cartoon.png", DATA_PREFIX "images/magic/cartoon.png",
@ -222,4 +226,3 @@ const int rainbow_hexes[NUM_RAINBOW_COLORS][3] = {
{255, 0, 128}, {255, 0, 128},
{255, 0, 64} {255, 0, 64}
}; };

View file

@ -34,169 +34,177 @@
/* Draw a single pixel into the surface: */ /* Draw a single pixel into the surface: */
void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel) void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
{ {
Uint8 * p; Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */ /* Assuming the X/Y values are within the bounds of this surface... */
if (likely( likely((unsigned)x<(unsigned)surface->w) && likely((unsigned)y<(unsigned)surface->h) )) if (likely
{ (likely((unsigned) x < (unsigned) surface->w)
// Set a pointer to the exact location in memory of the pixel && likely((unsigned) y < (unsigned) surface->h)))
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start: beginning of RAM */ {
(y * surface->pitch) + /* Go down Y lines */ // Set a pointer to the exact location in memory of the pixel
x); /* Go in X pixels */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
x); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM /* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */ * to the pixel value sent in: */
*p = pixel; *p = pixel;
} }
} }
/* Draw a single pixel into the surface: */ /* Draw a single pixel into the surface: */
void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel) void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
{ {
Uint8 * p; Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */ /* Assuming the X/Y values are within the bounds of this surface... */
if (likely( likely((unsigned)x<(unsigned)surface->w) && likely((unsigned)y<(unsigned)surface->h) )) if (likely
{ (likely((unsigned) x < (unsigned) surface->w)
// Set a pointer to the exact location in memory of the pixel && likely((unsigned) y < (unsigned) surface->h)))
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start: beginning of RAM */ {
(y * surface->pitch) + /* Go down Y lines */ // Set a pointer to the exact location in memory of the pixel
(x * 2)); /* Go in X pixels */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 2)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM /* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */ * to the pixel value sent in: */
*(Uint16 *)p = pixel; *(Uint16 *) p = pixel;
} }
} }
/* Draw a single pixel into the surface: */ /* Draw a single pixel into the surface: */
void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel) void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
{ {
Uint8 * p; Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */ /* Assuming the X/Y values are within the bounds of this surface... */
if (likely( likely((unsigned)x<(unsigned)surface->w) && likely((unsigned)y<(unsigned)surface->h) )) if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 3)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
{ {
// Set a pointer to the exact location in memory of the pixel p[0] = (pixel >> 16) & 0xff;
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start: beginning of RAM */ p[1] = (pixel >> 8) & 0xff;
(y * surface->pitch) + /* Go down Y lines */ p[2] = pixel & 0xff;
(x * 3)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
} }
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
}
} }
/* Draw a single pixel into the surface: */ /* Draw a single pixel into the surface: */
void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel) void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
{ {
Uint8 * p; Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */ /* Assuming the X/Y values are within the bounds of this surface... */
if (likely( likely((unsigned)x<(unsigned)surface->w) && likely((unsigned)y<(unsigned)surface->h) )) if (likely
{ (likely((unsigned) x < (unsigned) surface->w)
// Set a pointer to the exact location in memory of the pixel && likely((unsigned) y < (unsigned) surface->h)))
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start: beginning of RAM */ {
(y * surface->pitch) + /* Go down Y lines */ // Set a pointer to the exact location in memory of the pixel
(x * 4)); /* Go in X pixels */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
(y * surface->pitch) + /* Go down Y lines */
(x * 4)); /* Go in X pixels */
/* Set the (correctly-sized) piece of data in the surface's RAM /* Set the (correctly-sized) piece of data in the surface's RAM
* to the pixel value sent in: */ * to the pixel value sent in: */
*(Uint32 *)p = pixel; // 32-bit display *(Uint32 *) p = pixel; // 32-bit display
} }
} }
/* Get a pixel: */ /* Get a pixel: */
Uint32 getpixel8(SDL_Surface * surface, int x, int y) Uint32 getpixel8(SDL_Surface * surface, int x, int y)
{ {
Uint8 * p; Uint8 *p;
/* get the X/Y values within the bounds of this surface */ /* get the X/Y values within the bounds of this surface */
if (unlikely( (unsigned)x > (unsigned)surface->w - 1u )) if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
x = (x<0) ? 0 : surface->w - 1; x = (x < 0) ? 0 : surface->w - 1;
if (unlikely( (unsigned)y > (unsigned)surface->h - 1u )) if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
y = (y<0) ? 0 : surface->h - 1; y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel /* Set a pointer to the exact location in memory of the pixel
in question: */ in question: */
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start at top of RAM */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */ (y * surface->pitch) + /* Go down Y lines */
x); /* Go in X pixels */ x); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the /* Return the correctly-sized piece of data containing the
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
* RGB value) */ * RGB value) */
return(*p); return (*p);
} }
/* Get a pixel: */ /* Get a pixel: */
Uint32 getpixel16(SDL_Surface * surface, int x, int y) Uint32 getpixel16(SDL_Surface * surface, int x, int y)
{ {
Uint8 * p; Uint8 *p;
/* get the X/Y values within the bounds of this surface */ /* get the X/Y values within the bounds of this surface */
if (unlikely( (unsigned)x > (unsigned)surface->w - 1u )) if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
x = (x<0) ? 0 : surface->w - 1; x = (x < 0) ? 0 : surface->w - 1;
if (unlikely( (unsigned)y > (unsigned)surface->h - 1u )) if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
y = (y<0) ? 0 : surface->h - 1; y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel /* Set a pointer to the exact location in memory of the pixel
in question: */ in question: */
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start at top of RAM */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */ (y * surface->pitch) + /* Go down Y lines */
(x * 2)); /* Go in X pixels */ (x * 2)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the /* Return the correctly-sized piece of data containing the
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
* RGB value) */ * RGB value) */
return(*(Uint16 *)p); return (*(Uint16 *) p);
} }
/* Get a pixel: */ /* Get a pixel: */
Uint32 getpixel24(SDL_Surface * surface, int x, int y) Uint32 getpixel24(SDL_Surface * surface, int x, int y)
{ {
Uint8 * p; Uint8 *p;
Uint32 pixel; Uint32 pixel;
/* get the X/Y values within the bounds of this surface */ /* get the X/Y values within the bounds of this surface */
if (unlikely( (unsigned)x > (unsigned)surface->w - 1u )) if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
x = (x<0) ? 0 : surface->w - 1; x = (x < 0) ? 0 : surface->w - 1;
if (unlikely( (unsigned)y > (unsigned)surface->h - 1u )) if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
y = (y<0) ? 0 : surface->h - 1; y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel /* Set a pointer to the exact location in memory of the pixel
in question: */ in question: */
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start at top of RAM */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */ (y * surface->pitch) + /* Go down Y lines */
(x * 3)); /* Go in X pixels */ (x * 3)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the /* Return the correctly-sized piece of data containing the
@ -216,33 +224,34 @@ Uint32 getpixel24(SDL_Surface * surface, int x, int y)
/* Get a pixel: */ /* Get a pixel: */
Uint32 getpixel32(SDL_Surface * surface, int x, int y) Uint32 getpixel32(SDL_Surface * surface, int x, int y)
{ {
Uint8 * p; Uint8 *p;
/* get the X/Y values within the bounds of this surface */ /* get the X/Y values within the bounds of this surface */
if (unlikely( (unsigned)x > (unsigned)surface->w - 1u )) if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
x = (x<0) ? 0 : surface->w - 1; x = (x < 0) ? 0 : surface->w - 1;
if (unlikely( (unsigned)y > (unsigned)surface->h - 1u )) if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
y = (y<0) ? 0 : surface->h - 1; y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel /* Set a pointer to the exact location in memory of the pixel
in question: */ in question: */
p = (Uint8 *) (((Uint8 *)surface->pixels) + /* Start at top of RAM */ p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
(y * surface->pitch) + /* Go down Y lines */ (y * surface->pitch) + /* Go down Y lines */
(x * 4)); /* Go in X pixels */ (x * 4)); /* Go in X pixels */
/* Return the correctly-sized piece of data containing the /* Return the correctly-sized piece of data containing the
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
* RGB value) */ * RGB value) */
return *(Uint32 *)p; // 32-bit display return *(Uint32 *) p; // 32-bit display
} }
void (*putpixels[])(SDL_Surface *, int, int, Uint32) = { void (*putpixels[]) (SDL_Surface *, int, int, Uint32) =
putpixel8, putpixel8, putpixel16, putpixel24, putpixel32 }; {
putpixel8, putpixel8, putpixel16, putpixel24, putpixel32};
Uint32 (*getpixels[])(SDL_Surface *, int, int) = { Uint32(*getpixels[])(SDL_Surface *, int, int) =
getpixel8, getpixel8, getpixel16, getpixel24, getpixel32 }; {
getpixel8, getpixel8, getpixel16, getpixel24, getpixel32};

View file

@ -37,14 +37,13 @@ void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel);
void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel); void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel);
void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel); void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel);
extern void (*putpixels[])(SDL_Surface *, int, int, Uint32); extern void (*putpixels[]) (SDL_Surface *, int, int, Uint32);
Uint32 getpixel8(SDL_Surface * surface, int x, int y); Uint32 getpixel8(SDL_Surface * surface, int x, int y);
Uint32 getpixel16(SDL_Surface * surface, int x, int y); Uint32 getpixel16(SDL_Surface * surface, int x, int y);
Uint32 getpixel24(SDL_Surface * surface, int x, int y); Uint32 getpixel24(SDL_Surface * surface, int x, int y);
Uint32 getpixel32(SDL_Surface * surface, int x, int y); Uint32 getpixel32(SDL_Surface * surface, int x, int y);
extern Uint32 (*getpixels[])(SDL_Surface *, int, int); extern Uint32(*getpixels[]) (SDL_Surface *, int, int);
#endif #endif

View file

@ -2,61 +2,61 @@
#include "debug.h" #include "debug.h"
#ifndef NOSOUND #ifndef NOSOUND
Mix_Chunk * sounds[NUM_SOUNDS]; Mix_Chunk *sounds[NUM_SOUNDS];
#endif #endif
int mute, use_sound; int mute, use_sound;
int old_sound[4] = {-1, -1, -1, -1}; int old_sound[4] = { -1, -1, -1, -1 };
void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y) void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
int y)
{ {
#ifndef NOSOUND #ifndef NOSOUND
int left, dist; int left, dist;
if (!mute && use_sound && s != SND_NONE) if (!mute && use_sound && s != SND_NONE)
{
if (override || !Mix_Playing(chan))
{ {
if (override || !Mix_Playing(chan)) Mix_PlayChannel(chan, sounds[s], 0);
{
Mix_PlayChannel(chan, sounds[s], 0);
old_sound[chan] = s; old_sound[chan] = s;
}
if (old_sound[chan] == s)
{
if (y == SNDDIST_NEAR)
dist = 0;
else
{
if (y < 0)
y = 0;
else if (y >= screen->h - 1)
y = screen->h - 1;
dist = (255 * ((screen->h - 1) - y)) / (screen->h - 1);
}
if (x == SNDPOS_LEFT)
left = 255 - dist;
else if (x == SNDPOS_CENTER)
left = (255 - dist) / 2;
else if (x == SNDPOS_RIGHT)
left = 0;
else
{
if (x < 0)
x = 0;
else if (x >= screen->w)
x = screen->w - 1;
left = ((255 - dist) * ((screen->w - 1) - x)) / (screen->w - 1);
}
Mix_SetPanning(chan, left, (255 - dist) - left);
}
} }
if (old_sound[chan] == s)
{
if (y == SNDDIST_NEAR)
dist = 0;
else
{
if (y < 0)
y = 0;
else if (y >= screen->h - 1)
y = screen->h - 1;
dist = (255 * ((screen->h - 1) - y)) / (screen->h - 1);
}
if (x == SNDPOS_LEFT)
left = 255 - dist;
else if (x == SNDPOS_CENTER)
left = (255 - dist) / 2;
else if (x == SNDPOS_RIGHT)
left = 0;
else
{
if (x < 0)
x = 0;
else if (x >= screen->w)
x = screen->w - 1;
left = ((255 - dist) * ((screen->w - 1) - x)) / (screen->w - 1);
}
Mix_SetPanning(chan, left, (255 - dist) - left);
}
}
#endif #endif
} }

View file

@ -11,10 +11,10 @@
#define SNDDIST_NEAR -999 #define SNDDIST_NEAR -999
extern Mix_Chunk * sounds[NUM_SOUNDS]; extern Mix_Chunk *sounds[NUM_SOUNDS];
extern int mute, use_sound; extern int mute, use_sound;
void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y); void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
int y);
#endif #endif

View file

@ -31,7 +31,7 @@
#include "progressbar.h" #include "progressbar.h"
#include "debug.h" #include "debug.h"
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)
@ -41,33 +41,32 @@ void show_progress_bar(SDL_Surface * screen)
static Uint32 oldtime; static Uint32 oldtime;
Uint32 newtime; Uint32 newtime;
if(progress_bar_disabled) if (progress_bar_disabled)
return; return;
newtime = SDL_GetTicks(); newtime = SDL_GetTicks();
if(newtime > oldtime+15) // trying not to eat some serious CPU time! if (newtime > oldtime + 15) // trying not to eat some serious CPU time!
{
for (x = 0; x < screen->w; x = x + 65)
{ {
for (x = 0; x < screen->w; x = x + 65) src.x = 65 - (prog_bar_ctr % 65);
{ src.y = 0;
src.x = 65 - (prog_bar_ctr % 65); src.w = 65;
src.y = 0; src.h = 24;
src.w = 65;
src.h = 24;
dest.x = x; dest.x = x;
dest.y = screen->h - 24; dest.y = screen->h - 24;
SDL_BlitSurface(img_progress, &src, screen, &dest); SDL_BlitSurface(img_progress, &src, screen, &dest);
}
prog_bar_ctr++;
SDL_UpdateRect(screen, 0, screen->h - 24, screen->w, 24);
} }
prog_bar_ctr++;
SDL_UpdateRect(screen, 0, screen->h - 24, screen->w, 24);
}
oldtime = newtime; oldtime = newtime;
/* FIXME: RESURRECT THIS (bjk 2006.02.18) */ /* FIXME: RESURRECT THIS (bjk 2006.02.18) */
//eat_sdl_events(); //eat_sdl_events();
} }

View file

@ -33,10 +33,9 @@
#include "SDL.h" #include "SDL.h"
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);
#endif #endif

View file

@ -30,18 +30,16 @@
#include "rgblinear.h" #include "rgblinear.h"
#include "debug.h" #include "debug.h"
unsigned char linear_to_sRGB (float linear) unsigned char linear_to_sRGB(float linear)
{ {
unsigned slot; unsigned slot;
slot = linear*4096.0 + 0.5; slot = linear * 4096.0 + 0.5;
if(slot>4095) if (slot > 4095)
{ {
if(linear>0.5) if (linear > 0.5)
slot = 4095; slot = 4095;
else else
slot = 0; slot = 0;
} }
return linear_to_sRGB_table[slot]; return linear_to_sRGB_table[slot];
} }

View file

@ -306,10 +306,8 @@ static const unsigned char linear_to_sRGB_table[4096] =
"\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe" "\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe" "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff" "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
;
unsigned char linear_to_sRGB (float linear) FUNCTION; unsigned char linear_to_sRGB(float linear) FUNCTION;
#endif #endif

View file

@ -31,7 +31,8 @@
/* What shapes are available: */ /* What shapes are available: */
enum { enum
{
SHAPE_SQUARE, SHAPE_SQUARE,
SHAPE_SQUARE_FILL, SHAPE_SQUARE_FILL,
SHAPE_RECTANGLE, SHAPE_RECTANGLE,
@ -53,60 +54,60 @@ enum {
/* How many sides do they have? */ /* How many sides do they have? */
const int shape_sides[NUM_SHAPES] = { const int shape_sides[NUM_SHAPES] = {
4, /* Square */ 4, /* Square */
4, /* Square */ 4, /* Square */
4, /* Rectangle */ 4, /* Rectangle */
4, /* Rectangle */ 4, /* Rectangle */
72, /* Circle */ 72, /* Circle */
72, /* Circle */ 72, /* Circle */
72, /* Ellipse */ 72, /* Ellipse */
72, /* Ellipse */ 72, /* Ellipse */
3, /* Triangle */ 3, /* Triangle */
3, /* Triangle */ 3, /* Triangle */
5, /* Pentagon */ 5, /* Pentagon */
5, /* Pentagon */ 5, /* Pentagon */
4, /* Rhombus */ 4, /* Rhombus */
4 /* Rhombus */ 4 /* Rhombus */
}; };
/* Which shapes are 1:1 aspect? */ /* Which shapes are 1:1 aspect? */
const int shape_locked[NUM_SHAPES] = { const int shape_locked[NUM_SHAPES] = {
1, /* Square */ 1, /* Square */
1, /* Square */ 1, /* Square */
0, /* Rectangle */ 0, /* Rectangle */
0, /* Rectangle */ 0, /* Rectangle */
1, /* Circle */ 1, /* Circle */
1, /* Circle */ 1, /* Circle */
0, /* Ellipse */ 0, /* Ellipse */
0, /* Ellipse */ 0, /* Ellipse */
0, /* Triangle */ 0, /* Triangle */
0, /* Triangle */ 0, /* Triangle */
0, /* Pentagon */ 0, /* Pentagon */
0, /* Pentagon */ 0, /* Pentagon */
0, /* Rhombus */ 0, /* Rhombus */
0 /* Rhombus */ 0 /* Rhombus */
}; };
/* Which shapes are filled? */ /* Which shapes are filled? */
const int shape_filled[NUM_SHAPES] = { const int shape_filled[NUM_SHAPES] = {
0, /* Square */ 0, /* Square */
1, /* Square */ 1, /* Square */
0, /* Rectangle */ 0, /* Rectangle */
1, /* Rectangle */ 1, /* Rectangle */
0, /* Circle */ 0, /* Circle */
1, /* Circle */ 1, /* Circle */
0, /* Ellipse */ 0, /* Ellipse */
1, /* Ellipse */ 1, /* Ellipse */
0, /* Triangle */ 0, /* Triangle */
1, /* Triangle */ 1, /* Triangle */
0, /* Pentagon */ 0, /* Pentagon */
1, /* Pentagon */ 1, /* Pentagon */
0, /* Rhombus */ 0, /* Rhombus */
1 /* Rhombus */ 1 /* Rhombus */
}; };
@ -114,46 +115,46 @@ const int shape_filled[NUM_SHAPES] = {
/* Initial angles for shapes: */ /* Initial angles for shapes: */
const int shape_init_ang[NUM_SHAPES] = { const int shape_init_ang[NUM_SHAPES] = {
45, /* Square */ 45, /* Square */
45, /* Square */ 45, /* Square */
45, /* Rectangle */ 45, /* Rectangle */
45, /* Rectangle */ 45, /* Rectangle */
0, /* Circle */ 0, /* Circle */
0, /* Circle */ 0, /* Circle */
0, /* Ellipse */ 0, /* Ellipse */
0, /* Ellipse */ 0, /* Ellipse */
210, /* Triangle */ 210, /* Triangle */
210, /* Triangle */ 210, /* Triangle */
162, /* Pentagon */ 162, /* Pentagon */
162, /* Pentagon */ 162, /* Pentagon */
0, /* Rhombus */ 0, /* Rhombus */
0 /* Rhombus */ 0 /* Rhombus */
}; };
/* Shapes that don't make sense rotating (e.g., circles): */ /* Shapes that don't make sense rotating (e.g., circles): */
const int shape_no_rotate[NUM_SHAPES] = { const int shape_no_rotate[NUM_SHAPES] = {
0, /* Square */ 0, /* Square */
0, /* Square */ 0, /* Square */
0, /* Rectangle */ 0, /* Rectangle */
0, /* Rectangle */ 0, /* Rectangle */
1, /* Circle */ 1, /* Circle */
1, /* Circle */ 1, /* Circle */
0, /* Ellipse */ 0, /* Ellipse */
0, /* Ellipse */ 0, /* Ellipse */
0, /* Triangle */ 0, /* Triangle */
0, /* Triangle */ 0, /* Triangle */
0, /* Pentagon */ 0, /* Pentagon */
0, /* Pentagon */ 0, /* Pentagon */
0, /* Rhombus */ 0, /* Rhombus */
0 /* Rhombus */ 0 /* Rhombus */
}; };
/* Shape names: */ /* Shape names: */
const char * const shape_names[NUM_SHAPES] = { const char *const shape_names[NUM_SHAPES] = {
gettext_noop("Square"), gettext_noop("Square"),
gettext_noop("Square"), gettext_noop("Square"),
gettext_noop("Rectangle"), gettext_noop("Rectangle"),
@ -173,27 +174,31 @@ const char * const shape_names[NUM_SHAPES] = {
/* Some text to write when each shape is selected: */ /* Some text to write when each shape is selected: */
const char * const shape_tips[NUM_SHAPES] = { const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("A square is a rectangle with four equal sides."), gettext_noop("A square is a rectangle with four equal sides."),
gettext_noop("A square is a rectangle with four equal sides."), gettext_noop("A square is a rectangle with four equal sides."),
gettext_noop("A rectangle has four sides and four right angles."), gettext_noop("A rectangle has four sides and four right angles."),
gettext_noop("A rectangle has four sides and four right angles."), gettext_noop("A rectangle has four sides and four right angles."),
gettext_noop("A circle is a curve where all points have the same distance from the centre."), gettext_noop
gettext_noop("A circle is a curve where all points have the same distance from the centre."), ("A circle is a curve where all points have the same distance from the centre."),
gettext_noop
("A circle is a curve where all points have the same distance from the centre."),
gettext_noop("An ellipse is a stretched circle."), gettext_noop("An ellipse is a stretched circle."),
gettext_noop("An ellipse is a stretched circle."), gettext_noop("An ellipse is a stretched circle."),
gettext_noop("A triangle has three sides."), gettext_noop("A triangle has three sides."),
gettext_noop("A triangle has three sides."), gettext_noop("A triangle has three sides."),
gettext_noop("A pentagon has five sides."), gettext_noop("A pentagon has five sides."),
gettext_noop("A pentagon has five sides."), gettext_noop("A pentagon has five sides."),
gettext_noop("A rhombus has four equal sides, and opposite sides are parallel."), gettext_noop
gettext_noop("A rhombus has four equal sides, and opposite sides are parallel.") ("A rhombus has four equal sides, and opposite sides are parallel."),
gettext_noop
("A rhombus has four equal sides, and opposite sides are parallel.")
}; };
/* Shape icon filenames: */ /* Shape icon filenames: */
const char * const shape_img_fnames[NUM_SHAPES] = { const char *const shape_img_fnames[NUM_SHAPES] = {
DATA_PREFIX "images/shapes/square.png", DATA_PREFIX "images/shapes/square.png",
DATA_PREFIX "images/shapes/square_f.png", DATA_PREFIX "images/shapes/square_f.png",
DATA_PREFIX "images/shapes/rectangle.png", DATA_PREFIX "images/shapes/rectangle.png",
@ -209,4 +214,3 @@ const char * const shape_img_fnames[NUM_SHAPES] = {
DATA_PREFIX "images/shapes/diamond.png", DATA_PREFIX "images/shapes/diamond.png",
DATA_PREFIX "images/shapes/diamond_f.png" DATA_PREFIX "images/shapes/diamond_f.png"
}; };

View file

@ -35,59 +35,60 @@
#define SND_NONE -1 #define SND_NONE -1
enum { enum
SND_HARP, /* Begin / New */ {
SND_CLICK, /* Tool selections */ SND_HARP, /* Begin / New */
SND_BLEEP, /* Selector selection */ SND_CLICK, /* Tool selections */
SND_BUBBLE, /* Color selection */ SND_BLEEP, /* Selector selection */
SND_STAMP, /* Using stamp tool */ SND_BUBBLE, /* Color selection */
SND_LINE_START, /* Using line tool */ SND_STAMP, /* Using stamp tool */
SND_LINE_START, /* Using line tool */
SND_LINE_END, SND_LINE_END,
SND_SCROLL, /* Selector scroll buttons */ SND_SCROLL, /* Selector scroll buttons */
SND_PAINT1, /* Sound while painting */ SND_PAINT1, /* Sound while painting */
SND_PAINT2, SND_PAINT2,
SND_PAINT3, SND_PAINT3,
SND_PAINT4, SND_PAINT4,
SND_ERASER1, /* Sound while erasing */ SND_ERASER1, /* Sound while erasing */
SND_ERASER2, SND_ERASER2,
SND_SAVE, /* Save sound effect */ SND_SAVE, /* Save sound effect */
SND_PROMPT, /* Prompt animation sound effect */ SND_PROMPT, /* Prompt animation sound effect */
SND_DRIP, /* Magic drip */ SND_DRIP, /* Magic drip */
SND_CHALK, /* Magic chalk */ SND_CHALK, /* Magic chalk */
SND_SPARKLES1, /* Magic sparkles */ SND_SPARKLES1, /* Magic sparkles */
SND_SPARKLES2, SND_SPARKLES2,
SND_THICK, /* Magic thick */ SND_THICK, /* Magic thick */
SND_THIN, /* Magic thin */ SND_THIN, /* Magic thin */
SND_FLIP, /* Magic flip */ SND_FLIP, /* Magic flip */
SND_MIRROR, /* Magic mirror */ SND_MIRROR, /* Magic mirror */
SND_NEGATIVE, /* Magic negative */ SND_NEGATIVE, /* Magic negative */
SND_BLUR, /* Magic blur */ SND_BLUR, /* Magic blur */
SND_BLOCKS, /* Magic blocks */ SND_BLOCKS, /* Magic blocks */
SND_FADE, /* Magic fade */ SND_FADE, /* Magic fade */
SND_DARKEN, /* Magic darken */ SND_DARKEN, /* Magic darken */
SND_RAINBOW, /* Magic rainbow */ SND_RAINBOW, /* Magic rainbow */
SND_SMUDGE, /* Magic smudge */ SND_SMUDGE, /* Magic smudge */
SND_TINT, /* Magic tint */ SND_TINT, /* Magic tint */
SND_CARTOON, /* Magic cartoon */ SND_CARTOON, /* Magic cartoon */
SND_BRICK, /* Magic brick */ SND_BRICK, /* Magic brick */
SND_GRASS, /* Magic grass */ SND_GRASS, /* Magic grass */
SND_KEYCLICK, /* Text tool keyboard click feedback */ SND_KEYCLICK, /* Text tool keyboard click feedback */
SND_KEYCLICKRING, /* Text tool keyboard click feedback with bell ring */ SND_KEYCLICKRING, /* Text tool keyboard click feedback with bell ring */
SND_RETURN, /* Text tool carriage return sound */ SND_RETURN, /* Text tool carriage return sound */
SND_SHRINK, /* Stamp shrink */ SND_SHRINK, /* Stamp shrink */
SND_GROW, /* Stamp grow */ SND_GROW, /* Stamp grow */
SND_ITALIC_ON, /* Italic on */ SND_ITALIC_ON, /* Italic on */
SND_ITALIC_OFF, /* Italic off */ SND_ITALIC_OFF, /* Italic off */
SND_AREYOUSURE, /* "Are you sure?" */ SND_AREYOUSURE, /* "Are you sure?" */
SND_YOUCANNOT, /* "No no no!" */ SND_YOUCANNOT, /* "No no no!" */
SND_TUXOK, /* "Ok" */ SND_TUXOK, /* "Ok" */
NUM_SOUNDS NUM_SOUNDS
}; };
/* Sound file filenames: */ /* Sound file filenames: */
static const char * sound_fnames[NUM_SOUNDS] = { static const char *sound_fnames[NUM_SOUNDS] = {
DATA_PREFIX "sounds/harp.wav", DATA_PREFIX "sounds/harp.wav",
DATA_PREFIX "sounds/click.wav", DATA_PREFIX "sounds/click.wav",
DATA_PREFIX "sounds/bleep.wav", DATA_PREFIX "sounds/bleep.wav",
@ -136,4 +137,3 @@ static const char * sound_fnames[NUM_SOUNDS] = {
}; };
#endif #endif

View file

@ -18,7 +18,8 @@
/* What tuxes are available: */ /* What tuxes are available: */
enum { enum
{
TUX_DEFAULT, TUX_DEFAULT,
TUX_KISS, TUX_KISS,
TUX_BORED, TUX_BORED,
@ -31,7 +32,7 @@ enum {
/* Tux filenames: */ /* Tux filenames: */
const char * const tux_img_fnames[NUM_TIP_TUX] = { const char *const tux_img_fnames[NUM_TIP_TUX] = {
DATA_PREFIX "images/tux/default.png", DATA_PREFIX "images/tux/default.png",
DATA_PREFIX "images/tux/kiss.png", DATA_PREFIX "images/tux/kiss.png",
DATA_PREFIX "images/tux/bored.png", DATA_PREFIX "images/tux/bored.png",

View file

@ -16,7 +16,8 @@
/* What titles are available: */ /* What titles are available: */
enum { enum
{
TITLE_NONE, TITLE_NONE,
TITLE_NOCOLORS, TITLE_NOCOLORS,
TITLE_TOOLS, TITLE_TOOLS,
@ -33,7 +34,7 @@ enum {
/* Title names: */ /* Title names: */
const char * const title_names[NUM_TITLES] = { const char *const title_names[NUM_TITLES] = {
"", "",
"", "",
gettext_noop("Tools"), gettext_noop("Tools"),
@ -45,4 +46,3 @@ const char * const title_names[NUM_TITLES] = {
gettext_noop("Letters"), gettext_noop("Letters"),
gettext_noop("Magic") gettext_noop("Magic")
}; };

View file

@ -18,7 +18,8 @@
/* What tools are available: */ /* What tools are available: */
enum { enum
{
TOOL_BRUSH, TOOL_BRUSH,
TOOL_STAMP, TOOL_STAMP,
TOOL_LINES, TOOL_LINES,
@ -39,7 +40,7 @@ enum {
/* Tool names: */ /* Tool names: */
const char * const tool_names[NUM_TOOLS] = { const char *const tool_names[NUM_TOOLS] = {
gettext_noop("Paint"), gettext_noop("Paint"),
gettext_noop("Stamp"), gettext_noop("Stamp"),
gettext_noop("Lines"), gettext_noop("Lines"),
@ -59,12 +60,14 @@ const char * const tool_names[NUM_TOOLS] = {
/* Some text to write when each tool is selected: */ /* Some text to write when each tool is selected: */
const char * const tool_tips[NUM_TOOLS] = { const char *const tool_tips[NUM_TOOLS] = {
gettext_noop("Pick a color and a brush shape to draw with."), gettext_noop("Pick a color and a brush shape to draw with."),
gettext_noop("Pick a picture to stamp around your drawing."), gettext_noop("Pick a picture to stamp around your drawing."),
gettext_noop("Click to start drawing a line. Let go to complete it."), gettext_noop("Click to start drawing a line. Let go to complete it."),
gettext_noop("Pick a shape. Click to pick the center, drag, then let go when it is the size you want. Move around to rotate it, and click to draw it."), gettext_noop
gettext_noop("Choose a style of text. Click on your drawing and you can start typing."), ("Pick a shape. Click to pick the center, drag, then let go when it is the size you want. Move around to rotate it, and click to draw it."),
gettext_noop
("Choose a style of text. Click on your drawing and you can start typing."),
gettext_noop("Pick a magical effect to use on your drawing!"), gettext_noop("Pick a magical effect to use on your drawing!"),
/* Undo */ gettext_noop("Undo!"), /* Undo */ gettext_noop("Undo!"),
/* Redo */ gettext_noop("Redo!"), /* Redo */ gettext_noop("Redo!"),
@ -84,7 +87,7 @@ const char * const tool_tips[NUM_TOOLS] = {
/* Tool icon filenames: */ /* Tool icon filenames: */
const char * const tool_img_fnames[NUM_TOOLS] = { const char *const tool_img_fnames[NUM_TOOLS] = {
DATA_PREFIX "images/tools/brush.png", DATA_PREFIX "images/tools/brush.png",
DATA_PREFIX "images/tools/stamp.png", DATA_PREFIX "images/tools/stamp.png",
DATA_PREFIX "images/tools/lines.png", DATA_PREFIX "images/tools/lines.png",
@ -120,4 +123,3 @@ const int tool_tux[NUM_TOOLS] = {
TUX_GREAT, TUX_GREAT,
TUX_DEFAULT TUX_DEFAULT
}; };

File diff suppressed because it is too large Load diff

View file

@ -1,16 +1,16 @@
/****************************************************/ /****************************************************/
/* */ /* */
/* For Win32 that lacks Unix direct support. */ /* For Win32 that lacks Unix direct support. */
/* - avoids including "windows.h" */ /* - avoids including "windows.h" */
/* */ /* */
/* Copyright (c) 2002 John Popplewell */ /* Copyright (c) 2002 John Popplewell */
/* john@johnnypops.demon.co.uk */ /* john@johnnypops.demon.co.uk */
/* */ /* */
/* Version 1.0.1 - fixed bug in opendir() */ /* Version 1.0.1 - fixed bug in opendir() */
/* Version 1.0.0 - initial version */ /* Version 1.0.0 - initial version */
/* */ /* */
/****************************************************/ /****************************************************/
/* /*
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -25,111 +25,104 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/* $Id$ */ /* $Id$ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "win32_dirent.h" #include "win32_dirent.h"
#include "debug.h" #include "debug.h"
DIR * opendir(const char *pSpec)
DIR *opendir( const char *pSpec ) {
{ char pathname[MAX_PATH + 2];
char pathname[MAX_PATH+2]; DIR * pDir = calloc(1, sizeof(DIR));
DIR *pDir = calloc( 1, sizeof(DIR) ); if (!pDir)
return NULL;
if ( !pDir ) return NULL; strcpy(pathname, pSpec);
strcpy( pathname, pSpec ); strcat(pathname, "/*");
strcat( pathname, "/*" ); pDir->hFind = FindFirstFile(pathname, &pDir->wfd);
pDir->hFind = FindFirstFile(pathname, &pDir->wfd); if (pDir->hFind == INVALID_HANDLE_VALUE)
if ( pDir->hFind == INVALID_HANDLE_VALUE )
{ {
free(pDir); free(pDir);
pDir = NULL; pDir = NULL;
} }
return pDir; return pDir;
} }
void closedir(DIR * pDir)
{
void closedir( DIR *pDir ) assert(pDir != NULL);
{ free(pDir);
assert(pDir != NULL); } struct dirent *readdir(struct DIR *pDir)
free(pDir); {
} assert(pDir != NULL);
if (pDir->hFind)
struct dirent *readdir(struct DIR *pDir) {
{ strcpy(pDir->de.d_name, (const char *) pDir->wfd.cFileName);
assert(pDir != NULL); if (!FindNextFile(pDir->hFind, &pDir->wfd))
if (pDir->hFind)
{ {
strcpy(pDir->de.d_name, (const char *)pDir->wfd.cFileName); FindClose(pDir->hFind);
if (!FindNextFile(pDir->hFind, &pDir->wfd)) pDir->hFind = NULL;
{ }
FindClose(pDir->hFind); return &pDir->de;
pDir->hFind = NULL; }
} return NULL;
return &pDir->de; }
} int alphasort(const void *a, const void *b)
return NULL; {
} return (strcmp
((*(const struct dirent **) a)->d_name,
(*(const struct dirent **) b)->d_name));
int alphasort(const void *a, const void *b) } static int addToList(int i, struct dirent ***namelist,
{ struct dirent *entry)
return(strcmp((*(const struct dirent **)a)->d_name, (*(const struct dirent **)b)->d_name)); {
} int size;
struct dirent *block;
*namelist =
static int addToList( int i, struct dirent ***namelist, struct dirent *entry ) (struct dirent **) realloc((void *) (*namelist),
{ (size_t) ((i + 1) * sizeof(struct dirent *)));
int size; if (*namelist == NULL)
struct dirent *block; return -1;
size =
*namelist = (struct dirent**)realloc( (void*)(*namelist), (size_t)((i+1)*sizeof(struct dirent*)) ); (((char *) &entry->d_name) - ((char *) entry)) + strlen(entry->d_name) +
if ( *namelist == NULL ) return -1; 1;
block = (struct dirent *) malloc(size);
size = (((char*)&entry->d_name)-((char*)entry))+strlen(entry->d_name)+1; if (block == NULL)
block = (struct dirent*)malloc( size ); return -1;
(*namelist)[i] = block;
if ( block == NULL ) return -1; memcpy(block, entry, size);
return ++i;
(*namelist)[i] = block; }
memcpy( block, entry, size ); int scandir(const char *dir, struct dirent ***namelist, selectCB select,
comparCB compar)
return ++i; {
} DIR * pDir;
int count;
struct dirent *entry;
int scandir( const char *dir, struct dirent ***namelist, selectCB select, comparCB compar) assert((dir != NULL) && (namelist != NULL));
{ pDir = opendir(dir);
DIR *pDir; if (!pDir)
int count; return -1;
struct dirent *entry; count = 0;
while ((entry = readdir(pDir)) != NULL)
assert( (dir != NULL) && (namelist != NULL) );
{
pDir = opendir(dir); if (select == NULL || (select != NULL && select(entry)))
if ((count = addToList(count, namelist, entry)) < 0)
if ( !pDir ) return -1; break;
}
count = 0; closedir(pDir);
while( (entry = readdir(pDir)) != NULL ) if (count <= 0)
{ return -1;
if ( select == NULL || (select != NULL && select( entry )) ) if (compar != NULL)
if ( (count = addToList( count, namelist, entry )) < 0 ) qsort((void *) (*namelist), (size_t) count, sizeof(struct dirent *),
break; compar);
} return count;
closedir( pDir ); }
if ( count <= 0 ) return -1;
if ( compar != NULL )
qsort( (void *)(*namelist), (size_t)count, sizeof(struct dirent *), compar );
return count;
}

View file

@ -1,82 +1,73 @@
/****************************************************/ /****************************************************/
/* */ /* */
/* For Win32 that lacks Unix direct support. */ /* For Win32 that lacks Unix direct support. */
/* - avoids including "windows.h" */ /* - avoids including "windows.h" */
/* */ /* */
/* Copyright (c) 2002 John Popplewell */ /* Copyright (c) 2002 John Popplewell */
/* john@johnnypops.demon.co.uk */ /* john@johnnypops.demon.co.uk */
/* */ /* */
/****************************************************/ /****************************************************/
/* $Id$ */ /* $Id$ */
typedef long BOOL;
typedef long BOOL; typedef unsigned int DWORD;
typedef unsigned int DWORD; typedef wchar_t TCHAR;
typedef wchar_t TCHAR; typedef void *HANDLE;
typedef void* HANDLE;
#define MAX_PATH 256 #define MAX_PATH 256
#define INVALID_HANDLE_VALUE ((HANDLE)(-1)) #define INVALID_HANDLE_VALUE ((HANDLE)(-1))
#define WINAPI __stdcall #define WINAPI __stdcall
typedef struct
typedef struct {
{ DWORD dwLowDateTime;
DWORD dwLowDateTime; DWORD dwHighDateTime;
DWORD dwHighDateTime; } FILETIME;
} FILETIME; typedef struct
{
typedef struct DWORD dwFileAttributes;
{ FILETIME ftCreationTime;
DWORD dwFileAttributes; FILETIME ftLastAccessTime;
FILETIME ftCreationTime; FILETIME ftLastWriteTime;
FILETIME ftLastAccessTime; DWORD nFileSizeHigh;
FILETIME ftLastWriteTime; DWORD nFileSizeLow;
DWORD nFileSizeHigh; DWORD dwReserved0;
DWORD nFileSizeLow; DWORD dwReserved1;
DWORD dwReserved0; TCHAR cFileName[MAX_PATH];
DWORD dwReserved1; TCHAR cAlternateFileName[14];
TCHAR cFileName[ MAX_PATH ]; } WIN32_FIND_DATA;
TCHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATA;
#define FindFirstFile FindFirstFileA #define FindFirstFile FindFirstFileA
#define FindNextFile FindNextFileA #define FindNextFile FindNextFileA
#define FindClose FindClose #define FindClose FindClose
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
#endif {
extern HANDLE WINAPI FindFirstFile( const char*, WIN32_FIND_DATA* ); #endif /* */
extern BOOL WINAPI FindNextFile( HANDLE, WIN32_FIND_DATA* ); extern HANDLE WINAPI FindFirstFile(const char *, WIN32_FIND_DATA *);
extern BOOL WINAPI FindClose( HANDLE ); extern BOOL WINAPI FindNextFile(HANDLE, WIN32_FIND_DATA *);
extern BOOL WINAPI FindClose(HANDLE);
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif
#endif /* */
struct dirent
{
char d_name[MAX_PATH];
};
typedef struct
{
WIN32_FIND_DATA wfd;
HANDLE hFind;
struct dirent de;
} DIR;
extern DIR *opendir(const char *pSpec);
extern void closedir(DIR * pDir);
extern struct dirent *readdir(struct DIR *pDir);
typedef int (*selectCB) (const struct dirent *);
typedef int (*comparCB) (const void *, const void *);
extern int alphasort(const void *a, const void *b);
extern int scandir(const char *dir, struct dirent ***namelist,
selectCB select, comparCB compar);
struct dirent
{
char d_name[MAX_PATH];
};
typedef struct
{
WIN32_FIND_DATA wfd;
HANDLE hFind;
struct dirent de;
} DIR;
extern DIR *opendir(const char *pSpec);
extern void closedir(DIR *pDir);
extern struct dirent *readdir(struct DIR *pDir);
typedef int (*selectCB)(const struct dirent *);
typedef int (*comparCB)(const void*, const void*);
extern int alphasort( const void *a, const void *b );
extern int scandir( const char *dir, struct dirent ***namelist, selectCB select, comparCB compar);

View file

@ -32,11 +32,11 @@
#define NOREF(x) ((x)=(x)) #define NOREF(x) ((x)=(x))
#define GETHINST(hWnd) ((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE)) #define GETHINST(hWnd) ((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE))
#define MIR(id) (MAKEINTRESOURCE(id)) #define MIR(id) (MAKEINTRESOURCE(id))
static PRINTDLG global_pd = { static PRINTDLG global_pd = {
sizeof(PRINTDLG), sizeof(PRINTDLG),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
PD_RETURNDC, PD_RETURNDC,
@ -49,49 +49,50 @@ static PRINTDLG global_pd = {
}; };
static SDL_Surface *make24bitDIB(SDL_Surface *surf) static SDL_Surface *make24bitDIB(SDL_Surface * surf)
{ {
SDL_PixelFormat pixfmt; SDL_PixelFormat pixfmt;
SDL_Surface *surf24; SDL_Surface *surf24;
SDL_Surface *surfDIB; SDL_Surface *surfDIB;
Uint8 *src,*dst; Uint8 *src, *dst;
Uint32 linesize; Uint32 linesize;
int i; int i;
memset(&pixfmt, 0, sizeof(pixfmt)); memset(&pixfmt, 0, sizeof(pixfmt));
pixfmt.palette = NULL; pixfmt.palette = NULL;
pixfmt.BitsPerPixel = 24; pixfmt.BitsPerPixel = 24;
pixfmt.BytesPerPixel= 3; pixfmt.BytesPerPixel = 3;
pixfmt.Rmask = 0x00FF0000; pixfmt.Rmask = 0x00FF0000;
pixfmt.Gmask = 0x0000FF00; pixfmt.Gmask = 0x0000FF00;
pixfmt.Bmask = 0x000000FF; pixfmt.Bmask = 0x000000FF;
pixfmt.Amask = 0; pixfmt.Amask = 0;
pixfmt.Rshift = 16; pixfmt.Rshift = 16;
pixfmt.Gshift = 8; pixfmt.Gshift = 8;
pixfmt.Bshift = 0; pixfmt.Bshift = 0;
pixfmt.Ashift = 0; pixfmt.Ashift = 0;
pixfmt.Rloss = 0; pixfmt.Rloss = 0;
pixfmt.Gloss = 0; pixfmt.Gloss = 0;
pixfmt.Bloss = 0; pixfmt.Bloss = 0;
pixfmt.Aloss = 0; pixfmt.Aloss = 0;
pixfmt.colorkey = 0; pixfmt.colorkey = 0;
pixfmt.alpha = 0; pixfmt.alpha = 0;
surf24 = SDL_ConvertSurface(surf, &pixfmt, SDL_SWSURFACE); surf24 = SDL_ConvertSurface(surf, &pixfmt, SDL_SWSURFACE);
surfDIB = SDL_CreateRGBSurface(SDL_SWSURFACE, surf24->w, surf24->h, 24, surfDIB = SDL_CreateRGBSurface(SDL_SWSURFACE, surf24->w, surf24->h, 24,
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask, pixfmt.Amask); pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask,
pixfmt.Amask);
linesize = surf24->w * 3; // Flip top2bottom linesize = surf24->w * 3; // Flip top2bottom
dst = surfDIB->pixels; dst = surfDIB->pixels;
src = ((Uint8*)surf24->pixels)+((surf24->h-1)*surf24->pitch); src = ((Uint8 *) surf24->pixels) + ((surf24->h - 1) * surf24->pitch);
for (i = 0; i < surf24->h; ++i) for (i = 0; i < surf24->h; ++i)
{ {
memcpy(dst, src, linesize); memcpy(dst, src, linesize);
src -= surf24->pitch; src -= surf24->pitch;
dst += surfDIB->pitch; dst += surfDIB->pitch;
} }
SDL_FreeSurface(surf24); // Free temp surface SDL_FreeSurface(surf24); // Free temp surface
return surfDIB; return surfDIB;
} }
@ -99,25 +100,28 @@ static SDL_Surface *make24bitDIB(SDL_Surface *surf)
/* returns 0 if failed */ /* returns 0 if failed */
static int GetDefaultPrinterStrings(char *device, char *driver, char *output) static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
{ {
const char *section = "windows"; const char *section = "windows";
const char *key = "device"; const char *key = "device";
const char *def = "NODEFAULTPRINTER"; const char *def = "NODEFAULTPRINTER";
char buff[MAX_PATH]; char buff[MAX_PATH];
char *dev,*drv,*out; char *dev, *drv, *out;
if (!GetProfileString(section, key, def, buff, sizeof(buff))) if (!GetProfileString(section, key, def, buff, sizeof(buff)))
return 0; return 0;
if (strcmp(buff, def) == 0) if (strcmp(buff, def) == 0)
return 0; return 0;
if (((dev = strtok(buff, "," )) != NULL) && if (((dev = strtok(buff, ",")) != NULL) &&
((drv = strtok(NULL, ", ")) != NULL) && ((drv = strtok(NULL, ", ")) != NULL) &&
((out = strtok(NULL, ", ")) != NULL)) ((out = strtok(NULL, ", ")) != NULL))
{ {
if (device) strcpy(device, dev); if (device)
if (driver) strcpy(driver, drv); strcpy(device, dev);
if (output) strcpy(output, out); if (driver)
strcpy(driver, drv);
if (output)
strcpy(output, out);
return 1; return 1;
} }
return 0; return 0;
@ -127,15 +131,15 @@ static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath) static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
{ {
char device[MAX_PATH]; char device[MAX_PATH];
HANDLE hPrinter = NULL; HANDLE hPrinter = NULL;
int sizeof_devmode; int sizeof_devmode;
HGLOBAL hDevMode = NULL; HGLOBAL hDevMode = NULL;
DEVMODE *devmode = NULL; DEVMODE *devmode = NULL;
int res; int res;
FILE *fp = NULL; FILE *fp = NULL;
int block_size; int block_size;
int block_read; int block_read;
if ((fp = fopen(filepath, "rb")) == NULL) if ((fp = fopen(filepath, "rb")) == NULL)
return NULL; return NULL;
@ -146,7 +150,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
if (!OpenPrinter(device, &hPrinter, NULL)) if (!OpenPrinter(device, &hPrinter, NULL))
return NULL; return NULL;
sizeof_devmode = (int)DocumentProperties(hWnd, hPrinter, device, sizeof_devmode = (int) DocumentProperties(hWnd, hPrinter, device,
NULL, NULL, 0); NULL, NULL, 0);
if (!sizeof_devmode) if (!sizeof_devmode)
@ -156,12 +160,12 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
if (!hDevMode) if (!hDevMode)
goto err_exit; goto err_exit;
devmode = (DEVMODE*)GlobalLock(hDevMode); devmode = (DEVMODE *) GlobalLock(hDevMode);
if (!devmode) if (!devmode)
goto err_exit; goto err_exit;
res = DocumentProperties(hWnd, hPrinter, device, devmode, NULL, res = DocumentProperties(hWnd, hPrinter, device, devmode, NULL,
DM_OUT_BUFFER); DM_OUT_BUFFER);
if (res != IDOK) if (res != IDOK)
goto err_exit; goto err_exit;
@ -171,8 +175,8 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
goto err_exit; goto err_exit;
fclose(fp); fclose(fp);
res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode, res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode,
DM_IN_BUFFER|DM_OUT_BUFFER); DM_IN_BUFFER | DM_OUT_BUFFER);
if (res != IDOK) if (res != IDOK)
goto err_exit; goto err_exit;
@ -181,27 +185,32 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
return hDevMode; return hDevMode;
err_exit: err_exit:
if (fp) fclose(fp); if (fp)
if (devmode) GlobalUnlock(hDevMode); fclose(fp);
if (hDevMode) GlobalFree(hDevMode); if (devmode)
if (hPrinter) ClosePrinter(hPrinter); GlobalUnlock(hDevMode);
if (hDevMode)
GlobalFree(hDevMode);
if (hPrinter)
ClosePrinter(hPrinter);
return NULL; return NULL;
} }
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath, HANDLE hDevMode) static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath,
HANDLE hDevMode)
{ {
FILE *fp = NULL; FILE *fp = NULL;
NOREF(hWnd); NOREF(hWnd);
if ((fp = fopen(filepath, "wb")) != NULL) if ((fp = fopen(filepath, "wb")) != NULL)
{ {
DEVMODE *devmode = (DEVMODE*)GlobalLock(hDevMode); DEVMODE *devmode = (DEVMODE *) GlobalLock(hDevMode);
int block_size = devmode->dmSize + devmode->dmDriverExtra; int block_size = devmode->dmSize + devmode->dmDriverExtra;
int block_written; int block_written;
char devname[dmDeviceNameSize]; char devname[dmDeviceNameSize];
strcpy(devname, (const char*)devmode->dmDeviceName); strcpy(devname, (const char *) devmode->dmDeviceName);
fwrite(devname, 1, sizeof(devname), fp); fwrite(devname, 1, sizeof(devname), fp);
block_written = fwrite(devmode, 1, block_size, fp); block_written = fwrite(devmode, 1, block_size, fp);
GlobalUnlock(hDevMode); GlobalUnlock(hDevMode);
@ -215,12 +224,12 @@ static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath, HANDLE hDe
static HDC GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show) static HDC GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
{ {
global_pd.hwndOwner = hWnd; global_pd.hwndOwner = hWnd;
global_pd.hDC = NULL; global_pd.hDC = NULL;
global_pd.hDevNames = NULL; global_pd.hDevNames = NULL;
if (global_pd.hDevMode == NULL) if (global_pd.hDevMode == NULL)
{ {
global_pd.hDevMode = LoadCustomPrinterHDEVMODE(hWnd, printcfg); global_pd.hDevMode = LoadCustomPrinterHDEVMODE(hWnd, printcfg);
} }
if (show) if (show)
@ -234,9 +243,10 @@ static HDC GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
} }
{ {
DEVMODE *devmode = (DEVMODE*)GlobalLock(global_pd.hDevMode); DEVMODE *devmode = (DEVMODE *) GlobalLock(global_pd.hDevMode);
global_pd.hDC = CreateDC(NULL, (const char*)devmode->dmDeviceName, NULL, devmode); global_pd.hDC =
CreateDC(NULL, (const char *) devmode->dmDeviceName, NULL, devmode);
GlobalUnlock(global_pd.hDevMode); GlobalUnlock(global_pd.hDevMode);
} }
return global_pd.hDC; return global_pd.hDC;
@ -245,7 +255,7 @@ static HDC GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
static HDC GetDefaultPrinterDC(void) static HDC GetDefaultPrinterDC(void)
{ {
char device[MAX_PATH],driver[MAX_PATH],output[MAX_PATH]; char device[MAX_PATH], driver[MAX_PATH], output[MAX_PATH];
if (GetDefaultPrinterStrings(device, driver, output)) if (GetDefaultPrinterStrings(device, driver, output))
return CreateDC(driver, device, output, NULL); return CreateDC(driver, device, output, NULL);
@ -256,7 +266,8 @@ static HDC GetDefaultPrinterDC(void)
static HDC GetPrinterDC(HWND hWnd, const char *printcfg, int show) static HDC GetPrinterDC(HWND hWnd, const char *printcfg, int show)
{ {
if (!printcfg) return GetDefaultPrinterDC(); if (!printcfg)
return GetDefaultPrinterDC();
return GetCustomPrinterDC(hWnd, printcfg, show); return GetCustomPrinterDC(hWnd, printcfg, show);
} }
@ -264,11 +275,12 @@ static HDC GetPrinterDC(HWND hWnd, const char *printcfg, int show)
static int IsBandingRequired(HDC hPrinter) static int IsBandingRequired(HDC hPrinter)
{ {
OSVERSIONINFO osvi; OSVERSIONINFO osvi;
int indata = NEXTBAND; int indata = NEXTBAND;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osvi) && (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT)) if (GetVersionEx(&osvi) && (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT))
return Escape(hPrinter, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&indata, NULL); return Escape(hPrinter, QUERYESCSUPPORT, sizeof(int), (LPCSTR) & indata,
NULL);
return 0; return 0;
} }
@ -279,25 +291,26 @@ int IsPrinterAvailable(void)
} }
const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog) const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
int showdialog)
{ {
const char *res = NULL; const char *res = NULL;
HWND hWnd; HWND hWnd;
DOCINFO di; DOCINFO di;
int nError; int nError;
SDL_SysWMinfo wminfo; SDL_SysWMinfo wminfo;
HDC hDCwindow; HDC hDCwindow;
HDC hDCprinter; HDC hDCprinter;
BITMAPINFOHEADER bmih; BITMAPINFOHEADER bmih;
SDL_Surface *surf24 = NULL; SDL_Surface *surf24 = NULL;
RECT rc; RECT rc;
float fLogPelsX1, fLogPelsY1, fLogPelsX2, fLogPelsY2; float fLogPelsX1, fLogPelsY1, fLogPelsX2, fLogPelsY2;
float fScaleX, fScaleY; float fScaleX, fScaleY;
int cWidthPels, xLeft, yTop; int cWidthPels, xLeft, yTop;
float subscaler,subscalerx,subscalery; float subscaler, subscalerx, subscalery;
int hDCCaps; int hDCCaps;
HBITMAP hbm = NULL; HBITMAP hbm = NULL;
HDC hdcMem = NULL; HDC hdcMem = NULL;
SDL_VERSION(&wminfo.version); SDL_VERSION(&wminfo.version);
if (!SDL_GetWMInfo(&wminfo)) if (!SDL_GetWMInfo(&wminfo))
@ -312,8 +325,8 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
di.cbSize = sizeof(DOCINFO); di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Tux Paint"; di.lpszDocName = "Tux Paint";
di.lpszOutput = (LPTSTR)NULL; di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR)NULL; di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0; di.fwType = 0;
nError = StartDoc(hDCprinter, &di); nError = StartDoc(hDCprinter, &di);
@ -340,16 +353,16 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
} }
memset(&bmih, 0, sizeof(bmih)); memset(&bmih, 0, sizeof(bmih));
bmih.biSize = sizeof(bmih); bmih.biSize = sizeof(bmih);
bmih.biPlanes = 1; bmih.biPlanes = 1;
bmih.biCompression = BI_RGB; bmih.biCompression = BI_RGB;
bmih.biBitCount = 24; bmih.biBitCount = 24;
bmih.biWidth = surf24->w; bmih.biWidth = surf24->w;
bmih.biHeight = surf24->h; bmih.biHeight = surf24->h;
GetClientRect(hWnd, &rc); GetClientRect(hWnd, &rc);
subscalerx = (float)rc.right/surf24->w; subscalerx = (float) rc.right / surf24->w;
subscalery = (float)rc.bottom/surf24->h; subscalery = (float) rc.bottom / surf24->h;
subscaler = subscalery; subscaler = subscalery;
if (subscalerx < subscalery) if (subscalerx < subscalery)
subscaler = subscalerx; subscaler = subscalerx;
@ -368,62 +381,64 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
fLogPelsY2 = GetDeviceCaps(hDCprinter, LOGPIXELSY); fLogPelsY2 = GetDeviceCaps(hDCprinter, LOGPIXELSY);
if (fLogPelsX1 > fLogPelsX2) if (fLogPelsX1 > fLogPelsX2)
fScaleX = (fLogPelsX1/fLogPelsX2); fScaleX = (fLogPelsX1 / fLogPelsX2);
else else
fScaleX = (fLogPelsX2/fLogPelsX1); fScaleX = (fLogPelsX2 / fLogPelsX1);
if (fLogPelsY1 > fLogPelsY2) if (fLogPelsY1 > fLogPelsY2)
fScaleY = (fLogPelsY1/fLogPelsY2); fScaleY = (fLogPelsY1 / fLogPelsY2);
else else
fScaleY = (fLogPelsY2/fLogPelsY1); fScaleY = (fLogPelsY2 / fLogPelsY1);
fScaleX *= subscaler; fScaleX *= subscaler;
fScaleY *= subscaler; fScaleY *= subscaler;
yTop = 0; yTop = 0;
cWidthPels = GetDeviceCaps(hDCprinter, PHYSICALWIDTH); cWidthPels = GetDeviceCaps(hDCprinter, PHYSICALWIDTH);
xLeft = ((cWidthPels - ((int)(fScaleX*bmih.biWidth)))/2)- xLeft = ((cWidthPels - ((int) (fScaleX * bmih.biWidth))) / 2) -
GetDeviceCaps(hDCprinter, PHYSICALOFFSETX); GetDeviceCaps(hDCprinter, PHYSICALOFFSETX);
hDCCaps = GetDeviceCaps(hDCprinter, RASTERCAPS); hDCCaps = GetDeviceCaps(hDCprinter, RASTERCAPS);
if (hDCCaps & RC_PALETTE) if (hDCCaps & RC_PALETTE)
{ {
res = "win32_print: printer context requires palette."; res = "win32_print: printer context requires palette.";
goto error; goto error;
} }
if (IsBandingRequired(hDCprinter)) if (IsBandingRequired(hDCprinter))
{ {
RECT rcBand = { 0, 0, 0, 0 }; RECT rcBand = { 0, 0, 0, 0 };
RECT rcPrinter; RECT rcPrinter;
RECT rcImage; RECT rcImage;
SetRect(&rcPrinter, xLeft, yTop, (int)(fScaleX*bmih.biWidth), (int)(fScaleY*bmih.biHeight)); SetRect(&rcPrinter, xLeft, yTop, (int) (fScaleX * bmih.biWidth),
(int) (fScaleY * bmih.biHeight));
SetRect(&rcImage, 0, 0, bmih.biWidth, bmih.biHeight); SetRect(&rcImage, 0, 0, bmih.biWidth, bmih.biHeight);
while (Escape(hDCprinter, NEXTBAND, 0, NULL, &rcBand)) while (Escape(hDCprinter, NEXTBAND, 0, NULL, &rcBand))
{ {
if (IsRectEmpty(&rcBand)) break; if (IsRectEmpty(&rcBand))
break;
if (IntersectRect(&rcBand, &rcBand, &rcPrinter)) if (IntersectRect(&rcBand, &rcBand, &rcPrinter))
{ {
rcImage.top = (int)(0.5f+(float)rcBand.top/fScaleX); rcImage.top = (int) (0.5f + (float) rcBand.top / fScaleX);
rcImage.bottom = (int)(0.5f+(float)rcBand.bottom/fScaleX); rcImage.bottom = (int) (0.5f + (float) rcBand.bottom / fScaleX);
SetStretchBltMode(hDCprinter, COLORONCOLOR); SetStretchBltMode(hDCprinter, COLORONCOLOR);
nError = StretchDIBits(hDCprinter, rcBand.left, rcBand.top, nError = StretchDIBits(hDCprinter, rcBand.left, rcBand.top,
rcBand.right - rcBand.left, rcBand.right - rcBand.left,
rcBand.bottom - rcBand.top, rcBand.bottom - rcBand.top,
rcImage.left, rcImage.top, rcImage.left, rcImage.top,
rcImage.right - rcImage.left, rcImage.right - rcImage.left,
rcImage.bottom - rcImage.top, rcImage.bottom - rcImage.top,
surf24->pixels, (BITMAPINFO*)&bmih, surf24->pixels, (BITMAPINFO *) & bmih,
DIB_RGB_COLORS, SRCCOPY); DIB_RGB_COLORS, SRCCOPY);
if (nError == GDI_ERROR) if (nError == GDI_ERROR)
{ {
res = "win32_print: StretchDIBits() failed."; res = "win32_print: StretchDIBits() failed.";
goto error; goto error;
} }
} }
} }
} }
@ -434,15 +449,15 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
SetStretchBltMode(hDCprinter, COLORONCOLOR); SetStretchBltMode(hDCprinter, COLORONCOLOR);
nError = StretchDIBits(hDCprinter, xLeft, yTop, nError = StretchDIBits(hDCprinter, xLeft, yTop,
(int)(fScaleX*bmih.biWidth), (int) (fScaleX * bmih.biWidth),
(int)(fScaleY*bmih.biHeight), (int) (fScaleY * bmih.biHeight),
0, 0, bmih.biWidth, bmih.biHeight, 0, 0, bmih.biWidth, bmih.biHeight,
surf24->pixels, (BITMAPINFO*)&bmih, surf24->pixels, (BITMAPINFO *) & bmih,
DIB_RGB_COLORS, SRCCOPY); DIB_RGB_COLORS, SRCCOPY);
if (nError == GDI_ERROR) if (nError == GDI_ERROR)
{ {
res = "win32_print: StretchDIBits() failed."; res = "win32_print: StretchDIBits() failed.";
goto error; goto error;
} }
} }
else else
@ -463,10 +478,13 @@ const char *SurfacePrint(SDL_Surface *surf, const char *printcfg, int showdialog
EndDoc(hDCprinter); EndDoc(hDCprinter);
error: error:
if (hdcMem) DeleteDC(hdcMem); if (hdcMem)
if (hbm) DeleteObject(hbm); DeleteDC(hdcMem);
if (surf24) SDL_FreeSurface(surf24); if (hbm)
DeleteObject(hbm);
if (surf24)
SDL_FreeSurface(surf24);
EnableWindow(hWnd, TRUE); EnableWindow(hWnd, TRUE);
DeleteDC(hDCprinter); DeleteDC(hDCprinter);
@ -477,21 +495,25 @@ error:
/* /*
Read access to Windows Registry Read access to Windows Registry
*/ */
static HRESULT ReadRegistry(const char *key, const char *option, char *value, int size) static HRESULT ReadRegistry(const char *key, const char *option, char *value,
int size)
{ {
LONG res; LONG res;
HKEY hKey = NULL; HKEY hKey = NULL;
res = RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey); res = RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey);
if (res != ERROR_SUCCESS) if (res != ERROR_SUCCESS)
goto err_exit; goto err_exit;
res = RegQueryValueEx(hKey, option, NULL, NULL, (LPBYTE)value, (LPDWORD)&size); res =
RegQueryValueEx(hKey, option, NULL, NULL, (LPBYTE) value,
(LPDWORD) & size);
if (res != ERROR_SUCCESS) if (res != ERROR_SUCCESS)
goto err_exit; goto err_exit;
res = ERROR_SUCCESS; res = ERROR_SUCCESS;
err_exit: err_exit:
if (hKey) RegCloseKey(hKey); if (hKey)
RegCloseKey(hKey);
return HRESULT_FROM_WIN32(res); return HRESULT_FROM_WIN32(res);
} }
@ -505,8 +527,8 @@ static char *remove_slash(char *path)
if (!len) if (!len)
return path; return path;
if (path[len-1] == '/' || path[len-1] == '\\') if (path[len - 1] == '/' || path[len - 1] == '\\')
path[len-1] = 0; path[len - 1] = 0;
return path; return path;
} }
@ -518,10 +540,11 @@ static char *remove_slash(char *path)
*/ */
char *GetDefaultSaveDir(const char *suffix) char *GetDefaultSaveDir(const char *suffix)
{ {
char prefix[MAX_PATH]; char prefix[MAX_PATH];
char path[2*MAX_PATH]; char path[2 * MAX_PATH];
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; const char *key =
const char *option = "AppData"; "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *option = "AppData";
HRESULT hr = S_OK; HRESULT hr = S_OK;
if (SUCCEEDED(hr = ReadRegistry(key, option, prefix, sizeof(prefix)))) if (SUCCEEDED(hr = ReadRegistry(key, option, prefix, sizeof(prefix))))
@ -540,9 +563,10 @@ char *GetDefaultSaveDir(const char *suffix)
*/ */
char *GetSystemFontDir(void) char *GetSystemFontDir(void)
{ {
char path[MAX_PATH]; char path[MAX_PATH];
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; const char *key =
const char *option = "Fonts"; "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *option = "Fonts";
HRESULT hr = S_OK; HRESULT hr = S_OK;
if (SUCCEEDED(hr = ReadRegistry(key, option, path, sizeof(path)))) if (SUCCEEDED(hr = ReadRegistry(key, option, path, sizeof(path))))
@ -552,5 +576,3 @@ char *GetSystemFontDir(void)
} }
return strdup("C:\\WINDOWS\\FONTS"); return strdup("C:\\WINDOWS\\FONTS");
} }

View file

@ -15,10 +15,9 @@
#endif #endif
/* if printcfg is NULL, uses the default printer */ /* if printcfg is NULL, uses the default printer */
extern const char *SurfacePrint( SDL_Surface *surf, extern const char *SurfacePrint(SDL_Surface * surf,
const char *printcfg, const char *printcfg, int showdialog);
int showdialog ); extern int IsPrinterAvailable(void);
extern int IsPrinterAvailable( void );
/* additional windows functions requiring <windows.h> */ /* additional windows functions requiring <windows.h> */
extern char *GetDefaultSaveDir(const char *suffix); extern char *GetDefaultSaveDir(const char *suffix);