2000-05-08 09:23:30 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2000-05-31 14:15:06 +08:00
|
|
|
*
|
|
|
|
* gimpbrushmenu.c
|
2003-11-03 01:28:56 +08:00
|
|
|
* Copyright (C) 1998 Andy Thomas
|
1998-10-21 06:36:52 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-10-21 06:36:52 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
2000-05-08 09:23:30 +08:00
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
1998-10-21 06:36:52 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-10-21 06:36:52 +08:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2000-05-08 09:23:30 +08:00
|
|
|
*/
|
|
|
|
|
2002-05-14 07:30:23 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2002-01-30 22:54:27 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning GTK_DISABLE_DEPRECATED
|
|
|
|
#endif
|
|
|
|
#undef GTK_DISABLE_DEPRECATED
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimpui.h"
|
|
|
|
|
2003-06-17 17:43:14 +08:00
|
|
|
#include "libgimp-intl.h"
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
#define BRUSH_SELECT_DATA_KEY "gimp-brush-select-data"
|
|
|
|
#define CELL_SIZE 20
|
1998-10-21 06:36:52 +08:00
|
|
|
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
typedef struct _BrushSelect BrushSelect;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
struct _BrushSelect
|
2000-05-08 09:23:30 +08:00
|
|
|
{
|
2003-06-17 17:43:14 +08:00
|
|
|
gchar *title;
|
|
|
|
GimpRunBrushCallback callback;
|
2003-07-01 23:06:06 +08:00
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
GtkWidget *preview;
|
2000-05-31 14:15:06 +08:00
|
|
|
GtkWidget *button;
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2003-11-03 01:28:56 +08:00
|
|
|
GtkWidget *popup;
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2000-05-31 14:15:06 +08:00
|
|
|
gchar *brush_name; /* Local copy */
|
|
|
|
gdouble opacity;
|
|
|
|
gint spacing;
|
2003-06-17 21:15:37 +08:00
|
|
|
GimpLayerModeEffects paint_mode;
|
2000-05-31 14:15:06 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2003-06-17 17:43:14 +08:00
|
|
|
guchar *mask_data; /* local copy */
|
2003-07-01 23:06:06 +08:00
|
|
|
|
|
|
|
const gchar *temp_brush_callback;
|
1998-10-21 06:36:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void gimp_brush_select_widget_callback (const gchar *name,
|
|
|
|
gdouble opacity,
|
|
|
|
gint spacing,
|
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
const guchar *mask_data,
|
|
|
|
gboolean closing,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_brush_select_widget_clicked (GtkWidget *widget,
|
|
|
|
BrushSelect *brush_sel);
|
|
|
|
static void gimp_brush_select_widget_destroy (GtkWidget *widget,
|
|
|
|
BrushSelect *brush_sel);
|
|
|
|
static gboolean gimp_brush_select_preview_events (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
BrushSelect *brush_sel);
|
|
|
|
static void gimp_brush_select_preview_update (GtkWidget *preview,
|
|
|
|
gint brush_width,
|
|
|
|
gint brush_height,
|
2003-07-03 02:01:19 +08:00
|
|
|
const guchar *mask_data);
|
2003-07-01 23:06:06 +08:00
|
|
|
static void gimp_brush_select_popup_open (BrushSelect *brush_sel,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
|
|
|
static void gimp_brush_select_popup_close (BrushSelect *brush_sel);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-06-17 21:15:37 +08:00
|
|
|
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/**
|
|
|
|
* gimp_brush_select_widget_new:
|
|
|
|
* @title: Title of the dialog to use or %NULL to use the default title.
|
2003-11-03 01:28:56 +08:00
|
|
|
* @brush_name: Initial brush name or %NULL to use current selection.
|
2003-07-01 23:06:06 +08:00
|
|
|
* @opacity: Initial opacity. -1 means to use current opacity.
|
|
|
|
* @spacing: Initial spacing. -1 means to use current spacing.
|
|
|
|
* @paint_mode: Initial paint mode. -1 means to use current paint mode.
|
|
|
|
* @callback: A function to call when the selected brush changes.
|
|
|
|
* @data: A pointer to arbitary data to be used in the call to @callback.
|
|
|
|
*
|
|
|
|
* Creates a new #GtkWidget that completely controls the selection of
|
|
|
|
* a #GimpBrush. This widget is suitable for placement in a table in
|
|
|
|
* a plug-in dialog.
|
|
|
|
*
|
|
|
|
* Returns: A #GtkWidget that you can use in your UI.
|
|
|
|
*/
|
2003-11-03 01:28:56 +08:00
|
|
|
GtkWidget *
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_brush_select_widget_new (const gchar *title,
|
2003-11-03 01:28:56 +08:00
|
|
|
const gchar *brush_name,
|
2003-07-01 23:06:06 +08:00
|
|
|
gdouble opacity,
|
|
|
|
gint spacing,
|
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
GimpRunBrushCallback callback,
|
|
|
|
gpointer data)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
BrushSelect *brush_sel;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
gint init_spacing;
|
|
|
|
GimpLayerModeEffects init_paint_mode;
|
|
|
|
gdouble init_opacity;
|
|
|
|
gint mask_data_size;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_return_val_if_fail (callback != NULL, NULL);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (! title)
|
|
|
|
title = _("Brush Selection");
|
|
|
|
|
|
|
|
brush_sel = g_new0 (BrushSelect, 1);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
brush_sel->title = g_strdup (title);
|
|
|
|
brush_sel->callback = callback;
|
|
|
|
brush_sel->data = data;
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-06-17 21:15:37 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_OUT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
|
2003-06-17 21:15:37 +08:00
|
|
|
gtk_widget_show (frame);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
brush_sel->preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
|
|
|
gtk_widget_set_events (brush_sel->preview,
|
|
|
|
GDK_EXPOSURE_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK);
|
2003-11-03 01:28:56 +08:00
|
|
|
gtk_preview_size (GTK_PREVIEW (brush_sel->preview), CELL_SIZE, CELL_SIZE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), brush_sel->preview);
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_widget_show (brush_sel->preview);
|
|
|
|
|
|
|
|
g_signal_connect (brush_sel->preview, "event",
|
|
|
|
G_CALLBACK (gimp_brush_select_preview_events),
|
|
|
|
brush_sel);
|
|
|
|
|
2003-11-03 02:59:55 +08:00
|
|
|
brush_sel->button = gtk_button_new_with_mnemonic (_("_Browse..."));
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), brush_sel->button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (brush_sel->button);
|
|
|
|
|
|
|
|
g_signal_connect (brush_sel->button, "clicked",
|
|
|
|
G_CALLBACK (gimp_brush_select_widget_clicked),
|
|
|
|
brush_sel);
|
|
|
|
g_signal_connect (brush_sel->button, "destroy",
|
|
|
|
G_CALLBACK (gimp_brush_select_widget_destroy),
|
|
|
|
brush_sel);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/* Do initial brush setup */
|
|
|
|
brush_sel->brush_name = gimp_brushes_get_brush_data (brush_name,
|
|
|
|
&init_opacity,
|
|
|
|
&init_spacing,
|
|
|
|
&init_paint_mode,
|
|
|
|
&brush_sel->width,
|
|
|
|
&brush_sel->height,
|
|
|
|
&mask_data_size,
|
|
|
|
&brush_sel->mask_data);
|
|
|
|
|
|
|
|
if (brush_sel->brush_name)
|
|
|
|
{
|
|
|
|
brush_sel->opacity = (opacity == -1.0) ? init_opacity : opacity;
|
|
|
|
brush_sel->spacing = (spacing == -1) ? init_spacing : spacing;
|
|
|
|
brush_sel->paint_mode = (paint_mode == -1) ? init_paint_mode : paint_mode;
|
|
|
|
|
|
|
|
gimp_brush_select_preview_update (brush_sel->preview,
|
|
|
|
brush_sel->width,
|
|
|
|
brush_sel->height,
|
|
|
|
brush_sel->mask_data);
|
|
|
|
}
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_object_set_data (G_OBJECT (hbox), BRUSH_SELECT_DATA_KEY, brush_sel);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
return hbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_brush_select_widget_close:
|
|
|
|
* @widget: A brush select widget.
|
|
|
|
*
|
|
|
|
* Closes the popup window associated with @widget.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_brush_select_widget_close (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
BrushSelect *brush_sel;
|
|
|
|
|
|
|
|
brush_sel = g_object_get_data (G_OBJECT (widget), BRUSH_SELECT_DATA_KEY);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_return_if_fail (brush_sel != NULL);
|
|
|
|
|
|
|
|
if (brush_sel->temp_brush_callback)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_brush_select_destroy (brush_sel->temp_brush_callback);
|
|
|
|
brush_sel->temp_brush_callback = NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/**
|
|
|
|
* gimp_brush_select_widget_set;
|
|
|
|
* @widget: A brush select widget.
|
2003-11-03 01:28:56 +08:00
|
|
|
* @brush_name: Brush name to set; %NULL means no change.
|
2003-07-01 23:06:06 +08:00
|
|
|
* @opacity: Opacity to set. -1 means no change.
|
|
|
|
* @spacing: Spacing to set. -1 means no change.
|
|
|
|
* @paint_mode: Paint mode to set. -1 means no change.
|
|
|
|
*
|
|
|
|
* Sets the current brush and other values for the brush select
|
|
|
|
* widget. Calls the callback function if one was supplied in the
|
|
|
|
* call to gimp_brush_select_widget_new().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_brush_select_widget_set (GtkWidget *widget,
|
|
|
|
const gchar *brush_name,
|
|
|
|
gdouble opacity,
|
|
|
|
gint spacing,
|
|
|
|
GimpLayerModeEffects paint_mode)
|
|
|
|
{
|
|
|
|
BrushSelect *brush_sel;
|
2003-11-03 01:28:56 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
brush_sel = g_object_get_data (G_OBJECT (widget), BRUSH_SELECT_DATA_KEY);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_return_if_fail (brush_sel != NULL);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (brush_sel->temp_brush_callback)
|
|
|
|
{
|
2003-11-03 01:28:56 +08:00
|
|
|
gimp_brushes_set_popup (brush_sel->temp_brush_callback,
|
2003-07-01 23:06:06 +08:00
|
|
|
brush_name, opacity, spacing, paint_mode);
|
1998-10-21 06:36:52 +08:00
|
|
|
}
|
2003-07-01 23:06:06 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint init_spacing;
|
|
|
|
GimpLayerModeEffects init_paint_mode;
|
|
|
|
gdouble init_opacity;
|
|
|
|
gint mask_data_size;
|
|
|
|
guint8 *mask_data;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = gimp_brushes_get_brush_data (brush_name,
|
|
|
|
&init_opacity,
|
|
|
|
&init_spacing,
|
|
|
|
&init_paint_mode,
|
|
|
|
&width,
|
|
|
|
&height,
|
|
|
|
&mask_data_size,
|
|
|
|
&mask_data);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
if (opacity == -1.0) opacity = init_opacity;
|
|
|
|
if (spacing == -1) spacing = init_spacing;
|
|
|
|
if (paint_mode == -1) paint_mode = init_paint_mode;
|
2003-11-03 01:28:56 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_brush_select_widget_callback (brush_name, opacity, spacing,
|
|
|
|
paint_mode, width, height,
|
|
|
|
mask_data, FALSE, brush_sel);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_free (name);
|
|
|
|
g_free (mask_data);
|
|
|
|
}
|
|
|
|
}
|
1998-10-21 06:36:52 +08:00
|
|
|
}
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
static void
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_brush_select_widget_callback (const gchar *name,
|
|
|
|
gdouble opacity,
|
|
|
|
gint spacing,
|
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
const guchar *mask_data,
|
|
|
|
gboolean closing,
|
|
|
|
gpointer data)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
BrushSelect *brush_sel = (BrushSelect *) data;
|
|
|
|
|
|
|
|
g_free (brush_sel->brush_name);
|
|
|
|
g_free (brush_sel->mask_data);
|
|
|
|
|
|
|
|
brush_sel->brush_name = g_strdup (name);
|
|
|
|
brush_sel->width = width;
|
|
|
|
brush_sel->height = height;
|
|
|
|
brush_sel->mask_data = g_memdup (mask_data, width * height);
|
|
|
|
brush_sel->opacity = opacity;
|
|
|
|
brush_sel->spacing = spacing;
|
|
|
|
brush_sel->paint_mode = paint_mode;
|
|
|
|
|
|
|
|
gimp_brush_select_preview_update (brush_sel->preview,
|
|
|
|
width, height, mask_data);
|
|
|
|
|
|
|
|
if (brush_sel->callback)
|
|
|
|
brush_sel->callback (name, opacity, spacing, paint_mode,
|
|
|
|
width, height, mask_data, closing, brush_sel->data);
|
|
|
|
|
|
|
|
if (closing)
|
|
|
|
brush_sel->temp_brush_callback = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_select_widget_clicked (GtkWidget *widget,
|
|
|
|
BrushSelect *brush_sel)
|
|
|
|
{
|
|
|
|
if (brush_sel->temp_brush_callback)
|
|
|
|
{
|
|
|
|
/* calling gimp_brushes_set_popup() raises the dialog */
|
2003-11-03 01:28:56 +08:00
|
|
|
gimp_brushes_set_popup (brush_sel->temp_brush_callback,
|
2003-07-01 23:06:06 +08:00
|
|
|
brush_sel->brush_name,
|
|
|
|
brush_sel->opacity,
|
|
|
|
brush_sel->spacing,
|
|
|
|
brush_sel->paint_mode);
|
|
|
|
}
|
|
|
|
else
|
2003-06-17 21:15:37 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
brush_sel->temp_brush_callback =
|
|
|
|
gimp_brush_select_new (brush_sel->title,
|
|
|
|
brush_sel->brush_name,
|
|
|
|
brush_sel->opacity,
|
|
|
|
brush_sel->spacing,
|
|
|
|
brush_sel->paint_mode,
|
|
|
|
gimp_brush_select_widget_callback,
|
|
|
|
brush_sel);
|
2003-06-17 21:15:37 +08:00
|
|
|
}
|
1998-10-21 06:36:52 +08:00
|
|
|
}
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_select_widget_destroy (GtkWidget *widget,
|
|
|
|
BrushSelect *brush_sel)
|
|
|
|
{
|
|
|
|
if (brush_sel->temp_brush_callback)
|
|
|
|
{
|
|
|
|
gimp_brush_select_destroy (brush_sel->temp_brush_callback);
|
|
|
|
brush_sel->temp_brush_callback = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (brush_sel->title);
|
|
|
|
g_free (brush_sel->brush_name);
|
|
|
|
g_free (brush_sel->mask_data);
|
|
|
|
g_free (brush_sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_brush_select_preview_events (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
BrushSelect *brush_sel)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
|
|
|
GdkEventButton *bevent;
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (brush_sel->mask_data)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
bevent = (GdkEventButton *) event;
|
2003-11-03 01:28:56 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
if (bevent->button == 1)
|
|
|
|
{
|
2000-05-08 09:23:30 +08:00
|
|
|
gtk_grab_add (widget);
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_brush_select_popup_open (brush_sel, bevent->x, bevent->y);
|
1998-10-21 06:36:52 +08:00
|
|
|
}
|
|
|
|
break;
|
2003-11-03 01:28:56 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
case GDK_BUTTON_RELEASE:
|
|
|
|
bevent = (GdkEventButton *) event;
|
2003-11-03 01:28:56 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
if (bevent->button == 1)
|
|
|
|
{
|
2000-05-08 09:23:30 +08:00
|
|
|
gtk_grab_remove (widget);
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_brush_select_popup_close (brush_sel);
|
1998-10-21 06:36:52 +08:00
|
|
|
}
|
|
|
|
break;
|
2003-11-03 01:28:56 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-03 02:01:19 +08:00
|
|
|
gimp_brush_select_preview_update (GtkWidget *preview,
|
|
|
|
gint brush_width,
|
|
|
|
gint brush_height,
|
|
|
|
const guchar *mask_data)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2003-06-17 17:43:14 +08:00
|
|
|
guchar *buf;
|
|
|
|
guchar *b;
|
|
|
|
const guchar *src;
|
|
|
|
const guchar *s;
|
|
|
|
gint i, y;
|
|
|
|
gint offset_x, offset_y;
|
|
|
|
gint ystart, yend;
|
|
|
|
gint width, height;
|
2000-05-08 09:23:30 +08:00
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
/* Draw the brush */
|
2003-11-03 01:28:56 +08:00
|
|
|
buf = g_new (guchar, CELL_SIZE);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-11-03 01:28:56 +08:00
|
|
|
/* Set buffer to white */
|
2000-05-08 09:23:30 +08:00
|
|
|
memset (buf, 255, CELL_SIZE);
|
1998-10-21 06:36:52 +08:00
|
|
|
for (i = 0; i < CELL_SIZE; i++)
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview),
|
2003-06-17 17:43:14 +08:00
|
|
|
buf, 0, i, CELL_SIZE);
|
|
|
|
|
|
|
|
/* Limit to cell size */
|
|
|
|
width = (brush_width > CELL_SIZE) ? CELL_SIZE: brush_width;
|
|
|
|
height = (brush_height > CELL_SIZE) ? CELL_SIZE: brush_height;
|
|
|
|
|
|
|
|
offset_x = ((CELL_SIZE - width) / 2);
|
|
|
|
offset_y = ((CELL_SIZE - height) / 2);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
|
|
|
ystart = CLAMP (offset_y, 0, CELL_SIZE);
|
2000-05-31 14:15:06 +08:00
|
|
|
yend = CLAMP (offset_y + height, 0, CELL_SIZE);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
|
|
|
src = mask_data;
|
|
|
|
|
|
|
|
for (y = ystart; y < yend; y++)
|
|
|
|
{
|
2000-05-31 14:15:06 +08:00
|
|
|
gint j;
|
|
|
|
|
1998-10-21 06:36:52 +08:00
|
|
|
s = src;
|
|
|
|
b = buf;
|
|
|
|
for (j = 0; j < width ; j++)
|
|
|
|
*b++ = 255 - *s++;
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview),
|
2003-06-17 17:43:14 +08:00
|
|
|
buf, offset_x, y, width);
|
1998-10-21 06:36:52 +08:00
|
|
|
src += brush_width;
|
|
|
|
}
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2000-05-08 09:23:30 +08:00
|
|
|
g_free (buf);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_widget_queue_draw (preview);
|
1998-10-21 06:36:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_brush_select_popup_open (BrushSelect *brush_sel,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *preview;
|
|
|
|
const guchar *src;
|
|
|
|
const guchar *s;
|
|
|
|
guchar *buf;
|
|
|
|
guchar *b;
|
|
|
|
gint x_org;
|
|
|
|
gint y_org;
|
2003-11-02 04:06:01 +08:00
|
|
|
GdkScreen *screen;
|
2003-07-01 23:06:06 +08:00
|
|
|
gint scr_w;
|
|
|
|
gint scr_h;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (brush_sel->popup)
|
|
|
|
gimp_brush_select_popup_close (brush_sel);
|
2000-05-08 09:23:30 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (brush_sel->width <= CELL_SIZE && brush_sel->height <= CELL_SIZE)
|
|
|
|
return;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
brush_sel->popup = gtk_window_new (GTK_WINDOW_POPUP);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
|
|
|
gtk_container_add (GTK_CONTAINER (brush_sel->popup), frame);
|
2000-05-08 09:23:30 +08:00
|
|
|
gtk_widget_show (frame);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
|
|
|
gtk_preview_size (GTK_PREVIEW (preview),
|
|
|
|
brush_sel->width, brush_sel->height);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview);
|
|
|
|
gtk_widget_show (preview);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/* decide where to put the popup */
|
|
|
|
gdk_window_get_origin (brush_sel->preview->window, &x_org, &y_org);
|
2003-11-02 04:06:01 +08:00
|
|
|
|
|
|
|
screen = gtk_widget_get_screen (brush_sel->popup);
|
|
|
|
scr_w = gdk_screen_get_width (screen);
|
|
|
|
scr_h = gdk_screen_get_height (screen);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
x = x_org + x - (brush_sel->width / 2);
|
|
|
|
y = y_org + y - (brush_sel->height / 2);
|
|
|
|
x = (x < 0) ? 0 : x;
|
|
|
|
y = (y < 0) ? 0 : y;
|
|
|
|
x = (x + brush_sel->width > scr_w) ? scr_w - brush_sel->width : x;
|
|
|
|
y = (y + brush_sel->height > scr_h) ? scr_h - brush_sel->height : y;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_window_move (GTK_WINDOW (brush_sel->popup), x, y);
|
2003-11-03 01:28:56 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/* Draw the brush */
|
|
|
|
buf = g_new (guchar, brush_sel->width);
|
|
|
|
memset (buf, 255, brush_sel->width);
|
2003-11-03 01:28:56 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
src = brush_sel->mask_data;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
for (y = 0; y < brush_sel->height; y++)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
int j;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
s = src;
|
|
|
|
b = buf;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
for (j = 0; j < brush_sel->width ; j++)
|
|
|
|
*b++ = 255 - *s++;
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
|
|
|
0, y, brush_sel->width);
|
|
|
|
src += brush_sel->width;
|
|
|
|
}
|
2000-05-31 14:15:06 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_free (buf);
|
1998-10-21 06:36:52 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_widget_show (brush_sel->popup);
|
1998-10-21 06:36:52 +08:00
|
|
|
}
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_select_popup_close (BrushSelect *brush_sel)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
if (brush_sel->popup)
|
1998-10-21 06:36:52 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_widget_destroy (brush_sel->popup);
|
|
|
|
brush_sel->popup = NULL;
|
1998-10-21 06:36:52 +08:00
|
|
|
}
|
|
|
|
}
|