mirror of https://github.com/GNOME/gimp.git
app/brush_edit.[ch] app/brush_header.h app/gimpbrush.[ch]
2000-09-29 Michael Natterer <mitch@gimp.org> * app/brush_edit.[ch] * app/brush_header.h * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushlist.[ch] * app/gimpbrushpipe.[ch] * app/gimpcontext.h * app/gimplist.[ch] * app/gimpobject.[ch] * app/gimpset.[ch] * app/gimpsignal.[ch] * app/parasitelist.h: Lotsa fixes in the brush referencing code and cleanups in many GtkObjects: - Reference brushes correctly (call gtk_object_sink() after adding them to the brush list). Don't crash when renaming a brush multiple times. - Replaced all gtk_object_destroy() with gtk_object_unref|sink(). - Removed the "Fake Gimp object system" (gimp_object_destroy() et.al.) all over the place (while it's a good idea to have a common Gimp base object, it's totally useless to try to imitate Gtk's object system). - s/sz_BrushHeader/sizeof(BrushHeader)/g - And of course various indentation and coding style paranoia changes in all files I visited.
This commit is contained in:
parent
48e3c38f4a
commit
f38cdf123c
28
ChangeLog
28
ChangeLog
|
@ -1,3 +1,31 @@
|
|||
2000-09-29 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/brush_edit.[ch]
|
||||
* app/brush_header.h
|
||||
* app/gimpbrush.[ch]
|
||||
* app/gimpbrushgenerated.[ch]
|
||||
* app/gimpbrushlist.[ch]
|
||||
* app/gimpbrushpipe.[ch]
|
||||
* app/gimpcontext.h
|
||||
* app/gimplist.[ch]
|
||||
* app/gimpobject.[ch]
|
||||
* app/gimpset.[ch]
|
||||
* app/gimpsignal.[ch]
|
||||
* app/parasitelist.h: Lotsa fixes in the brush referencing code
|
||||
and cleanups in many GtkObjects:
|
||||
|
||||
- Reference brushes correctly (call gtk_object_sink() after adding
|
||||
them to the brush list). Don't crash when renaming a brush
|
||||
multiple times.
|
||||
- Replaced all gtk_object_destroy() with gtk_object_unref|sink().
|
||||
- Removed the "Fake Gimp object system" (gimp_object_destroy() et.al.)
|
||||
all over the place (while it's a good idea to have a common Gimp
|
||||
base object, it's totally useless to try to imitate Gtk's object
|
||||
system).
|
||||
- s/sz_BrushHeader/sizeof(BrushHeader)/g
|
||||
- And of course various indentation and coding style paranoia changes
|
||||
in all files I visited.
|
||||
|
||||
Fri Sep 29 03:10:10 CEST 2000 Daniel Egger <egger@suse.de>
|
||||
|
||||
* app/brightness_contrast.c:
|
||||
|
|
177
app/brush_edit.c
177
app/brush_edit.c
|
@ -17,7 +17,9 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "appenv.h"
|
||||
|
@ -25,45 +27,50 @@
|
|||
#include "brush_edit.h"
|
||||
#include "gimpui.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libgimp/gimpmath.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
static void brush_edit_close_callback (GtkWidget *, gpointer);
|
||||
static gint brush_edit_preview_resize (GtkWidget *widget, GdkEvent *event,
|
||||
|
||||
static void brush_edit_close_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static gint brush_edit_preview_resize (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
BrushEditGeneratedWindow *begw);
|
||||
|
||||
|
||||
static void
|
||||
update_brush_callback (GtkAdjustment *adjustment,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
if (begw->brush &&
|
||||
((begw->radius_data->value
|
||||
!= gimp_brush_generated_get_radius(begw->brush))
|
||||
!= gimp_brush_generated_get_radius (begw->brush))
|
||||
|| (begw->hardness_data->value
|
||||
!= gimp_brush_generated_get_hardness(begw->brush))
|
||||
!= gimp_brush_generated_get_hardness (begw->brush))
|
||||
|| (begw->aspect_ratio_data->value
|
||||
!= gimp_brush_generated_get_aspect_ratio(begw->brush))
|
||||
!= gimp_brush_generated_get_aspect_ratio (begw->brush))
|
||||
|| (begw->angle_data->value
|
||||
!=gimp_brush_generated_get_angle(begw->brush))))
|
||||
{
|
||||
gimp_brush_generated_freeze (begw->brush);
|
||||
gimp_brush_generated_set_radius (begw->brush,
|
||||
begw->radius_data->value);
|
||||
gimp_brush_generated_set_hardness (begw->brush,
|
||||
begw->hardness_data->value);
|
||||
gimp_brush_generated_set_aspect_ratio (begw->brush,
|
||||
begw->aspect_ratio_data->value);
|
||||
gimp_brush_generated_set_angle (begw->brush,
|
||||
begw->angle_data->value);
|
||||
gimp_brush_generated_thaw (begw->brush);
|
||||
}
|
||||
!= gimp_brush_generated_get_angle (begw->brush))))
|
||||
{
|
||||
gimp_brush_generated_freeze (begw->brush);
|
||||
gimp_brush_generated_set_radius (begw->brush,
|
||||
begw->radius_data->value);
|
||||
gimp_brush_generated_set_hardness (begw->brush,
|
||||
begw->hardness_data->value);
|
||||
gimp_brush_generated_set_aspect_ratio (begw->brush,
|
||||
begw->aspect_ratio_data->value);
|
||||
gimp_brush_generated_set_angle (begw->brush,
|
||||
begw->angle_data->value);
|
||||
gimp_brush_generated_thaw (begw->brush);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
brush_edit_clear_preview (BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
guchar * buf;
|
||||
gint i;
|
||||
guchar *buf;
|
||||
gint i;
|
||||
|
||||
buf = g_new (guchar, begw->preview->requisition.width);
|
||||
|
||||
|
@ -126,7 +133,7 @@ brush_edit_brush_dirty_callback (GimpBrush *brush,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
brush_renamed_callback (GtkWidget *widget,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
|
@ -138,15 +145,20 @@ void
|
|||
brush_edit_generated_set_brush (BrushEditGeneratedWindow *begw,
|
||||
GimpBrush *gbrush)
|
||||
{
|
||||
GimpBrushGenerated *brush = 0;
|
||||
if (begw->brush == (GimpBrushGenerated*)gbrush)
|
||||
GimpBrushGenerated *brush = NULL;
|
||||
|
||||
g_return_if_fail (begw != NULL);
|
||||
|
||||
if (begw->brush == (GimpBrushGenerated *) gbrush)
|
||||
return;
|
||||
if (begw && begw->brush)
|
||||
|
||||
if (begw->brush)
|
||||
{
|
||||
gtk_signal_disconnect_by_data (GTK_OBJECT (begw->brush), begw);
|
||||
gtk_object_unref (GTK_OBJECT (begw->brush));
|
||||
begw->brush = NULL;
|
||||
}
|
||||
|
||||
if (!gbrush || !GIMP_IS_BRUSH_GENERATED (gbrush))
|
||||
{
|
||||
begw->brush = NULL;
|
||||
|
@ -154,29 +166,30 @@ brush_edit_generated_set_brush (BrushEditGeneratedWindow *begw,
|
|||
gtk_widget_hide (begw->shell);
|
||||
return;
|
||||
}
|
||||
|
||||
brush = GIMP_BRUSH_GENERATED (gbrush);
|
||||
if (begw)
|
||||
{
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "dirty",
|
||||
GTK_SIGNAL_FUNC (brush_edit_brush_dirty_callback),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "rename",
|
||||
GTK_SIGNAL_FUNC (brush_renamed_callback),
|
||||
begw);
|
||||
begw->brush = NULL;
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->radius_data),
|
||||
gimp_brush_generated_get_radius (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->hardness_data),
|
||||
gimp_brush_generated_get_hardness (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->angle_data),
|
||||
gimp_brush_generated_get_angle (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->aspect_ratio_data),
|
||||
gimp_brush_generated_get_aspect_ratio (brush));
|
||||
gtk_entry_set_text (GTK_ENTRY (begw->name), gimp_brush_get_name (gbrush));
|
||||
begw->brush = brush;
|
||||
gtk_object_ref (GTK_OBJECT (begw->brush));
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (brush), begw);
|
||||
}
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "dirty",
|
||||
GTK_SIGNAL_FUNC (brush_edit_brush_dirty_callback),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "rename",
|
||||
GTK_SIGNAL_FUNC (brush_renamed_callback),
|
||||
begw);
|
||||
|
||||
begw->brush = NULL;
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->radius_data),
|
||||
gimp_brush_generated_get_radius (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->hardness_data),
|
||||
gimp_brush_generated_get_hardness (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->angle_data),
|
||||
gimp_brush_generated_get_angle (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->aspect_ratio_data),
|
||||
gimp_brush_generated_get_aspect_ratio (brush));
|
||||
gtk_entry_set_text (GTK_ENTRY (begw->name), gimp_brush_get_name (gbrush));
|
||||
begw->brush = brush;
|
||||
|
||||
gtk_object_ref (GTK_OBJECT (begw->brush));
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (brush), begw);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -184,6 +197,7 @@ name_changed_func (GtkWidget *widget,
|
|||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
gchar *entry_text;
|
||||
|
||||
entry_text = gtk_entry_get_text (GTK_ENTRY (widget));
|
||||
gimp_brush_set_name (GIMP_BRUSH (begw->brush), entry_text);
|
||||
}
|
||||
|
@ -204,8 +218,7 @@ brush_edit_generated_new (void)
|
|||
GtkWidget *slider;
|
||||
GtkWidget *table;
|
||||
|
||||
begw = g_new (BrushEditGeneratedWindow, 1);
|
||||
begw->brush = NULL;
|
||||
begw = g_new0 (BrushEditGeneratedWindow, 1);
|
||||
|
||||
begw->shell = gimp_dialog_new (_("Brush Editor"), "generated_brush_editor",
|
||||
gimp_standard_help_func,
|
||||
|
@ -222,23 +235,18 @@ brush_edit_generated_new (void)
|
|||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
||||
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (begw->shell)->vbox), vbox);
|
||||
|
||||
/* Populate the window with some widgets */
|
||||
|
||||
/* table for brush controlls */
|
||||
table = gtk_table_new (5, 4, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
|
||||
|
||||
/* Brush's name */
|
||||
begw->name = gtk_entry_new();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->name, TRUE, TRUE, 0);
|
||||
|
||||
begw->name = gtk_entry_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->name, FALSE, FALSE, 0);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (begw->name), "activate",
|
||||
(GtkSignalFunc) name_changed_func,
|
||||
GTK_SIGNAL_FUNC (name_changed_func),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->name), "focus_out_event",
|
||||
(GtkSignalFunc) focus_out_func,
|
||||
GTK_SIGNAL_FUNC (focus_out_func),
|
||||
begw);
|
||||
gtk_widget_show(begw->name);
|
||||
|
||||
gtk_widget_show (begw->name);
|
||||
|
||||
/* brush's preview widget w/frame */
|
||||
begw->frame = gtk_frame_new (NULL);
|
||||
|
@ -247,21 +255,23 @@ brush_edit_generated_new (void)
|
|||
|
||||
begw->preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview), 125, 100);
|
||||
gtk_signal_connect_after (GTK_OBJECT(begw->frame), "size_allocate",
|
||||
(GtkSignalFunc) brush_edit_preview_resize,
|
||||
begw);
|
||||
gtk_signal_connect_after (GTK_OBJECT (begw->frame), "size_allocate",
|
||||
GTK_SIGNAL_FUNC (brush_edit_preview_resize),
|
||||
begw);
|
||||
gtk_container_add (GTK_CONTAINER (begw->frame), begw->preview);
|
||||
|
||||
gtk_widget_show(begw->preview);
|
||||
gtk_widget_show(begw->frame);
|
||||
gtk_widget_show (begw->preview);
|
||||
gtk_widget_show (begw->frame);
|
||||
|
||||
/* table for sliders/labels */
|
||||
begw->scale_label = gtk_label_new ("-1:1");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->scale_label, FALSE, FALSE, 0);
|
||||
begw->scale = -1;
|
||||
gtk_widget_show (begw->scale_label);
|
||||
|
||||
begw->scale = -1;
|
||||
|
||||
/* table for sliders/labels */
|
||||
table = gtk_table_new(2, 4, FALSE);
|
||||
table = gtk_table_new (4, 2, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
||||
|
||||
/* brush radius scale */
|
||||
|
@ -271,7 +281,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->radius_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
||||
_("Radius:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -283,7 +294,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->hardness_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
||||
_("Hardness:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -295,7 +307,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->aspect_ratio_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
|
||||
_("Aspect Ratio:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -307,7 +320,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->angle_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
|
||||
_("Angle:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -327,14 +341,15 @@ brush_edit_preview_resize (GtkWidget *widget,
|
|||
GdkEvent *event,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview),
|
||||
widget->allocation.width - 4,
|
||||
widget->allocation.height - 4);
|
||||
|
||||
/* update the display */
|
||||
if (begw->brush)
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (begw->brush), begw);
|
||||
return FALSE;
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview),
|
||||
widget->allocation.width - 4,
|
||||
widget->allocation.height - 4);
|
||||
|
||||
/* update the display */
|
||||
if (begw->brush)
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (begw->brush), begw);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __BRUSH_EDIT_H__
|
||||
#define __BRUSH_EDIT_H__
|
||||
|
||||
|
@ -26,20 +27,21 @@ typedef struct _BrushEditGeneratedWindow BrushEditGeneratedWindow;
|
|||
|
||||
struct _BrushEditGeneratedWindow
|
||||
{
|
||||
GtkWidget *shell;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *scale_label;
|
||||
GtkWidget *options_box;
|
||||
GtkWidget *name;
|
||||
GtkWidget *shell;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *scale_label;
|
||||
GtkWidget *options_box;
|
||||
GtkWidget *name;
|
||||
GtkAdjustment *radius_data;
|
||||
GtkAdjustment *hardness_data;
|
||||
GtkAdjustment *angle_data;
|
||||
GtkAdjustment *aspect_ratio_data;
|
||||
|
||||
/* Brush preview */
|
||||
GtkWidget *brush_preview;
|
||||
GtkWidget *brush_preview;
|
||||
GimpBrushGenerated *brush;
|
||||
gint scale;
|
||||
gint scale;
|
||||
};
|
||||
|
||||
BrushEditGeneratedWindow * brush_edit_generated_new (void);
|
||||
|
|
|
@ -15,30 +15,30 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __BRUSH_HEADER_H__
|
||||
#define __BRUSH_HEADER_H__
|
||||
|
||||
typedef struct _BrushHeader BrushHeader;
|
||||
|
||||
#define GBRUSH_FILE_VERSION 2
|
||||
#define GBRUSH_MAGIC (('G' << 24) + ('I' << 16) + ('M' << 8) + ('P' << 0))
|
||||
#define sz_BrushHeader (sizeof (BrushHeader))
|
||||
|
||||
/* All field entries are MSB */
|
||||
|
||||
typedef struct _BrushHeader BrushHeader;
|
||||
|
||||
struct _BrushHeader
|
||||
{
|
||||
unsigned int header_size; /* header_size = sz_BrushHeader + brush name */
|
||||
unsigned int version; /* brush file version # */
|
||||
unsigned int width; /* width of brush */
|
||||
unsigned int height; /* height of brush */
|
||||
unsigned int bytes; /* depth of brush in bytes--always 1 */
|
||||
unsigned int magic_number;/* GIMP brush magic number */
|
||||
unsigned int spacing; /* brush spacing */
|
||||
guint header_size; /* header_size = sizeof (BrushHeader) + brush name */
|
||||
guint version; /* brush file version # */
|
||||
guint width; /* width of brush */
|
||||
guint height; /* height of brush */
|
||||
guint bytes; /* depth of brush in bytes--always 1 */
|
||||
guint magic_number; /* GIMP brush magic number */
|
||||
guint spacing; /* brush spacing */
|
||||
};
|
||||
|
||||
/* In a brush file, next comes the brush name, null-terminated. After that
|
||||
* comes the brush data--width * height * bytes bytes of it...
|
||||
*/
|
||||
|
||||
#endif /* __BRUSH_HEADER_H__ */
|
||||
#endif /* ! __BRUSH_HEADER_H__ */
|
||||
|
|
|
@ -15,30 +15,30 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __BRUSH_HEADER_H__
|
||||
#define __BRUSH_HEADER_H__
|
||||
|
||||
typedef struct _BrushHeader BrushHeader;
|
||||
|
||||
#define GBRUSH_FILE_VERSION 2
|
||||
#define GBRUSH_MAGIC (('G' << 24) + ('I' << 16) + ('M' << 8) + ('P' << 0))
|
||||
#define sz_BrushHeader (sizeof (BrushHeader))
|
||||
|
||||
/* All field entries are MSB */
|
||||
|
||||
typedef struct _BrushHeader BrushHeader;
|
||||
|
||||
struct _BrushHeader
|
||||
{
|
||||
unsigned int header_size; /* header_size = sz_BrushHeader + brush name */
|
||||
unsigned int version; /* brush file version # */
|
||||
unsigned int width; /* width of brush */
|
||||
unsigned int height; /* height of brush */
|
||||
unsigned int bytes; /* depth of brush in bytes--always 1 */
|
||||
unsigned int magic_number;/* GIMP brush magic number */
|
||||
unsigned int spacing; /* brush spacing */
|
||||
guint header_size; /* header_size = sizeof (BrushHeader) + brush name */
|
||||
guint version; /* brush file version # */
|
||||
guint width; /* width of brush */
|
||||
guint height; /* height of brush */
|
||||
guint bytes; /* depth of brush in bytes--always 1 */
|
||||
guint magic_number; /* GIMP brush magic number */
|
||||
guint spacing; /* brush spacing */
|
||||
};
|
||||
|
||||
/* In a brush file, next comes the brush name, null-terminated. After that
|
||||
* comes the brush data--width * height * bytes bytes of it...
|
||||
*/
|
||||
|
||||
#endif /* __BRUSH_HEADER_H__ */
|
||||
#endif /* ! __BRUSH_HEADER_H__ */
|
||||
|
|
|
@ -47,15 +47,14 @@ gimp_brush_destroy (GtkObject *object)
|
|||
{
|
||||
GimpBrush *brush = GIMP_BRUSH (object);
|
||||
|
||||
if (brush->filename)
|
||||
g_free (brush->filename);
|
||||
if (brush->name)
|
||||
g_free (brush->name);
|
||||
g_free (brush->filename);
|
||||
g_free (brush->name);
|
||||
|
||||
if (brush->mask)
|
||||
temp_buf_free (brush->mask);
|
||||
|
||||
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
||||
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -116,6 +115,7 @@ gimp_brush_get_type (void)
|
|||
/* reserved_2 */ NULL,
|
||||
(GtkClassInitFunc) NULL
|
||||
};
|
||||
|
||||
type = gtk_type_unique (gimp_object_get_type (), &info);
|
||||
}
|
||||
return type;
|
||||
|
@ -126,7 +126,10 @@ gimp_brush_new (gchar *filename)
|
|||
{
|
||||
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
|
||||
|
||||
return (gimp_brush_load (brush, filename)? brush : NULL);
|
||||
if (gimp_brush_load (brush, filename))
|
||||
return brush;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GimpBrush *
|
||||
|
@ -144,6 +147,7 @@ gimp_brush_want_null_motion (PaintCore *paint_core)
|
|||
TempBuf *
|
||||
gimp_brush_get_mask (GimpBrush *brush)
|
||||
{
|
||||
g_return_val_if_fail (brush != NULL, NULL);
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
|
||||
|
||||
return brush->mask;
|
||||
|
@ -152,6 +156,7 @@ gimp_brush_get_mask (GimpBrush *brush)
|
|||
gchar *
|
||||
gimp_brush_get_name (GimpBrush *brush)
|
||||
{
|
||||
g_return_val_if_fail (brush != NULL, NULL);
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
|
||||
|
||||
return brush->name;
|
||||
|
@ -161,10 +166,12 @@ void
|
|||
gimp_brush_set_name (GimpBrush *brush,
|
||||
gchar *name)
|
||||
{
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH (brush));
|
||||
|
||||
if (strcmp (brush->name, name) == 0)
|
||||
return;
|
||||
|
||||
if (brush->name)
|
||||
g_free (brush->name);
|
||||
brush->name = g_strdup (name);
|
||||
|
@ -195,20 +202,23 @@ gboolean
|
|||
gimp_brush_load (GimpBrush *brush,
|
||||
gchar *filename)
|
||||
{
|
||||
FILE * fp;
|
||||
FILE *fp;
|
||||
|
||||
brush->filename = g_strdup (filename);
|
||||
|
||||
/* Open the requested file */
|
||||
if (! (fp = fopen (filename, "rb")))
|
||||
{
|
||||
gimp_object_destroy (brush);
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! gimp_brush_load_brush (brush, fp, filename))
|
||||
{
|
||||
fclose (fp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gimp_brush_load_brush (brush, fp, filename))
|
||||
return FALSE;
|
||||
|
||||
/* Clean up */
|
||||
fclose (fp);
|
||||
|
||||
|
@ -219,39 +229,37 @@ gimp_brush_load (GimpBrush *brush,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
gboolean
|
||||
gimp_brush_load_brush (GimpBrush *brush,
|
||||
FILE *fp,
|
||||
gchar *filename)
|
||||
{
|
||||
gint bn_size;
|
||||
guchar buf [sz_BrushHeader];
|
||||
guchar buf [sizeof (BrushHeader)];
|
||||
BrushHeader header;
|
||||
guint *hp;
|
||||
gint i;
|
||||
|
||||
/* Read in the header size */
|
||||
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
|
||||
if ((fread (buf, 1, sizeof (BrushHeader), fp)) < sizeof (BrushHeader))
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* rearrange the bytes in each unsigned int */
|
||||
hp = (guint *) &header;
|
||||
for (i = 0; i < (sz_BrushHeader / 4); i++)
|
||||
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
|
||||
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
|
||||
for (i = 0; i < (sizeof (BrushHeader) / 4); i++)
|
||||
hp [i] = ((buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
|
||||
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]));
|
||||
|
||||
/* Check for correct file format */
|
||||
if (header.magic_number != GBRUSH_MAGIC)
|
||||
{
|
||||
if (header.version != 1)
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,19 +273,20 @@ gimp_brush_load_brush (GimpBrush *brush,
|
|||
}
|
||||
|
||||
/* Read in the brush name */
|
||||
if ((bn_size = (header.header_size - sz_BrushHeader)))
|
||||
{
|
||||
brush->name = g_new (gchar, bn_size);
|
||||
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
|
||||
{
|
||||
g_message (_("Error in GIMP brush file...aborting."));
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((bn_size = (header.header_size - sizeof (BrushHeader))))
|
||||
{
|
||||
brush->name = g_new (gchar, bn_size);
|
||||
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
|
||||
{
|
||||
g_message (_("Error in GIMP brush file...aborting."));
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
brush->name = g_strdup (_("Unnamed"));
|
||||
{
|
||||
brush->name = g_strdup (_("Unnamed"));
|
||||
}
|
||||
|
||||
switch (header.version)
|
||||
{
|
||||
|
@ -293,16 +302,18 @@ gimp_brush_load_brush (GimpBrush *brush,
|
|||
brush->y_axis.x = 0.0;
|
||||
brush->y_axis.y = header.height / 2.0;
|
||||
/* Read the brush mask data */
|
||||
if ((fread (temp_buf_data (brush->mask), 1, header.width * header.height,
|
||||
fp)) < header.width * header.height)
|
||||
if ((fread (temp_buf_data (brush->mask),
|
||||
1, header.width * header.height, fp)) <
|
||||
header.width * header.height)
|
||||
g_message (_("GIMP brush file appears to be truncated."));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
|
||||
header.version, filename);
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
return 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -47,15 +47,14 @@ gimp_brush_destroy (GtkObject *object)
|
|||
{
|
||||
GimpBrush *brush = GIMP_BRUSH (object);
|
||||
|
||||
if (brush->filename)
|
||||
g_free (brush->filename);
|
||||
if (brush->name)
|
||||
g_free (brush->name);
|
||||
g_free (brush->filename);
|
||||
g_free (brush->name);
|
||||
|
||||
if (brush->mask)
|
||||
temp_buf_free (brush->mask);
|
||||
|
||||
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
||||
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -116,6 +115,7 @@ gimp_brush_get_type (void)
|
|||
/* reserved_2 */ NULL,
|
||||
(GtkClassInitFunc) NULL
|
||||
};
|
||||
|
||||
type = gtk_type_unique (gimp_object_get_type (), &info);
|
||||
}
|
||||
return type;
|
||||
|
@ -126,7 +126,10 @@ gimp_brush_new (gchar *filename)
|
|||
{
|
||||
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
|
||||
|
||||
return (gimp_brush_load (brush, filename)? brush : NULL);
|
||||
if (gimp_brush_load (brush, filename))
|
||||
return brush;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GimpBrush *
|
||||
|
@ -144,6 +147,7 @@ gimp_brush_want_null_motion (PaintCore *paint_core)
|
|||
TempBuf *
|
||||
gimp_brush_get_mask (GimpBrush *brush)
|
||||
{
|
||||
g_return_val_if_fail (brush != NULL, NULL);
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
|
||||
|
||||
return brush->mask;
|
||||
|
@ -152,6 +156,7 @@ gimp_brush_get_mask (GimpBrush *brush)
|
|||
gchar *
|
||||
gimp_brush_get_name (GimpBrush *brush)
|
||||
{
|
||||
g_return_val_if_fail (brush != NULL, NULL);
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
|
||||
|
||||
return brush->name;
|
||||
|
@ -161,10 +166,12 @@ void
|
|||
gimp_brush_set_name (GimpBrush *brush,
|
||||
gchar *name)
|
||||
{
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH (brush));
|
||||
|
||||
if (strcmp (brush->name, name) == 0)
|
||||
return;
|
||||
|
||||
if (brush->name)
|
||||
g_free (brush->name);
|
||||
brush->name = g_strdup (name);
|
||||
|
@ -195,20 +202,23 @@ gboolean
|
|||
gimp_brush_load (GimpBrush *brush,
|
||||
gchar *filename)
|
||||
{
|
||||
FILE * fp;
|
||||
FILE *fp;
|
||||
|
||||
brush->filename = g_strdup (filename);
|
||||
|
||||
/* Open the requested file */
|
||||
if (! (fp = fopen (filename, "rb")))
|
||||
{
|
||||
gimp_object_destroy (brush);
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! gimp_brush_load_brush (brush, fp, filename))
|
||||
{
|
||||
fclose (fp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gimp_brush_load_brush (brush, fp, filename))
|
||||
return FALSE;
|
||||
|
||||
/* Clean up */
|
||||
fclose (fp);
|
||||
|
||||
|
@ -219,39 +229,37 @@ gimp_brush_load (GimpBrush *brush,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
gboolean
|
||||
gimp_brush_load_brush (GimpBrush *brush,
|
||||
FILE *fp,
|
||||
gchar *filename)
|
||||
{
|
||||
gint bn_size;
|
||||
guchar buf [sz_BrushHeader];
|
||||
guchar buf [sizeof (BrushHeader)];
|
||||
BrushHeader header;
|
||||
guint *hp;
|
||||
gint i;
|
||||
|
||||
/* Read in the header size */
|
||||
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
|
||||
if ((fread (buf, 1, sizeof (BrushHeader), fp)) < sizeof (BrushHeader))
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* rearrange the bytes in each unsigned int */
|
||||
hp = (guint *) &header;
|
||||
for (i = 0; i < (sz_BrushHeader / 4); i++)
|
||||
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
|
||||
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
|
||||
for (i = 0; i < (sizeof (BrushHeader) / 4); i++)
|
||||
hp [i] = ((buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
|
||||
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]));
|
||||
|
||||
/* Check for correct file format */
|
||||
if (header.magic_number != GBRUSH_MAGIC)
|
||||
{
|
||||
if (header.version != 1)
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,19 +273,20 @@ gimp_brush_load_brush (GimpBrush *brush,
|
|||
}
|
||||
|
||||
/* Read in the brush name */
|
||||
if ((bn_size = (header.header_size - sz_BrushHeader)))
|
||||
{
|
||||
brush->name = g_new (gchar, bn_size);
|
||||
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
|
||||
{
|
||||
g_message (_("Error in GIMP brush file...aborting."));
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((bn_size = (header.header_size - sizeof (BrushHeader))))
|
||||
{
|
||||
brush->name = g_new (gchar, bn_size);
|
||||
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
|
||||
{
|
||||
g_message (_("Error in GIMP brush file...aborting."));
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
brush->name = g_strdup (_("Unnamed"));
|
||||
{
|
||||
brush->name = g_strdup (_("Unnamed"));
|
||||
}
|
||||
|
||||
switch (header.version)
|
||||
{
|
||||
|
@ -293,16 +302,18 @@ gimp_brush_load_brush (GimpBrush *brush,
|
|||
brush->y_axis.x = 0.0;
|
||||
brush->y_axis.y = header.height / 2.0;
|
||||
/* Read the brush mask data */
|
||||
if ((fread (temp_buf_data (brush->mask), 1, header.width * header.height,
|
||||
fp)) < header.width * header.height)
|
||||
if ((fread (temp_buf_data (brush->mask),
|
||||
1, header.width * header.height, fp)) <
|
||||
header.width * header.height)
|
||||
g_message (_("GIMP brush file appears to be truncated."));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
|
||||
header.version, filename);
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
return 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef __GIMPBRUSH_H__
|
||||
#define __GIMPBRUSH_H__
|
||||
|
||||
#ifndef __GIMP_BRUSH_H__
|
||||
#define __GIMP_BRUSH_H__
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -41,23 +43,23 @@ struct _GimpBrush
|
|||
|
||||
struct _GimpBrushClass
|
||||
{
|
||||
GimpObjectClass parent_class;
|
||||
GimpObjectClass parent_class;
|
||||
|
||||
GimpBrush * (* select_brush) (PaintCore *paint_core);
|
||||
gboolean (* want_null_motion) (PaintCore *paint_core);
|
||||
GimpBrush * (* select_brush) (PaintCore *paint_core);
|
||||
gboolean (* want_null_motion) (PaintCore *paint_core);
|
||||
};
|
||||
|
||||
#define GIMP_BRUSH_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gimp_brush_get_type(), GimpBrushClass)
|
||||
#define GIMP_TYPE_BRUSH (gimp_brush_get_type ())
|
||||
#define GIMP_BRUSH(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH, GimpBrush))
|
||||
#define GIMP_IS_BRUSH(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH))
|
||||
#define GIMP_BRUSH(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH, GimpBrush))
|
||||
#define GIMP_IS_BRUSH(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH))
|
||||
|
||||
GtkType gimp_brush_get_type (void);
|
||||
GimpBrush * gimp_brush_new (gchar *filename);
|
||||
|
||||
gboolean gimp_brush_load (GimpBrush *brush,
|
||||
gchar *filename);
|
||||
gint gimp_brush_load_brush (GimpBrush *brush,
|
||||
gboolean gimp_brush_load_brush (GimpBrush *brush,
|
||||
FILE *fp,
|
||||
gchar *filename);
|
||||
|
||||
|
@ -71,4 +73,5 @@ gint gimp_brush_get_spacing (GimpBrush *brush);
|
|||
void gimp_brush_set_spacing (GimpBrush *brush,
|
||||
gint spacing);
|
||||
|
||||
#endif /* __GIMPBRUSH_H__ */
|
||||
|
||||
#endif /* __GIMP_BRUSH_H__ */
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -36,9 +37,12 @@
|
|||
|
||||
#define OVERSAMPLING 5
|
||||
|
||||
|
||||
static void gimp_brush_generated_generate (GimpBrushGenerated *brush);
|
||||
|
||||
static GimpObjectClass *parent_class;
|
||||
|
||||
static GimpObjectClass *parent_class = NULL;
|
||||
|
||||
|
||||
static void
|
||||
gimp_brush_generated_destroy (GtkObject *object)
|
||||
|
@ -55,6 +59,7 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass)
|
|||
object_class = GTK_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = gtk_type_class (GIMP_TYPE_BRUSH);
|
||||
|
||||
object_class->destroy = gimp_brush_generated_destroy;
|
||||
}
|
||||
|
||||
|
@ -103,7 +108,7 @@ gimp_brush_generated_new (gfloat radius,
|
|||
|
||||
/* set up normal brush data */
|
||||
brush =
|
||||
GIMP_BRUSH_GENERATED (gimp_type_new (gimp_brush_generated_get_type ()));
|
||||
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
|
||||
|
||||
GIMP_BRUSH (brush)->name = g_strdup ("Untitled");
|
||||
GIMP_BRUSH (brush)->spacing = 20;
|
||||
|
@ -145,7 +150,7 @@ gimp_brush_generated_load (const gchar *file_name)
|
|||
|
||||
/* create new brush */
|
||||
brush =
|
||||
GIMP_BRUSH_GENERATED (gimp_type_new (gimp_brush_generated_get_type ()));
|
||||
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
|
||||
|
||||
GIMP_BRUSH (brush)->filename = g_strdup (file_name);
|
||||
|
||||
|
@ -153,8 +158,8 @@ gimp_brush_generated_load (const gchar *file_name)
|
|||
|
||||
/* read name */
|
||||
fgets (string, 255, fp);
|
||||
if (string[strlen (string)-1] == '\n')
|
||||
string[strlen (string)-1] = 0;
|
||||
if (string[strlen (string) - 1] == '\n')
|
||||
string[strlen (string) - 1] = 0;
|
||||
GIMP_BRUSH (brush)->name = g_strdup (string);
|
||||
|
||||
/* read brush spacing */
|
||||
|
@ -240,7 +245,7 @@ gimp_brush_generated_freeze (GimpBrushGenerated *brush)
|
|||
{
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
||||
|
||||
|
||||
brush->freeze++;
|
||||
}
|
||||
|
||||
|
@ -263,11 +268,13 @@ gauss (gdouble f)
|
|||
/* this aint' a real gauss function */
|
||||
if (f < -.5)
|
||||
{
|
||||
f = -1.0-f;
|
||||
f = -1.0 - f;
|
||||
return (2.0 * f*f);
|
||||
}
|
||||
|
||||
if (f < .5)
|
||||
return (1.0 - 2.0 * f*f);
|
||||
|
||||
f = 1.0 -f;
|
||||
return (2.0 * f*f);
|
||||
}
|
||||
|
@ -276,16 +283,16 @@ void
|
|||
gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
||||
{
|
||||
register GimpBrush *gbrush = NULL;
|
||||
register gint x, y;
|
||||
register guchar *centerp;
|
||||
register gdouble d;
|
||||
register gdouble exponent;
|
||||
register guchar a;
|
||||
register gint length;
|
||||
register guchar *lookup;
|
||||
register gint x, y;
|
||||
register guchar *centerp;
|
||||
register gdouble d;
|
||||
register gdouble exponent;
|
||||
register guchar a;
|
||||
register gint length;
|
||||
register guchar *lookup;
|
||||
register gdouble sum, c, s, tx, ty;
|
||||
gdouble buffer[OVERSAMPLING];
|
||||
register gdouble sum, c, s, tx, ty;
|
||||
gint width, height;
|
||||
gint width, height;
|
||||
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
||||
|
@ -302,9 +309,11 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
{
|
||||
temp_buf_free(gbrush->mask);
|
||||
}
|
||||
|
||||
/* compute the range of the brush. should do a better job than this? */
|
||||
s = sin (gimp_deg_to_rad (brush->angle));
|
||||
c = cos (gimp_deg_to_rad (brush->angle));
|
||||
|
||||
tx = MAX (fabs (c*ceil (brush->radius) - s*ceil (brush->radius)
|
||||
/ brush->aspect_ratio),
|
||||
fabs (c*ceil (brush->radius) + s*ceil (brush->radius)
|
||||
|
@ -313,53 +322,60 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
/ brush->aspect_ratio),
|
||||
fabs (s*ceil (brush->radius) - c*ceil (brush->radius)
|
||||
/ brush->aspect_ratio));
|
||||
|
||||
if (brush->radius > tx)
|
||||
width = ceil (tx);
|
||||
else
|
||||
width = ceil (brush->radius);
|
||||
|
||||
if (brush->radius > ty)
|
||||
height = ceil (ty);
|
||||
else
|
||||
height = ceil (brush->radius);
|
||||
/* compute the axis for spacing */
|
||||
GIMP_BRUSH (brush)->x_axis.x = c*brush->radius;
|
||||
GIMP_BRUSH (brush)->x_axis.y = -1.0*s*brush->radius;
|
||||
|
||||
GIMP_BRUSH (brush)->y_axis.x = (s*brush->radius / brush->aspect_ratio);
|
||||
GIMP_BRUSH (brush)->y_axis.y = (c*brush->radius / brush->aspect_ratio);
|
||||
/* compute the axis for spacing */
|
||||
GIMP_BRUSH (brush)->x_axis.x = c * brush->radius;
|
||||
GIMP_BRUSH (brush)->x_axis.y = -1.0 * s * brush->radius;
|
||||
|
||||
GIMP_BRUSH (brush)->y_axis.x = (s * brush->radius / brush->aspect_ratio);
|
||||
GIMP_BRUSH (brush)->y_axis.y = (c * brush->radius / brush->aspect_ratio);
|
||||
|
||||
gbrush->mask = temp_buf_new (width*2 + 1,
|
||||
height*2 + 1,
|
||||
gbrush->mask = temp_buf_new (width * 2 + 1,
|
||||
height * 2 + 1,
|
||||
1, width, height, 0);
|
||||
centerp = &gbrush->mask->data[height*gbrush->mask->width + width];
|
||||
centerp = &gbrush->mask->data[height * gbrush->mask->width + width];
|
||||
|
||||
if ((1.0 - brush->hardness) < 0.000001)
|
||||
exponent = 1000000;
|
||||
else
|
||||
exponent = 1/(1.0 - brush->hardness);
|
||||
|
||||
/* set up lookup table */
|
||||
length = ceil (sqrt (2*ceil (brush->radius+1)*ceil (brush->radius+1))+1) * OVERSAMPLING;
|
||||
length = ceil (sqrt (2 * ceil (brush->radius+1) * ceil (brush->radius+1))+1) * OVERSAMPLING;
|
||||
lookup = g_malloc (length);
|
||||
sum = 0.0;
|
||||
|
||||
for (x = 0; x < OVERSAMPLING; x++)
|
||||
{
|
||||
d = fabs ((x+.5)/OVERSAMPLING - .5);
|
||||
if (d > brush->radius)
|
||||
buffer[x] = 0.0;
|
||||
else
|
||||
/* buffer[x] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x];
|
||||
}
|
||||
for (x = 0; d < brush->radius || sum > .00001; d += 1.0/OVERSAMPLING)
|
||||
{
|
||||
sum -= buffer[x%OVERSAMPLING];
|
||||
d = fabs ((x + 0.5) / OVERSAMPLING - 0.5);
|
||||
if (d > brush->radius)
|
||||
buffer[x%OVERSAMPLING] = 0.0;
|
||||
buffer[x] = 0.0;
|
||||
else
|
||||
/* buffer[x] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x];
|
||||
}
|
||||
|
||||
for (x = 0; d < brush->radius || sum > 0.00001; d += 1.0 / OVERSAMPLING)
|
||||
{
|
||||
sum -= buffer[x % OVERSAMPLING];
|
||||
if (d > brush->radius)
|
||||
buffer[x % OVERSAMPLING] = 0.0;
|
||||
else
|
||||
/* buffer[x%OVERSAMPLING] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x%OVERSAMPLING] = gauss (pow (d/brush->radius, exponent));
|
||||
buffer[x % OVERSAMPLING] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x%OVERSAMPLING];
|
||||
lookup[x++] = RINT (sum*(255.0/OVERSAMPLING));
|
||||
lookup[x++] = RINT (sum * (255.0 / OVERSAMPLING));
|
||||
}
|
||||
while (x < length)
|
||||
{
|
||||
|
@ -375,7 +391,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
ty *= brush->aspect_ratio;
|
||||
d = sqrt (tx*tx + ty*ty);
|
||||
if (d < brush->radius+1)
|
||||
a = lookup[(int)RINT(d*OVERSAMPLING)];
|
||||
a = lookup[(gint) RINT (d * OVERSAMPLING)];
|
||||
else
|
||||
a = 0;
|
||||
centerp[ y*gbrush->mask->width + x] = a;
|
||||
|
@ -383,6 +399,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
}
|
||||
}
|
||||
g_free (lookup);
|
||||
|
||||
gtk_signal_emit_by_name (GTK_OBJECT (brush), "dirty");
|
||||
}
|
||||
|
||||
|
@ -396,11 +413,15 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
|
|||
radius = 0.0;
|
||||
else if (radius > 32767.0)
|
||||
radius = 32767.0;
|
||||
|
||||
if (radius == brush->radius)
|
||||
return radius;
|
||||
|
||||
brush->radius = radius;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->radius;
|
||||
}
|
||||
|
||||
|
@ -412,13 +433,17 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
|
|||
|
||||
if (hardness < 0.0)
|
||||
hardness = 0.0;
|
||||
else if(hardness > 1.0)
|
||||
else if (hardness > 1.0)
|
||||
hardness = 1.0;
|
||||
|
||||
if (brush->hardness == hardness)
|
||||
return hardness;
|
||||
|
||||
brush->hardness = hardness;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->hardness;
|
||||
}
|
||||
|
||||
|
@ -430,13 +455,17 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
|
|||
|
||||
if (angle < 0.0)
|
||||
angle = -1.0 * fmod (angle, 180.0);
|
||||
else if(angle > 180.0)
|
||||
else if (angle > 180.0)
|
||||
angle = fmod (angle, 180.0);
|
||||
|
||||
if (brush->angle == angle)
|
||||
return angle;
|
||||
|
||||
brush->angle = angle;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->angle;
|
||||
}
|
||||
|
||||
|
@ -448,13 +477,17 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
|
|||
|
||||
if (ratio < 1.0)
|
||||
ratio = 1.0;
|
||||
else if(ratio > 1000)
|
||||
else if (ratio > 1000)
|
||||
ratio = 1000;
|
||||
|
||||
if (brush->aspect_ratio == ratio)
|
||||
return ratio;
|
||||
|
||||
brush->aspect_ratio = ratio;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate(brush);
|
||||
|
||||
return brush->aspect_ratio;
|
||||
}
|
||||
|
||||
|
@ -467,7 +500,7 @@ gimp_brush_generated_get_radius (const GimpBrushGenerated *brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_hardness (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
@ -475,7 +508,7 @@ gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_angle (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_angle (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
@ -483,7 +516,7 @@ gimp_brush_generated_get_angle (const GimpBrushGenerated* brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -36,9 +37,12 @@
|
|||
|
||||
#define OVERSAMPLING 5
|
||||
|
||||
|
||||
static void gimp_brush_generated_generate (GimpBrushGenerated *brush);
|
||||
|
||||
static GimpObjectClass *parent_class;
|
||||
|
||||
static GimpObjectClass *parent_class = NULL;
|
||||
|
||||
|
||||
static void
|
||||
gimp_brush_generated_destroy (GtkObject *object)
|
||||
|
@ -55,6 +59,7 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass)
|
|||
object_class = GTK_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = gtk_type_class (GIMP_TYPE_BRUSH);
|
||||
|
||||
object_class->destroy = gimp_brush_generated_destroy;
|
||||
}
|
||||
|
||||
|
@ -103,7 +108,7 @@ gimp_brush_generated_new (gfloat radius,
|
|||
|
||||
/* set up normal brush data */
|
||||
brush =
|
||||
GIMP_BRUSH_GENERATED (gimp_type_new (gimp_brush_generated_get_type ()));
|
||||
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
|
||||
|
||||
GIMP_BRUSH (brush)->name = g_strdup ("Untitled");
|
||||
GIMP_BRUSH (brush)->spacing = 20;
|
||||
|
@ -145,7 +150,7 @@ gimp_brush_generated_load (const gchar *file_name)
|
|||
|
||||
/* create new brush */
|
||||
brush =
|
||||
GIMP_BRUSH_GENERATED (gimp_type_new (gimp_brush_generated_get_type ()));
|
||||
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
|
||||
|
||||
GIMP_BRUSH (brush)->filename = g_strdup (file_name);
|
||||
|
||||
|
@ -153,8 +158,8 @@ gimp_brush_generated_load (const gchar *file_name)
|
|||
|
||||
/* read name */
|
||||
fgets (string, 255, fp);
|
||||
if (string[strlen (string)-1] == '\n')
|
||||
string[strlen (string)-1] = 0;
|
||||
if (string[strlen (string) - 1] == '\n')
|
||||
string[strlen (string) - 1] = 0;
|
||||
GIMP_BRUSH (brush)->name = g_strdup (string);
|
||||
|
||||
/* read brush spacing */
|
||||
|
@ -240,7 +245,7 @@ gimp_brush_generated_freeze (GimpBrushGenerated *brush)
|
|||
{
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
||||
|
||||
|
||||
brush->freeze++;
|
||||
}
|
||||
|
||||
|
@ -263,11 +268,13 @@ gauss (gdouble f)
|
|||
/* this aint' a real gauss function */
|
||||
if (f < -.5)
|
||||
{
|
||||
f = -1.0-f;
|
||||
f = -1.0 - f;
|
||||
return (2.0 * f*f);
|
||||
}
|
||||
|
||||
if (f < .5)
|
||||
return (1.0 - 2.0 * f*f);
|
||||
|
||||
f = 1.0 -f;
|
||||
return (2.0 * f*f);
|
||||
}
|
||||
|
@ -276,16 +283,16 @@ void
|
|||
gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
||||
{
|
||||
register GimpBrush *gbrush = NULL;
|
||||
register gint x, y;
|
||||
register guchar *centerp;
|
||||
register gdouble d;
|
||||
register gdouble exponent;
|
||||
register guchar a;
|
||||
register gint length;
|
||||
register guchar *lookup;
|
||||
register gint x, y;
|
||||
register guchar *centerp;
|
||||
register gdouble d;
|
||||
register gdouble exponent;
|
||||
register guchar a;
|
||||
register gint length;
|
||||
register guchar *lookup;
|
||||
register gdouble sum, c, s, tx, ty;
|
||||
gdouble buffer[OVERSAMPLING];
|
||||
register gdouble sum, c, s, tx, ty;
|
||||
gint width, height;
|
||||
gint width, height;
|
||||
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
||||
|
@ -302,9 +309,11 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
{
|
||||
temp_buf_free(gbrush->mask);
|
||||
}
|
||||
|
||||
/* compute the range of the brush. should do a better job than this? */
|
||||
s = sin (gimp_deg_to_rad (brush->angle));
|
||||
c = cos (gimp_deg_to_rad (brush->angle));
|
||||
|
||||
tx = MAX (fabs (c*ceil (brush->radius) - s*ceil (brush->radius)
|
||||
/ brush->aspect_ratio),
|
||||
fabs (c*ceil (brush->radius) + s*ceil (brush->radius)
|
||||
|
@ -313,53 +322,60 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
/ brush->aspect_ratio),
|
||||
fabs (s*ceil (brush->radius) - c*ceil (brush->radius)
|
||||
/ brush->aspect_ratio));
|
||||
|
||||
if (brush->radius > tx)
|
||||
width = ceil (tx);
|
||||
else
|
||||
width = ceil (brush->radius);
|
||||
|
||||
if (brush->radius > ty)
|
||||
height = ceil (ty);
|
||||
else
|
||||
height = ceil (brush->radius);
|
||||
/* compute the axis for spacing */
|
||||
GIMP_BRUSH (brush)->x_axis.x = c*brush->radius;
|
||||
GIMP_BRUSH (brush)->x_axis.y = -1.0*s*brush->radius;
|
||||
|
||||
GIMP_BRUSH (brush)->y_axis.x = (s*brush->radius / brush->aspect_ratio);
|
||||
GIMP_BRUSH (brush)->y_axis.y = (c*brush->radius / brush->aspect_ratio);
|
||||
/* compute the axis for spacing */
|
||||
GIMP_BRUSH (brush)->x_axis.x = c * brush->radius;
|
||||
GIMP_BRUSH (brush)->x_axis.y = -1.0 * s * brush->radius;
|
||||
|
||||
GIMP_BRUSH (brush)->y_axis.x = (s * brush->radius / brush->aspect_ratio);
|
||||
GIMP_BRUSH (brush)->y_axis.y = (c * brush->radius / brush->aspect_ratio);
|
||||
|
||||
gbrush->mask = temp_buf_new (width*2 + 1,
|
||||
height*2 + 1,
|
||||
gbrush->mask = temp_buf_new (width * 2 + 1,
|
||||
height * 2 + 1,
|
||||
1, width, height, 0);
|
||||
centerp = &gbrush->mask->data[height*gbrush->mask->width + width];
|
||||
centerp = &gbrush->mask->data[height * gbrush->mask->width + width];
|
||||
|
||||
if ((1.0 - brush->hardness) < 0.000001)
|
||||
exponent = 1000000;
|
||||
else
|
||||
exponent = 1/(1.0 - brush->hardness);
|
||||
|
||||
/* set up lookup table */
|
||||
length = ceil (sqrt (2*ceil (brush->radius+1)*ceil (brush->radius+1))+1) * OVERSAMPLING;
|
||||
length = ceil (sqrt (2 * ceil (brush->radius+1) * ceil (brush->radius+1))+1) * OVERSAMPLING;
|
||||
lookup = g_malloc (length);
|
||||
sum = 0.0;
|
||||
|
||||
for (x = 0; x < OVERSAMPLING; x++)
|
||||
{
|
||||
d = fabs ((x+.5)/OVERSAMPLING - .5);
|
||||
if (d > brush->radius)
|
||||
buffer[x] = 0.0;
|
||||
else
|
||||
/* buffer[x] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x];
|
||||
}
|
||||
for (x = 0; d < brush->radius || sum > .00001; d += 1.0/OVERSAMPLING)
|
||||
{
|
||||
sum -= buffer[x%OVERSAMPLING];
|
||||
d = fabs ((x + 0.5) / OVERSAMPLING - 0.5);
|
||||
if (d > brush->radius)
|
||||
buffer[x%OVERSAMPLING] = 0.0;
|
||||
buffer[x] = 0.0;
|
||||
else
|
||||
/* buffer[x] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x];
|
||||
}
|
||||
|
||||
for (x = 0; d < brush->radius || sum > 0.00001; d += 1.0 / OVERSAMPLING)
|
||||
{
|
||||
sum -= buffer[x % OVERSAMPLING];
|
||||
if (d > brush->radius)
|
||||
buffer[x % OVERSAMPLING] = 0.0;
|
||||
else
|
||||
/* buffer[x%OVERSAMPLING] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x%OVERSAMPLING] = gauss (pow (d/brush->radius, exponent));
|
||||
buffer[x % OVERSAMPLING] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x%OVERSAMPLING];
|
||||
lookup[x++] = RINT (sum*(255.0/OVERSAMPLING));
|
||||
lookup[x++] = RINT (sum * (255.0 / OVERSAMPLING));
|
||||
}
|
||||
while (x < length)
|
||||
{
|
||||
|
@ -375,7 +391,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
ty *= brush->aspect_ratio;
|
||||
d = sqrt (tx*tx + ty*ty);
|
||||
if (d < brush->radius+1)
|
||||
a = lookup[(int)RINT(d*OVERSAMPLING)];
|
||||
a = lookup[(gint) RINT (d * OVERSAMPLING)];
|
||||
else
|
||||
a = 0;
|
||||
centerp[ y*gbrush->mask->width + x] = a;
|
||||
|
@ -383,6 +399,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
}
|
||||
}
|
||||
g_free (lookup);
|
||||
|
||||
gtk_signal_emit_by_name (GTK_OBJECT (brush), "dirty");
|
||||
}
|
||||
|
||||
|
@ -396,11 +413,15 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
|
|||
radius = 0.0;
|
||||
else if (radius > 32767.0)
|
||||
radius = 32767.0;
|
||||
|
||||
if (radius == brush->radius)
|
||||
return radius;
|
||||
|
||||
brush->radius = radius;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->radius;
|
||||
}
|
||||
|
||||
|
@ -412,13 +433,17 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
|
|||
|
||||
if (hardness < 0.0)
|
||||
hardness = 0.0;
|
||||
else if(hardness > 1.0)
|
||||
else if (hardness > 1.0)
|
||||
hardness = 1.0;
|
||||
|
||||
if (brush->hardness == hardness)
|
||||
return hardness;
|
||||
|
||||
brush->hardness = hardness;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->hardness;
|
||||
}
|
||||
|
||||
|
@ -430,13 +455,17 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
|
|||
|
||||
if (angle < 0.0)
|
||||
angle = -1.0 * fmod (angle, 180.0);
|
||||
else if(angle > 180.0)
|
||||
else if (angle > 180.0)
|
||||
angle = fmod (angle, 180.0);
|
||||
|
||||
if (brush->angle == angle)
|
||||
return angle;
|
||||
|
||||
brush->angle = angle;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->angle;
|
||||
}
|
||||
|
||||
|
@ -448,13 +477,17 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
|
|||
|
||||
if (ratio < 1.0)
|
||||
ratio = 1.0;
|
||||
else if(ratio > 1000)
|
||||
else if (ratio > 1000)
|
||||
ratio = 1000;
|
||||
|
||||
if (brush->aspect_ratio == ratio)
|
||||
return ratio;
|
||||
|
||||
brush->aspect_ratio = ratio;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate(brush);
|
||||
|
||||
return brush->aspect_ratio;
|
||||
}
|
||||
|
||||
|
@ -467,7 +500,7 @@ gimp_brush_generated_get_radius (const GimpBrushGenerated *brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_hardness (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
@ -475,7 +508,7 @@ gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_angle (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_angle (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
@ -483,7 +516,7 @@ gimp_brush_generated_get_angle (const GimpBrushGenerated* brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -36,9 +37,12 @@
|
|||
|
||||
#define OVERSAMPLING 5
|
||||
|
||||
|
||||
static void gimp_brush_generated_generate (GimpBrushGenerated *brush);
|
||||
|
||||
static GimpObjectClass *parent_class;
|
||||
|
||||
static GimpObjectClass *parent_class = NULL;
|
||||
|
||||
|
||||
static void
|
||||
gimp_brush_generated_destroy (GtkObject *object)
|
||||
|
@ -55,6 +59,7 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass)
|
|||
object_class = GTK_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = gtk_type_class (GIMP_TYPE_BRUSH);
|
||||
|
||||
object_class->destroy = gimp_brush_generated_destroy;
|
||||
}
|
||||
|
||||
|
@ -103,7 +108,7 @@ gimp_brush_generated_new (gfloat radius,
|
|||
|
||||
/* set up normal brush data */
|
||||
brush =
|
||||
GIMP_BRUSH_GENERATED (gimp_type_new (gimp_brush_generated_get_type ()));
|
||||
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
|
||||
|
||||
GIMP_BRUSH (brush)->name = g_strdup ("Untitled");
|
||||
GIMP_BRUSH (brush)->spacing = 20;
|
||||
|
@ -145,7 +150,7 @@ gimp_brush_generated_load (const gchar *file_name)
|
|||
|
||||
/* create new brush */
|
||||
brush =
|
||||
GIMP_BRUSH_GENERATED (gimp_type_new (gimp_brush_generated_get_type ()));
|
||||
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
|
||||
|
||||
GIMP_BRUSH (brush)->filename = g_strdup (file_name);
|
||||
|
||||
|
@ -153,8 +158,8 @@ gimp_brush_generated_load (const gchar *file_name)
|
|||
|
||||
/* read name */
|
||||
fgets (string, 255, fp);
|
||||
if (string[strlen (string)-1] == '\n')
|
||||
string[strlen (string)-1] = 0;
|
||||
if (string[strlen (string) - 1] == '\n')
|
||||
string[strlen (string) - 1] = 0;
|
||||
GIMP_BRUSH (brush)->name = g_strdup (string);
|
||||
|
||||
/* read brush spacing */
|
||||
|
@ -240,7 +245,7 @@ gimp_brush_generated_freeze (GimpBrushGenerated *brush)
|
|||
{
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
||||
|
||||
|
||||
brush->freeze++;
|
||||
}
|
||||
|
||||
|
@ -263,11 +268,13 @@ gauss (gdouble f)
|
|||
/* this aint' a real gauss function */
|
||||
if (f < -.5)
|
||||
{
|
||||
f = -1.0-f;
|
||||
f = -1.0 - f;
|
||||
return (2.0 * f*f);
|
||||
}
|
||||
|
||||
if (f < .5)
|
||||
return (1.0 - 2.0 * f*f);
|
||||
|
||||
f = 1.0 -f;
|
||||
return (2.0 * f*f);
|
||||
}
|
||||
|
@ -276,16 +283,16 @@ void
|
|||
gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
||||
{
|
||||
register GimpBrush *gbrush = NULL;
|
||||
register gint x, y;
|
||||
register guchar *centerp;
|
||||
register gdouble d;
|
||||
register gdouble exponent;
|
||||
register guchar a;
|
||||
register gint length;
|
||||
register guchar *lookup;
|
||||
register gint x, y;
|
||||
register guchar *centerp;
|
||||
register gdouble d;
|
||||
register gdouble exponent;
|
||||
register guchar a;
|
||||
register gint length;
|
||||
register guchar *lookup;
|
||||
register gdouble sum, c, s, tx, ty;
|
||||
gdouble buffer[OVERSAMPLING];
|
||||
register gdouble sum, c, s, tx, ty;
|
||||
gint width, height;
|
||||
gint width, height;
|
||||
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
||||
|
@ -302,9 +309,11 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
{
|
||||
temp_buf_free(gbrush->mask);
|
||||
}
|
||||
|
||||
/* compute the range of the brush. should do a better job than this? */
|
||||
s = sin (gimp_deg_to_rad (brush->angle));
|
||||
c = cos (gimp_deg_to_rad (brush->angle));
|
||||
|
||||
tx = MAX (fabs (c*ceil (brush->radius) - s*ceil (brush->radius)
|
||||
/ brush->aspect_ratio),
|
||||
fabs (c*ceil (brush->radius) + s*ceil (brush->radius)
|
||||
|
@ -313,53 +322,60 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
/ brush->aspect_ratio),
|
||||
fabs (s*ceil (brush->radius) - c*ceil (brush->radius)
|
||||
/ brush->aspect_ratio));
|
||||
|
||||
if (brush->radius > tx)
|
||||
width = ceil (tx);
|
||||
else
|
||||
width = ceil (brush->radius);
|
||||
|
||||
if (brush->radius > ty)
|
||||
height = ceil (ty);
|
||||
else
|
||||
height = ceil (brush->radius);
|
||||
/* compute the axis for spacing */
|
||||
GIMP_BRUSH (brush)->x_axis.x = c*brush->radius;
|
||||
GIMP_BRUSH (brush)->x_axis.y = -1.0*s*brush->radius;
|
||||
|
||||
GIMP_BRUSH (brush)->y_axis.x = (s*brush->radius / brush->aspect_ratio);
|
||||
GIMP_BRUSH (brush)->y_axis.y = (c*brush->radius / brush->aspect_ratio);
|
||||
/* compute the axis for spacing */
|
||||
GIMP_BRUSH (brush)->x_axis.x = c * brush->radius;
|
||||
GIMP_BRUSH (brush)->x_axis.y = -1.0 * s * brush->radius;
|
||||
|
||||
GIMP_BRUSH (brush)->y_axis.x = (s * brush->radius / brush->aspect_ratio);
|
||||
GIMP_BRUSH (brush)->y_axis.y = (c * brush->radius / brush->aspect_ratio);
|
||||
|
||||
gbrush->mask = temp_buf_new (width*2 + 1,
|
||||
height*2 + 1,
|
||||
gbrush->mask = temp_buf_new (width * 2 + 1,
|
||||
height * 2 + 1,
|
||||
1, width, height, 0);
|
||||
centerp = &gbrush->mask->data[height*gbrush->mask->width + width];
|
||||
centerp = &gbrush->mask->data[height * gbrush->mask->width + width];
|
||||
|
||||
if ((1.0 - brush->hardness) < 0.000001)
|
||||
exponent = 1000000;
|
||||
else
|
||||
exponent = 1/(1.0 - brush->hardness);
|
||||
|
||||
/* set up lookup table */
|
||||
length = ceil (sqrt (2*ceil (brush->radius+1)*ceil (brush->radius+1))+1) * OVERSAMPLING;
|
||||
length = ceil (sqrt (2 * ceil (brush->radius+1) * ceil (brush->radius+1))+1) * OVERSAMPLING;
|
||||
lookup = g_malloc (length);
|
||||
sum = 0.0;
|
||||
|
||||
for (x = 0; x < OVERSAMPLING; x++)
|
||||
{
|
||||
d = fabs ((x+.5)/OVERSAMPLING - .5);
|
||||
if (d > brush->radius)
|
||||
buffer[x] = 0.0;
|
||||
else
|
||||
/* buffer[x] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x];
|
||||
}
|
||||
for (x = 0; d < brush->radius || sum > .00001; d += 1.0/OVERSAMPLING)
|
||||
{
|
||||
sum -= buffer[x%OVERSAMPLING];
|
||||
d = fabs ((x + 0.5) / OVERSAMPLING - 0.5);
|
||||
if (d > brush->radius)
|
||||
buffer[x%OVERSAMPLING] = 0.0;
|
||||
buffer[x] = 0.0;
|
||||
else
|
||||
/* buffer[x] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x];
|
||||
}
|
||||
|
||||
for (x = 0; d < brush->radius || sum > 0.00001; d += 1.0 / OVERSAMPLING)
|
||||
{
|
||||
sum -= buffer[x % OVERSAMPLING];
|
||||
if (d > brush->radius)
|
||||
buffer[x % OVERSAMPLING] = 0.0;
|
||||
else
|
||||
/* buffer[x%OVERSAMPLING] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x%OVERSAMPLING] = gauss (pow (d/brush->radius, exponent));
|
||||
buffer[x % OVERSAMPLING] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x%OVERSAMPLING];
|
||||
lookup[x++] = RINT (sum*(255.0/OVERSAMPLING));
|
||||
lookup[x++] = RINT (sum * (255.0 / OVERSAMPLING));
|
||||
}
|
||||
while (x < length)
|
||||
{
|
||||
|
@ -375,7 +391,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
ty *= brush->aspect_ratio;
|
||||
d = sqrt (tx*tx + ty*ty);
|
||||
if (d < brush->radius+1)
|
||||
a = lookup[(int)RINT(d*OVERSAMPLING)];
|
||||
a = lookup[(gint) RINT (d * OVERSAMPLING)];
|
||||
else
|
||||
a = 0;
|
||||
centerp[ y*gbrush->mask->width + x] = a;
|
||||
|
@ -383,6 +399,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
}
|
||||
}
|
||||
g_free (lookup);
|
||||
|
||||
gtk_signal_emit_by_name (GTK_OBJECT (brush), "dirty");
|
||||
}
|
||||
|
||||
|
@ -396,11 +413,15 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
|
|||
radius = 0.0;
|
||||
else if (radius > 32767.0)
|
||||
radius = 32767.0;
|
||||
|
||||
if (radius == brush->radius)
|
||||
return radius;
|
||||
|
||||
brush->radius = radius;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->radius;
|
||||
}
|
||||
|
||||
|
@ -412,13 +433,17 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
|
|||
|
||||
if (hardness < 0.0)
|
||||
hardness = 0.0;
|
||||
else if(hardness > 1.0)
|
||||
else if (hardness > 1.0)
|
||||
hardness = 1.0;
|
||||
|
||||
if (brush->hardness == hardness)
|
||||
return hardness;
|
||||
|
||||
brush->hardness = hardness;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->hardness;
|
||||
}
|
||||
|
||||
|
@ -430,13 +455,17 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
|
|||
|
||||
if (angle < 0.0)
|
||||
angle = -1.0 * fmod (angle, 180.0);
|
||||
else if(angle > 180.0)
|
||||
else if (angle > 180.0)
|
||||
angle = fmod (angle, 180.0);
|
||||
|
||||
if (brush->angle == angle)
|
||||
return angle;
|
||||
|
||||
brush->angle = angle;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->angle;
|
||||
}
|
||||
|
||||
|
@ -448,13 +477,17 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
|
|||
|
||||
if (ratio < 1.0)
|
||||
ratio = 1.0;
|
||||
else if(ratio > 1000)
|
||||
else if (ratio > 1000)
|
||||
ratio = 1000;
|
||||
|
||||
if (brush->aspect_ratio == ratio)
|
||||
return ratio;
|
||||
|
||||
brush->aspect_ratio = ratio;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate(brush);
|
||||
|
||||
return brush->aspect_ratio;
|
||||
}
|
||||
|
||||
|
@ -467,7 +500,7 @@ gimp_brush_generated_get_radius (const GimpBrushGenerated *brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_hardness (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
@ -475,7 +508,7 @@ gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_angle (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_angle (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
@ -483,7 +516,7 @@ gimp_brush_generated_get_angle (const GimpBrushGenerated* brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
|
|
@ -17,12 +17,21 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_BRUSH_GENERATED_H__
|
||||
#define __GIMP_BRUSH_GENERATED_H__
|
||||
|
||||
#include "gimpbrush.h"
|
||||
|
||||
typedef struct _GimpBrushGenerated
|
||||
|
||||
#define GIMP_TYPE_BRUSH_GENERATED (gimp_brush_generated_get_type ())
|
||||
#define GIMP_BRUSH_GENERATED(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_GENERATED, GimpBrushGenerated))
|
||||
#define GIMP_IS_BRUSH_GENERATED(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_GENERATED))
|
||||
|
||||
typedef struct _GimpBrushGenerated GimpBrushGenerated;
|
||||
typedef struct _GimpBrushGeneratedClass GimpBrushGeneratedClass;
|
||||
|
||||
struct _GimpBrushGenerated
|
||||
{
|
||||
GimpBrush gbrush;
|
||||
|
||||
|
@ -34,51 +43,42 @@ typedef struct _GimpBrushGenerated
|
|||
gint freeze;
|
||||
|
||||
/*GSpline *profile_curve */ /* Some lazy day... */
|
||||
} GimpBrushGenerated;
|
||||
};
|
||||
|
||||
typedef struct _GimpBrushGeneratedClass
|
||||
struct _GimpBrushGeneratedClass
|
||||
{
|
||||
GimpBrushClass parent_class;
|
||||
};
|
||||
|
||||
void (* generate) (GimpBrushGenerated *brush);
|
||||
} GimpBrushGeneratedClass;
|
||||
|
||||
/* object stuff */
|
||||
GtkType gimp_brush_generated_get_type (void);
|
||||
|
||||
#define GIMP_TYPE_BRUSH_GENERATED (gimp_brush_generated_get_type ())
|
||||
#define GIMP_BRUSH_GENERATED(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_GENERATED, GimpBrushGenerated))
|
||||
#define GIMP_IS_BRUSH_GENERATED(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_GENERATED))
|
||||
GimpBrushGenerated * gimp_brush_generated_new (gfloat radius,
|
||||
gfloat hardness,
|
||||
gfloat angle,
|
||||
gfloat aspect_ratio);
|
||||
GimpBrushGenerated * gimp_brush_generated_load (const gchar *file_name);
|
||||
|
||||
guint gimp_brush_generated_get_type (void);
|
||||
|
||||
/* normal stuff */
|
||||
|
||||
GimpBrushGenerated *gimp_brush_generated_new (gfloat radius,
|
||||
gfloat hardness,
|
||||
gfloat angle,
|
||||
gfloat aspect_ratio);
|
||||
|
||||
GimpBrushGenerated *gimp_brush_generated_load (const gchar *file_name);
|
||||
|
||||
void gimp_brush_generated_save (GimpBrushGenerated *brush,
|
||||
void gimp_brush_generated_save (GimpBrushGenerated *brush,
|
||||
const gchar *file_name);
|
||||
void gimp_brush_generated_delete (GimpBrushGenerated *brush);
|
||||
void gimp_brush_generated_delete (GimpBrushGenerated *brush);
|
||||
|
||||
void gimp_brush_generated_freeze (GimpBrushGenerated *brush);
|
||||
void gimp_brush_generated_thaw (GimpBrushGenerated *brush);
|
||||
void gimp_brush_generated_freeze (GimpBrushGenerated *brush);
|
||||
void gimp_brush_generated_thaw (GimpBrushGenerated *brush);
|
||||
|
||||
gfloat gimp_brush_generated_set_radius (GimpBrushGenerated* brush,
|
||||
gfloat gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
|
||||
gfloat radius);
|
||||
gfloat gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
|
||||
gfloat hardness);
|
||||
gfloat gimp_brush_generated_set_angle (GimpBrushGenerated* brush,
|
||||
gfloat gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
|
||||
gfloat angle);
|
||||
gfloat gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated* brush,
|
||||
gfloat gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
|
||||
gfloat ratio);
|
||||
|
||||
gfloat gimp_brush_generated_get_radius (const GimpBrushGenerated* brush);
|
||||
gfloat gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush);
|
||||
gfloat gimp_brush_generated_get_angle (const GimpBrushGenerated* brush);
|
||||
gfloat gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated* brush);
|
||||
gfloat gimp_brush_generated_get_radius (const GimpBrushGenerated *brush);
|
||||
gfloat gimp_brush_generated_get_hardness (const GimpBrushGenerated *brush);
|
||||
gfloat gimp_brush_generated_get_angle (const GimpBrushGenerated *brush);
|
||||
gfloat gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated *brush);
|
||||
|
||||
|
||||
#endif /* __GIMP_BRUSH_GENERATED_H__ */
|
||||
|
|
|
@ -293,14 +293,14 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
}
|
||||
buf[strlen (buf) - 1] = 0;
|
||||
|
||||
pipe = GIMP_BRUSH_PIPE (gimp_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
pipe = GIMP_BRUSH_PIPE (gtk_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
name = g_strdup (buf);
|
||||
|
||||
/* get the number of brushes */
|
||||
if (fgets (buf, 1024, fp) == NULL)
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
num_of_brushes = strtol (buf, ¶mstring, 10);
|
||||
|
@ -308,7 +308,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
{
|
||||
g_message (_("Brush pipes should have at least one brush."));
|
||||
fclose (fp);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -389,7 +389,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
if (pipe->nbrushes > 0)
|
||||
{
|
||||
pipe->brushes[pipe->nbrushes] =
|
||||
GIMP_BRUSH_PIXMAP (gimp_type_new (GIMP_TYPE_BRUSH_PIXMAP));
|
||||
GIMP_BRUSH_PIXMAP (gtk_type_new (GIMP_TYPE_BRUSH_PIXMAP));
|
||||
g_free (GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name);
|
||||
GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name = NULL;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
"brushes in the brush pipe."));
|
||||
fclose (fp);
|
||||
pattern_free (pattern);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ gimp_brush_pixmap_load (gchar *filename)
|
|||
if ((fp = fopen (filename, "rb")) == NULL)
|
||||
return NULL;
|
||||
|
||||
pipe = GIMP_BRUSH_PIPE (gimp_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
pipe = GIMP_BRUSH_PIPE (gtk_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
|
||||
/* A (single) pixmap brush is a pixmap pipe brush with just one pixmap */
|
||||
pipe->dimension = 1;
|
||||
|
@ -466,7 +466,7 @@ gimp_brush_pixmap_load (gchar *filename)
|
|||
g_message (_("Failed to load pixmap brush."));
|
||||
fclose (fp);
|
||||
pattern_free (pattern);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -293,14 +293,14 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
}
|
||||
buf[strlen (buf) - 1] = 0;
|
||||
|
||||
pipe = GIMP_BRUSH_PIPE (gimp_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
pipe = GIMP_BRUSH_PIPE (gtk_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
name = g_strdup (buf);
|
||||
|
||||
/* get the number of brushes */
|
||||
if (fgets (buf, 1024, fp) == NULL)
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
num_of_brushes = strtol (buf, ¶mstring, 10);
|
||||
|
@ -308,7 +308,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
{
|
||||
g_message (_("Brush pipes should have at least one brush."));
|
||||
fclose (fp);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -389,7 +389,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
if (pipe->nbrushes > 0)
|
||||
{
|
||||
pipe->brushes[pipe->nbrushes] =
|
||||
GIMP_BRUSH_PIXMAP (gimp_type_new (GIMP_TYPE_BRUSH_PIXMAP));
|
||||
GIMP_BRUSH_PIXMAP (gtk_type_new (GIMP_TYPE_BRUSH_PIXMAP));
|
||||
g_free (GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name);
|
||||
GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name = NULL;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
"brushes in the brush pipe."));
|
||||
fclose (fp);
|
||||
pattern_free (pattern);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ gimp_brush_pixmap_load (gchar *filename)
|
|||
if ((fp = fopen (filename, "rb")) == NULL)
|
||||
return NULL;
|
||||
|
||||
pipe = GIMP_BRUSH_PIPE (gimp_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
pipe = GIMP_BRUSH_PIPE (gtk_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
|
||||
/* A (single) pixmap brush is a pixmap pipe brush with just one pixmap */
|
||||
pipe->dimension = 1;
|
||||
|
@ -466,7 +466,7 @@ gimp_brush_pixmap_load (gchar *filename)
|
|||
g_message (_("Failed to load pixmap brush."));
|
||||
fclose (fp);
|
||||
pattern_free (pattern);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,24 +17,28 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMPBRUSHPIPE_H__
|
||||
#define __GIMPBRUSHPIPE_H__
|
||||
#ifndef __GIMP_BRUSH_PIPE_H__
|
||||
#define __GIMP_BRUSH_PIPE_H__
|
||||
|
||||
|
||||
#include "tools.h"
|
||||
#include "paint_core.h"
|
||||
#include "gimpbrush.h"
|
||||
#include "temp_buf.h"
|
||||
|
||||
|
||||
typedef struct _GimpBrushPixmap GimpBrushPixmap;
|
||||
typedef struct _GimpBrushPipe GimpBrushPipe;
|
||||
|
||||
|
||||
#define GIMP_TYPE_BRUSH_PIXMAP (gimp_brush_pixmap_get_type ())
|
||||
#define GIMP_BRUSH_PIXMAP(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIXMAP, GimpBrushPixmap))
|
||||
#define GIMP_IS_BRUSH_PIXMAP(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIXMAP))
|
||||
#define GIMP_BRUSH_PIXMAP(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIXMAP, GimpBrushPixmap))
|
||||
#define GIMP_IS_BRUSH_PIXMAP(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIXMAP))
|
||||
|
||||
#define GIMP_TYPE_BRUSH_PIPE (gimp_brush_pipe_get_type ())
|
||||
#define GIMP_BRUSH_PIPE(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIPE, GimpBrushPipe))
|
||||
#define GIMP_IS_BRUSH_PIPE(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIPE))
|
||||
#define GIMP_BRUSH_PIPE(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIPE, GimpBrushPipe))
|
||||
#define GIMP_IS_BRUSH_PIPE(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIPE))
|
||||
|
||||
|
||||
GtkType gimp_brush_pixmap_get_type (void);
|
||||
GtkType gimp_brush_pipe_get_type (void);
|
||||
|
@ -44,10 +48,12 @@ GimpBrushPipe * gimp_brush_pixmap_load (gchar *filename);
|
|||
|
||||
TempBuf * gimp_brush_pixmap_pixmap (GimpBrushPixmap *brush);
|
||||
|
||||
|
||||
/* appearantly GIMP_IS_BRUSH_PIPE () returning TRUE is no indication
|
||||
* that you really have a brush_pipe in front of you, so here we introduce
|
||||
* a macro that works:
|
||||
*/
|
||||
#define GIMP_IS_REALLY_A_BRUSH_PIPE(obj) (GIMP_IS_BRUSH_PIPE (obj) && GIMP_BRUSH_PIPE (obj)->nbrushes > 1)
|
||||
|
||||
#endif /* __GIMPBRUSHPIPE_H__ */
|
||||
|
||||
#endif /* __GIMP_BRUSH_PIPE_H__ */
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_CONTEXT_H__
|
||||
#define __GIMP_CONTEXT_H__
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "apptypes.h"
|
||||
|
@ -32,10 +34,10 @@
|
|||
#include "gimpobjectP.h"
|
||||
|
||||
#define GIMP_TYPE_CONTEXT (gimp_context_get_type ())
|
||||
#define GIMP_CONTEXT(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_CONTEXT, GimpContext))
|
||||
#define GIMP_CONTEXT_CLASS(klass) (GIMP_CHECK_CLASS_CAST (klass, GIMP_TYPE_CONTEXT, GimpContextClass))
|
||||
#define GIMP_IS_CONTEXT(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_CONTEXT))
|
||||
#define GIMP_IS_CONTEXT_CLASS(klass) (GIMP_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTEXT))
|
||||
#define GIMP_CONTEXT(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_CONTEXT, GimpContext))
|
||||
#define GIMP_CONTEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST (klass, GIMP_TYPE_CONTEXT, GimpContextClass))
|
||||
#define GIMP_IS_CONTEXT(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_CONTEXT))
|
||||
#define GIMP_IS_CONTEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTEXT))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -288,4 +290,5 @@ void gimp_context_gradient_changed (GimpContext *context);
|
|||
void gimp_context_refresh_gradients (void);
|
||||
void gimp_context_update_gradients (gradient_t *gradient);
|
||||
|
||||
|
||||
#endif /* __GIMP_CONTEXT_H__ */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -15,11 +15,13 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gimpsignal.h"
|
||||
#include "gimplistP.h"
|
||||
|
||||
/* code mostly ripped from nether's gimpset class */
|
||||
/* code mostly ripped from nether's gimpset class */
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -28,42 +30,49 @@ enum
|
|||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint gimp_list_signals [LAST_SIGNAL];
|
||||
static guint gimp_list_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static GimpObjectClass* parent_class;
|
||||
static GimpObjectClass *parent_class = NULL;
|
||||
|
||||
|
||||
static void gimp_list_add_func (GimpList *list,
|
||||
gpointer object);
|
||||
static void gimp_list_remove_func (GimpList *list,
|
||||
gpointer object);
|
||||
|
||||
static void gimp_list_add_func (GimpList *list, void *);
|
||||
static void gimp_list_remove_func (GimpList *list, void *);
|
||||
|
||||
static void
|
||||
gimp_list_destroy (GtkObject* ob)
|
||||
gimp_list_destroy (GtkObject *object)
|
||||
{
|
||||
GimpList* list=GIMP_LIST (ob);
|
||||
GimpList *list = GIMP_LIST (object);
|
||||
|
||||
while (list->list) /* ought to put a sanity check in here... */
|
||||
{
|
||||
gimp_list_remove (list, list->list->data);
|
||||
}
|
||||
g_slist_free (list->list);
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (ob);
|
||||
|
||||
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_list_init (GimpList* list)
|
||||
gimp_list_init (GimpList *list)
|
||||
{
|
||||
list->list = NULL;
|
||||
list->type = GTK_TYPE_OBJECT;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_list_class_init (GimpListClass* klass)
|
||||
gimp_list_class_init (GimpListClass *klass)
|
||||
{
|
||||
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
|
||||
GtkType type = object_class->type;
|
||||
|
||||
parent_class = gtk_type_parent_class (type);
|
||||
|
||||
|
||||
object_class->destroy = gimp_list_destroy;
|
||||
|
||||
|
||||
gimp_list_signals[ADD]=
|
||||
gimp_signal_new ("add", GTK_RUN_FIRST, type, 0,
|
||||
gimp_sigtype_pointer);
|
||||
|
@ -94,11 +103,11 @@ gimp_list_get_type (void)
|
|||
return type;
|
||||
}
|
||||
|
||||
GimpList*
|
||||
GimpList *
|
||||
gimp_list_new (GtkType type,
|
||||
gboolean weak)
|
||||
{
|
||||
GimpList* list;
|
||||
GimpList *list;
|
||||
|
||||
list = gtk_type_new (gimp_list_get_type ());
|
||||
|
||||
|
@ -109,84 +118,94 @@ gimp_list_new (GtkType type,
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_list_destroy_cb (GtkObject *ob,
|
||||
gimp_list_destroy_cb (GtkObject *object,
|
||||
gpointer data)
|
||||
{
|
||||
GimpList* list;
|
||||
GimpList *list;
|
||||
|
||||
list = GIMP_LIST (data);
|
||||
|
||||
gimp_list_remove (list, ob);
|
||||
gimp_list_remove (list, object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_list_add_func (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
list->list = g_slist_prepend (list->list, val);
|
||||
list->list = g_slist_prepend (list->list, object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_list_remove_func (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
list->list = g_slist_remove (list->list, val);
|
||||
list->list = g_slist_remove (list->list, object);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_list_add (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
g_return_val_if_fail (list, FALSE);
|
||||
g_return_val_if_fail (GTK_CHECK_TYPE (val, list->type), FALSE);
|
||||
g_return_val_if_fail (GTK_CHECK_TYPE (object, list->type), FALSE);
|
||||
|
||||
if (g_slist_find (list->list, val))
|
||||
if (g_slist_find (list->list, object))
|
||||
return FALSE;
|
||||
|
||||
if (list->weak)
|
||||
gtk_signal_connect (GTK_OBJECT (val), "destroy",
|
||||
GTK_SIGNAL_FUNC (gimp_list_destroy_cb),
|
||||
list);
|
||||
{
|
||||
gtk_signal_connect (GTK_OBJECT (object), "destroy",
|
||||
GTK_SIGNAL_FUNC (gimp_list_destroy_cb),
|
||||
list);
|
||||
}
|
||||
else
|
||||
gtk_object_ref (GTK_OBJECT (val));
|
||||
{
|
||||
gtk_object_ref (GTK_OBJECT (object));
|
||||
gtk_object_sink (GTK_OBJECT (object));
|
||||
}
|
||||
|
||||
GIMP_LIST_CLASS (GTK_OBJECT (list)->klass)->add (list, val);
|
||||
GIMP_LIST_CLASS (GTK_OBJECT (list)->klass)->add (list, object);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT(list), gimp_list_signals[ADD], val);
|
||||
gtk_signal_emit (GTK_OBJECT(list), gimp_list_signals[ADD], object);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_list_remove (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
g_return_val_if_fail (list, FALSE);
|
||||
|
||||
if (!g_slist_find (list->list, val))
|
||||
if (!g_slist_find (list->list, object))
|
||||
{
|
||||
fprintf (stderr, "gimp_list_remove: can't find val\n");
|
||||
g_warning ("gimp_list_remove: can't find val");
|
||||
return FALSE;
|
||||
}
|
||||
GIMP_LIST_CLASS (GTK_OBJECT (list)->klass)->remove (list, val);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (list), gimp_list_signals[REMOVE], val);
|
||||
GIMP_LIST_CLASS (GTK_OBJECT (list)->klass)->remove (list, object);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (list), gimp_list_signals[REMOVE], object);
|
||||
|
||||
if (list->weak)
|
||||
gtk_signal_disconnect_by_func (GTK_OBJECT (val),
|
||||
GTK_SIGNAL_FUNC (gimp_list_destroy_cb),
|
||||
list);
|
||||
{
|
||||
gtk_signal_disconnect_by_func (GTK_OBJECT (object),
|
||||
GTK_SIGNAL_FUNC (gimp_list_destroy_cb),
|
||||
list);
|
||||
}
|
||||
else
|
||||
gtk_object_unref (GTK_OBJECT (val));
|
||||
{
|
||||
gtk_object_unref (GTK_OBJECT (object));
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_list_have (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
return g_slist_find (list->list, val) ? TRUE : FALSE;
|
||||
return g_slist_find (list->list, object) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,22 +1,40 @@
|
|||
#ifndef __GIMPLIST_H__
|
||||
#define __GIMPLIST_H__
|
||||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_LIST_H__
|
||||
#define __GIMP_LIST_H__
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
#include "gimplistF.h"
|
||||
|
||||
|
||||
/* GimpList - a typed list of objects with signals for adding and
|
||||
removing of stuff. If it is weak, destroyed objects get removed
|
||||
automatically. If it is not, it refs them so they won't be freed
|
||||
till they are removed. (Though they can be destroyed, of course) */
|
||||
|
||||
#define GIMP_TYPE_LIST gimp_list_get_type()
|
||||
|
||||
#define GIMP_LIST(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_LIST, GimpList)
|
||||
* removing of stuff. If it is weak, destroyed objects get removed
|
||||
* automatically. If it is not, it refs them so they won't be freed
|
||||
* till they are removed. (Though they can be destroyed, of course)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define GIMP_TYPE_LIST gimp_list_get_type ()
|
||||
#define GIMP_LIST(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_LIST, GimpList)
|
||||
#define GIMP_IS_LIST(obj) GTK_CHECK_TYPE (obj, gimp_list_get_type())
|
||||
|
||||
|
||||
/* Signals:
|
||||
add
|
||||
|
@ -24,15 +42,22 @@
|
|||
*/
|
||||
|
||||
|
||||
guint gimp_list_get_type (void);
|
||||
GtkType gimp_list_get_type (void);
|
||||
|
||||
GimpList* gimp_list_new (GtkType type, gboolean weak);
|
||||
GtkType gimp_list_type (GimpList* list);
|
||||
gboolean gimp_list_add (GimpList* gimplist, gpointer ob);
|
||||
gboolean gimp_list_remove (GimpList* gimplist, gpointer ob);
|
||||
gboolean gimp_list_have (GimpList* gimplist, gpointer ob);
|
||||
void gimp_list_foreach(GimpList* gimplist, GFunc func,
|
||||
gpointer user_data);
|
||||
gint gimp_list_size (GimpList* gimplist);
|
||||
GimpList * gimp_list_new (GtkType type,
|
||||
gboolean weak);
|
||||
|
||||
#endif
|
||||
GtkType gimp_list_type (GimpList *list);
|
||||
gboolean gimp_list_add (GimpList *list,
|
||||
gpointer object);
|
||||
gboolean gimp_list_remove (GimpList *list,
|
||||
gpointer object);
|
||||
gboolean gimp_list_have (GimpList *list,
|
||||
gpointer object);
|
||||
void gimp_list_foreach (GimpList *list,
|
||||
GFunc func,
|
||||
gpointer user_data);
|
||||
gint gimp_list_size (GimpList *list);
|
||||
|
||||
|
||||
#endif /* __GIMP_LIST_H__ */
|
||||
|
|
|
@ -1,12 +1,30 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "gimpobjectP.h"
|
||||
|
||||
static void
|
||||
gimp_object_init (GimpObject *gobject)
|
||||
gimp_object_init (GimpObject *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_object_class_init (GimpObjectClass *gobjectclass)
|
||||
gimp_object_class_init (GimpObjectClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -14,16 +32,13 @@ GtkType
|
|||
gimp_object_get_type (void)
|
||||
{
|
||||
static GtkType type = 0;
|
||||
GIMP_TYPE_INIT(type,
|
||||
GimpObject,
|
||||
GimpObjectClass,
|
||||
gimp_object_init,
|
||||
gimp_object_class_init,
|
||||
GTK_TYPE_OBJECT);
|
||||
|
||||
GIMP_TYPE_INIT (type,
|
||||
GimpObject,
|
||||
GimpObjectClass,
|
||||
gimp_object_init,
|
||||
gimp_object_class_init,
|
||||
GTK_TYPE_OBJECT);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,29 +1,36 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_OBJECT_H__
|
||||
#define __GIMP_OBJECT_H__
|
||||
|
||||
|
||||
#include <gtk/gtktypeutils.h>
|
||||
|
||||
#include "gimpobjectF.h"
|
||||
|
||||
#define GIMP_TYPE_OBJECT gimp_object_get_type()
|
||||
|
||||
#define GIMP_OBJECT(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_OBJECT, GimpObject)
|
||||
|
||||
#define GIMP_TYPE_OBJECT gimp_object_get_type ()
|
||||
#define GIMP_OBJECT(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_OBJECT, GimpObject)
|
||||
#define GIMP_IS_OBJECT(obj) GTK_CHECK_TYPE (obj, GIMP_TYPE_OBJECT)
|
||||
|
||||
|
||||
guint gimp_object_get_type(void);
|
||||
|
||||
/* hacks to fake a gimp object lib */
|
||||
#define GIMP_CHECK_CAST GTK_CHECK_CAST
|
||||
#define GIMP_CHECK_TYPE GTK_CHECK_TYPE
|
||||
#define gimp_type_new gtk_type_new
|
||||
#define gimp_object_destroy(obj) gtk_object_destroy(GTK_OBJECT(obj))
|
||||
#define gimp_object_ref(obj) gtk_object_ref(GTK_OBJECT(obj))
|
||||
#define gimp_object_unref(obj) gtk_object_unref(GTK_OBJECT(obj))
|
||||
|
||||
#endif
|
||||
GtkType gimp_object_get_type (void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* __GIMP_OBJECT_H__ */
|
||||
|
|
|
@ -14,9 +14,11 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PARASITE_LIST_H__
|
||||
#define __PARASITE_LIST_H__
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -27,8 +29,8 @@
|
|||
|
||||
|
||||
#define GIMP_TYPE_PARASITE_LIST (parasite_list_get_type ())
|
||||
#define GIMP_PARASITE_LIST(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_PARASITE_LIST, GimpParasiteList))
|
||||
#define GIMP_IS_PARASITE_LIST(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_PARASITE_LIST))
|
||||
#define GIMP_PARASITE_LIST(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_PARASITE_LIST, GimpParasiteList))
|
||||
#define GIMP_IS_PARASITE_LIST(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_PARASITE_LIST))
|
||||
|
||||
/* Signals:
|
||||
add
|
||||
|
@ -55,4 +57,5 @@ GimpParasite * parasite_list_find (ParasiteList *list,
|
|||
|
||||
void parasite_shift_parent (GimpParasite *parasite);
|
||||
|
||||
|
||||
#endif /* __PARASITE_LIST_H__ */
|
||||
|
|
|
@ -15,30 +15,30 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __BRUSH_HEADER_H__
|
||||
#define __BRUSH_HEADER_H__
|
||||
|
||||
typedef struct _BrushHeader BrushHeader;
|
||||
|
||||
#define GBRUSH_FILE_VERSION 2
|
||||
#define GBRUSH_MAGIC (('G' << 24) + ('I' << 16) + ('M' << 8) + ('P' << 0))
|
||||
#define sz_BrushHeader (sizeof (BrushHeader))
|
||||
|
||||
/* All field entries are MSB */
|
||||
|
||||
typedef struct _BrushHeader BrushHeader;
|
||||
|
||||
struct _BrushHeader
|
||||
{
|
||||
unsigned int header_size; /* header_size = sz_BrushHeader + brush name */
|
||||
unsigned int version; /* brush file version # */
|
||||
unsigned int width; /* width of brush */
|
||||
unsigned int height; /* height of brush */
|
||||
unsigned int bytes; /* depth of brush in bytes--always 1 */
|
||||
unsigned int magic_number;/* GIMP brush magic number */
|
||||
unsigned int spacing; /* brush spacing */
|
||||
guint header_size; /* header_size = sizeof (BrushHeader) + brush name */
|
||||
guint version; /* brush file version # */
|
||||
guint width; /* width of brush */
|
||||
guint height; /* height of brush */
|
||||
guint bytes; /* depth of brush in bytes--always 1 */
|
||||
guint magic_number; /* GIMP brush magic number */
|
||||
guint spacing; /* brush spacing */
|
||||
};
|
||||
|
||||
/* In a brush file, next comes the brush name, null-terminated. After that
|
||||
* comes the brush data--width * height * bytes bytes of it...
|
||||
*/
|
||||
|
||||
#endif /* __BRUSH_HEADER_H__ */
|
||||
#endif /* ! __BRUSH_HEADER_H__ */
|
||||
|
|
|
@ -47,15 +47,14 @@ gimp_brush_destroy (GtkObject *object)
|
|||
{
|
||||
GimpBrush *brush = GIMP_BRUSH (object);
|
||||
|
||||
if (brush->filename)
|
||||
g_free (brush->filename);
|
||||
if (brush->name)
|
||||
g_free (brush->name);
|
||||
g_free (brush->filename);
|
||||
g_free (brush->name);
|
||||
|
||||
if (brush->mask)
|
||||
temp_buf_free (brush->mask);
|
||||
|
||||
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
||||
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -116,6 +115,7 @@ gimp_brush_get_type (void)
|
|||
/* reserved_2 */ NULL,
|
||||
(GtkClassInitFunc) NULL
|
||||
};
|
||||
|
||||
type = gtk_type_unique (gimp_object_get_type (), &info);
|
||||
}
|
||||
return type;
|
||||
|
@ -126,7 +126,10 @@ gimp_brush_new (gchar *filename)
|
|||
{
|
||||
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
|
||||
|
||||
return (gimp_brush_load (brush, filename)? brush : NULL);
|
||||
if (gimp_brush_load (brush, filename))
|
||||
return brush;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GimpBrush *
|
||||
|
@ -144,6 +147,7 @@ gimp_brush_want_null_motion (PaintCore *paint_core)
|
|||
TempBuf *
|
||||
gimp_brush_get_mask (GimpBrush *brush)
|
||||
{
|
||||
g_return_val_if_fail (brush != NULL, NULL);
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
|
||||
|
||||
return brush->mask;
|
||||
|
@ -152,6 +156,7 @@ gimp_brush_get_mask (GimpBrush *brush)
|
|||
gchar *
|
||||
gimp_brush_get_name (GimpBrush *brush)
|
||||
{
|
||||
g_return_val_if_fail (brush != NULL, NULL);
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
|
||||
|
||||
return brush->name;
|
||||
|
@ -161,10 +166,12 @@ void
|
|||
gimp_brush_set_name (GimpBrush *brush,
|
||||
gchar *name)
|
||||
{
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH (brush));
|
||||
|
||||
if (strcmp (brush->name, name) == 0)
|
||||
return;
|
||||
|
||||
if (brush->name)
|
||||
g_free (brush->name);
|
||||
brush->name = g_strdup (name);
|
||||
|
@ -195,20 +202,23 @@ gboolean
|
|||
gimp_brush_load (GimpBrush *brush,
|
||||
gchar *filename)
|
||||
{
|
||||
FILE * fp;
|
||||
FILE *fp;
|
||||
|
||||
brush->filename = g_strdup (filename);
|
||||
|
||||
/* Open the requested file */
|
||||
if (! (fp = fopen (filename, "rb")))
|
||||
{
|
||||
gimp_object_destroy (brush);
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! gimp_brush_load_brush (brush, fp, filename))
|
||||
{
|
||||
fclose (fp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gimp_brush_load_brush (brush, fp, filename))
|
||||
return FALSE;
|
||||
|
||||
/* Clean up */
|
||||
fclose (fp);
|
||||
|
||||
|
@ -219,39 +229,37 @@ gimp_brush_load (GimpBrush *brush,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
gboolean
|
||||
gimp_brush_load_brush (GimpBrush *brush,
|
||||
FILE *fp,
|
||||
gchar *filename)
|
||||
{
|
||||
gint bn_size;
|
||||
guchar buf [sz_BrushHeader];
|
||||
guchar buf [sizeof (BrushHeader)];
|
||||
BrushHeader header;
|
||||
guint *hp;
|
||||
gint i;
|
||||
|
||||
/* Read in the header size */
|
||||
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
|
||||
if ((fread (buf, 1, sizeof (BrushHeader), fp)) < sizeof (BrushHeader))
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* rearrange the bytes in each unsigned int */
|
||||
hp = (guint *) &header;
|
||||
for (i = 0; i < (sz_BrushHeader / 4); i++)
|
||||
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
|
||||
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
|
||||
for (i = 0; i < (sizeof (BrushHeader) / 4); i++)
|
||||
hp [i] = ((buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
|
||||
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]));
|
||||
|
||||
/* Check for correct file format */
|
||||
if (header.magic_number != GBRUSH_MAGIC)
|
||||
{
|
||||
if (header.version != 1)
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,19 +273,20 @@ gimp_brush_load_brush (GimpBrush *brush,
|
|||
}
|
||||
|
||||
/* Read in the brush name */
|
||||
if ((bn_size = (header.header_size - sz_BrushHeader)))
|
||||
{
|
||||
brush->name = g_new (gchar, bn_size);
|
||||
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
|
||||
{
|
||||
g_message (_("Error in GIMP brush file...aborting."));
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((bn_size = (header.header_size - sizeof (BrushHeader))))
|
||||
{
|
||||
brush->name = g_new (gchar, bn_size);
|
||||
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
|
||||
{
|
||||
g_message (_("Error in GIMP brush file...aborting."));
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
brush->name = g_strdup (_("Unnamed"));
|
||||
{
|
||||
brush->name = g_strdup (_("Unnamed"));
|
||||
}
|
||||
|
||||
switch (header.version)
|
||||
{
|
||||
|
@ -293,16 +302,18 @@ gimp_brush_load_brush (GimpBrush *brush,
|
|||
brush->y_axis.x = 0.0;
|
||||
brush->y_axis.y = header.height / 2.0;
|
||||
/* Read the brush mask data */
|
||||
if ((fread (temp_buf_data (brush->mask), 1, header.width * header.height,
|
||||
fp)) < header.width * header.height)
|
||||
if ((fread (temp_buf_data (brush->mask),
|
||||
1, header.width * header.height, fp)) <
|
||||
header.width * header.height)
|
||||
g_message (_("GIMP brush file appears to be truncated."));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
|
||||
header.version, filename);
|
||||
fclose (fp);
|
||||
gimp_object_destroy (brush);
|
||||
return 0;
|
||||
gtk_object_sink (GTK_OBJECT (brush));
|
||||
return FALSE;
|
||||
}
|
||||
return 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef __GIMPBRUSH_H__
|
||||
#define __GIMPBRUSH_H__
|
||||
|
||||
#ifndef __GIMP_BRUSH_H__
|
||||
#define __GIMP_BRUSH_H__
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -41,23 +43,23 @@ struct _GimpBrush
|
|||
|
||||
struct _GimpBrushClass
|
||||
{
|
||||
GimpObjectClass parent_class;
|
||||
GimpObjectClass parent_class;
|
||||
|
||||
GimpBrush * (* select_brush) (PaintCore *paint_core);
|
||||
gboolean (* want_null_motion) (PaintCore *paint_core);
|
||||
GimpBrush * (* select_brush) (PaintCore *paint_core);
|
||||
gboolean (* want_null_motion) (PaintCore *paint_core);
|
||||
};
|
||||
|
||||
#define GIMP_BRUSH_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gimp_brush_get_type(), GimpBrushClass)
|
||||
#define GIMP_TYPE_BRUSH (gimp_brush_get_type ())
|
||||
#define GIMP_BRUSH(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH, GimpBrush))
|
||||
#define GIMP_IS_BRUSH(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH))
|
||||
#define GIMP_BRUSH(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH, GimpBrush))
|
||||
#define GIMP_IS_BRUSH(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH))
|
||||
|
||||
GtkType gimp_brush_get_type (void);
|
||||
GimpBrush * gimp_brush_new (gchar *filename);
|
||||
|
||||
gboolean gimp_brush_load (GimpBrush *brush,
|
||||
gchar *filename);
|
||||
gint gimp_brush_load_brush (GimpBrush *brush,
|
||||
gboolean gimp_brush_load_brush (GimpBrush *brush,
|
||||
FILE *fp,
|
||||
gchar *filename);
|
||||
|
||||
|
@ -71,4 +73,5 @@ gint gimp_brush_get_spacing (GimpBrush *brush);
|
|||
void gimp_brush_set_spacing (GimpBrush *brush,
|
||||
gint spacing);
|
||||
|
||||
#endif /* __GIMPBRUSH_H__ */
|
||||
|
||||
#endif /* __GIMP_BRUSH_H__ */
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -36,9 +37,12 @@
|
|||
|
||||
#define OVERSAMPLING 5
|
||||
|
||||
|
||||
static void gimp_brush_generated_generate (GimpBrushGenerated *brush);
|
||||
|
||||
static GimpObjectClass *parent_class;
|
||||
|
||||
static GimpObjectClass *parent_class = NULL;
|
||||
|
||||
|
||||
static void
|
||||
gimp_brush_generated_destroy (GtkObject *object)
|
||||
|
@ -55,6 +59,7 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass)
|
|||
object_class = GTK_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = gtk_type_class (GIMP_TYPE_BRUSH);
|
||||
|
||||
object_class->destroy = gimp_brush_generated_destroy;
|
||||
}
|
||||
|
||||
|
@ -103,7 +108,7 @@ gimp_brush_generated_new (gfloat radius,
|
|||
|
||||
/* set up normal brush data */
|
||||
brush =
|
||||
GIMP_BRUSH_GENERATED (gimp_type_new (gimp_brush_generated_get_type ()));
|
||||
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
|
||||
|
||||
GIMP_BRUSH (brush)->name = g_strdup ("Untitled");
|
||||
GIMP_BRUSH (brush)->spacing = 20;
|
||||
|
@ -145,7 +150,7 @@ gimp_brush_generated_load (const gchar *file_name)
|
|||
|
||||
/* create new brush */
|
||||
brush =
|
||||
GIMP_BRUSH_GENERATED (gimp_type_new (gimp_brush_generated_get_type ()));
|
||||
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
|
||||
|
||||
GIMP_BRUSH (brush)->filename = g_strdup (file_name);
|
||||
|
||||
|
@ -153,8 +158,8 @@ gimp_brush_generated_load (const gchar *file_name)
|
|||
|
||||
/* read name */
|
||||
fgets (string, 255, fp);
|
||||
if (string[strlen (string)-1] == '\n')
|
||||
string[strlen (string)-1] = 0;
|
||||
if (string[strlen (string) - 1] == '\n')
|
||||
string[strlen (string) - 1] = 0;
|
||||
GIMP_BRUSH (brush)->name = g_strdup (string);
|
||||
|
||||
/* read brush spacing */
|
||||
|
@ -240,7 +245,7 @@ gimp_brush_generated_freeze (GimpBrushGenerated *brush)
|
|||
{
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
||||
|
||||
|
||||
brush->freeze++;
|
||||
}
|
||||
|
||||
|
@ -263,11 +268,13 @@ gauss (gdouble f)
|
|||
/* this aint' a real gauss function */
|
||||
if (f < -.5)
|
||||
{
|
||||
f = -1.0-f;
|
||||
f = -1.0 - f;
|
||||
return (2.0 * f*f);
|
||||
}
|
||||
|
||||
if (f < .5)
|
||||
return (1.0 - 2.0 * f*f);
|
||||
|
||||
f = 1.0 -f;
|
||||
return (2.0 * f*f);
|
||||
}
|
||||
|
@ -276,16 +283,16 @@ void
|
|||
gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
||||
{
|
||||
register GimpBrush *gbrush = NULL;
|
||||
register gint x, y;
|
||||
register guchar *centerp;
|
||||
register gdouble d;
|
||||
register gdouble exponent;
|
||||
register guchar a;
|
||||
register gint length;
|
||||
register guchar *lookup;
|
||||
register gint x, y;
|
||||
register guchar *centerp;
|
||||
register gdouble d;
|
||||
register gdouble exponent;
|
||||
register guchar a;
|
||||
register gint length;
|
||||
register guchar *lookup;
|
||||
register gdouble sum, c, s, tx, ty;
|
||||
gdouble buffer[OVERSAMPLING];
|
||||
register gdouble sum, c, s, tx, ty;
|
||||
gint width, height;
|
||||
gint width, height;
|
||||
|
||||
g_return_if_fail (brush != NULL);
|
||||
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
||||
|
@ -302,9 +309,11 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
{
|
||||
temp_buf_free(gbrush->mask);
|
||||
}
|
||||
|
||||
/* compute the range of the brush. should do a better job than this? */
|
||||
s = sin (gimp_deg_to_rad (brush->angle));
|
||||
c = cos (gimp_deg_to_rad (brush->angle));
|
||||
|
||||
tx = MAX (fabs (c*ceil (brush->radius) - s*ceil (brush->radius)
|
||||
/ brush->aspect_ratio),
|
||||
fabs (c*ceil (brush->radius) + s*ceil (brush->radius)
|
||||
|
@ -313,53 +322,60 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
/ brush->aspect_ratio),
|
||||
fabs (s*ceil (brush->radius) - c*ceil (brush->radius)
|
||||
/ brush->aspect_ratio));
|
||||
|
||||
if (brush->radius > tx)
|
||||
width = ceil (tx);
|
||||
else
|
||||
width = ceil (brush->radius);
|
||||
|
||||
if (brush->radius > ty)
|
||||
height = ceil (ty);
|
||||
else
|
||||
height = ceil (brush->radius);
|
||||
/* compute the axis for spacing */
|
||||
GIMP_BRUSH (brush)->x_axis.x = c*brush->radius;
|
||||
GIMP_BRUSH (brush)->x_axis.y = -1.0*s*brush->radius;
|
||||
|
||||
GIMP_BRUSH (brush)->y_axis.x = (s*brush->radius / brush->aspect_ratio);
|
||||
GIMP_BRUSH (brush)->y_axis.y = (c*brush->radius / brush->aspect_ratio);
|
||||
/* compute the axis for spacing */
|
||||
GIMP_BRUSH (brush)->x_axis.x = c * brush->radius;
|
||||
GIMP_BRUSH (brush)->x_axis.y = -1.0 * s * brush->radius;
|
||||
|
||||
GIMP_BRUSH (brush)->y_axis.x = (s * brush->radius / brush->aspect_ratio);
|
||||
GIMP_BRUSH (brush)->y_axis.y = (c * brush->radius / brush->aspect_ratio);
|
||||
|
||||
gbrush->mask = temp_buf_new (width*2 + 1,
|
||||
height*2 + 1,
|
||||
gbrush->mask = temp_buf_new (width * 2 + 1,
|
||||
height * 2 + 1,
|
||||
1, width, height, 0);
|
||||
centerp = &gbrush->mask->data[height*gbrush->mask->width + width];
|
||||
centerp = &gbrush->mask->data[height * gbrush->mask->width + width];
|
||||
|
||||
if ((1.0 - brush->hardness) < 0.000001)
|
||||
exponent = 1000000;
|
||||
else
|
||||
exponent = 1/(1.0 - brush->hardness);
|
||||
|
||||
/* set up lookup table */
|
||||
length = ceil (sqrt (2*ceil (brush->radius+1)*ceil (brush->radius+1))+1) * OVERSAMPLING;
|
||||
length = ceil (sqrt (2 * ceil (brush->radius+1) * ceil (brush->radius+1))+1) * OVERSAMPLING;
|
||||
lookup = g_malloc (length);
|
||||
sum = 0.0;
|
||||
|
||||
for (x = 0; x < OVERSAMPLING; x++)
|
||||
{
|
||||
d = fabs ((x+.5)/OVERSAMPLING - .5);
|
||||
if (d > brush->radius)
|
||||
buffer[x] = 0.0;
|
||||
else
|
||||
/* buffer[x] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x];
|
||||
}
|
||||
for (x = 0; d < brush->radius || sum > .00001; d += 1.0/OVERSAMPLING)
|
||||
{
|
||||
sum -= buffer[x%OVERSAMPLING];
|
||||
d = fabs ((x + 0.5) / OVERSAMPLING - 0.5);
|
||||
if (d > brush->radius)
|
||||
buffer[x%OVERSAMPLING] = 0.0;
|
||||
buffer[x] = 0.0;
|
||||
else
|
||||
/* buffer[x] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x];
|
||||
}
|
||||
|
||||
for (x = 0; d < brush->radius || sum > 0.00001; d += 1.0 / OVERSAMPLING)
|
||||
{
|
||||
sum -= buffer[x % OVERSAMPLING];
|
||||
if (d > brush->radius)
|
||||
buffer[x % OVERSAMPLING] = 0.0;
|
||||
else
|
||||
/* buffer[x%OVERSAMPLING] = (1.0 - pow (d/brush->radius, exponent)); */
|
||||
buffer[x%OVERSAMPLING] = gauss (pow (d/brush->radius, exponent));
|
||||
buffer[x % OVERSAMPLING] = gauss (pow (d/brush->radius, exponent));
|
||||
sum += buffer[x%OVERSAMPLING];
|
||||
lookup[x++] = RINT (sum*(255.0/OVERSAMPLING));
|
||||
lookup[x++] = RINT (sum * (255.0 / OVERSAMPLING));
|
||||
}
|
||||
while (x < length)
|
||||
{
|
||||
|
@ -375,7 +391,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
ty *= brush->aspect_ratio;
|
||||
d = sqrt (tx*tx + ty*ty);
|
||||
if (d < brush->radius+1)
|
||||
a = lookup[(int)RINT(d*OVERSAMPLING)];
|
||||
a = lookup[(gint) RINT (d * OVERSAMPLING)];
|
||||
else
|
||||
a = 0;
|
||||
centerp[ y*gbrush->mask->width + x] = a;
|
||||
|
@ -383,6 +399,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
|
|||
}
|
||||
}
|
||||
g_free (lookup);
|
||||
|
||||
gtk_signal_emit_by_name (GTK_OBJECT (brush), "dirty");
|
||||
}
|
||||
|
||||
|
@ -396,11 +413,15 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
|
|||
radius = 0.0;
|
||||
else if (radius > 32767.0)
|
||||
radius = 32767.0;
|
||||
|
||||
if (radius == brush->radius)
|
||||
return radius;
|
||||
|
||||
brush->radius = radius;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->radius;
|
||||
}
|
||||
|
||||
|
@ -412,13 +433,17 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
|
|||
|
||||
if (hardness < 0.0)
|
||||
hardness = 0.0;
|
||||
else if(hardness > 1.0)
|
||||
else if (hardness > 1.0)
|
||||
hardness = 1.0;
|
||||
|
||||
if (brush->hardness == hardness)
|
||||
return hardness;
|
||||
|
||||
brush->hardness = hardness;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->hardness;
|
||||
}
|
||||
|
||||
|
@ -430,13 +455,17 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
|
|||
|
||||
if (angle < 0.0)
|
||||
angle = -1.0 * fmod (angle, 180.0);
|
||||
else if(angle > 180.0)
|
||||
else if (angle > 180.0)
|
||||
angle = fmod (angle, 180.0);
|
||||
|
||||
if (brush->angle == angle)
|
||||
return angle;
|
||||
|
||||
brush->angle = angle;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate (brush);
|
||||
|
||||
return brush->angle;
|
||||
}
|
||||
|
||||
|
@ -448,13 +477,17 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
|
|||
|
||||
if (ratio < 1.0)
|
||||
ratio = 1.0;
|
||||
else if(ratio > 1000)
|
||||
else if (ratio > 1000)
|
||||
ratio = 1000;
|
||||
|
||||
if (brush->aspect_ratio == ratio)
|
||||
return ratio;
|
||||
|
||||
brush->aspect_ratio = ratio;
|
||||
|
||||
if (!brush->freeze)
|
||||
gimp_brush_generated_generate(brush);
|
||||
|
||||
return brush->aspect_ratio;
|
||||
}
|
||||
|
||||
|
@ -467,7 +500,7 @@ gimp_brush_generated_get_radius (const GimpBrushGenerated *brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_hardness (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
@ -475,7 +508,7 @@ gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_angle (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_angle (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
@ -483,7 +516,7 @@ gimp_brush_generated_get_angle (const GimpBrushGenerated* brush)
|
|||
}
|
||||
|
||||
gfloat
|
||||
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated* brush)
|
||||
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated *brush)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
||||
|
||||
|
|
|
@ -17,12 +17,21 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_BRUSH_GENERATED_H__
|
||||
#define __GIMP_BRUSH_GENERATED_H__
|
||||
|
||||
#include "gimpbrush.h"
|
||||
|
||||
typedef struct _GimpBrushGenerated
|
||||
|
||||
#define GIMP_TYPE_BRUSH_GENERATED (gimp_brush_generated_get_type ())
|
||||
#define GIMP_BRUSH_GENERATED(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_GENERATED, GimpBrushGenerated))
|
||||
#define GIMP_IS_BRUSH_GENERATED(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_GENERATED))
|
||||
|
||||
typedef struct _GimpBrushGenerated GimpBrushGenerated;
|
||||
typedef struct _GimpBrushGeneratedClass GimpBrushGeneratedClass;
|
||||
|
||||
struct _GimpBrushGenerated
|
||||
{
|
||||
GimpBrush gbrush;
|
||||
|
||||
|
@ -34,51 +43,42 @@ typedef struct _GimpBrushGenerated
|
|||
gint freeze;
|
||||
|
||||
/*GSpline *profile_curve */ /* Some lazy day... */
|
||||
} GimpBrushGenerated;
|
||||
};
|
||||
|
||||
typedef struct _GimpBrushGeneratedClass
|
||||
struct _GimpBrushGeneratedClass
|
||||
{
|
||||
GimpBrushClass parent_class;
|
||||
};
|
||||
|
||||
void (* generate) (GimpBrushGenerated *brush);
|
||||
} GimpBrushGeneratedClass;
|
||||
|
||||
/* object stuff */
|
||||
GtkType gimp_brush_generated_get_type (void);
|
||||
|
||||
#define GIMP_TYPE_BRUSH_GENERATED (gimp_brush_generated_get_type ())
|
||||
#define GIMP_BRUSH_GENERATED(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_GENERATED, GimpBrushGenerated))
|
||||
#define GIMP_IS_BRUSH_GENERATED(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_GENERATED))
|
||||
GimpBrushGenerated * gimp_brush_generated_new (gfloat radius,
|
||||
gfloat hardness,
|
||||
gfloat angle,
|
||||
gfloat aspect_ratio);
|
||||
GimpBrushGenerated * gimp_brush_generated_load (const gchar *file_name);
|
||||
|
||||
guint gimp_brush_generated_get_type (void);
|
||||
|
||||
/* normal stuff */
|
||||
|
||||
GimpBrushGenerated *gimp_brush_generated_new (gfloat radius,
|
||||
gfloat hardness,
|
||||
gfloat angle,
|
||||
gfloat aspect_ratio);
|
||||
|
||||
GimpBrushGenerated *gimp_brush_generated_load (const gchar *file_name);
|
||||
|
||||
void gimp_brush_generated_save (GimpBrushGenerated *brush,
|
||||
void gimp_brush_generated_save (GimpBrushGenerated *brush,
|
||||
const gchar *file_name);
|
||||
void gimp_brush_generated_delete (GimpBrushGenerated *brush);
|
||||
void gimp_brush_generated_delete (GimpBrushGenerated *brush);
|
||||
|
||||
void gimp_brush_generated_freeze (GimpBrushGenerated *brush);
|
||||
void gimp_brush_generated_thaw (GimpBrushGenerated *brush);
|
||||
void gimp_brush_generated_freeze (GimpBrushGenerated *brush);
|
||||
void gimp_brush_generated_thaw (GimpBrushGenerated *brush);
|
||||
|
||||
gfloat gimp_brush_generated_set_radius (GimpBrushGenerated* brush,
|
||||
gfloat gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
|
||||
gfloat radius);
|
||||
gfloat gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
|
||||
gfloat hardness);
|
||||
gfloat gimp_brush_generated_set_angle (GimpBrushGenerated* brush,
|
||||
gfloat gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
|
||||
gfloat angle);
|
||||
gfloat gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated* brush,
|
||||
gfloat gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
|
||||
gfloat ratio);
|
||||
|
||||
gfloat gimp_brush_generated_get_radius (const GimpBrushGenerated* brush);
|
||||
gfloat gimp_brush_generated_get_hardness (const GimpBrushGenerated* brush);
|
||||
gfloat gimp_brush_generated_get_angle (const GimpBrushGenerated* brush);
|
||||
gfloat gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated* brush);
|
||||
gfloat gimp_brush_generated_get_radius (const GimpBrushGenerated *brush);
|
||||
gfloat gimp_brush_generated_get_hardness (const GimpBrushGenerated *brush);
|
||||
gfloat gimp_brush_generated_get_angle (const GimpBrushGenerated *brush);
|
||||
gfloat gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated *brush);
|
||||
|
||||
|
||||
#endif /* __GIMP_BRUSH_GENERATED_H__ */
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -47,6 +48,7 @@
|
|||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
/* global variables */
|
||||
GimpBrushList *brush_list = NULL;
|
||||
|
||||
|
@ -57,8 +59,10 @@ static void brushes_brush_load (gchar *filename);
|
|||
static gint brush_compare_func (gconstpointer first,
|
||||
gconstpointer second);
|
||||
|
||||
|
||||
/* class functions */
|
||||
static GimpObjectClass* parent_class;
|
||||
static GimpObjectClass* parent_class = NULL;
|
||||
|
||||
|
||||
static void
|
||||
gimp_brush_list_add_func (GimpList *list,
|
||||
|
@ -82,7 +86,7 @@ gimp_brush_list_class_init (GimpBrushListClass *klass)
|
|||
{
|
||||
GimpListClass *gimp_list_class;
|
||||
|
||||
gimp_list_class = GIMP_LIST_CLASS(klass);
|
||||
gimp_list_class = GIMP_LIST_CLASS (klass);
|
||||
gimp_list_class->add = gimp_brush_list_add_func;
|
||||
gimp_list_class->remove = gimp_brush_list_remove_func;
|
||||
|
||||
|
@ -135,7 +139,7 @@ gimp_brush_list_new (void)
|
|||
|
||||
/* function declarations */
|
||||
void
|
||||
brushes_init (gint no_data)
|
||||
brushes_init (gboolean no_data)
|
||||
{
|
||||
if (brush_list)
|
||||
brushes_free ();
|
||||
|
@ -170,6 +174,7 @@ brushes_get_standard_brush (void)
|
|||
/* set ref_count to 2 --> never swap the standard brush */
|
||||
gtk_object_ref (GTK_OBJECT (standard_brush));
|
||||
gtk_object_ref (GTK_OBJECT (standard_brush));
|
||||
gtk_object_sink (GTK_OBJECT (standard_brush));
|
||||
}
|
||||
|
||||
return standard_brush;
|
||||
|
@ -181,7 +186,9 @@ brushes_brush_load (gchar *filename)
|
|||
if (strcmp (&filename[strlen (filename) - 4], ".gbr") == 0)
|
||||
{
|
||||
GimpBrush *brush;
|
||||
|
||||
brush = gimp_brush_new (filename);
|
||||
|
||||
if (brush != NULL)
|
||||
gimp_brush_list_add (brush_list, brush);
|
||||
else
|
||||
|
@ -190,7 +197,9 @@ brushes_brush_load (gchar *filename)
|
|||
else if (strcmp (&filename[strlen(filename) - 4], ".vbr") == 0)
|
||||
{
|
||||
GimpBrushGenerated *brush;
|
||||
|
||||
brush = gimp_brush_generated_load (filename);
|
||||
|
||||
if (brush != NULL)
|
||||
gimp_brush_list_add (brush_list, GIMP_BRUSH (brush));
|
||||
else
|
||||
|
@ -199,7 +208,9 @@ brushes_brush_load (gchar *filename)
|
|||
else if (strcmp (&filename[strlen (filename) - 4], ".gpb") == 0)
|
||||
{
|
||||
GimpBrushPipe *brush;
|
||||
|
||||
brush = gimp_brush_pixmap_load (filename);
|
||||
|
||||
if (brush != NULL)
|
||||
gimp_brush_list_add (brush_list, GIMP_BRUSH (brush));
|
||||
else
|
||||
|
@ -208,7 +219,9 @@ brushes_brush_load (gchar *filename)
|
|||
else if (strcmp (&filename[strlen (filename) - 4], ".gih") == 0)
|
||||
{
|
||||
GimpBrushPipe *brush;
|
||||
|
||||
brush = gimp_brush_pipe_load (filename);
|
||||
|
||||
if (brush != NULL)
|
||||
gimp_brush_list_add (brush_list, GIMP_BRUSH (brush));
|
||||
else
|
||||
|
@ -307,8 +320,8 @@ gint
|
|||
gimp_brush_list_get_brush_index (GimpBrushList *brush_list,
|
||||
GimpBrush *brush)
|
||||
{
|
||||
/* fix me: make a gimp_list function that does this? */
|
||||
return g_slist_index (GIMP_LIST(brush_list)->list, brush);
|
||||
/* FIXME: make a gimp_list function that does this? */
|
||||
return g_slist_index (GIMP_LIST (brush_list)->list, brush);
|
||||
}
|
||||
|
||||
GimpBrush *
|
||||
|
@ -318,7 +331,7 @@ gimp_brush_list_get_brush_by_index (GimpBrushList *brush_list,
|
|||
GimpBrush *brush = NULL;
|
||||
GSList *list;
|
||||
|
||||
/* fix me: make a gimp_list function that does this? */
|
||||
/* FIXME: make a gimp_list function that does this? */
|
||||
list = g_slist_nth (GIMP_LIST (brush_list)->list, index);
|
||||
if (list)
|
||||
brush = (GimpBrush *) list->data;
|
||||
|
@ -330,12 +343,13 @@ static void
|
|||
gimp_brush_list_uniquefy_brush_name (GimpBrushList *brush_list,
|
||||
GimpBrush *brush)
|
||||
{
|
||||
GSList *list, *listb;
|
||||
GSList *list;
|
||||
GSList *listb;
|
||||
GimpBrush *brushb;
|
||||
gint number = 1;
|
||||
gchar *newname;
|
||||
gchar *oldname;
|
||||
gchar *ext;
|
||||
gint number = 1;
|
||||
gchar *newname;
|
||||
gchar *oldname;
|
||||
gchar *ext;
|
||||
|
||||
g_return_if_fail (GIMP_IS_BRUSH_LIST (brush_list));
|
||||
g_return_if_fail (GIMP_IS_BRUSH (brush));
|
||||
|
@ -343,6 +357,7 @@ gimp_brush_list_uniquefy_brush_name (GimpBrushList *brush_list,
|
|||
for (list = GIMP_LIST (brush_list)->list; list; list = g_slist_next (list))
|
||||
{
|
||||
brushb = GIMP_BRUSH (list->data);
|
||||
|
||||
if (brush != brushb &&
|
||||
strcmp (gimp_brush_get_name (brush),
|
||||
gimp_brush_get_name (brushb)) == 0)
|
||||
|
@ -354,7 +369,8 @@ gimp_brush_list_uniquefy_brush_name (GimpBrushList *brush_list,
|
|||
strcpy (newname, oldname);
|
||||
if ((ext = strrchr (newname, '#')))
|
||||
{
|
||||
number = atoi (ext+1);
|
||||
number = atoi (ext + 1);
|
||||
|
||||
if (&ext[(gint)(log10 (number) + 1)] !=
|
||||
&newname[strlen (newname) - 1])
|
||||
{
|
||||
|
@ -367,10 +383,11 @@ gimp_brush_list_uniquefy_brush_name (GimpBrushList *brush_list,
|
|||
number = 1;
|
||||
ext = &newname[strlen (newname)];
|
||||
}
|
||||
sprintf (ext, "#%d", number+1);
|
||||
sprintf (ext, "#%d", number + 1);
|
||||
for (listb = GIMP_LIST (brush_list)->list; listb; listb = listb->next)
|
||||
{
|
||||
brushb = GIMP_BRUSH (listb->data);
|
||||
|
||||
if (brush != brushb &&
|
||||
strcmp (newname, gimp_brush_get_name (brushb)) == 0)
|
||||
{
|
||||
|
@ -407,7 +424,6 @@ gimp_brush_list_add (GimpBrushList *brush_list,
|
|||
{
|
||||
gimp_brush_list_uniquefy_brush_name (brush_list, brush);
|
||||
gimp_list_add (GIMP_LIST (brush_list), brush);
|
||||
gtk_object_unref (GTK_OBJECT (brush));
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "rename",
|
||||
GTK_SIGNAL_FUNC (brush_renamed),
|
||||
brush_list);
|
||||
|
|
|
@ -15,21 +15,25 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef __GIMPBRUSHLIST_H__
|
||||
#define __GIMPBRUSHLIST_H__
|
||||
|
||||
#ifndef __GIMP_BRUSH_LIST_H__
|
||||
#define __GIMP_BRUSH_LIST_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "gimpbrush.h"
|
||||
#include "gimpbrushlistF.h"
|
||||
|
||||
|
||||
#define GIMP_TYPE_BRUSH_LIST (gimp_brush_list_get_type ())
|
||||
#define GIMP_BRUSH_LIST(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_LIST, GimpBrushList))
|
||||
#define GIMP_IS_BRUSH_LIST(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_LIST))
|
||||
#define GIMP_BRUSH_LIST(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_LIST, GimpBrushList))
|
||||
#define GIMP_IS_BRUSH_LIST(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_LIST))
|
||||
|
||||
|
||||
/* global variables */
|
||||
extern GimpBrushList *brush_list;
|
||||
|
||||
|
||||
/* function declarations */
|
||||
GimpBrushList * gimp_brush_list_new (void);
|
||||
GtkType gimp_brush_list_get_type (void);
|
||||
|
@ -49,8 +53,9 @@ gint gimp_brush_list_get_brush_index (GimpBrushList *list,
|
|||
GimpBrush *brush);
|
||||
|
||||
|
||||
void brushes_init (gint no_data);
|
||||
void brushes_init (gboolean no_data);
|
||||
void brushes_free (void);
|
||||
GimpBrush * brushes_get_standard_brush (void);
|
||||
|
||||
#endif /* __GIMPBRUSHLIST_H__ */
|
||||
|
||||
#endif /* __GIMP_BRUSH_LIST_H__ */
|
||||
|
|
|
@ -293,14 +293,14 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
}
|
||||
buf[strlen (buf) - 1] = 0;
|
||||
|
||||
pipe = GIMP_BRUSH_PIPE (gimp_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
pipe = GIMP_BRUSH_PIPE (gtk_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
name = g_strdup (buf);
|
||||
|
||||
/* get the number of brushes */
|
||||
if (fgets (buf, 1024, fp) == NULL)
|
||||
{
|
||||
fclose (fp);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
num_of_brushes = strtol (buf, ¶mstring, 10);
|
||||
|
@ -308,7 +308,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
{
|
||||
g_message (_("Brush pipes should have at least one brush."));
|
||||
fclose (fp);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -389,7 +389,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
if (pipe->nbrushes > 0)
|
||||
{
|
||||
pipe->brushes[pipe->nbrushes] =
|
||||
GIMP_BRUSH_PIXMAP (gimp_type_new (GIMP_TYPE_BRUSH_PIXMAP));
|
||||
GIMP_BRUSH_PIXMAP (gtk_type_new (GIMP_TYPE_BRUSH_PIXMAP));
|
||||
g_free (GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name);
|
||||
GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name = NULL;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ gimp_brush_pipe_load (gchar *filename)
|
|||
"brushes in the brush pipe."));
|
||||
fclose (fp);
|
||||
pattern_free (pattern);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ gimp_brush_pixmap_load (gchar *filename)
|
|||
if ((fp = fopen (filename, "rb")) == NULL)
|
||||
return NULL;
|
||||
|
||||
pipe = GIMP_BRUSH_PIPE (gimp_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
pipe = GIMP_BRUSH_PIPE (gtk_type_new (GIMP_TYPE_BRUSH_PIPE));
|
||||
|
||||
/* A (single) pixmap brush is a pixmap pipe brush with just one pixmap */
|
||||
pipe->dimension = 1;
|
||||
|
@ -466,7 +466,7 @@ gimp_brush_pixmap_load (gchar *filename)
|
|||
g_message (_("Failed to load pixmap brush."));
|
||||
fclose (fp);
|
||||
pattern_free (pattern);
|
||||
gimp_object_destroy (pipe);
|
||||
gtk_object_sink (GTK_OBJECT (pipe));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,24 +17,28 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMPBRUSHPIPE_H__
|
||||
#define __GIMPBRUSHPIPE_H__
|
||||
#ifndef __GIMP_BRUSH_PIPE_H__
|
||||
#define __GIMP_BRUSH_PIPE_H__
|
||||
|
||||
|
||||
#include "tools.h"
|
||||
#include "paint_core.h"
|
||||
#include "gimpbrush.h"
|
||||
#include "temp_buf.h"
|
||||
|
||||
|
||||
typedef struct _GimpBrushPixmap GimpBrushPixmap;
|
||||
typedef struct _GimpBrushPipe GimpBrushPipe;
|
||||
|
||||
|
||||
#define GIMP_TYPE_BRUSH_PIXMAP (gimp_brush_pixmap_get_type ())
|
||||
#define GIMP_BRUSH_PIXMAP(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIXMAP, GimpBrushPixmap))
|
||||
#define GIMP_IS_BRUSH_PIXMAP(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIXMAP))
|
||||
#define GIMP_BRUSH_PIXMAP(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIXMAP, GimpBrushPixmap))
|
||||
#define GIMP_IS_BRUSH_PIXMAP(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIXMAP))
|
||||
|
||||
#define GIMP_TYPE_BRUSH_PIPE (gimp_brush_pipe_get_type ())
|
||||
#define GIMP_BRUSH_PIPE(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIPE, GimpBrushPipe))
|
||||
#define GIMP_IS_BRUSH_PIPE(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIPE))
|
||||
#define GIMP_BRUSH_PIPE(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIPE, GimpBrushPipe))
|
||||
#define GIMP_IS_BRUSH_PIPE(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIPE))
|
||||
|
||||
|
||||
GtkType gimp_brush_pixmap_get_type (void);
|
||||
GtkType gimp_brush_pipe_get_type (void);
|
||||
|
@ -44,10 +48,12 @@ GimpBrushPipe * gimp_brush_pixmap_load (gchar *filename);
|
|||
|
||||
TempBuf * gimp_brush_pixmap_pixmap (GimpBrushPixmap *brush);
|
||||
|
||||
|
||||
/* appearantly GIMP_IS_BRUSH_PIPE () returning TRUE is no indication
|
||||
* that you really have a brush_pipe in front of you, so here we introduce
|
||||
* a macro that works:
|
||||
*/
|
||||
#define GIMP_IS_REALLY_A_BRUSH_PIPE(obj) (GIMP_IS_BRUSH_PIPE (obj) && GIMP_BRUSH_PIPE (obj)->nbrushes > 1)
|
||||
|
||||
#endif /* __GIMPBRUSHPIPE_H__ */
|
||||
|
||||
#endif /* __GIMP_BRUSH_PIPE_H__ */
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_CONTEXT_H__
|
||||
#define __GIMP_CONTEXT_H__
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "apptypes.h"
|
||||
|
@ -32,10 +34,10 @@
|
|||
#include "gimpobjectP.h"
|
||||
|
||||
#define GIMP_TYPE_CONTEXT (gimp_context_get_type ())
|
||||
#define GIMP_CONTEXT(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_CONTEXT, GimpContext))
|
||||
#define GIMP_CONTEXT_CLASS(klass) (GIMP_CHECK_CLASS_CAST (klass, GIMP_TYPE_CONTEXT, GimpContextClass))
|
||||
#define GIMP_IS_CONTEXT(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_CONTEXT))
|
||||
#define GIMP_IS_CONTEXT_CLASS(klass) (GIMP_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTEXT))
|
||||
#define GIMP_CONTEXT(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_CONTEXT, GimpContext))
|
||||
#define GIMP_CONTEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST (klass, GIMP_TYPE_CONTEXT, GimpContextClass))
|
||||
#define GIMP_IS_CONTEXT(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_CONTEXT))
|
||||
#define GIMP_IS_CONTEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTEXT))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -288,4 +290,5 @@ void gimp_context_gradient_changed (GimpContext *context);
|
|||
void gimp_context_refresh_gradients (void);
|
||||
void gimp_context_update_gradients (gradient_t *gradient);
|
||||
|
||||
|
||||
#endif /* __GIMP_CONTEXT_H__ */
|
||||
|
|
103
app/gimplist.c
103
app/gimplist.c
|
@ -1,5 +1,5 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -15,11 +15,13 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gimpsignal.h"
|
||||
#include "gimplistP.h"
|
||||
|
||||
/* code mostly ripped from nether's gimpset class */
|
||||
/* code mostly ripped from nether's gimpset class */
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -28,42 +30,49 @@ enum
|
|||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint gimp_list_signals [LAST_SIGNAL];
|
||||
static guint gimp_list_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static GimpObjectClass* parent_class;
|
||||
static GimpObjectClass *parent_class = NULL;
|
||||
|
||||
|
||||
static void gimp_list_add_func (GimpList *list,
|
||||
gpointer object);
|
||||
static void gimp_list_remove_func (GimpList *list,
|
||||
gpointer object);
|
||||
|
||||
static void gimp_list_add_func (GimpList *list, void *);
|
||||
static void gimp_list_remove_func (GimpList *list, void *);
|
||||
|
||||
static void
|
||||
gimp_list_destroy (GtkObject* ob)
|
||||
gimp_list_destroy (GtkObject *object)
|
||||
{
|
||||
GimpList* list=GIMP_LIST (ob);
|
||||
GimpList *list = GIMP_LIST (object);
|
||||
|
||||
while (list->list) /* ought to put a sanity check in here... */
|
||||
{
|
||||
gimp_list_remove (list, list->list->data);
|
||||
}
|
||||
g_slist_free (list->list);
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (ob);
|
||||
|
||||
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_list_init (GimpList* list)
|
||||
gimp_list_init (GimpList *list)
|
||||
{
|
||||
list->list = NULL;
|
||||
list->type = GTK_TYPE_OBJECT;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_list_class_init (GimpListClass* klass)
|
||||
gimp_list_class_init (GimpListClass *klass)
|
||||
{
|
||||
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
|
||||
GtkType type = object_class->type;
|
||||
|
||||
parent_class = gtk_type_parent_class (type);
|
||||
|
||||
|
||||
object_class->destroy = gimp_list_destroy;
|
||||
|
||||
|
||||
gimp_list_signals[ADD]=
|
||||
gimp_signal_new ("add", GTK_RUN_FIRST, type, 0,
|
||||
gimp_sigtype_pointer);
|
||||
|
@ -94,11 +103,11 @@ gimp_list_get_type (void)
|
|||
return type;
|
||||
}
|
||||
|
||||
GimpList*
|
||||
GimpList *
|
||||
gimp_list_new (GtkType type,
|
||||
gboolean weak)
|
||||
{
|
||||
GimpList* list;
|
||||
GimpList *list;
|
||||
|
||||
list = gtk_type_new (gimp_list_get_type ());
|
||||
|
||||
|
@ -109,84 +118,94 @@ gimp_list_new (GtkType type,
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_list_destroy_cb (GtkObject *ob,
|
||||
gimp_list_destroy_cb (GtkObject *object,
|
||||
gpointer data)
|
||||
{
|
||||
GimpList* list;
|
||||
GimpList *list;
|
||||
|
||||
list = GIMP_LIST (data);
|
||||
|
||||
gimp_list_remove (list, ob);
|
||||
gimp_list_remove (list, object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_list_add_func (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
list->list = g_slist_prepend (list->list, val);
|
||||
list->list = g_slist_prepend (list->list, object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_list_remove_func (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
list->list = g_slist_remove (list->list, val);
|
||||
list->list = g_slist_remove (list->list, object);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_list_add (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
g_return_val_if_fail (list, FALSE);
|
||||
g_return_val_if_fail (GTK_CHECK_TYPE (val, list->type), FALSE);
|
||||
g_return_val_if_fail (GTK_CHECK_TYPE (object, list->type), FALSE);
|
||||
|
||||
if (g_slist_find (list->list, val))
|
||||
if (g_slist_find (list->list, object))
|
||||
return FALSE;
|
||||
|
||||
if (list->weak)
|
||||
gtk_signal_connect (GTK_OBJECT (val), "destroy",
|
||||
GTK_SIGNAL_FUNC (gimp_list_destroy_cb),
|
||||
list);
|
||||
{
|
||||
gtk_signal_connect (GTK_OBJECT (object), "destroy",
|
||||
GTK_SIGNAL_FUNC (gimp_list_destroy_cb),
|
||||
list);
|
||||
}
|
||||
else
|
||||
gtk_object_ref (GTK_OBJECT (val));
|
||||
{
|
||||
gtk_object_ref (GTK_OBJECT (object));
|
||||
gtk_object_sink (GTK_OBJECT (object));
|
||||
}
|
||||
|
||||
GIMP_LIST_CLASS (GTK_OBJECT (list)->klass)->add (list, val);
|
||||
GIMP_LIST_CLASS (GTK_OBJECT (list)->klass)->add (list, object);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT(list), gimp_list_signals[ADD], val);
|
||||
gtk_signal_emit (GTK_OBJECT(list), gimp_list_signals[ADD], object);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_list_remove (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
g_return_val_if_fail (list, FALSE);
|
||||
|
||||
if (!g_slist_find (list->list, val))
|
||||
if (!g_slist_find (list->list, object))
|
||||
{
|
||||
fprintf (stderr, "gimp_list_remove: can't find val\n");
|
||||
g_warning ("gimp_list_remove: can't find val");
|
||||
return FALSE;
|
||||
}
|
||||
GIMP_LIST_CLASS (GTK_OBJECT (list)->klass)->remove (list, val);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (list), gimp_list_signals[REMOVE], val);
|
||||
GIMP_LIST_CLASS (GTK_OBJECT (list)->klass)->remove (list, object);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (list), gimp_list_signals[REMOVE], object);
|
||||
|
||||
if (list->weak)
|
||||
gtk_signal_disconnect_by_func (GTK_OBJECT (val),
|
||||
GTK_SIGNAL_FUNC (gimp_list_destroy_cb),
|
||||
list);
|
||||
{
|
||||
gtk_signal_disconnect_by_func (GTK_OBJECT (object),
|
||||
GTK_SIGNAL_FUNC (gimp_list_destroy_cb),
|
||||
list);
|
||||
}
|
||||
else
|
||||
gtk_object_unref (GTK_OBJECT (val));
|
||||
{
|
||||
gtk_object_unref (GTK_OBJECT (object));
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_list_have (GimpList *list,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
return g_slist_find (list->list, val) ? TRUE : FALSE;
|
||||
return g_slist_find (list->list, object) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,22 +1,40 @@
|
|||
#ifndef __GIMPLIST_H__
|
||||
#define __GIMPLIST_H__
|
||||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_LIST_H__
|
||||
#define __GIMP_LIST_H__
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
#include "gimplistF.h"
|
||||
|
||||
|
||||
/* GimpList - a typed list of objects with signals for adding and
|
||||
removing of stuff. If it is weak, destroyed objects get removed
|
||||
automatically. If it is not, it refs them so they won't be freed
|
||||
till they are removed. (Though they can be destroyed, of course) */
|
||||
|
||||
#define GIMP_TYPE_LIST gimp_list_get_type()
|
||||
|
||||
#define GIMP_LIST(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_LIST, GimpList)
|
||||
* removing of stuff. If it is weak, destroyed objects get removed
|
||||
* automatically. If it is not, it refs them so they won't be freed
|
||||
* till they are removed. (Though they can be destroyed, of course)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define GIMP_TYPE_LIST gimp_list_get_type ()
|
||||
#define GIMP_LIST(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_LIST, GimpList)
|
||||
#define GIMP_IS_LIST(obj) GTK_CHECK_TYPE (obj, gimp_list_get_type())
|
||||
|
||||
|
||||
/* Signals:
|
||||
add
|
||||
|
@ -24,15 +42,22 @@
|
|||
*/
|
||||
|
||||
|
||||
guint gimp_list_get_type (void);
|
||||
GtkType gimp_list_get_type (void);
|
||||
|
||||
GimpList* gimp_list_new (GtkType type, gboolean weak);
|
||||
GtkType gimp_list_type (GimpList* list);
|
||||
gboolean gimp_list_add (GimpList* gimplist, gpointer ob);
|
||||
gboolean gimp_list_remove (GimpList* gimplist, gpointer ob);
|
||||
gboolean gimp_list_have (GimpList* gimplist, gpointer ob);
|
||||
void gimp_list_foreach(GimpList* gimplist, GFunc func,
|
||||
gpointer user_data);
|
||||
gint gimp_list_size (GimpList* gimplist);
|
||||
GimpList * gimp_list_new (GtkType type,
|
||||
gboolean weak);
|
||||
|
||||
#endif
|
||||
GtkType gimp_list_type (GimpList *list);
|
||||
gboolean gimp_list_add (GimpList *list,
|
||||
gpointer object);
|
||||
gboolean gimp_list_remove (GimpList *list,
|
||||
gpointer object);
|
||||
gboolean gimp_list_have (GimpList *list,
|
||||
gpointer object);
|
||||
void gimp_list_foreach (GimpList *list,
|
||||
GFunc func,
|
||||
gpointer user_data);
|
||||
gint gimp_list_size (GimpList *list);
|
||||
|
||||
|
||||
#endif /* __GIMP_LIST_H__ */
|
||||
|
|
|
@ -1,12 +1,30 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "gimpobjectP.h"
|
||||
|
||||
static void
|
||||
gimp_object_init (GimpObject *gobject)
|
||||
gimp_object_init (GimpObject *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_object_class_init (GimpObjectClass *gobjectclass)
|
||||
gimp_object_class_init (GimpObjectClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -14,16 +32,13 @@ GtkType
|
|||
gimp_object_get_type (void)
|
||||
{
|
||||
static GtkType type = 0;
|
||||
GIMP_TYPE_INIT(type,
|
||||
GimpObject,
|
||||
GimpObjectClass,
|
||||
gimp_object_init,
|
||||
gimp_object_class_init,
|
||||
GTK_TYPE_OBJECT);
|
||||
|
||||
GIMP_TYPE_INIT (type,
|
||||
GimpObject,
|
||||
GimpObjectClass,
|
||||
gimp_object_init,
|
||||
gimp_object_class_init,
|
||||
GTK_TYPE_OBJECT);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,29 +1,36 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_OBJECT_H__
|
||||
#define __GIMP_OBJECT_H__
|
||||
|
||||
|
||||
#include <gtk/gtktypeutils.h>
|
||||
|
||||
#include "gimpobjectF.h"
|
||||
|
||||
#define GIMP_TYPE_OBJECT gimp_object_get_type()
|
||||
|
||||
#define GIMP_OBJECT(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_OBJECT, GimpObject)
|
||||
|
||||
#define GIMP_TYPE_OBJECT gimp_object_get_type ()
|
||||
#define GIMP_OBJECT(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_OBJECT, GimpObject)
|
||||
#define GIMP_IS_OBJECT(obj) GTK_CHECK_TYPE (obj, GIMP_TYPE_OBJECT)
|
||||
|
||||
|
||||
guint gimp_object_get_type(void);
|
||||
|
||||
/* hacks to fake a gimp object lib */
|
||||
#define GIMP_CHECK_CAST GTK_CHECK_CAST
|
||||
#define GIMP_CHECK_TYPE GTK_CHECK_TYPE
|
||||
#define gimp_type_new gtk_type_new
|
||||
#define gimp_object_destroy(obj) gtk_object_destroy(GTK_OBJECT(obj))
|
||||
#define gimp_object_ref(obj) gtk_object_ref(GTK_OBJECT(obj))
|
||||
#define gimp_object_unref(obj) gtk_object_unref(GTK_OBJECT(obj))
|
||||
|
||||
#endif
|
||||
GtkType gimp_object_get_type (void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* __GIMP_OBJECT_H__ */
|
||||
|
|
106
app/gimpset.c
106
app/gimpset.c
|
@ -1,5 +1,5 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -43,19 +43,22 @@ enum
|
|||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static Node * gimp_set_find_node (GimpSet* set, gpointer object);
|
||||
static Node * gimp_set_node_new (GimpSet* set, gpointer obbject);
|
||||
static void gimp_set_node_free (GimpSet* set, Node* node);
|
||||
static Node * gimp_set_find_node (GimpSet *set,
|
||||
gpointer object);
|
||||
static Node * gimp_set_node_new (GimpSet *set,
|
||||
gpointer object);
|
||||
static void gimp_set_node_free (GimpSet *set,
|
||||
Node *node);
|
||||
|
||||
static guint gimp_set_signals [LAST_SIGNAL];
|
||||
static guint gimp_set_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static GimpObjectClass* parent_class;
|
||||
static GimpObjectClass *parent_class = NULL;
|
||||
|
||||
static void
|
||||
gimp_set_destroy (GtkObject* object)
|
||||
gimp_set_destroy (GtkObject *object)
|
||||
{
|
||||
GimpSet* set = GIMP_SET (object);
|
||||
GSList* list;
|
||||
GimpSet *set = GIMP_SET (object);
|
||||
GSList *list;
|
||||
|
||||
for (list = set->list; list; list = list->next)
|
||||
gimp_set_node_free (set, list->data);
|
||||
|
@ -64,15 +67,15 @@ gimp_set_destroy (GtkObject* object)
|
|||
g_array_free (set->handlers, TRUE);
|
||||
|
||||
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
||||
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_set_init (GimpSet* set)
|
||||
gimp_set_init (GimpSet *set)
|
||||
{
|
||||
set->list = NULL;
|
||||
set->type = GTK_TYPE_OBJECT;
|
||||
set->handlers = g_array_new (FALSE, FALSE, sizeof (GimpSetHandler));
|
||||
set->list = NULL;
|
||||
set->type = GTK_TYPE_OBJECT;
|
||||
set->handlers = g_array_new (FALSE, FALSE, sizeof (GimpSetHandler));
|
||||
set->active_element = NULL;
|
||||
}
|
||||
|
||||
|
@ -123,20 +126,20 @@ gimp_set_get_type (void)
|
|||
{
|
||||
static GtkType gimpset_type = 0;
|
||||
|
||||
GIMP_TYPE_INIT(gimpset_type,
|
||||
GimpSet,
|
||||
GimpSetClass,
|
||||
gimp_set_init,
|
||||
gimp_set_class_init,
|
||||
GIMP_TYPE_OBJECT);
|
||||
GIMP_TYPE_INIT (gimpset_type,
|
||||
GimpSet,
|
||||
GimpSetClass,
|
||||
gimp_set_init,
|
||||
gimp_set_class_init,
|
||||
GIMP_TYPE_OBJECT);
|
||||
|
||||
return gimpset_type;
|
||||
}
|
||||
|
||||
|
||||
GimpSet *
|
||||
gimp_set_new (GtkType type,
|
||||
gboolean weak)
|
||||
gimp_set_new (GtkType type,
|
||||
gboolean weak)
|
||||
{
|
||||
GimpSet *set;
|
||||
|
||||
|
@ -167,7 +170,7 @@ gimp_set_find_node (GimpSet *set,
|
|||
{
|
||||
GSList *list = set->list;
|
||||
|
||||
for(list = set->list; list; list = list->next)
|
||||
for (list = set->list; list; list = list->next)
|
||||
{
|
||||
Node *node = list->data;
|
||||
|
||||
|
@ -178,7 +181,7 @@ gimp_set_find_node (GimpSet *set,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static Node*
|
||||
static Node *
|
||||
gimp_set_node_new (GimpSet *set,
|
||||
gpointer object)
|
||||
{
|
||||
|
@ -196,17 +199,17 @@ gimp_set_node_new (GimpSet *set,
|
|||
|
||||
if (handler->signame)
|
||||
g_array_index (node->handlers, guint, i)
|
||||
= gtk_signal_connect (GTK_OBJECT(object),
|
||||
= gtk_signal_connect (GTK_OBJECT (object),
|
||||
handler->signame,
|
||||
handler->func,
|
||||
handler->user_data);
|
||||
}
|
||||
|
||||
if(set->weak)
|
||||
if (set->weak)
|
||||
node->destroy_handler =
|
||||
gtk_signal_connect(GTK_OBJECT (object), "destroy",
|
||||
GTK_SIGNAL_FUNC (gimp_set_destroy_cb),
|
||||
set);
|
||||
gtk_signal_connect (GTK_OBJECT (object), "destroy",
|
||||
GTK_SIGNAL_FUNC (gimp_set_destroy_cb),
|
||||
set);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
@ -218,9 +221,9 @@ gimp_set_node_free (GimpSet *set,
|
|||
gint i;
|
||||
GimpObject *object = node->object;
|
||||
|
||||
for (i=0; i < set->handlers->len; i++)
|
||||
for (i = 0; i < set->handlers->len; i++)
|
||||
{
|
||||
GimpSetHandler* handler =
|
||||
GimpSetHandler *handler =
|
||||
&g_array_index (set->handlers, GimpSetHandler, i);
|
||||
|
||||
if (handler->signame)
|
||||
|
@ -238,47 +241,47 @@ gimp_set_node_free (GimpSet *set,
|
|||
|
||||
gboolean
|
||||
gimp_set_add (GimpSet *set,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
g_return_val_if_fail (set, FALSE);
|
||||
|
||||
if (set->type != GTK_TYPE_NONE)
|
||||
g_return_val_if_fail (GTK_CHECK_TYPE (val, set->type), FALSE);
|
||||
|
||||
if (gimp_set_find_node (set, val))
|
||||
return FALSE;
|
||||
|
||||
set->list = g_slist_prepend (set->list, gimp_set_node_new (set, val));
|
||||
g_return_val_if_fail (GTK_CHECK_TYPE (object, set->type), FALSE);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (set), gimp_set_signals[ADD], val);
|
||||
if (gimp_set_find_node (set, object))
|
||||
return FALSE;
|
||||
|
||||
set->list = g_slist_prepend (set->list, gimp_set_node_new (set, object));
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (set), gimp_set_signals[ADD], object);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_set_remove (GimpSet *set,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
Node *node;
|
||||
|
||||
|
||||
g_return_val_if_fail (set, FALSE);
|
||||
|
||||
node = gimp_set_find_node (set, val);
|
||||
node = gimp_set_find_node (set, object);
|
||||
g_return_val_if_fail (node, FALSE);
|
||||
|
||||
gimp_set_node_free (set, node);
|
||||
set->list = g_slist_remove (set->list, node);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (set), gimp_set_signals[REMOVE], val);
|
||||
gtk_signal_emit (GTK_OBJECT (set), gimp_set_signals[REMOVE], object);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_set_have (GimpSet *set,
|
||||
gpointer val)
|
||||
gpointer object)
|
||||
{
|
||||
return !!gimp_set_find_node (set, val);
|
||||
return !!gimp_set_find_node (set, object);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -286,7 +289,7 @@ gimp_set_foreach (GimpSet *set,
|
|||
GFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSList* list;
|
||||
GSList *list;
|
||||
|
||||
for (list = set->list; list; list = list->next)
|
||||
{
|
||||
|
@ -316,7 +319,7 @@ gimp_set_set_active (GimpSet *set,
|
|||
}
|
||||
|
||||
gpointer
|
||||
gimp_set_get_active (GimpSet* set)
|
||||
gimp_set_get_active (GimpSet *set)
|
||||
{
|
||||
if (gimp_set_have (set, set->active_element))
|
||||
return set->active_element;
|
||||
|
@ -339,8 +342,8 @@ gimp_set_add_handler (GimpSet *set,
|
|||
/* you can't set a handler on something that's not a GTK object */
|
||||
g_assert (set->type != GTK_TYPE_NONE);
|
||||
|
||||
set_handler.signame = signame;
|
||||
set_handler.func = handler;
|
||||
set_handler.signame = signame;
|
||||
set_handler.func = handler;
|
||||
set_handler.user_data = user_data;
|
||||
|
||||
for (a = 0; a < set->handlers->len; a++)
|
||||
|
@ -350,6 +353,7 @@ gimp_set_add_handler (GimpSet *set,
|
|||
if (a < set->handlers->len)
|
||||
{
|
||||
g_array_index (set->handlers, GimpSetHandler, a) = set_handler;
|
||||
|
||||
for (list = set->list; list; list = list->next)
|
||||
{
|
||||
Node *node = list->data;
|
||||
|
@ -365,7 +369,7 @@ gimp_set_add_handler (GimpSet *set,
|
|||
|
||||
for (list = set->list; list; list = list->next)
|
||||
{
|
||||
Node* node = list->data;
|
||||
Node *node = list->data;
|
||||
|
||||
guint i = gtk_signal_connect (GTK_OBJECT(node->object), signame,
|
||||
handler,
|
||||
|
@ -381,7 +385,7 @@ void
|
|||
gimp_set_remove_handler (GimpSet *set,
|
||||
GimpSetHandlerId id)
|
||||
{
|
||||
GSList* list;
|
||||
GSList *list;
|
||||
|
||||
/* you can't remove a signal handler on something that's not a GTK object */
|
||||
g_return_if_fail (set->type != GTK_TYPE_NONE);
|
||||
|
|
|
@ -15,24 +15,26 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef __GIMPSET_H__
|
||||
#define __GIMPSET_H__
|
||||
|
||||
#ifndef __GIMP_SET_H__
|
||||
#define __GIMP_SET_H__
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
#include "gimpsetF.h"
|
||||
|
||||
/* GimpSet - a (usually) typed set of objects with signals for adding
|
||||
and removing of stuff. If it is weak, destroyed objects get removed
|
||||
automatically. If it is not, it refs them so they won't be freed
|
||||
till they are removed. (Though they can be destroyed, of course).
|
||||
|
||||
If GTK_TYPE_NONE is specified at gimpset creation time, no type
|
||||
checking is performed by gimp_set_add() and the
|
||||
gimp_set_{add,remove}_handler() functions should not be used. It
|
||||
is also illegal to ask for a weak untyped gimpset.
|
||||
* and removing of stuff. If it is weak, destroyed objects get removed
|
||||
* automatically. If it is not, it refs them so they won't be freed
|
||||
* till they are removed. (Though they can be destroyed, of course).
|
||||
*
|
||||
* If GTK_TYPE_NONE is specified at gimpset creation time, no type
|
||||
* checking is performed by gimp_set_add() and the
|
||||
* gimp_set_{add,remove}_handler() functions should not be used. It
|
||||
* is also illegal to ask for a weak untyped gimpset.
|
||||
*/
|
||||
|
||||
#define GIMP_TYPE_SET gimp_set_get_type()
|
||||
#define GIMP_TYPE_SET gimp_set_get_type ()
|
||||
#define GIMP_SET(obj) GTK_CHECK_CAST (obj, GIMP_TYPE_SET, GimpSet)
|
||||
#define GIMP_IS_SET(obj) GTK_CHECK_TYPE (obj, gimp_set_get_type())
|
||||
|
||||
|
@ -44,26 +46,26 @@
|
|||
|
||||
typedef guint GimpSetHandlerId;
|
||||
|
||||
GtkType gimp_set_get_type (void);
|
||||
GimpSet * gimp_set_new (GtkType type,
|
||||
gboolean weak);
|
||||
GtkType gimp_set_get_type (void);
|
||||
GimpSet * gimp_set_new (GtkType type,
|
||||
gboolean weak);
|
||||
|
||||
GtkType gimp_set_type (GimpSet *set);
|
||||
GtkType gimp_set_type (GimpSet *set);
|
||||
|
||||
gboolean gimp_set_add (GimpSet *gimpset,
|
||||
gpointer ob);
|
||||
gboolean gimp_set_remove (GimpSet *gimpset,
|
||||
gpointer ob);
|
||||
gboolean gimp_set_add (GimpSet *gimpset,
|
||||
gpointer object);
|
||||
gboolean gimp_set_remove (GimpSet *gimpset,
|
||||
gpointer object);
|
||||
|
||||
gboolean gimp_set_have (GimpSet *gimpset,
|
||||
gpointer ob);
|
||||
void gimp_set_foreach (GimpSet *gimpset,
|
||||
GFunc func,
|
||||
gpointer user_data);
|
||||
gint gimp_set_size (GimpSet* gimpset);
|
||||
gboolean gimp_set_have (GimpSet *gimpset,
|
||||
gpointer object);
|
||||
void gimp_set_foreach (GimpSet *gimpset,
|
||||
GFunc func,
|
||||
gpointer user_data);
|
||||
gint gimp_set_size (GimpSet *gimpset);
|
||||
|
||||
void gimp_set_set_active (GimpSet *gimpset,
|
||||
gpointer ob);
|
||||
gpointer object);
|
||||
gpointer gimp_set_get_active (GimpSet *gimpset);
|
||||
|
||||
GimpSetHandlerId gimp_set_add_handler (GimpSet *set,
|
||||
|
@ -73,4 +75,5 @@ GimpSetHandlerId gimp_set_add_handler (GimpSet *set,
|
|||
void gimp_set_remove_handler (GimpSet *set,
|
||||
GimpSetHandlerId id);
|
||||
|
||||
|
||||
#endif /* __GIMP_SET_H__ */
|
||||
|
|
|
@ -28,11 +28,12 @@ struct _GimpSignalType
|
|||
|
||||
typedef const GtkType TypeArr[];
|
||||
|
||||
GimpSignalID gimp_signal_new (const gchar *name,
|
||||
GtkSignalRunType signal_flags,
|
||||
GtkType object_type,
|
||||
guint function_offset,
|
||||
GimpSignalType *sig_type)
|
||||
GimpSignalID
|
||||
gimp_signal_new (const gchar *name,
|
||||
GtkSignalRunType signal_flags,
|
||||
GtkType object_type,
|
||||
guint function_offset,
|
||||
GimpSignalType *sig_type)
|
||||
{
|
||||
return gtk_signal_newv (name,
|
||||
signal_flags,
|
||||
|
@ -46,6 +47,9 @@ GimpSignalID gimp_signal_new (const gchar *name,
|
|||
(GtkType *) sig_type->param_types);
|
||||
}
|
||||
|
||||
|
||||
/* void__void */
|
||||
|
||||
static GimpSignalType sigtype_void =
|
||||
{
|
||||
gtk_signal_default_marshaller,
|
||||
|
@ -54,7 +58,10 @@ static GimpSignalType sigtype_void =
|
|||
NULL
|
||||
};
|
||||
|
||||
GimpSignalType* const gimp_sigtype_void = &sigtype_void;
|
||||
GimpSignalType * const gimp_sigtype_void = &sigtype_void;
|
||||
|
||||
|
||||
/* void__pointer */
|
||||
|
||||
static void
|
||||
gimp_marshaller_pointer (GtkObject *object,
|
||||
|
@ -80,7 +87,10 @@ static GimpSignalType sigtype_pointer =
|
|||
pointer_types
|
||||
};
|
||||
|
||||
GimpSignalType* const gimp_sigtype_pointer = &sigtype_pointer;
|
||||
GimpSignalType * const gimp_sigtype_pointer = &sigtype_pointer;
|
||||
|
||||
|
||||
/* void__int */
|
||||
|
||||
static void
|
||||
gimp_marshaller_int (GtkObject *object,
|
||||
|
@ -108,6 +118,9 @@ static GimpSignalType sigtype_int =
|
|||
|
||||
GimpSignalType* const gimp_sigtype_int = &sigtype_int;
|
||||
|
||||
|
||||
/* void__double */
|
||||
|
||||
static void
|
||||
gimp_marshaller_double (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
|
@ -134,6 +147,9 @@ static GimpSignalType sigtype_double =
|
|||
|
||||
GimpSignalType* const gimp_sigtype_double = &sigtype_double;
|
||||
|
||||
|
||||
/* void__int_int_int */
|
||||
|
||||
static void
|
||||
gimp_marshaller_int_int_int (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
|
@ -164,6 +180,9 @@ static GimpSignalType sigtype_int_int_int =
|
|||
|
||||
GimpSignalType* const gimp_sigtype_int_int_int = &sigtype_int_int_int;
|
||||
|
||||
|
||||
/* void__int_int_int_int */
|
||||
|
||||
static void
|
||||
gimp_marshaller_int_int_int_int (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
|
@ -194,4 +213,4 @@ static GimpSignalType sigtype_int_int_int_int =
|
|||
int_int_int_int_types
|
||||
};
|
||||
|
||||
GimpSignalType* const gimp_sigtype_int_int_int_int = &sigtype_int_int_int_int;
|
||||
GimpSignalType * const gimp_sigtype_int_int_int_int = &sigtype_int_int_int_int;
|
||||
|
|
|
@ -15,41 +15,56 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_SIGNAL_H__
|
||||
#define __GIMP_SIGNAL_H__
|
||||
|
||||
|
||||
#include <gtk/gtksignal.h>
|
||||
|
||||
|
||||
/* This is the gtk "signal id" */
|
||||
typedef guint GimpSignalID;
|
||||
|
||||
typedef const struct _GimpSignalType GimpSignalType;
|
||||
|
||||
|
||||
/* The arguments are encoded in the names.. */
|
||||
|
||||
extern GimpSignalType* const gimp_sigtype_void;
|
||||
typedef void (*GimpHandlerVoid) (GtkObject*,
|
||||
gpointer);
|
||||
extern GimpSignalType * const gimp_sigtype_void;
|
||||
typedef void (* GimpHandlerVoid) (GtkObject *object,
|
||||
gpointer data);
|
||||
|
||||
extern GimpSignalType* const gimp_sigtype_pointer;
|
||||
typedef void (*GimpHandlerPointer) (GtkObject*, gpointer,
|
||||
gpointer);
|
||||
extern GimpSignalType * const gimp_sigtype_pointer;
|
||||
typedef void (* GimpHandlerPointer) (GtkObject *object,
|
||||
gpointer p,
|
||||
gpointer data);
|
||||
|
||||
extern GimpSignalType* const gimp_sigtype_int;
|
||||
typedef void (*GimpHandlerInt) (GtkObject*, gint,
|
||||
gpointer);
|
||||
extern GimpSignalType * const gimp_sigtype_int;
|
||||
typedef void (* GimpHandlerInt) (GtkObject *object,
|
||||
gint i,
|
||||
gpointer data);
|
||||
|
||||
extern GimpSignalType* const gimp_sigtype_double;
|
||||
typedef void (*GimpHandlerDouble) (GtkObject*, gdouble,
|
||||
gpointer);
|
||||
extern GimpSignalType * const gimp_sigtype_double;
|
||||
typedef void (* GimpHandlerDouble) (GtkObject *object,
|
||||
gdouble d,
|
||||
gpointer data);
|
||||
|
||||
extern GimpSignalType* const gimp_sigtype_int_int_int;
|
||||
typedef void (*GimpHandlerIntIntInt) (GtkObject*, gint, gint, gint,
|
||||
gpointer);
|
||||
extern GimpSignalType * const gimp_sigtype_int_int_int;
|
||||
typedef void (* GimpHandlerIntIntInt) (GtkObject *object,
|
||||
gint i1,
|
||||
gint i2,
|
||||
gint i3,
|
||||
gpointer data);
|
||||
|
||||
extern GimpSignalType * const gimp_sigtype_int_int_int_int;
|
||||
typedef void (* GimpHandlerIntIntIntInt) (GtkObject *object,
|
||||
gint i1,
|
||||
gint i2,
|
||||
gint i3,
|
||||
gint i4,
|
||||
gpointer data);
|
||||
|
||||
extern GimpSignalType* const gimp_sigtype_int_int_int_int;
|
||||
typedef void (*GimpHandlerIntIntIntInt) (GtkObject*, gint, gint, gint, gint,
|
||||
gpointer);
|
||||
|
||||
GimpSignalID gimp_signal_new (const gchar *name,
|
||||
GtkSignalRunType signal_flags,
|
||||
|
@ -57,4 +72,5 @@ GimpSignalID gimp_signal_new (const gchar *name,
|
|||
guint function_offset,
|
||||
GimpSignalType *sig_type);
|
||||
|
||||
|
||||
#endif /* __GIMP_SIGNAL_H__ */
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "appenv.h"
|
||||
|
@ -25,45 +27,50 @@
|
|||
#include "brush_edit.h"
|
||||
#include "gimpui.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libgimp/gimpmath.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
static void brush_edit_close_callback (GtkWidget *, gpointer);
|
||||
static gint brush_edit_preview_resize (GtkWidget *widget, GdkEvent *event,
|
||||
|
||||
static void brush_edit_close_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static gint brush_edit_preview_resize (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
BrushEditGeneratedWindow *begw);
|
||||
|
||||
|
||||
static void
|
||||
update_brush_callback (GtkAdjustment *adjustment,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
if (begw->brush &&
|
||||
((begw->radius_data->value
|
||||
!= gimp_brush_generated_get_radius(begw->brush))
|
||||
!= gimp_brush_generated_get_radius (begw->brush))
|
||||
|| (begw->hardness_data->value
|
||||
!= gimp_brush_generated_get_hardness(begw->brush))
|
||||
!= gimp_brush_generated_get_hardness (begw->brush))
|
||||
|| (begw->aspect_ratio_data->value
|
||||
!= gimp_brush_generated_get_aspect_ratio(begw->brush))
|
||||
!= gimp_brush_generated_get_aspect_ratio (begw->brush))
|
||||
|| (begw->angle_data->value
|
||||
!=gimp_brush_generated_get_angle(begw->brush))))
|
||||
{
|
||||
gimp_brush_generated_freeze (begw->brush);
|
||||
gimp_brush_generated_set_radius (begw->brush,
|
||||
begw->radius_data->value);
|
||||
gimp_brush_generated_set_hardness (begw->brush,
|
||||
begw->hardness_data->value);
|
||||
gimp_brush_generated_set_aspect_ratio (begw->brush,
|
||||
begw->aspect_ratio_data->value);
|
||||
gimp_brush_generated_set_angle (begw->brush,
|
||||
begw->angle_data->value);
|
||||
gimp_brush_generated_thaw (begw->brush);
|
||||
}
|
||||
!= gimp_brush_generated_get_angle (begw->brush))))
|
||||
{
|
||||
gimp_brush_generated_freeze (begw->brush);
|
||||
gimp_brush_generated_set_radius (begw->brush,
|
||||
begw->radius_data->value);
|
||||
gimp_brush_generated_set_hardness (begw->brush,
|
||||
begw->hardness_data->value);
|
||||
gimp_brush_generated_set_aspect_ratio (begw->brush,
|
||||
begw->aspect_ratio_data->value);
|
||||
gimp_brush_generated_set_angle (begw->brush,
|
||||
begw->angle_data->value);
|
||||
gimp_brush_generated_thaw (begw->brush);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
brush_edit_clear_preview (BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
guchar * buf;
|
||||
gint i;
|
||||
guchar *buf;
|
||||
gint i;
|
||||
|
||||
buf = g_new (guchar, begw->preview->requisition.width);
|
||||
|
||||
|
@ -126,7 +133,7 @@ brush_edit_brush_dirty_callback (GimpBrush *brush,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
brush_renamed_callback (GtkWidget *widget,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
|
@ -138,15 +145,20 @@ void
|
|||
brush_edit_generated_set_brush (BrushEditGeneratedWindow *begw,
|
||||
GimpBrush *gbrush)
|
||||
{
|
||||
GimpBrushGenerated *brush = 0;
|
||||
if (begw->brush == (GimpBrushGenerated*)gbrush)
|
||||
GimpBrushGenerated *brush = NULL;
|
||||
|
||||
g_return_if_fail (begw != NULL);
|
||||
|
||||
if (begw->brush == (GimpBrushGenerated *) gbrush)
|
||||
return;
|
||||
if (begw && begw->brush)
|
||||
|
||||
if (begw->brush)
|
||||
{
|
||||
gtk_signal_disconnect_by_data (GTK_OBJECT (begw->brush), begw);
|
||||
gtk_object_unref (GTK_OBJECT (begw->brush));
|
||||
begw->brush = NULL;
|
||||
}
|
||||
|
||||
if (!gbrush || !GIMP_IS_BRUSH_GENERATED (gbrush))
|
||||
{
|
||||
begw->brush = NULL;
|
||||
|
@ -154,29 +166,30 @@ brush_edit_generated_set_brush (BrushEditGeneratedWindow *begw,
|
|||
gtk_widget_hide (begw->shell);
|
||||
return;
|
||||
}
|
||||
|
||||
brush = GIMP_BRUSH_GENERATED (gbrush);
|
||||
if (begw)
|
||||
{
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "dirty",
|
||||
GTK_SIGNAL_FUNC (brush_edit_brush_dirty_callback),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "rename",
|
||||
GTK_SIGNAL_FUNC (brush_renamed_callback),
|
||||
begw);
|
||||
begw->brush = NULL;
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->radius_data),
|
||||
gimp_brush_generated_get_radius (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->hardness_data),
|
||||
gimp_brush_generated_get_hardness (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->angle_data),
|
||||
gimp_brush_generated_get_angle (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->aspect_ratio_data),
|
||||
gimp_brush_generated_get_aspect_ratio (brush));
|
||||
gtk_entry_set_text (GTK_ENTRY (begw->name), gimp_brush_get_name (gbrush));
|
||||
begw->brush = brush;
|
||||
gtk_object_ref (GTK_OBJECT (begw->brush));
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (brush), begw);
|
||||
}
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "dirty",
|
||||
GTK_SIGNAL_FUNC (brush_edit_brush_dirty_callback),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "rename",
|
||||
GTK_SIGNAL_FUNC (brush_renamed_callback),
|
||||
begw);
|
||||
|
||||
begw->brush = NULL;
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->radius_data),
|
||||
gimp_brush_generated_get_radius (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->hardness_data),
|
||||
gimp_brush_generated_get_hardness (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->angle_data),
|
||||
gimp_brush_generated_get_angle (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->aspect_ratio_data),
|
||||
gimp_brush_generated_get_aspect_ratio (brush));
|
||||
gtk_entry_set_text (GTK_ENTRY (begw->name), gimp_brush_get_name (gbrush));
|
||||
begw->brush = brush;
|
||||
|
||||
gtk_object_ref (GTK_OBJECT (begw->brush));
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (brush), begw);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -184,6 +197,7 @@ name_changed_func (GtkWidget *widget,
|
|||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
gchar *entry_text;
|
||||
|
||||
entry_text = gtk_entry_get_text (GTK_ENTRY (widget));
|
||||
gimp_brush_set_name (GIMP_BRUSH (begw->brush), entry_text);
|
||||
}
|
||||
|
@ -204,8 +218,7 @@ brush_edit_generated_new (void)
|
|||
GtkWidget *slider;
|
||||
GtkWidget *table;
|
||||
|
||||
begw = g_new (BrushEditGeneratedWindow, 1);
|
||||
begw->brush = NULL;
|
||||
begw = g_new0 (BrushEditGeneratedWindow, 1);
|
||||
|
||||
begw->shell = gimp_dialog_new (_("Brush Editor"), "generated_brush_editor",
|
||||
gimp_standard_help_func,
|
||||
|
@ -222,23 +235,18 @@ brush_edit_generated_new (void)
|
|||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
||||
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (begw->shell)->vbox), vbox);
|
||||
|
||||
/* Populate the window with some widgets */
|
||||
|
||||
/* table for brush controlls */
|
||||
table = gtk_table_new (5, 4, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
|
||||
|
||||
/* Brush's name */
|
||||
begw->name = gtk_entry_new();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->name, TRUE, TRUE, 0);
|
||||
|
||||
begw->name = gtk_entry_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->name, FALSE, FALSE, 0);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (begw->name), "activate",
|
||||
(GtkSignalFunc) name_changed_func,
|
||||
GTK_SIGNAL_FUNC (name_changed_func),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->name), "focus_out_event",
|
||||
(GtkSignalFunc) focus_out_func,
|
||||
GTK_SIGNAL_FUNC (focus_out_func),
|
||||
begw);
|
||||
gtk_widget_show(begw->name);
|
||||
|
||||
gtk_widget_show (begw->name);
|
||||
|
||||
/* brush's preview widget w/frame */
|
||||
begw->frame = gtk_frame_new (NULL);
|
||||
|
@ -247,21 +255,23 @@ brush_edit_generated_new (void)
|
|||
|
||||
begw->preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview), 125, 100);
|
||||
gtk_signal_connect_after (GTK_OBJECT(begw->frame), "size_allocate",
|
||||
(GtkSignalFunc) brush_edit_preview_resize,
|
||||
begw);
|
||||
gtk_signal_connect_after (GTK_OBJECT (begw->frame), "size_allocate",
|
||||
GTK_SIGNAL_FUNC (brush_edit_preview_resize),
|
||||
begw);
|
||||
gtk_container_add (GTK_CONTAINER (begw->frame), begw->preview);
|
||||
|
||||
gtk_widget_show(begw->preview);
|
||||
gtk_widget_show(begw->frame);
|
||||
gtk_widget_show (begw->preview);
|
||||
gtk_widget_show (begw->frame);
|
||||
|
||||
/* table for sliders/labels */
|
||||
begw->scale_label = gtk_label_new ("-1:1");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->scale_label, FALSE, FALSE, 0);
|
||||
begw->scale = -1;
|
||||
gtk_widget_show (begw->scale_label);
|
||||
|
||||
begw->scale = -1;
|
||||
|
||||
/* table for sliders/labels */
|
||||
table = gtk_table_new(2, 4, FALSE);
|
||||
table = gtk_table_new (4, 2, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
||||
|
||||
/* brush radius scale */
|
||||
|
@ -271,7 +281,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->radius_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
||||
_("Radius:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -283,7 +294,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->hardness_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
||||
_("Hardness:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -295,7 +307,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->aspect_ratio_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
|
||||
_("Aspect Ratio:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -307,7 +320,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->angle_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
|
||||
_("Angle:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -327,14 +341,15 @@ brush_edit_preview_resize (GtkWidget *widget,
|
|||
GdkEvent *event,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview),
|
||||
widget->allocation.width - 4,
|
||||
widget->allocation.height - 4);
|
||||
|
||||
/* update the display */
|
||||
if (begw->brush)
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (begw->brush), begw);
|
||||
return FALSE;
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview),
|
||||
widget->allocation.width - 4,
|
||||
widget->allocation.height - 4);
|
||||
|
||||
/* update the display */
|
||||
if (begw->brush)
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (begw->brush), begw);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __BRUSH_EDIT_H__
|
||||
#define __BRUSH_EDIT_H__
|
||||
|
||||
|
@ -26,20 +27,21 @@ typedef struct _BrushEditGeneratedWindow BrushEditGeneratedWindow;
|
|||
|
||||
struct _BrushEditGeneratedWindow
|
||||
{
|
||||
GtkWidget *shell;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *scale_label;
|
||||
GtkWidget *options_box;
|
||||
GtkWidget *name;
|
||||
GtkWidget *shell;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *scale_label;
|
||||
GtkWidget *options_box;
|
||||
GtkWidget *name;
|
||||
GtkAdjustment *radius_data;
|
||||
GtkAdjustment *hardness_data;
|
||||
GtkAdjustment *angle_data;
|
||||
GtkAdjustment *aspect_ratio_data;
|
||||
|
||||
/* Brush preview */
|
||||
GtkWidget *brush_preview;
|
||||
GtkWidget *brush_preview;
|
||||
GimpBrushGenerated *brush;
|
||||
gint scale;
|
||||
gint scale;
|
||||
};
|
||||
|
||||
BrushEditGeneratedWindow * brush_edit_generated_new (void);
|
||||
|
|
|
@ -14,9 +14,11 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PARASITE_LIST_H__
|
||||
#define __PARASITE_LIST_H__
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -27,8 +29,8 @@
|
|||
|
||||
|
||||
#define GIMP_TYPE_PARASITE_LIST (parasite_list_get_type ())
|
||||
#define GIMP_PARASITE_LIST(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_PARASITE_LIST, GimpParasiteList))
|
||||
#define GIMP_IS_PARASITE_LIST(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_PARASITE_LIST))
|
||||
#define GIMP_PARASITE_LIST(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_PARASITE_LIST, GimpParasiteList))
|
||||
#define GIMP_IS_PARASITE_LIST(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_PARASITE_LIST))
|
||||
|
||||
/* Signals:
|
||||
add
|
||||
|
@ -55,4 +57,5 @@ GimpParasite * parasite_list_find (ParasiteList *list,
|
|||
|
||||
void parasite_shift_parent (GimpParasite *parasite);
|
||||
|
||||
|
||||
#endif /* __PARASITE_LIST_H__ */
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "appenv.h"
|
||||
|
@ -25,45 +27,50 @@
|
|||
#include "brush_edit.h"
|
||||
#include "gimpui.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libgimp/gimpmath.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
static void brush_edit_close_callback (GtkWidget *, gpointer);
|
||||
static gint brush_edit_preview_resize (GtkWidget *widget, GdkEvent *event,
|
||||
|
||||
static void brush_edit_close_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static gint brush_edit_preview_resize (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
BrushEditGeneratedWindow *begw);
|
||||
|
||||
|
||||
static void
|
||||
update_brush_callback (GtkAdjustment *adjustment,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
if (begw->brush &&
|
||||
((begw->radius_data->value
|
||||
!= gimp_brush_generated_get_radius(begw->brush))
|
||||
!= gimp_brush_generated_get_radius (begw->brush))
|
||||
|| (begw->hardness_data->value
|
||||
!= gimp_brush_generated_get_hardness(begw->brush))
|
||||
!= gimp_brush_generated_get_hardness (begw->brush))
|
||||
|| (begw->aspect_ratio_data->value
|
||||
!= gimp_brush_generated_get_aspect_ratio(begw->brush))
|
||||
!= gimp_brush_generated_get_aspect_ratio (begw->brush))
|
||||
|| (begw->angle_data->value
|
||||
!=gimp_brush_generated_get_angle(begw->brush))))
|
||||
{
|
||||
gimp_brush_generated_freeze (begw->brush);
|
||||
gimp_brush_generated_set_radius (begw->brush,
|
||||
begw->radius_data->value);
|
||||
gimp_brush_generated_set_hardness (begw->brush,
|
||||
begw->hardness_data->value);
|
||||
gimp_brush_generated_set_aspect_ratio (begw->brush,
|
||||
begw->aspect_ratio_data->value);
|
||||
gimp_brush_generated_set_angle (begw->brush,
|
||||
begw->angle_data->value);
|
||||
gimp_brush_generated_thaw (begw->brush);
|
||||
}
|
||||
!= gimp_brush_generated_get_angle (begw->brush))))
|
||||
{
|
||||
gimp_brush_generated_freeze (begw->brush);
|
||||
gimp_brush_generated_set_radius (begw->brush,
|
||||
begw->radius_data->value);
|
||||
gimp_brush_generated_set_hardness (begw->brush,
|
||||
begw->hardness_data->value);
|
||||
gimp_brush_generated_set_aspect_ratio (begw->brush,
|
||||
begw->aspect_ratio_data->value);
|
||||
gimp_brush_generated_set_angle (begw->brush,
|
||||
begw->angle_data->value);
|
||||
gimp_brush_generated_thaw (begw->brush);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
brush_edit_clear_preview (BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
guchar * buf;
|
||||
gint i;
|
||||
guchar *buf;
|
||||
gint i;
|
||||
|
||||
buf = g_new (guchar, begw->preview->requisition.width);
|
||||
|
||||
|
@ -126,7 +133,7 @@ brush_edit_brush_dirty_callback (GimpBrush *brush,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
brush_renamed_callback (GtkWidget *widget,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
|
@ -138,15 +145,20 @@ void
|
|||
brush_edit_generated_set_brush (BrushEditGeneratedWindow *begw,
|
||||
GimpBrush *gbrush)
|
||||
{
|
||||
GimpBrushGenerated *brush = 0;
|
||||
if (begw->brush == (GimpBrushGenerated*)gbrush)
|
||||
GimpBrushGenerated *brush = NULL;
|
||||
|
||||
g_return_if_fail (begw != NULL);
|
||||
|
||||
if (begw->brush == (GimpBrushGenerated *) gbrush)
|
||||
return;
|
||||
if (begw && begw->brush)
|
||||
|
||||
if (begw->brush)
|
||||
{
|
||||
gtk_signal_disconnect_by_data (GTK_OBJECT (begw->brush), begw);
|
||||
gtk_object_unref (GTK_OBJECT (begw->brush));
|
||||
begw->brush = NULL;
|
||||
}
|
||||
|
||||
if (!gbrush || !GIMP_IS_BRUSH_GENERATED (gbrush))
|
||||
{
|
||||
begw->brush = NULL;
|
||||
|
@ -154,29 +166,30 @@ brush_edit_generated_set_brush (BrushEditGeneratedWindow *begw,
|
|||
gtk_widget_hide (begw->shell);
|
||||
return;
|
||||
}
|
||||
|
||||
brush = GIMP_BRUSH_GENERATED (gbrush);
|
||||
if (begw)
|
||||
{
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "dirty",
|
||||
GTK_SIGNAL_FUNC (brush_edit_brush_dirty_callback),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "rename",
|
||||
GTK_SIGNAL_FUNC (brush_renamed_callback),
|
||||
begw);
|
||||
begw->brush = NULL;
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->radius_data),
|
||||
gimp_brush_generated_get_radius (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->hardness_data),
|
||||
gimp_brush_generated_get_hardness (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->angle_data),
|
||||
gimp_brush_generated_get_angle (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->aspect_ratio_data),
|
||||
gimp_brush_generated_get_aspect_ratio (brush));
|
||||
gtk_entry_set_text (GTK_ENTRY (begw->name), gimp_brush_get_name (gbrush));
|
||||
begw->brush = brush;
|
||||
gtk_object_ref (GTK_OBJECT (begw->brush));
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (brush), begw);
|
||||
}
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "dirty",
|
||||
GTK_SIGNAL_FUNC (brush_edit_brush_dirty_callback),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (brush), "rename",
|
||||
GTK_SIGNAL_FUNC (brush_renamed_callback),
|
||||
begw);
|
||||
|
||||
begw->brush = NULL;
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->radius_data),
|
||||
gimp_brush_generated_get_radius (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->hardness_data),
|
||||
gimp_brush_generated_get_hardness (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->angle_data),
|
||||
gimp_brush_generated_get_angle (brush));
|
||||
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->aspect_ratio_data),
|
||||
gimp_brush_generated_get_aspect_ratio (brush));
|
||||
gtk_entry_set_text (GTK_ENTRY (begw->name), gimp_brush_get_name (gbrush));
|
||||
begw->brush = brush;
|
||||
|
||||
gtk_object_ref (GTK_OBJECT (begw->brush));
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (brush), begw);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -184,6 +197,7 @@ name_changed_func (GtkWidget *widget,
|
|||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
gchar *entry_text;
|
||||
|
||||
entry_text = gtk_entry_get_text (GTK_ENTRY (widget));
|
||||
gimp_brush_set_name (GIMP_BRUSH (begw->brush), entry_text);
|
||||
}
|
||||
|
@ -204,8 +218,7 @@ brush_edit_generated_new (void)
|
|||
GtkWidget *slider;
|
||||
GtkWidget *table;
|
||||
|
||||
begw = g_new (BrushEditGeneratedWindow, 1);
|
||||
begw->brush = NULL;
|
||||
begw = g_new0 (BrushEditGeneratedWindow, 1);
|
||||
|
||||
begw->shell = gimp_dialog_new (_("Brush Editor"), "generated_brush_editor",
|
||||
gimp_standard_help_func,
|
||||
|
@ -222,23 +235,18 @@ brush_edit_generated_new (void)
|
|||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
||||
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (begw->shell)->vbox), vbox);
|
||||
|
||||
/* Populate the window with some widgets */
|
||||
|
||||
/* table for brush controlls */
|
||||
table = gtk_table_new (5, 4, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
|
||||
|
||||
/* Brush's name */
|
||||
begw->name = gtk_entry_new();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->name, TRUE, TRUE, 0);
|
||||
|
||||
begw->name = gtk_entry_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->name, FALSE, FALSE, 0);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (begw->name), "activate",
|
||||
(GtkSignalFunc) name_changed_func,
|
||||
GTK_SIGNAL_FUNC (name_changed_func),
|
||||
begw);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->name), "focus_out_event",
|
||||
(GtkSignalFunc) focus_out_func,
|
||||
GTK_SIGNAL_FUNC (focus_out_func),
|
||||
begw);
|
||||
gtk_widget_show(begw->name);
|
||||
|
||||
gtk_widget_show (begw->name);
|
||||
|
||||
/* brush's preview widget w/frame */
|
||||
begw->frame = gtk_frame_new (NULL);
|
||||
|
@ -247,21 +255,23 @@ brush_edit_generated_new (void)
|
|||
|
||||
begw->preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview), 125, 100);
|
||||
gtk_signal_connect_after (GTK_OBJECT(begw->frame), "size_allocate",
|
||||
(GtkSignalFunc) brush_edit_preview_resize,
|
||||
begw);
|
||||
gtk_signal_connect_after (GTK_OBJECT (begw->frame), "size_allocate",
|
||||
GTK_SIGNAL_FUNC (brush_edit_preview_resize),
|
||||
begw);
|
||||
gtk_container_add (GTK_CONTAINER (begw->frame), begw->preview);
|
||||
|
||||
gtk_widget_show(begw->preview);
|
||||
gtk_widget_show(begw->frame);
|
||||
gtk_widget_show (begw->preview);
|
||||
gtk_widget_show (begw->frame);
|
||||
|
||||
/* table for sliders/labels */
|
||||
begw->scale_label = gtk_label_new ("-1:1");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), begw->scale_label, FALSE, FALSE, 0);
|
||||
begw->scale = -1;
|
||||
gtk_widget_show (begw->scale_label);
|
||||
|
||||
begw->scale = -1;
|
||||
|
||||
/* table for sliders/labels */
|
||||
table = gtk_table_new(2, 4, FALSE);
|
||||
table = gtk_table_new (4, 2, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
||||
|
||||
/* brush radius scale */
|
||||
|
@ -271,7 +281,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->radius_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
||||
_("Radius:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -283,7 +294,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->hardness_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
||||
_("Hardness:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -295,7 +307,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->aspect_ratio_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
|
||||
_("Aspect Ratio:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -307,7 +320,8 @@ brush_edit_generated_new (void)
|
|||
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
|
||||
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
||||
gtk_signal_connect (GTK_OBJECT (begw->angle_data), "value_changed",
|
||||
(GtkSignalFunc) update_brush_callback, begw);
|
||||
GTK_SIGNAL_FUNC (update_brush_callback),
|
||||
begw);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
|
||||
_("Angle:"), 1.0, 1.0,
|
||||
slider, 1, FALSE);
|
||||
|
@ -327,14 +341,15 @@ brush_edit_preview_resize (GtkWidget *widget,
|
|||
GdkEvent *event,
|
||||
BrushEditGeneratedWindow *begw)
|
||||
{
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview),
|
||||
widget->allocation.width - 4,
|
||||
widget->allocation.height - 4);
|
||||
|
||||
/* update the display */
|
||||
if (begw->brush)
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (begw->brush), begw);
|
||||
return FALSE;
|
||||
gtk_preview_size (GTK_PREVIEW (begw->preview),
|
||||
widget->allocation.width - 4,
|
||||
widget->allocation.height - 4);
|
||||
|
||||
/* update the display */
|
||||
if (begw->brush)
|
||||
brush_edit_brush_dirty_callback (GIMP_BRUSH (begw->brush), begw);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __BRUSH_EDIT_H__
|
||||
#define __BRUSH_EDIT_H__
|
||||
|
||||
|
@ -26,20 +27,21 @@ typedef struct _BrushEditGeneratedWindow BrushEditGeneratedWindow;
|
|||
|
||||
struct _BrushEditGeneratedWindow
|
||||
{
|
||||
GtkWidget *shell;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *scale_label;
|
||||
GtkWidget *options_box;
|
||||
GtkWidget *name;
|
||||
GtkWidget *shell;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *scale_label;
|
||||
GtkWidget *options_box;
|
||||
GtkWidget *name;
|
||||
GtkAdjustment *radius_data;
|
||||
GtkAdjustment *hardness_data;
|
||||
GtkAdjustment *angle_data;
|
||||
GtkAdjustment *aspect_ratio_data;
|
||||
|
||||
/* Brush preview */
|
||||
GtkWidget *brush_preview;
|
||||
GtkWidget *brush_preview;
|
||||
GimpBrushGenerated *brush;
|
||||
gint scale;
|
||||
gint scale;
|
||||
};
|
||||
|
||||
BrushEditGeneratedWindow * brush_edit_generated_new (void);
|
||||
|
|
Loading…
Reference in New Issue