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
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include "config.h"
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display-types.h"
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools/tools-types.h"
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimp.h"
|
2002-05-09 01:48:24 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2001-11-28 11:08:03 +08:00
|
|
|
#include "core/gimpimage-projection.h"
|
2002-05-09 01:48:24 +08:00
|
|
|
#include "core/gimplist.h"
|
2001-05-14 05:51:20 +08:00
|
|
|
|
2004-04-22 00:33:17 +08:00
|
|
|
#include "widgets/gimpuimanager.h"
|
2003-01-11 01:55:53 +08:00
|
|
|
|
2003-04-15 22:20:19 +08:00
|
|
|
#include "tools/gimptool.h"
|
2001-02-28 10:53:27 +08:00
|
|
|
#include "tools/tool_manager.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdisplay.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "gimpdisplay-area.h"
|
|
|
|
#include "gimpdisplay-handlers.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdisplayshell.h"
|
2001-11-11 07:03:22 +08:00
|
|
|
#include "gimpdisplayshell-handlers.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "gimpdisplayshell-transform.h"
|
2001-04-18 05:43:29 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2001-07-31 19:33:13 +08:00
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_IMAGE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
/* local function prototypes */
|
2001-07-31 19:33:13 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
static void gimp_display_class_init (GimpDisplayClass *klass);
|
|
|
|
static void gimp_display_init (GimpDisplay *gdisp);
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
static void gimp_display_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_display_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2003-10-08 22:50:26 +08:00
|
|
|
static void gimp_display_flush_whenever (GimpDisplay *gdisp,
|
2001-11-11 07:03:22 +08:00
|
|
|
gboolean now);
|
|
|
|
static void gimp_display_idlerender_init (GimpDisplay *gdisp);
|
|
|
|
static gboolean gimp_display_idlerender_callback (gpointer data);
|
|
|
|
static gboolean gimp_display_idle_render_next_area (GimpDisplay *gdisp);
|
|
|
|
static void gimp_display_paint_area (GimpDisplay *gdisp,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2001-09-26 01:44:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
static GimpObjectClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_display_get_type (void)
|
|
|
|
{
|
|
|
|
static GType display_type = 0;
|
|
|
|
|
|
|
|
if (! display_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo display_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpDisplayClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_display_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpDisplay),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_display_init,
|
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
display_type = g_type_register_static (GIMP_TYPE_OBJECT,
|
|
|
|
"GimpDisplay",
|
|
|
|
&display_info, 0);
|
|
|
|
}
|
2001-02-02 02:44:22 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
return display_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_display_class_init (GimpDisplayClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
object_class->set_property = gimp_display_set_property;
|
|
|
|
object_class->get_property = gimp_display_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_IMAGE,
|
|
|
|
g_param_spec_object ("image",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_IMAGE,
|
|
|
|
G_PARAM_READABLE));
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_display_init (GimpDisplay *gdisp)
|
|
|
|
{
|
2002-05-09 01:48:24 +08:00
|
|
|
gdisp->ID = 0;
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gdisp->gimage = NULL;
|
|
|
|
gdisp->instance = 0;
|
2001-09-26 01:44:03 +08:00
|
|
|
|
|
|
|
gdisp->shell = NULL;
|
|
|
|
|
|
|
|
gdisp->update_areas = NULL;
|
1998-06-15 10:25:27 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
gdisp->idle_render.idle_id = 0;
|
1998-10-02 00:22:28 +08:00
|
|
|
gdisp->idle_render.update_areas = NULL;
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
static void
|
|
|
|
gimp_display_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_IMAGE:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_display_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
GimpDisplay *gdisp = GIMP_DISPLAY (object);
|
2002-05-10 21:09:19 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_IMAGE:
|
|
|
|
g_value_set_object (value, gdisp->gimage);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
GimpDisplay *
|
2003-01-11 01:55:53 +08:00
|
|
|
gimp_display_new (GimpImage *gimage,
|
2004-06-02 06:04:20 +08:00
|
|
|
GimpUnit unit,
|
2004-01-30 06:22:29 +08:00
|
|
|
gdouble scale,
|
2003-01-11 01:55:53 +08:00
|
|
|
GimpMenuFactory *menu_factory,
|
2004-04-29 20:52:29 +08:00
|
|
|
GimpUIManager *popup_manager)
|
2001-09-26 01:44:03 +08:00
|
|
|
{
|
|
|
|
GimpDisplay *gdisp;
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
/* If there isn't an interface, never create a gdisplay */
|
2001-10-29 19:47:11 +08:00
|
|
|
if (gimage->gimp->no_interface)
|
2001-09-26 01:44:03 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gdisp = g_object_new (GIMP_TYPE_DISPLAY, NULL);
|
|
|
|
|
2002-05-11 02:27:51 +08:00
|
|
|
gdisp->ID = gimage->gimp->next_display_ID++;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-05-08 20:39:01 +08:00
|
|
|
/* refs the image */
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_connect (gdisp, gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
/* create the shell for the image */
|
2004-06-02 06:04:20 +08:00
|
|
|
gdisp->shell = gimp_display_shell_new (gdisp, unit, scale,
|
2004-04-29 20:52:29 +08:00
|
|
|
menu_factory, popup_manager);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
gtk_widget_show (gdisp->shell);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return gdisp;
|
|
|
|
}
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
void
|
2001-11-11 07:03:22 +08:00
|
|
|
gimp_display_delete (GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpTool *active_tool;
|
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
/* remove the display from the list */
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_container_remove (gdisp->gimage->gimp->displays,
|
|
|
|
GIMP_OBJECT (gdisp));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* stop any active tool */
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
|
|
|
|
|
|
|
|
active_tool = tool_manager_get_active (gdisp->gimage->gimp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-14 19:14:28 +08:00
|
|
|
if (active_tool)
|
1999-06-22 06:12:07 +08:00
|
|
|
{
|
2003-10-14 19:14:28 +08:00
|
|
|
if (active_tool->focus_display == gdisp)
|
|
|
|
tool_manager_focus_display_active (gdisp->gimage->gimp, NULL);
|
|
|
|
|
|
|
|
/* clear out the pointer to this gdisp from the active tool */
|
|
|
|
if (active_tool->gdisp == gdisp)
|
|
|
|
{
|
|
|
|
active_tool->drawable = NULL;
|
|
|
|
active_tool->gdisp = NULL;
|
|
|
|
}
|
1998-04-15 06:05:08 +08:00
|
|
|
}
|
1998-04-13 12:32:39 +08:00
|
|
|
|
1998-10-02 00:22:28 +08:00
|
|
|
/* If this gdisplay was idlerendering at the time when it was deleted,
|
2001-11-11 07:03:22 +08:00
|
|
|
* deactivate the idlerendering thread before deletion!
|
|
|
|
*/
|
|
|
|
if (gdisp->idle_render.idle_id)
|
1998-10-02 00:22:28 +08:00
|
|
|
{
|
2001-11-11 07:03:22 +08:00
|
|
|
g_source_remove (gdisp->idle_render.idle_id);
|
|
|
|
gdisp->idle_render.idle_id = 0;
|
1998-10-02 00:22:28 +08:00
|
|
|
}
|
1999-08-23 22:34:58 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
/* free the update area lists */
|
|
|
|
gimp_display_area_list_free (gdisp->update_areas);
|
|
|
|
gimp_display_area_list_free (gdisp->idle_render.update_areas);
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
if (gdisp->shell)
|
|
|
|
{
|
2004-01-03 01:36:45 +08:00
|
|
|
GtkWidget *shell = gdisp->shell;
|
|
|
|
|
|
|
|
/* set gdisp->shell to NULL *before* destroying the shell.
|
|
|
|
* all callbacks in gimpdisplayshell-callbacks.c will check
|
|
|
|
* this pointer and do nothing if the shell is in destruction.
|
|
|
|
*/
|
2001-09-26 01:44:03 +08:00
|
|
|
gdisp->shell = NULL;
|
2004-01-03 01:36:45 +08:00
|
|
|
gtk_widget_destroy (shell);
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
1998-02-14 23:30:31 +08:00
|
|
|
|
2002-05-08 20:39:01 +08:00
|
|
|
/* unrefs the gimage */
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_disconnect (gdisp);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
gint
|
|
|
|
gimp_display_get_ID (GimpDisplay *gdisp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (gdisp), -1);
|
|
|
|
|
|
|
|
return gdisp->ID;
|
|
|
|
}
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplay *
|
2001-11-11 07:03:22 +08:00
|
|
|
gimp_display_get_by_ID (Gimp *gimp,
|
|
|
|
gint ID)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplay *gdisp;
|
2002-05-09 01:48:24 +08:00
|
|
|
GList *list;
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2002-05-08 20:39:01 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
2002-05-09 01:48:24 +08:00
|
|
|
for (list = GIMP_LIST (gimp->displays)->list;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
gdisp = (GimpDisplay *) list->data;
|
|
|
|
|
|
|
|
if (gdisp->ID == ID)
|
|
|
|
return gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
void
|
2003-10-08 22:50:26 +08:00
|
|
|
gimp_display_reconnect (GimpDisplay *gdisp,
|
2001-11-11 07:03:22 +08:00
|
|
|
GimpImage *gimage)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
if (gdisp->idle_render.idle_id)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-11 07:03:22 +08:00
|
|
|
g_source_remove (gdisp->idle_render.idle_id);
|
|
|
|
gdisp->idle_render.idle_id = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2003-10-12 19:20:22 +08:00
|
|
|
/* stop any active tool */
|
|
|
|
tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
|
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
gimp_display_shell_disconnect (GIMP_DISPLAY_SHELL (gdisp->shell));
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_disconnect (gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_connect (gdisp, gimage);
|
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
gimp_display_add_update_area (gdisp,
|
|
|
|
0, 0,
|
|
|
|
gdisp->gimage->width,
|
|
|
|
gdisp->gimage->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
gimp_display_shell_reconnect (GIMP_DISPLAY_SHELL (gdisp->shell));
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
void
|
|
|
|
gimp_display_add_update_area (GimpDisplay *gdisp,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-16 23:08:59 +08:00
|
|
|
GimpArea *area;
|
1998-10-02 00:22:28 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
|
1998-10-02 00:22:28 +08:00
|
|
|
|
2001-11-16 23:08:59 +08:00
|
|
|
area = gimp_area_new (CLAMP (x, 0, gdisp->gimage->width),
|
|
|
|
CLAMP (y, 0, gdisp->gimage->height),
|
|
|
|
CLAMP (x + w, 0, gdisp->gimage->width),
|
|
|
|
CLAMP (y + h, 0, gdisp->gimage->height));
|
1997-11-27 03:30:17 +08:00
|
|
|
|
2001-11-16 23:08:59 +08:00
|
|
|
gdisp->update_areas = gimp_display_area_list_process (gdisp->update_areas,
|
|
|
|
area);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-10-02 00:22:28 +08:00
|
|
|
void
|
2001-11-11 07:03:22 +08:00
|
|
|
gimp_display_flush (GimpDisplay *gdisp)
|
1998-10-02 00:22:28 +08:00
|
|
|
{
|
2001-09-26 01:44:03 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
|
|
|
|
|
1998-10-02 00:22:28 +08:00
|
|
|
/* Redraw on idle time */
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_flush_whenever (gdisp, FALSE);
|
1998-10-02 00:22:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-11 07:03:22 +08:00
|
|
|
gimp_display_flush_now (GimpDisplay *gdisp)
|
1998-10-02 00:22:28 +08:00
|
|
|
{
|
2001-09-26 01:44:03 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
|
|
|
|
|
1998-10-02 00:22:28 +08:00
|
|
|
/* Redraw NOW */
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_flush_whenever (gdisp, TRUE);
|
1998-10-02 00:22:28 +08:00
|
|
|
}
|
|
|
|
|
1999-01-18 06:50:14 +08:00
|
|
|
/* Force all gdisplays to finish their idlerender projection */
|
2001-02-20 23:15:30 +08:00
|
|
|
void
|
2001-11-11 07:03:22 +08:00
|
|
|
gimp_display_finish_draw (GimpDisplay *gdisp)
|
2001-02-20 23:15:30 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
|
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
if (gdisp->idle_render.idle_id)
|
|
|
|
{
|
|
|
|
g_source_remove (gdisp->idle_render.idle_id);
|
|
|
|
gdisp->idle_render.idle_id = 0;
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
while (gimp_display_idlerender_callback (gdisp));
|
|
|
|
}
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2002-10-14 21:39:35 +08:00
|
|
|
/* utility function to check if the cursor is inside the active drawable */
|
|
|
|
gboolean
|
|
|
|
gimp_display_coords_in_active_drawable (GimpDisplay *gdisp,
|
|
|
|
const GimpCoords *coords)
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (gdisp), FALSE);
|
|
|
|
|
|
|
|
if (!gdisp->gimage)
|
|
|
|
return FALSE;
|
|
|
|
|
2003-05-08 22:06:03 +08:00
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2003-05-08 22:06:03 +08:00
|
|
|
if (drawable)
|
|
|
|
{
|
|
|
|
GimpItem *item;
|
|
|
|
gint x, y;
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2003-05-08 22:06:03 +08:00
|
|
|
item = GIMP_ITEM (drawable);
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2003-05-08 22:06:03 +08:00
|
|
|
gimp_item_offsets (item, &x, &y);
|
|
|
|
|
|
|
|
x = ROUND (coords->x) - x;
|
|
|
|
y = ROUND (coords->y) - y;
|
|
|
|
|
|
|
|
if (x < 0 || x > gimp_item_width (item))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (y < 0 || y > gimp_item_height (item))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2003-05-08 22:06:03 +08:00
|
|
|
return FALSE;
|
2002-10-14 21:39:35 +08:00
|
|
|
}
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2003-10-08 22:50:26 +08:00
|
|
|
gimp_display_flush_whenever (GimpDisplay *gdisp,
|
2001-11-11 07:03:22 +08:00
|
|
|
gboolean now)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
2002-06-27 06:16:59 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
/* Flush the items in the displays and updates lists -
|
|
|
|
* but only if gdisplay has been mapped and exposed
|
|
|
|
*/
|
2002-06-27 06:16:59 +08:00
|
|
|
if (! shell->select)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
|
|
|
g_warning ("gimp_display_flush_whenever(): called unrealized");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First the updates... */
|
2003-07-30 00:36:56 +08:00
|
|
|
if (gdisp->update_areas)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2003-07-30 00:36:56 +08:00
|
|
|
if (now)
|
|
|
|
{
|
|
|
|
/* Synchronous */
|
|
|
|
|
|
|
|
GSList *list;
|
|
|
|
GimpArea *area;
|
|
|
|
|
|
|
|
for (list = gdisp->update_areas; list; list = g_slist_next (list))
|
|
|
|
{
|
|
|
|
/* Paint the area specified by the GimpArea */
|
|
|
|
area = (GimpArea *) list->data;
|
|
|
|
|
|
|
|
if ((area->x1 != area->x2) && (area->y1 != area->y2))
|
|
|
|
{
|
|
|
|
gimp_display_paint_area (gdisp,
|
|
|
|
area->x1,
|
|
|
|
area->y1,
|
|
|
|
(area->x2 - area->x1),
|
|
|
|
(area->y2 - area->y1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Asynchronous */
|
|
|
|
|
|
|
|
gimp_display_idlerender_init (gdisp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the update lists */
|
|
|
|
gdisp->update_areas = gimp_display_area_list_free (gdisp->update_areas);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
else
|
|
|
|
{
|
2003-07-30 00:36:56 +08:00
|
|
|
/* if there was nothing to update, we still need to start the
|
|
|
|
* selection --mitch
|
|
|
|
*/
|
|
|
|
gimp_display_shell_selection_visibility (shell, GIMP_SELECTION_ON);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Next the displays... */
|
2003-10-08 22:50:26 +08:00
|
|
|
gimp_display_shell_flush (shell, now);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2002-12-14 22:13:54 +08:00
|
|
|
/* ensure the consistency of the menus */
|
|
|
|
if (! now)
|
2003-01-11 01:55:53 +08:00
|
|
|
{
|
2003-11-11 21:09:50 +08:00
|
|
|
GimpContext *user_context;
|
2003-01-11 01:55:53 +08:00
|
|
|
|
2004-04-22 00:33:17 +08:00
|
|
|
gimp_ui_manager_update (shell->menubar_manager, shell);
|
2003-01-11 01:55:53 +08:00
|
|
|
|
2003-11-11 21:09:50 +08:00
|
|
|
user_context = gimp_get_user_context (gdisp->gimage->gimp);
|
2003-01-11 01:55:53 +08:00
|
|
|
|
2003-11-11 21:09:50 +08:00
|
|
|
if (gdisp == gimp_context_get_display (user_context))
|
2004-04-29 20:52:29 +08:00
|
|
|
gimp_ui_manager_update (shell->popup_manager, shell);
|
2003-01-11 01:55:53 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_display_idlerender_init (GimpDisplay *gdisp)
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
GSList *list;
|
|
|
|
GimpArea *area;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
/* We need to merge the IdleRender's and the GimpDisplay's update_areas list
|
|
|
|
* to keep track of which of the updates have been flushed and hence need
|
2003-10-08 22:50:26 +08:00
|
|
|
* to be drawn.
|
2001-11-11 07:03:22 +08:00
|
|
|
*/
|
2001-11-16 23:08:59 +08:00
|
|
|
for (list = gdisp->update_areas; list; list = g_slist_next (list))
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
area = g_memdup (list->data, sizeof (GimpArea));
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
gdisp->idle_render.update_areas =
|
2004-06-02 06:04:20 +08:00
|
|
|
gimp_display_area_list_process (gdisp->idle_render.update_areas, area);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If an idlerender was already running, merge the remainder of its
|
|
|
|
* unrendered area with the update_areas list, and make it start work
|
|
|
|
* on the next unrendered area in the list.
|
|
|
|
*/
|
|
|
|
if (gdisp->idle_render.idle_id)
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
area =
|
2001-11-16 23:08:59 +08:00
|
|
|
gimp_area_new (gdisp->idle_render.basex,
|
|
|
|
gdisp->idle_render.y,
|
|
|
|
gdisp->idle_render.basex + gdisp->idle_render.width,
|
|
|
|
gdisp->idle_render.y + (gdisp->idle_render.height -
|
|
|
|
(gdisp->idle_render.y -
|
|
|
|
gdisp->idle_render.basey)));
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
gdisp->idle_render.update_areas =
|
2004-06-02 06:04:20 +08:00
|
|
|
gimp_display_area_list_process (gdisp->idle_render.update_areas, area);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
gimp_display_idle_render_next_area (gdisp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gdisp->idle_render.update_areas == NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Wanted to start idlerender thread with no update_areas. (+memleak)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_display_idle_render_next_area (gdisp);
|
|
|
|
|
|
|
|
gdisp->idle_render.idle_id = g_idle_add_full (G_PRIORITY_LOW,
|
|
|
|
gimp_display_idlerender_callback,
|
|
|
|
gdisp,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Caller frees gdisp->update_areas */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unless specified otherwise, display re-rendering is organised by
|
|
|
|
* IdleRender, which amalgamates areas to be re-rendered and breaks
|
|
|
|
* them into bite-sized chunks which are chewed on in a low- priority
|
|
|
|
* idle thread. This greatly improves responsiveness for many GIMP
|
|
|
|
* operations. -- Adam
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
gimp_display_idlerender_callback (gpointer data)
|
|
|
|
{
|
|
|
|
const gint CHUNK_WIDTH = 256;
|
|
|
|
const gint CHUNK_HEIGHT = 128;
|
|
|
|
gint workx, worky, workw, workh;
|
|
|
|
GimpDisplay *gdisp = data;
|
|
|
|
|
|
|
|
workw = CHUNK_WIDTH;
|
|
|
|
workh = CHUNK_HEIGHT;
|
|
|
|
workx = gdisp->idle_render.x;
|
|
|
|
worky = gdisp->idle_render.y;
|
|
|
|
|
|
|
|
if (workx + workw > gdisp->idle_render.basex + gdisp->idle_render.width)
|
|
|
|
{
|
|
|
|
workw = gdisp->idle_render.basex + gdisp->idle_render.width - workx;
|
|
|
|
}
|
|
|
|
|
2001-11-16 23:08:59 +08:00
|
|
|
if (worky + workh > gdisp->idle_render.basey + gdisp->idle_render.height)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
|
|
|
workh = gdisp->idle_render.basey + gdisp->idle_render.height - worky;
|
2003-10-08 22:50:26 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
gimp_display_paint_area (gdisp, workx, worky, workw, workh);
|
|
|
|
|
|
|
|
gdisp->idle_render.x += CHUNK_WIDTH;
|
|
|
|
|
|
|
|
if (gdisp->idle_render.x >=
|
|
|
|
gdisp->idle_render.basex + gdisp->idle_render.width)
|
|
|
|
{
|
|
|
|
gdisp->idle_render.x = gdisp->idle_render.basex;
|
|
|
|
gdisp->idle_render.y += CHUNK_HEIGHT;
|
|
|
|
|
|
|
|
if (gdisp->idle_render.y >=
|
|
|
|
gdisp->idle_render.basey + gdisp->idle_render.height)
|
|
|
|
{
|
|
|
|
if (! gimp_display_idle_render_next_area (gdisp))
|
|
|
|
{
|
|
|
|
/* FINISHED */
|
|
|
|
gdisp->idle_render.idle_id = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Still work to do. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_display_idle_render_next_area (GimpDisplay *gdisp)
|
|
|
|
{
|
2001-11-16 23:08:59 +08:00
|
|
|
GimpArea *area;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2001-11-16 23:08:59 +08:00
|
|
|
if (! gdisp->idle_render.update_areas)
|
|
|
|
return FALSE;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2001-11-16 23:08:59 +08:00
|
|
|
area = (GimpArea *) gdisp->idle_render.update_areas->data;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
gdisp->idle_render.update_areas =
|
2001-11-16 23:08:59 +08:00
|
|
|
g_slist_remove (gdisp->idle_render.update_areas, area);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2001-11-16 23:08:59 +08:00
|
|
|
gdisp->idle_render.x = gdisp->idle_render.basex = area->x1;
|
|
|
|
gdisp->idle_render.y = gdisp->idle_render.basey = area->y1;
|
|
|
|
gdisp->idle_render.width = area->x2 - area->x1;
|
|
|
|
gdisp->idle_render.height = area->y2 - area->y1;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2001-11-16 23:08:59 +08:00
|
|
|
g_free (area);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_display_paint_area (GimpDisplay *gdisp,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
2001-11-11 07:03:22 +08:00
|
|
|
gint x1, y1, x2, y2;
|
2003-11-21 02:08:01 +08:00
|
|
|
gdouble x1_f, y1_f, x2_f, y2_f;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
/* Bounds check */
|
|
|
|
x1 = CLAMP (x, 0, gdisp->gimage->width);
|
|
|
|
y1 = CLAMP (y, 0, gdisp->gimage->height);
|
|
|
|
x2 = CLAMP (x + w, 0, gdisp->gimage->width);
|
|
|
|
y2 = CLAMP (y + h, 0, gdisp->gimage->height);
|
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
w = (x2 - x1);
|
|
|
|
h = (y2 - y1);
|
|
|
|
|
|
|
|
/* calculate the extents of the update as limited by what's visible */
|
2004-01-12 19:11:27 +08:00
|
|
|
gimp_display_shell_untransform_xy_f (shell,
|
|
|
|
0, 0,
|
|
|
|
&x1_f, &y1_f,
|
|
|
|
FALSE);
|
|
|
|
gimp_display_shell_untransform_xy_f (shell,
|
|
|
|
shell->disp_width, shell->disp_height,
|
|
|
|
&x2_f, &y2_f,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
/* make sure to limit the invalidated area to a superset of the
|
|
|
|
* untransformed sub-pixel display area, not a subset.
|
|
|
|
* bug #116765. --mitch
|
|
|
|
*/
|
|
|
|
x1 = floor (x1_f);
|
|
|
|
y1 = floor (y1_f);
|
|
|
|
x2 = ceil (x2_f);
|
|
|
|
y2 = ceil (y2_f);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
gimp_image_invalidate (gdisp->gimage, x, y, w, h, x1, y1, x2, y2);
|
|
|
|
|
|
|
|
/* display the area */
|
2003-11-21 02:08:01 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell, x, y, &x1_f, &y1_f, FALSE);
|
|
|
|
gimp_display_shell_transform_xy_f (shell, x + w, y + h, &x2_f, &y2_f, FALSE);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2003-11-21 02:08:01 +08:00
|
|
|
/* make sure to expose a superset of the transformed sub-pixel expose
|
|
|
|
* area, not a subset. bug #126942. --mitch
|
|
|
|
*/
|
|
|
|
x1 = floor (x1_f);
|
|
|
|
y1 = floor (y1_f);
|
|
|
|
x2 = ceil (x2_f);
|
|
|
|
y2 = ceil (y2_f);
|
|
|
|
|
|
|
|
gimp_display_shell_expose_area (shell, x1, y1, x2 - x1, y2 - y1);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|