I decided not to try to rewrite the brush_select dialog to make use of

the new preview widgets. This means code_duplication, but I don't want to
spend the whole weekend on this...


--Sven
This commit is contained in:
Sven Neumann
1999-09-02 17:27:28 +00:00
parent c73db058f3
commit 42b6faccc0
11 changed files with 334 additions and 318 deletions

View File

@ -1,3 +1,17 @@
Thu Sep 2 19:25:03 MEST 1999 Sven Neumann <sven@gimp.org>
* app/app_procs.c: call device_status_free before freeing brushes
and patterns, so the devicerc can be written properly.
* app/brush_scale.h: removed the scale_indicator_bits definition
* app/brush_select.[ch]
* tools/pdbgen/pdb/brush_select.pdb
* app/brush_select_cmds.c
* app/gimpbrushlist.c: display the pixmap brushes correctly and
set the sensitivity of the edit/delete buttons properly when adding
or deleting brushes.
Thu Sep 2 16:46:35 MEST 1999 Sven Neumann <sven@gimp.org> Thu Sep 2 16:46:35 MEST 1999 Sven Neumann <sven@gimp.org>
* app/gimpcontextpreview.c: grab the pointer so that the popups don't * app/gimpcontextpreview.c: grab the pointer so that the popups don't

View File

@ -633,6 +633,10 @@ app_exit_finish (void)
message_handler = CONSOLE; message_handler = CONSOLE;
we_are_exiting = TRUE; we_are_exiting = TRUE;
/* do this here before brushes and patterns are freed */
if (!no_interface)
device_status_free ();
module_db_free (); module_db_free ();
lc_dialog_free (); lc_dialog_free ();
gdisplays_delete (); gdisplays_delete ();
@ -661,9 +665,8 @@ app_exit_finish (void)
gimp_parasiterc_save (); gimp_parasiterc_save ();
/* Things to do only if there is an interface */ /* Things to do only if there is an interface */
if (no_interface == FALSE) if (!no_interface)
{ {
device_status_free ();
toolbox_free (); toolbox_free ();
close_idea_window(); close_idea_window();
gximage_free (); gximage_free ();

View File

@ -20,27 +20,6 @@
#include "temp_buf.h" #include "temp_buf.h"
/* the pixmap for the brush_scale_indicator */
#define brush_scale_indicator_width 7
#define brush_scale_indicator_height 7
#define WHT {255,255,255}
#define BLK { 0, 0, 0}
static unsigned char brush_scale_indicator_bits[7][7][3] =
{
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, BLK, BLK, BLK, BLK, BLK, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT }
};
#undef WHT
#undef BLK
/* functions */ /* functions */
MaskBuf * brush_scale_mask (MaskBuf *, int, int); MaskBuf * brush_scale_mask (MaskBuf *, int, int);

View File

@ -20,27 +20,6 @@
#include "temp_buf.h" #include "temp_buf.h"
/* the pixmap for the brush_scale_indicator */
#define brush_scale_indicator_width 7
#define brush_scale_indicator_height 7
#define WHT {255,255,255}
#define BLK { 0, 0, 0}
static unsigned char brush_scale_indicator_bits[7][7][3] =
{
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, BLK, BLK, BLK, BLK, BLK, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT }
};
#undef WHT
#undef BLK
/* functions */ /* functions */
MaskBuf * brush_scale_mask (MaskBuf *, int, int); MaskBuf * brush_scale_mask (MaskBuf *, int, int);

View File

@ -21,11 +21,12 @@
#include "appenv.h" #include "appenv.h"
#include "actionarea.h" #include "actionarea.h"
#include "brush_scale.h" #include "brush_scale.h"
#include "gimpbrushpipe.h" #include "gimpbrushgenerated.h"
#include "gimpbrushlist.h" #include "gimpbrushlist.h"
#include "gimpbrushpipe.h"
#include "gimpbrushpipeP.h"
#include "gimpcontext.h" #include "gimpcontext.h"
#include "gimplist.h" #include "gimplist.h"
#include "gimpbrushgenerated.h"
#include "gimprc.h" #include "gimprc.h"
#include "brush_edit.h" #include "brush_edit.h"
#include "brush_select.h" #include "brush_select.h"
@ -57,6 +58,25 @@
GDK_BUTTON1_MOTION_MASK | \ GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK GDK_ENTER_NOTIFY_MASK
/* the pixmap for the scale_indicator */
#define scale_indicator_width 7
#define scale_indicator_height 7
#define WHT {255,255,255}
#define BLK { 0, 0, 0}
static unsigned char scale_indicator_bits[7][7][3] =
{
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, BLK, BLK, BLK, BLK, BLK, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT }
};
/* local function prototypes */ /* local function prototypes */
static void brush_popup_open (BrushSelectP, int, int, GimpBrushP); static void brush_popup_open (BrushSelectP, int, int, GimpBrushP);
static void brush_popup_close (BrushSelectP); static void brush_popup_close (BrushSelectP);
@ -323,19 +343,19 @@ brush_select_new (gchar *title,
util_box = gtk_hbox_new (FALSE, 0); util_box = gtk_hbox_new (FALSE, 0);
gtk_box_pack_end (GTK_BOX (bsp->options_box), util_box, FALSE, FALSE, 4); gtk_box_pack_end (GTK_BOX (bsp->options_box), util_box, FALSE, FALSE, 4);
button2 = gtk_button_new_with_label (_("New Brush")); button2 = gtk_button_new_with_label (_("New"));
gtk_signal_connect (GTK_OBJECT (button2), "clicked", gtk_signal_connect (GTK_OBJECT (button2), "clicked",
(GtkSignalFunc) new_brush_callback, (GtkSignalFunc) new_brush_callback,
NULL); NULL);
gtk_box_pack_start (GTK_BOX (util_box), button2, TRUE, TRUE, 6); gtk_box_pack_start (GTK_BOX (util_box), button2, TRUE, TRUE, 6);
bsp->edit_button = gtk_button_new_with_label (_("Edit Brush")); bsp->edit_button = gtk_button_new_with_label (_("Edit"));
gtk_signal_connect (GTK_OBJECT (bsp->edit_button), "clicked", gtk_signal_connect (GTK_OBJECT (bsp->edit_button), "clicked",
(GtkSignalFunc) edit_brush_callback, (GtkSignalFunc) edit_brush_callback,
NULL); NULL);
gtk_box_pack_start (GTK_BOX (util_box), bsp->edit_button, TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (util_box), bsp->edit_button, TRUE, TRUE, 5);
bsp->delete_button = gtk_button_new_with_label (_("Delete Brush")); bsp->delete_button = gtk_button_new_with_label (_("Delete"));
gtk_signal_connect (GTK_OBJECT (bsp->delete_button), "clicked", gtk_signal_connect (GTK_OBJECT (bsp->delete_button), "clicked",
(GtkSignalFunc) delete_brush_callback, (GtkSignalFunc) delete_brush_callback,
bsp); bsp);
@ -448,8 +468,7 @@ brush_select_new (gchar *title,
bsp->opacity_value = init_opacity; bsp->opacity_value = init_opacity;
bsp->paint_mode = init_mode; bsp->paint_mode = init_mode;
} }
brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, brush_select_select (bsp, active);
active));
if (gotinitbrush && init_spacing >= 0) if (gotinitbrush && init_spacing >= 0)
{ {
@ -459,16 +478,6 @@ brush_select_new (gchar *title,
"value_changed"); "value_changed");
} }
bsp->redraw = old_value; bsp->redraw = old_value;
if (GIMP_IS_BRUSH_GENERATED (active))
{
gtk_widget_set_sensitive (bsp->edit_button, 1);
gtk_widget_set_sensitive (bsp->delete_button, 1);
}
else
{
gtk_widget_set_sensitive (bsp->edit_button, 0);
gtk_widget_set_sensitive (bsp->delete_button, 0);
}
} }
/* Finally, show the dialog */ /* Finally, show the dialog */
@ -480,14 +489,28 @@ brush_select_new (gchar *title,
void void
brush_select_select (BrushSelectP bsp, brush_select_select (BrushSelectP bsp,
int index) GimpBrushP brush)
{ {
int index;
int row, col; int row, col;
index = gimp_brush_list_get_brush_index (brush_list, brush);
if (index >= gimp_brush_list_length(brush_list)) if (index >= gimp_brush_list_length(brush_list))
index = gimp_brush_list_length(brush_list) - 1; index = gimp_brush_list_length(brush_list) - 1;
if (index < 0 || index >= gimp_brush_list_length(brush_list)) if (index < 0 || index >= gimp_brush_list_length(brush_list))
return; return;
if (bsp == brush_select_dialog && GIMP_IS_BRUSH_GENERATED (brush))
{
gtk_widget_set_sensitive (bsp->edit_button, TRUE);
gtk_widget_set_sensitive (bsp->delete_button, TRUE);
}
else
{
gtk_widget_set_sensitive (bsp->edit_button, FALSE);
gtk_widget_set_sensitive (bsp->delete_button, FALSE);
}
update_active_brush_field (bsp); update_active_brush_field (bsp);
row = index / bsp->NUM_BRUSH_COLUMNS; row = index / bsp->NUM_BRUSH_COLUMNS;
col = index - row * (bsp->NUM_BRUSH_COLUMNS); col = index - row * (bsp->NUM_BRUSH_COLUMNS);
@ -728,7 +751,9 @@ brush_popup_timeout (gpointer data)
gint x, y; gint x, y;
gint x_org, y_org; gint x_org, y_org;
gint scr_w, scr_h; gint scr_w, scr_h;
gchar *src, *buf; gint width, height;
guchar *mask, *buf, *b;
guchar bg;
/* timeout has gone off so our tag is now invalid */ /* timeout has gone off so our tag is now invalid */
bsp->popup_timeout_tag = 0; bsp->popup_timeout_tag = 0;
@ -755,54 +780,61 @@ brush_popup_timeout (gpointer data)
} }
/* decide where to put the popup */ /* decide where to put the popup */
width = brush->mask->width;
height = brush->mask->height;
gdk_window_get_origin (bsp->preview->window, &x_org, &y_org); gdk_window_get_origin (bsp->preview->window, &x_org, &y_org);
scr_w = gdk_screen_width (); scr_w = gdk_screen_width ();
scr_h = gdk_screen_height (); scr_h = gdk_screen_height ();
x = x_org + args->x - brush->mask->width * 0.5; x = x_org + args->x - width * 0.5;
y = y_org + args->y - brush->mask->height * 0.5; y = y_org + args->y - height * 0.5;
x = (x < 0) ? 0 : x; x = (x < 0) ? 0 : x;
y = (y < 0) ? 0 : y; y = (y < 0) ? 0 : y;
x = (x + brush->mask->width > scr_w) ? scr_w - brush->mask->width : x; x = (x + width > scr_w) ? scr_w - width : x;
y = (y + brush->mask->height > scr_h) ? scr_h - brush->mask->height : y; y = (y + height > scr_h) ? scr_h - height : y;
gtk_preview_size (GTK_PREVIEW (bsp->brush_preview), gtk_preview_size (GTK_PREVIEW (bsp->brush_preview), width, height);
brush->mask->width, brush->mask->height);
gtk_widget_popup (bsp->brush_popup, x, y); gtk_widget_popup (bsp->brush_popup, x, y);
/* Draw the brush */ /* Draw the brush */
buf = g_new (guchar, 3 * width);
mask = temp_buf_data (brush->mask);
if (GIMP_IS_BRUSH_PIXMAP (brush)) if (GIMP_IS_BRUSH_PIXMAP (brush))
{ {
GimpBrushPixmap *pixmapbrush = GIMP_BRUSH_PIXMAP(brush); guchar *pixmap = temp_buf_data (GIMP_BRUSH_PIXMAP (brush)->pixmap_mask);
src = (gchar *) temp_buf_data (gimp_brush_pixmap_pixmap (pixmapbrush)); for (y = 0; y < height; y++)
for (y = 0; y < brush->mask->height; y++)
{ {
gtk_preview_draw_row (GTK_PREVIEW (bsp->brush_preview), (guchar *)src, b = buf;
0, y, brush->mask->width); for (x = 0; x < width ; x++)
src += brush->mask->width * 3; {
bg = (255 - *mask);
*b++ = bg + (*mask * *pixmap++) / 255;
*b++ = bg + (*mask * *pixmap++) / 255;
*b++ = bg + (*mask * *pixmap++) / 255;
mask++;
}
gtk_preview_draw_row (GTK_PREVIEW (bsp->brush_preview), buf, 0, y, width);
} }
} }
else else
{ {
buf = g_new (gchar, 3*brush->mask->width); for (y = 0; y < height; y++)
src = (gchar *) temp_buf_data (brush->mask);
for (y = 0; y < brush->mask->height; y++)
{ {
/* Invert the mask for display. We're doing this because b = buf;
* a value of 255 in the mask means it is full intensity. /* Invert the mask for display. */
* However, it makes more sense for full intensity to show for (x = 0; x < width; x++)
* up as black in this brush preview window... {
*/ bg = 255 - *mask++;
for (x = 0; x < brush->mask->width; x++) memset (b, bg, 3);
buf[3*x] = buf[3*x+1] = buf[3*x+2] = 255 - src[x]; b += 3;
gtk_preview_draw_row (GTK_PREVIEW (bsp->brush_preview), (guchar *)buf, }
0, y, brush->mask->width); gtk_preview_draw_row (GTK_PREVIEW (bsp->brush_preview), buf, 0, y, width);
src += brush->mask->width;
} }
g_free (buf);
} }
g_free (buf);
/* Draw the brush preview */ /* Draw the brush preview */
gtk_widget_draw (bsp->brush_preview, NULL); gtk_widget_queue_draw (bsp->brush_preview);
return FALSE; /* don't repeat */ return FALSE; /* don't repeat */
} }
@ -844,73 +876,68 @@ display_brush (BrushSelectP bsp,
int col, int col,
int row) int row)
{ {
MaskBuf * brush_buf; TempBuf *mask_buf, *pixmap_buf = NULL;
unsigned char * src, *s; guchar *mask, *buf, *b;
unsigned char * buf, *b; guchar bg;
gboolean scale = FALSE; gboolean scale = FALSE;
int width, height; gint width, height;
int offset_x, offset_y; gint offset_x, offset_y;
int yend; gint yend;
int ystart; gint ystart;
int i, j; gint i, j;
brush_buf = GIMP_IS_BRUSH_PIXMAP (brush) ? mask_buf = brush->mask;
gimp_brush_pixmap_pixmap (GIMP_BRUSH_PIXMAP(brush))
: brush->mask;
if (brush_buf->width > bsp->cell_width || brush_buf->height > bsp->cell_height) if (mask_buf->width > bsp->cell_width || mask_buf->height > bsp->cell_height)
{ {
double ratio_x = (double)brush_buf->width / bsp->cell_width; gdouble ratio_x = (gdouble)mask_buf->width / bsp->cell_width;
double ratio_y = (double)brush_buf->height / bsp->cell_height; gdouble ratio_y = (gdouble)mask_buf->height / bsp->cell_height;
if (ratio_x >= ratio_y) mask_buf = brush_scale_mask (mask_buf,
brush_buf = GIMP_IS_BRUSH_PIXMAP (brush) ? (gdouble)(mask_buf->width) / MAX (ratio_x, ratio_y),
brush_scale_pixmap (brush_buf, (gdouble)(mask_buf->height) / MAX (ratio_x, ratio_y));
(double)(brush_buf->width) / ratio_x, if (GIMP_IS_BRUSH_PIXMAP (brush))
(double)(brush_buf->height) / ratio_x) : {
brush_scale_mask (brush_buf, /* TODO: the scale function should scale the pixmap
(double)(brush_buf->width) / ratio_x, and the mask in one run */
(double)(brush_buf->height) / ratio_x); pixmap_buf = brush_scale_pixmap (GIMP_BRUSH_PIXMAP(brush)->pixmap_mask,
else mask_buf->width, mask_buf->height);
brush_buf = GIMP_IS_BRUSH_PIXMAP (brush) ? }
brush_scale_pixmap (brush_buf,
(double)(brush_buf->width) / ratio_y,
(double)(brush_buf->height) / ratio_y) :
brush_scale_mask (brush_buf,
(double)(brush_buf->width) / ratio_y,
(double)(brush_buf->height) / ratio_y);
scale = TRUE; scale = TRUE;
} }
/* calculate the offset into the image */ /* calculate the offset into the image */
width = (brush_buf->width > bsp->cell_width) ? bsp->cell_width : width = (mask_buf->width > bsp->cell_width) ? bsp->cell_width : mask_buf->width;
brush_buf->width; height = (mask_buf->height > bsp->cell_height) ? bsp->cell_height : mask_buf->height;
height = (brush_buf->height > bsp->cell_height) ? bsp->cell_height :
brush_buf->height;
offset_x = col * bsp->cell_width + ((bsp->cell_width - width) >> 1); offset_x = col * bsp->cell_width + ((bsp->cell_width - width) >> 1);
offset_y = row * bsp->cell_height + ((bsp->cell_height - height) >> 1) offset_y = row * bsp->cell_height + ((bsp->cell_height - height) >> 1) - bsp->scroll_offset;
- bsp->scroll_offset;
ystart = BOUNDS (offset_y, 0, bsp->preview->allocation.height); ystart = BOUNDS (offset_y, 0, bsp->preview->allocation.height);
yend = BOUNDS (offset_y + height, 0, bsp->preview->allocation.height); yend = BOUNDS (offset_y + height, 0, bsp->preview->allocation.height);
/* Get the pointer into the brush mask data */ mask = temp_buf_data (mask_buf) + (ystart - offset_y) * mask_buf->width * 3;
buf = g_new (guchar, 3 * bsp->cell_width);
if (GIMP_IS_BRUSH_PIXMAP (brush)) if (GIMP_IS_BRUSH_PIXMAP (brush))
{ {
src = mask_buf_data (brush_buf) + (ystart - offset_y) * brush_buf->width * 3; guchar *pixmap = temp_buf_data (pixmap_buf) + (ystart - offset_y) * mask_buf->width * 3;
for (i = ystart; i < yend; i++) for (i = ystart; i < yend; i++)
{ {
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), src, b = buf;
offset_x, i, width); for (j = 0; j < width ; j++)
src += brush_buf->width * 3; {
bg = (255 - *mask);
*b++ = bg + (*mask * *pixmap++) / 255;
*b++ = bg + (*mask * *pixmap++) / 255;
*b++ = bg + (*mask * *pixmap++) / 255;
mask++;
}
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), buf, offset_x, i, width);
} }
} }
else else
{ {
buf = (unsigned char *) g_malloc (3 * sizeof (char) * bsp->cell_width);
src = mask_buf_data (brush_buf) + (ystart - offset_y) * brush_buf->width;
for (i = ystart; i < yend; i++) for (i = ystart; i < yend; i++)
{ {
/* Invert the mask for display. We're doing this because /* Invert the mask for display. We're doing this because
@ -918,38 +945,34 @@ display_brush (BrushSelectP bsp,
* However, it makes more sense for full intensity to show * However, it makes more sense for full intensity to show
* up as black in this brush preview window... * up as black in this brush preview window...
*/ */
s = src;
b = buf; b = buf;
for (j = 0; j < width; j++) for (j = 0; j < width; j++)
{ {
int k = 255 - *s++; bg = 255 - *mask++;
*b++ = k; memset (b, bg, 3);
*b++ = k; b += 3;
*b++ = k; }
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), buf, offset_x, i, width);
} }
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), buf,
offset_x, i, width);
src += brush_buf->width;
} }
g_free (buf); g_free (buf);
}
if (scale) if (scale)
{ {
offset_x = (col + 1) * bsp->cell_width - offset_x = (col + 1) * bsp->cell_width - scale_indicator_width;
brush_scale_indicator_width; offset_y = (row + 1) * bsp->cell_height - scale_indicator_height - bsp->scroll_offset;;
offset_y = (row + 1) * bsp->cell_height -
brush_scale_indicator_height - bsp->scroll_offset;;
for (i = 0; i < brush_scale_indicator_height; i++, offset_y++) for (i = 0; i < scale_indicator_height; i++, offset_y++)
{ {
if (offset_y > 0 && offset_y < bsp->preview->allocation.height) if (offset_y > 0 && offset_y < bsp->preview->allocation.height)
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), gtk_preview_draw_row (GTK_PREVIEW (bsp->preview),
brush_scale_indicator_bits[i][0], scale_indicator_bits[i][0],
offset_x, offset_y, offset_x, offset_y,
brush_scale_indicator_width); scale_indicator_width);
} }
mask_buf_free (brush_buf); temp_buf_free (mask_buf);
if (GIMP_IS_BRUSH_PIXMAP (brush))
temp_buf_free (pixmap_buf);
} }
} }
@ -1232,7 +1255,8 @@ delete_active_brush(BrushSelectP bsp)
} }
index = gimp_brush_list_get_brush_index(brush_list, brush); index = gimp_brush_list_get_brush_index(brush_list, brush);
gimp_brush_list_remove(brush_list, GIMP_BRUSH (brush)); gimp_brush_list_remove(brush_list, GIMP_BRUSH (brush));
select_brush (gimp_brush_list_get_brush_by_index(brush_list, index)); brush = gimp_brush_list_get_brush_by_index (brush_list, index);
select_brush (brush);
} }
else else
g_message ("Wilber says: \"I don\'t know how to delete that brush.\""); g_message ("Wilber says: \"I don\'t know how to delete that brush.\"");
@ -1253,6 +1277,14 @@ brush_select_events (GtkWidget *widget,
break; break;
case GDK_2BUTTON_PRESS: case GDK_2BUTTON_PRESS:
bevent = (GdkEventButton *) event;
col = bevent->x / bsp->cell_width;
row = (bevent->y + bsp->scroll_offset) / bsp->cell_height;
index = row * bsp->NUM_BRUSH_COLUMNS + col;
/* Get the brush and check if it is editable */
brush = gimp_brush_list_get_brush_by_index (brush_list, index);
if (GIMP_IS_BRUSH_GENERATED (brush))
edit_active_brush(); edit_active_brush();
break; break;
case GDK_BUTTON_PRESS: case GDK_BUTTON_PRESS:
@ -1285,23 +1317,10 @@ brush_select_events (GtkWidget *widget,
if (bsp) if (bsp)
{ {
bsp->brush = brush; bsp->brush = brush;
brush_select_select (bsp, brush_select_select (bsp, brush);
gimp_brush_list_get_brush_index (brush_list, brush));
} }
} }
if (GIMP_IS_BRUSH_GENERATED (brush) && bsp == brush_select_dialog)
{
gtk_widget_set_sensitive (bsp->edit_button, 1);
gtk_widget_set_sensitive (bsp->delete_button, 1);
}
else
{
gtk_widget_set_sensitive (bsp->edit_button, 0);
gtk_widget_set_sensitive (bsp->delete_button, 0);
}
if (brush_edit_generated_dialog) if (brush_edit_generated_dialog)
brush_edit_generated_set_brush (brush_edit_generated_dialog, brush_edit_generated_set_brush (brush_edit_generated_dialog,
get_active_brush ()); get_active_brush ());
@ -1446,12 +1465,14 @@ brush_select_refresh_callback (GtkWidget *w,
display_brushes (bsp); display_brushes (bsp);
/* update the active selection */ /* update the active selection */
active = get_active_brush (); /* active = get_active_brush ();
/* if (active) if (active)
select_brush (bsp, active); */ select_brush (bsp, active);
/* brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, active));
active)); */ */
select_brush(gimp_brush_list_get_brush_by_index (brush_list, 0));
active = gimp_brush_list_get_brush_by_index (brush_list, 0);
select_brush (active);
/* update the display */ /* update the display */
if (bsp->redraw) if (bsp->redraw)

View File

@ -89,7 +89,7 @@ BrushSelectP brush_select_new (gchar *title,
void brush_select_free (BrushSelectP bsp); void brush_select_free (BrushSelectP bsp);
void brush_select_select (BrushSelectP bsp, void brush_select_select (BrushSelectP bsp,
int index); GimpBrushP brush);
void brush_change_callbacks (BrushSelectP bsp, void brush_change_callbacks (BrushSelectP bsp,
gint closing); gint closing);

View File

@ -263,7 +263,7 @@ brushes_set_popup_invoker (Argument *args)
/* Must alter the wigdets on screen as well */ /* Must alter the wigdets on screen as well */
bsp->brush = active; bsp->brush = active;
brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, active)); brush_select_select (bsp, active);
bsp->opacity_value = opacity; bsp->opacity_value = opacity;
bsp->spacing_value = spacing; bsp->spacing_value = spacing;

View File

@ -501,8 +501,7 @@ select_brush (GimpBrush * brush)
/* Keep up appearances in the brush dialog */ /* Keep up appearances in the brush dialog */
if (brush_select_dialog) if (brush_select_dialog)
brush_select_select (brush_select_dialog, brush_select_select (brush_select_dialog, brush);
gimp_brush_list_get_brush_index(brush_list, brush));
device_status_update (current_device); device_status_update (current_device);
} }

View File

@ -21,11 +21,12 @@
#include "appenv.h" #include "appenv.h"
#include "actionarea.h" #include "actionarea.h"
#include "brush_scale.h" #include "brush_scale.h"
#include "gimpbrushpipe.h" #include "gimpbrushgenerated.h"
#include "gimpbrushlist.h" #include "gimpbrushlist.h"
#include "gimpbrushpipe.h"
#include "gimpbrushpipeP.h"
#include "gimpcontext.h" #include "gimpcontext.h"
#include "gimplist.h" #include "gimplist.h"
#include "gimpbrushgenerated.h"
#include "gimprc.h" #include "gimprc.h"
#include "brush_edit.h" #include "brush_edit.h"
#include "brush_select.h" #include "brush_select.h"
@ -57,6 +58,25 @@
GDK_BUTTON1_MOTION_MASK | \ GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK GDK_ENTER_NOTIFY_MASK
/* the pixmap for the scale_indicator */
#define scale_indicator_width 7
#define scale_indicator_height 7
#define WHT {255,255,255}
#define BLK { 0, 0, 0}
static unsigned char scale_indicator_bits[7][7][3] =
{
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, BLK, BLK, BLK, BLK, BLK, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT }
};
/* local function prototypes */ /* local function prototypes */
static void brush_popup_open (BrushSelectP, int, int, GimpBrushP); static void brush_popup_open (BrushSelectP, int, int, GimpBrushP);
static void brush_popup_close (BrushSelectP); static void brush_popup_close (BrushSelectP);
@ -323,19 +343,19 @@ brush_select_new (gchar *title,
util_box = gtk_hbox_new (FALSE, 0); util_box = gtk_hbox_new (FALSE, 0);
gtk_box_pack_end (GTK_BOX (bsp->options_box), util_box, FALSE, FALSE, 4); gtk_box_pack_end (GTK_BOX (bsp->options_box), util_box, FALSE, FALSE, 4);
button2 = gtk_button_new_with_label (_("New Brush")); button2 = gtk_button_new_with_label (_("New"));
gtk_signal_connect (GTK_OBJECT (button2), "clicked", gtk_signal_connect (GTK_OBJECT (button2), "clicked",
(GtkSignalFunc) new_brush_callback, (GtkSignalFunc) new_brush_callback,
NULL); NULL);
gtk_box_pack_start (GTK_BOX (util_box), button2, TRUE, TRUE, 6); gtk_box_pack_start (GTK_BOX (util_box), button2, TRUE, TRUE, 6);
bsp->edit_button = gtk_button_new_with_label (_("Edit Brush")); bsp->edit_button = gtk_button_new_with_label (_("Edit"));
gtk_signal_connect (GTK_OBJECT (bsp->edit_button), "clicked", gtk_signal_connect (GTK_OBJECT (bsp->edit_button), "clicked",
(GtkSignalFunc) edit_brush_callback, (GtkSignalFunc) edit_brush_callback,
NULL); NULL);
gtk_box_pack_start (GTK_BOX (util_box), bsp->edit_button, TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (util_box), bsp->edit_button, TRUE, TRUE, 5);
bsp->delete_button = gtk_button_new_with_label (_("Delete Brush")); bsp->delete_button = gtk_button_new_with_label (_("Delete"));
gtk_signal_connect (GTK_OBJECT (bsp->delete_button), "clicked", gtk_signal_connect (GTK_OBJECT (bsp->delete_button), "clicked",
(GtkSignalFunc) delete_brush_callback, (GtkSignalFunc) delete_brush_callback,
bsp); bsp);
@ -448,8 +468,7 @@ brush_select_new (gchar *title,
bsp->opacity_value = init_opacity; bsp->opacity_value = init_opacity;
bsp->paint_mode = init_mode; bsp->paint_mode = init_mode;
} }
brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, brush_select_select (bsp, active);
active));
if (gotinitbrush && init_spacing >= 0) if (gotinitbrush && init_spacing >= 0)
{ {
@ -459,16 +478,6 @@ brush_select_new (gchar *title,
"value_changed"); "value_changed");
} }
bsp->redraw = old_value; bsp->redraw = old_value;
if (GIMP_IS_BRUSH_GENERATED (active))
{
gtk_widget_set_sensitive (bsp->edit_button, 1);
gtk_widget_set_sensitive (bsp->delete_button, 1);
}
else
{
gtk_widget_set_sensitive (bsp->edit_button, 0);
gtk_widget_set_sensitive (bsp->delete_button, 0);
}
} }
/* Finally, show the dialog */ /* Finally, show the dialog */
@ -480,14 +489,28 @@ brush_select_new (gchar *title,
void void
brush_select_select (BrushSelectP bsp, brush_select_select (BrushSelectP bsp,
int index) GimpBrushP brush)
{ {
int index;
int row, col; int row, col;
index = gimp_brush_list_get_brush_index (brush_list, brush);
if (index >= gimp_brush_list_length(brush_list)) if (index >= gimp_brush_list_length(brush_list))
index = gimp_brush_list_length(brush_list) - 1; index = gimp_brush_list_length(brush_list) - 1;
if (index < 0 || index >= gimp_brush_list_length(brush_list)) if (index < 0 || index >= gimp_brush_list_length(brush_list))
return; return;
if (bsp == brush_select_dialog && GIMP_IS_BRUSH_GENERATED (brush))
{
gtk_widget_set_sensitive (bsp->edit_button, TRUE);
gtk_widget_set_sensitive (bsp->delete_button, TRUE);
}
else
{
gtk_widget_set_sensitive (bsp->edit_button, FALSE);
gtk_widget_set_sensitive (bsp->delete_button, FALSE);
}
update_active_brush_field (bsp); update_active_brush_field (bsp);
row = index / bsp->NUM_BRUSH_COLUMNS; row = index / bsp->NUM_BRUSH_COLUMNS;
col = index - row * (bsp->NUM_BRUSH_COLUMNS); col = index - row * (bsp->NUM_BRUSH_COLUMNS);
@ -728,7 +751,9 @@ brush_popup_timeout (gpointer data)
gint x, y; gint x, y;
gint x_org, y_org; gint x_org, y_org;
gint scr_w, scr_h; gint scr_w, scr_h;
gchar *src, *buf; gint width, height;
guchar *mask, *buf, *b;
guchar bg;
/* timeout has gone off so our tag is now invalid */ /* timeout has gone off so our tag is now invalid */
bsp->popup_timeout_tag = 0; bsp->popup_timeout_tag = 0;
@ -755,54 +780,61 @@ brush_popup_timeout (gpointer data)
} }
/* decide where to put the popup */ /* decide where to put the popup */
width = brush->mask->width;
height = brush->mask->height;
gdk_window_get_origin (bsp->preview->window, &x_org, &y_org); gdk_window_get_origin (bsp->preview->window, &x_org, &y_org);
scr_w = gdk_screen_width (); scr_w = gdk_screen_width ();
scr_h = gdk_screen_height (); scr_h = gdk_screen_height ();
x = x_org + args->x - brush->mask->width * 0.5; x = x_org + args->x - width * 0.5;
y = y_org + args->y - brush->mask->height * 0.5; y = y_org + args->y - height * 0.5;
x = (x < 0) ? 0 : x; x = (x < 0) ? 0 : x;
y = (y < 0) ? 0 : y; y = (y < 0) ? 0 : y;
x = (x + brush->mask->width > scr_w) ? scr_w - brush->mask->width : x; x = (x + width > scr_w) ? scr_w - width : x;
y = (y + brush->mask->height > scr_h) ? scr_h - brush->mask->height : y; y = (y + height > scr_h) ? scr_h - height : y;
gtk_preview_size (GTK_PREVIEW (bsp->brush_preview), gtk_preview_size (GTK_PREVIEW (bsp->brush_preview), width, height);
brush->mask->width, brush->mask->height);
gtk_widget_popup (bsp->brush_popup, x, y); gtk_widget_popup (bsp->brush_popup, x, y);
/* Draw the brush */ /* Draw the brush */
buf = g_new (guchar, 3 * width);
mask = temp_buf_data (brush->mask);
if (GIMP_IS_BRUSH_PIXMAP (brush)) if (GIMP_IS_BRUSH_PIXMAP (brush))
{ {
GimpBrushPixmap *pixmapbrush = GIMP_BRUSH_PIXMAP(brush); guchar *pixmap = temp_buf_data (GIMP_BRUSH_PIXMAP (brush)->pixmap_mask);
src = (gchar *) temp_buf_data (gimp_brush_pixmap_pixmap (pixmapbrush)); for (y = 0; y < height; y++)
for (y = 0; y < brush->mask->height; y++)
{ {
gtk_preview_draw_row (GTK_PREVIEW (bsp->brush_preview), (guchar *)src, b = buf;
0, y, brush->mask->width); for (x = 0; x < width ; x++)
src += brush->mask->width * 3; {
bg = (255 - *mask);
*b++ = bg + (*mask * *pixmap++) / 255;
*b++ = bg + (*mask * *pixmap++) / 255;
*b++ = bg + (*mask * *pixmap++) / 255;
mask++;
}
gtk_preview_draw_row (GTK_PREVIEW (bsp->brush_preview), buf, 0, y, width);
} }
} }
else else
{ {
buf = g_new (gchar, 3*brush->mask->width); for (y = 0; y < height; y++)
src = (gchar *) temp_buf_data (brush->mask);
for (y = 0; y < brush->mask->height; y++)
{ {
/* Invert the mask for display. We're doing this because b = buf;
* a value of 255 in the mask means it is full intensity. /* Invert the mask for display. */
* However, it makes more sense for full intensity to show for (x = 0; x < width; x++)
* up as black in this brush preview window... {
*/ bg = 255 - *mask++;
for (x = 0; x < brush->mask->width; x++) memset (b, bg, 3);
buf[3*x] = buf[3*x+1] = buf[3*x+2] = 255 - src[x]; b += 3;
gtk_preview_draw_row (GTK_PREVIEW (bsp->brush_preview), (guchar *)buf, }
0, y, brush->mask->width); gtk_preview_draw_row (GTK_PREVIEW (bsp->brush_preview), buf, 0, y, width);
src += brush->mask->width;
} }
g_free (buf);
} }
g_free (buf);
/* Draw the brush preview */ /* Draw the brush preview */
gtk_widget_draw (bsp->brush_preview, NULL); gtk_widget_queue_draw (bsp->brush_preview);
return FALSE; /* don't repeat */ return FALSE; /* don't repeat */
} }
@ -844,73 +876,68 @@ display_brush (BrushSelectP bsp,
int col, int col,
int row) int row)
{ {
MaskBuf * brush_buf; TempBuf *mask_buf, *pixmap_buf = NULL;
unsigned char * src, *s; guchar *mask, *buf, *b;
unsigned char * buf, *b; guchar bg;
gboolean scale = FALSE; gboolean scale = FALSE;
int width, height; gint width, height;
int offset_x, offset_y; gint offset_x, offset_y;
int yend; gint yend;
int ystart; gint ystart;
int i, j; gint i, j;
brush_buf = GIMP_IS_BRUSH_PIXMAP (brush) ? mask_buf = brush->mask;
gimp_brush_pixmap_pixmap (GIMP_BRUSH_PIXMAP(brush))
: brush->mask;
if (brush_buf->width > bsp->cell_width || brush_buf->height > bsp->cell_height) if (mask_buf->width > bsp->cell_width || mask_buf->height > bsp->cell_height)
{ {
double ratio_x = (double)brush_buf->width / bsp->cell_width; gdouble ratio_x = (gdouble)mask_buf->width / bsp->cell_width;
double ratio_y = (double)brush_buf->height / bsp->cell_height; gdouble ratio_y = (gdouble)mask_buf->height / bsp->cell_height;
if (ratio_x >= ratio_y) mask_buf = brush_scale_mask (mask_buf,
brush_buf = GIMP_IS_BRUSH_PIXMAP (brush) ? (gdouble)(mask_buf->width) / MAX (ratio_x, ratio_y),
brush_scale_pixmap (brush_buf, (gdouble)(mask_buf->height) / MAX (ratio_x, ratio_y));
(double)(brush_buf->width) / ratio_x, if (GIMP_IS_BRUSH_PIXMAP (brush))
(double)(brush_buf->height) / ratio_x) : {
brush_scale_mask (brush_buf, /* TODO: the scale function should scale the pixmap
(double)(brush_buf->width) / ratio_x, and the mask in one run */
(double)(brush_buf->height) / ratio_x); pixmap_buf = brush_scale_pixmap (GIMP_BRUSH_PIXMAP(brush)->pixmap_mask,
else mask_buf->width, mask_buf->height);
brush_buf = GIMP_IS_BRUSH_PIXMAP (brush) ? }
brush_scale_pixmap (brush_buf,
(double)(brush_buf->width) / ratio_y,
(double)(brush_buf->height) / ratio_y) :
brush_scale_mask (brush_buf,
(double)(brush_buf->width) / ratio_y,
(double)(brush_buf->height) / ratio_y);
scale = TRUE; scale = TRUE;
} }
/* calculate the offset into the image */ /* calculate the offset into the image */
width = (brush_buf->width > bsp->cell_width) ? bsp->cell_width : width = (mask_buf->width > bsp->cell_width) ? bsp->cell_width : mask_buf->width;
brush_buf->width; height = (mask_buf->height > bsp->cell_height) ? bsp->cell_height : mask_buf->height;
height = (brush_buf->height > bsp->cell_height) ? bsp->cell_height :
brush_buf->height;
offset_x = col * bsp->cell_width + ((bsp->cell_width - width) >> 1); offset_x = col * bsp->cell_width + ((bsp->cell_width - width) >> 1);
offset_y = row * bsp->cell_height + ((bsp->cell_height - height) >> 1) offset_y = row * bsp->cell_height + ((bsp->cell_height - height) >> 1) - bsp->scroll_offset;
- bsp->scroll_offset;
ystart = BOUNDS (offset_y, 0, bsp->preview->allocation.height); ystart = BOUNDS (offset_y, 0, bsp->preview->allocation.height);
yend = BOUNDS (offset_y + height, 0, bsp->preview->allocation.height); yend = BOUNDS (offset_y + height, 0, bsp->preview->allocation.height);
/* Get the pointer into the brush mask data */ mask = temp_buf_data (mask_buf) + (ystart - offset_y) * mask_buf->width * 3;
buf = g_new (guchar, 3 * bsp->cell_width);
if (GIMP_IS_BRUSH_PIXMAP (brush)) if (GIMP_IS_BRUSH_PIXMAP (brush))
{ {
src = mask_buf_data (brush_buf) + (ystart - offset_y) * brush_buf->width * 3; guchar *pixmap = temp_buf_data (pixmap_buf) + (ystart - offset_y) * mask_buf->width * 3;
for (i = ystart; i < yend; i++) for (i = ystart; i < yend; i++)
{ {
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), src, b = buf;
offset_x, i, width); for (j = 0; j < width ; j++)
src += brush_buf->width * 3; {
bg = (255 - *mask);
*b++ = bg + (*mask * *pixmap++) / 255;
*b++ = bg + (*mask * *pixmap++) / 255;
*b++ = bg + (*mask * *pixmap++) / 255;
mask++;
}
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), buf, offset_x, i, width);
} }
} }
else else
{ {
buf = (unsigned char *) g_malloc (3 * sizeof (char) * bsp->cell_width);
src = mask_buf_data (brush_buf) + (ystart - offset_y) * brush_buf->width;
for (i = ystart; i < yend; i++) for (i = ystart; i < yend; i++)
{ {
/* Invert the mask for display. We're doing this because /* Invert the mask for display. We're doing this because
@ -918,38 +945,34 @@ display_brush (BrushSelectP bsp,
* However, it makes more sense for full intensity to show * However, it makes more sense for full intensity to show
* up as black in this brush preview window... * up as black in this brush preview window...
*/ */
s = src;
b = buf; b = buf;
for (j = 0; j < width; j++) for (j = 0; j < width; j++)
{ {
int k = 255 - *s++; bg = 255 - *mask++;
*b++ = k; memset (b, bg, 3);
*b++ = k; b += 3;
*b++ = k; }
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), buf, offset_x, i, width);
} }
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), buf,
offset_x, i, width);
src += brush_buf->width;
} }
g_free (buf); g_free (buf);
}
if (scale) if (scale)
{ {
offset_x = (col + 1) * bsp->cell_width - offset_x = (col + 1) * bsp->cell_width - scale_indicator_width;
brush_scale_indicator_width; offset_y = (row + 1) * bsp->cell_height - scale_indicator_height - bsp->scroll_offset;;
offset_y = (row + 1) * bsp->cell_height -
brush_scale_indicator_height - bsp->scroll_offset;;
for (i = 0; i < brush_scale_indicator_height; i++, offset_y++) for (i = 0; i < scale_indicator_height; i++, offset_y++)
{ {
if (offset_y > 0 && offset_y < bsp->preview->allocation.height) if (offset_y > 0 && offset_y < bsp->preview->allocation.height)
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview), gtk_preview_draw_row (GTK_PREVIEW (bsp->preview),
brush_scale_indicator_bits[i][0], scale_indicator_bits[i][0],
offset_x, offset_y, offset_x, offset_y,
brush_scale_indicator_width); scale_indicator_width);
} }
mask_buf_free (brush_buf); temp_buf_free (mask_buf);
if (GIMP_IS_BRUSH_PIXMAP (brush))
temp_buf_free (pixmap_buf);
} }
} }
@ -1232,7 +1255,8 @@ delete_active_brush(BrushSelectP bsp)
} }
index = gimp_brush_list_get_brush_index(brush_list, brush); index = gimp_brush_list_get_brush_index(brush_list, brush);
gimp_brush_list_remove(brush_list, GIMP_BRUSH (brush)); gimp_brush_list_remove(brush_list, GIMP_BRUSH (brush));
select_brush (gimp_brush_list_get_brush_by_index(brush_list, index)); brush = gimp_brush_list_get_brush_by_index (brush_list, index);
select_brush (brush);
} }
else else
g_message ("Wilber says: \"I don\'t know how to delete that brush.\""); g_message ("Wilber says: \"I don\'t know how to delete that brush.\"");
@ -1253,6 +1277,14 @@ brush_select_events (GtkWidget *widget,
break; break;
case GDK_2BUTTON_PRESS: case GDK_2BUTTON_PRESS:
bevent = (GdkEventButton *) event;
col = bevent->x / bsp->cell_width;
row = (bevent->y + bsp->scroll_offset) / bsp->cell_height;
index = row * bsp->NUM_BRUSH_COLUMNS + col;
/* Get the brush and check if it is editable */
brush = gimp_brush_list_get_brush_by_index (brush_list, index);
if (GIMP_IS_BRUSH_GENERATED (brush))
edit_active_brush(); edit_active_brush();
break; break;
case GDK_BUTTON_PRESS: case GDK_BUTTON_PRESS:
@ -1285,23 +1317,10 @@ brush_select_events (GtkWidget *widget,
if (bsp) if (bsp)
{ {
bsp->brush = brush; bsp->brush = brush;
brush_select_select (bsp, brush_select_select (bsp, brush);
gimp_brush_list_get_brush_index (brush_list, brush));
} }
} }
if (GIMP_IS_BRUSH_GENERATED (brush) && bsp == brush_select_dialog)
{
gtk_widget_set_sensitive (bsp->edit_button, 1);
gtk_widget_set_sensitive (bsp->delete_button, 1);
}
else
{
gtk_widget_set_sensitive (bsp->edit_button, 0);
gtk_widget_set_sensitive (bsp->delete_button, 0);
}
if (brush_edit_generated_dialog) if (brush_edit_generated_dialog)
brush_edit_generated_set_brush (brush_edit_generated_dialog, brush_edit_generated_set_brush (brush_edit_generated_dialog,
get_active_brush ()); get_active_brush ());
@ -1446,12 +1465,14 @@ brush_select_refresh_callback (GtkWidget *w,
display_brushes (bsp); display_brushes (bsp);
/* update the active selection */ /* update the active selection */
active = get_active_brush (); /* active = get_active_brush ();
/* if (active) if (active)
select_brush (bsp, active); */ select_brush (bsp, active);
/* brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, active));
active)); */ */
select_brush(gimp_brush_list_get_brush_by_index (brush_list, 0));
active = gimp_brush_list_get_brush_by_index (brush_list, 0);
select_brush (active);
/* update the display */ /* update the display */
if (bsp->redraw) if (bsp->redraw)

View File

@ -89,7 +89,7 @@ BrushSelectP brush_select_new (gchar *title,
void brush_select_free (BrushSelectP bsp); void brush_select_free (BrushSelectP bsp);
void brush_select_select (BrushSelectP bsp, void brush_select_select (BrushSelectP bsp,
int index); GimpBrushP brush);
void brush_change_callbacks (BrushSelectP bsp, void brush_change_callbacks (BrushSelectP bsp,
gint closing); gint closing);

View File

@ -145,7 +145,7 @@ sub brushes_set_popup {
/* Must alter the wigdets on screen as well */ /* Must alter the wigdets on screen as well */
bsp->brush = active; bsp->brush = active;
brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, active)); brush_select_select (bsp, active);
bsp->opacity_value = opacity; bsp->opacity_value = opacity;
bsp->spacing_value = spacing; bsp->spacing_value = spacing;