bind the "gimp-libgimp" textdomain to get the libgimp widget translations.

2000-01-28  Michael Natterer  <mitch@gimp.org>

	* app/main.c: bind the "gimp-libgimp" textdomain to get the
	libgimp widget translations. Did some code cleanup.

	* libgimp/stdplugins-intl.h: bind "gimp-libgimp".

	* libgimp/gimpintl.h: copyright header.

	* libgimp/libgimp-intl.h: there is no dgettext_noop() function
	(typo/braino).

	* libgimp/gimpwidgets.[ch]: one more table attach helper
	function. Should probably find a general way for the two
	functions.

	* plug-ins/common/CML_explorer.c
	* plug-ins/common/align_layers.c
	* plug-ins/common/scatter_hsv.c
	* plug-ins/common/threshold_alpha.c: removed the gtkW_* wrapper
	functions. Badly hacked CML_explorer (The optionmenu creation is a
	bit more ugly than before but at least consistent with the other
	files using the libgimp optionmenu constructor).
This commit is contained in:
Michael Natterer 2000-01-27 19:26:00 +00:00 committed by Michael Natterer
parent b6c9232fbe
commit 278a69918d
13 changed files with 1824 additions and 2267 deletions

View File

@ -1,3 +1,27 @@
2000-01-28 Michael Natterer <mitch@gimp.org>
* app/main.c: bind the "gimp-libgimp" textdomain to get the
libgimp widget translations. Did some code cleanup.
* libgimp/stdplugins-intl.h: bind "gimp-libgimp".
* libgimp/gimpintl.h: copyright header.
* libgimp/libgimp-intl.h: there is no dgettext_noop() function
(typo/braino).
* libgimp/gimpwidgets.[ch]: one more table attach helper
function. Should probably find a general way for the two
functions.
* plug-ins/common/CML_explorer.c
* plug-ins/common/align_layers.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/threshold_alpha.c: removed the gtkW_* wrapper
functions. Badly hacked CML_explorer (The optionmenu creation is a
bit more ugly than before but at least consistent with the other
files using the libgimp optionmenu constructor).
2000-01-28 Asbjorn Pettersen <asbjornP@dualog.no>
* plug-ins/print/print-ps.c: use g_strcasecmp() instead of

View File

@ -17,7 +17,6 @@
*/
#include "config.h"
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
@ -49,36 +48,37 @@
#ifdef G_OS_WIN32
#include <windows.h>
#else
static RETSIGTYPE on_signal (int);
static RETSIGTYPE on_signal (gint);
#ifdef SIGCHLD
static RETSIGTYPE on_sig_child (int);
static RETSIGTYPE on_sig_child (gint);
#endif
#endif
static void init (void);
static void test_gserialize();
static void on_error (const gchar* domain,
GLogLevelFlags flags,
const gchar* msg,
gpointer user_data);
static void init (void);
static void test_gserialize (void);
static void on_error (const gchar *domain,
GLogLevelFlags flags,
const gchar *msg,
gpointer user_data);
/* GLOBAL data */
int no_interface;
int no_data;
int no_splash;
int no_splash_image;
int be_verbose;
int use_shm;
int use_debug_handler;
int console_messages;
int restore_session;
GimpSet* image_context;
gint no_interface = FALSE;
gint no_data = FALSE;
gint no_splash = FALSE;
gint no_splash_image = FALSE;
gint be_verbose = FALSE;
gint use_shm = FALSE;
gint use_debug_handler = FALSE;
gint console_messages = FALSE;
gint restore_session = FALSE;
MessageHandlerType message_handler;
GimpSet *image_context = NULL;
gchar *prog_name; /* The path name we are invoked with */
gchar *alternate_gimprc;
gchar *alternate_system_gimprc;
gchar **batch_cmds;
MessageHandlerType message_handler = CONSOLE;
gchar *prog_name = NULL; /* The path name we are invoked with */
gchar *alternate_gimprc = NULL;
gchar *alternate_system_gimprc = NULL;
gchar **batch_cmds = NULL;
#ifdef ENABLE_NLS
gchar *plugin_domains[] = { "gimp-std-plugins",
@ -88,8 +88,8 @@ gint n_plugin_domains = (sizeof (plugin_domains) /
#endif
/* LOCAL data */
static gint gimp_argc;
static gchar **gimp_argv;
static gint gimp_argc = 0;
static gchar **gimp_argv = NULL;
/*
* argv processing:
@ -113,25 +113,28 @@ static gchar **gimp_argv;
*/
int
main (int argc, char **argv)
main (int argc,
char **argv)
{
int show_version;
int show_help;
int i, j;
gint show_version = FALSE;
gint show_help = FALSE;
gint i, j;
#ifdef HAVE_PUTENV
gchar *display_name, *display_env;
gchar *display_env;
#endif
g_atexit (g_mem_profile);
/* Initialize variables */
prog_name = argv[0];
/* Initialize i18n support */
INIT_LOCALE ("gimp");
#ifdef ENABLE_NLS
bindtextdomain ("gimp-libgimp", LOCALEDIR);
for (i = 0; i < n_plugin_domains; i++)
bindtextdomain (plugin_domains[i], LOCALEDIR);
#endif
@ -141,39 +144,16 @@ main (int argc, char **argv)
setlocale (LC_NUMERIC, "C"); /* gtk seems to zap this during init.. */
#ifdef HAVE_PUTENV
display_name = gdk_get_display ();
display_env = g_new (gchar, strlen (display_name) + 9);
*display_env = 0;
strcat (display_env, "DISPLAY=");
strcat (display_env, display_name);
display_env = g_strconcat ("DISPLAY=", gdk_get_display (), NULL);
putenv (display_env);
#endif
no_interface = FALSE;
no_data = FALSE;
no_splash = FALSE;
no_splash_image = FALSE;
#if defined (HAVE_SHM_H) || defined (G_OS_WIN32)
use_shm = TRUE;
#else
use_shm = FALSE;
#endif
use_debug_handler = FALSE;
restore_session = FALSE;
console_messages = FALSE;
message_handler = CONSOLE;
batch_cmds = g_new (char *, argc);
batch_cmds = g_new (char *, argc);
batch_cmds[0] = NULL;
alternate_gimprc = NULL;
alternate_system_gimprc = NULL;
show_version = FALSE;
show_help = FALSE;
test_gserialize ();
@ -278,9 +258,9 @@ main (int argc, char **argv)
restore_session = TRUE;
argv[i] = NULL;
}
/*
* ANYTHING ELSE starting with a '-' is an error.
*/
/*
* ANYTHING ELSE starting with a '-' is an error.
*/
else if (argv[i][0] == '-')
{
show_help = TRUE;
@ -391,7 +371,7 @@ main (int argc, char **argv)
g_log_set_handler (NULL, G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
on_error, NULL);
/* Keep the command line arguments--for use in gimp_init */
gimp_argc = argc - 1;
gimp_argv = argv + 1;
@ -402,7 +382,7 @@ main (int argc, char **argv)
/* Main application loop */
if (!app_exit_finish_done ())
gtk_main ();
return 0;
}
@ -447,7 +427,7 @@ static int caught_fatal_sig = 0;
#ifndef G_OS_WIN32
static RETSIGTYPE
on_signal (int sig_num)
on_signal (gint sig_num)
{
if (caught_fatal_sig)
kill (getpid (), sig_num);
@ -510,8 +490,8 @@ on_signal (int sig_num)
static RETSIGTYPE
on_sig_child (int sig_num)
{
int pid;
int status;
gint pid;
gint status;
while (1)
{

View File

@ -1,3 +1,23 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* libgimp-intl.h
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*/
#ifndef __GIMPINTL_H__
#define __GIMPINTL_H__

View File

@ -697,3 +697,51 @@ gimp_table_attach_aligned (GtkTable *table,
gtk_widget_show (widget);
}
/* add aligned label & widget to a table */
void
gimp_table_attach_aligned2 (GtkTable *table,
gint row,
gchar *label_text,
gfloat xalign,
gfloat yalign,
GtkWidget *widget,
gint widget_left,
gint widget_right,
gboolean left_adjust)
{
if (label_text)
{
GtkWidget *label;
label = gtk_label_new (label_text);
gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
gtk_table_attach (table, GTK_WIDGET (label),
widget_left - 1, widget_left,
row, row + 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
}
if (left_adjust)
{
GtkWidget *alignment;
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
gtk_table_attach (table, alignment,
widget_left, widget_right,
row, row + 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (alignment);
gtk_container_add (GTK_CONTAINER (alignment), widget);
}
else
{
gtk_table_attach_defaults (table, widget,
widget_left, widget_right,
row, row + 1);
}
gtk_widget_show (widget);
}

View File

@ -156,6 +156,17 @@ void gimp_table_attach_aligned (GtkTable *table,
GtkWidget *widget,
gboolean left_adjust);
/* add aligned label & widget to a table */
void gimp_table_attach_aligned2 (GtkTable *table,
gint row,
gchar *label_text,
gfloat xalign,
gfloat yalign,
GtkWidget *widget,
gint widget_left,
gint widget_right,
gboolean left_adjust);
#ifdef __cplusplus
}
#endif

View File

@ -27,7 +27,7 @@
# undef gettext
# define gettext(String) dgettext ("gimp-libgimp", String)
# ifdef gettext_noop
# define N_(String) dgettext_noop ("gimp-libgimp", String)
# define N_(String) gettext_noop (String)
# else
# define N_(String) (String)
# endif

View File

@ -1,13 +1,32 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* libgimp-intl.h
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*/
#ifndef __STDPLUGINS_INTL_H__
#define __STDPLUGINS_INTL_H__
#include <locale.h>
#include "libgimp/gimpintl.h"
#include "gimpintl.h"
#ifdef HAVE_LC_MESSAGES
#define INIT_I18N() G_STMT_START{ \
setlocale(LC_MESSAGES, ""); \
bindtextdomain("gimp-libgimp", LOCALEDIR); \
bindtextdomain("gimp-std-plugins", LOCALEDIR); \
textdomain("gimp-std-plugins"); \
}G_STMT_END

View File

@ -697,3 +697,51 @@ gimp_table_attach_aligned (GtkTable *table,
gtk_widget_show (widget);
}
/* add aligned label & widget to a table */
void
gimp_table_attach_aligned2 (GtkTable *table,
gint row,
gchar *label_text,
gfloat xalign,
gfloat yalign,
GtkWidget *widget,
gint widget_left,
gint widget_right,
gboolean left_adjust)
{
if (label_text)
{
GtkWidget *label;
label = gtk_label_new (label_text);
gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
gtk_table_attach (table, GTK_WIDGET (label),
widget_left - 1, widget_left,
row, row + 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
}
if (left_adjust)
{
GtkWidget *alignment;
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
gtk_table_attach (table, alignment,
widget_left, widget_right,
row, row + 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (alignment);
gtk_container_add (GTK_CONTAINER (alignment), widget);
}
else
{
gtk_table_attach_defaults (table, widget,
widget_left, widget_right,
row, row + 1);
}
gtk_widget_show (widget);
}

View File

@ -156,6 +156,17 @@ void gimp_table_attach_aligned (GtkTable *table,
GtkWidget *widget,
gboolean left_adjust);
/* add aligned label & widget to a table */
void gimp_table_attach_aligned2 (GtkTable *table,
gint row,
gchar *label_text,
gfloat xalign,
gfloat yalign,
GtkWidget *widget,
gint widget_left,
gint widget_right,
gboolean left_adjust);
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -33,63 +33,41 @@
#include "libgimp/stdplugins-intl.h"
#define PLUG_IN_NAME "plug_in_align_layers"
#define SHORT_NAME "align_layers"
#define PROGRESS_NAME "align_layers"
#define MAIN_FUNCTION main_function
#define INTERFACE align_layers_interface
#define DIALOG align_layers_dialog
#define VALS align_layers_vals
#define OK_CALLBACK align_layers_ok_callback
#define PREVIEW_UPDATE _preview_update
#define PROGRESS_UPDATE_NUM 100
#define PLUG_IN_NAME "plug_in_align_layers"
#define SHORT_NAME "align_layers"
#define SCALE_WIDTH 150
/* gtkWrapper functions */
#define GTKW_ENTRY_WIDTH 40
#define GTKW_SCALE_WIDTH 100
#define GTKW_PREVIEW_WIDTH 50
#define GTKW_PREVIEW_HEIGHT 256
#define GTKW_BORDER_WIDTH 5
#define GTKW_FLOAT_MIN_ERROR 0.000001
static gint **gtkW_gint_wrapper_new (gint index, gint *pointer);
static void gtkW_toggle_update (GtkWidget *widget, gpointer data);
static void gtkW_table_add_toggle (GtkWidget *table,
gchar *name,
gint x,
gint y,
GtkSignalFunc update,
gint *value);
GtkWidget *gtkW_table_add_button (GtkWidget *table,
gchar *name,
gint x0,
gint x1,
gint y,
GtkSignalFunc callback,
gpointer value);
typedef struct
enum
{
gchar *name;
gpointer data;
} gtkW_menu_item;
GtkWidget *gtkW_table_add_menu (GtkWidget *parent,
gchar *name,
int x,
int y,
GtkSignalFunc imenu_update,
int *val,
gtkW_menu_item *item,
int item_num);
static void gtkW_menu_update (GtkWidget *widget, gpointer data);
GtkWidget *gtkW_check_button_new (GtkWidget *parent,
gchar *name,
GtkSignalFunc update,
gint *value);
GtkWidget *gtkW_frame_new (GtkWidget *parent, gchar *name);
GtkWidget *gtkW_table_new (GtkWidget *parent, gint col, gint row);
GtkWidget *gtkW_hbox_new (GtkWidget *parent);
GtkWidget *gtkW_vbox_new (GtkWidget *parent);
/* end of GtkW */
H_NONE,
H_COLLECT,
LEFT2RIGHT,
RIGHT2LEFT,
SNAP2HGRID
};
enum
{
H_BASE_LEFT,
H_BASE_CENTER,
H_BASE_RIGHT
};
enum
{
V_NONE,
V_COLLECT,
TOP2BOTTOM,
BOTTOM2TOP,
SNAP2VGRID
};
enum
{
V_BASE_TOP,
V_BASE_CENTER,
V_BASE_BOTTOM
};
static void query (void);
static void run (gchar *name,
@ -98,12 +76,14 @@ static void run (gchar *name,
gint *nreturn_vals,
GParam **return_vals);
static GStatusType align_layers (gint32 image_id);
static void align_layers_get_align_offsets (gint32 drawable_id,
gint *x,
gint *y);
static gint DIALOG (void);
static void OK_CALLBACK (GtkWidget *widget, gpointer data);
static GStatusType align_layers (gint32 image_id);
static void align_layers_get_align_offsets (gint32 drawable_id,
gint *x,
gint *y);
static gint align_layers_dialog (void);
static void align_layers_ok_callback (GtkWidget *widget,
gpointer data);
GPlugInInfo PLUG_IN_INFO =
{
@ -113,55 +93,8 @@ GPlugInInfo PLUG_IN_INFO =
run, /* run_proc */
};
/* dialog variables */
gtkW_menu_item h_style_menu [] =
{
#define H_NONE 0
{ N_("None"), NULL },
#define H_COLLECT 1
{ N_("Collect"), NULL },
#define LEFT2RIGHT 2
{ N_("Fill (left to right)"), NULL },
#define RIGHT2LEFT 3
{ N_("Fill (right to left)"), NULL },
#define SNAP2HGRID 4
{ N_("Snap to grid"), NULL }
};
gtkW_menu_item h_base_menu [] =
{
#define H_BASE_LEFT 0
{ N_("Left edge"), NULL },
#define H_BASE_CENTER 1
{ N_("Center"), NULL },
#define H_BASE_RIGHT 2
{ N_("Right edge"), NULL }
};
gtkW_menu_item v_style_menu [] =
{
#define V_NONE 0
{ N_("None"), NULL },
#define V_COLLECT 1
{ N_("Collect"), NULL },
#define TOP2BOTTOM 2
{ N_("Fill (top to bottom)"), NULL },
#define BOTTOM2TOP 3
{ N_("Fill (bottom to top)"), NULL },
#define SNAP2VGRID 4
{ N_("Snap to grid"), NULL }
};
gtkW_menu_item v_base_menu [] =
{
#define V_BASE_TOP 0
{ N_("Top edge"), NULL },
#define V_BASE_CENTER 1
{ N_("Center"), NULL },
#define V_BASE_BOTTOM 2
{ N_("Bottom edge"), NULL }
};
typedef struct
{
gint h_style;
@ -175,7 +108,13 @@ typedef struct
static ValueType VALS =
{
H_NONE, H_BASE_LEFT, V_NONE, V_BASE_TOP, 1, 0, 10
H_NONE,
H_BASE_LEFT,
V_NONE,
V_BASE_TOP,
TRUE,
FALSE,
10
};
typedef struct
@ -183,9 +122,11 @@ typedef struct
gint run;
} Interface;
static Interface INTERFACE = { FALSE };
static Interface INTERFACE =
{
FALSE
};
/* gint link_after_alignment = 0;*/
MAIN ()
@ -249,7 +190,7 @@ run (gchar *name,
return;
}
gimp_get_data (PLUG_IN_NAME, &VALS);
if (! DIALOG ())
if (! align_layers_dialog ())
return;
break;
case RUN_NONINTERACTIVE:
@ -260,12 +201,12 @@ run (gchar *name,
gimp_get_data (PLUG_IN_NAME, &VALS);
break;
}
status = align_layers (image_id);
if (run_mode != RUN_NONINTERACTIVE)
gimp_displays_flush();
if (run_mode == RUN_INTERACTIVE && status == STATUS_SUCCESS )
gimp_displays_flush ();
if (run_mode == RUN_INTERACTIVE && status == STATUS_SUCCESS)
gimp_set_data (PLUG_IN_NAME, &VALS, sizeof (ValueType));
values[0].type = PARAM_STATUS;
@ -453,15 +394,16 @@ align_layers_get_align_offsets (gint32 drawable_id,
/* dialog stuff */
static int
DIALOG (void)
align_layers_dialog (void)
{
GtkWidget *dlg;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *optionmenu;
GtkWidget *toggle;
GtkObject *adj;
gchar **argv;
gint argc;
gint index = 0;
argc = 1;
argv = g_new (gchar *, 1);
@ -475,7 +417,7 @@ DIALOG (void)
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
_("OK"), OK_CALLBACK,
_("OK"), align_layers_ok_callback,
NULL, NULL, NULL, TRUE, FALSE,
_("Cancel"), gtk_widget_destroy,
NULL, 1, NULL, FALSE, TRUE,
@ -485,42 +427,108 @@ DIALOG (void)
gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit),
NULL);
frame = gtkW_frame_new (GTK_DIALOG (dlg)->vbox, _("Parameter Settings"));
table = gtkW_table_new (frame, 7, 3);
gtkW_table_add_menu (table, _("Horizontal Style:"), 0, index++,
(GtkSignalFunc) gtkW_menu_update,
&VALS.h_style,
h_style_menu,
sizeof (h_style_menu) / sizeof (h_style_menu[0]));
gtkW_table_add_menu (table, _("Horizontal Base:"), 0, index++,
(GtkSignalFunc) gtkW_menu_update,
&VALS.h_base,
h_base_menu,
sizeof (h_base_menu) / sizeof (h_base_menu[0]));
gtkW_table_add_menu (table, _("Vertical Style:"), 0, index++,
(GtkSignalFunc) gtkW_menu_update,
&VALS.v_style,
v_style_menu,
sizeof (v_style_menu) / sizeof (v_style_menu[0]));
gtkW_table_add_menu (table, _("Vertical Base:"), 0, index++,
(GtkSignalFunc) gtkW_menu_update,
&VALS.v_base,
v_base_menu,
sizeof (v_base_menu) / sizeof (v_base_menu[0]));
gtkW_table_add_toggle (table, _("Ignore the Bottom Layer even if Visible"),
0, index++,
(GtkSignalFunc) gtkW_toggle_update,
&VALS.ignore_bottom);
gtkW_table_add_toggle (table,
_("Use the (Invisible) Bottom Layer as the Base"),
0, index++,
(GtkSignalFunc) gtkW_toggle_update,
&VALS.base_is_bottom_layer);
frame = gtk_frame_new (_("Parameter Settings"));
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, index++,
_("Grid Size:"), GTKW_SCALE_WIDTH, 0,
table = gtk_table_new (7, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
optionmenu =
gimp_option_menu_new2 (FALSE, gimp_menu_item_update,
&VALS.h_style, (gpointer) VALS.h_style,
_("None"),
(gpointer) H_NONE, NULL,
_("Collect"),
(gpointer) H_COLLECT, NULL,
_("Fill (left to right)"),
(gpointer) LEFT2RIGHT, NULL,
_("Fill (right to left)"),
(gpointer) RIGHT2LEFT, NULL,
_("Snap to Grid"),
(gpointer) SNAP2HGRID, NULL,
NULL);
gimp_table_attach_aligned (GTK_TABLE (table), 0,
_("Horizontal Style:"), 1.0, 0.5,
optionmenu, FALSE);
optionmenu =
gimp_option_menu_new2 (FALSE, gimp_menu_item_update,
&VALS.h_base, (gpointer) VALS.h_base,
_("Left Edge"), (gpointer) H_BASE_LEFT, NULL,
_("Center"), (gpointer) H_BASE_CENTER, NULL,
_("Right Edge"), (gpointer) H_BASE_RIGHT, NULL,
NULL);
gimp_table_attach_aligned (GTK_TABLE (table), 1,
_("Horizontal Base:"), 1.0, 0.5,
optionmenu, FALSE);
optionmenu =
gimp_option_menu_new2 (FALSE, gimp_menu_item_update,
&VALS.v_style, (gpointer) VALS.v_style,
_("None"),
(gpointer) V_NONE, NULL,
_("Collect"),
(gpointer) V_COLLECT, NULL,
_("Fill (top to bottom)"),
(gpointer) TOP2BOTTOM, NULL,
_("Fill (bottom to top)"),
(gpointer) BOTTOM2TOP, NULL,
_("Snap to Grid"),
(gpointer) SNAP2VGRID, NULL,
NULL);
gimp_table_attach_aligned (GTK_TABLE (table), 2,
_("Vertical Style:"), 1.0, 0.5,
optionmenu, FALSE);
optionmenu =
gimp_option_menu_new2 (FALSE, gimp_menu_item_update,
&VALS.v_base, (gpointer) VALS.v_base,
_("Top Edge"), (gpointer) V_BASE_TOP, NULL,
_("Center"), (gpointer) V_BASE_CENTER, NULL,
_("Bottom Edge"), (gpointer) V_BASE_BOTTOM, NULL,
NULL);
gimp_table_attach_aligned (GTK_TABLE (table), 3,
_("Horizontal Base:"), 1.0, 0.5,
optionmenu, FALSE);
toggle =
gtk_check_button_new_with_label
(_("Ignore the Bottom Layer even if Visible"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), VALS.ignore_bottom);
gtk_table_attach_defaults (GTK_TABLE (table), toggle, 0, 2, 4, 5);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
&VALS.ignore_bottom);
gtk_widget_show (toggle);
toggle =
gtk_check_button_new_with_label
(_("Use the (Invisible) Bottom Layer as the Base"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
VALS.base_is_bottom_layer);
gtk_table_attach_defaults (GTK_TABLE (table), toggle, 0, 2, 5, 6);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
&VALS.base_is_bottom_layer);
gtk_widget_show (toggle);
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 6,
_("Grid Size:"), SCALE_WIDTH, 0,
VALS.grid_size, 0, 200, 1, 10, 0,
NULL, NULL);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
@ -538,247 +546,10 @@ DIALOG (void)
}
static void
OK_CALLBACK (GtkWidget *widget,
gpointer data)
align_layers_ok_callback (GtkWidget *widget,
gpointer data)
{
#ifdef OLD
int index;
for (index = H_NONE; index <= SNAP2HGRID; index++)
if (d_var[index])
{
VALS.h_style = index;
break;
}
for (index = H_BASE_LEFT; index <= H_BASE_RIGHT; index++)
if (d_var[index])
{
VALS.h_base = index;
break;
}
for (index = V_NONE; index <= SNAP2VGRID; index++)
if (d_var[index])
{
VALS.v_style = index;
break;
}
for (index = V_BASE_TOP; index <= V_BASE_BOTTOM; index++)
if (d_var[index])
{
VALS.v_base = index;
break;
}
#endif
INTERFACE.run = TRUE;
gtk_widget_destroy (GTK_WIDGET (data));
}
static void
PREVIEW_UPDATE ()
{
}
/* gtkW functions: gtkW is the abbreviation of gtk Wrapper */
static gint **
gtkW_gint_wrapper_new (gint index, gint *pointer)
{
gint **tmp;
tmp = (gint **)malloc(3 * sizeof (gint *));
tmp[0] = (gint *) ((*pointer == index) ? TRUE : FALSE);
tmp[1] = pointer;
tmp[2] = (gint *) index;
return tmp;
}
static void
gtkW_toggle_update (GtkWidget *widget,
gpointer data)
{
int *toggle_val;
toggle_val = (int *) data;
if (GTK_TOGGLE_BUTTON (widget)->active)
*toggle_val = TRUE;
else
*toggle_val = FALSE;
PREVIEW_UPDATE ();
}
GtkWidget *
gtkW_table_new (GtkWidget *parent, gint col, gint row)
{
GtkWidget *table;
table = gtk_table_new (col,row, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_container_add (GTK_CONTAINER (parent), table);
gtk_widget_show (table);
return table;
}
GtkWidget *
gtkW_hbox_new (GtkWidget *parent)
{
GtkWidget *hbox;
hbox = gtk_hbox_new (FALSE, 2);
gtk_container_border_width (GTK_CONTAINER (hbox), GTKW_BORDER_WIDTH);
/* gtk_box_pack_start (GTK_BOX (parent), hbox, FALSE, TRUE, 0); */
gtk_container_add (GTK_CONTAINER (parent), hbox);
gtk_widget_show (hbox);
return hbox;
}
GtkWidget *
gtkW_vbox_new (GtkWidget *parent)
{
GtkWidget *vbox;
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_border_width (GTK_CONTAINER (vbox), GTKW_BORDER_WIDTH);
/* gtk_box_pack_start (GTK_BOX (parent), vbox, TRUE, TRUE, 0); */
gtk_container_add (GTK_CONTAINER (parent), vbox);
gtk_widget_show (vbox);
return vbox;
}
GtkWidget *
gtkW_check_button_new (GtkWidget *parent,
gchar *name,
GtkSignalFunc update,
gint *value)
{
GtkWidget *toggle;
toggle = gtk_check_button_new_with_label (name);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) update,
value);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), *value);
gtk_container_add (GTK_CONTAINER (parent), toggle);
gtk_widget_show (toggle);
return toggle;
}
GtkWidget *
gtkW_frame_new (GtkWidget *parent,
gchar *name)
{
GtkWidget *frame;
frame = gtk_frame_new (name);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
if (parent != NULL)
gtk_box_pack_start (GTK_BOX (parent), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
return frame;
}
static void
gtkW_table_add_toggle (GtkWidget *table,
gchar *name,
gint x,
gint y,
GtkSignalFunc update,
gint *value)
{
GtkWidget *toggle;
toggle = gtk_check_button_new_with_label(name);
gtk_table_attach (GTK_TABLE (table), toggle, x, x + 2, y, y+1,
GTK_FILL|GTK_EXPAND, 0 & GTK_FILL, 0, 0);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) update,
value);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), *value);
gtk_widget_show (toggle);
}
GtkWidget *
gtkW_table_add_button (GtkWidget *table,
gchar *name,
gint x0,
gint x1,
gint y,
GtkSignalFunc callback,
gpointer value)
{
GtkWidget *button;
button = gtk_button_new_with_label (name);
gtk_table_attach (GTK_TABLE(table), button, x0, x1, y, y+1,
GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) callback, value);
gtk_widget_show(button);
return button;
}
GtkWidget *
gtkW_table_add_menu (GtkWidget *table,
gchar *name,
int x,
int y,
GtkSignalFunc menu_update,
int *val,
gtkW_menu_item *item,
int item_num)
{
GtkWidget *label;
GtkWidget *menu, *menuitem, *option_menu;
gchar buf[64];
gint i;
label = gtk_label_new (name);
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, x, x + 1, y, y + 1,
GTK_FILL|GTK_EXPAND, 0 & GTK_FILL, 0, 0);
gtk_widget_show (label);
menu = gtk_menu_new ();
for (i = 0; i < item_num; i++)
{
sprintf (buf, gettext(item[i].name));
menuitem = gtk_menu_item_new_with_label (buf);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
(GtkSignalFunc) menu_update,
gtkW_gint_wrapper_new (i, val));
gtk_widget_show (menuitem);
}
option_menu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), *val);
gtk_table_attach (GTK_TABLE (table), option_menu, x + 1, x + 2, y, y + 1,
GTK_FILL|GTK_EXPAND, 0, 0, 0);
gtk_widget_show (option_menu);
return option_menu;
}
static void
gtkW_menu_update (GtkWidget *widget,
gpointer data)
{
gint **buffer = (gint **) data;
if (*buffer[1] != (gint) buffer[2])
{
*buffer[1] = (gint) buffer[2];
PREVIEW_UPDATE ();
}
}
/* end of gtkW functions */
/* end of align_layers.c */

View File

@ -24,8 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h> /* for seed of random number */
#include <time.h>
#include <gtk/gtk.h>
@ -36,11 +35,6 @@
#define PLUG_IN_NAME "plug_in_scatter_hsv"
#define SHORT_NAME "scatter_hsv"
#define MAIN_FUNCTION scatter_hsv
#define INTERFACE scatter_hsv_interface
#define DIALOG scatter_hsv_dialog
#define VALS scatter_hsv_vals
#define OK_CALLBACK scatter_hsv_ok_callback
static void query (void);
static void run (gchar *name,
@ -49,29 +43,32 @@ static void run (gchar *name,
gint *nreturn_vals,
GParam **return_vals);
static GStatusType MAIN_FUNCTION (gint32 drawable_id);
void scatter_hsv_scatter (guchar *r, guchar *g, guchar *b);
static int randomize_value (int now,
int min,
int max,
int mod_p,
int rand_max);
static GStatusType scatter_hsv (gint32 drawable_id);
static void scatter_hsv_scatter (guchar *r,
guchar *g,
guchar *b);
static gint randomize_value (gint now,
gint min,
gint max,
gint mod_p,
gint rand_max);
static gint DIALOG (void);
static void OK_CALLBACK (GtkWidget *widget,
static gint scatter_hsv_dialog (void);
static void scatter_hsv_ok_callback (GtkWidget *widget,
gpointer data);
static gint preview_event_handler (GtkWidget *widget,
GdkEvent *event);
static void scatter_hsv_preview_update (void);
static void scatter_hsv_iscale_update (GtkAdjustment *adjustment,
gpointer data);
/* gtkWrapper functions */
#define PROGRESS_UPDATE_NUM 100
#define PREVIEW_WIDTH 128
gint preview_width = PREVIEW_WIDTH;
#define PREVIEW_HEIGHT 128
gint preview_height = PREVIEW_HEIGHT;
#define SCALE_WIDTH 100
#define PROGRESS_UPDATE_NUM 100
#define PREVIEW_WIDTH 128
#define PREVIEW_HEIGHT 128
#define SCALE_WIDTH 100
static gint preview_width = PREVIEW_WIDTH;
static gint preview_height = PREVIEW_HEIGHT;
GPlugInInfo PLUG_IN_INFO =
{
@ -91,7 +88,10 @@ typedef struct
static ValueType VALS =
{
2, 3, 10, 10
2,
3,
10,
10
};
typedef struct
@ -99,20 +99,22 @@ typedef struct
gint run;
} Interface;
static Interface INTERFACE = { FALSE };
gint drawable_id;
static Interface INTERFACE =
{
FALSE
};
GtkWidget *preview;
gint preview_start_x = 0;
gint preview_end_x = 0;
gint preview_start_y = 0;
gint preview_end_y = 0;
guchar *preview_buffer = NULL;
gint preview_offset_x = 0;
gint preview_offset_y = 0;
gint preview_dragging = FALSE;
gint preview_drag_start_x = 0;
gint preview_drag_start_y = 0;
static gint drawable_id;
static GtkWidget *preview;
static gint preview_start_x = 0;
static gint preview_start_y = 0;
static guchar *preview_buffer = NULL;
static gint preview_offset_x = 0;
static gint preview_offset_y = 0;
static gint preview_dragging = FALSE;
static gint preview_drag_start_x = 0;
static gint preview_drag_start_y = 0;
MAIN ()
@ -129,9 +131,7 @@ query (void)
{ PARAM_INT32, "saturation_distance", "distribution distance on saturation axis [0,255]"},
{ PARAM_INT32, "value_distance", "distribution distance on value axis [0,255]"}
};
static GParamDef *return_vals = NULL;
static int nargs = sizeof (args) / sizeof (args[0]);
static int nreturn_vals = 0;
static gint nargs = sizeof (args) / sizeof (args[0]);
INIT_I18N();
@ -141,11 +141,11 @@ query (void)
"Shuji Narazaki (narazaki@InetQ.or.jp)",
"Shuji Narazaki",
"1997",
N_("<Image>/Filters/Noise/Scatter HSV..."),
N_("<Image>/Filters/Noise/Scatter HSV..."),
"RGB*",
PROC_PLUG_IN,
nargs, nreturn_vals,
args, return_vals);
nargs, 0,
args, NULL);
}
static void
@ -155,9 +155,9 @@ run (gchar *name,
gint *nreturn_vals,
GParam **return_vals)
{
static GParam values[1];
GStatusType status = STATUS_EXECUTION_ERROR;
GRunModeType run_mode;
static GParam values[1];
GStatusType status = STATUS_EXECUTION_ERROR;
GRunModeType run_mode;
run_mode = param[0].data.d_int32;
drawable_id = param[2].data.d_int32;
@ -178,7 +178,7 @@ run (gchar *name,
g_message ("Scatter HSV: RGB drawable is not selected.");
return;
}
if (! DIALOG ())
if (! scatter_hsv_dialog ())
return;
break;
case RUN_NONINTERACTIVE:
@ -194,7 +194,7 @@ run (gchar *name,
break;
}
status = MAIN_FUNCTION (drawable_id);
status = scatter_hsv (drawable_id);
if (run_mode != RUN_NONINTERACTIVE)
gimp_displays_flush();
@ -206,14 +206,14 @@ run (gchar *name,
}
static GStatusType
MAIN_FUNCTION (gint32 drawable_id)
scatter_hsv (gint32 drawable_id)
{
GDrawable *drawable;
GPixelRgn src_rgn, dest_rgn;
guchar *src, *dest;
gpointer pr;
gint x, y, x1, x2, y1, y2;
gint gap, total, processed = 0;
GDrawable *drawable;
GPixelRgn src_rgn, dest_rgn;
guchar *src, *dest;
gpointer pr;
gint x, y, x1, x2, y1, y2;
gint gap, total, processed = 0;
drawable = gimp_drawable_get (drawable_id);
gap = (gimp_drawable_has_alpha (drawable_id)) ? 1 : 0;
@ -221,10 +221,12 @@ MAIN_FUNCTION (gint32 drawable_id)
total = (x2 - x1) * (y2 - y1);
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
gimp_progress_init ( _("scatter_hsv: scattering..."));
gimp_progress_init (_("Scatter HSV: Scattering..."));
srand (time (NULL));
pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
@ -260,32 +262,35 @@ MAIN_FUNCTION (gint32 drawable_id)
}
/* the function */
if ((++processed % (total / PROGRESS_UPDATE_NUM)) == 0)
gimp_progress_update ((double)processed /(double) total);
gimp_progress_update ((double) processed /(double) total);
}
}
}
gimp_progress_update (1.0);
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->id, TRUE);
gimp_drawable_update (drawable->id, x1, y1, (x2 - x1), (y2 - y1));
gimp_drawable_detach (drawable);
return STATUS_SUCCESS;
}
static int randomize_value (int now,
int min,
int max,
int mod_p,
int rand_max)
static gint
randomize_value (gint now,
gint min,
gint max,
gint mod_p,
gint rand_max)
{
int flag, new, steps, index;
double rand_val;
gint flag, new, steps, index;
gdouble rand_val;
steps = max - min + 1;
rand_val = ((double) rand() / (double) G_MAXRAND);
rand_val = ((double) rand () / (double) G_MAXRAND);
for (index = 1; index < VALS.holdness; index++)
{
double tmp = ((double) rand()/(double)G_MAXRAND);
double tmp = ((double) rand () / (double) G_MAXRAND);
if (tmp < rand_val)
rand_val = tmp;
}
@ -314,9 +319,9 @@ void scatter_hsv_scatter (guchar *r,
guchar *g,
guchar *b)
{
int h, s, v;
int h1, s1, v1;
int h2, s2, v2;
gint h, s, v;
gint h1, s1, v1;
gint h2, s2, v2;
h = *r; s = *g; v = *b;
@ -348,8 +353,8 @@ void scatter_hsv_scatter (guchar *r,
}
/* dialog stuff */
static int
DIALOG (void)
static gint
scatter_hsv_dialog (void)
{
GtkWidget *dlg;
GtkWidget *vbox;
@ -364,7 +369,7 @@ DIALOG (void)
argc = 1;
argv = g_new (gchar *, 1);
argv[0] = g_strdup (PLUG_IN_NAME);
argv[0] = g_strdup (SHORT_NAME);
gtk_init (&argc, &argv);
gtk_rc_parse (gimp_gtkrc ());
@ -379,12 +384,12 @@ DIALOG (void)
gtk_widget_set_default_visual (gtk_preview_get_visual ());
gtk_widget_set_default_colormap (gtk_preview_get_cmap ());
dlg = gimp_dialog_new (_("Scatter HSV"), "scatter_hsv",
dlg = gimp_dialog_new (_("Scatter HSV"), SHORT_NAME,
gimp_plugin_help_func, "filters/scatter_hsv.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
_("OK"), OK_CALLBACK,
_("OK"), scatter_hsv_ok_callback,
NULL, NULL, NULL, TRUE, FALSE,
_("Cancel"), gtk_widget_destroy,
NULL, 1, NULL, FALSE, TRUE,
@ -416,10 +421,10 @@ DIALOG (void)
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
{
gint width = gimp_drawable_width (drawable_id);
gint width = gimp_drawable_width (drawable_id);
gint height = gimp_drawable_height (drawable_id);
preview_width = (PREVIEW_WIDTH < width) ? PREVIEW_WIDTH : width;
preview_width = (PREVIEW_WIDTH < width) ? PREVIEW_WIDTH : width;
preview_height = (PREVIEW_HEIGHT < height) ? PREVIEW_HEIGHT : height;
}
gtk_preview_size (GTK_PREVIEW (preview), preview_width * 2, preview_height);
@ -644,10 +649,11 @@ scatter_hsv_preview_update (void)
}
static void
OK_CALLBACK (GtkWidget *widget,
gpointer data)
scatter_hsv_ok_callback (GtkWidget *widget,
gpointer data)
{
INTERFACE.run = TRUE;
gtk_widget_destroy (GTK_WIDGET (data));
}

View File

@ -34,60 +34,23 @@
#include "libgimp/stdplugins-intl.h"
/* Replace them with the right ones */
#define PLUG_IN_NAME "plug_in_threshold_alpha"
#define SHORT_NAME "threshold_alpha"
#define MAIN_FUNCTION threshold_alpha
/* you need not change the following names */
#define INTERFACE threshold_alpha_interface
#define DIALOG threshold_alpha_dialog
#define ERROR_DIALOG threshold_alpha_error_dialog
#define VALS threshold_alpha_vals
#define OK_CALLBACK threshold_alpha_ok_callback
#define PLUG_IN_NAME "plug_in_threshold_alpha"
#define SHORT_NAME "threshold_alpha"
#define PROGRESS_UPDATE_NUM 100
#define SCALE_WIDTH 120
static void query (void);
static void run (char *name,
int nparams,
GParam *param,
int *nreturn_vals,
GParam **return_vals);
static GStatusType MAIN_FUNCTION ();
static gint DIALOG ();
static void ERROR_DIALOG (gint gtk_was_not_initialized, gchar *message);
static void OK_CALLBACK (GtkWidget *widget, gpointer data);
static void query (void);
static void run (gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals);
/* gtkWrapper functions */
#define PROGRESS_UPDATE_NUM 100
#define ENTRY_WIDTH 100
#define SCALE_WIDTH 120
static GStatusType threshold_alpha (gint32 drawable_id);
static void
gtkW_iscale_update (GtkAdjustment *adjustment,
gpointer data);
static void
gtkW_ientry_update (GtkWidget *widget,
gpointer data);
static void
gtkW_table_add_iscale_entry (GtkWidget *table,
gchar *name,
gint x,
gint y,
GtkSignalFunc scale_update,
GtkSignalFunc entry_update,
gint *value,
gdouble min,
gdouble max,
gdouble step,
gchar *buffer);
GtkWidget *gtkW_check_button_new (GtkWidget *parent,
gchar *name,
GtkSignalFunc update,
gint *value);
GtkWidget *gtkW_frame_new (GtkWidget *parent, gchar *name);
GtkWidget *gtkW_table_new (GtkWidget *parent, gint col, gint row);
GtkWidget *gtkW_hbox_new (GtkWidget *parent);
GtkWidget *gtkW_vbox_new (GtkWidget *parent);
static gint threshold_alpha_dialog (void);
static void threshold_alpha_ok_callback (GtkWidget *widget,
gpointer data);
GPlugInInfo PLUG_IN_INFO =
{
@ -112,7 +75,10 @@ typedef struct
gint run;
} Interface;
static Interface INTERFACE = { FALSE };
static Interface INTERFACE =
{
FALSE
};
MAIN ()
@ -142,16 +108,16 @@ query (void)
}
static void
run (char *name,
int nparams,
GParam *param,
int *nreturn_vals,
GParam **return_vals)
run (gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals)
{
static GParam values[1];
GStatusType status = STATUS_SUCCESS;
GRunModeType run_mode;
gint drawable_id;
static GParam values[1];
GStatusType status = STATUS_SUCCESS;
GRunModeType run_mode;
gint drawable_id;
run_mode = param[0].data.d_int32;
drawable_id = param[2].data.d_int32;
@ -177,17 +143,17 @@ run (char *name,
/* Since a channel might be selected, we must check wheter RGB or not. */
if (gimp_layer_get_preserve_transparency (drawable_id))
{
ERROR_DIALOG (1, _("The layer preserves transparency."));
g_message (_("The layer preserves transparency."));
return;
}
if (!gimp_drawable_is_rgb (drawable_id) &&
!gimp_drawable_is_gray (drawable_id))
{
ERROR_DIALOG (1, _("RGBA/GRAYA drawable is not selected."));
g_message (_("RGBA/GRAYA drawable is not selected."));
return;
}
gimp_get_data (PLUG_IN_NAME, &VALS);
if (! DIALOG ())
if (! threshold_alpha_dialog ())
return;
break;
case RUN_NONINTERACTIVE:
@ -204,7 +170,7 @@ run (char *name,
}
if (status == STATUS_SUCCESS)
status = MAIN_FUNCTION (drawable_id);
status = threshold_alpha (drawable_id);
if (run_mode != RUN_NONINTERACTIVE)
gimp_displays_flush();
@ -216,19 +182,20 @@ run (char *name,
}
static GStatusType
MAIN_FUNCTION (gint32 drawable_id)
threshold_alpha (gint32 drawable_id)
{
GDrawable *drawable;
GPixelRgn src_rgn, dest_rgn;
guchar *src, *dest;
gpointer pr;
gint x, y, x1, x2, y1, y2;
gint gap, total, processed = 0;
GDrawable *drawable;
GPixelRgn src_rgn, dest_rgn;
guchar *src, *dest;
gpointer pr;
gint x, y, x1, x2, y1, y2;
gint gap, total, processed = 0;
drawable = gimp_drawable_get (drawable_id);
if (! gimp_drawable_has_alpha (drawable_id)) return STATUS_EXECUTION_ERROR;
if (! gimp_drawable_has_alpha (drawable_id))
return STATUS_EXECUTION_ERROR;
if (gimp_drawable_is_rgb(drawable_id))
if (gimp_drawable_is_rgb (drawable_id))
gap = 3;
else
gap = 1;
@ -237,15 +204,17 @@ MAIN_FUNCTION (gint32 drawable_id)
total = (x2 - x1) * (y2 - y1);
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
gimp_progress_init (_("threshold_alpha (0.13):coloring transparency..."));
gimp_progress_init (_("Threshold Alpha: Coloring Transparency..."));
for (; pr != NULL; pr = gimp_pixel_rgns_process (pr))
{
int offset, index;
gint offset, index;
for (y = 0; y < src_rgn.h; y++)
{
src = src_rgn.data + y * src_rgn.rowstride;
@ -259,25 +228,28 @@ MAIN_FUNCTION (gint32 drawable_id)
*dest++ = (VALS.threshold < *src++) ? 255 : 0;
if ((++processed % (total / PROGRESS_UPDATE_NUM)) == 0)
gimp_progress_update ((double)processed /(double) total);
gimp_progress_update ((double) processed /(double) total);
}
}
}
gimp_progress_update (1.0);
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->id, TRUE);
gimp_drawable_update (drawable->id, x1, y1, (x2 - x1), (y2 - y1));
gimp_drawable_detach (drawable);
return STATUS_SUCCESS;
}
/* dialog stuff */
static int
DIALOG ()
threshold_alpha_dialog (void)
{
GtkWidget *dlg;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *dlg;
GtkWidget *frame;
GtkWidget *table;
GtkObject *adj;
gchar **argv;
gint argc;
@ -293,7 +265,7 @@ DIALOG ()
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
_("OK"), OK_CALLBACK,
_("OK"), threshold_alpha_ok_callback,
NULL, NULL, NULL, TRUE, FALSE,
_("Cancel"), gtk_widget_destroy,
NULL, 1, NULL, FALSE, TRUE,
@ -304,15 +276,27 @@ DIALOG ()
GTK_SIGNAL_FUNC (gtk_main_quit),
NULL);
frame = gtkW_frame_new (GTK_DIALOG (dlg)->vbox, _("Parameter Settings"));
table = gtkW_table_new (frame, 1, 2);
gtkW_table_add_iscale_entry (table, _("Threshold:"), 0, 0,
(GtkSignalFunc) gtkW_iscale_update,
(GtkSignalFunc) gtkW_ientry_update,
&VALS.threshold,
0, 255, 1, malloc (10));
frame = gtk_frame_new (_("Parameter Settings"));
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
table = gtk_table_new (1 ,3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
_("Threshold:"), SCALE_WIDTH, 0,
VALS.threshold, 0, 255, 1, 8, 0,
NULL, NULL);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&VALS.threshold);
gtk_widget_show (dlg);
gtk_main ();
gdk_flush ();
@ -320,219 +304,10 @@ DIALOG ()
}
static void
ERROR_DIALOG (gint gtk_was_not_initialized, gchar *message)
{
GtkWidget *dlg;
GtkWidget *table;
GtkWidget *label;
gchar **argv;
gint argc;
if (gtk_was_not_initialized)
{
argc = 1;
argv = g_new (gchar *, 1);
argv[0] = g_strdup (PLUG_IN_NAME);
gtk_init (&argc, &argv);
gtk_rc_parse (gimp_gtkrc ());
}
dlg = gimp_dialog_new (_("Threshold Alpha"), "threshold_alpha",
gimp_plugin_help_func, "filters/threshold_alpha.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
_("OK"), gtk_main_quit,
NULL, NULL, NULL, TRUE, TRUE,
NULL);
table = gtk_table_new (1,1, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (table), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), table, TRUE, TRUE, 0);
label = gtk_label_new (message);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL|GTK_EXPAND,
0, 0, 0);
gtk_widget_show (table);
gtk_widget_show (label);
gtk_widget_show (dlg);
gtk_main ();
gdk_flush ();
}
static void
OK_CALLBACK (GtkWidget *widget,
gpointer data)
threshold_alpha_ok_callback (GtkWidget *widget,
gpointer data)
{
INTERFACE.run = TRUE;
gtk_widget_destroy (GTK_WIDGET (data));
}
GtkWidget *
gtkW_table_new (GtkWidget *parent, gint col, gint row)
{
GtkWidget *table;
table = gtk_table_new (col,row, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_container_add (GTK_CONTAINER (parent), table);
gtk_widget_show (table);
return table;
}
GtkWidget *
gtkW_hbox_new (GtkWidget *parent)
{
GtkWidget *hbox;
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
gtk_box_pack_start (GTK_BOX (parent), hbox, FALSE, TRUE, 0);
gtk_widget_show (hbox);
return hbox;
}
GtkWidget *
gtkW_vbox_new (GtkWidget *parent)
{
GtkWidget *vbox;
vbox = gtk_vbox_new (FALSE, 5);
gtk_container_border_width (GTK_CONTAINER (vbox), 10);
/* gtk_box_pack_start (GTK_BOX (parent), vbox, TRUE, TRUE, 0); */
gtk_container_add (GTK_CONTAINER (parent), vbox);
gtk_widget_show (vbox);
return vbox;
}
GtkWidget *
gtkW_check_button_new (GtkWidget *parent,
gchar *name,
GtkSignalFunc update,
gint *value)
{
GtkWidget *toggle;
toggle = gtk_check_button_new_with_label (name);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) update,
value);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), *value);
gtk_container_add (GTK_CONTAINER (parent), toggle);
gtk_widget_show (toggle);
return toggle;
}
GtkWidget *
gtkW_frame_new (GtkWidget *parent,
gchar *name)
{
GtkWidget *frame;
frame = gtk_frame_new (name);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
gtk_box_pack_start (GTK_BOX(parent), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
return frame;
}
static void
gtkW_table_add_iscale_entry (GtkWidget *table,
gchar *name,
gint x,
gint y,
GtkSignalFunc scale_update,
GtkSignalFunc entry_update,
gint *value,
gdouble min,
gdouble max,
gdouble step,
gchar *buffer)
{
GtkObject *adjustment;
GtkWidget *label, *hbox, *scale, *entry;
label = gtk_label_new (name);
gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE(table), label, x, x+1, y, y+1,
GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
gtk_widget_show (label);
hbox = gtk_hbox_new (FALSE, 4);
gtk_table_attach (GTK_TABLE (table), hbox, x+1, x+2, y, y+1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
adjustment = gtk_adjustment_new (*value, min, max, step, step, 0.0);
gtk_widget_show (hbox);
scale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
gtk_widget_set_usize (scale, SCALE_WIDTH, 0);
gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
(GtkSignalFunc) scale_update, value);
entry = gtk_entry_new ();
gtk_object_set_user_data (GTK_OBJECT (entry), adjustment);
gtk_object_set_user_data (adjustment, entry);
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
gtk_widget_set_usize (entry, ENTRY_WIDTH/3, 0);
sprintf (buffer, "%d", *value);
gtk_entry_set_text (GTK_ENTRY (entry), buffer);
gtk_signal_connect (GTK_OBJECT (entry), "changed",
(GtkSignalFunc) entry_update, value);
gtk_widget_show (label);
gtk_widget_show (scale);
gtk_widget_show (entry);
}
static void
gtkW_iscale_update (GtkAdjustment *adjustment,
gpointer data)
{
GtkWidget *entry;
gchar buffer[32];
int *val;
val = data;
if (*val != (int) adjustment->value)
{
*val = adjustment->value;
entry = gtk_object_get_user_data (GTK_OBJECT (adjustment));
sprintf (buffer, "%d", (int) adjustment->value);
gtk_entry_set_text (GTK_ENTRY (entry), buffer);
}
}
static void
gtkW_ientry_update (GtkWidget *widget,
gpointer data)
{
GtkAdjustment *adjustment;
int new_val;
int *val;
val = data;
new_val = atoi (gtk_entry_get_text (GTK_ENTRY (widget)));
if (*val != new_val)
{
adjustment = gtk_object_get_user_data (GTK_OBJECT (widget));
if ((new_val >= adjustment->lower) &&
(new_val <= adjustment->upper))
{
*val = new_val;
adjustment->value = new_val;
gtk_signal_emit_by_name (GTK_OBJECT (adjustment), "value_changed");
}
}
}