From a52c4c3fe0ae73392ac30143f9dae1ee78d1199b Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Thu, 28 Sep 2006 07:51:15 +0000 Subject: [PATCH] Animated brushes can be randomized. Use "random" in its ".dat" file. Made newly-animated spray brush random. --- data/brushes/spray.dat | 1 + docs/CHANGES.txt | 2 ++ docs/EXTENDING.txt | 6 +++++- docs/html/EXTENDING.html | 6 +++++- src/tuxpaint.c | 27 +++++++++++++++++++++------ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/data/brushes/spray.dat b/data/brushes/spray.dat index 0a46c48fd..864c99846 100644 --- a/data/brushes/spray.dat +++ b/data/brushes/spray.dat @@ -1 +1,2 @@ frames=3 +random diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 12386829c..6ea56bbdf 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -81,6 +81,8 @@ $Id$ (Create an image (W*N) x H in size (where N is number of frames), then create a ".dat" file for the brush, containing the line "frames=N". + * Animated brushes can be randomized. Use "random" in its ".dat" file. + * Brushes can include directional variations. (Implements RFE #1522694) (Create an image (W*3) x (H*3) in size, then create a ".dat" file for the brush, containing the line: "directional". Each of the 9 diff --git a/docs/EXTENDING.txt b/docs/EXTENDING.txt index 3722f9b49..4f47eb777 100644 --- a/docs/EXTENDING.txt +++ b/docs/EXTENDING.txt @@ -8,7 +8,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/tuxpaint/ - June 14, 2002 - September 3, 2006 + June 14, 2002 - September 28, 2006 -------------------------------------------------------------------------- @@ -164,6 +164,10 @@ Brushes Add a line containing the line "frames=N" to the brush's data file, where N is the number of frames in the brush. + Note: If you'd rather the frames be flipped through randomly, rather + than sequentially, also add a line containing "random" to the + brush's data file. + Directional Brushes As of Tux Paint version 0.9.16, you may now create directional diff --git a/docs/html/EXTENDING.html b/docs/html/EXTENDING.html index 8f8534d46..0e48f12ce 100644 --- a/docs/html/EXTENDING.html +++ b/docs/html/EXTENDING.html @@ -23,7 +23,7 @@ New Breed Software

bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/

-

June 14, 2002 - September 3, 2006

+

June 14, 2002 - September 28, 2006


@@ -241,6 +241,10 @@ effect.

Add a line containing the line "frames=N" to the brush's data file, where N is the number of frames in the brush.

+ +

Note: If you'd rather the frames be flipped through + randomly, rather than sequentially, also add a line containing + "random" to the brush's data file.

Directional Brushes

diff --git a/src/tuxpaint.c b/src/tuxpaint.c index e6c6e45b9..60e2a67d4 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -3436,7 +3436,7 @@ static void brush_draw(int x1, int y1, int x2, int y2, int update) orig_y2 = y2; - frame_w = img_brushes[cur_brush]->w / brushes_frames[cur_brush]; + frame_w = img_brushes[cur_brush]->w / abs(brushes_frames[cur_brush]); w = frame_w / (brushes_directional[cur_brush] ? 3: 1); h = img_brushes[cur_brush]->h / (brushes_directional[cur_brush] ? 3 : 1); @@ -3552,9 +3552,14 @@ static void blit_brush(int x, int y, int direction) { brush_counter = 0; - brush_frame++; - if (brush_frame >= img_cur_brush_frames) - brush_frame = 0; + if (img_cur_brush_frames >= 0) + { + brush_frame++; + if (brush_frame >= img_cur_brush_frames) + brush_frame = 0; + } + else + brush_frame = rand() % abs(img_cur_brush_frames); dest.x = x; dest.y = y; @@ -5249,6 +5254,7 @@ static void loadbrush_callback(SDL_Surface * screen, { FILE * fi; char buf[64]; + int want_rand; dirlen = dirlen; @@ -5288,6 +5294,8 @@ static void loadbrush_callback(SDL_Surface * screen, strcpy(strcasestr(fname, ".png"), ".dat"); fi = fopen(fname, "r"); + want_rand = 0; + if (fi != NULL) { do @@ -5308,9 +5316,16 @@ static void loadbrush_callback(SDL_Surface * screen, { brushes_directional[num_brushes] = 1; } + else if (strstr(buf, "random") != NULL) + { + want_rand = 1; + } } while (!feof(fi)); fclose(fi); + + if (want_rand) + brushes_frames[num_brushes] *= -1; } num_brushes++; @@ -7760,7 +7775,7 @@ static void draw_brushes(void) src.x = 0; src.y = brushes_directional[brush] ? (img_brushes[brush]->h / 3) : 0; - src.w = (img_brushes[brush]->w / brushes_frames[brush]) / + src.w = (img_brushes[brush]->w / abs(brushes_frames[brush])) / (brushes_directional[brush] ? 3 : 1); src.h = (img_brushes[brush]->h / (brushes_directional[brush] ? 3 : 1)); @@ -8834,7 +8849,7 @@ static void render_brush(void) SDL_UnlockSurface(img_cur_brush); SDL_UnlockSurface(img_brushes[cur_brush]); - img_cur_brush_frame_w = img_cur_brush->w / brushes_frames[cur_brush]; + img_cur_brush_frame_w = img_cur_brush->w / abs(brushes_frames[cur_brush]); img_cur_brush_w = img_cur_brush_frame_w / (brushes_directional[cur_brush] ? 3 : 1); img_cur_brush_h = img_cur_brush->h / (brushes_directional[cur_brush] ? 3 : 1);