Files
gimp/app/core/gimpimage-new.c
Michael Natterer 5f63e079b8 Chopped up the display stuff (beware: unfinished)...
2001-10-31  Michael Natterer  <mitch@gimp.org>

	Chopped up the display stuff (beware: unfinished)...

	The plan is that GimpDisplay is the object which collects
	updates from the image, compresses them and waits for the GIMP
	to be idle to actually paint them. It should be a non-GUI object
	which is the model for the actual widget to connect to.

	GimpDisplayShell has all the widgets and handles painting and
	exposing of the result. Nobody should actually be required to
	update ot look at it as it should be a view on the GimpDisplay
	object.

	Much stuff is still in the wrong place and the functions don't
	follow their files' filename namespace any more. More to come...

	* app/display/Makefile.am
	* app/display/gimpdisplay-ops.[ch]: removed. It's functions didn't
	belong together anyway.

	* app/display/gimpdisplay-area.[ch]: new files: the GimpArea
	functions.

	* app/display/gimpdisplay-handlers.[ch]: new files: signal
	handlers for GimpImage signals. Mostly from app/gui.c.

	* app/display/gimpdisplay.[ch]: removed all widgets and other
	GUI stuff. There is still much undecided here...

	* app/display/gimpdisplayshell.[ch]: actually use the object and
	filled it with all the stuff from GimpDisplay.

	* app/display/gimpdisplay-callbacks.[ch]
	* app/display/gimpdisplay-foreach.[ch]
	* app/display/gimpdisplay-render.c
	* app/display/gimpdisplay-scale.[ch]
	* app/display/gimpdisplay-scroll.[ch]
	* app/display/gimpdisplay-selection.c: changed accordingly.

	* app/core/gimp.[ch]: return a GimpObject from
	gimp_create_display() so it can be used as single GUI independent
	point to create displays, require the initial scale as parameter.

	* app/core/gimpcontext.c: changed the ugly EEKWrapper according to
	the GimpDisplay structure changes. Bugfix: set the image to NULL
	in gimp_context_display_destroyed().

	* app/core/gimpedit.c
	* app/core/gimpimage-new.c: changed gimp_create_display() calls
	accordingly.

	* app/core/gimpimage-convert.c: invalidate the layer & image
	previews here, not in the caller.

	* app/core/gimpimage-crop.c: update the whole image after cropping.

	* app/core/gimpimage.[ch]: added gimp_image_find_guide(),
	gimp_image_snap_point() and gimp_image_snap_rectangle(). Added
	"resolution_changed" and "unit_changed" signals and corresp.
	public convenience functions to emit them.

	* app/core/gimplayer.c: emit the image's "alpha_changed" signal
	when adding alpha to the bottom (and only) layer of the image.

	* app/gimpprogress.c
	* app/image_map.c
	* app/nav_window.c
	* app/qmask.c
	* app/undo.c
	* app/user_install.c: changed accordingly.

	* app/gui/edit-commands.c
	* app/gui/file-commands.c
	* app/gui/file-open-dialog.c
	* app/gui/image-commands.c
	* app/gui/info-window.c
	* app/gui/preferences-dialog.c
	* app/gui/toolbox.c
	* app/gui/view-commands.c: ditto.

	* app/gui/gui.[ch]: removed most gimp->images handlers as the
	displays connect to them themselves now. chaged gui_display_new()
	according to the gimp_create_display() changes.
	Added gui_get_screen_resolution().

	* app/tools/gimpbezierselecttool.c
	* app/tools/gimpblendtool.c
	* app/tools/gimpbucketfilltool.c
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpclonetool.c
	* app/tools/gimpcolorpickertool.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpdrawtool.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimpfliptool.c
	* app/tools/gimpfreeselecttool.c
	* app/tools/gimpfuzzyselecttool.c
	* app/tools/gimpinktool.c
	* app/tools/gimpiscissorstool.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimpmovetool.c
	* app/tools/gimppainttool.c
	* app/tools/gimppathtool.c
	* app/tools/gimprectselecttool.c
	* app/tools/gimpselectiontool.c
	* app/tools/gimptexttool.c
	* app/tools/gimptool.c
	* app/tools/gimptransformtool.c
	* app/tools/xinput_airbrush.c: lots of changes because GimpDisplay
	has become two objects. Lots of gdisp->shell casting uglyness
	added. This is fine because exactly these parts will have to go
	away.

	(GimpDisplay will provide methods for XOR drawing upon the display
	in image coordinates without the need to transform coordinates all
	the time. Also the tools shouldn't see GdkEvents but get more
	useful virtual functions which speak in image coordinates too).

	* app/widgets/gimpcomponentlistitem.c: removed a now useless image
	update.

	* tools/pdbgen/pdb/display.pdb: use gimp_create_display().

	* app/pdb/display_cmds.c: regenerated.
2001-10-31 21:18:57 +00:00

287 lines
7.6 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h> /* memcpy */
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "base/tile-manager.h"
#include "paint-funcs/paint-funcs.h"
#include "gimp.h"
#include "gimpcoreconfig.h"
#include "gimpdrawable.h"
#include "gimpimage.h"
#include "gimpimage-new.h"
#include "gimplayer.h"
#include "libgimp/gimpintl.h"
void
gimp_image_new_init (Gimp *gimp)
{
GimpImageBaseTypeName *new_type;
GimpFillTypeName *new_fill_type;
/* Available Image Base Types */
new_type = g_new (GimpImageBaseTypeName, 1);
new_type->type = RGB;
new_type->name = _("RGB");
gimp->image_base_type_names = g_list_append (gimp->image_base_type_names,
new_type);
new_type = g_new (GimpImageBaseTypeName, 1);
new_type->type = GRAY;
new_type->name = _("Grayscale");
gimp->image_base_type_names = g_list_append (gimp->image_base_type_names,
new_type);
/* Available Fill Types */
new_fill_type = g_new (GimpFillTypeName, 1);
new_fill_type->type = FOREGROUND_FILL;
new_fill_type->name = _("Foreground");
gimp->fill_type_names = g_list_append (gimp->fill_type_names, new_fill_type);
new_fill_type = g_new (GimpFillTypeName, 1);
new_fill_type->type = BACKGROUND_FILL;
new_fill_type->name = _("Background");
gimp->fill_type_names = g_list_append (gimp->fill_type_names, new_fill_type);
new_fill_type = g_new (GimpFillTypeName, 1);
new_fill_type->type = WHITE_FILL;
new_fill_type->name = _("White");
gimp->fill_type_names = g_list_append (gimp->fill_type_names, new_fill_type);
new_fill_type = g_new (GimpFillTypeName, 1);
new_fill_type->type = TRANSPARENT_FILL;
new_fill_type->name = _("Transparent");
gimp->fill_type_names = g_list_append (gimp->fill_type_names, new_fill_type);
/* Set the last values used to default values. */
gimp->image_new_last_values.width = gimp->config->default_width;
gimp->image_new_last_values.height = gimp->config->default_height;
gimp->image_new_last_values.unit = gimp->config->default_units;
gimp->image_new_last_values.xresolution = gimp->config->default_xresolution;
gimp->image_new_last_values.yresolution = gimp->config->default_yresolution;
gimp->image_new_last_values.res_unit = gimp->config->default_resolution_units;
gimp->image_new_last_values.type = gimp->config->default_type;
gimp->image_new_last_values.fill_type = BACKGROUND_FILL;
gimp->have_current_cut_buffer = FALSE;
}
void
gimp_image_new_exit (Gimp *gimp)
{
g_list_foreach (gimp->image_base_type_names, (GFunc) g_free, NULL);
g_list_free (gimp->image_base_type_names);
gimp->image_base_type_names = NULL;
g_list_foreach (gimp->fill_type_names, (GFunc) g_free, NULL);
g_list_free (gimp->fill_type_names);
gimp->fill_type_names = NULL;
}
GList *
gimp_image_new_get_base_type_names (Gimp *gimp)
{
return gimp->image_base_type_names;
}
GList *
gimp_image_new_get_fill_type_names (Gimp *gimp)
{
return gimp->fill_type_names;
}
GimpImageNewValues *
gimp_image_new_values_new (Gimp *gimp,
GimpImage *gimage)
{
GimpImageNewValues *values;
values = g_new0 (GimpImageNewValues, 1);
if (gimage)
{
values->width = gimp_image_get_width (gimage);
values->height = gimp_image_get_height (gimage);
values->unit = gimp_image_get_unit (gimage);
gimp_image_get_resolution (gimage,
&values->xresolution,
&values->yresolution);
values->type = gimp_image_base_type (gimage);
if (values->type == INDEXED)
values->type = RGB; /* no indexed images */
}
else
{
memcpy (values, &gimp->image_new_last_values, sizeof (GimpImageNewValues));
}
if (gimp->global_buffer && gimp->have_current_cut_buffer)
{
values->width = tile_manager_width (gimp->global_buffer);
values->height = tile_manager_height (gimp->global_buffer);
}
return values;
}
void
gimp_image_new_set_default_values (Gimp *gimp,
GimpImageNewValues *values)
{
g_return_if_fail (values != NULL);
memcpy (&gimp->image_new_last_values, values, sizeof (GimpImageNewValues));
gimp->have_current_cut_buffer = FALSE;
}
void
gimp_image_new_values_free (GimpImageNewValues *values)
{
g_return_if_fail (values != NULL);
g_free (values);
}
gdouble
gimp_image_new_calculate_size (GimpImageNewValues *values)
{
gdouble width, height;
gdouble size;
width = (gdouble) values->width;
height = (gdouble) values->height;
size =
width * height *
((values->type == RGB ? 3 : 1) + /* bytes per pixel */
(values->fill_type == TRANSPARENT_FILL ? 1 : 0)); /* alpha channel */
return size;
}
gchar *
gimp_image_new_get_size_string (gdouble size)
{
if (size < 4096)
return g_strdup_printf (_("%d Bytes"), (gint) size);
else if (size < 1024 * 10)
return g_strdup_printf (_("%.2f KB"), size / 1024);
else if (size < 1024 * 100)
return g_strdup_printf (_("%.1f KB"), size / 1024);
else if (size < 1024 * 1024)
return g_strdup_printf (_("%d KB"), (gint) size / 1024);
else if (size < 1024 * 1024 * 10)
return g_strdup_printf (_("%.2f MB"), size / 1024 / 1024);
else
return g_strdup_printf (_("%.1f MB"), size / 1024 / 1024);
}
void
gimp_image_new_set_have_current_cut_buffer (Gimp *gimp)
{
gimp->have_current_cut_buffer = TRUE;
}
GimpImage *
gimp_image_new_create_image (Gimp *gimp,
GimpImageNewValues *values)
{
GimpImage *gimage;
GimpLayer *layer;
GimpImageType type;
gint width, height;
g_return_val_if_fail (values != NULL, NULL);
gimp_image_new_set_default_values (gimp, values);
switch (values->fill_type)
{
case FOREGROUND_FILL:
case BACKGROUND_FILL:
case WHITE_FILL:
type = (values->type == RGB) ? RGB_GIMAGE : GRAY_GIMAGE;
break;
case TRANSPARENT_FILL:
type = (values->type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE;
break;
default:
type = RGB_GIMAGE;
break;
}
gimage = gimp_create_image (gimp,
values->width, values->height,
values->type,
TRUE);
gimp_image_set_resolution (gimage, values->xresolution, values->yresolution);
gimp_image_set_unit (gimage, values->unit);
width = gimp_image_get_width (gimage);
height = gimp_image_get_height (gimage);
layer = gimp_layer_new (gimage, width, height,
type, _("Background"),
OPAQUE_OPACITY, NORMAL_MODE);
if (layer)
{
gimp_image_undo_disable (gimage);
gimp_image_add_layer (gimage, layer, 0);
gimp_image_undo_enable (gimage);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer),
gimp_get_current_context (gimp),
values->fill_type);
gimp_image_clean_all (gimage);
gimp_create_display (gimp, gimage, 0x0101);
g_object_unref (G_OBJECT (gimage));
}
return gimage;
}