Commit b490b262 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added "gint freeze_count" and gimp_data_freeze()/thaw() functions. Emit

2004-06-13  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpdata.[ch]: added "gint freeze_count" and
	gimp_data_freeze()/thaw() functions. Emit "dirty" only if
	freeze_count either is 0 or drops to 0.

	* app/core/gimpbrushgenerated.[ch]
	* app/core/gimpgradient.[ch]: removed freeze/thaw stuff that
	was duplicated in these two subclasses and use the new
	GimpData API instead.

	* app/widgets/gimpbrusheditor.c
	* app/widgets/gimpgradienteditor.c: changed accordingly.
parent 2fd178c6
2004-06-13 Michael Natterer <mitch@gimp.org>
* app/core/gimpdata.[ch]: added "gint freeze_count" and
gimp_data_freeze()/thaw() functions. Emit "dirty" only if
freeze_count either is 0 or drops to 0.
* app/core/gimpbrushgenerated.[ch]
* app/core/gimpgradient.[ch]: removed freeze/thaw stuff that
was duplicated in these two subclasses and use the new
GimpData API instead.
* app/widgets/gimpbrusheditor.c
* app/widgets/gimpgradienteditor.c: changed accordingly.
2004-06-12 Sven Neumann <sven@gimp.org>
* app/widgets/gimpcolorbar.c (gimp_color_bar_expose): don't copy
......
......@@ -111,7 +111,6 @@ gimp_brush_generated_init (GimpBrushGenerated *brush)
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
static gboolean
......@@ -227,9 +226,6 @@ gimp_brush_generated_dirty (GimpData *data)
gdouble short_radius;
gdouble buffer[OVERSAMPLING];
if (brush->freeze) /* if we are frozen defer rerendering till later */
return;
if (gbrush->mask)
temp_buf_free (gbrush->mask);
......@@ -413,7 +409,7 @@ gimp_brush_generated_load (const gchar *filename,
"name", string,
NULL);
gimp_brush_generated_freeze (brush);
gimp_data_freeze (GIMP_DATA (brush));
/* read brush spacing */
fgets (string, 255, file);
......@@ -437,7 +433,7 @@ gimp_brush_generated_load (const gchar *filename,
fclose (file);
gimp_brush_generated_thaw (brush);
gimp_data_thaw (GIMP_DATA (brush));
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
......@@ -445,26 +441,6 @@ gimp_brush_generated_load (const gchar *filename,
return GIMP_DATA (brush);
}
void
gimp_brush_generated_freeze (GimpBrushGenerated *brush)
{
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
brush->freeze++;
}
void
gimp_brush_generated_thaw (GimpBrushGenerated *brush)
{
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze > 0)
brush->freeze--;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
}
gfloat
gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
gfloat radius)
......@@ -477,8 +453,7 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
{
brush->radius = radius;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->radius;
......@@ -496,8 +471,7 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
{
brush->hardness = hardness;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->hardness;
......@@ -518,8 +492,7 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
{
brush->angle = angle;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->angle;
......@@ -537,8 +510,7 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
{
brush->aspect_ratio = ratio;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->aspect_ratio;
......
......@@ -111,7 +111,6 @@ gimp_brush_generated_init (GimpBrushGenerated *brush)
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
static gboolean
......@@ -227,9 +226,6 @@ gimp_brush_generated_dirty (GimpData *data)
gdouble short_radius;
gdouble buffer[OVERSAMPLING];
if (brush->freeze) /* if we are frozen defer rerendering till later */
return;
if (gbrush->mask)
temp_buf_free (gbrush->mask);
......@@ -413,7 +409,7 @@ gimp_brush_generated_load (const gchar *filename,
"name", string,
NULL);
gimp_brush_generated_freeze (brush);
gimp_data_freeze (GIMP_DATA (brush));
/* read brush spacing */
fgets (string, 255, file);
......@@ -437,7 +433,7 @@ gimp_brush_generated_load (const gchar *filename,
fclose (file);
gimp_brush_generated_thaw (brush);
gimp_data_thaw (GIMP_DATA (brush));
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
......@@ -445,26 +441,6 @@ gimp_brush_generated_load (const gchar *filename,
return GIMP_DATA (brush);
}
void
gimp_brush_generated_freeze (GimpBrushGenerated *brush)
{
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
brush->freeze++;
}
void
gimp_brush_generated_thaw (GimpBrushGenerated *brush)
{
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze > 0)
brush->freeze--;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
}
gfloat
gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
gfloat radius)
......@@ -477,8 +453,7 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
{
brush->radius = radius;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->radius;
......@@ -496,8 +471,7 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
{
brush->hardness = hardness;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->hardness;
......@@ -518,8 +492,7 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
{
brush->angle = angle;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->angle;
......@@ -537,8 +510,7 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
{
brush->aspect_ratio = ratio;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->aspect_ratio;
......
......@@ -111,7 +111,6 @@ gimp_brush_generated_init (GimpBrushGenerated *brush)
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
static gboolean
......@@ -227,9 +226,6 @@ gimp_brush_generated_dirty (GimpData *data)
gdouble short_radius;
gdouble buffer[OVERSAMPLING];
if (brush->freeze) /* if we are frozen defer rerendering till later */
return;
if (gbrush->mask)
temp_buf_free (gbrush->mask);
......@@ -413,7 +409,7 @@ gimp_brush_generated_load (const gchar *filename,
"name", string,
NULL);
gimp_brush_generated_freeze (brush);
gimp_data_freeze (GIMP_DATA (brush));
/* read brush spacing */
fgets (string, 255, file);
......@@ -437,7 +433,7 @@ gimp_brush_generated_load (const gchar *filename,
fclose (file);
gimp_brush_generated_thaw (brush);
gimp_data_thaw (GIMP_DATA (brush));
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
......@@ -445,26 +441,6 @@ gimp_brush_generated_load (const gchar *filename,
return GIMP_DATA (brush);
}
void
gimp_brush_generated_freeze (GimpBrushGenerated *brush)
{
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
brush->freeze++;
}
void
gimp_brush_generated_thaw (GimpBrushGenerated *brush)
{
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze > 0)
brush->freeze--;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
}
gfloat
gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
gfloat radius)
......@@ -477,8 +453,7 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
{
brush->radius = radius;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->radius;
......@@ -496,8 +471,7 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
{
brush->hardness = hardness;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->hardness;
......@@ -518,8 +492,7 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
{
brush->angle = angle;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->angle;
......@@ -537,8 +510,7 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
{
brush->aspect_ratio = ratio;
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
gimp_data_dirty (GIMP_DATA (brush));
}
return brush->aspect_ratio;
......
......@@ -46,9 +46,6 @@ struct _GimpBrushGenerated
gfloat hardness; /* 0.0 - 1.0 */
gfloat angle; /* in degrees */
gfloat aspect_ratio; /* y/x */
/* private */
gint freeze;
};
struct _GimpBrushGeneratedClass
......@@ -69,9 +66,6 @@ GimpData * gimp_brush_generated_load (const gchar *file_name,
gboolean stingy_memory_use,
GError **error);
void gimp_brush_generated_freeze (GimpBrushGenerated *brush);
void gimp_brush_generated_thaw (GimpBrushGenerated *brush);
gfloat gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
gfloat radius);
gfloat gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
......
......@@ -138,11 +138,12 @@ static void
gimp_data_init (GimpData *data,
GimpDataClass *data_class)
{
data->filename = NULL;
data->writable = TRUE;
data->deletable = TRUE;
data->dirty = TRUE;
data->internal = FALSE;
data->filename = NULL;
data->writable = TRUE;
data->deletable = TRUE;
data->dirty = TRUE;
data->internal = FALSE;
data->freeze_count = 0;
/* look at the passed class pointer, not at GIMP_DATA_GET_CLASS(data)
* here, because the latter is always GimpDataClass itself
......@@ -188,6 +189,14 @@ gimp_data_get_memsize (GimpObject *object,
gui_size);
}
static void
gimp_data_real_dirty (GimpData *data)
{
data->dirty = TRUE;
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (data));
}
gboolean
gimp_data_save (GimpData *data,
GError **error)
......@@ -220,15 +229,28 @@ gimp_data_dirty (GimpData *data)
{
g_return_if_fail (GIMP_IS_DATA (data));
g_signal_emit (data, data_signals[DIRTY], 0);
if (data->freeze_count == 0)
g_signal_emit (data, data_signals[DIRTY], 0);
}
static void
gimp_data_real_dirty (GimpData *data)
void
gimp_data_freeze (GimpData *data)
{
data->dirty = TRUE;
g_return_if_fail (GIMP_IS_DATA (data));
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (data));
data->freeze_count++;
}
void
gimp_data_thaw (GimpData *data)
{
g_return_if_fail (GIMP_IS_DATA (data));
g_return_if_fail (data->freeze_count > 0);
data->freeze_count--;
if (data->freeze_count == 0)
gimp_data_dirty (data);
}
gboolean
......
......@@ -54,6 +54,7 @@ struct _GimpData
guint deletable : 1;
guint dirty : 1;
guint internal : 1;
gint freeze_count;
};
struct _GimpDataClass
......@@ -78,6 +79,9 @@ gboolean gimp_data_save (GimpData *data,
GError **error);
void gimp_data_dirty (GimpData *data);
void gimp_data_freeze (GimpData *data);
void gimp_data_thaw (GimpData *data);
gboolean gimp_data_delete_from_disk (GimpData *data,
GError **error);
......
......@@ -145,7 +145,6 @@ gimp_gradient_init (GimpGradient *gradient)
{
gradient->segments = NULL;
gradient->last_visited = NULL;
gradient->freeze_count = 0;
}
static void
......@@ -823,26 +822,6 @@ gimp_gradient_get_segment_at (GimpGradient *gradient,
return NULL;
}
void
gimp_gradient_freeze (GimpGradient *gradient)
{
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
gradient->freeze_count++;
}
void
gimp_gradient_thaw (GimpGradient *gradient)
{
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
g_return_if_fail (gradient->freeze_count > 0);
gradient->freeze_count--;
if (gradient->freeze_count == 0)
gimp_data_dirty (GIMP_DATA (gradient));
}
static gdouble
gimp_gradient_calc_linear_factor (gdouble middle,
gdouble pos)
......@@ -1013,7 +992,7 @@ gimp_gradient_segment_split_midpoint (GimpGradient *gradient,
g_return_if_fail (newl != NULL);
g_return_if_fail (newr != NULL);
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
/* Get color at original segment's midpoint */
gimp_gradient_get_color_at (gradient, lseg->middle, FALSE, &color);
......@@ -1060,7 +1039,7 @@ gimp_gradient_segment_split_midpoint (GimpGradient *gradient,
*newl = lseg;
*newr = newseg;
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
void
......@@ -1079,7 +1058,7 @@ gimp_gradient_segment_split_uniform (GimpGradient *gradient,
g_return_if_fail (newl != NULL);
g_return_if_fail (newr != NULL);
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
seg_len = (lseg->right - lseg->left) / parts; /* Length of divisions */
......@@ -1146,7 +1125,7 @@ gimp_gradient_segment_split_uniform (GimpGradient *gradient,
gimp_gradient_segment_free (lseg);
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
void
......@@ -1170,13 +1149,13 @@ gimp_gradient_segment_set_left_color (GimpGradient *gradient,
g_return_if_fail (seg != NULL);
g_return_if_fail (color != NULL);
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
gimp_gradient_segment_range_blend (gradient, seg, seg,
color, &seg->right_color,
TRUE, TRUE);
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
void
......@@ -1200,13 +1179,13 @@ gimp_gradient_segment_set_right_color (GimpGradient *gradient,
g_return_if_fail (seg != NULL);
g_return_if_fail (color != NULL);
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
gimp_gradient_segment_range_blend (gradient, seg, seg,
&seg->left_color, color,
TRUE, TRUE);
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
gdouble
......@@ -1235,14 +1214,14 @@ gimp_gradient_segment_set_left_pos (GimpGradient *gradient,
}
else
{
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
final_pos = seg->prev->right = seg->left =
CLAMP (pos,
seg->prev->middle + EPSILON,
seg->middle - EPSILON);
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
return final_pos;
......@@ -1274,14 +1253,14 @@ gimp_gradient_segment_set_right_pos (GimpGradient *gradient,
}
else
{
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
final_pos = seg->next->left = seg->right =
CLAMP (pos,
seg->middle + EPSILON,
seg->next->middle - EPSILON);
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
return final_pos;
......@@ -1307,14 +1286,14 @@ gimp_gradient_segment_set_middle_pos (GimpGradient *gradient,
g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), 0.0);
g_return_val_if_fail (seg != NULL, 0.0);
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
final_pos = seg->middle =
CLAMP (pos,
seg->left + EPSILON,
seg->right - EPSILON);
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
return final_pos;
}
......@@ -1351,7 +1330,7 @@ gimp_gradient_segment_range_compress (GimpGradient *gradient,
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
g_return_if_fail (range_l != NULL);
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
if (! range_r)
range_r = gimp_gradient_segment_get_last (range_l);
......@@ -1378,7 +1357,7 @@ gimp_gradient_segment_range_compress (GimpGradient *gradient,
}
while (aseg != range_r);
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
void
......@@ -1398,7 +1377,7 @@ gimp_gradient_segment_range_blend (GimpGradient *gradient,
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
g_return_if_fail (lseg != NULL);
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
if (! rseg)
rseg = gimp_gradient_segment_get_last (lseg);
......@@ -1436,7 +1415,7 @@ gimp_gradient_segment_range_blend (GimpGradient *gradient,
seg = seg->next;
}
while (aseg != rseg);
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
......@@ -1451,7 +1430,7 @@ gimp_gradient_segment_range_set_blending_function (GimpGradient *grad
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
seg = start_seg;
while (seg && ! reached_last_segment)
......@@ -1463,7 +1442,7 @@ gimp_gradient_segment_range_set_blending_function (GimpGradient *grad
seg = seg->next;
}
gimp_gradient_thaw (gradient);
gimp_data_thaw (GIMP_DATA (gradient));
}
void
......@@ -1477,7 +1456,7 @@ gimp_gradient_segment_range_set_coloring_type (GimpGradient *gradien
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
gimp_gradient_freeze (gradient);
gimp_data_freeze (GIMP_DATA (gradient));
seg = start_seg;
while (seg && ! reached_last_segment)
......@@ -1489,7 +1468,7 @@ gimp_gradient_segment_range_set_coloring_type (GimpGradient *gradien
seg = seg->next;
}
gimp_gradient_thaw (gradient);