diff --git a/ChangeLog b/ChangeLog index 3afa1d31a2..d642a97c5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2008-07-18 Sven Neumann + + * app/core/core-types.h: removed delta_time, delta_x, delta_y, + distance and random from the GimpCoords struct. These don't need + to be kept here and they can't be properly interpolated. + + * app/core/gimpcoords.c: changed accordingly. + + * app/xcf/xcf-load.c (xcf_load_vector): the size of the GimpCoords + struct changed. + + * app/display/gimpdisplayshell.[ch] (struct _GimpDisplayShell): + added some members to store values from the last event that are + needed in gimp_display_shell_eval_event() and which are not any + longer part of GimpCoords. + + * app/display/gimpdisplayshell-coords.c + (gimp_display_shell_eval_event): changed accordingly. + + * app/paint/gimppaintoptions.c: calculate a random number when one + is needed. + + * app/paint/gimpbrushcore.c (gimp_brush_core_interpolate): + GimpCoords doesn't have a "random" field any longer. + 2008-07-18 Sven Neumann * app/core/core-types.h (GIMP_COORDS_DEFAULT_VALUES): initialize diff --git a/app/core/core-types.h b/app/core/core-types.h index 3bbc8b4f58..ab1a9dff91 100644 --- a/app/core/core-types.h +++ b/app/core/core-types.h @@ -52,9 +52,7 @@ GIMP_COORDS_DEFAULT_TILT, \ GIMP_COORDS_DEFAULT_TILT, \ GIMP_COORDS_DEFAULT_WHEEL, \ - 0.0, 0.0, 0.0, 0.0, \ - GIMP_COORDS_DEFAULT_VELOCITY, \ - 0.0 } + GIMP_COORDS_DEFAULT_VELOCITY } /* base classes */ @@ -204,12 +202,7 @@ struct _GimpCoords gdouble xtilt; gdouble ytilt; gdouble wheel; - gdouble delta_time; - gdouble delta_x; - gdouble delta_y; - gdouble distance; gdouble velocity; - gdouble random; }; diff --git a/app/core/gimpcoords.c b/app/core/gimpcoords.c index 7b2fa59afa..12e69495cb 100644 --- a/app/core/gimpcoords.c +++ b/app/core/gimpcoords.c @@ -44,33 +44,23 @@ gimp_coords_mix (const gdouble amul, { if (b) { - ret_val->x = amul * a->x + bmul * b->x; - ret_val->y = amul * a->y + bmul * b->y; - ret_val->pressure = amul * a->pressure + bmul * b->pressure; - ret_val->xtilt = amul * a->xtilt + bmul * b->xtilt; - ret_val->ytilt = amul * a->ytilt + bmul * b->ytilt; - ret_val->wheel = amul * a->wheel + bmul * b->wheel; - ret_val->delta_time = amul * a->delta_time + bmul * b->delta_time; - ret_val->delta_x = amul * a->delta_x + bmul * b->delta_x; - ret_val->delta_y = amul * a->delta_y + bmul * b->delta_y; - ret_val->distance = amul * a->distance + bmul * b->distance; - ret_val->velocity = amul * a->velocity + bmul * b->velocity; - ret_val->random = amul * a->random + bmul * b->random; + ret_val->x = amul * a->x + bmul * b->x; + ret_val->y = amul * a->y + bmul * b->y; + ret_val->pressure = amul * a->pressure + bmul * b->pressure; + ret_val->xtilt = amul * a->xtilt + bmul * b->xtilt; + ret_val->ytilt = amul * a->ytilt + bmul * b->ytilt; + ret_val->wheel = amul * a->wheel + bmul * b->wheel; + ret_val->velocity = amul * a->velocity + bmul * b->velocity; } else { - ret_val->x = amul * a->x; - ret_val->y = amul * a->y; - ret_val->pressure = amul * a->pressure; - ret_val->xtilt = amul * a->xtilt; - ret_val->ytilt = amul * a->ytilt; - ret_val->wheel = amul * a->wheel; - ret_val->delta_time = amul * a->delta_time; - ret_val->delta_x = amul * a->delta_x; - ret_val->delta_y = amul * a->delta_y; - ret_val->distance = amul * a->distance; - ret_val->velocity = amul * a->velocity; - ret_val->random = amul * a->random; + ret_val->x = amul * a->x; + ret_val->y = amul * a->y; + ret_val->pressure = amul * a->pressure; + ret_val->xtilt = amul * a->xtilt; + ret_val->ytilt = amul * a->ytilt; + ret_val->wheel = amul * a->wheel; + ret_val->velocity = amul * a->velocity; } } diff --git a/app/display/gimpdisplayshell-coords.c b/app/display/gimpdisplayshell-coords.c index 246ae28bfa..42cbf4b9f5 100644 --- a/app/display/gimpdisplayshell-coords.c +++ b/app/display/gimpdisplayshell-coords.c @@ -213,6 +213,11 @@ gimp_display_shell_eval_event (GimpDisplayShell *shell, gdouble inertia_factor, guint32 time) { + gdouble delta_time = 0.001; + gdouble delta_x = 0.0; + gdouble delta_y = 0.0; + gdouble distance = 1.0; + /* Smoothing causes problems with cursor tracking * when zoomed above screen resolution so we need to supress it. */ @@ -221,22 +226,21 @@ gimp_display_shell_eval_event (GimpDisplayShell *shell, inertia_factor = 0.0; } - if (shell->last_disp_motion_time == 0) + if (shell->last_motion_time == 0) { /* First pair is invalid to do any velocity calculation, - * so we apply constant values. + * so we apply a constant value. */ - coords->velocity = 1.0; - coords->delta_time = 0.001; - coords->distance = 1; + coords->velocity = 1.0; } else { - gdouble dx = coords->delta_x = shell->last_coords.x - coords->x; - gdouble dy = coords->delta_y = shell->last_coords.y - coords->y; gdouble filter; gdouble dist; + delta_x = shell->last_coords.x - coords->x; + delta_y = shell->last_coords.y - coords->y; + #define SMOOTH_FACTOR 0.3 /* Events with distances less than the screen resolution are not @@ -244,20 +248,18 @@ gimp_display_shell_eval_event (GimpDisplayShell *shell, */ filter = MIN (1 / shell->scale_x, 1 / shell->scale_y) / 2.0; - if (fabs (dx) < filter && fabs (dy) < filter) + if (fabs (delta_x) < filter && fabs (delta_y) < filter) return FALSE; - coords->delta_time = time - shell->last_disp_motion_time; - coords->delta_time = (shell->last_coords.delta_time * (1 - SMOOTH_FACTOR) - + coords->delta_time * SMOOTH_FACTOR); - coords->distance = dist = sqrt (SQR (dx) + SQR (dy)); + delta_time = (shell->last_motion_delta_time * (1 - SMOOTH_FACTOR) + + (time - shell->last_motion_time) * SMOOTH_FACTOR); - coords->random = g_random_double_range (0.0, 1.0); + distance = dist = sqrt (SQR (delta_x) + SQR (delta_y)); /* If even smoothed time resolution does not allow to guess for speed, * use last velocity. */ - if ((coords->delta_time == 0)) + if (delta_time == 0) { coords->velocity = shell->last_coords.velocity; } @@ -266,14 +268,13 @@ gimp_display_shell_eval_event (GimpDisplayShell *shell, /* We need to calculate the velocity in screen coordinates * for human interaction */ - gdouble screen_distance = (coords->distance * + gdouble screen_distance = (distance * MIN (shell->scale_x, shell->scale_y)); /* Calculate raw valocity */ - coords->velocity = ((screen_distance / (gdouble) coords->delta_time) / - VELOCITY_UNIT); + coords->velocity = ((screen_distance / delta_time) / VELOCITY_UNIT); - /* Adding velocity dependent smooth, feels better in tools this way. */ + /* Adding velocity dependent smoothing, feels better in tools. */ coords->velocity = (shell->last_coords.velocity * (1 - MIN (SMOOTH_FACTOR, coords->velocity)) + coords->velocity * @@ -282,10 +283,11 @@ gimp_display_shell_eval_event (GimpDisplayShell *shell, /* Speed needs upper limit */ coords->velocity = MIN (coords->velocity, 1.0); } + /* High speed -> less smooth*/ inertia_factor *= (1 - coords->velocity); - if (inertia_factor > 0 && coords->distance > 0) + if (inertia_factor > 0 && distance > 0) { /* Apply smoothing to X and Y. */ @@ -301,23 +303,21 @@ gimp_display_shell_eval_event (GimpDisplayShell *shell, gdouble new_x; gdouble new_y; - sin_new = coords->delta_x / coords->distance; - sin_old = shell->last_coords.delta_x / shell->last_coords.distance; + sin_new = delta_x / distance; + sin_old = shell->last_motion_delta_x / shell->last_motion_distance; sin_avg = sin (asin (sin_old) * inertia_factor + asin (sin_new) * (1 - inertia_factor)); - cos_new = coords->delta_y / coords->distance; - cos_old = shell->last_coords.delta_y / shell->last_coords.distance; + cos_new = delta_y / distance; + cos_old = shell->last_motion_delta_y / shell->last_motion_distance; cos_avg = cos (acos (cos_old) * inertia_factor + acos (cos_new) * (1 - inertia_factor)); - coords->delta_x = sin_avg * coords->distance; - coords->delta_y = cos_avg * coords->distance; + delta_x = sin_avg * distance; + delta_y = cos_avg * distance; - new_x = - (shell->last_coords.x - coords->delta_x) * 0.5 + coords->x * 0.5; - new_y = - (shell->last_coords.y - coords->delta_y) * 0.5 + coords->y * 0.5; + new_x = (shell->last_coords.x - delta_x) * 0.5 + coords->x * 0.5; + new_y = (shell->last_coords.y - delta_y) * 0.5 + coords->y * 0.5; cur_deviation = SQR (coords->x - new_x) + SQR (coords->y - new_y); @@ -333,18 +333,17 @@ gimp_display_shell_eval_event (GimpDisplayShell *shell, coords->x = new_x; coords->y = new_y; - coords->delta_x = shell->last_coords.x - coords->x; - coords->delta_y = shell->last_coords.y - coords->y; + delta_x = shell->last_coords.x - coords->x; + delta_y = shell->last_coords.y - coords->y; /* Recalculate distance */ - coords->distance = sqrt (SQR (coords->delta_x) + - SQR (coords->delta_y)); + distance = sqrt (SQR (delta_x) + SQR (delta_y)); } #ifdef VERBOSE g_printerr ("DIST: %f, DT:%f, Vel:%f, Press:%f,smooth_dd:%f, sf %f\n", - coords->distance, - coords->delta_time, + distance, + delta_time, shell->last_coords.velocity, coords->pressure, coords->distance - dist, @@ -352,8 +351,13 @@ gimp_display_shell_eval_event (GimpDisplayShell *shell, #endif } - shell->last_coords = *coords; - shell->last_disp_motion_time = time; + shell->last_coords = *coords; + + shell->last_motion_time = time; + shell->last_motion_delta_time = delta_time; + shell->last_motion_delta_x = delta_x; + shell->last_motion_delta_y = delta_y; + shell->last_motion_distance = distance; return TRUE; } diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index eb4d5dc15f..fcebe75689 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -337,6 +337,12 @@ gimp_display_shell_init (GimpDisplayShell *shell) shell->scroll_start_x = 0; shell->scroll_start_y = 0; shell->button_press_before_focus = FALSE; + + shell->last_motion_time = 0; + shell->last_motion_delta_x = 0.0; + shell->last_motion_delta_y = 0.0; + shell->last_motion_distance = 0.0; + shell->last_motion_delta_time = 0.0; shell->highlight = NULL; shell->mask = NULL; diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index 2350ca830a..52f85ba2d5 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -180,8 +180,13 @@ struct _GimpDisplayShell gint scroll_start_x; gint scroll_start_y; gboolean button_press_before_focus; - guint32 last_disp_motion_time; /* previous time of a forwarded motion event */ + + guint32 last_motion_time; /* previous time of a forwarded motion event */ guint32 last_read_motion_time; + gdouble last_motion_delta_time; + gdouble last_motion_delta_x; + gdouble last_motion_delta_y; + gdouble last_motion_distance; GdkRectangle *highlight; /* in image coordinates, can be NULL */ GimpDrawable *mask; diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c index 88828d835a..3960276565 100644 --- a/app/paint/gimpbrushcore.c +++ b/app/paint/gimpbrushcore.c @@ -635,7 +635,6 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core, p * delta_wheel); paint_core->cur_coords.velocity = (paint_core->last_coords.velocity + p * delta_velocity); - paint_core->cur_coords.random = g_random_double_range (0.0, 1.0); if (core->jitter > 0.0) { diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c index a6c0f03243..8e920c0d6d 100644 --- a/app/paint/gimppaintoptions.c +++ b/app/paint/gimppaintoptions.c @@ -1002,7 +1002,7 @@ gimp_paint_options_get_dynamic_opacity (GimpPaintOptions *paint_options, velocity = GIMP_PAINT_VELOCITY_SCALE * (1 - coords->velocity); if (paint_options->random_options->opacity) - random = coords->random; + random = g_random_double_range (0.0, 1.0); opacity = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, @@ -1048,11 +1048,11 @@ gimp_paint_options_get_dynamic_size (GimpPaintOptions *paint_options, if (paint_options->random_options->size) { - random = 1.0 - coords->random; + random = 1.0 - g_random_double_range (0.0, 1.0); } else if (paint_options->random_options->inverse_size) { - random = coords->random; + random = g_random_double_range (0.0, 1.0); } scale = gimp_paint_options_get_dynamics_mix (pressure, @@ -1098,7 +1098,7 @@ gimp_paint_options_get_dynamic_rate (GimpPaintOptions *paint_options, velocity = GIMP_PAINT_VELOCITY_SCALE * (1 - coords->velocity); if (paint_options->random_options->rate) - random = coords->random; + random = g_random_double_range (0.0, 1.0); rate = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, @@ -1136,7 +1136,7 @@ gimp_paint_options_get_dynamic_color (GimpPaintOptions *paint_options, velocity = GIMP_PAINT_VELOCITY_SCALE * coords->velocity; if (paint_options->random_options->color) - random = coords->random; + random = g_random_double_range (0.0, 1.0); color = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, @@ -1173,7 +1173,7 @@ gimp_paint_options_get_dynamic_hardness (GimpPaintOptions *paint_options, velocity = GIMP_PAINT_VELOCITY_SCALE * (1 - coords->velocity); if (paint_options->random_options->hardness) - random = coords->random; + random = g_random_double_range (0.0, 1.0); hardness = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c index a0c002d062..52f72cf966 100644 --- a/app/xcf/xcf-load.c +++ b/app/xcf/xcf-load.c @@ -1735,7 +1735,7 @@ xcf_load_vector (XcfInfo *info, guint32 num_axes; guint32 num_control_points; guint32 type; - gfloat coords[6] = GIMP_COORDS_DEFAULT_VALUES; + gfloat coords[7] = GIMP_COORDS_DEFAULT_VALUES; GimpStroke *stroke; gint j;