diff --git a/ChangeLog b/ChangeLog index b6fb12adcc..ee7e4b32a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Sep 1 13:29:09 MEST 1999 Sven Neumann + + * app/gimpcontextpreview.[ch]: added gradient preview. + + * app/gradient_select.c + * app/indicator_area.[ch] + * app/interface.c: display the active gradient in the toolbox. + Tue Aug 31 23:13:51 PDT 1999 Manish Singh * app/tile_swap.c: no leading underscore for S_IFOO constants diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c index 40e691d857..4fcb9edc24 100644 --- a/app/display/gimpdisplayshell-draw.c +++ b/app/display/gimpdisplayshell-draw.c @@ -267,7 +267,7 @@ create_indicator_area (GtkWidget *parent) gtk_container_set_border_width (GTK_CONTAINER (alignment), 3); gtk_container_add (GTK_CONTAINER (frame), alignment); - ind_area = indicator_area_create (54, 42); + ind_area = indicator_area_create (); gtk_container_add (GTK_CONTAINER (alignment), ind_area); gtk_widget_show (ind_area); gtk_widget_show (alignment); diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 40e691d857..4fcb9edc24 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -267,7 +267,7 @@ create_indicator_area (GtkWidget *parent) gtk_container_set_border_width (GTK_CONTAINER (alignment), 3); gtk_container_add (GTK_CONTAINER (frame), alignment); - ind_area = indicator_area_create (54, 42); + ind_area = indicator_area_create (); gtk_container_add (GTK_CONTAINER (alignment), ind_area); gtk_widget_show (ind_area); gtk_widget_show (alignment); diff --git a/app/gimpcontextpreview.c b/app/gimpcontextpreview.c index b21aee718f..302557f1d7 100644 --- a/app/gimpcontextpreview.c +++ b/app/gimpcontextpreview.c @@ -24,6 +24,8 @@ #include "gimpbrushpipe.h" #include "gimpbrushpipeP.h" #include "gimpcontextpreview.h" +#include "gradient.h" +#include "gradient_header.h" #include "interface.h" /* for tool_tips */ #include "patterns.h" #include "temp_buf.h" @@ -46,14 +48,22 @@ static unsigned char scale_indicator_bits[7][7][3] = { WHT, WHT, WHT, WHT, WHT, WHT, WHT } }; +/* size of the gradient popup */ +#define GRADIENT_POPUP_WIDTH 128 +#define GRADIENT_POPUP_HEIGHT 32 + +/* event mask for the context_preview */ #define CONTEXT_PREVIEW_EVENT_MASK (GDK_BUTTON_PRESS_MASK | \ GDK_BUTTON_RELEASE_MASK | \ GDK_ENTER_NOTIFY_MASK | \ GDK_LEAVE_NOTIFY_MASK) +/* shared widgets for the popups */ static GtkWidget *gcp_popup = NULL; static GtkWidget *gcp_popup_preview = NULL; + +/* signals */ enum { CLICKED, LAST_SIGNAL @@ -75,6 +85,8 @@ static void gimp_context_preview_draw_brush (GimpContextPreview *) static void gimp_context_preview_draw_brush_popup (GimpContextPreview *); static void gimp_context_preview_draw_pattern (GimpContextPreview *); static void gimp_context_preview_draw_pattern_popup (GimpContextPreview *); +static void gimp_context_preview_draw_gradient (GimpContextPreview *); +static void gimp_context_preview_draw_gradient_popup (GimpContextPreview *); static void @@ -195,9 +207,14 @@ gimp_context_preview_update (GimpContextPreview *gcp, break; case GCP_PATTERN: gimp_context_preview_draw_pattern (gcp); + break; + case GCP_GRADIENT: + gimp_context_preview_draw_gradient (gcp); + break; default: break; } + gtk_widget_queue_draw (GTK_WIDGET (gcp)); if (gcp->show_tooltips) { @@ -217,6 +234,12 @@ gimp_context_preview_update (GimpContextPreview *gcp, name = pattern->name; } break; + case GCP_GRADIENT: + { + gradient_t *gradient = (gradient_t *)(gcp->data); + name = gradient->name; + } + break; default: break; } @@ -276,6 +299,10 @@ gimp_context_preview_popup_open (GimpContextPreview *gcp, height = pattern->mask->height; } break; + case GCP_GRADIENT: + width = GRADIENT_POPUP_WIDTH; + height = GRADIENT_POPUP_HEIGHT; + break; default: return; } @@ -328,6 +355,9 @@ gimp_context_preview_popup_open (GimpContextPreview *gcp, case GCP_PATTERN: gimp_context_preview_draw_pattern_popup (gcp); break; + case GCP_GRADIENT: + gimp_context_preview_draw_gradient_popup (gcp); + break; default: break; } @@ -355,7 +385,8 @@ gimp_context_preview_data_matches_type (GimpContextPreview *gcp, match = GIMP_IS_BRUSH (data); break; case GCP_PATTERN: - match = data != NULL; /* would be nice if pattern was a real gtk_object */ + case GCP_GRADIENT: + match = data != NULL; /* would be nicer if these were real gtk_objects */ break; default: break; @@ -527,8 +558,6 @@ gimp_context_preview_draw_brush (GimpContextPreview *gcp) } g_free (buf); - - gtk_widget_queue_draw (GTK_WIDGET (gcp)); } @@ -636,3 +665,90 @@ gimp_context_preview_draw_pattern (GimpContextPreview *gcp) g_free(buf); } + + +/* gradient draw functions */ + +static void +draw_gradient (GtkPreview *preview, + gradient_t *gradient, + gint width, + gint height) +{ + gradient_t *old_gradient = curr_gradient; + guchar *p0, *p1, *even, *odd; + gint x, y; + gdouble dx, cur_x; + gdouble r, g, b, a; + gdouble c0, c1; + + curr_gradient = gradient; + + dx = 1.0 / (width - 1); + cur_x = 0.0; + p0 = even = g_new (guchar, 3 * width); + p1 = odd = g_new (guchar, 3 * width); + + for (x = 0; x < width; x++) + { + grad_get_color_at (cur_x, &r, &g, &b, &a); + + if ((x / GRAD_CHECK_SIZE_SM) & 1) + { + c0 = GRAD_CHECK_LIGHT; + c1 = GRAD_CHECK_DARK; + } + else + { + c0 = GRAD_CHECK_DARK; + c1 = GRAD_CHECK_LIGHT; + } + + *p0++ = (c0 + (r - c0) * a) * 255.0; + *p0++ = (c0 + (g - c0) * a) * 255.0; + *p0++ = (c0 + (b - c0) * a) * 255.0; + + *p1++ = (c1 + (r - c1) * a) * 255.0; + *p1++ = (c1 + (g - c1) * a) * 255.0; + *p1++ = (c1 + (b - c1) * a) * 255.0; + + cur_x += dx; + } + + for (y = 0; y < height; y++) + { + if ((y / GRAD_CHECK_SIZE_SM) & 1) + gtk_preview_draw_row (preview, odd, 0, y, width); + else + gtk_preview_draw_row (preview, even, 0, y, width); + } + + g_free (odd); + g_free (even); + curr_gradient = old_gradient; +} + +static void +gimp_context_preview_draw_gradient_popup (GimpContextPreview *gcp) +{ + gradient_t *gradient; + + g_return_if_fail (gcp != NULL && gcp->data != NULL); + + gradient = (gradient_t*)(gcp->data); + draw_gradient (GTK_PREVIEW (gcp_popup_preview), gradient, + GRADIENT_POPUP_WIDTH, GRADIENT_POPUP_HEIGHT); +} + +static void +gimp_context_preview_draw_gradient (GimpContextPreview *gcp) +{ + gradient_t *gradient; + + g_return_if_fail (gcp != NULL && gcp->data != NULL); + + gradient = (gradient_t*)(gcp->data); + draw_gradient (GTK_PREVIEW (gcp), gradient, gcp->width, gcp->height); +} + + diff --git a/app/gimpcontextpreview.h b/app/gimpcontextpreview.h index 281ef776dc..b4e3b8ee54 100644 --- a/app/gimpcontextpreview.h +++ b/app/gimpcontextpreview.h @@ -41,6 +41,7 @@ typedef enum { GCP_BRUSH = 0, GCP_PATTERN, + GCP_GRADIENT, GCP_LAST } GimpContextPreviewType; diff --git a/app/gradient_select.c b/app/gradient_select.c index 03a3666566..054567e7b7 100644 --- a/app/gradient_select.c +++ b/app/gradient_select.c @@ -53,6 +53,7 @@ #include "gimprc.h" #include "gradient.h" #include "gradient_header.h" +#include "indicator_area.h" #include "interface.h" #include "palette.h" #include "session.h" @@ -261,6 +262,7 @@ sel_list_item_update(GtkWidget *widget, if(gsp == gradient_select_dialog) { grad_set_grad_to_name(gsp->grad->name); + gradient_area_update (); /* update the indicator_area */ import_palette_grad_update(gsp->grad); } else @@ -279,7 +281,7 @@ grad_select_edit_callback (GtkWidget *w, grad_create_gradient_editor_init(TRUE); - /* Set the current gradient in this dailog to the "real current"*/ + /* Set the current gradient in this dialog to the "real current"*/ if(gsp && gsp->grad) grad_set_grad_to_name(gsp->grad->name); } diff --git a/app/gui/gradient-select.c b/app/gui/gradient-select.c index 03a3666566..054567e7b7 100644 --- a/app/gui/gradient-select.c +++ b/app/gui/gradient-select.c @@ -53,6 +53,7 @@ #include "gimprc.h" #include "gradient.h" #include "gradient_header.h" +#include "indicator_area.h" #include "interface.h" #include "palette.h" #include "session.h" @@ -261,6 +262,7 @@ sel_list_item_update(GtkWidget *widget, if(gsp == gradient_select_dialog) { grad_set_grad_to_name(gsp->grad->name); + gradient_area_update (); /* update the indicator_area */ import_palette_grad_update(gsp->grad); } else @@ -279,7 +281,7 @@ grad_select_edit_callback (GtkWidget *w, grad_create_gradient_editor_init(TRUE); - /* Set the current gradient in this dailog to the "real current"*/ + /* Set the current gradient in this dialog to the "real current"*/ if(gsp && gsp->grad) grad_set_grad_to_name(gsp->grad->name); } diff --git a/app/gui/indicator-area.c b/app/gui/indicator-area.c index f63a02f259..9b75439c2f 100644 --- a/app/gui/indicator-area.c +++ b/app/gui/indicator-area.c @@ -21,17 +21,21 @@ #include "appenv.h" #include "gimpbrushlist.h" #include "gimpcontextpreview.h" +#include "gradient.h" +#include "gradient_header.h" #include "indicator_area.h" #include "interface.h" /* for tool_tips */ #include "libgimp/gimpintl.h" -#define CELL_SIZE 23 /* The size of the previews */ -#define CELL_PADDING 2 /* How much between brush and pattern cells */ +#define CELL_SIZE 23 /* The size of the previews */ +#define GRAD_CELL_WIDTH 48 /* The width of the gradient preview */ +#define GRAD_CELL_HEIGHT 12 /* The height of the gradient preview */ +#define CELL_PADDING 2 /* How much between brush and pattern cells */ /* Static variables */ -static GtkWidget *indicator_table; static GtkWidget *brush_preview; static GtkWidget *pattern_preview; +static GtkWidget *gradient_preview; /* The _area_update () functions should be called _preview_update(), @@ -88,11 +92,28 @@ pattern_preview_clicked (GtkWidget *widget, return TRUE; } -GtkWidget * -indicator_area_create (int width, - int height) +void +gradient_area_update () { - indicator_table = gtk_table_new (1, 3, FALSE); + gimp_context_preview_update (GIMP_CONTEXT_PREVIEW (gradient_preview), curr_gradient); +} + +static gint +gradient_preview_clicked (GtkWidget *widget, + gpointer data) +{ + grad_create_gradient_editor (); + return TRUE; +} + +GtkWidget * +indicator_area_create () +{ + GtkWidget *indicator_table; + + indicator_table = gtk_table_new (2, 2, FALSE); + gtk_table_set_row_spacing (GTK_TABLE (indicator_table), 0, CELL_PADDING); + gtk_table_set_col_spacing (GTK_TABLE (indicator_table), 0, CELL_PADDING); brush_preview = gimp_context_preview_new (GCP_BRUSH, CELL_SIZE, CELL_SIZE, @@ -116,11 +137,24 @@ indicator_area_create (int width, gtk_table_attach_defaults (GTK_TABLE(indicator_table), pattern_preview, 1, 2, 0, 1); + gradient_preview = gimp_context_preview_new (GCP_GRADIENT, + GRAD_CELL_WIDTH, GRAD_CELL_HEIGHT, + FALSE); + gtk_tooltips_set_tip (tool_tips, gradient_preview, + _("The active gradient.\nClick to open the Gradients Dialog."), + NULL); + gtk_signal_connect (GTK_OBJECT (gradient_preview), "clicked", + (GtkSignalFunc) gradient_preview_clicked, NULL); + gtk_table_attach_defaults (GTK_TABLE(indicator_table), gradient_preview, + 0, 2, 1, 2); + brush_area_update (); pattern_area_update (); + gradient_area_update (); gtk_widget_show (brush_preview); gtk_widget_show (pattern_preview); + gtk_widget_show (gradient_preview); gtk_widget_show (indicator_table); return (indicator_table); diff --git a/app/gui/indicator-area.h b/app/gui/indicator-area.h index 9791f283ed..9b7230e9a1 100644 --- a/app/gui/indicator-area.h +++ b/app/gui/indicator-area.h @@ -19,11 +19,11 @@ #define __INDICATOR_AREA_H__ #include "patterns.h" #include "gimpbrushlist.h" -GtkWidget * -indicator_area_create (int width, int height); -void brush_area_update(void); -void pattern_area_update(void); +GtkWidget *indicator_area_create (void); +void brush_area_update (void); +void pattern_area_update (void); +void gradient_area_update (void); #endif /* __INDICATOR_AREA_H__ */ diff --git a/app/indicator_area.c b/app/indicator_area.c index f63a02f259..9b75439c2f 100644 --- a/app/indicator_area.c +++ b/app/indicator_area.c @@ -21,17 +21,21 @@ #include "appenv.h" #include "gimpbrushlist.h" #include "gimpcontextpreview.h" +#include "gradient.h" +#include "gradient_header.h" #include "indicator_area.h" #include "interface.h" /* for tool_tips */ #include "libgimp/gimpintl.h" -#define CELL_SIZE 23 /* The size of the previews */ -#define CELL_PADDING 2 /* How much between brush and pattern cells */ +#define CELL_SIZE 23 /* The size of the previews */ +#define GRAD_CELL_WIDTH 48 /* The width of the gradient preview */ +#define GRAD_CELL_HEIGHT 12 /* The height of the gradient preview */ +#define CELL_PADDING 2 /* How much between brush and pattern cells */ /* Static variables */ -static GtkWidget *indicator_table; static GtkWidget *brush_preview; static GtkWidget *pattern_preview; +static GtkWidget *gradient_preview; /* The _area_update () functions should be called _preview_update(), @@ -88,11 +92,28 @@ pattern_preview_clicked (GtkWidget *widget, return TRUE; } -GtkWidget * -indicator_area_create (int width, - int height) +void +gradient_area_update () { - indicator_table = gtk_table_new (1, 3, FALSE); + gimp_context_preview_update (GIMP_CONTEXT_PREVIEW (gradient_preview), curr_gradient); +} + +static gint +gradient_preview_clicked (GtkWidget *widget, + gpointer data) +{ + grad_create_gradient_editor (); + return TRUE; +} + +GtkWidget * +indicator_area_create () +{ + GtkWidget *indicator_table; + + indicator_table = gtk_table_new (2, 2, FALSE); + gtk_table_set_row_spacing (GTK_TABLE (indicator_table), 0, CELL_PADDING); + gtk_table_set_col_spacing (GTK_TABLE (indicator_table), 0, CELL_PADDING); brush_preview = gimp_context_preview_new (GCP_BRUSH, CELL_SIZE, CELL_SIZE, @@ -116,11 +137,24 @@ indicator_area_create (int width, gtk_table_attach_defaults (GTK_TABLE(indicator_table), pattern_preview, 1, 2, 0, 1); + gradient_preview = gimp_context_preview_new (GCP_GRADIENT, + GRAD_CELL_WIDTH, GRAD_CELL_HEIGHT, + FALSE); + gtk_tooltips_set_tip (tool_tips, gradient_preview, + _("The active gradient.\nClick to open the Gradients Dialog."), + NULL); + gtk_signal_connect (GTK_OBJECT (gradient_preview), "clicked", + (GtkSignalFunc) gradient_preview_clicked, NULL); + gtk_table_attach_defaults (GTK_TABLE(indicator_table), gradient_preview, + 0, 2, 1, 2); + brush_area_update (); pattern_area_update (); + gradient_area_update (); gtk_widget_show (brush_preview); gtk_widget_show (pattern_preview); + gtk_widget_show (gradient_preview); gtk_widget_show (indicator_table); return (indicator_table); diff --git a/app/indicator_area.h b/app/indicator_area.h index 9791f283ed..9b7230e9a1 100644 --- a/app/indicator_area.h +++ b/app/indicator_area.h @@ -19,11 +19,11 @@ #define __INDICATOR_AREA_H__ #include "patterns.h" #include "gimpbrushlist.h" -GtkWidget * -indicator_area_create (int width, int height); -void brush_area_update(void); -void pattern_area_update(void); +GtkWidget *indicator_area_create (void); +void brush_area_update (void); +void pattern_area_update (void); +void gradient_area_update (void); #endif /* __INDICATOR_AREA_H__ */ diff --git a/app/interface.c b/app/interface.c index 40e691d857..4fcb9edc24 100644 --- a/app/interface.c +++ b/app/interface.c @@ -267,7 +267,7 @@ create_indicator_area (GtkWidget *parent) gtk_container_set_border_width (GTK_CONTAINER (alignment), 3); gtk_container_add (GTK_CONTAINER (frame), alignment); - ind_area = indicator_area_create (54, 42); + ind_area = indicator_area_create (); gtk_container_add (GTK_CONTAINER (alignment), ind_area); gtk_widget_show (ind_area); gtk_widget_show (alignment); diff --git a/app/widgets/gimptoolbox-indicator-area.c b/app/widgets/gimptoolbox-indicator-area.c index f63a02f259..9b75439c2f 100644 --- a/app/widgets/gimptoolbox-indicator-area.c +++ b/app/widgets/gimptoolbox-indicator-area.c @@ -21,17 +21,21 @@ #include "appenv.h" #include "gimpbrushlist.h" #include "gimpcontextpreview.h" +#include "gradient.h" +#include "gradient_header.h" #include "indicator_area.h" #include "interface.h" /* for tool_tips */ #include "libgimp/gimpintl.h" -#define CELL_SIZE 23 /* The size of the previews */ -#define CELL_PADDING 2 /* How much between brush and pattern cells */ +#define CELL_SIZE 23 /* The size of the previews */ +#define GRAD_CELL_WIDTH 48 /* The width of the gradient preview */ +#define GRAD_CELL_HEIGHT 12 /* The height of the gradient preview */ +#define CELL_PADDING 2 /* How much between brush and pattern cells */ /* Static variables */ -static GtkWidget *indicator_table; static GtkWidget *brush_preview; static GtkWidget *pattern_preview; +static GtkWidget *gradient_preview; /* The _area_update () functions should be called _preview_update(), @@ -88,11 +92,28 @@ pattern_preview_clicked (GtkWidget *widget, return TRUE; } -GtkWidget * -indicator_area_create (int width, - int height) +void +gradient_area_update () { - indicator_table = gtk_table_new (1, 3, FALSE); + gimp_context_preview_update (GIMP_CONTEXT_PREVIEW (gradient_preview), curr_gradient); +} + +static gint +gradient_preview_clicked (GtkWidget *widget, + gpointer data) +{ + grad_create_gradient_editor (); + return TRUE; +} + +GtkWidget * +indicator_area_create () +{ + GtkWidget *indicator_table; + + indicator_table = gtk_table_new (2, 2, FALSE); + gtk_table_set_row_spacing (GTK_TABLE (indicator_table), 0, CELL_PADDING); + gtk_table_set_col_spacing (GTK_TABLE (indicator_table), 0, CELL_PADDING); brush_preview = gimp_context_preview_new (GCP_BRUSH, CELL_SIZE, CELL_SIZE, @@ -116,11 +137,24 @@ indicator_area_create (int width, gtk_table_attach_defaults (GTK_TABLE(indicator_table), pattern_preview, 1, 2, 0, 1); + gradient_preview = gimp_context_preview_new (GCP_GRADIENT, + GRAD_CELL_WIDTH, GRAD_CELL_HEIGHT, + FALSE); + gtk_tooltips_set_tip (tool_tips, gradient_preview, + _("The active gradient.\nClick to open the Gradients Dialog."), + NULL); + gtk_signal_connect (GTK_OBJECT (gradient_preview), "clicked", + (GtkSignalFunc) gradient_preview_clicked, NULL); + gtk_table_attach_defaults (GTK_TABLE(indicator_table), gradient_preview, + 0, 2, 1, 2); + brush_area_update (); pattern_area_update (); + gradient_area_update (); gtk_widget_show (brush_preview); gtk_widget_show (pattern_preview); + gtk_widget_show (gradient_preview); gtk_widget_show (indicator_table); return (indicator_table); diff --git a/app/widgets/gimptoolbox-indicator-area.h b/app/widgets/gimptoolbox-indicator-area.h index 9791f283ed..9b7230e9a1 100644 --- a/app/widgets/gimptoolbox-indicator-area.h +++ b/app/widgets/gimptoolbox-indicator-area.h @@ -19,11 +19,11 @@ #define __INDICATOR_AREA_H__ #include "patterns.h" #include "gimpbrushlist.h" -GtkWidget * -indicator_area_create (int width, int height); -void brush_area_update(void); -void pattern_area_update(void); +GtkWidget *indicator_area_create (void); +void brush_area_update (void); +void pattern_area_update (void); +void gradient_area_update (void); #endif /* __INDICATOR_AREA_H__ */