Commit a528c42a authored by jaycox's avatar jaycox
Browse files

----------------------------------------------------------------------


 ----------------------------------------------------------------------
 Modified Files:
 	ChangeLog app/brush_edit.c app/brush_select.c
	app/gimpbrushgenerated.c app/gimpbrushgenerated.h
 	app/interface.c
     Added freeze/thaw to gimpbrushgenerated.
     added a close button and a preview to the brush_edit dialog.
 ----------------------------------------------------------------------
parent 0de5a3e2
Wed Jul 15 04:55:30 PDT 1998 Jay Cox <jaycox@earthlink.net>
* app/gimpbrushgenerated.c
* app/gimpbrushgenerated.h
Added freeze/thaw methods
* app/brush_edit.c
display a preview in the brush_edit window
Tue Jul 14 19:22:46 PDT 1998 Manish Singh <yosh@gimp.org>
* acconfig.h
......
......@@ -21,8 +21,19 @@
#include "appenv.h"
#include "gimpbrushgenerated.h"
#include "brush_edit.h"
#include "actionarea.h"
#include "math.h"
static void
brush_edit_close_callback (GtkWidget *w, void *data);
/* the action area structure */
static ActionAreaItem action_items[] =
{
{ "Close", brush_edit_close_callback, NULL, NULL }
};
static void
update_brush_callback (GtkAdjustment *adjustment,
BrushEditGeneratedWindow *begw)
......@@ -37,6 +48,7 @@ update_brush_callback (GtkAdjustment *adjustment,
|| (begw->angle_data->value
!=gimp_brush_generated_get_angle(begw->brush))))
{
gimp_brush_generated_freeze (begw->brush);
gimp_brush_generated_set_radius (begw->brush,
begw->radius_data->value);
gimp_brush_generated_set_hardness (begw->brush,
......@@ -45,11 +57,11 @@ update_brush_callback (GtkAdjustment *adjustment,
begw->aspect_ratio_data->value);
gimp_brush_generated_set_angle (begw->brush,
begw->angle_data->value);
gimp_brush_generated_generate(begw->brush);
gimp_brush_generated_thaw (begw->brush);
}
}
static int
static gint
brush_edit_delete_callback (GtkWidget *w,
BrushEditGeneratedWindow *begw)
{
......@@ -58,16 +70,84 @@ brush_edit_delete_callback (GtkWidget *w,
return TRUE;
}
static void
brush_edit_clear_preview (BrushEditGeneratedWindow *begw)
{
unsigned char * buf;
int i;
buf = (unsigned char *) g_malloc (sizeof (char) * begw->preview->requisition.width);
/* Set the buffer to white */
memset (buf, 255, begw->preview->requisition.width);
/* Set the image buffer to white */
for (i = 0; i < begw->preview->requisition.height; i++)
gtk_preview_draw_row (GTK_PREVIEW (begw->preview), buf, 0, i,
begw->preview->requisition.width);
g_free (buf);
}
static gint
brush_edit_brush_dirty_callback(GimpBrush *brush,
BrushEditGeneratedWindow *begw)
{
int x, y, width, yend, ystart, xo;
int scale;
gchar *src, *buf;
brush_edit_clear_preview (begw);
scale = MAX(ceil(brush->mask->width/(float)begw->preview->requisition.width),
ceil(brush->mask->height/(float)begw->preview->requisition.height));
ystart = 0;
xo = begw->preview->requisition.width/2 - brush->mask->width/(2*scale);
ystart = begw->preview->requisition.height/2 - brush->mask->height/(2*scale);
yend = ystart + brush->mask->height/(scale);
width = BOUNDS (brush->mask->width/scale, 0, begw->preview->requisition.width);
buf = g_new (gchar, width);
src = (gchar *)temp_buf_data (brush->mask);
for (y = ystart; y < yend; y++)
{
/* Invert the mask for display. We're doing this because
* a value of 255 in the mask means it is full intensity.
* However, it makes more sense for full intensity to show
* up as black in this brush preview window...
*/
for (x = 0; x < width; x++)
buf[x] = 255 - src[x*scale];
gtk_preview_draw_row (GTK_PREVIEW (begw->preview), (guchar *)buf, xo, y,
width);
src += brush->mask->width*scale;
}
g_free(buf);
gtk_widget_draw(begw->preview, NULL);
return TRUE;
}
void
brush_edit_generated_set_brush(BrushEditGeneratedWindow *begw,
GimpBrush *gbrush)
{
GimpBrushGenerated *brush = 0;
if (!GIMP_IS_BRUSH_GENERATED(gbrush))
{
if (GTK_WIDGET_VISIBLE (begw->shell))
gtk_widget_hide (begw->shell);
return;
}
brush = GIMP_BRUSH_GENERATED(gbrush);
if (begw->brush)
gtk_signal_disconnect_by_data(GTK_OBJECT(begw->brush), begw);
if (begw)
{
gtk_signal_connect(GTK_OBJECT (brush), "dirty",
GTK_SIGNAL_FUNC(brush_edit_brush_dirty_callback),
begw);
begw->brush = NULL;
gtk_adjustment_set_value(GTK_ADJUSTMENT(begw->radius_data),
gimp_brush_generated_get_radius (brush));
......@@ -78,6 +158,7 @@ brush_edit_generated_set_brush(BrushEditGeneratedWindow *begw,
gtk_adjustment_set_value(GTK_ADJUSTMENT(begw->aspect_ratio_data),
gimp_brush_generated_get_aspect_ratio(brush));
begw->brush = brush;
brush_edit_brush_dirty_callback(GIMP_BRUSH(brush), begw);
}
}
......@@ -86,14 +167,14 @@ brush_edit_generated_new ()
{
BrushEditGeneratedWindow *begw ;
GtkWidget *vbox;
GtkWidget *sbar;
GtkWidget *label;
GtkWidget *slider;
GtkWidget *table;
GtkWidget *button1, *button2;
begw = g_malloc (sizeof (BrushEditGeneratedWindow));
begw->brush = NULL;
begw->redraw = TRUE;
begw->shell = gtk_dialog_new ();
......@@ -132,8 +213,9 @@ brush_edit_generated_new ()
/* brush radius scale */
label = gtk_label_new ("Radius:");
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT);
gtk_table_attach(GTK_TABLE (table), label, 0, 1, 0, 1, 0, 0, 0, 0);
gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.5);
/* gtk_table_attach(GTK_TABLE (table), label, 0, 1, 0, 1, 0, 0, 0, 0); */
gtk_table_attach(GTK_TABLE (table), label, 0, 1, 0, 1, 3, 0, 0, 0);
begw->radius_data = GTK_ADJUSTMENT (gtk_adjustment_new (10.0, 0.0, 100.0, 0.1, 1.0, 0.0));
slider = gtk_hscale_new (begw->radius_data);
gtk_table_attach_defaults(GTK_TABLE (table), slider, 1, 2, 0, 1);
......@@ -148,7 +230,7 @@ brush_edit_generated_new ()
/* brush hardness scale */
label = gtk_label_new ("Hardness:");
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT);
gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.5);
gtk_table_attach(GTK_TABLE (table), label, 0, 1, 1, 2, 0, 0, 0, 0);
begw->hardness_data = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 1.0, 0.01, 0.01, 0.0));
slider = gtk_hscale_new (begw->hardness_data);
......@@ -164,7 +246,7 @@ brush_edit_generated_new ()
/* brush aspect ratio scale */
label = gtk_label_new ("Aspect Ratio:");
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.5);
gtk_table_attach(GTK_TABLE (table), label, 0, 1, 2, 3, 0, 0, 0, 0);
begw->aspect_ratio_data = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 1.0, 20.0, 0.1, 1.0, 0.0));
slider = gtk_hscale_new (begw->aspect_ratio_data);
......@@ -180,7 +262,7 @@ brush_edit_generated_new ()
/* brush angle scale */
label = gtk_label_new ("Angle:");
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.5);
gtk_table_attach(GTK_TABLE (table), label, 0, 1, 3, 4, 0, 0, 0, 0);
begw->angle_data = GTK_ADJUSTMENT (gtk_adjustment_new (00.0, 0.0, 180.0, 0.1, 1.0, 0.0));
slider = gtk_hscale_new (begw->angle_data);
......@@ -197,9 +279,21 @@ brush_edit_generated_new ()
gtk_table_set_col_spacing(GTK_TABLE (table), 0, 3);
gtk_widget_show (table);
/* The action area */
action_items[0].user_data = begw;
build_action_area (GTK_DIALOG (begw->shell), action_items, 1, 0);
gtk_widget_show (vbox);
gtk_widget_show (begw->shell);
return begw;
}
static void
brush_edit_close_callback (GtkWidget *w, void *data)
{
BrushEditGeneratedWindow *begw = (BrushEditGeneratedWindow *)data;
if (GTK_WIDGET_VISIBLE (begw->shell))
gtk_widget_hide (begw->shell);
}
......@@ -113,7 +113,7 @@ static MenuItem option_items[] =
static ActionAreaItem action_items[] =
{
{ "Close", brush_select_close_callback, NULL, NULL },
{ "Refresh", brush_select_refresh_callback, NULL, NULL },
{ "Refresh", brush_select_refresh_callback, NULL, NULL }
};
static double old_opacity;
......@@ -323,6 +323,7 @@ brush_select_new ()
/* render the brushes into the newly created image structure */
display_brushes (bsp);
/* add callbacks to keep the display area current */
gimp_list_foreach(GIMP_LIST(brush_list), (GFunc)connect_signals_to_brush,
bsp);
gtk_signal_connect (GTK_OBJECT (brush_list), "add",
......
......@@ -26,6 +26,9 @@
#define OVERSAMPLING 5
static void
gimp_brush_generated_generate(GimpBrushGenerated *brush);
static GimpObjectClass* parent_class;
static void
......@@ -53,6 +56,7 @@ gimp_brush_generated_init(GimpBrushGenerated *brush)
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
guint gimp_brush_generated_get_type(void)
......@@ -100,6 +104,27 @@ GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness,
return brush;
}
void
gimp_brush_generated_freeze(GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
brush->freeze++;
}
void
gimp_brush_generated_thaw(GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze > 0)
brush->freeze--;
if (brush->freeze == 0)
gimp_brush_generated_generate(brush);
}
void
gimp_brush_generated_generate(GimpBrushGenerated *brush)
{
......@@ -114,11 +139,11 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
double buffer[OVERSAMPLING];
register double sum, c, s, tx, ty;
int width, height;
if (!GIMP_IS_BRUSH_GENERATED(brush))
{
g_message("call to gimp_brush_generated_generate on non generated brush");
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze) /* if we are frozen defer rerendering till later */
return;
}
gbrush = GIMP_BRUSH(brush);
if (gbrush->mask)
{
......@@ -209,7 +234,11 @@ gimp_brush_generated_set_radius (GimpBrushGenerated* brush, float radius)
radius = 0.0;
else if(radius > 32767.0)
radius = 32767.0;
if (radius == brush->radius)
return radius;
brush->radius = radius;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->radius;
}
......@@ -221,7 +250,11 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated* brush, float hardness)
hardness = 0.0;
else if(hardness > 1.0)
hardness = 1.0;
if (brush->hardness == hardness)
return hardness;
brush->hardness = hardness;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->hardness;
}
......@@ -233,7 +266,11 @@ gimp_brush_generated_set_angle (GimpBrushGenerated* brush, float angle)
angle = -1.0 * fmod(angle, 180.0);
else if(angle > 180.0)
angle = fmod(angle, 180.0);
if (brush->angle == angle)
return angle;
brush->angle = angle;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->angle;
}
......@@ -245,7 +282,11 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated* brush, float ratio)
ratio = 1.0;
else if(ratio > 1000)
ratio = 1000;
if (brush->aspect_ratio == ratio)
return ratio;
brush->aspect_ratio = ratio;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->aspect_ratio;
}
......
......@@ -26,6 +26,9 @@
#define OVERSAMPLING 5
static void
gimp_brush_generated_generate(GimpBrushGenerated *brush);
static GimpObjectClass* parent_class;
static void
......@@ -53,6 +56,7 @@ gimp_brush_generated_init(GimpBrushGenerated *brush)
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
guint gimp_brush_generated_get_type(void)
......@@ -100,6 +104,27 @@ GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness,
return brush;
}
void
gimp_brush_generated_freeze(GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
brush->freeze++;
}
void
gimp_brush_generated_thaw(GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze > 0)
brush->freeze--;
if (brush->freeze == 0)
gimp_brush_generated_generate(brush);
}
void
gimp_brush_generated_generate(GimpBrushGenerated *brush)
{
......@@ -114,11 +139,11 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
double buffer[OVERSAMPLING];
register double sum, c, s, tx, ty;
int width, height;
if (!GIMP_IS_BRUSH_GENERATED(brush))
{
g_message("call to gimp_brush_generated_generate on non generated brush");
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze) /* if we are frozen defer rerendering till later */
return;
}
gbrush = GIMP_BRUSH(brush);
if (gbrush->mask)
{
......@@ -209,7 +234,11 @@ gimp_brush_generated_set_radius (GimpBrushGenerated* brush, float radius)
radius = 0.0;
else if(radius > 32767.0)
radius = 32767.0;
if (radius == brush->radius)
return radius;
brush->radius = radius;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->radius;
}
......@@ -221,7 +250,11 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated* brush, float hardness)
hardness = 0.0;
else if(hardness > 1.0)
hardness = 1.0;
if (brush->hardness == hardness)
return hardness;
brush->hardness = hardness;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->hardness;
}
......@@ -233,7 +266,11 @@ gimp_brush_generated_set_angle (GimpBrushGenerated* brush, float angle)
angle = -1.0 * fmod(angle, 180.0);
else if(angle > 180.0)
angle = fmod(angle, 180.0);
if (brush->angle == angle)
return angle;
brush->angle = angle;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->angle;
}
......@@ -245,7 +282,11 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated* brush, float ratio)
ratio = 1.0;
else if(ratio > 1000)
ratio = 1000;
if (brush->aspect_ratio == ratio)
return ratio;
brush->aspect_ratio = ratio;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->aspect_ratio;
}
......
......@@ -26,6 +26,9 @@
#define OVERSAMPLING 5
static void
gimp_brush_generated_generate(GimpBrushGenerated *brush);
static GimpObjectClass* parent_class;
static void
......@@ -53,6 +56,7 @@ gimp_brush_generated_init(GimpBrushGenerated *brush)
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
guint gimp_brush_generated_get_type(void)
......@@ -100,6 +104,27 @@ GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness,
return brush;
}
void
gimp_brush_generated_freeze(GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
brush->freeze++;
}
void
gimp_brush_generated_thaw(GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze > 0)
brush->freeze--;
if (brush->freeze == 0)
gimp_brush_generated_generate(brush);
}
void
gimp_brush_generated_generate(GimpBrushGenerated *brush)
{
......@@ -114,11 +139,11 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
double buffer[OVERSAMPLING];
register double sum, c, s, tx, ty;
int width, height;
if (!GIMP_IS_BRUSH_GENERATED(brush))
{
g_message("call to gimp_brush_generated_generate on non generated brush");
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze) /* if we are frozen defer rerendering till later */
return;
}
gbrush = GIMP_BRUSH(brush);
if (gbrush->mask)
{
......@@ -209,7 +234,11 @@ gimp_brush_generated_set_radius (GimpBrushGenerated* brush, float radius)
radius = 0.0;
else if(radius > 32767.0)
radius = 32767.0;
if (radius == brush->radius)
return radius;
brush->radius = radius;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->radius;
}
......@@ -221,7 +250,11 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated* brush, float hardness)
hardness = 0.0;
else if(hardness > 1.0)
hardness = 1.0;
if (brush->hardness == hardness)
return hardness;
brush->hardness = hardness;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->hardness;
}
......@@ -233,7 +266,11 @@ gimp_brush_generated_set_angle (GimpBrushGenerated* brush, float angle)
angle = -1.0 * fmod(angle, 180.0);
else if(angle > 180.0)
angle = fmod(angle, 180.0);
if (brush->angle == angle)
return angle;
brush->angle = angle;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->angle;
}
......@@ -245,7 +282,11 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated* brush, float ratio)
ratio = 1.0;
else if(ratio > 1000)
ratio = 1000;
if (brush->aspect_ratio == ratio)
return ratio;
brush->aspect_ratio = ratio;
if (!brush->freeze)
gimp_brush_generated_generate(brush);
return brush->aspect_ratio;
}
......
......@@ -30,6 +30,7 @@ typedef struct _GimpBrushGenerated
float hardness; /* 0.0 - 1.0 */
float angle; /* in degrees */
float aspect_ratio; /* y/x */
int freeze;
/*GSpline *profile_curve */ /* Some lazy day... */
} GimpBrushGenerated;
......@@ -53,7 +54,8 @@ guint gimp_brush_generated_get_type (void);
GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness,
float angle, float aspect_ratio);
void gimp_brush_generated_generate (GimpBrushGenerated *brush);
void gimp_brush_generated_freeze (GimpBrushGenerated *brush);
void gimp_brush_generated_thaw (GimpBrushGenerated *brush);
float gimp_brush_generated_set_radius (GimpBrushGenerated* brush,
float radius);
......
......@@ -719,7 +719,7 @@ create_display_shell (GDisplay* gdisp,
gdisp->cancelbutton = gtk_button_new_with_label("Cancel");
gtk_box_pack_start (GTK_BOX (hbox), gdisp->cancelbutton, FALSE, TRUE, 0);
gtk_widget_set_sensitive (gdisp->cancelbutton, FALSE);
/* the popup menu */
gdisp->popup = image_popup_menu;
......
......@@ -719,7 +719,7 @@ create_display_shell (GDisplay* gdisp,
gdisp->cancelbutton = gtk_button_new_with_label("Cancel");
gtk_box_pack_start (GTK_BOX (hbox), gdisp->cancelbutton, FALSE, TRUE, 0);
gtk_widget_set_sensitive (gdisp->cancelbutton, FALSE);
/* the popup menu */
gdisp->popup = image_popup_menu;
......
......@@ -26,6 +26,9 @@
#define OVERSAMPLING 5
static void
gimp_brush_generated_generate(GimpBrushGenerated *brush);
static GimpObjectClass* parent_class;
static void
......@@ -53,6 +56,7 @@ gimp_brush_generated_init(GimpBrushGenerated *brush)
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
guint gimp_brush_generated_get_type(void)
......@@ -100,6 +104,27 @@ GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness,
return brush;
}
void
gimp_brush_generated_freeze(GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));