all stamp data into stamp_data struct, and fix new sound crash
This commit is contained in:
parent
3d9e11b23e
commit
e0a24c108a
1 changed files with 48 additions and 57 deletions
105
src/tuxpaint.c
105
src/tuxpaint.c
|
|
@ -133,8 +133,8 @@ static scaleparams scaletable[] = {
|
||||||
// to scale some offset, in pixels, like the current stamp is scaled
|
// to scale some offset, in pixels, like the current stamp is scaled
|
||||||
#define SCALE_LIKE_STAMP(x) ( ((x) * scaletable[stamp_data[cur_stamp]->size].numer + scaletable[stamp_data[cur_stamp]->size].denom-1) / scaletable[stamp_data[cur_stamp]->size].denom )
|
#define SCALE_LIKE_STAMP(x) ( ((x) * scaletable[stamp_data[cur_stamp]->size].numer + scaletable[stamp_data[cur_stamp]->size].denom-1) / scaletable[stamp_data[cur_stamp]->size].denom )
|
||||||
// pixel dimensions of the current stamp, as scaled
|
// pixel dimensions of the current stamp, as scaled
|
||||||
#define CUR_STAMP_W SCALE_LIKE_STAMP(img_stamps[cur_stamp]->w)
|
#define CUR_STAMP_W SCALE_LIKE_STAMP(stamp_data[cur_stamp]->full_norm->w)
|
||||||
#define CUR_STAMP_H SCALE_LIKE_STAMP(img_stamps[cur_stamp]->h)
|
#define CUR_STAMP_H SCALE_LIKE_STAMP(stamp_data[cur_stamp]->full_norm->h)
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
@ -2051,6 +2051,11 @@ typedef struct stamp_type {
|
||||||
#ifndef NOSOUND
|
#ifndef NOSOUND
|
||||||
Mix_Chunk *ssnd;
|
Mix_Chunk *ssnd;
|
||||||
#endif
|
#endif
|
||||||
|
char *stampfile;
|
||||||
|
SDL_Surface *full_norm;
|
||||||
|
SDL_Surface *full_mirr;
|
||||||
|
SDL_Surface *thumb_norm;
|
||||||
|
SDL_Surface *thumb_mirr;
|
||||||
unsigned tinter : 3;
|
unsigned tinter : 3;
|
||||||
unsigned colorable : 1;
|
unsigned colorable : 1;
|
||||||
unsigned tintable : 1;
|
unsigned tintable : 1;
|
||||||
|
|
@ -2066,11 +2071,7 @@ typedef struct stamp_type {
|
||||||
|
|
||||||
#define MAX_STAMPS 512
|
#define MAX_STAMPS 512
|
||||||
static int num_stamps;
|
static int num_stamps;
|
||||||
static SDL_Surface * img_stamps[MAX_STAMPS];
|
|
||||||
static SDL_Surface * img_stamps_premirror[MAX_STAMPS];
|
|
||||||
static stamp_type * stamp_data[MAX_STAMPS];
|
static stamp_type * stamp_data[MAX_STAMPS];
|
||||||
static SDL_Surface * img_stamp_thumbs[MAX_STAMPS],
|
|
||||||
* img_stamp_thumbs_premirror[MAX_STAMPS];
|
|
||||||
|
|
||||||
/* Returns whether a particular stamp can be colored: */
|
/* Returns whether a particular stamp can be colored: */
|
||||||
static int stamp_colorable(int stamp)
|
static int stamp_colorable(int stamp)
|
||||||
|
|
@ -4277,8 +4278,8 @@ static void mainloop(void)
|
||||||
|
|
||||||
if (cur_tool == TOOL_STAMP)
|
if (cur_tool == TOOL_STAMP)
|
||||||
{
|
{
|
||||||
w = img_stamps[cur_stamp]->w;
|
w = stamp_data[cur_stamp]->full_norm->w;
|
||||||
h = img_stamps[cur_stamp]->h;
|
h = stamp_data[cur_stamp]->full_norm->h;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -5125,24 +5126,24 @@ static void stamp_draw(int x, int y)
|
||||||
|
|
||||||
if (stamp_data[cur_stamp]->mirrored)
|
if (stamp_data[cur_stamp]->mirrored)
|
||||||
{
|
{
|
||||||
if (img_stamps_premirror[cur_stamp] != NULL)
|
if (stamp_data[cur_stamp]->full_mirr != NULL)
|
||||||
{
|
{
|
||||||
/* Use pre-mirrored one! */
|
/* Use pre-mirrored one! */
|
||||||
|
|
||||||
surf_ptr = img_stamps_premirror[cur_stamp];
|
surf_ptr = stamp_data[cur_stamp]->full_mirr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Use normal (only) one, and mirror it ourselves: */
|
/* Use normal (only) one, and mirror it ourselves: */
|
||||||
|
|
||||||
surf_ptr = img_stamps[cur_stamp];
|
surf_ptr = stamp_data[cur_stamp]->full_norm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Not mirrored: */
|
/* Not mirrored: */
|
||||||
|
|
||||||
surf_ptr = img_stamps[cur_stamp];
|
surf_ptr = stamp_data[cur_stamp]->full_norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
getpixel = getpixels[surf_ptr->format->BytesPerPixel];
|
getpixel = getpixels[surf_ptr->format->BytesPerPixel];
|
||||||
|
|
@ -5259,7 +5260,7 @@ static void stamp_draw(int x, int y)
|
||||||
/* Flipped! */
|
/* Flipped! */
|
||||||
|
|
||||||
if (stamp_data[cur_stamp]->mirrored &&
|
if (stamp_data[cur_stamp]->mirrored &&
|
||||||
img_stamps_premirror[cur_stamp] == NULL)
|
stamp_data[cur_stamp]->full_mirr == NULL)
|
||||||
{
|
{
|
||||||
/* Mirrored, too! */
|
/* Mirrored, too! */
|
||||||
|
|
||||||
|
|
@ -5300,7 +5301,7 @@ static void stamp_draw(int x, int y)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (stamp_data[cur_stamp]->mirrored &&
|
if (stamp_data[cur_stamp]->mirrored &&
|
||||||
img_stamps_premirror[cur_stamp] == NULL)
|
stamp_data[cur_stamp]->full_mirr == NULL)
|
||||||
{
|
{
|
||||||
/* Mirrored! */
|
/* Mirrored! */
|
||||||
|
|
||||||
|
|
@ -6725,28 +6726,20 @@ static unsigned default_stamp_size;
|
||||||
|
|
||||||
static void loadstamp_finisher(int i)
|
static void loadstamp_finisher(int i)
|
||||||
{
|
{
|
||||||
if (img_stamps[i]->w > 40 || img_stamps[i]->h > 40)
|
if (stamp_data[i]->full_norm->w > 40 || stamp_data[i]->full_norm->h > 40)
|
||||||
img_stamp_thumbs[i] = thumbnail(img_stamps[i], 40, 40, 1);
|
stamp_data[i]->thumb_norm = thumbnail(stamp_data[i]->full_norm, 40, 40, 1);
|
||||||
else
|
|
||||||
img_stamp_thumbs[i] = NULL;
|
|
||||||
|
|
||||||
if (img_stamps_premirror[i])
|
if (stamp_data[i]->full_mirr)
|
||||||
{
|
{
|
||||||
/* Also thumbnail the pre-drawn mirror version, if any: */
|
/* Also thumbnail the pre-drawn mirror version, if any: */
|
||||||
if (img_stamps_premirror[i]->w > 40 || img_stamps_premirror[i]->h > 40)
|
if (stamp_data[i]->full_mirr->w > 40 || stamp_data[i]->full_mirr->h > 40)
|
||||||
img_stamp_thumbs_premirror[i] = thumbnail(img_stamps_premirror[i], 40, 40, 1);
|
stamp_data[i]->thumb_mirr = thumbnail(stamp_data[i]->full_mirr, 40, 40, 1);
|
||||||
else
|
|
||||||
img_stamp_thumbs_premirror[i] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If Tux Paint is in mirror-image-by-default mode, mirror, if we can: */
|
/* If Tux Paint is in mirror-image-by-default mode, mirror, if we can: */
|
||||||
|
|
||||||
if (mirrorstamps && stamp_data[i]->mirrorable)
|
if (mirrorstamps && stamp_data[i]->mirrorable)
|
||||||
stamp_data[i]->mirrored = 1;
|
stamp_data[i]->mirrored = 1;
|
||||||
else
|
|
||||||
stamp_data[i]->mirrored = 0;
|
|
||||||
|
|
||||||
stamp_data[i]->flipped = 0;
|
|
||||||
|
|
||||||
unsigned int upper = HARD_MAX_STAMP_SIZE;
|
unsigned int upper = HARD_MAX_STAMP_SIZE;
|
||||||
unsigned int lower = 0;
|
unsigned int lower = 0;
|
||||||
|
|
@ -6756,8 +6749,8 @@ static void loadstamp_finisher(int i)
|
||||||
scaleparams *s = &scaletable[upper];
|
scaleparams *s = &scaletable[upper];
|
||||||
int pw, ph; // proposed width and height
|
int pw, ph; // proposed width and height
|
||||||
|
|
||||||
pw = (img_stamps[i]->w * s->numer + s->denom - 1) / s->denom;
|
pw = (stamp_data[i]->full_norm->w * s->numer + s->denom - 1) / s->denom;
|
||||||
ph = (img_stamps[i]->h * s->numer + s->denom - 1) / s->denom;
|
ph = (stamp_data[i]->full_norm->h * s->numer + s->denom - 1) / s->denom;
|
||||||
|
|
||||||
// OK to let a stamp stick off the sides in one direction, not two
|
// OK to let a stamp stick off the sides in one direction, not two
|
||||||
if (pw < canvas->w * 2 && ph < canvas->h * 1)
|
if (pw < canvas->w * 2 && ph < canvas->h * 1)
|
||||||
|
|
@ -6772,8 +6765,8 @@ static void loadstamp_finisher(int i)
|
||||||
scaleparams *s = &scaletable[lower];
|
scaleparams *s = &scaletable[lower];
|
||||||
int pw, ph; // proposed width and height
|
int pw, ph; // proposed width and height
|
||||||
|
|
||||||
pw = (img_stamps[i]->w * s->numer + s->denom - 1) / s->denom;
|
pw = (stamp_data[i]->full_norm->w * s->numer + s->denom - 1) / s->denom;
|
||||||
ph = (img_stamps[i]->h * s->numer + s->denom - 1) / s->denom;
|
ph = (stamp_data[i]->full_norm->h * s->numer + s->denom - 1) / s->denom;
|
||||||
|
|
||||||
if (pw*ph > 20)
|
if (pw*ph > 20)
|
||||||
break;
|
break;
|
||||||
|
|
@ -6814,24 +6807,21 @@ static void loadstamp_callback(const char *restrict const dir, unsigned dirlen,
|
||||||
{
|
{
|
||||||
char fname[512];
|
char fname[512];
|
||||||
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
|
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
|
||||||
stamp_data[num_stamps] = malloc(sizeof *stamp_data[num_stamps]);
|
stamp_data[num_stamps] = calloc(1, sizeof *stamp_data[num_stamps]);
|
||||||
stamp_data[num_stamps]->stxt = loaddesc(fname);
|
stamp_data[num_stamps]->stxt = loaddesc(fname);
|
||||||
loadinfo(fname, stamp_data[num_stamps]);
|
loadinfo(fname, stamp_data[num_stamps]);
|
||||||
|
|
||||||
img_stamps[num_stamps] = NULL;
|
|
||||||
if(!mirrorstamps || !disable_stamp_controls || !stamp_data[num_stamps]->mirrorable)
|
if(!mirrorstamps || !disable_stamp_controls || !stamp_data[num_stamps]->mirrorable)
|
||||||
img_stamps[num_stamps] = loadimage(fname);
|
stamp_data[num_stamps]->full_norm = loadimage(fname);
|
||||||
|
|
||||||
img_stamps_premirror[num_stamps] = NULL;
|
|
||||||
if((mirrorstamps || !disable_stamp_controls) && stamp_data[num_stamps]->mirrorable)
|
if((mirrorstamps || !disable_stamp_controls) && stamp_data[num_stamps]->mirrorable)
|
||||||
img_stamps_premirror[num_stamps] = loadaltimage(fname);
|
stamp_data[num_stamps]->full_mirr = loadaltimage(fname);
|
||||||
|
|
||||||
if(img_stamps[num_stamps] || img_stamps_premirror[num_stamps])
|
if(stamp_data[num_stamps]->full_norm || stamp_data[num_stamps]->full_mirr)
|
||||||
{
|
{
|
||||||
// we have a stamp; finalize it
|
// we have a stamp; finalize it
|
||||||
#ifndef NOSOUND
|
#ifndef NOSOUND
|
||||||
if (use_sound)
|
stamp_data[num_stamps]->ssnd = use_sound ? loadsound(fname) : NULL;
|
||||||
stamp_data[num_stamps]->ssnd = loadsound(fname);
|
|
||||||
#endif
|
#endif
|
||||||
loadstamp_finisher(num_stamps);
|
loadstamp_finisher(num_stamps);
|
||||||
num_stamps++; // FIXME: no limit and no resizing right now...
|
num_stamps++; // FIXME: no limit and no resizing right now...
|
||||||
|
|
@ -6839,8 +6829,8 @@ static void loadstamp_callback(const char *restrict const dir, unsigned dirlen,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we have a failure, abort mission
|
// we have a failure, abort mission
|
||||||
free(img_stamps[num_stamps]);
|
free(stamp_data[num_stamps]->full_norm);
|
||||||
free(img_stamps_premirror[num_stamps]);
|
free(stamp_data[num_stamps]->full_mirr);
|
||||||
free(stamp_data[num_stamps]->stxt);
|
free(stamp_data[num_stamps]->stxt);
|
||||||
free(stamp_data[num_stamps]);
|
free(stamp_data[num_stamps]);
|
||||||
}
|
}
|
||||||
|
|
@ -9293,23 +9283,23 @@ static void draw_stamps(void)
|
||||||
/* Draw the stamp itself: */
|
/* Draw the stamp itself: */
|
||||||
|
|
||||||
if (stamp_data[stamp]->mirrored &&
|
if (stamp_data[stamp]->mirrored &&
|
||||||
img_stamps_premirror[stamp] != NULL)
|
stamp_data[stamp]->full_mirr != NULL)
|
||||||
{
|
{
|
||||||
/* Use pre-drawn mirrored version! */
|
/* Use pre-drawn mirrored version! */
|
||||||
|
|
||||||
if (img_stamp_thumbs_premirror[stamp] != NULL)
|
if (stamp_data[stamp]->thumb_mirr != NULL)
|
||||||
img = img_stamp_thumbs_premirror[stamp];
|
img = stamp_data[stamp]->thumb_mirr;
|
||||||
else
|
else
|
||||||
img = img_stamps_premirror[stamp];
|
img = stamp_data[stamp]->full_mirr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Use normal version: */
|
/* Use normal version: */
|
||||||
|
|
||||||
if (img_stamp_thumbs[stamp] != NULL)
|
if (stamp_data[stamp]->thumb_norm != NULL)
|
||||||
img = img_stamp_thumbs[stamp];
|
img = stamp_data[stamp]->thumb_norm;
|
||||||
else
|
else
|
||||||
img = img_stamps[stamp];
|
img = stamp_data[stamp]->full_norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -9322,7 +9312,7 @@ static void draw_stamps(void)
|
||||||
|
|
||||||
|
|
||||||
if (stamp_data[stamp]->mirrored &&
|
if (stamp_data[stamp]->mirrored &&
|
||||||
img_stamps_premirror[stamp] == NULL)
|
stamp_data[stamp]->full_mirr == NULL)
|
||||||
{
|
{
|
||||||
/* It's mirrored!: */
|
/* It's mirrored!: */
|
||||||
|
|
||||||
|
|
@ -12055,11 +12045,14 @@ static void cleanup(void)
|
||||||
free(stamp_data[i]->stxt);
|
free(stamp_data[i]->stxt);
|
||||||
stamp_data[i]->stxt = NULL;
|
stamp_data[i]->stxt = NULL;
|
||||||
}
|
}
|
||||||
|
free_surface( &stamp_data[i]->full_norm );
|
||||||
|
free_surface( &stamp_data[i]->full_mirr );
|
||||||
|
free_surface( &stamp_data[i]->thumb_norm );
|
||||||
|
free_surface( &stamp_data[i]->thumb_mirr );
|
||||||
|
|
||||||
free(stamp_data[i]);
|
free(stamp_data[i]);
|
||||||
stamp_data[i] = NULL;
|
stamp_data[i] = NULL;
|
||||||
}
|
}
|
||||||
free_surface_array( img_stamps, num_stamps );
|
|
||||||
free_surface_array( img_stamps_premirror, num_stamps );
|
|
||||||
|
|
||||||
free_surface_array( img_brushes, num_brushes );
|
free_surface_array( img_brushes, num_brushes );
|
||||||
free_surface_array( img_tools, NUM_TOOLS );
|
free_surface_array( img_tools, NUM_TOOLS );
|
||||||
|
|
@ -12126,8 +12119,6 @@ static void cleanup(void)
|
||||||
free_surface_array( img_color_btns, NUM_COLORS*2 );
|
free_surface_array( img_color_btns, NUM_COLORS*2 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
free_surface_array( img_stamp_thumbs, num_stamps );
|
|
||||||
|
|
||||||
free_surface( &screen );
|
free_surface( &screen );
|
||||||
free_surface( &img_starter );
|
free_surface( &img_starter );
|
||||||
free_surface( &img_starter_bkgd );
|
free_surface( &img_starter_bkgd );
|
||||||
|
|
@ -14195,13 +14186,13 @@ static void update_stamp_xor(void)
|
||||||
/* Use pre-mirrored stamp image, if applicable: */
|
/* Use pre-mirrored stamp image, if applicable: */
|
||||||
|
|
||||||
if (stamp_data[cur_stamp]->mirrored &&
|
if (stamp_data[cur_stamp]->mirrored &&
|
||||||
img_stamps_premirror[cur_stamp] != NULL)
|
stamp_data[cur_stamp]->full_mirr != NULL)
|
||||||
{
|
{
|
||||||
src = img_stamps_premirror[cur_stamp];
|
src = stamp_data[cur_stamp]->full_mirr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
src = img_stamps[cur_stamp];
|
src = stamp_data[cur_stamp]->full_norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start by scaling
|
// start by scaling
|
||||||
|
|
@ -14222,7 +14213,7 @@ static void update_stamp_xor(void)
|
||||||
{
|
{
|
||||||
/* Compensate for mirror! */
|
/* Compensate for mirror! */
|
||||||
if (stamp_data[cur_stamp]->mirrored &&
|
if (stamp_data[cur_stamp]->mirrored &&
|
||||||
img_stamps_premirror[cur_stamp] == NULL)
|
stamp_data[cur_stamp]->full_mirr == NULL)
|
||||||
{
|
{
|
||||||
rx = src->w - 1 - xx;
|
rx = src->w - 1 - xx;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue