2008-01-29 05:08:35 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2008-01-29 05:08:35 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-01-29 05:08:35 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2008-01-29 05:08:35 +08:00
|
|
|
*/
|
2002-01-30 22:54:27 +08:00
|
|
|
|
1999-08-27 06:29:37 +08:00
|
|
|
#include "config.h"
|
2002-01-30 22:54:27 +08:00
|
|
|
|
1999-08-27 06:29:37 +08:00
|
|
|
#include <string.h>
|
2002-01-30 22:54:27 +08:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include <libgimpmath/gimpmath.h>
|
|
|
|
|
|
|
|
#include "gimpressionist.h"
|
|
|
|
#include "ppmtool.h"
|
2004-07-06 00:50:46 +08:00
|
|
|
#include "brush.h"
|
2004-07-06 22:17:17 +08:00
|
|
|
#include "presets.h"
|
2002-01-30 22:54:27 +08:00
|
|
|
|
|
|
|
#include <libgimp/stdplugins-intl.h>
|
|
|
|
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
static void update_brush_preview (const char *fn);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
static GtkWidget *brush_preview = NULL;
|
2004-07-13 21:27:47 +08:00
|
|
|
static GtkListStore *brush_list_store = NULL;
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2011-10-02 20:09:45 +08:00
|
|
|
static GtkWidget *brush_list = NULL;
|
2020-10-31 10:44:21 +08:00
|
|
|
static GtkWidget *brush_relief_scale = NULL;
|
|
|
|
static GtkWidget *brush_aspect_scale = NULL;
|
2011-10-02 20:09:45 +08:00
|
|
|
static GtkAdjustment *brush_gamma_adjust = NULL;
|
|
|
|
static gboolean brush_dont_update = FALSE;
|
2004-07-02 21:31:25 +08:00
|
|
|
|
2004-07-06 00:50:46 +08:00
|
|
|
static gchar *last_selected_brush = NULL;
|
|
|
|
|
2004-07-13 21:27:47 +08:00
|
|
|
static gint brush_from_file = 2;
|
2004-07-08 23:55:14 +08:00
|
|
|
|
|
|
|
static ppm_t brushppm = {0, 0, NULL};
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
void
|
|
|
|
brush_restore (void)
|
2004-07-02 21:31:25 +08:00
|
|
|
{
|
2004-07-30 02:41:47 +08:00
|
|
|
reselect (brush_list, pcvals.selected_brush);
|
2011-10-02 20:09:45 +08:00
|
|
|
gtk_adjustment_set_value (brush_gamma_adjust, pcvals.brushgamma);
|
2020-11-06 00:37:15 +08:00
|
|
|
gimp_label_spin_set_value (GIMP_LABEL_SPIN (brush_relief_scale), pcvals.brush_relief);
|
|
|
|
gimp_label_spin_set_value (GIMP_LABEL_SPIN (brush_aspect_scale), pcvals.brush_aspect);
|
2004-07-02 21:31:25 +08:00
|
|
|
}
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
void
|
|
|
|
brush_store (void)
|
2004-07-02 21:31:25 +08:00
|
|
|
{
|
2011-10-02 20:09:45 +08:00
|
|
|
pcvals.brushgamma = gtk_adjustment_get_value (brush_gamma_adjust);
|
2004-07-02 21:31:25 +08:00
|
|
|
}
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
void
|
|
|
|
brush_free (void)
|
2004-07-06 00:50:46 +08:00
|
|
|
{
|
|
|
|
g_free (last_selected_brush);
|
|
|
|
}
|
|
|
|
|
2004-07-08 23:55:14 +08:00
|
|
|
void brush_get_selected (ppm_t *p)
|
|
|
|
{
|
2004-09-03 07:28:44 +08:00
|
|
|
if (brush_from_file)
|
2004-07-30 02:41:47 +08:00
|
|
|
brush_reload (pcvals.selected_brush, p);
|
2004-07-08 23:55:14 +08:00
|
|
|
else
|
2004-07-15 19:58:47 +08:00
|
|
|
ppm_copy (&brushppm, p);
|
2004-07-08 23:55:14 +08:00
|
|
|
}
|
|
|
|
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
static gboolean
|
|
|
|
file_is_color (const char *fn)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-07-15 19:58:47 +08:00
|
|
|
return fn && strstr (fn, ".ppm");
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
void
|
|
|
|
set_colorbrushes (const gchar *fn)
|
2004-07-02 21:31:25 +08:00
|
|
|
{
|
2004-09-03 07:28:44 +08:00
|
|
|
pcvals.color_brushes = file_is_color (fn);
|
2004-07-02 21:31:25 +08:00
|
|
|
}
|
|
|
|
|
2019-07-20 00:58:24 +08:00
|
|
|
static const Babl *
|
2019-09-01 16:48:05 +08:00
|
|
|
get_u8_format (GimpDrawable *drawable)
|
2019-07-20 00:58:24 +08:00
|
|
|
{
|
2019-09-01 16:48:05 +08:00
|
|
|
if (gimp_drawable_is_rgb (drawable))
|
2019-07-20 00:58:24 +08:00
|
|
|
{
|
2019-09-01 16:48:05 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2019-07-20 00:58:24 +08:00
|
|
|
return babl_format ("R'G'B'A u8");
|
|
|
|
else
|
|
|
|
return babl_format ("R'G'B' u8");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-01 16:48:05 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2019-07-20 00:58:24 +08:00
|
|
|
return babl_format ("Y'A u8");
|
|
|
|
else
|
|
|
|
return babl_format ("Y' u8");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-22 07:09:16 +08:00
|
|
|
static void
|
|
|
|
brushdmenuselect (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2019-09-01 16:48:05 +08:00
|
|
|
GeglBuffer *src_buffer;
|
|
|
|
const Babl *format;
|
|
|
|
guchar *src_row;
|
|
|
|
guchar *src;
|
|
|
|
gint bpp;
|
|
|
|
gint x, y;
|
|
|
|
ppm_t *p;
|
|
|
|
gint x1, y1, w, h;
|
|
|
|
gint row;
|
|
|
|
gint32 drawable_id = -1;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
gint rowstride;
|
2019-07-20 00:58:24 +08:00
|
|
|
|
|
|
|
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &drawable_id);
|
|
|
|
|
2019-09-03 16:48:32 +08:00
|
|
|
drawable = gimp_drawable_get_by_id (drawable_id);
|
2019-09-01 16:48:05 +08:00
|
|
|
|
|
|
|
if (! drawable)
|
2004-04-22 07:09:16 +08:00
|
|
|
return;
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-07-13 21:27:47 +08:00
|
|
|
if (brush_from_file == 2)
|
2004-04-22 07:09:16 +08:00
|
|
|
return; /* Not finished GUI-building yet */
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-07-13 21:27:47 +08:00
|
|
|
if (brush_from_file)
|
2004-04-22 07:09:16 +08:00
|
|
|
{
|
2004-07-02 21:31:25 +08:00
|
|
|
#if 0
|
2004-09-03 07:28:44 +08:00
|
|
|
unselectall (brush_list);
|
2004-07-02 21:31:25 +08:00
|
|
|
#endif
|
2004-07-08 23:55:14 +08:00
|
|
|
preset_save_button_set_sensitive (FALSE);
|
2004-04-22 07:09:16 +08:00
|
|
|
}
|
|
|
|
|
2011-10-02 20:09:45 +08:00
|
|
|
gtk_adjustment_set_value (brush_gamma_adjust, 1.0);
|
2020-11-06 00:37:15 +08:00
|
|
|
gimp_label_spin_set_value (GIMP_LABEL_SPIN (brush_aspect_scale), 0.0);
|
2004-04-22 07:09:16 +08:00
|
|
|
|
2019-09-01 16:48:05 +08:00
|
|
|
if (! gimp_drawable_mask_intersect (drawable, &x1, &y1, &w, &h))
|
2015-10-26 18:54:39 +08:00
|
|
|
return;
|
2003-11-10 06:44:45 +08:00
|
|
|
|
2019-09-01 16:48:05 +08:00
|
|
|
format = get_u8_format (drawable);
|
2019-07-20 00:58:24 +08:00
|
|
|
bpp = babl_format_get_bytes_per_pixel (format);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-07-26 02:12:49 +08:00
|
|
|
ppm_kill (&brushppm);
|
2015-10-26 18:54:39 +08:00
|
|
|
ppm_new (&brushppm, w, h);
|
1999-08-27 06:29:37 +08:00
|
|
|
p = &brushppm;
|
|
|
|
|
1999-08-30 05:06:26 +08:00
|
|
|
rowstride = p->width * 3;
|
|
|
|
|
2015-10-26 18:54:39 +08:00
|
|
|
src_row = g_new (guchar, w * bpp);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2019-09-01 16:48:05 +08:00
|
|
|
src_buffer = gimp_drawable_get_buffer (drawable);
|
2003-11-10 06:44:45 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
if (bpp == 3)
|
|
|
|
{ /* RGB */
|
2015-10-26 18:54:39 +08:00
|
|
|
gint bpr = w * 3;
|
|
|
|
gint y2 = y1 + h;
|
2004-09-03 07:28:44 +08:00
|
|
|
|
|
|
|
for (row = 0, y = y1; y < y2; row++, y++)
|
|
|
|
{
|
2019-07-20 00:58:24 +08:00
|
|
|
gegl_buffer_get (src_buffer, GEGL_RECTANGLE (x1, y, w, 1), 1.0,
|
|
|
|
format, src_row,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
memcpy (p->col + row*rowstride, src_row, bpr);
|
|
|
|
}
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
2004-09-03 07:28:44 +08:00
|
|
|
else
|
|
|
|
{ /* RGBA (bpp > 3) GrayA (bpp == 2) or Gray */
|
|
|
|
gboolean is_gray = ((bpp > 3) ? TRUE : FALSE);
|
2015-10-26 18:54:39 +08:00
|
|
|
gint y2 = y1 + h;
|
2004-09-03 07:28:44 +08:00
|
|
|
|
|
|
|
for (row = 0, y = y1; y < y2; row++, y++)
|
|
|
|
{
|
|
|
|
guchar *tmprow_ptr;
|
2023-08-21 02:57:05 +08:00
|
|
|
guchar *tmprow = p->col + row * rowstride;
|
|
|
|
gint x2 = x1 + w;
|
2015-10-26 18:54:39 +08:00
|
|
|
|
2019-07-20 00:58:24 +08:00
|
|
|
gegl_buffer_get (src_buffer, GEGL_RECTANGLE (x1, y, w, 1), 1.0,
|
|
|
|
format, src_row,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2004-09-03 07:28:44 +08:00
|
|
|
|
|
|
|
src = src_row;
|
|
|
|
tmprow_ptr = tmprow;
|
|
|
|
/* Possible micro-optimization here:
|
2015-10-26 18:54:39 +08:00
|
|
|
* src_end = src + src_rgn.bpp * w);
|
2004-09-03 07:28:44 +08:00
|
|
|
* for ( ; src < src_end ; src += src_rgn.bpp)
|
|
|
|
*/
|
|
|
|
for (x = x1; x < x2; x++)
|
|
|
|
{
|
|
|
|
*(tmprow_ptr++) = src[0];
|
|
|
|
*(tmprow_ptr++) = src[is_gray ? 1 : 0];
|
|
|
|
*(tmprow_ptr++) = src[is_gray ? 2 : 0];
|
2019-07-20 00:58:24 +08:00
|
|
|
src += bpp;
|
2004-09-03 07:28:44 +08:00
|
|
|
}
|
|
|
|
}
|
2003-11-10 06:44:45 +08:00
|
|
|
}
|
2019-07-20 00:58:24 +08:00
|
|
|
|
|
|
|
g_object_unref (src_buffer);
|
|
|
|
|
1999-12-31 02:54:17 +08:00
|
|
|
g_free (src_row);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
if (bpp >= 3)
|
|
|
|
pcvals.color_brushes = 1;
|
|
|
|
else
|
|
|
|
pcvals.color_brushes = 0;
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-07-13 21:27:47 +08:00
|
|
|
brush_from_file = 0;
|
2004-09-03 07:28:44 +08:00
|
|
|
update_brush_preview (NULL);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
static void
|
|
|
|
brushlistrefresh (void)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-07-13 21:27:47 +08:00
|
|
|
gtk_list_store_clear (brush_list_store);
|
|
|
|
readdirintolist ("Brushes", brush_list, NULL);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
static void
|
|
|
|
savebrush_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
gpointer data)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2003-11-19 22:51:52 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-05-18 19:39:22 +08:00
|
|
|
gchar *name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
2003-11-19 22:51:52 +08:00
|
|
|
|
2004-07-15 19:58:47 +08:00
|
|
|
ppm_save (&brushppm, name);
|
2003-11-19 22:51:52 +08:00
|
|
|
brushlistrefresh ();
|
2004-05-18 19:39:22 +08:00
|
|
|
|
|
|
|
g_free (name);
|
2003-11-19 22:51:52 +08:00
|
|
|
}
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
static void
|
2003-11-19 22:51:52 +08:00
|
|
|
savebrush (GtkWidget *wg,
|
|
|
|
gpointer data)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-07-26 22:56:44 +08:00
|
|
|
GtkWidget *dialog = NULL;
|
2004-09-03 07:28:44 +08:00
|
|
|
GList *thispath = parsepath ();
|
|
|
|
gchar *path;
|
2003-11-19 22:51:52 +08:00
|
|
|
|
2004-07-26 02:12:49 +08:00
|
|
|
if (! PPM_IS_INITED (&brushppm))
|
2003-11-19 22:51:52 +08:00
|
|
|
{
|
2004-09-03 07:28:44 +08:00
|
|
|
g_message ( _("Can only save drawables!"));
|
2003-11-19 22:51:52 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
dialog =
|
|
|
|
gtk_file_chooser_dialog_new (_("Save Brush"),
|
|
|
|
GTK_WINDOW (gtk_widget_get_toplevel (wg)),
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
|
2017-02-12 23:18:24 +08:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Save"), GTK_RESPONSE_OK,
|
2003-11-10 06:44:45 +08:00
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
NULL);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2017-02-12 23:18:24 +08:00
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
2018-05-10 23:04:37 +08:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-04-08 01:10:05 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2007-02-02 16:57:15 +08:00
|
|
|
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
|
|
|
|
TRUE);
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
path = g_build_filename ((gchar *)thispath->data, "Brushes", NULL);
|
2004-01-27 09:44:55 +08:00
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), path);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-01-27 09:44:55 +08:00
|
|
|
g_free (path);
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
g_signal_connect (dialog, "destroy",
|
2003-11-19 22:51:52 +08:00
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
2004-05-18 19:39:22 +08:00
|
|
|
&dialog);
|
|
|
|
g_signal_connect (dialog, "response",
|
2003-11-19 22:51:52 +08:00
|
|
|
G_CALLBACK (savebrush_response),
|
|
|
|
NULL);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
gtk_widget_show (dialog);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-04-22 07:09:16 +08:00
|
|
|
static gboolean
|
2019-09-01 16:48:05 +08:00
|
|
|
validdrawable (GimpImage *image,
|
|
|
|
GimpItem *item,
|
|
|
|
gpointer data)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2019-09-01 16:48:05 +08:00
|
|
|
return (gimp_drawable_is_rgb (GIMP_DRAWABLE (item)) ||
|
|
|
|
gimp_drawable_is_gray (GIMP_DRAWABLE (item)));
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-07-02 21:31:25 +08:00
|
|
|
/*
|
|
|
|
* This function caches the last result. Call it with fn as NULL, to
|
|
|
|
* free the arguments.
|
|
|
|
* */
|
2004-05-18 19:39:22 +08:00
|
|
|
void
|
2004-07-13 21:27:47 +08:00
|
|
|
brush_reload (const gchar *fn,
|
2004-09-03 07:28:44 +08:00
|
|
|
ppm_t *p)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-09-03 07:28:44 +08:00
|
|
|
static char lastfn[256] = "";
|
|
|
|
static ppm_t cache = {0, 0, NULL};
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-07-02 21:31:25 +08:00
|
|
|
if (fn == NULL)
|
|
|
|
{
|
2004-07-15 19:58:47 +08:00
|
|
|
ppm_kill (&cache);
|
2004-07-02 21:31:25 +08:00
|
|
|
lastfn[0] = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
if (strcmp (fn, lastfn))
|
2004-01-27 09:44:55 +08:00
|
|
|
{
|
|
|
|
g_strlcpy (lastfn, fn, sizeof (lastfn));
|
2004-07-15 19:58:47 +08:00
|
|
|
ppm_kill (&cache);
|
|
|
|
ppm_load (fn, &cache);
|
2004-01-27 09:44:55 +08:00
|
|
|
}
|
2004-07-15 19:58:47 +08:00
|
|
|
ppm_copy (&cache, p);
|
|
|
|
set_colorbrushes (fn);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
static void
|
|
|
|
padbrush (ppm_t *p,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-09-03 07:28:44 +08:00
|
|
|
guchar black[3] = {0, 0, 0};
|
|
|
|
|
|
|
|
int left = (width - p->width) / 2;
|
|
|
|
int right = (width - p->width) - left;
|
|
|
|
int top = (height - p->height) / 2;
|
1999-08-27 06:29:37 +08:00
|
|
|
int bottom = (height - p->height) - top;
|
2004-09-03 07:28:44 +08:00
|
|
|
|
|
|
|
ppm_pad (p, left, right, top, bottom, black);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
static void
|
2004-07-13 21:27:47 +08:00
|
|
|
update_brush_preview (const gchar *fn)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2003-07-03 21:26:06 +08:00
|
|
|
gint i, j;
|
2004-07-31 16:42:44 +08:00
|
|
|
guchar *preview_image;
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
if (fn)
|
2004-07-13 21:27:47 +08:00
|
|
|
brush_from_file = 1;
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
preview_image = g_new0 (guchar, 100*100);
|
2004-07-31 16:42:44 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
if (!fn && brush_from_file)
|
|
|
|
{
|
2004-07-31 16:42:44 +08:00
|
|
|
/* preview_image is already initialized to our liking. */
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
2004-09-03 07:28:44 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
double sc;
|
|
|
|
ppm_t p = {0, 0, NULL};
|
|
|
|
guchar gammatable[256];
|
|
|
|
int newheight;
|
|
|
|
|
|
|
|
if (brush_from_file)
|
|
|
|
brush_reload (fn, &p);
|
|
|
|
else if (PPM_IS_INITED (&brushppm))
|
|
|
|
ppm_copy (&brushppm, &p);
|
|
|
|
|
|
|
|
set_colorbrushes (fn);
|
|
|
|
|
2011-10-02 20:09:45 +08:00
|
|
|
sc = gtk_adjustment_get_value (brush_gamma_adjust);
|
2004-09-03 07:28:44 +08:00
|
|
|
if (sc != 1.0)
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
gammatable[i] = pow (i / 255.0, sc) * 255;
|
|
|
|
else
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
gammatable[i] = i;
|
|
|
|
|
|
|
|
newheight = p.height *
|
2020-11-06 00:37:15 +08:00
|
|
|
pow (10, gimp_label_spin_get_value (GIMP_LABEL_SPIN (brush_aspect_scale)));
|
2004-09-03 07:28:44 +08:00
|
|
|
|
|
|
|
sc = p.width > newheight ? p.width : newheight;
|
|
|
|
sc = 100.0 / sc;
|
|
|
|
resize_fast (&p, p.width*sc,newheight*sc);
|
|
|
|
padbrush (&p, 100, 100);
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
{
|
|
|
|
int k = i * p.width * 3;
|
|
|
|
if (i < p.height)
|
|
|
|
for (j = 0; j < p.width; j++)
|
|
|
|
preview_image[i*100+j] = gammatable[p.col[k + j * 3]];
|
|
|
|
}
|
|
|
|
ppm_kill (&p);
|
|
|
|
}
|
2004-07-31 16:42:44 +08:00
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (brush_preview),
|
|
|
|
0, 0, 100, 100,
|
|
|
|
GIMP_GRAY_IMAGE,
|
|
|
|
preview_image,
|
|
|
|
100);
|
|
|
|
|
|
|
|
g_free (preview_image);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-31 16:42:44 +08:00
|
|
|
/*
|
|
|
|
* "force" implies here to change the brush even if it was the same.
|
|
|
|
* It is used for the initialization of the preview.
|
|
|
|
* */
|
2004-05-18 19:39:22 +08:00
|
|
|
static void
|
2004-07-31 16:42:44 +08:00
|
|
|
brush_select (GtkTreeSelection *selection, gboolean force)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-01-27 09:44:55 +08:00
|
|
|
GtkTreeIter iter;
|
2002-12-18 04:18:16 +08:00
|
|
|
GtkTreeModel *model;
|
2004-07-06 00:50:46 +08:00
|
|
|
gchar *fname = NULL;
|
|
|
|
gchar *brush = NULL;
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-07-13 21:27:47 +08:00
|
|
|
if (brush_dont_update)
|
2004-07-06 00:50:46 +08:00
|
|
|
goto cleanup;
|
2004-01-27 09:44:55 +08:00
|
|
|
|
2004-07-13 21:27:47 +08:00
|
|
|
if (brush_from_file == 0)
|
2004-01-27 09:44:55 +08:00
|
|
|
{
|
2004-07-13 21:27:47 +08:00
|
|
|
update_brush_preview (NULL);
|
2004-07-06 00:50:46 +08:00
|
|
|
goto cleanup;
|
2004-01-27 09:44:55 +08:00
|
|
|
}
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2002-12-18 04:18:16 +08:00
|
|
|
if (gtk_tree_selection_get_selected (selection, &model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &brush, -1);
|
|
|
|
|
2004-07-06 00:50:46 +08:00
|
|
|
/* Check if the same brush was selected twice, and if so
|
|
|
|
* break. Otherwise, the brush gamma and stuff would have been
|
|
|
|
* reset.
|
|
|
|
* */
|
|
|
|
if (last_selected_brush == NULL)
|
|
|
|
{
|
2004-09-03 07:28:44 +08:00
|
|
|
last_selected_brush = g_strdup (brush);
|
2004-07-06 00:50:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!strcmp (last_selected_brush, brush))
|
2004-07-31 16:42:44 +08:00
|
|
|
{
|
|
|
|
if (!force)
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2004-07-06 00:50:46 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (last_selected_brush);
|
2004-09-03 07:28:44 +08:00
|
|
|
last_selected_brush = g_strdup (brush);
|
2004-07-06 00:50:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-13 21:27:47 +08:00
|
|
|
brush_dont_update = TRUE;
|
2011-10-02 20:09:45 +08:00
|
|
|
gtk_adjustment_set_value (brush_gamma_adjust, 1.0);
|
2020-11-06 00:37:15 +08:00
|
|
|
gimp_label_spin_set_value (GIMP_LABEL_SPIN (brush_aspect_scale), 0.0);
|
2004-07-13 21:27:47 +08:00
|
|
|
brush_dont_update = FALSE;
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-01-27 09:44:55 +08:00
|
|
|
if (brush)
|
|
|
|
{
|
2004-07-06 00:50:46 +08:00
|
|
|
fname = g_build_filename ("Brushes", brush, NULL);
|
2004-01-27 09:44:55 +08:00
|
|
|
|
2004-07-30 02:41:47 +08:00
|
|
|
g_strlcpy (pcvals.selected_brush,
|
|
|
|
fname, sizeof (pcvals.selected_brush));
|
2003-11-10 06:44:45 +08:00
|
|
|
|
2004-07-13 21:27:47 +08:00
|
|
|
update_brush_preview (fname);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-01-27 09:44:55 +08:00
|
|
|
}
|
2002-12-18 04:18:16 +08:00
|
|
|
}
|
2004-07-06 00:50:46 +08:00
|
|
|
cleanup:
|
|
|
|
g_free (fname);
|
|
|
|
g_free (brush);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
static void
|
2004-07-13 21:27:47 +08:00
|
|
|
brush_select_file (GtkTreeSelection *selection, gpointer data)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-07-13 21:27:47 +08:00
|
|
|
brush_from_file = 1;
|
2004-07-08 23:55:14 +08:00
|
|
|
preset_save_button_set_sensitive (TRUE);
|
2004-07-31 16:42:44 +08:00
|
|
|
brush_select (selection, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
brush_preview_size_allocate (GtkWidget *preview)
|
|
|
|
{
|
|
|
|
GtkTreeSelection *selection;
|
2004-09-03 07:28:44 +08:00
|
|
|
|
2004-07-31 16:42:44 +08:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (brush_list));
|
|
|
|
brush_select (selection, TRUE);
|
2002-12-18 04:18:16 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
static void
|
2020-11-06 00:37:15 +08:00
|
|
|
brush_aspect_adjust_cb (GimpLabelSpin *scale,
|
|
|
|
gdouble *value)
|
2002-12-18 04:18:16 +08:00
|
|
|
{
|
2020-10-31 10:44:21 +08:00
|
|
|
gimpressionist_scale_entry_update_double (scale, value);
|
2004-07-30 02:41:47 +08:00
|
|
|
update_brush_preview (pcvals.selected_brush);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:39:22 +08:00
|
|
|
void
|
2004-09-03 07:28:44 +08:00
|
|
|
create_brushpage (GtkNotebook *notebook)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-09-03 07:28:44 +08:00
|
|
|
GtkWidget *box1, *box2, *box3, *thispage;
|
|
|
|
GtkWidget *view;
|
2018-05-06 05:37:02 +08:00
|
|
|
GtkWidget *tmpw, *grid;
|
2004-09-03 07:28:44 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *combo;
|
|
|
|
GtkWidget *label;
|
2004-05-25 23:27:46 +08:00
|
|
|
GtkSizeGroup *group;
|
2002-12-18 04:18:16 +08:00
|
|
|
GtkTreeSelection *selection;
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2002-11-20 04:25:57 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (_("_Brush"));
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
thispage = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (thispage), 12);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_widget_show (thispage);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (thispage), box1, TRUE,TRUE,0);
|
1999-08-27 06:29:37 +08:00
|
|
|
gtk_widget_show (box1);
|
|
|
|
|
2004-07-14 21:28:01 +08:00
|
|
|
view = create_one_column_list (box1, brush_select_file);
|
2004-07-13 21:27:47 +08:00
|
|
|
brush_list = view;
|
2004-09-03 07:28:44 +08:00
|
|
|
brush_list_store =
|
2004-07-13 21:27:47 +08:00
|
|
|
GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
|
2004-09-03 07:28:44 +08:00
|
|
|
|
2002-12-18 04:18:16 +08:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
|
1999-08-27 06:29:37 +08:00
|
|
|
gtk_widget_show (box2);
|
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_widget_show (frame);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-07-31 16:42:44 +08:00
|
|
|
brush_preview = tmpw = gimp_preview_area_new ();
|
|
|
|
gtk_widget_set_size_request (brush_preview, 100, 100);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), tmpw);
|
|
|
|
gtk_widget_show (tmpw);
|
2004-07-31 16:42:44 +08:00
|
|
|
g_signal_connect (brush_preview, "size-allocate",
|
2004-09-03 07:28:44 +08:00
|
|
|
G_CALLBACK (brush_preview_size_allocate), NULL);
|
2004-05-25 23:27:46 +08:00
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
box3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (box2), box3, FALSE, FALSE,0);
|
|
|
|
gtk_widget_show (box3);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
tmpw = gtk_label_new (_("Gamma:"));
|
2016-09-09 01:11:20 +08:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (tmpw), 0.0);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box3), tmpw, FALSE, FALSE,0);
|
1999-08-27 06:29:37 +08:00
|
|
|
gtk_widget_show (tmpw);
|
|
|
|
|
2018-06-25 00:15:16 +08:00
|
|
|
brush_gamma_adjust = gtk_adjustment_new (pcvals.brushgamma,
|
|
|
|
0.5, 3.0, 0.1, 0.1, 1.0);
|
2011-10-02 20:09:45 +08:00
|
|
|
tmpw = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, brush_gamma_adjust);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (tmpw), 100, 30);
|
1999-08-27 06:29:37 +08:00
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (tmpw), FALSE);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_scale_set_digits (GTK_SCALE (tmpw), 2);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box3), tmpw, FALSE, FALSE, 0);
|
1999-08-27 06:29:37 +08:00
|
|
|
gtk_widget_show (tmpw);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect_swapped (brush_gamma_adjust, "value-changed",
|
2004-09-03 07:28:44 +08:00
|
|
|
G_CALLBACK (update_brush_preview),
|
|
|
|
pcvals.selected_brush);
|
2002-12-18 04:18:16 +08:00
|
|
|
|
2003-11-10 06:44:45 +08:00
|
|
|
gimp_help_set_help_data
|
2003-10-25 04:57:29 +08:00
|
|
|
(tmpw, _("Changes the gamma (brightness) of the selected brush"), NULL);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
box3 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (thispage), box3, FALSE, FALSE,0);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_widget_show (box3);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
tmpw = gtk_label_new (_("Select:"));
|
2016-09-09 01:11:20 +08:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (tmpw), 0.0);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box3), tmpw, FALSE, FALSE, 0);
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_widget_show (tmpw);
|
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_size_group_add_widget (group, tmpw);
|
|
|
|
g_object_unref (group);
|
|
|
|
|
2019-08-08 05:16:25 +08:00
|
|
|
combo = gimp_drawable_combo_box_new (validdrawable, NULL, NULL);
|
2004-04-22 07:09:16 +08:00
|
|
|
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), -1,
|
|
|
|
G_CALLBACK (brushdmenuselect),
|
2019-08-08 06:22:15 +08:00
|
|
|
NULL, NULL);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box3), combo, TRUE, TRUE, 0);
|
2004-04-22 07:09:16 +08:00
|
|
|
gtk_widget_show (combo);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2017-03-05 23:01:59 +08:00
|
|
|
tmpw = gtk_button_new_with_mnemonic (_("Save _as"));
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box3),tmpw, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect (tmpw, "clicked", G_CALLBACK (savebrush), NULL);
|
|
|
|
gtk_widget_show (tmpw);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2018-05-06 05:37:02 +08:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (thispage), grid, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (grid);
|
2002-11-20 04:25:57 +08:00
|
|
|
|
2020-10-31 10:44:21 +08:00
|
|
|
brush_aspect_scale =
|
2020-11-01 09:35:03 +08:00
|
|
|
gimp_scale_entry_new (_("Aspect ratio:"), pcvals.brush_aspect, -1.0, 1.0, 2);
|
2020-10-31 10:44:21 +08:00
|
|
|
gimp_help_set_help_data (brush_aspect_scale,
|
|
|
|
_("Specifies the aspect ratio of the brush"),
|
|
|
|
NULL);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_size_group_add_widget (group,
|
2020-11-06 00:37:15 +08:00
|
|
|
gimp_labeled_get_label (GIMP_LABELED (brush_aspect_scale)));
|
2020-10-31 10:44:21 +08:00
|
|
|
g_signal_connect (brush_aspect_scale, "value-changed",
|
|
|
|
G_CALLBACK (brush_aspect_adjust_cb),
|
2018-06-25 00:15:16 +08:00
|
|
|
&pcvals.brush_aspect);
|
2020-10-31 10:44:21 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), brush_aspect_scale, 0, 0, 3, 1);
|
|
|
|
gtk_widget_show (brush_aspect_scale);
|
|
|
|
|
|
|
|
brush_relief_scale =
|
2020-11-01 09:35:03 +08:00
|
|
|
gimp_scale_entry_new (_("Relief:"), pcvals.brush_relief, 0.0, 100.0, 1);
|
2020-10-31 10:44:21 +08:00
|
|
|
gimp_help_set_help_data (brush_relief_scale,
|
|
|
|
_("Specifies the amount of embossing to apply to the image (in percent)"),
|
|
|
|
NULL);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_size_group_add_widget (group,
|
2020-11-06 00:37:15 +08:00
|
|
|
gimp_labeled_get_label (GIMP_LABELED (brush_relief_scale)));
|
2020-10-31 10:44:21 +08:00
|
|
|
g_signal_connect (brush_relief_scale, "value-changed",
|
|
|
|
G_CALLBACK (gimpressionist_scale_entry_update_double),
|
2004-07-30 02:41:47 +08:00
|
|
|
&pcvals.brush_relief);
|
2020-10-31 10:44:21 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), brush_relief_scale, 0, 1, 3, 1);
|
|
|
|
gtk_widget_show (brush_relief_scale);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-07-31 16:42:44 +08:00
|
|
|
brush_select (selection, FALSE);
|
2004-07-30 02:41:47 +08:00
|
|
|
readdirintolist ("Brushes", view, pcvals.selected_brush);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2006-01-17 20:43:50 +08:00
|
|
|
/*
|
2004-07-06 00:50:46 +08:00
|
|
|
* This is so the "changed signal won't get sent to the brushes' list
|
|
|
|
* and reset the gamma and stuff.
|
|
|
|
* */
|
2004-07-13 21:27:47 +08:00
|
|
|
gtk_widget_grab_focus (brush_list);
|
2004-07-06 00:50:46 +08:00
|
|
|
|
2002-11-20 04:25:57 +08:00
|
|
|
gtk_notebook_append_page_menu (notebook, thispage, label, NULL);
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
2004-07-13 21:27:47 +08:00
|
|
|
|