Commit 6b31ee49 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

plug-ins/common/.cvsignore plug-ins/common/Makefile.am

2000-02-29  Michael Natterer  <mitch@gimp.org>

	* plug-ins/common/.cvsignore
	* plug-ins/common/Makefile.am
	* plug-ins/common/plugin-defs.pl
	* po-plug-ins/POTFILES.in
	* help/C/filters/Makefile.am
	* help/C/filters/index.html
	* plug-ins/common/uniteditor.c
	* help/C/filters/uniteditor.html: new plugin.

	After one year of announcing it, I finally hacked the GIMP unit
	editor. Have fun with lightyears, parsec, ... :-)
parent 81692505
2000-02-29 Michael Natterer <mitch@gimp.org>
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl
* po-plug-ins/POTFILES.in
* help/C/filters/Makefile.am
* help/C/filters/index.html
* plug-ins/common/uniteditor.c
* help/C/filters/uniteditor.html: new plugin.
After one year of announcing it, I finally hacked the GIMP unit
editor. Have fun with lightyears, parsec, ... :-)
Mon Feb 28 23:52:56 CET 2000 Sven Neumann <sven@gimp.org>
* app/measure.c: fixed off-by-one error for the x coordinate
......
......@@ -877,6 +877,12 @@ MAINTAINER :
SIZE : 70.6 kB in 5 files (only C files counted)
COMMENT :
-----------
NAME : uniteditor
AUTHOR : Michael Natterer <mitch@gimp.org>
MAINTAINER : Michael Natterer <mitch@gimp.org>
SIZE : 16.5 kB in 1 file (only C files counted)
COMMENT :
-----------
NAME : unsharp
AUTHOR : Winston Chang <wchang3@students.wisc.edu>
MAINTAINER : Winston Chang <wchang3@students.wisc.edu>
......
......@@ -145,6 +145,7 @@ helpdata_DATA = \
tile.html \
tileit.html \
tiler.html \
uniteditor.html \
unsharp.html \
url.html \
video.html \
......
......@@ -161,6 +161,7 @@
<a href="tile.html">tile</a><br>
<a href="tileit.html">tileit</a><br>
<a href="tiler.html">tiler</a><br>
<a href="uniteditor.html">uniteditor</a><br>
<a href="unsharp.html">unsharp</a><br>
<a href="url.html">url</a><br>
<a href="video.html">video</a><br>
......
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<title>Help Page for uniteditor</title>
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#0000FF"
vlink="#FF0000" alink="#000088">
<table width="100%" cellspacing="1" cellpadding="1">
<tr bgcolor="black">
<td width="100%" align="center">
<font size="+2" color="white">uniteditor help page</font>
</td>
</tr>
<tr bgcolor="white" >
<td width="100%" align="left">
<p>
<a href="index.html">Index</a><p>
(/filters/uniteditor.html)<p>
Sorry but the help file for uniteditor is not yet done.
<p>
/Karin & Olof
<p>
</td>
</tr>
</table>
</body>
</html>
......@@ -110,6 +110,7 @@ tiff
tile
tileit
tiler
uniteditor
unsharp
url
video
......
......@@ -125,6 +125,7 @@ libexec_PROGRAMS = \
tile \
tileit \
tiler \
uniteditor \
unsharp \
url \
video \
......@@ -1121,6 +1122,15 @@ tiler_LDADD = \
$(GLIB_LIBS) \
$(INTLLIBS)
uniteditor_SOURCES = \
uniteditor.c
uniteditor_LDADD = \
$(top_builddir)/libgimp/libgimpui.la \
$(top_builddir)/libgimp/libgimp.la \
$(GTK_LIBS) \
$(INTLLIBS)
unsharp_SOURCES = \
unsharp.c
......
......@@ -107,6 +107,7 @@
'tile' => { libdep => 'gtk', ui => 1 },
'tileit' => { libdep => 'gtk', ui => 1 },
'tiler' => { libdep => 'glib' },
'uniteditor' => { libdep => 'gtk', ui => 1 },
'unsharp' => { libdep => 'gtk', ui => 1 },
'url' => { libdep => 'glib' },
'video' => { libdep => 'gtk', ui => 1 },
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
*
* Copyright (C) 2000 Michael Natterer <mitch@gimp.org>
*
* 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 "config.h"
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
#include "pixmaps/new.xpm"
#include "pixmaps/duplicate.xpm"
#include "pixmaps/yes.xpm"
#include "pixmaps/no.xpm"
static void query (void);
static void run (gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals);
static void unit_editor_dialog (void);
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN ()
static void
query (void)
{
static GParamDef args[] =
{
{ PARAM_INT32, "run_mode", "Interactive" }
};
static gint nargs = sizeof (args) / sizeof (args[0]);
gimp_install_procedure ("plug_in_unit_editor",
"The GIMP unit editor (runs in interactive mode only)",
"The GIMP unit editor (runs in interactive mode only)",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer <mitch@gimp.org>",
"2000",
N_("<Toolbox>/Xtns/Unit Editor..."),
"",
PROC_EXTENSION,
nargs, 0,
args, NULL);
}
static void
run (gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals)
{
static GParam values[2];
GRunModeType run_mode;
run_mode = param[0].data.d_int32;
*nreturn_vals = 1;
*return_vals = values;
values[0].type = PARAM_STATUS;
values[0].data.d_status = STATUS_CALLING_ERROR;
if (strcmp (name, "plug_in_unit_editor") == 0)
{
values[0].data.d_status = STATUS_SUCCESS;
INIT_I18N_UI();
unit_editor_dialog ();
}
}
static GdkPixmap *yes_pixmap = NULL;
static GdkBitmap *yes_mask = NULL;
static GdkPixmap *no_pixmap = NULL;
static GdkBitmap *no_mask = NULL;
static GtkWidget *delete_button = NULL;
static GtkWidget *undelete_button = NULL;
static GtkWidget *main_dialog = NULL;
static GtkWidget *clist = NULL;
static GdkColor color;
static GimpUnit current_unit = GIMP_UNIT_INCH;
static gint current_row = 0;
static void
new_unit_ok_callback (GtkWidget *widget,
gpointer data)
{
*((gboolean *) data) = TRUE;
gtk_main_quit ();
}
static GimpUnit
new_unit (GimpUnit template)
{
GtkWidget *dialog;
GtkWidget *table;
GtkWidget *entry;
GtkWidget *spinbutton;
GtkWidget *identifier_entry;
GtkObject *factor_adj;
GtkObject *digits_adj;
GtkWidget *symbol_entry;
GtkWidget *abbreviation_entry;
GtkWidget *singular_entry;
GtkWidget *plural_entry;
gchar *str;
gboolean ok = FALSE;
GimpUnit unit = GIMP_UNIT_PIXEL;
gtk_widget_set_sensitive (main_dialog, FALSE);
dialog = gimp_dialog_new (_("New Unit"), "uniteditor",
gimp_plugin_help_func, "filters/uniteditor.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
_("OK"), new_unit_ok_callback,
&ok, NULL, NULL, TRUE, FALSE,
_("Cancel"), gtk_main_quit,
NULL, 1, NULL, FALSE, TRUE,
NULL);
table = gtk_table_new (7, 2, 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), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), table,
FALSE, FALSE, 0);
gtk_widget_show (table);
entry = identifier_entry = gtk_entry_new ();
if (template != GIMP_UNIT_PIXEL)
{
str = gimp_unit_get_identifier (template);
gtk_entry_set_text (GTK_ENTRY (entry), str);
g_free (str);
}
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("ID:"), 1.0, 0.5,
entry, 1, FALSE);
spinbutton = gimp_spin_button_new (&factor_adj,
(template != GIMP_UNIT_PIXEL) ?
gimp_unit_get_factor (template) : 1.0,
GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION,
0.01, 0.1, 0.0, 0.01, 5);
gtk_widget_set_usize (spinbutton, 100, -1);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Factor:"), 1.0, 0.5,
spinbutton, 1, TRUE);
spinbutton = gimp_spin_button_new (&digits_adj,
(template != GIMP_UNIT_PIXEL) ?
gimp_unit_get_digits (template) : 2.0,
0, 5, 1, 1, 0, 1, 0);
gtk_widget_set_usize (spinbutton, 50, -1);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("Digits:"), 1.0, 0.5,
spinbutton, 1, TRUE);
entry = symbol_entry = gtk_entry_new ();
if (template != GIMP_UNIT_PIXEL)
{
str = gimp_unit_get_symbol (template);
gtk_entry_set_text (GTK_ENTRY (entry), str);
g_free (str);
}
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
_("Symbol:"), 1.0, 0.5,
entry, 1, FALSE);
entry = abbreviation_entry = gtk_entry_new ();
if (template != GIMP_UNIT_PIXEL)
{
str = gimp_unit_get_abbreviation (template);
gtk_entry_set_text (GTK_ENTRY (entry), str);
g_free (str);
}
gimp_table_attach_aligned (GTK_TABLE (table), 0, 4,
_("Abbreviation:"), 1.0, 0.5,
entry, 1, FALSE);
entry = singular_entry = gtk_entry_new ();
if (template != GIMP_UNIT_PIXEL)
{
str = gimp_unit_get_singular (template);
gtk_entry_set_text (GTK_ENTRY (entry), str);
g_free (str);
}
gimp_table_attach_aligned (GTK_TABLE (table), 0, 5,
_("Singular:"), 1.0, 0.5,
entry, 1, FALSE);
entry = plural_entry = gtk_entry_new ();
if (template != GIMP_UNIT_PIXEL)
{
str = gimp_unit_get_plural (template);
gtk_entry_set_text (GTK_ENTRY (entry), str);
g_free (str);
}
gimp_table_attach_aligned (GTK_TABLE (table), 0, 6,
_("Plural:"), 1.0, 0.5,
entry, 1, FALSE);
gtk_widget_show (dialog);
while (1)
{
gtk_main ();
if (ok)
{
gchar *identifier;
gdouble factor;
gint digits;
gchar *symbol;
gchar *abbreviation;
gchar *singular;
gchar *plural;
identifier = gtk_entry_get_text (GTK_ENTRY (identifier_entry));
factor = GTK_ADJUSTMENT (factor_adj)->value;
digits = ROUND (GTK_ADJUSTMENT (digits_adj)->value);
symbol = gtk_entry_get_text (GTK_ENTRY (symbol_entry));
abbreviation = gtk_entry_get_text (GTK_ENTRY (abbreviation_entry));
singular = gtk_entry_get_text (GTK_ENTRY (singular_entry));
plural = gtk_entry_get_text (GTK_ENTRY (plural_entry));
identifier = g_strstrip (g_strdup (identifier));
symbol = g_strstrip (g_strdup (symbol));
abbreviation = g_strstrip (g_strdup (abbreviation));
singular = g_strstrip (g_strdup (singular));
plural = g_strstrip (g_strdup (plural));
if (factor < GIMP_MIN_RESOLUTION)
{
g_message (_("Unit factor must not be 0."));
ok = FALSE;
}
if (!strlen (identifier) |
!strlen (symbol) |
!strlen (abbreviation) |
!strlen (singular) |
!strlen (plural))
{
g_message (_("All text fields must contain a value."));
ok = FALSE;
}
if (ok)
unit = gimp_unit_new (identifier, factor, digits,
symbol, abbreviation,
singular, plural);
g_free (identifier);
g_free (symbol);
g_free (abbreviation);
g_free (singular);
g_free (plural);
if (ok)
break;
}
else
{
break;
}
}
gtk_widget_destroy (dialog);
gdk_flush ();
gtk_widget_set_sensitive (main_dialog, TRUE);
return unit;
}
static void
clist_init (void)
{
gchar *entries[8];
gint num_units;
GimpUnit unit;
gint column_width;
gint row;
gint i;
entries[0] = NULL;
num_units = gimp_unit_get_number_of_units ();
for (unit = GIMP_UNIT_INCH; unit < num_units; unit++)
{
row = unit - GIMP_UNIT_INCH;
entries[1] = gimp_unit_get_identifier (unit);
entries[2] = g_strdup_printf ("%.5f", gimp_unit_get_factor (unit));
entries[3] = g_strdup_printf ("%d", gimp_unit_get_digits (unit));
entries[4] = gimp_unit_get_symbol (unit);
entries[5] = gimp_unit_get_abbreviation (unit);
entries[6] = gimp_unit_get_singular (unit);
entries[7] = gimp_unit_get_plural (unit);
gtk_clist_append (GTK_CLIST (clist), entries);
gtk_clist_set_row_data (GTK_CLIST (clist), row,
(gpointer) unit);
if (unit < gimp_unit_get_number_of_built_in_units ())
gtk_clist_set_background (GTK_CLIST (clist), row, &color);
if (gimp_unit_get_deletion_flag (unit))
{
gtk_clist_set_pixmap (GTK_CLIST (clist), row, 0,
no_pixmap, no_mask);
}
else
{
gtk_clist_set_pixmap (GTK_CLIST (clist), row, 0,
yes_pixmap, yes_mask);
}
for (i = 1; i < 8; i++)
g_free (entries[i]);
}
for (i = 0; i < 8; i++)
{
column_width = gtk_clist_optimal_column_width (GTK_CLIST (clist), i);
gtk_clist_set_column_width (GTK_CLIST (clist), i, column_width);
}
}
static void
select_row_callback (GtkWidget *widget,
gint row,
gint column,
GdkEventButton *bevent,
gpointer data)
{
GimpUnit unit;
gboolean delete_sensitive = TRUE;
gboolean undelete_sensitive = TRUE;
current_row = row;
unit = current_unit =
(GimpUnit) gtk_clist_get_row_data (GTK_CLIST (widget), row);
if (unit < gimp_unit_get_number_of_built_in_units ())
{
delete_sensitive = FALSE;
undelete_sensitive = FALSE;
}
else if (gimp_unit_get_deletion_flag (unit))
{
delete_sensitive = FALSE;
}
else
{
undelete_sensitive = FALSE;
}
gtk_widget_set_sensitive (delete_button, delete_sensitive);
gtk_widget_set_sensitive (undelete_button, undelete_sensitive);
}
static void
refresh_callback (GtkWidget *widget,
gpointer data)
{
gtk_clist_clear (GTK_CLIST (clist));
clist_init ();
gtk_clist_select_row (GTK_CLIST (clist), 0, 0);
}
static void
new_callback (GtkWidget *widget,
gpointer data)
{
GimpUnit unit;
unit = new_unit (GIMP_UNIT_PIXEL);
if (unit != GIMP_UNIT_PIXEL)
{
refresh_callback (NULL, NULL);
gtk_clist_select_row (GTK_CLIST (clist), unit - GIMP_UNIT_INCH, 0);
gtk_clist_moveto (GTK_CLIST (clist), unit - GIMP_UNIT_INCH, -1, 0.5, 0.0);
}
}
static void
duplicate_callback (GtkWidget *widget,
gpointer data)
{
GimpUnit unit;
unit = new_unit (current_unit);
if (unit != GIMP_UNIT_PIXEL)
{
refresh_callback (NULL, NULL);
gtk_clist_select_row (GTK_CLIST (clist), unit - GIMP_UNIT_INCH, 0);
gtk_clist_moveto (GTK_CLIST (clist), unit - GIMP_UNIT_INCH, -1, 0.5, 0.0);
}
}
static void
delete_callback (GtkWidget *widget,
gpointer data)
{
gimp_unit_set_deletion_flag (current_unit, TRUE);
gtk_clist_set_pixmap (GTK_CLIST (clist), current_row, 0,
no_pixmap, no_mask);
gtk_clist_select_row (GTK_CLIST (clist), current_row, 0);
}
static void
undelete_callback (GtkWidget *widget,
gpointer data)
{
gimp_unit_set_deletion_flag (current_unit, FALSE);
gtk_clist_set_pixmap (GTK_CLIST (clist), current_row, 0,
yes_pixmap, yes_mask);
gtk_clist_select_row (GTK_CLIST (clist), current_row, 0);
}
static void
unit_editor_dialog (void)
{
GtkWidget *main_vbox;
GtkWidget *scrolled_win;
GtkWidget *hbox;
GtkWidget *button;
GtkStyle *style;
gchar *titles[8];
gchar **argv;
gint argc;
argc = 1;
argv = g_new (gchar *, 1);
argv[0] = g_strdup ("uniteditor");
gtk_init (&argc, &argv);
gtk_rc_parse (gimp_gtkrc ());
main_dialog =
gimp_dialog_new (_("Unit Editor"), "uniteditor",
gimp_plugin_help_func, "filters/uniteditor.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, TRUE,
_("Refresh"), refresh_callback,
NULL, NULL, NULL, FALSE, FALSE,
_("Close"), gtk_widget_destroy,
NULL, 1, NULL, TRUE, TRUE,
NULL);
gtk_signal_connect (GTK_OBJECT (main_dialog), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit),
NULL);
gimp_help_init ();
/* the main vbox */
main_vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (main_dialog)->vbox), main_vbox);
gtk_widget_show (main_vbox);
/* the selection list */
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_NEVER,
GTK_POLICY_ALWAYS);
gtk_container_add (GTK_CONTAINER (main_vbox), scrolled_win);
gtk_widget_show (scrolled_win);
titles[0] = _("Saved");
titles[1] = _("ID");
titles[2] = _("Factor");
titles[3] = _("Digits");
titles[4] = _("Symbol");
titles[5] = _("Abbr.");
titles[6] = _("Singular");
titles[7] = _("Plural");
clist = gtk_clist_new_with_titles (8, titles);
gtk_clist_set_shadow_type (GTK_CLIST (clist), GTK_SHADOW_IN);
gtk_clist_set_selection_mode (GTK_CLIST (clist), GTK_SELECTION_BROWSE);
gtk_clist_column_titles_passive (GTK_CLIST (clist));
gtk_widget_realize (main_dialog);
style = gtk_widget_get_style (main_dialog);
yes_pixmap = gdk_pixmap_create_from_xpm_d (main_dialog->window,
&yes_mask,
&style->bg[GTK_STATE_NORMAL],
yes_xpm);
no_pixmap = gdk_pixmap_create_from_xpm_d (main_dialog->window,
&no_mask,
&style->bg[GTK_STATE_NORMAL],
no_xpm);
color.red = 65535;
color.green = 50000;
color.blue = 50000;
gdk_color_alloc (gtk_widget_get_colormap (main_dialog), &color);
clist_init ();
gtk_widget_set_usize (clist, -1, 200);
gtk_container_add (GTK_CONTAINER (scrolled_win), clist);
gtk_signal_connect (GTK_OBJECT (clist), "select_row",
GTK_SIGNAL_FUNC (select_row_callback),
NULL);