From 3487236f9360df6c27d81452527c3b4d3703e8a8 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Wed, 8 Sep 2021 00:53:47 -0700 Subject: [PATCH] Animated brushes can rotate now Takes advantage of SDL_gfxBlitRGBA(), also from SDL_gfx. --- docs/CHANGES.txt | 7 +++---- src/tuxpaint.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 82572e8af..d76d895ae 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -8,7 +8,7 @@ http://www.tuxpaint.org/ $Id$ -2021.September.6 (0.9.27) +2021.September.8 (0.9.27) * New Magic Tools: ---------------- * "Opposite" -- Change parts of the picture to their complementary @@ -33,17 +33,16 @@ $Id$ * Other Improvements: ------------------- - * WIP Rotational brushes now supported. Unlike "directional" + * Rotational brushes now supported. Unlike "directional" brushes, in which a 3x3 grid representing the 8 cardinal directions (45 degree steps) is used, only a single brush image is required, and Tux Paint will rotate it between 0 and 360 degrees, depending on the direction the mouse is going. The brush's ".dat" file should contain a line consisting of the word "rotate". - * FIXME: WIP -- Doesn't handle animated brushes correctly! * Note: This adds a dependency on "SDL_gfx" library (Homepage: https://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx/ SourceForge project page: https://sourceforge.net/projects/sdlgfx/) - as this feature use it's "rotozoom" functionality. + as this feature use it's "rotozoomSurface()" and "SDL_gfxBlitRGBA()". (Closes https://sourceforge.net/p/tuxpaint/feature-requests/122/) * Replaced the "arrow_compass_points" brush with a single diff --git a/src/tuxpaint.c b/src/tuxpaint.c index e45977c7d..fc7b17d71 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 14, 2002 - September 6, 2021 + June 14, 2002 - September 8, 2021 */ #include "platform.h" @@ -6045,8 +6045,32 @@ static void blit_brush(int x, int y, int direction, int rotation, int * w, int * SDL_Surface * rotated_brush; /* TODO: Cache these; discard them when the user changes the brush or alters its color */ - /* FIXME: Account for src being within an animated brush! */ - rotated_brush = rotozoomSurface(img_cur_brush, rotation, 1.0, SMOOTHING_ON); + + rotated_brush = NULL; + + if (img_cur_brush_frames != 1) + { + SDL_Surface * brush_frame_surf; + + brush_frame_surf = + SDL_CreateRGBSurface(img_cur_brush->flags, + src.w, + src.h, + img_cur_brush->format->BitsPerPixel, + img_cur_brush->format->Rmask, img_cur_brush->format->Gmask, img_cur_brush->format->Bmask, + img_cur_brush->format->Amask); + if (brush_frame_surf != NULL) + { + SDL_gfxBlitRGBA(img_cur_brush, &src, brush_frame_surf, NULL); + rotated_brush = rotozoomSurface(brush_frame_surf, rotation, 1.0, SMOOTHING_ON); + SDL_FreeSurface(brush_frame_surf); + } + } + else + { + rotated_brush = rotozoomSurface(img_cur_brush, rotation, 1.0, SMOOTHING_ON); + } + if (rotated_brush != NULL) { src.x = 0;