----------------------------------------------------------------------

----------------------------------------------------------------------
Modified Files:
	ChangeLog app/Makefile.am app/brush_select.c
	app/gimpbrushlist.c app/gimpbrushlist.h app/gimpsetF.h
	added sorting on the brush_list, fixed some encapulation issues.

	app/paint_funcs.c
	minor speed tweak to border_region
Added Files:
	app/gimpbrushlistF.h app/gimpbrushlistP.h app/gimplist.c
	app/gimplist.h app/gimplistF.h app/gimplistP.h
        Split gimpbrushlist.h into 3 files.  New class "GimpList"
----------------------------------------------------------------------
This commit is contained in:
jaycox 1998-07-12 11:40:43 +00:00
parent 999b2781f4
commit ed2e3ee66f
17 changed files with 684 additions and 188 deletions

View File

@ -1,3 +1,16 @@
Sun Jul 12 04:16:17 PDT 1998 Jay Cox <jaycox@earthlink.net>
* gimplist{.c,.h,F.h,P.h}
New class for lists
* gimpbrushlist.h gimpbrushlistF.h gimpbrushlistP.h brush_select.c
split gimpbrushlist.h into 3 files. Made gimplist
the parent class of GimpBrushList.
* gimpbrushlist.c: brushes in the list are once again sorted by name.
* paint_funcs.c: minor speed tweak to a minor speed tweak in
border_region
Sat Jul 11 22:15:31 PDT 1998 Manish Singh <yosh@gimp.org>
* fileops.c

View File

@ -148,6 +148,10 @@ gimp_SOURCES = \
gimpbrushgenerated.h \
gimpbrushlist.c \
gimpbrushlist.h \
gimplist.c \
gimplist.h \
gimplistF.h \
gimplistP.h \
gimprc.c \
gimprc.h \
global_edit.c \

View File

@ -21,8 +21,7 @@
#include "appenv.h"
#include "actionarea.h"
#include "gimpbrushlist.h"
#include "gimpset.h"
#include "gimpsetP.h" /* FIXME: get rid of this include */
#include "gimplist.h"
#include "gimpbrushgenerated.h"
#include "brush_edit.h"
#include "brush_select.h"
@ -324,7 +323,8 @@ brush_select_new ()
/* render the brushes into the newly created image structure */
display_brushes (bsp);
gimp_set_foreach(GIMP_SET(brush_list), (GFunc)connect_signals_to_brush, bsp);
gimp_list_foreach(GIMP_LIST(brush_list), (GFunc)connect_signals_to_brush,
bsp);
gtk_signal_connect (GTK_OBJECT (brush_list), "add",
(GtkSignalFunc) brush_added_callback,
bsp);
@ -574,44 +574,31 @@ display_setup (BrushSelectP bsp)
}
static int brush_counter = 0;
static void do_display_brush (GimpBrush *brush, BrushSelectP bsp)
{
display_brush (bsp, brush, brush_counter % NUM_BRUSH_COLUMNS,
brush_counter / NUM_BRUSH_COLUMNS);
brush_counter++;
}
static void
display_brushes (BrushSelectP bsp)
{
/* FIXME: use gimp_set_foreach?? */
GSList * list = GIMP_SET(brush_list)->list; /* the global brush list */
int row, col;
GimpBrushP brush;
/* If there are no brushes, insensitize widgets */
if (brush_list == NULL)
{
gtk_widget_set_sensitive (bsp->options_box, FALSE);
return;
}
if (brush_list == NULL || gimp_brush_list_length(brush_list) == 0)
{
gtk_widget_set_sensitive (bsp->options_box, FALSE);
return;
}
/* Else, sensitize widgets */
else
gtk_widget_set_sensitive (bsp->options_box, TRUE);
/* setup the display area */
display_setup (bsp);
row = col = 0;
while (list)
{
brush = (GimpBrushP) list->data;
/* Display the brush */
display_brush (bsp, brush, col, row);
/* increment the counts */
if (++col == NUM_BRUSH_COLUMNS)
{
row ++;
col = 0;
}
list = g_slist_next (list);
}
brush_counter = 0;
gimp_list_foreach(GIMP_LIST(brush_list), (GFunc)do_display_brush, bsp);
}
@ -708,27 +695,18 @@ preview_calc_scrollbar (BrushSelectP bsp)
int page_size;
int max;
int offs;
/* int rowy; */
offs = bsp->scroll_offset;
num_rows = (brush_list->num_brushes + NUM_BRUSH_COLUMNS - 1)
num_rows = (gimp_brush_list_length(brush_list) + NUM_BRUSH_COLUMNS - 1)
/ NUM_BRUSH_COLUMNS;
max = num_rows * bsp->cell_width;
if (!num_rows) num_rows = 1;
page_size = bsp->preview->allocation.height;
page_size = ((page_size < max) ? page_size : max);
/*
rowy = (get_active_brush()->index / NUM_BRUSH_COLUMNS) * bsp->cell_width
+ bsp->cell_width/2;
if((rowy < offs) || (rowy > (offs + page_size)))
offs = rowy - page_size/2;
offs = MIN(MAX(offs, 0), max - page_size);
*/
bsp->scroll_offset = offs;
bsp->sbar_data->value = bsp->scroll_offset;
bsp->sbar_data->upper = max;
/* bsp->sbar_data->page_size = page_size; */
bsp->sbar_data->page_size = ((page_size < max) ? page_size : max);
bsp->sbar_data->page_increment = (page_size >> 1);
bsp->sbar_data->step_increment = bsp->cell_width;
@ -742,7 +720,7 @@ brush_select_resize (GtkWidget *widget,
BrushSelectP bsp)
{
NUM_BRUSH_COLUMNS = (gint)((widget->allocation.width - 4) / STD_CELL_WIDTH);
NUM_BRUSH_ROWS = (brush_list->num_brushes + NUM_BRUSH_COLUMNS - 1) / NUM_BRUSH_COLUMNS;
NUM_BRUSH_ROWS = (gimp_brush_list_length(brush_list) + NUM_BRUSH_COLUMNS - 1) / NUM_BRUSH_COLUMNS;
bsp->width = widget->allocation.width - 4;
bsp->height = widget->allocation.height - 4;

180
app/core/gimplist.c Normal file
View File

@ -0,0 +1,180 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 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 "gimpsignal.h"
#include "gimplistP.h"
/* code mostly ripped from nether's gimpset class */
enum
{
ADD,
REMOVE,
LAST_SIGNAL
};
static guint gimp_list_signals [LAST_SIGNAL];
static GimpObjectClass* parent_class;
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)
{
GimpList* list=GIMP_LIST(ob);
GSList* node;
for(node=list->list;node;node=node->next){
if(!list->weak)
gtk_object_unref(GTK_OBJECT(node->data));
gtk_signal_emit (GTK_OBJECT(list),
gimp_list_signals[REMOVE],
node->data);
}
g_slist_free(list->list);
GTK_OBJECT_CLASS(parent_class)->destroy (ob);
}
static void
gimp_list_init (GimpList* list)
{
list->list=NULL;
list->type=GTK_TYPE_OBJECT;
}
static void
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,
GTK_SIGNAL_OFFSET (GimpListClass, add),
gimp_sigtype_pointer);
gimp_list_signals[REMOVE]=
gimp_signal_new ("remove", GTK_RUN_FIRST, type,
GTK_SIGNAL_OFFSET (GimpListClass, remove),
gimp_sigtype_pointer);
gtk_object_class_add_signals (object_class,
gimp_list_signals,
LAST_SIGNAL);
klass->add = gimp_list_add_func;
klass->remove = gimp_list_remove_func;
}
GtkType gimp_list_get_type (void)
{
static GtkType type;
GIMP_TYPE_INIT(type,
GimpList,
GimpListClass,
gimp_list_init,
gimp_list_class_init,
GIMP_TYPE_OBJECT);
return type;
}
GimpList*
gimp_list_new (GtkType type, gboolean weak){
GimpList* list=gtk_type_new (gimp_list_get_type ());
list->type=type;
list->weak=weak;
return list;
}
static void
gimp_list_destroy_cb (GtkObject* ob, gpointer data){
GimpList* list=GIMP_LIST(data);
gimp_list_remove(list, ob);
}
static void
gimp_list_add_func(GimpList* list, gpointer val)
{
list->list=g_slist_prepend(list->list, val);
}
static void
gimp_list_remove_func(GimpList* list, gpointer val)
{
list->list=g_slist_remove(list->list, val);
}
gboolean
gimp_list_add (GimpList* list, gpointer val)
{
g_return_val_if_fail(list, FALSE);
g_return_val_if_fail(GTK_CHECK_TYPE(val, list->type), FALSE);
if(g_slist_find(list->list, val))
return FALSE;
if(list->weak)
gtk_signal_connect(GTK_OBJECT(val), "destroy",
GTK_SIGNAL_FUNC(gimp_list_destroy_cb), list);
else
gtk_object_ref(GTK_OBJECT(val));
gtk_signal_emit (GTK_OBJECT(list), gimp_list_signals[ADD], val);
return TRUE;
}
gboolean
gimp_list_remove (GimpList* list, gpointer val)
{
g_return_val_if_fail(list, FALSE);
if(!g_slist_find(list->list, val))
return FALSE;
gtk_signal_emit (GTK_OBJECT(list), gimp_list_signals[REMOVE], val);
if(list->weak)
gtk_signal_disconnect_by_func
(GTK_OBJECT(val),
GTK_SIGNAL_FUNC(gimp_list_destroy_cb),
list);
else
gtk_object_unref(GTK_OBJECT(val));
return TRUE;
}
gboolean
gimp_list_have (GimpList* list, gpointer val) {
return g_slist_find(list->list, val)?TRUE:FALSE;
}
void
gimp_list_foreach(GimpList* list, GFunc func, gpointer user_data)
{
g_slist_foreach(list->list, func, user_data);
}
GtkType
gimp_list_type (GimpList* list){
return list->type;
}

38
app/core/gimplist.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef __GIMPLIST_H__
#define __GIMPLIST_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)
#define GIMP_IS_LIST(obj) GTK_CHECK_TYPE (obj, gimp_list_get_type())
/* Signals:
add
remove
*/
guint 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);
#endif

View File

@ -23,7 +23,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include "appenv.h"
#include "gimpbrushlist.h"
#include "gimpbrushgenerated.h"
#include "brush_header.h"
#include "brush_select.h"
@ -37,13 +36,15 @@
#include "gimpsignal.h"
#include "menus.h"
#include "paint_core.h"
#include "gimpset.h"
#include "gimpsetP.h"
#include "gimplist.h"
#include "gimpbrush.h"
#include "gimplistP.h"
#include "gimpbrushlistP.h"
/* global variables */
GimpBrushP active_brush = NULL;
GimpBrushList * brush_list = NULL;
GimpBrush *active_brush = NULL;
GimpBrushList *brush_list = NULL;
double opacity = 1.0;
int paint_mode = 0;
@ -69,14 +70,29 @@ static void gimp_brush_list_uniquefy_names(GimpBrushList *brush_list);
/* class functions */
static GimpObjectClass* parent_class;
static void
gimp_brush_list_add_func(GimpList* list, gpointer val)
{
list->list=g_slist_insert_sorted (list->list, val, brush_compare_func);
GIMP_BRUSH_LIST(list)->num_brushes++;
}
static void
gimp_list_remove_func(GimpList* list, gpointer val)
{
list->list=g_slist_remove(list->list, val);
GIMP_BRUSH_LIST(list)->num_brushes--;
}
static void
gimp_brush_list_class_init (GimpBrushListClass *klass)
{
GtkObjectClass *object_class;
GimpListClass *gimp_list_class;
object_class = GTK_OBJECT_CLASS(klass);
parent_class = gtk_type_class (gimp_object_get_type ());
gimp_list_class = GIMP_LIST_CLASS(klass);
gimp_list_class->add = gimp_brush_list_add_func;
gimp_list_class->remove = gimp_brush_list_add_func;
parent_class = gtk_type_class (gimp_list_get_type ());
}
void
@ -98,7 +114,7 @@ GtkType gimp_brush_list_get_type(void)
(GtkObjectInitFunc)gimp_brush_list_init,
NULL,
NULL };
type=gtk_type_unique(gimp_set_get_type(), &info);
type=gtk_type_unique(gimp_list_get_type(), &info);
}
return type;
}
@ -107,24 +123,24 @@ GimpBrushList *
gimp_brush_list_new ()
{
GimpBrushList *list=GIMP_BRUSH_LIST(gtk_type_new(gimp_brush_list_get_type()));
GIMP_SET(list)->type = GIMP_TYPE_BRUSH;
GIMP_SET(list)->weak = 0;
GIMP_LIST(list)->type = GIMP_TYPE_BRUSH;
GIMP_LIST(list)->weak = 0;
return list;
}
void gimp_brush_list_uniquefy_names(GimpBrushList *blist)
{
GSList *list = GIMP_SET(blist)->list;
GimpBrushP gb_start = NULL;
GSList *list = GIMP_LIST(blist)->list;
GimpBrush * gb_start = NULL;
gint gb_count = 0;
while (list)
{
GimpBrushP gb = (GimpBrushP)list->data;
GimpBrush * gb = (GimpBrush *)list->data;
list = g_slist_next(list);
if(list) {
GimpBrushP gb2 = (GimpBrushP)list->data;
GimpBrush * gb2 = (GimpBrush *)list->data;
if(gb_start == NULL) {
gb_start = gb;
@ -186,8 +202,8 @@ brushes_free_one (gpointer data, gpointer dummy)
static gint
brush_compare_func (gconstpointer first, gconstpointer second)
{
return strcmp (((const GimpBrushP)first)->name,
((const GimpBrushP)second)->name);
return strcmp (((const GimpBrush *)first)->name,
((const GimpBrush *)second)->name);
}
@ -195,7 +211,7 @@ void
brushes_free ()
{
if (brush_list) {
/* gimp_set_foreach (brush_list, brushes_free_one, NULL); */
/* gimp_list_foreach (GIMP_LIST(brush_list), brushes_free_one, NULL);*/
gimp_object_destroy(GIMP_OBJECT(brush_list));
}
@ -216,7 +232,7 @@ brush_select_dialog_free ()
}
GimpBrushP
GimpBrush *
get_active_brush ()
{
if (have_default_brush)
@ -226,15 +242,15 @@ get_active_brush ()
fatal_error ("Specified default brush not found!");
}
else if (! active_brush && brush_list)
/* need a gimp_set_get_first() type function */
active_brush = (GimpBrushP) GIMP_SET(brush_list)->list->data;
/* need a gimp_list_get_first() type function */
active_brush = (GimpBrush *) GIMP_LIST(brush_list)->list->data;
return active_brush;
}
static GSList *
insert_brush_in_list (GSList *list, GimpBrushP brush)
insert_brush_in_list (GSList *list, GimpBrush * brush)
{
return g_slist_insert_sorted (list, brush, brush_compare_func);
}
@ -257,15 +273,15 @@ create_default_brush ()
GimpBrushP
GimpBrush *
get_brush_by_index (int index)
{
GSList *list;
GimpBrushP brush = NULL;
/* fix me: make a gimp_set function that does this */
list = g_slist_nth (GIMP_SET(brush_list)->list, index);
GimpBrush * brush = NULL;
/* fix me: make a gimp_list function that does this? */
list = g_slist_nth (GIMP_LIST(brush_list)->list, index);
if (list)
brush = (GimpBrushP) list->data;
brush = (GimpBrush *) list->data;
return brush;
}
@ -279,20 +295,57 @@ static void
gimp_brush_list_recalc_indexes(GimpBrushList *brush_list)
{
int index = 0;
gimp_set_foreach (GIMP_SET(brush_list), (GFunc)gimp_brush_do_indexes,
&index);
gimp_list_foreach (GIMP_LIST(brush_list), (GFunc)gimp_brush_do_indexes,
&index);
}
void
gimp_brush_list_add (GimpBrushList *brush_list, GimpBrushP brush)
gimp_brush_list_add (GimpBrushList *brush_list, GimpBrush * brush)
{
gimp_set_add(GIMP_SET(brush_list), brush);
brush_list->num_brushes++;
gimp_list_add(GIMP_LIST(brush_list), brush);
gimp_brush_list_recalc_indexes(brush_list);
}
void
select_brush (GimpBrushP brush)
gimp_brush_list_remove (GimpBrushList *brush_list, GimpBrush * brush)
{
gimp_list_remove(GIMP_LIST(brush_list), brush);
gimp_brush_list_recalc_indexes(brush_list);
}
int
gimp_brush_list_length (GimpBrushList *brush_list)
{
g_return_val_if_fail(GIMP_IS_BRUSH_LIST(brush_list), 0);
return (brush_list->num_brushes);
}
GimpBrush *
gimp_brush_list_get_brush(GimpBrushList *blist, char *name)
{
GimpBrush *brushp;
GSList *list;
if (blist == NULL)
return NULL;
list = GIMP_LIST(brush_list)->list;
while (list)
{
brushp = (GimpBrush *) list->data;
if (!strcmp (brushp->name, name))
{
return brushp;
}
list = g_slist_next (list);
}
return NULL;
}
void
select_brush (GimpBrush * brush)
{
/* Make sure the active brush is swapped before we get a new one... */
if (stingy_memory_use)
@ -340,7 +393,7 @@ create_brush_dialog ()
static Argument *
brushes_get_brush_invoker (Argument *args)
{
GimpBrushP brushp;
GimpBrush * brushp;
success = (brushp = get_active_brush ()) != NULL;
@ -772,29 +825,6 @@ ProcRecord brushes_set_paint_mode_proc =
};
GimpBrushP
gimp_brush_list_get_brush(GimpBrushListP blist, char *name)
{
GimpBrushP brushp;
GSList *list;
if (blist == NULL)
return NULL;
list = GIMP_SET(brush_list)->list;
while (list)
{
brushp = (GimpBrushP) list->data;
if (!strcmp (brushp->name, name))
{
return brushp;
}
list = g_slist_next (list);
}
return NULL;
}
/***********************/
/* BRUSHES_SET_BRUSH */
@ -803,7 +833,7 @@ gimp_brush_list_get_brush(GimpBrushListP blist, char *name)
static Argument *
brushes_set_brush_invoker (Argument *args)
{
GimpBrushP brushp;
GimpBrush * brushp;
char *name;
success = (name = (char *) args[0].value.pdb_pointer) != NULL;
@ -860,19 +890,19 @@ ProcRecord brushes_set_brush_proc =
static Argument *
brushes_list_invoker (Argument *args)
{
GimpBrushP brushp;
GimpBrush * brushp;
GSList *list;
char **brushes;
int i;
brushes = (char **) g_malloc (sizeof (char *) * brush_list->num_brushes);
success = (list = GIMP_SET(brush_list)->list) != NULL;
success = (list = GIMP_LIST(brush_list)->list) != NULL;
i = 0;
while (list)
{
brushp = (GimpBrushP) list->data;
brushp = (GimpBrush *) list->data;
brushes[i++] = g_strdup (brushp->name);
list = g_slist_next (list);

View File

@ -22,36 +22,19 @@
#include "procedural_db.h"
#include "temp_buf.h"
#include "gimpbrush.h"
#include "gimpset.h"
#include "gimpsetP.h"
#include "gimpbrushlistF.h"
typedef struct _GimpBrushList GimpBrushList, * GimpBrushListP;
struct _GimpBrushList
{
GimpSet gimpset;
int num_brushes;
};
typedef struct _GimpBrushListClass GimpBrushListClass;
struct _GimpBrushListClass
{
GimpSetClass parent_class;
};
#define BRUSH_LIST_CLASS(klass) \
GTK_CHECK_CLASS_CAST (klass, gimp_brush_list_get_type(), GimpBrushListClass)
#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))
GimpBrushListP gimp_brush_list_new (void);
GimpBrushList *gimp_brush_list_new (void);
GtkType gimp_brush_list_get_type (void);
void gimp_brush_list_add (GimpBrushListP list,
GimpBrushP brush);
GimpBrushP gimp_brush_list_get_brush(GimpBrushListP list, char *name);
void gimp_brush_list_add (GimpBrushList *list,
GimpBrush *brush);
GimpBrushP gimp_brush_list_get_brush(GimpBrushList *list, char *name);
int gimp_brush_list_length (GimpBrushList *list);
/* global variables */
@ -69,8 +52,6 @@ GimpBrushP get_active_brush (void);
/* TODO: {re}move this function */
void create_brush_dialog (void);
/* access functions */
/* TODO: move opacity and paint_mode into individual tools? */
/* TODO: move spacing into gimpbrush */

6
app/gimpbrushlistF.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __GIMPBRUSHLISTF_H__
#define __GIMPBRUSHLISTF_H__
typedef struct _GimpBrushList GimpBrushList;
#endif /* __GIMPBRUSHLISTF_H__ */

24
app/gimpbrushlistP.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef __GIMPBRUSHLISTP_H__
#define __GIMPBRUSHLISTP_H__
#include "gimplistP.h"
#include "gimpbrushlist.h"
struct _GimpBrushList
{
GimpList gimplist;
int num_brushes;
};
struct _GimpBrushListClass
{
GimpListClass parent_class;
};
typedef struct _GimpBrushListClass GimpBrushListClass;
#define BRUSH_LIST_CLASS(klass) \
GTK_CHECK_CLASS_CAST (klass, gimp_brush_list_get_type(), GimpBrushListClass)
#endif /* __GIMPBRUSHLISTP_H__ */

180
app/gimplist.c Normal file
View File

@ -0,0 +1,180 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 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 "gimpsignal.h"
#include "gimplistP.h"
/* code mostly ripped from nether's gimpset class */
enum
{
ADD,
REMOVE,
LAST_SIGNAL
};
static guint gimp_list_signals [LAST_SIGNAL];
static GimpObjectClass* parent_class;
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)
{
GimpList* list=GIMP_LIST(ob);
GSList* node;
for(node=list->list;node;node=node->next){
if(!list->weak)
gtk_object_unref(GTK_OBJECT(node->data));
gtk_signal_emit (GTK_OBJECT(list),
gimp_list_signals[REMOVE],
node->data);
}
g_slist_free(list->list);
GTK_OBJECT_CLASS(parent_class)->destroy (ob);
}
static void
gimp_list_init (GimpList* list)
{
list->list=NULL;
list->type=GTK_TYPE_OBJECT;
}
static void
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,
GTK_SIGNAL_OFFSET (GimpListClass, add),
gimp_sigtype_pointer);
gimp_list_signals[REMOVE]=
gimp_signal_new ("remove", GTK_RUN_FIRST, type,
GTK_SIGNAL_OFFSET (GimpListClass, remove),
gimp_sigtype_pointer);
gtk_object_class_add_signals (object_class,
gimp_list_signals,
LAST_SIGNAL);
klass->add = gimp_list_add_func;
klass->remove = gimp_list_remove_func;
}
GtkType gimp_list_get_type (void)
{
static GtkType type;
GIMP_TYPE_INIT(type,
GimpList,
GimpListClass,
gimp_list_init,
gimp_list_class_init,
GIMP_TYPE_OBJECT);
return type;
}
GimpList*
gimp_list_new (GtkType type, gboolean weak){
GimpList* list=gtk_type_new (gimp_list_get_type ());
list->type=type;
list->weak=weak;
return list;
}
static void
gimp_list_destroy_cb (GtkObject* ob, gpointer data){
GimpList* list=GIMP_LIST(data);
gimp_list_remove(list, ob);
}
static void
gimp_list_add_func(GimpList* list, gpointer val)
{
list->list=g_slist_prepend(list->list, val);
}
static void
gimp_list_remove_func(GimpList* list, gpointer val)
{
list->list=g_slist_remove(list->list, val);
}
gboolean
gimp_list_add (GimpList* list, gpointer val)
{
g_return_val_if_fail(list, FALSE);
g_return_val_if_fail(GTK_CHECK_TYPE(val, list->type), FALSE);
if(g_slist_find(list->list, val))
return FALSE;
if(list->weak)
gtk_signal_connect(GTK_OBJECT(val), "destroy",
GTK_SIGNAL_FUNC(gimp_list_destroy_cb), list);
else
gtk_object_ref(GTK_OBJECT(val));
gtk_signal_emit (GTK_OBJECT(list), gimp_list_signals[ADD], val);
return TRUE;
}
gboolean
gimp_list_remove (GimpList* list, gpointer val)
{
g_return_val_if_fail(list, FALSE);
if(!g_slist_find(list->list, val))
return FALSE;
gtk_signal_emit (GTK_OBJECT(list), gimp_list_signals[REMOVE], val);
if(list->weak)
gtk_signal_disconnect_by_func
(GTK_OBJECT(val),
GTK_SIGNAL_FUNC(gimp_list_destroy_cb),
list);
else
gtk_object_unref(GTK_OBJECT(val));
return TRUE;
}
gboolean
gimp_list_have (GimpList* list, gpointer val) {
return g_slist_find(list->list, val)?TRUE:FALSE;
}
void
gimp_list_foreach(GimpList* list, GFunc func, gpointer user_data)
{
g_slist_foreach(list->list, func, user_data);
}
GtkType
gimp_list_type (GimpList* list){
return list->type;
}

38
app/gimplist.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef __GIMPLIST_H__
#define __GIMPLIST_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)
#define GIMP_IS_LIST(obj) GTK_CHECK_TYPE (obj, gimp_list_get_type())
/* Signals:
add
remove
*/
guint 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);
#endif

6
app/gimplistF.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __GIMPLISTF_H__
#define __GIMPLISTF_H__
typedef struct _GimpList GimpList;
#endif /* __GIMPLISTF_H__ */

44
app/gimplistP.h Normal file
View File

@ -0,0 +1,44 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 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 __GIMPLISTP_H__
#define __GIMPLISTP_H__
#include "gimpobjectP.h"
#include "gimplist.h"
struct _GimpList
{
GimpObject gobject;
GtkType type;
GSList* list;
gboolean weak;
};
struct _GimpListClass
{
GimpObjectClass parent_class;
void (* add) (GimpList *list, void *data);
void (* remove) (GimpList *list, void *data);
};
typedef struct _GimpListClass GimpListClass;
#define GIMP_LIST_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gimp_list_get_type(), GimpListClass)
#endif

View File

@ -3,4 +3,4 @@
typedef struct _GimpSet GimpSet;
#endif
#endif /* __GIMPSETF_H__ */

View File

@ -21,8 +21,7 @@
#include "appenv.h"
#include "actionarea.h"
#include "gimpbrushlist.h"
#include "gimpset.h"
#include "gimpsetP.h" /* FIXME: get rid of this include */
#include "gimplist.h"
#include "gimpbrushgenerated.h"
#include "brush_edit.h"
#include "brush_select.h"
@ -324,7 +323,8 @@ brush_select_new ()
/* render the brushes into the newly created image structure */
display_brushes (bsp);
gimp_set_foreach(GIMP_SET(brush_list), (GFunc)connect_signals_to_brush, bsp);
gimp_list_foreach(GIMP_LIST(brush_list), (GFunc)connect_signals_to_brush,
bsp);
gtk_signal_connect (GTK_OBJECT (brush_list), "add",
(GtkSignalFunc) brush_added_callback,
bsp);
@ -574,44 +574,31 @@ display_setup (BrushSelectP bsp)
}
static int brush_counter = 0;
static void do_display_brush (GimpBrush *brush, BrushSelectP bsp)
{
display_brush (bsp, brush, brush_counter % NUM_BRUSH_COLUMNS,
brush_counter / NUM_BRUSH_COLUMNS);
brush_counter++;
}
static void
display_brushes (BrushSelectP bsp)
{
/* FIXME: use gimp_set_foreach?? */
GSList * list = GIMP_SET(brush_list)->list; /* the global brush list */
int row, col;
GimpBrushP brush;
/* If there are no brushes, insensitize widgets */
if (brush_list == NULL)
{
gtk_widget_set_sensitive (bsp->options_box, FALSE);
return;
}
if (brush_list == NULL || gimp_brush_list_length(brush_list) == 0)
{
gtk_widget_set_sensitive (bsp->options_box, FALSE);
return;
}
/* Else, sensitize widgets */
else
gtk_widget_set_sensitive (bsp->options_box, TRUE);
/* setup the display area */
display_setup (bsp);
row = col = 0;
while (list)
{
brush = (GimpBrushP) list->data;
/* Display the brush */
display_brush (bsp, brush, col, row);
/* increment the counts */
if (++col == NUM_BRUSH_COLUMNS)
{
row ++;
col = 0;
}
list = g_slist_next (list);
}
brush_counter = 0;
gimp_list_foreach(GIMP_LIST(brush_list), (GFunc)do_display_brush, bsp);
}
@ -708,27 +695,18 @@ preview_calc_scrollbar (BrushSelectP bsp)
int page_size;
int max;
int offs;
/* int rowy; */
offs = bsp->scroll_offset;
num_rows = (brush_list->num_brushes + NUM_BRUSH_COLUMNS - 1)
num_rows = (gimp_brush_list_length(brush_list) + NUM_BRUSH_COLUMNS - 1)
/ NUM_BRUSH_COLUMNS;
max = num_rows * bsp->cell_width;
if (!num_rows) num_rows = 1;
page_size = bsp->preview->allocation.height;
page_size = ((page_size < max) ? page_size : max);
/*
rowy = (get_active_brush()->index / NUM_BRUSH_COLUMNS) * bsp->cell_width
+ bsp->cell_width/2;
if((rowy < offs) || (rowy > (offs + page_size)))
offs = rowy - page_size/2;
offs = MIN(MAX(offs, 0), max - page_size);
*/
bsp->scroll_offset = offs;
bsp->sbar_data->value = bsp->scroll_offset;
bsp->sbar_data->upper = max;
/* bsp->sbar_data->page_size = page_size; */
bsp->sbar_data->page_size = ((page_size < max) ? page_size : max);
bsp->sbar_data->page_increment = (page_size >> 1);
bsp->sbar_data->step_increment = bsp->cell_width;
@ -742,7 +720,7 @@ brush_select_resize (GtkWidget *widget,
BrushSelectP bsp)
{
NUM_BRUSH_COLUMNS = (gint)((widget->allocation.width - 4) / STD_CELL_WIDTH);
NUM_BRUSH_ROWS = (brush_list->num_brushes + NUM_BRUSH_COLUMNS - 1) / NUM_BRUSH_COLUMNS;
NUM_BRUSH_ROWS = (gimp_brush_list_length(brush_list) + NUM_BRUSH_COLUMNS - 1) / NUM_BRUSH_COLUMNS;
bsp->width = widget->allocation.width - 4;
bsp->height = widget->allocation.height - 4;

View File

@ -4043,7 +4043,8 @@ void
border_region(PixelRegion *src, gint16 radius)
{
/*
blame all bugs in this function on jaycox@earthlink.net
This function has no bugs, but if you imagine some you can
blame them on jaycox@earthlink.net
*/
register gint32 i, j, x, y;
guchar **buf, *out;
@ -4121,12 +4122,13 @@ border_region(PixelRegion *src, gint16 radius)
density = (guchar **)g_malloc (diameter*sizeof(void *));
density += radius;
for (x = -(radius); x < (radius+1); x++) /* allocate density[][] */
for (x = 0; x < (radius+1); x++) /* allocate density[][] */
{
density[x] = (guchar *)g_malloc (diameter);
density[x] += radius;
density[-x] = density[x];
}
for (x = -(radius); x < (radius+1); x++) /* compute density[][] */
for (x = 0; x < (radius+1); x++) /* compute density[][] */
{
register double tmpx, tmpy;
guchar a;
@ -4149,13 +4151,9 @@ border_region(PixelRegion *src, gint16 radius)
else
a = 0;
density[ x][ y] = a;
density[-x][ y] = a;
density[ x][-y] = a;
density[-x][-y] = a;
density[ y][ x] = a;
density[-y][ x] = a;
density[ y][-x] = a;
density[-y][-x] = a;
}
}
pixel_region_get_row (src, src->x, src->y + 0, src->w, buf[0], 1);
@ -4282,7 +4280,7 @@ border_region(PixelRegion *src, gint16 radius)
}
g_free (transition);
for (i = -radius; i < radius +1 ; i++)
for (i = 0; i < radius +1 ; i++)
{
density[i]-= radius;
g_free(density[i]);

View File

@ -4043,7 +4043,8 @@ void
border_region(PixelRegion *src, gint16 radius)
{
/*
blame all bugs in this function on jaycox@earthlink.net
This function has no bugs, but if you imagine some you can
blame them on jaycox@earthlink.net
*/
register gint32 i, j, x, y;
guchar **buf, *out;
@ -4121,12 +4122,13 @@ border_region(PixelRegion *src, gint16 radius)
density = (guchar **)g_malloc (diameter*sizeof(void *));
density += radius;
for (x = -(radius); x < (radius+1); x++) /* allocate density[][] */
for (x = 0; x < (radius+1); x++) /* allocate density[][] */
{
density[x] = (guchar *)g_malloc (diameter);
density[x] += radius;
density[-x] = density[x];
}
for (x = -(radius); x < (radius+1); x++) /* compute density[][] */
for (x = 0; x < (radius+1); x++) /* compute density[][] */
{
register double tmpx, tmpy;
guchar a;
@ -4149,13 +4151,9 @@ border_region(PixelRegion *src, gint16 radius)
else
a = 0;
density[ x][ y] = a;
density[-x][ y] = a;
density[ x][-y] = a;
density[-x][-y] = a;
density[ y][ x] = a;
density[-y][ x] = a;
density[ y][-x] = a;
density[-y][-x] = a;
}
}
pixel_region_get_row (src, src->x, src->y + 0, src->w, buf[0], 1);
@ -4282,7 +4280,7 @@ border_region(PixelRegion *src, gint16 radius)
}
g_free (transition);
for (i = -radius; i < radius +1 ; i++)
for (i = 0; i < radius +1 ; i++)
{
density[i]-= radius;
g_free(density[i]);