1997-11-25 06:05:25 +08:00
|
|
|
/* 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdio.h>
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
#include <stdlib.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <string.h>
|
1999-05-05 20:32:24 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <unistd.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_DIRENT_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <dirent.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#endif
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "datafiles.h"
|
|
|
|
#include "patterns.h"
|
|
|
|
#include "pattern_header.h"
|
1999-11-14 19:43:03 +08:00
|
|
|
#include "gimpcontext.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gimprc.h"
|
|
|
|
|
1998-12-16 08:37:09 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* global variables */
|
1999-11-14 19:43:03 +08:00
|
|
|
GPattern *active_pattern = NULL;
|
|
|
|
GSList *pattern_list = NULL;
|
|
|
|
gint num_patterns = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* static variables */
|
1999-10-27 02:27:27 +08:00
|
|
|
static GPattern *standard_pattern = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-11-14 19:43:03 +08:00
|
|
|
/* local function prototypes */
|
1999-10-27 02:27:27 +08:00
|
|
|
static GSList * insert_pattern_in_list (GSList *, GPattern *);
|
|
|
|
static void load_pattern (gchar *);
|
1999-11-04 08:03:27 +08:00
|
|
|
static void pattern_free_func (gpointer, gpointer);
|
1999-10-27 02:27:27 +08:00
|
|
|
static gint pattern_compare_func (gconstpointer,
|
|
|
|
gconstpointer);
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
patterns_init (gboolean no_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-01-29 16:03:27 +08:00
|
|
|
GSList *list;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (pattern_list)
|
|
|
|
patterns_free ();
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
if (pattern_path != NULL && !no_data)
|
1998-03-27 02:24:42 +08:00
|
|
|
datafiles_read_directories (pattern_path, load_pattern, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* assign indexes to the loaded patterns */
|
1999-10-27 02:27:27 +08:00
|
|
|
for (list = pattern_list; list; list = g_slist_next (list))
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
{
|
|
|
|
/* Set the pattern index */
|
|
|
|
((GPattern *) list->data)->index = num_patterns++;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_context_refresh_patterns ();
|
1998-01-29 16:03:27 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-29 16:03:27 +08:00
|
|
|
void
|
1999-11-14 19:43:03 +08:00
|
|
|
patterns_free (void)
|
1998-01-29 16:03:27 +08:00
|
|
|
{
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
if (pattern_list)
|
|
|
|
{
|
1999-11-04 08:03:27 +08:00
|
|
|
g_slist_foreach (pattern_list, pattern_free_func, NULL);
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
g_slist_free (pattern_list);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
num_patterns = 0;
|
|
|
|
pattern_list = NULL;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
GPattern *
|
|
|
|
patterns_get_standard_pattern (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
if (! standard_pattern)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-11-14 19:43:03 +08:00
|
|
|
guchar *data;
|
|
|
|
gint row, col;
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
standard_pattern = g_new (GPattern, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
standard_pattern->filename = NULL;
|
|
|
|
standard_pattern->name = g_strdup ("Standard");
|
1999-11-14 18:50:19 +08:00
|
|
|
standard_pattern->index = -1; /* not part of the pattern list */
|
1999-11-14 19:43:03 +08:00
|
|
|
standard_pattern->mask = temp_buf_new (32, 32, 3, 0, 0, NULL);
|
|
|
|
|
|
|
|
data = temp_buf_data (standard_pattern->mask);
|
|
|
|
|
|
|
|
for (row = 0; row < standard_pattern->mask->height; row++)
|
|
|
|
for (col = 0; col < standard_pattern->mask->width; col++)
|
|
|
|
{
|
1999-12-07 06:44:40 +08:00
|
|
|
memset (data, (col % 2) && (row % 2) ? 255 : 0, 3);
|
|
|
|
data += 3;
|
1999-11-14 19:43:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
return standard_pattern;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
GPattern *
|
|
|
|
pattern_list_get_pattern_by_index (GSList *list,
|
|
|
|
gint index)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
GPattern *pattern = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
list = g_slist_nth (list, index);
|
|
|
|
if (list)
|
|
|
|
pattern = (GPattern *) list->data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
return pattern;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
GPattern *
|
|
|
|
pattern_list_get_pattern (GSList *list,
|
|
|
|
gchar *name)
|
|
|
|
{
|
|
|
|
GPattern *pattern;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
for (; list; list = g_slist_next (list))
|
1999-08-23 14:06:12 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
pattern = (GPattern *) list->data;
|
|
|
|
|
|
|
|
if (!strcmp (pattern->name, name))
|
|
|
|
return pattern;
|
1999-08-23 14:06:12 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
return NULL;
|
1999-08-23 14:06:12 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gboolean
|
|
|
|
pattern_load (GPattern *pattern,
|
|
|
|
FILE *fp,
|
|
|
|
gchar *filename)
|
1999-08-23 14:06:12 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
gint bn_size;
|
|
|
|
guchar buf [sz_PatternHeader];
|
|
|
|
PatternHeader header;
|
|
|
|
guint *hp;
|
|
|
|
gint i;
|
1999-08-23 14:06:12 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Read in the header size */
|
|
|
|
if ((fread (buf, 1, sz_PatternHeader, fp)) < sz_PatternHeader)
|
|
|
|
{
|
|
|
|
fclose (fp);
|
1999-11-04 08:03:27 +08:00
|
|
|
pattern_free (pattern);
|
1999-10-27 02:27:27 +08:00
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* rearrange the bytes in each unsigned int */
|
1999-10-27 02:27:27 +08:00
|
|
|
hp = (guint *) &header;
|
1997-11-25 06:05:25 +08:00
|
|
|
for (i = 0; i < (sz_PatternHeader / 4); i++)
|
|
|
|
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
|
|
|
|
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
|
|
|
|
|
|
|
|
/* Check for correct file format */
|
|
|
|
if (header.magic_number != GPATTERN_MAGIC)
|
|
|
|
{
|
|
|
|
/* One thing that can save this error is if the pattern is version 1 */
|
|
|
|
if (header.version != 1)
|
|
|
|
{
|
|
|
|
fclose (fp);
|
1999-11-04 08:03:27 +08:00
|
|
|
pattern_free (pattern);
|
1999-10-27 02:27:27 +08:00
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Check for correct version */
|
1999-08-16 11:43:48 +08:00
|
|
|
if (header.version != GPATTERN_FILE_VERSION)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-12-16 08:37:09 +08:00
|
|
|
g_message (_("Unknown GIMP version #%d in \"%s\"\n"), header.version,
|
1998-05-28 17:03:57 +08:00
|
|
|
filename);
|
1997-11-25 06:05:25 +08:00
|
|
|
fclose (fp);
|
1999-11-04 08:03:27 +08:00
|
|
|
pattern_free (pattern);
|
1999-10-27 02:27:27 +08:00
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a new pattern mask */
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
pattern->mask =
|
|
|
|
temp_buf_new (header.width, header.height, header.bytes, 0, 0, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Read in the pattern name */
|
|
|
|
if ((bn_size = (header.header_size - sz_PatternHeader)))
|
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
pattern->name = g_new (gchar, bn_size);
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((fread (pattern->name, 1, bn_size, fp)) < bn_size)
|
|
|
|
{
|
1998-12-16 08:37:09 +08:00
|
|
|
g_message (_("Error in GIMP pattern file...aborting."));
|
1997-11-25 06:05:25 +08:00
|
|
|
fclose (fp);
|
1999-11-04 08:03:27 +08:00
|
|
|
pattern_free (pattern);
|
1999-10-27 02:27:27 +08:00
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1998-12-16 08:37:09 +08:00
|
|
|
pattern->name = g_strdup (_("Unnamed"));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Read the pattern mask data */
|
|
|
|
/* Read the image data */
|
|
|
|
if ((fread (temp_buf_data (pattern->mask), 1,
|
|
|
|
header.width * header.height * header.bytes, fp)) <
|
|
|
|
header.width * header.height * header.bytes)
|
1998-12-16 08:37:09 +08:00
|
|
|
g_message (_("GIMP pattern file appears to be truncated."));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* success */
|
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-11-04 08:03:27 +08:00
|
|
|
void
|
|
|
|
pattern_free (GPattern *pattern)
|
|
|
|
{
|
|
|
|
if (pattern->mask)
|
|
|
|
temp_buf_free (pattern->mask);
|
|
|
|
if (pattern->filename)
|
|
|
|
g_free (pattern->filename);
|
|
|
|
if (pattern->name)
|
|
|
|
g_free (pattern->name);
|
|
|
|
|
|
|
|
g_free (pattern);
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* private functions */
|
1998-08-01 06:44:26 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
static void
|
1999-11-04 08:03:27 +08:00
|
|
|
pattern_free_func (gpointer data,
|
|
|
|
gpointer dummy)
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
1999-11-04 08:03:27 +08:00
|
|
|
pattern_free ((GPattern *) data);
|
1998-08-01 06:44:26 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
static gint
|
|
|
|
pattern_compare_func (gconstpointer first,
|
|
|
|
gconstpointer second)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
return strcmp (((const GPattern *) first)->name,
|
|
|
|
((const GPattern *) second)->name);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
static GSList *
|
|
|
|
insert_pattern_in_list (GSList *list,
|
|
|
|
GPattern *pattern)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
return g_slist_insert_sorted (list, pattern, pattern_compare_func);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
static void
|
|
|
|
load_pattern (gchar *filename)
|
|
|
|
{
|
|
|
|
GPattern *pattern;
|
|
|
|
FILE *fp;
|
1998-08-01 06:44:26 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
pattern = g_new (GPattern, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
pattern->filename = g_strdup (filename);
|
|
|
|
pattern->name = NULL;
|
|
|
|
pattern->mask = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* Open the requested file */
|
|
|
|
if (! (fp = fopen (filename, "rb")))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-11-04 08:03:27 +08:00
|
|
|
pattern_free (pattern);
|
1999-10-27 02:27:27 +08:00
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
if (! pattern_load (pattern, fp, filename))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_message (_("Pattern load failed"));
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* Clean up */
|
|
|
|
fclose (fp);
|
|
|
|
|
|
|
|
/*temp_buf_swap (pattern->mask);*/
|
|
|
|
|
|
|
|
pattern_list = insert_pattern_in_list (pattern_list, pattern);
|
|
|
|
}
|