From 5a1a80ff69180640cd0294297980e36d9c53c1eb Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Tue, 10 Nov 2020 09:54:50 -0800 Subject: [PATCH] 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. --- src/tuxpaint.c | 81 +++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/src/tuxpaint.c b/src/tuxpaint.c index c08b32d76..da91f03e4 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 - October 15, 2020 + June 14, 2002 - November 10, 2020 */ @@ -1533,7 +1533,7 @@ static SDL_Surface *render_text(TuxPaint_Font * restrict font, const char *restr /** * Convert a wide-character string to string of Uint16's. - * + * * 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. * Mismatch caused by the use of Uint16 for unicode characters by SDL, SDL_ttf. @@ -2220,7 +2220,7 @@ int brushflag, xnew, ynew, eraflag, lineflag, magicflag, keybd_flag, keybd_posit int cur_thing; /** - * --- MAIN LOOP! --- + * --- MAIN LOOP! --- */ static void mainloop(void) { @@ -9274,7 +9274,7 @@ static void draw_shapes(void) /* Show shape-from-center button: */ - if (shape_mode == SHAPEMODE_CENTER) + if (shape_mode == SHAPEMODE_CENTER) button_color = img_btn_down; else button_color = img_btn_up; @@ -9292,7 +9292,7 @@ static void draw_shapes(void) /* Show shape-from-corner button: */ - if (shape_mode == SHAPEMODE_CORNER) + if (shape_mode == SHAPEMODE_CORNER) button_color = img_btn_down; else button_color = img_btn_up; @@ -11447,7 +11447,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. * Free the original surface. - * + * * @param SDL_Surface * src -- source surface (will be freed by this function!) * @param SDL_Surface * dst -- destination surface * @param int SDCALL(*blit) -- function for blitting; "NondefectiveBlit" or "SDL_BlitSurface" @@ -13181,22 +13181,22 @@ static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush) if (rotn != 0) { rotn_rad = rotn * M_PI / 180; - + xp = (x1 + offx) * cos(rotn_rad) - (y1 + offy) * sin(rotn_rad); yp = (x1 + offx) * sin(rotn_rad) + (y1 + offy) * cos(rotn_rad); - + x1 = xp - offx; y1 = yp - offy; - + xp = (x2 + offx) * cos(rotn_rad) - (y2 + offy) * sin(rotn_rad); yp = (x2 + offx) * sin(rotn_rad) + (y2 + offy) * cos(rotn_rad); - + x2 = xp - offx; y2 = yp - offy; - + xp = (xv + offx) * cos(rotn_rad) - (yv + offy) * sin(rotn_rad); yp = (xv + offx) * sin(rotn_rad) + (yv + offy) * cos(rotn_rad); - + xv = xp - offx; yv = yp - offy; } @@ -13271,6 +13271,10 @@ static int shape_rotation(int ctr_x, int ctr_y, int ox, int oy) else if (shape_radius < 100) 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]) { int angle_skip; @@ -13278,6 +13282,7 @@ static int shape_rotation(int ctr_x, int ctr_y, int ox, int oy) angle_skip = 360 / shape_sides[cur_shape]; deg = deg % angle_skip; } +*/ return (deg); } @@ -16003,19 +16008,19 @@ static int do_slideshow(void) draw_toolbar(); draw_colors(COLORSEL_CLOBBER_WIPE); draw_none(); - + /* Show a message depending on success */ if (export_successful) do_prompt_snd(PROMPT_GIF_EXPORT_TXT, PROMPT_EXPORT_YES, "", SND_TUXOK, screen->w / 2, screen->h / 2); else do_prompt_snd(PROMPT_GIF_EXPORT_FAILED_TXT, PROMPT_EXPORT_YES, "", SND_YOUCANNOT, screen->w / 2, screen->h / 2); - + freeme = textdir(TUX_TIP_SLIDESHOW); draw_tux_text(TUX_BORED, freeme, 1); free(freeme); - + SDL_Flip(screen); - + update_list = 1; } } @@ -22971,7 +22976,7 @@ static void setup_config(char *argv[]) free(picturesdir); exportdir = strdup(str); } - + /* Load options from user's own configuration (".rc" / ".cfg") file: */ #if defined(_WIN32) @@ -25575,12 +25580,12 @@ char * get_xdg_user_dir(const char * dir_type, const char * fallback) { } else { safe_strncpy(return_path, found, MAX_PATH); } - + /* Trim trailing " */ if (return_path[strlen(return_path) - 1] == '\"') { return_path[strlen(return_path) - 1] = '\0'; } - + found_it = TRUE; } } @@ -25672,34 +25677,34 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n if (bitmap != NULL) { done = 0; - + for (i = 0; i < num_selected && !done; i++) { which = selected[i]; show_progress_bar(screen); - - + + /* Figure out filename: */ safe_snprintf(fname, sizeof(fname), "%s/%s%s", dirname, d_names[which], d_exts[which]); - + /* Load and scale the image */ img = myIMG_Load(fname); - + if (img != NULL) { autoscale_copy_smear_free(img, screen, SDL_BlitSurface); - + safe_strncpy(file_id, d_names[which], sizeof(file_id)); - + /* See if this saved image was based on a 'starter' */ load_starter_id(d_names[which], NULL); if (starter_id[0] != '\0') { load_starter(starter_id); - + if (starter_mirrored) mirror_starter(); - + if (starter_flipped) flip_starter(); } @@ -25715,7 +25720,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n for (y = 0; y < overall_h; y++) { for (x = 0; x < overall_w; x++) { 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 + 1] = g; bitmap[((i * overall_area) + (y * overall_w) + x) * 4 + 2] = b; @@ -25724,7 +25729,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n } SDL_Flip(screen); - done = export_gif_monitor_events(); + done = export_gif_monitor_events(); } @@ -25732,7 +25737,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 */ 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); show_progress_bar(screen); @@ -25750,7 +25755,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n pixels_size = num_selected * overall_area; raw_8bit_pixels = malloc(pixels_size); liq_set_dithering_level(quantization_result, 1.0); - + liq_write_remapped_image(quantization_result, input_image, raw_8bit_pixels, pixels_size); palette = liq_get_palette(quantization_result); free(bitmap); @@ -25769,24 +25774,24 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n 8, /* 256 colors */ 0 /* infinite loop */ ); - + /* Export each frame */ for (i = 0; i < num_selected && !done; i++) { memcpy(gif->frame, raw_8bit_pixels + i * overall_area, overall_area); ge_add_frame(gif, gif_speed); - + show_progress_bar(screen); - done = export_gif_monitor_events(); + done = export_gif_monitor_events(); } - + /* Close the GIF */ ge_close_gif(gif); } else { fprintf(stderr, "Quantization failed\n"); done = 1; } - + if (done) { /* Aborted; discard the partially-saved GIF */ @@ -25816,7 +25821,7 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n starter_flipped = tmp_starter_flipped; starter_personal = tmp_starter_personal; - + free(gif_fname); /* Success if we didn't have an error, and user didn't abort */