Correct locked shapes' rotation after corner drag

When using the new (on 0.9.25) corner-drag option for creating
a new shape, "shape-locked" (1:1 aspect ratio) shapes -- square
and octagon -- would only rotate in a few positions, based on the
angle of ther vertices.

Corrected this, with no apparent adverse effect on other shapes,
in either drag mode (classic "from-center", and new "from-corner").

Also, removed extranous whitespace before EOLs in src/tuxpaint.c.
This commit is contained in:
Bill Kendrick 2020-11-10 09:54:50 -08:00 committed by Pere Pujal i Carabantes
parent 8abe13640c
commit b857d67f28

View file

@ -22,7 +22,7 @@
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)
June 14, 2002 - October 15, 2020 June 14, 2002 - November 10, 2020
*/ */
@ -1635,7 +1635,7 @@ static SDL_Surface *render_text(TuxPaint_Font * restrict font, const char *restr
/** /**
* Convert a wide-character string to string of Uint16's. * Convert a wide-character string to string of Uint16's.
* *
* This conversion is required on platforms where Uint16 doesn't match wchar_t. * This conversion is required on platforms where Uint16 doesn't match wchar_t.
* On Windows, wchar_t is 16-bit, elsewhere it is 32-bit. * On Windows, wchar_t is 16-bit, elsewhere it is 32-bit.
* Mismatch caused by the use of Uint16 for unicode characters by SDL, SDL_ttf. * Mismatch caused by the use of Uint16 for unicode characters by SDL, SDL_ttf.
@ -2323,7 +2323,7 @@ int brushflag, xnew, ynew, eraflag, lineflag, magicflag, keybd_flag, keybd_posit
int cur_thing; int cur_thing;
/** /**
* --- MAIN LOOP! --- * --- MAIN LOOP! ---
*/ */
static void mainloop(void) static void mainloop(void)
{ {
@ -9604,7 +9604,7 @@ static void draw_shapes(void)
/* Show shape-from-center button: */ /* Show shape-from-center button: */
if (shape_mode == SHAPEMODE_CENTER) if (shape_mode == SHAPEMODE_CENTER)
button_color = img_btn_down; button_color = img_btn_down;
else else
button_color = img_btn_up; button_color = img_btn_up;
@ -9622,7 +9622,7 @@ static void draw_shapes(void)
/* Show shape-from-corner button: */ /* Show shape-from-corner button: */
if (shape_mode == SHAPEMODE_CORNER) if (shape_mode == SHAPEMODE_CORNER)
button_color = img_btn_down; button_color = img_btn_down;
else else
button_color = img_btn_up; button_color = img_btn_up;
@ -11780,7 +11780,7 @@ static int SDLCALL NondefectiveBlit(SDL_Surface * src, SDL_Rect * srcrect, SDL_S
/** /**
* Copy an image, scaling and smearing, as needed, into a new surface. * Copy an image, scaling and smearing, as needed, into a new surface.
* Free the original surface. * Free the original surface.
* *
* @param SDL_Surface * src -- source surface (will be freed by this function!) * @param SDL_Surface * src -- source surface (will be freed by this function!)
* @param SDL_Surface * dst -- destination surface * @param SDL_Surface * dst -- destination surface
* @param int SDCALL(*blit) -- function for blitting; "NondefectiveBlit" or "SDL_BlitSurface" * @param int SDCALL(*blit) -- function for blitting; "NondefectiveBlit" or "SDL_BlitSurface"
@ -13574,22 +13574,22 @@ static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
if (rotn != 0) if (rotn != 0)
{ {
rotn_rad = rotn * M_PI / 180; rotn_rad = rotn * M_PI / 180;
xp = (x1 + offx) * cos(rotn_rad) - (y1 + offy) * sin(rotn_rad); xp = (x1 + offx) * cos(rotn_rad) - (y1 + offy) * sin(rotn_rad);
yp = (x1 + offx) * sin(rotn_rad) + (y1 + offy) * cos(rotn_rad); yp = (x1 + offx) * sin(rotn_rad) + (y1 + offy) * cos(rotn_rad);
x1 = xp - offx; x1 = xp - offx;
y1 = yp - offy; y1 = yp - offy;
xp = (x2 + offx) * cos(rotn_rad) - (y2 + offy) * sin(rotn_rad); xp = (x2 + offx) * cos(rotn_rad) - (y2 + offy) * sin(rotn_rad);
yp = (x2 + offx) * sin(rotn_rad) + (y2 + offy) * cos(rotn_rad); yp = (x2 + offx) * sin(rotn_rad) + (y2 + offy) * cos(rotn_rad);
x2 = xp - offx; x2 = xp - offx;
y2 = yp - offy; y2 = yp - offy;
xp = (xv + offx) * cos(rotn_rad) - (yv + offy) * sin(rotn_rad); xp = (xv + offx) * cos(rotn_rad) - (yv + offy) * sin(rotn_rad);
yp = (xv + offx) * sin(rotn_rad) + (yv + offy) * cos(rotn_rad); yp = (xv + offx) * sin(rotn_rad) + (yv + offy) * cos(rotn_rad);
xv = xp - offx; xv = xp - offx;
yv = yp - offy; yv = yp - offy;
} }
@ -13664,6 +13664,10 @@ static int shape_rotation(int ctr_x, int ctr_y, int ox, int oy)
else if (shape_radius < 100) else if (shape_radius < 100)
deg = ((deg - 7) / 15) * 15; deg = ((deg - 7) / 15) * 15;
/* Disabled b/c it adversely affected shape_locked shapes (square & octagon)
with corner-dragged shapes; disabling doesn't seem to cause problems
with any shape, in either drag mode... -bjk 2020-11-10 */
/*
if (shape_locked[cur_shape]) if (shape_locked[cur_shape])
{ {
int angle_skip; int angle_skip;
@ -13671,6 +13675,7 @@ static int shape_rotation(int ctr_x, int ctr_y, int ox, int oy)
angle_skip = 360 / shape_sides[cur_shape]; angle_skip = 360 / shape_sides[cur_shape];
deg = deg % angle_skip; deg = deg % angle_skip;
} }
*/
return (deg); return (deg);
} }
@ -16440,19 +16445,19 @@ static int do_slideshow(void)
draw_toolbar(); draw_toolbar();
draw_colors(COLORSEL_CLOBBER_WIPE); draw_colors(COLORSEL_CLOBBER_WIPE);
draw_none(); draw_none();
/* Show a message depending on success */ /* Show a message depending on success */
if (export_successful) if (export_successful)
do_prompt_snd(PROMPT_GIF_EXPORT_TXT, PROMPT_EXPORT_YES, "", SND_TUXOK, screen->w / 2, screen->h / 2); do_prompt_snd(PROMPT_GIF_EXPORT_TXT, PROMPT_EXPORT_YES, "", SND_TUXOK, screen->w / 2, screen->h / 2);
else else
do_prompt_snd(PROMPT_GIF_EXPORT_FAILED_TXT, PROMPT_EXPORT_YES, "", SND_YOUCANNOT, screen->w / 2, screen->h / 2); do_prompt_snd(PROMPT_GIF_EXPORT_FAILED_TXT, PROMPT_EXPORT_YES, "", SND_YOUCANNOT, screen->w / 2, screen->h / 2);
freeme = textdir(TUX_TIP_SLIDESHOW); freeme = textdir(TUX_TIP_SLIDESHOW);
draw_tux_text(TUX_BORED, freeme, 1); draw_tux_text(TUX_BORED, freeme, 1);
free(freeme); free(freeme);
SDL_Flip(screen); SDL_Flip(screen);
update_list = 1; update_list = 1;
} }
} }
@ -23527,7 +23532,7 @@ static void setup_config(char *argv[])
free(picturesdir); free(picturesdir);
exportdir = strdup(str); exportdir = strdup(str);
} }
/* Load options from user's own configuration (".rc" / ".cfg") file: */ /* Load options from user's own configuration (".rc" / ".cfg") file: */
#if defined(_WIN32) #if defined(_WIN32)
@ -26416,12 +26421,12 @@ char * get_xdg_user_dir(const char * dir_type, const char * fallback) {
} else { } else {
safe_strncpy(return_path, found, MAX_PATH); safe_strncpy(return_path, found, MAX_PATH);
} }
/* Trim trailing " */ /* Trim trailing " */
if (return_path[strlen(return_path) - 1] == '\"') { if (return_path[strlen(return_path) - 1] == '\"') {
return_path[strlen(return_path) - 1] = '\0'; return_path[strlen(return_path) - 1] = '\0';
} }
found_it = TRUE; found_it = TRUE;
} }
} }
@ -26513,34 +26518,34 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
if (bitmap != NULL) if (bitmap != NULL)
{ {
done = 0; done = 0;
for (i = 0; i < num_selected && !done; i++) for (i = 0; i < num_selected && !done; i++)
{ {
which = selected[i]; which = selected[i];
show_progress_bar(screen); show_progress_bar(screen);
/* Figure out filename: */ /* Figure out filename: */
safe_snprintf(fname, sizeof(fname), "%s/%s%s", dirname, d_names[which], d_exts[which]); safe_snprintf(fname, sizeof(fname), "%s/%s%s", dirname, d_names[which], d_exts[which]);
/* Load and scale the image */ /* Load and scale the image */
img = myIMG_Load(fname); img = myIMG_Load(fname);
if (img != NULL) if (img != NULL)
{ {
autoscale_copy_smear_free(img, screen, SDL_BlitSurface); autoscale_copy_smear_free(img, screen, SDL_BlitSurface);
safe_strncpy(file_id, d_names[which], sizeof(file_id)); safe_strncpy(file_id, d_names[which], sizeof(file_id));
/* See if this saved image was based on a 'starter' */ /* See if this saved image was based on a 'starter' */
load_starter_id(d_names[which], NULL); load_starter_id(d_names[which], NULL);
if (starter_id[0] != '\0') if (starter_id[0] != '\0')
{ {
load_starter(starter_id); load_starter(starter_id);
if (starter_mirrored) if (starter_mirrored)
mirror_starter(); mirror_starter();
if (starter_flipped) if (starter_flipped)
flip_starter(); flip_starter();
} }
@ -26556,7 +26561,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
for (y = 0; y < overall_h; y++) { for (y = 0; y < overall_h; y++) {
for (x = 0; x < overall_w; x++) { for (x = 0; x < overall_w; x++) {
SDL_GetRGBA(getpixels[screen->format->BytesPerPixel](screen, x, y), screen->format, &r, &g, &b, &a); SDL_GetRGBA(getpixels[screen->format->BytesPerPixel](screen, x, y), screen->format, &r, &g, &b, &a);
bitmap[((i * overall_area) + (y * overall_w) + x) * 4 + 0] = r; bitmap[((i * overall_area) + (y * overall_w) + x) * 4 + 0] = r;
bitmap[((i * overall_area) + (y * overall_w) + x) * 4 + 1] = g; bitmap[((i * overall_area) + (y * overall_w) + x) * 4 + 1] = g;
bitmap[((i * overall_area) + (y * overall_w) + x) * 4 + 2] = b; bitmap[((i * overall_area) + (y * overall_w) + x) * 4 + 2] = b;
@ -26565,7 +26570,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
} }
SDL_Flip(screen); SDL_Flip(screen);
done = export_gif_monitor_events(); done = export_gif_monitor_events();
} }
@ -26573,7 +26578,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
{ {
/* Quantize to max 256 (8bpp) colors and generate a suitable palette */ /* Quantize to max 256 (8bpp) colors and generate a suitable palette */
liq_handle = liq_attr_create(); liq_handle = liq_attr_create();
input_image = liq_image_create_rgba(liq_handle, bitmap, overall_w, num_selected * overall_h, 0); input_image = liq_image_create_rgba(liq_handle, bitmap, overall_w, num_selected * overall_h, 0);
liq_set_max_colors(liq_handle, 256); liq_set_max_colors(liq_handle, 256);
show_progress_bar(screen); show_progress_bar(screen);
@ -26591,7 +26596,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
pixels_size = num_selected * overall_area; pixels_size = num_selected * overall_area;
raw_8bit_pixels = malloc(pixels_size); raw_8bit_pixels = malloc(pixels_size);
liq_set_dithering_level(quantization_result, 1.0); liq_set_dithering_level(quantization_result, 1.0);
liq_write_remapped_image(quantization_result, input_image, raw_8bit_pixels, pixels_size); liq_write_remapped_image(quantization_result, input_image, raw_8bit_pixels, pixels_size);
palette = liq_get_palette(quantization_result); palette = liq_get_palette(quantization_result);
free(bitmap); free(bitmap);
@ -26610,24 +26615,24 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
8, /* 256 colors */ 8, /* 256 colors */
0 /* infinite loop */ 0 /* infinite loop */
); );
/* Export each frame */ /* Export each frame */
for (i = 0; i < num_selected && !done; i++) for (i = 0; i < num_selected && !done; i++)
{ {
memcpy(gif->frame, raw_8bit_pixels + i * overall_area, overall_area); memcpy(gif->frame, raw_8bit_pixels + i * overall_area, overall_area);
ge_add_frame(gif, gif_speed); ge_add_frame(gif, gif_speed);
show_progress_bar(screen); show_progress_bar(screen);
done = export_gif_monitor_events(); done = export_gif_monitor_events();
} }
/* Close the GIF */ /* Close the GIF */
ge_close_gif(gif); ge_close_gif(gif);
} else { } else {
fprintf(stderr, "Quantization failed\n"); fprintf(stderr, "Quantization failed\n");
done = 1; done = 1;
} }
if (done) if (done)
{ {
/* Aborted; discard the partially-saved GIF */ /* Aborted; discard the partially-saved GIF */
@ -26657,7 +26662,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
starter_flipped = tmp_starter_flipped; starter_flipped = tmp_starter_flipped;
starter_personal = tmp_starter_personal; starter_personal = tmp_starter_personal;
free(gif_fname); free(gif_fname);
/* Success if we didn't have an error, and user didn't abort */ /* Success if we didn't have an error, and user didn't abort */