Commit af5cdfbd authored by BST 1998 Andy Thomas's avatar BST 1998 Andy Thomas Committed by Andy Thomas

app/brush_select.h app/brush_select.c app/internal_procs.c


Tue Oct 20 23:20:40 BST 1998 Andy Thomas <alt@picnic.demon.co.uk>


	* app/brush_select.h
	* app/brush_select.c
	* app/internal_procs.c
	* app/gimpbrushlist.c
	* libgimp/Makefile.am
	* libgimp/gimpmenu.h
	* libgimp/gimpmenu.c
	* plug-ins/script-fu/scripts/3d-outline.scm
	* plug-ins/script-fu/scripts/test-sphere.scm
	* plug-ins/script-fu/scripts/trochoid.scm
	* plug-ins/script-fu/script-fu-enums.h
	* plug-ins/script-fu/script-fu-scripts.c
	* plug-ins/script-fu/script-fu.c

	New file libgimp/gimpbrushmneu.c.

	Brush dialog can now be fully controlled via the PDB. New widget (not
	true widget) type added to libgimpui (gimp_brush_select_widget()).
	Plugins should easily be able to control & select brushes. Script-fu
	updated to use new widget. See the test script for example.

	Started to change some of the scripts to use the new widget types.
parent 30ffe1bc
Tue Oct 20 23:20:40 BST 1998 Andy Thomas <alt@picnic.demon.co.uk>
* app/brush_select.h
* app/brush_select.c
* app/internal_procs.c
* app/gimpbrushlist.c
* libgimp/Makefile.am
* libgimp/gimpmenu.h
* libgimp/gimpmenu.c
* plug-ins/script-fu/scripts/3d-outline.scm
* plug-ins/script-fu/scripts/test-sphere.scm
* plug-ins/script-fu/scripts/trochoid.scm
* plug-ins/script-fu/script-fu-enums.h
* plug-ins/script-fu/script-fu-scripts.c
* plug-ins/script-fu/script-fu.c
New file libgimp/gimpbrushmneu.c.
Brush dialog can now be fully controlled via the PDB. New widget (not
true widget) type added to libgimpui (gimp_brush_select_widget()).
Plugins should easily be able to control & select brushes. Script-fu
updated to use new widget. See the test script for example.
Started to change some of the scripts to use the new widget types.
1998-10-19 Christopher James Lahey <clahey@umich.edu>
* app/docindex.c: New Drag & Drop works now.
......
......@@ -270,7 +270,8 @@ brush_select_new (gchar * title,
label = gtk_label_new (_("Mode:"));
gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 2);
menu = create_paint_mode_menu (paint_mode_menu_callback,(gpointer)bsp);
option_menu = gtk_option_menu_new ();
bsp->option_menu =
option_menu = gtk_option_menu_new ();
gtk_box_pack_start (GTK_BOX (util_box), option_menu, FALSE, FALSE, 2);
gtk_widget_show (label);
......@@ -284,7 +285,7 @@ brush_select_new (gchar * title,
label = gtk_label_new (_("Opacity:"));
gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 2);
bsp->opacity_data =
GTK_ADJUSTMENT (gtk_adjustment_new ((active)?init_opacity:100.0, 0.0, 100.0, 1.0, 1.0, 0.0));
GTK_ADJUSTMENT (gtk_adjustment_new ((active)?(init_opacity*100.0):100.0, 0.0, 100.0, 1.0, 1.0, 0.0));
slider = gtk_hscale_new (bsp->opacity_data);
gtk_box_pack_start (GTK_BOX (util_box), slider, TRUE, TRUE, 0);
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
......@@ -1221,7 +1222,7 @@ brushes_popup_invoker (Argument *args)
gchar * name;
gchar * title;
gchar * initial_brush;
gdouble initial_opacity = 100.0;
gdouble initial_opacity = 1.0;
gint initial_spacing = 20;
gint initial_mode = 0;
ProcRecord *prec = NULL;
......@@ -1316,3 +1317,200 @@ ProcRecord brushes_popup_proc =
/* Exec method */
{ { brushes_popup_invoker } },
};
static BrushSelectP
brush_get_brushselect(gchar *name)
{
GSList *list;
BrushSelectP bsp;
list = active_dialogs;
while (list)
{
bsp = (BrushSelectP) list->data;
list = list->next;
if(strcmp(name,bsp->callback_name) == 0)
{
return bsp;
}
}
return NULL;
}
static Argument *
brush_close_popup_invoker (Argument *args)
{
gchar * name;
ProcRecord *prec = NULL;
BrushSelectP bsp;
success = (name = (char *) args[0].value.pdb_pointer) != NULL;
/* Check the proc exists */
if(!success || (prec = procedural_db_lookup(name)) == NULL)
{
success = 0;
return procedural_db_return_args (&brushes_close_popup_proc, success);
}
bsp = brush_get_brushselect(name);
if(bsp)
{
active_dialogs = g_slist_remove(active_dialogs,bsp);
if (GTK_WIDGET_VISIBLE (bsp->shell))
gtk_widget_hide (bsp->shell);
/* Free memory if poping down dialog which is not the main one */
if(bsp != brush_select_dialog)
{
gtk_widget_destroy(bsp->shell);
brush_select_free(bsp);
}
}
else
{
success = FALSE;
}
return procedural_db_return_args (&brushes_close_popup_proc, success);
}
/* The procedure definition */
ProcArg brush_close_popup_in_args[] =
{
{ PDB_STRING,
"callback_PDB_entry_name",
N_("The name of the callback registered for this popup"),
},
};
ProcRecord brushes_close_popup_proc =
{
"gimp_brushes_close_popup",
N_("Popdown the Gimp brush selection"),
N_("This procedure closes an opened brush selection dialog"),
"Andy Thomas",
"Andy Thomas",
"1998",
PDB_INTERNAL,
/* Input arguments */
sizeof(brush_close_popup_in_args) / sizeof(brush_close_popup_in_args[0]),
brush_close_popup_in_args,
/* Output arguments */
0,
NULL,
/* Exec method */
{ { brush_close_popup_invoker } },
};
static Argument *
brush_set_popup_invoker (Argument *args)
{
gchar * pdbname;
gchar * brush_name;
ProcRecord *prec = NULL;
BrushSelectP bsp;
success = (pdbname = (char *) args[0].value.pdb_pointer) != NULL;
brush_name = (char *) args[1].value.pdb_pointer;
/* Check the proc exists */
if(!success || (prec = procedural_db_lookup(pdbname)) == NULL)
{
success = 0;
return procedural_db_return_args (&brushes_set_popup_proc, success);
}
bsp = brush_get_brushselect(pdbname);
if(bsp)
{
GimpBrushP active = gimp_brush_list_get_brush(brush_list,brush_name);
if(active)
{
/* Must alter the wigdets on screen as well */
bsp->brush = active;
brush_select_select (bsp, gimp_brush_list_get_brush_index(brush_list, active));
bsp->opacity_value = args[2].value.pdb_float;
bsp->spacing_value = args[3].value.pdb_int;
if(args[4].value.pdb_int >= 0 && args[4].value.pdb_int <= VALUE_MODE)
bsp->paint_mode = args[4].value.pdb_int;
bsp->spacing_data->value = bsp->spacing_value;
gtk_signal_emit_by_name (GTK_OBJECT (bsp->spacing_data), "value_changed");
bsp->opacity_data->value = bsp->opacity_value * 100.0;
gtk_signal_emit_by_name (GTK_OBJECT (bsp->opacity_data), "value_changed");
gtk_option_menu_set_history(GTK_OPTION_MENU(bsp->option_menu),bsp->paint_mode);
/* Can alter active_dialogs list*/
success = TRUE;
}
}
else
{
success = FALSE;
}
return procedural_db_return_args (&brushes_set_popup_proc, success);
}
/* The procedure definition */
ProcArg brush_set_popup_in_args[] =
{
{ PDB_STRING,
"callback_PDB_entry_name",
N_("The name of the callback registered for this popup"),
},
{ PDB_STRING,
"brushname",
N_("The name of the brush to set as selected"),
},
{ PDB_FLOAT,
"opacity",
N_("The initial opacity of the brush"),
},
{ PDB_INT32,
"spacing",
N_("The initial spacing of the brush (if < 0 then use brush default spacing)"),
},
{ PDB_INT32,
"initial paint mode",
N_("The initial paint mode: { NORMAL (0), DISSOLVE (1), BEHIND (2), MULTIPLY/BURN (3), SCREEN (4), OVERLAY (5) DIFFERENCE (6), ADDITION (7), SUBTRACT (8), DARKEN-ONLY (9), LIGHTEN-ONLY (10), HUE (11), SATURATION (12), COLOR (13), VALUE (14), DIVIDE/DODGE (15) }"),
},
};
ProcRecord brushes_set_popup_proc =
{
"gimp_brushes_set_popup",
N_("Sets the current brush selection in a popup"),
N_("Sets the current brush selection in a popup"),
"Andy Thomas",
"Andy Thomas",
"1998",
PDB_INTERNAL,
/* Input arguments */
sizeof(brush_set_popup_in_args) / sizeof(brush_set_popup_in_args[0]),
brush_set_popup_in_args,
/* Output arguments */
0,
NULL,
/* Exec method */
{ { brush_set_popup_invoker } },
};
......@@ -35,6 +35,7 @@ struct _BrushSelect {
GtkAdjustment *spacing_data;
GtkAdjustment *sbar_data;
GtkWidget *edit_button;
GtkWidget *option_menu;
int width, height;
int cell_width, cell_height;
int scroll_offset;
......@@ -74,5 +75,8 @@ GtkWidget * create_paint_mode_menu (MenuItemCallback, gpointer);
/* PDB entry */
extern ProcRecord brushes_popup_proc;
extern ProcRecord brushes_close_popup_proc;
extern ProcRecord brushes_set_popup_proc;
extern ProcRecord brushes_get_brush_data_proc;
#endif /* __BRUSH_SELECT_H__ */
......@@ -988,3 +988,126 @@ ProcRecord brushes_list_proc =
/* Exec method */
{ { brushes_list_invoker } },
};
/*******************************/
/* BRUSHES_GET_BRUSH_DATA */
static Argument *
brushes_get_brush_data_invoker (Argument *args)
{
GimpBrushP brushp = NULL;
GSList *list;
char *name;
static Argument *return_args;
success = (name = (char *) args[0].value.pdb_pointer) != NULL;
if (!success)
{
/* No name use active pattern */
success = (brushp = get_active_brush ()) != NULL;
}
else
{
list = GIMP_LIST(brush_list)->list;
success = FALSE;
while (list)
{
brushp = (GimpBrushP) list->data;
if (!strcmp (brushp->name, name))
{
success = TRUE;
break;
}
list = g_slist_next (list);
}
}
return_args = procedural_db_return_args (&brushes_get_brush_data_proc, success);
if (success)
{
return_args[1].value.pdb_pointer = g_strdup (brushp->name);
return_args[2].value.pdb_float = 1.0; /*opacity_value;*/
return_args[3].value.pdb_int = brushp->spacing;
return_args[4].value.pdb_int = 0; /* paint_mode; */
return_args[5].value.pdb_int = brushp->mask->width;
return_args[6].value.pdb_int = brushp->mask->height;
return_args[7].value.pdb_int = brushp->mask->height*brushp->mask->width;
return_args[8].value.pdb_pointer = g_malloc(return_args[7].value.pdb_int);
g_memmove(return_args[8].value.pdb_pointer,
temp_buf_data (brushp->mask),
return_args[7].value.pdb_int);
}
return return_args;
}
/* The procedure definition */
ProcArg brushes_get_brush_data_in_args[] =
{
{ PDB_STRING,
"name",
"the brush name (\"\" means current active pattern) "
}
};
ProcArg brushes_get_brush_data_out_args[] =
{
{ PDB_STRING,
"name",
"the brush name"
},
{ PDB_FLOAT,
"opacity",
"the brush opacity"
},
{ PDB_INT32,
"spacing",
"the brush spacing"
},
{ PDB_INT32,
"paint_mode",
"the brush paint mode"
},
{ PDB_INT32,
"width",
"the brush width"
},
{ PDB_INT32,
"height",
"the brush height"
},
{ PDB_INT32,
"length",
"length of brush mask data"},
{ PDB_INT8ARRAY,
"mask_data",
"the brush mask data"},
};
ProcRecord brushes_get_brush_data_proc =
{
"gimp_brushes_get_brush_data",
"Retrieve information about the currently active brush (including data)",
"This procedure retrieves information about the currently active brush. This includes the brush name, and the brush extents (width and height). It also returns the brush data",
"Andy Thomas",
"Andy Thomas",
"1998",
PDB_INTERNAL,
/* Input arguments */
sizeof(brushes_get_brush_data_in_args) / sizeof(brushes_get_brush_data_in_args[0]),
brushes_get_brush_data_in_args,
/* Output arguments */
sizeof(brushes_get_brush_data_out_args) / sizeof(brushes_get_brush_data_out_args[0]),
brushes_get_brush_data_out_args,
/* Exec method */
{ { brushes_get_brush_data_invoker } },
};
......@@ -270,7 +270,8 @@ brush_select_new (gchar * title,
label = gtk_label_new (_("Mode:"));
gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 2);
menu = create_paint_mode_menu (paint_mode_menu_callback,(gpointer)bsp);
option_menu = gtk_option_menu_new ();
bsp->option_menu =
option_menu = gtk_option_menu_new ();
gtk_box_pack_start (GTK_BOX (util_box), option_menu, FALSE, FALSE, 2);
gtk_widget_show (label);
......@@ -284,7 +285,7 @@ brush_select_new (gchar * title,
label = gtk_label_new (_("Opacity:"));
gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 2);
bsp->opacity_data =
GTK_ADJUSTMENT (gtk_adjustment_new ((active)?init_opacity:100.0, 0.0, 100.0, 1.0, 1.0, 0.0));
GTK_ADJUSTMENT (gtk_adjustment_new ((active)?(init_opacity*100.0):100.0, 0.0, 100.0, 1.0, 1.0, 0.0));
slider = gtk_hscale_new (bsp->opacity_data);
gtk_box_pack_start (GTK_BOX (util_box), slider, TRUE, TRUE, 0);
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
......@@ -1221,7 +1222,7 @@ brushes_popup_invoker (Argument *args)
gchar * name;
gchar * title;
gchar * initial_brush;
gdouble initial_opacity = 100.0;
gdouble initial_opacity = 1.0;
gint initial_spacing = 20;
gint initial_mode = 0;
ProcRecord *prec = NULL;
......@@ -1316,3 +1317,200 @@ ProcRecord brushes_popup_proc =
/* Exec method */
{ { brushes_popup_invoker } },
};
static BrushSelectP
brush_get_brushselect(gchar *name)
{
GSList *list;
BrushSelectP bsp;
list = active_dialogs;
while (list)
{
bsp = (BrushSelectP) list->data;
list = list->next;
if(strcmp(name,bsp->callback_name) == 0)
{
return bsp;
}
}
return NULL;
}
static Argument *
brush_close_popup_invoker (Argument *args)
{
gchar * name;
ProcRecord *prec = NULL;
BrushSelectP bsp;
success = (name = (char *) args[0].value.pdb_pointer) != NULL;
/* Check the proc exists */
if(!success || (prec = procedural_db_lookup(name)) == NULL)
{
success = 0;
return procedural_db_return_args (&brushes_close_popup_proc, success);
}
bsp = brush_get_brushselect(name);
if(bsp)
{
active_dialogs = g_slist_remove(active_dialogs,bsp);
if (GTK_WIDGET_VISIBLE (bsp->shell))
gtk_widget_hide (bsp->shell);
/* Free memory if poping down dialog which is not the main one */
if(bsp != brush_select_dialog)
{
gtk_widget_destroy(bsp->shell);
brush_select_free(bsp);
}
}
else
{
success = FALSE;
}
return procedural_db_return_args (&brushes_close_popup_proc, success);
}
/* The procedure definition */
ProcArg brush_close_popup_in_args[] =
{
{ PDB_STRING,
"callback_PDB_entry_name",
N_("The name of the callback registered for this popup"),
},
};
ProcRecord brushes_close_popup_proc =
{
"gimp_brushes_close_popup",
N_("Popdown the Gimp brush selection"),
N_("This procedure closes an opened brush selection dialog"),
"Andy Thomas",
"Andy Thomas",
"1998",
PDB_INTERNAL,
/* Input arguments */
sizeof(brush_close_popup_in_args) / sizeof(brush_close_popup_in_args[0]),
brush_close_popup_in_args,
/* Output arguments */
0,
NULL,
/* Exec method */
{ { brush_close_popup_invoker } },
};
static Argument *
brush_set_popup_invoker (Argument *args)
{
gchar * pdbname;
gchar * brush_name;
ProcRecord *prec = NULL;
BrushSelectP bsp;
success = (pdbname = (char *) args[0].value.pdb_pointer) != NULL;
brush_name = (char *) args[1].value.pdb_pointer;
/* Check the proc exists */
if(!success || (prec = procedural_db_lookup(pdbname)) == NULL)
{
success = 0;
return procedural_db_return_args (&brushes_set_popup_proc, success);
}
bsp = brush_get_brushselect(pdbname);
if(bsp)
{
GimpBrushP active = gimp_brush_list_get_brush(brush_list,brush_name);
if(active)
{
/* Must alter the wigdets on screen as well */
bsp->brush = active;
brush_select_select (bsp, gimp_brush_list_get_brush_index(brush_list, active));
bsp->opacity_value = args[2].value.pdb_float;
bsp->spacing_value = args[3].value.pdb_int;
if(args[4].value.pdb_int >= 0 && args[4].value.pdb_int <= VALUE_MODE)
bsp->paint_mode = args[4].value.pdb_int;
bsp->spacing_data->value = bsp->spacing_value;
gtk_signal_emit_by_name (GTK_OBJECT (bsp->spacing_data), "value_changed");
bsp->opacity_data->value = bsp->opacity_value * 100.0;
gtk_signal_emit_by_name (GTK_OBJECT (bsp->opacity_data), "value_changed");
gtk_option_menu_set_history(GTK_OPTION_MENU(bsp->option_menu),bsp->paint_mode);
/* Can alter active_dialogs list*/
success = TRUE;
}
}
else
{
success = FALSE;
}
return procedural_db_return_args (&brushes_set_popup_proc, success);
}
/* The procedure definition */
ProcArg brush_set_popup_in_args[] =
{
{ PDB_STRING,
"callback_PDB_entry_name",
N_("The name of the callback registered for this popup"),
},
{ PDB_STRING,
"brushname",
N_("The name of the brush to set as selected"),
},
{ PDB_FLOAT,
"opacity",
N_("The initial opacity of the brush"),
},
{ PDB_INT32,
"spacing",
N_("The initial spacing of the brush (if < 0 then use brush default spacing)"),
},
{ PDB_INT32,
"initial paint mode",
N_("The initial paint mode: { NORMAL (0), DISSOLVE (1), BEHIND (2), MULTIPLY/BURN (3), SCREEN (4), OVERLAY (5) DIFFERENCE (6), ADDITION (7), SUBTRACT (8), DARKEN-ONLY (9), LIGHTEN-ONLY (10), HUE (11), SATURATION (12), COLOR (13), VALUE (14), DIVIDE/DODGE (15) }"),
},
};
ProcRecord brushes_set_popup_proc =
{
"gimp_brushes_set_popup",
N_("Sets the current brush selection in a popup"),
N_("Sets the current brush selection in a popup"),
"Andy Thomas",
"Andy Thomas",
"1998",
PDB_INTERNAL,
/* Input arguments */
sizeof(brush_set_popup_in_args) / sizeof(brush_set_popup_in_args[0]),
brush_set_popup_in_args,
/* Output arguments */
0,
NULL,
/* Exec method */
{ { brush_set_popup_invoker } },
};
......@@ -35,6 +35,7 @@ struct _BrushSelect {
GtkAdjustment *spacing_data;
GtkAdjustment *sbar_data;
GtkWidget *edit_button;
GtkWidget *option_menu;
int width, height;
int cell_width, cell_height;
int scroll_offset;
......@@ -74,5 +75,8 @@ GtkWidget * create_paint_mode_menu (MenuItemCallback, gpointer);
/* PDB entry */
extern ProcRecord brushes_popup_proc;
extern ProcRecord brushes_close_popup_proc;
extern ProcRecord brushes_set_popup_proc;
extern ProcRecord brushes_get_brush_data_proc;
#endif /* __BRUSH_SELECT_H__ */
......@@ -80,7 +80,7 @@ internal_procs_init ()
{
gfloat pcount = 0;
/* grep -c procedural_db_register internal_procs.c */
gfloat total_pcount = 237;
gfloat total_pcount = 240;
app_init_update_status("Internal Procedures", "Tool procedures",
pcount/total_pcount);
......@@ -338,6 +338,9 @@ internal_procs_init ()
procedural_db_register (&brushes_set_paint_mode_proc); pcount++;
procedural_db_register (&brushes_list_proc); pcount++;
procedural_db_register (&brushes_popup_proc); pcount++;
procedural_db_register (&brushes_close_popup_proc); pcount++;
procedural_db_register (&brushes_set_popup_proc); pcount++;
procedural_db_register (&brushes_get_brush_data_proc); pcount++;
procedural_db_register (&patterns_get_pattern_proc); pcount++;
procedural_db_register (&patterns_set_pattern_proc); pcount++;
procedural_db_register (&patterns_list_proc); pcount++;
......
......@@ -48,6 +48,7 @@ libgimp_la_SOURCES = \
libgimpui_la_SOURCES = \
gimpmenu.c \
gimpbrushmenu.c \
gimppatternmenu.c
gimpinclude_HEADERS = \
......
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
* Copyright (C) 1998 Andy Thomas
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <string.h>
#include "gimp.h"
#include "gimpui.h"
/* Idea is to have a function to call that returns a widget that
* completely controls the selection of a brush.
* you get a widget returned that you can use in a table say.
* In:- Initial brush name. Null means use current selection.
* pointer to func to call when brush changes (GRunBrushCallback).
* Returned:- Pointer to a widget that you can use in UI.
*
* Widget simply made up of a preview widget (20x20) containing the brush mask
* and a button that can be clicked on to change the brush.
*/
#define BSEL_DATA_KEY "__bsel_data"
#define CELL_SIZE 20
#define BRUSH_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK
struct __brushes_sel {
gchar * dname;
GRunBrushCallback cback;
GtkWidget *brush_preview;