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
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "gdk/gdkkeysyms.h"
|
|
|
|
#include "appenv.h"
|
1999-08-23 22:19:26 +08:00
|
|
|
#include "bucket_fill.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "colormaps.h"
|
|
|
|
#include "cursorutil.h"
|
1998-06-06 11:49:01 +08:00
|
|
|
#include "devices.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "disp_callbacks.h"
|
|
|
|
#include "gdisplay.h"
|
|
|
|
#include "general.h"
|
1999-06-20 21:53:15 +08:00
|
|
|
#include "gimpcontext.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gimprc.h"
|
1999-08-13 06:21:04 +08:00
|
|
|
#include "info_window.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "interface.h"
|
|
|
|
#include "layer_select.h"
|
|
|
|
#include "move.h"
|
|
|
|
#include "scale.h"
|
|
|
|
#include "scroll.h"
|
|
|
|
#include "tools.h"
|
1999-08-20 03:53:30 +08:00
|
|
|
#include "undo.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gimage.h"
|
1999-01-11 07:20:33 +08:00
|
|
|
#include "dialog_handler.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-20 03:53:30 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1998-06-06 11:49:01 +08:00
|
|
|
/* Function declarations */
|
|
|
|
|
|
|
|
static void gdisplay_check_device_cursor (GDisplay *gdisp);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
|
|
|
redraw (GDisplay *gdisp,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h)
|
|
|
|
{
|
|
|
|
long x1, y1, x2, y2; /* coordinate of rectangle corners */
|
|
|
|
|
|
|
|
x1 = x;
|
|
|
|
y1 = y;
|
|
|
|
x2 = (x+w);
|
|
|
|
y2 = (y+h);
|
|
|
|
x1 = BOUNDS (x1, 0, gdisp->disp_width);
|
|
|
|
y1 = BOUNDS (y1, 0, gdisp->disp_height);
|
|
|
|
x2 = BOUNDS (x2, 0, gdisp->disp_width);
|
|
|
|
y2 = BOUNDS (y2, 0, gdisp->disp_height);
|
|
|
|
if ((x2 - x1) && (y2 - y1))
|
|
|
|
{
|
|
|
|
gdisplay_expose_area (gdisp, x1, y1, (x2 - x1), (y2 - y1));
|
1999-03-21 06:05:24 +08:00
|
|
|
gdisplay_flush_displays_only (gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-06 11:49:01 +08:00
|
|
|
static void
|
|
|
|
gdisplay_check_device_cursor (GDisplay *gdisp)
|
|
|
|
{
|
|
|
|
GList *tmp_list;
|
|
|
|
|
|
|
|
/* gdk_input_list_devices returns an internal list, so we shouldn't
|
|
|
|
free it afterwards */
|
|
|
|
tmp_list = gdk_input_list_devices();
|
|
|
|
|
|
|
|
while (tmp_list)
|
|
|
|
{
|
|
|
|
GdkDeviceInfo *info = (GdkDeviceInfo *)tmp_list->data;
|
|
|
|
|
|
|
|
if (info->deviceid == current_device)
|
|
|
|
{
|
|
|
|
gdisp->draw_cursor = !info->has_cursor;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_list = tmp_list->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-05 17:10:35 +08:00
|
|
|
static int
|
1999-06-04 02:28:39 +08:00
|
|
|
key_to_state (int key)
|
1999-05-05 17:10:35 +08:00
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case GDK_Alt_L: case GDK_Alt_R:
|
|
|
|
return GDK_MOD1_MASK;
|
|
|
|
case GDK_Shift_L: case GDK_Shift_R:
|
|
|
|
return GDK_SHIFT_MASK;
|
|
|
|
case GDK_Control_L: case GDK_Control_R:
|
|
|
|
return GDK_CONTROL_MASK;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-04 02:28:39 +08:00
|
|
|
gint
|
1999-08-20 03:53:30 +08:00
|
|
|
gdisplay_shell_events (GtkWidget *widget,
|
1999-06-04 02:28:39 +08:00
|
|
|
GdkEvent *event,
|
|
|
|
GDisplay *gdisp)
|
|
|
|
{
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
case GDK_KEY_PRESS:
|
1999-06-20 21:53:15 +08:00
|
|
|
/* Setting the context's display automatically sets the image, too */
|
|
|
|
gimp_context_set_display (gimp_context_get_user (), gdisp);
|
1999-06-04 02:28:39 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1999-06-20 21:53:15 +08:00
|
|
|
}
|
|
|
|
|
1999-06-04 02:28:39 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gint
|
|
|
|
gdisplay_canvas_events (GtkWidget *canvas,
|
|
|
|
GdkEvent *event)
|
|
|
|
{
|
1998-04-30 13:30:28 +08:00
|
|
|
GDisplay *gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
GdkEventExpose *eevent;
|
|
|
|
GdkEventMotion *mevent;
|
|
|
|
GdkEventButton *bevent;
|
|
|
|
GdkEventKey *kevent;
|
1998-06-06 11:49:01 +08:00
|
|
|
gdouble tx, ty;
|
1997-11-25 06:05:25 +08:00
|
|
|
guint state = 0;
|
|
|
|
gint return_val = FALSE;
|
1998-04-15 17:15:40 +08:00
|
|
|
static gboolean scrolled = FALSE;
|
|
|
|
static guint key_signal_id = 0;
|
1998-12-13 01:41:41 +08:00
|
|
|
int update_cursor = FALSE;
|
1998-07-16 11:23:14 +08:00
|
|
|
|
|
|
|
tx = ty = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisp = (GDisplay *) gtk_object_get_user_data (GTK_OBJECT (canvas));
|
|
|
|
|
1998-02-05 08:07:31 +08:00
|
|
|
if (!canvas->window)
|
|
|
|
return FALSE;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* If this is the first event... */
|
|
|
|
if (!gdisp->select)
|
|
|
|
{
|
|
|
|
/* create the selection object */
|
|
|
|
gdisp->select = selection_create (gdisp->canvas->window, gdisp,
|
|
|
|
gdisp->gimage->height,
|
|
|
|
gdisp->gimage->width, marching_speed);
|
|
|
|
|
|
|
|
gdisp->disp_width = gdisp->canvas->allocation.width;
|
|
|
|
gdisp->disp_height = gdisp->canvas->allocation.height;
|
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
/* create GC for scrolling */
|
1997-12-18 14:30:11 +08:00
|
|
|
gdisp->scroll_gc = gdk_gc_new (gdisp->canvas->window);
|
|
|
|
gdk_gc_set_exposures (gdisp->scroll_gc, TRUE);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* set up the scrollbar observers */
|
|
|
|
gtk_signal_connect (GTK_OBJECT (gdisp->hsbdata), "value_changed",
|
|
|
|
(GtkSignalFunc) scrollbar_horz_update,
|
|
|
|
gdisp);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (gdisp->vsbdata), "value_changed",
|
|
|
|
(GtkSignalFunc) scrollbar_vert_update,
|
|
|
|
gdisp);
|
|
|
|
|
|
|
|
/* setup scale properly */
|
|
|
|
setup_scale (gdisp);
|
|
|
|
}
|
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
/* Find out what device the event occurred upon */
|
1998-06-06 11:49:01 +08:00
|
|
|
if (devices_check_change (event))
|
|
|
|
gdisplay_check_device_cursor (gdisp);
|
1999-06-22 06:12:07 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_EXPOSE:
|
|
|
|
eevent = (GdkEventExpose *) event;
|
1998-10-04 04:14:00 +08:00
|
|
|
/*printf(" EXP:%d,%d(%dx%d) ",eevent->area.x, eevent->area.y,
|
|
|
|
eevent->area.width, eevent->area.height);fflush(stdout);*/
|
1997-11-25 06:05:25 +08:00
|
|
|
redraw (gdisp, eevent->area.x, eevent->area.y,
|
|
|
|
eevent->area.width, eevent->area.height);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_CONFIGURE:
|
1998-10-04 04:14:00 +08:00
|
|
|
/*printf(" CNF ");fflush(stdout);*/
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((gdisp->disp_width != gdisp->canvas->allocation.width) ||
|
|
|
|
(gdisp->disp_height != gdisp->canvas->allocation.height))
|
|
|
|
{
|
|
|
|
gdisp->disp_width = gdisp->canvas->allocation.width;
|
|
|
|
gdisp->disp_height = gdisp->canvas->allocation.height;
|
|
|
|
resize_display (gdisp, 0, FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-06-06 11:49:01 +08:00
|
|
|
case GDK_LEAVE_NOTIFY:
|
|
|
|
gdisplay_update_cursor (gdisp, 0, 0);
|
1999-01-11 05:54:02 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (gdisp->cursor_label), "");
|
1999-08-13 06:21:04 +08:00
|
|
|
info_window_update_RGB(gdisp->window_info_dialog,
|
|
|
|
gdisp,
|
|
|
|
-1,
|
|
|
|
-1);
|
1999-06-26 19:16:47 +08:00
|
|
|
|
1998-08-01 02:34:05 +08:00
|
|
|
case GDK_PROXIMITY_OUT:
|
|
|
|
gdisp->proximity = FALSE;
|
1998-06-06 11:49:01 +08:00
|
|
|
break;
|
|
|
|
|
1998-07-16 11:23:14 +08:00
|
|
|
case GDK_ENTER_NOTIFY:
|
1998-12-13 01:41:41 +08:00
|
|
|
/* Actually, should figure out tx,ty here */
|
1998-06-06 11:49:01 +08:00
|
|
|
break;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
state = bevent->state;
|
|
|
|
|
|
|
|
switch (bevent->button)
|
|
|
|
{
|
|
|
|
case 1:
|
1999-05-05 17:10:35 +08:00
|
|
|
state |= GDK_BUTTON1_MASK;
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_grab_add (canvas);
|
1998-04-20 15:03:04 +08:00
|
|
|
|
|
|
|
/* This is a hack to prevent other stuff being run in the middle of
|
|
|
|
a tool operation (like changing image types.... brrrr). We just
|
|
|
|
block all the keypress event. A better solution is to implement
|
|
|
|
some sort of locking for images.
|
|
|
|
Note that this is dependent on specific GTK behavior, and isn't
|
|
|
|
guaranteed to work in future versions of GTK.
|
|
|
|
-Yosh
|
|
|
|
*/
|
|
|
|
if (key_signal_id == 0)
|
|
|
|
key_signal_id = gtk_signal_connect (GTK_OBJECT (canvas),
|
|
|
|
"key_press_event",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_true),
|
|
|
|
NULL);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (active_tool && ((active_tool->type == MOVE) ||
|
|
|
|
!gimage_is_empty (gdisp->gimage)))
|
1999-06-22 06:12:07 +08:00
|
|
|
{
|
|
|
|
if (active_tool->auto_snap_to)
|
|
|
|
{
|
|
|
|
gdisplay_snap_point (gdisp, bevent->x, bevent->y, &tx, &ty);
|
|
|
|
bevent->x = tx;
|
|
|
|
bevent->y = ty;
|
|
|
|
update_cursor = TRUE;
|
|
|
|
}
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
/* reset the current tool if ... */
|
|
|
|
if ((/* it has no drawable */
|
|
|
|
! active_tool->drawable ||
|
1999-06-22 06:12:07 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
/* or a drawable different from the current one */
|
|
|
|
(gimage_active_drawable (gdisp->gimage) !=
|
|
|
|
active_tool->drawable)) &&
|
1999-06-22 06:12:07 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
/* and doesn't want to be preserved across drawable changes */
|
|
|
|
! active_tool->preserve)
|
1999-06-22 06:12:07 +08:00
|
|
|
{
|
|
|
|
tools_initialize (active_tool->type, gdisp);
|
|
|
|
}
|
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
/* otherwise set it's drawable if it has none */
|
|
|
|
else if (! active_tool->drawable)
|
|
|
|
{
|
|
|
|
active_tool->drawable = gimage_active_drawable (gdisp->gimage);
|
|
|
|
}
|
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
(* active_tool->button_press_func) (active_tool, bevent, gdisp);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
1999-05-05 17:10:35 +08:00
|
|
|
state |= GDK_BUTTON2_MASK;
|
1998-04-15 17:15:40 +08:00
|
|
|
scrolled = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_grab_add (canvas);
|
|
|
|
start_grab_and_scroll (gdisp, bevent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
1999-05-05 17:10:35 +08:00
|
|
|
state |= GDK_BUTTON3_MASK;
|
1999-06-21 07:29:34 +08:00
|
|
|
gtk_menu_popup (GTK_MENU (gdisp->popup),
|
|
|
|
NULL, NULL, NULL, NULL, 3, bevent->time);
|
1999-06-26 19:16:47 +08:00
|
|
|
return_val = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
1999-07-10 07:03:11 +08:00
|
|
|
/* wheelmouse support */
|
|
|
|
case 4:
|
|
|
|
state |= GDK_BUTTON4_MASK;
|
1999-08-20 03:53:30 +08:00
|
|
|
if (state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
change_scale (gdisp, ZOOMIN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj =
|
|
|
|
(state & GDK_CONTROL_MASK) ? gdisp->hsbdata : gdisp->vsbdata;
|
|
|
|
gfloat new_value = adj->value - adj->page_increment / 2;
|
|
|
|
new_value =
|
|
|
|
CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
|
|
|
|
gtk_adjustment_set_value (adj, new_value);
|
|
|
|
}
|
1999-07-10 07:03:11 +08:00
|
|
|
return_val = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
state |= GDK_BUTTON5_MASK;
|
1999-08-20 03:53:30 +08:00
|
|
|
if (state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
change_scale (gdisp, ZOOMOUT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj =
|
|
|
|
(state & GDK_CONTROL_MASK) ? gdisp->hsbdata : gdisp->vsbdata;
|
|
|
|
gfloat new_value = adj->value + adj->page_increment / 2;
|
|
|
|
new_value = CLAMP (new_value,
|
|
|
|
adj->lower, adj->upper - adj->page_size);
|
|
|
|
gtk_adjustment_set_value (adj, new_value);
|
|
|
|
}
|
1999-07-10 07:03:11 +08:00
|
|
|
return_val = TRUE;
|
|
|
|
break;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_BUTTON_RELEASE:
|
|
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
state = bevent->state;
|
|
|
|
|
|
|
|
switch (bevent->button)
|
|
|
|
{
|
|
|
|
case 1:
|
1999-05-05 17:10:35 +08:00
|
|
|
state &= ~GDK_BUTTON1_MASK;
|
|
|
|
|
1998-04-20 15:03:04 +08:00
|
|
|
/* Lame hack. See above */
|
|
|
|
if (key_signal_id)
|
|
|
|
{
|
|
|
|
gtk_signal_disconnect (GTK_OBJECT (canvas), key_signal_id);
|
|
|
|
key_signal_id = 0;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_grab_remove (canvas);
|
1998-04-03 17:13:07 +08:00
|
|
|
gdk_pointer_ungrab (bevent->time); /* fixes pointer grab bug */
|
1997-11-25 06:05:25 +08:00
|
|
|
if (active_tool && ((active_tool->type == MOVE) ||
|
|
|
|
!gimage_is_empty (gdisp->gimage)))
|
1999-03-21 23:38:11 +08:00
|
|
|
{
|
|
|
|
if (active_tool->state == ACTIVE)
|
|
|
|
{
|
|
|
|
if (active_tool->auto_snap_to)
|
|
|
|
{
|
|
|
|
gdisplay_snap_point (gdisp, bevent->x, bevent->y, &tx, &ty);
|
|
|
|
bevent->x = tx;
|
|
|
|
bevent->y = ty;
|
|
|
|
update_cursor = TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-05 17:10:35 +08:00
|
|
|
(* active_tool->button_release_func) (active_tool, bevent,
|
|
|
|
gdisp);
|
1999-03-21 23:38:11 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
1999-05-05 17:10:35 +08:00
|
|
|
state &= ~GDK_BUTTON2_MASK;
|
1998-04-15 17:15:40 +08:00
|
|
|
scrolled = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_grab_remove (canvas);
|
|
|
|
end_grab_and_scroll (gdisp, bevent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
1999-05-05 17:10:35 +08:00
|
|
|
state &= ~GDK_BUTTON3_MASK;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
1999-07-10 07:03:11 +08:00
|
|
|
/* wheelmouse support */
|
|
|
|
case 4:
|
|
|
|
state &= ~GDK_BUTTON4_MASK;
|
|
|
|
return_val = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
state &= ~GDK_BUTTON5_MASK;
|
|
|
|
return_val = TRUE;
|
|
|
|
break;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_MOTION_NOTIFY:
|
|
|
|
mevent = (GdkEventMotion *) event;
|
|
|
|
state = mevent->state;
|
|
|
|
|
1998-06-06 11:49:01 +08:00
|
|
|
/* Ask for the pointer position, but ignore it except for cursor
|
|
|
|
* handling, so motion events sync with the button press/release events */
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (mevent->is_hint)
|
1998-06-06 11:49:01 +08:00
|
|
|
gdk_input_window_get_pointer (canvas->window, current_device, &tx, &ty,
|
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
else
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-06-06 11:49:01 +08:00
|
|
|
tx = mevent->x;
|
|
|
|
ty = mevent->y;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-12-13 01:41:41 +08:00
|
|
|
update_cursor = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-06 11:49:01 +08:00
|
|
|
if (!gdisp->proximity)
|
|
|
|
{
|
|
|
|
gdisp->proximity = TRUE;
|
|
|
|
gdisplay_check_device_cursor (gdisp);
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (active_tool && ((active_tool->type == MOVE) ||
|
|
|
|
!gimage_is_empty (gdisp->gimage)) &&
|
|
|
|
(mevent->state & GDK_BUTTON1_MASK))
|
|
|
|
{
|
|
|
|
if (active_tool->state == ACTIVE)
|
|
|
|
{
|
|
|
|
/* if the first mouse button is down, check for automatic
|
|
|
|
* scrolling...
|
|
|
|
*/
|
1999-02-21 07:20:54 +08:00
|
|
|
if ((mevent->state & GDK_BUTTON1_MASK) && !active_tool->scroll_lock)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (mevent->x < 0 || mevent->y < 0 ||
|
|
|
|
mevent->x > gdisp->disp_width ||
|
|
|
|
mevent->y > gdisp->disp_height)
|
|
|
|
scroll_to_pointer_position (gdisp, mevent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active_tool->auto_snap_to)
|
|
|
|
{
|
|
|
|
gdisplay_snap_point (gdisp, mevent->x, mevent->y, &tx, &ty);
|
|
|
|
mevent->x = tx;
|
|
|
|
mevent->y = ty;
|
1998-12-13 01:41:41 +08:00
|
|
|
update_cursor = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
(* active_tool->motion_func) (active_tool, mevent, gdisp);
|
|
|
|
}
|
|
|
|
}
|
1998-04-09 13:05:05 +08:00
|
|
|
else if ((mevent->state & GDK_BUTTON2_MASK) && scrolled)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
grab_and_scroll (gdisp, mevent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_KEY_PRESS:
|
|
|
|
kevent = (GdkEventKey *) event;
|
|
|
|
state = kevent->state;
|
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_Left: case GDK_Right:
|
|
|
|
case GDK_Up: case GDK_Down:
|
|
|
|
if (active_tool && !gimage_is_empty (gdisp->gimage))
|
|
|
|
(* active_tool->arrow_keys_func) (active_tool, kevent, gdisp);
|
|
|
|
return_val = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Tab:
|
|
|
|
if (kevent->state & GDK_MOD1_MASK && !gimage_is_empty (gdisp->gimage))
|
|
|
|
layer_select_init (gdisp->gimage, 1, kevent->time);
|
|
|
|
if (kevent->state & GDK_CONTROL_MASK && !gimage_is_empty (gdisp->gimage))
|
|
|
|
layer_select_init (gdisp->gimage, -1, kevent->time);
|
1999-01-11 07:20:33 +08:00
|
|
|
|
|
|
|
/* Hide or show all dialogs */
|
|
|
|
if (!kevent->state)
|
|
|
|
dialog_toggle();
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return_val = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Update the state based on modifiers being pressed */
|
|
|
|
case GDK_Alt_L: case GDK_Alt_R:
|
|
|
|
case GDK_Shift_L: case GDK_Shift_R:
|
1999-04-28 05:06:00 +08:00
|
|
|
case GDK_Control_L: case GDK_Control_R:
|
1999-05-05 17:10:35 +08:00
|
|
|
state |= key_to_state(kevent->keyval);
|
1999-04-28 05:06:00 +08:00
|
|
|
/* For all modifier keys: call the tools modifier_key_func */
|
1999-04-27 10:09:03 +08:00
|
|
|
if (active_tool && !gimage_is_empty (gdisp->gimage))
|
|
|
|
{
|
|
|
|
gdk_input_window_get_pointer (canvas->window, current_device,
|
1999-06-18 04:34:50 +08:00
|
|
|
&tx, &ty, NULL, NULL, NULL, NULL);
|
|
|
|
(* active_tool->modifier_key_func) (active_tool, kevent, gdisp);
|
1999-04-27 10:09:03 +08:00
|
|
|
return_val = TRUE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_KEY_RELEASE:
|
|
|
|
kevent = (GdkEventKey *) event;
|
|
|
|
state = kevent->state;
|
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_Alt_L: case GDK_Alt_R:
|
|
|
|
case GDK_Shift_L: case GDK_Shift_R:
|
1999-04-28 05:06:00 +08:00
|
|
|
case GDK_Control_L: case GDK_Control_R:
|
1999-05-05 17:10:35 +08:00
|
|
|
state &= ~key_to_state(kevent->keyval);
|
1999-04-28 05:06:00 +08:00
|
|
|
/* For all modifier keys: call the tools modifier_key_func */
|
1999-04-27 10:09:03 +08:00
|
|
|
if (active_tool && !gimage_is_empty (gdisp->gimage))
|
|
|
|
{
|
|
|
|
gdk_input_window_get_pointer (canvas->window, current_device,
|
|
|
|
&tx, &ty, NULL, NULL, NULL, NULL);
|
1999-06-18 04:34:50 +08:00
|
|
|
(* active_tool->modifier_key_func) (active_tool, kevent, gdisp);
|
1999-04-27 10:09:03 +08:00
|
|
|
return_val = TRUE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return_val = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no_cursor_updating == 0)
|
|
|
|
{
|
|
|
|
if (active_tool && !gimage_is_empty (gdisp->gimage) &&
|
|
|
|
!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)))
|
|
|
|
{
|
|
|
|
GdkEventMotion me;
|
|
|
|
me.x = tx; me.y = ty;
|
|
|
|
me.state = state;
|
|
|
|
(* active_tool->cursor_update_func) (active_tool, &me, gdisp);
|
|
|
|
}
|
|
|
|
else if (gimage_is_empty (gdisp->gimage))
|
|
|
|
gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW);
|
|
|
|
}
|
|
|
|
|
1998-07-16 11:23:14 +08:00
|
|
|
if (update_cursor)
|
|
|
|
gdisplay_update_cursor (gdisp, tx, ty);
|
1998-06-06 11:49:01 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gdisplay_hruler_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GDisplay *gdisp;
|
|
|
|
|
|
|
|
if (event->button == 1)
|
|
|
|
{
|
|
|
|
gdisp = data;
|
1998-03-13 11:35:33 +08:00
|
|
|
|
1998-06-22 04:17:21 +08:00
|
|
|
gtk_widget_activate (tool_info[(int) MOVE].tool_widget);
|
1997-11-25 06:05:25 +08:00
|
|
|
move_tool_start_hguide (active_tool, gdisp);
|
|
|
|
gtk_grab_add (gdisp->canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gdisplay_vruler_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GDisplay *gdisp;
|
|
|
|
|
|
|
|
if (event->button == 1)
|
|
|
|
{
|
|
|
|
gdisp = data;
|
1998-03-13 11:35:33 +08:00
|
|
|
|
1998-06-22 04:17:21 +08:00
|
|
|
gtk_widget_activate (tool_info[(int) MOVE].tool_widget);
|
1997-11-25 06:05:25 +08:00
|
|
|
move_tool_start_vguide (active_tool, gdisp);
|
|
|
|
gtk_grab_add (gdisp->canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
1998-06-09 17:20:46 +08:00
|
|
|
|
|
|
|
gint
|
|
|
|
gdisplay_origin_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GDisplay *gdisp;
|
|
|
|
|
|
|
|
if (event->button == 1)
|
|
|
|
{
|
|
|
|
gdisp = data;
|
1999-06-04 02:28:39 +08:00
|
|
|
gtk_menu_popup (GTK_MENU (gdisp->popup),
|
|
|
|
NULL, NULL, NULL, NULL, 1, event->time);
|
1998-06-09 17:20:46 +08:00
|
|
|
}
|
|
|
|
|
1999-06-04 02:28:39 +08:00
|
|
|
/* Stop the signal emission so the button doesn't grab the
|
|
|
|
* pointer away from us */
|
|
|
|
gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "button_press_event");
|
|
|
|
|
1998-06-09 17:20:46 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-08-20 03:53:30 +08:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdisplay_drag_drop (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guint time,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GDisplay *gdisp;
|
|
|
|
GtkWidget *src_widget;
|
|
|
|
gboolean return_val = FALSE;
|
|
|
|
|
|
|
|
gdisp = (GDisplay *) data;
|
|
|
|
|
|
|
|
if ((src_widget = gtk_drag_get_source_widget (context)))
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
GimpDrawable *drawable = NULL;
|
|
|
|
Layer *layer = NULL;
|
|
|
|
Channel *channel = NULL;
|
|
|
|
LayerMask *layer_mask = NULL;
|
|
|
|
GImage *component = NULL;
|
|
|
|
ChannelType component_type = -1;
|
1999-08-20 03:53:30 +08:00
|
|
|
|
|
|
|
layer = (Layer *) gtk_object_get_data (GTK_OBJECT (src_widget),
|
|
|
|
"gimp_layer");
|
|
|
|
channel = (Channel *) gtk_object_get_data (GTK_OBJECT (src_widget),
|
|
|
|
"gimp_channel");
|
1999-08-22 19:45:31 +08:00
|
|
|
layer_mask = (LayerMask *) gtk_object_get_data (GTK_OBJECT (src_widget),
|
|
|
|
"gimp_layer_mask");
|
|
|
|
component = (GImage *) gtk_object_get_data (GTK_OBJECT (src_widget),
|
|
|
|
"gimp_component");
|
1999-08-20 03:53:30 +08:00
|
|
|
|
|
|
|
if (layer)
|
|
|
|
{
|
|
|
|
drawable = GIMP_DRAWABLE (layer);
|
|
|
|
}
|
|
|
|
else if (channel)
|
|
|
|
{
|
|
|
|
drawable = GIMP_DRAWABLE (channel);
|
|
|
|
}
|
|
|
|
else if (layer_mask)
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
drawable = GIMP_DRAWABLE (layer_mask);
|
|
|
|
}
|
|
|
|
else if (component)
|
|
|
|
{
|
|
|
|
component_type =
|
|
|
|
(ChannelType) gtk_object_get_data (GTK_OBJECT (src_widget),
|
|
|
|
"gimp_component_type");
|
1999-08-20 03:53:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: implement special treatment of channel etc.
|
|
|
|
*/
|
|
|
|
if (drawable)
|
|
|
|
{
|
|
|
|
GImage *gimage;
|
|
|
|
Layer *new_layer;
|
|
|
|
GImage *dest_gimage;
|
|
|
|
gint width, height;
|
|
|
|
gint dest_width, dest_height;
|
|
|
|
gint off_x, off_y;
|
|
|
|
TileManager *tiles;
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
guchar bg[MAX_CHANNELS];
|
|
|
|
gint bytes, type;
|
|
|
|
|
|
|
|
gimage = gimp_drawable_gimage (drawable);
|
|
|
|
width = gimp_drawable_width (drawable);
|
|
|
|
height = gimp_drawable_height (drawable);
|
|
|
|
|
|
|
|
/* How many bytes in the temp buffer? */
|
|
|
|
switch (drawable_type (drawable))
|
|
|
|
{
|
|
|
|
case RGB_GIMAGE: case RGBA_GIMAGE:
|
|
|
|
bytes = 4; type = RGB;
|
|
|
|
break;
|
|
|
|
case GRAY_GIMAGE: case GRAYA_GIMAGE:
|
|
|
|
bytes = 2; type = GRAY;
|
|
|
|
break;
|
|
|
|
case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
|
|
|
|
bytes = 4; type = INDEXED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bytes = 3; type = RGB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimage_get_background (gimage, drawable, bg);
|
|
|
|
|
|
|
|
tiles = tile_manager_new (width, height, bytes);
|
|
|
|
|
|
|
|
pixel_region_init (&srcPR, drawable_data (drawable),
|
|
|
|
0, 0, width, height, FALSE);
|
|
|
|
pixel_region_init (&destPR, tiles,
|
|
|
|
0, 0, width, height, TRUE);
|
|
|
|
|
|
|
|
if (type == INDEXED)
|
|
|
|
/* If the layer is indexed...we need to extract pixels */
|
|
|
|
extract_from_region (&srcPR, &destPR, NULL,
|
|
|
|
drawable_cmap (drawable), bg, type,
|
|
|
|
drawable_has_alpha (drawable), FALSE);
|
|
|
|
else if (bytes > srcPR.bytes)
|
|
|
|
/* If the layer doesn't have an alpha channel, add one */
|
|
|
|
add_alpha_region (&srcPR, &destPR);
|
|
|
|
else
|
|
|
|
/* Otherwise, do a straight copy */
|
|
|
|
copy_region (&srcPR, &destPR);
|
|
|
|
|
|
|
|
dest_gimage = gdisp->gimage;
|
|
|
|
dest_width = dest_gimage->width;
|
|
|
|
dest_height = dest_gimage->height;
|
|
|
|
|
|
|
|
new_layer =
|
|
|
|
layer_from_tiles (dest_gimage,
|
|
|
|
GIMP_DRAWABLE (gimage_get_active_layer (dest_gimage)),
|
|
|
|
tiles, _("Pasted Layer"),
|
|
|
|
OPAQUE_OPACITY, NORMAL_MODE);
|
|
|
|
|
|
|
|
tile_manager_destroy (tiles);
|
|
|
|
|
|
|
|
if (new_layer)
|
|
|
|
{
|
|
|
|
undo_push_group_start (dest_gimage, EDIT_PASTE_UNDO);
|
|
|
|
|
|
|
|
gimp_drawable_set_gimage (GIMP_DRAWABLE (new_layer), dest_gimage);
|
|
|
|
|
|
|
|
off_x = (dest_gimage->width - width) / 2;
|
|
|
|
off_y = (dest_gimage->height - height) / 2;
|
|
|
|
|
|
|
|
layer_translate (new_layer, off_x, off_y);
|
|
|
|
|
|
|
|
gimage_add_layer (dest_gimage, new_layer, -1);
|
|
|
|
|
|
|
|
gdisplays_flush ();
|
|
|
|
|
|
|
|
return_val = TRUE;
|
|
|
|
|
|
|
|
undo_push_group_end (dest_gimage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_drag_finish (context, return_val, FALSE, time);
|
|
|
|
|
|
|
|
if (return_val)
|
|
|
|
gimp_context_set_display (gimp_context_get_user (), gdisp);
|
|
|
|
|
|
|
|
return return_val;
|
|
|
|
}
|
1999-08-23 22:19:26 +08:00
|
|
|
|
|
|
|
void
|
1999-08-24 08:36:57 +08:00
|
|
|
gdisplay_set_color (GtkWidget *widget,
|
|
|
|
guchar r,
|
|
|
|
guchar g,
|
|
|
|
guchar b,
|
|
|
|
gpointer data)
|
1999-08-23 22:19:26 +08:00
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
TileManager *buf_tiles;
|
|
|
|
PixelRegion bufPR;
|
|
|
|
GimpContext *context;
|
|
|
|
gint x1, x2, y1, y2;
|
|
|
|
gint bytes;
|
|
|
|
gboolean has_alpha;
|
|
|
|
guchar col[3];
|
|
|
|
|
|
|
|
gimage = ((GDisplay *) data)->gimage;
|
|
|
|
drawable = gimage_active_drawable (gimage);
|
|
|
|
|
|
|
|
gimp_add_busy_cursors ();
|
|
|
|
|
|
|
|
/* Get the fill parameters */
|
|
|
|
if (gimp_context_get_current () == gimp_context_get_user () &&
|
|
|
|
! global_paint_options)
|
|
|
|
context = tool_info[BUCKET_FILL].tool_context;
|
|
|
|
else
|
|
|
|
context = gimp_context_get_current ();
|
|
|
|
|
|
|
|
drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
bytes = drawable_bytes (drawable);
|
|
|
|
has_alpha = drawable_has_alpha (drawable);
|
|
|
|
|
|
|
|
col[0] = r;
|
|
|
|
col[1] = g;
|
|
|
|
col[2] = b;
|
|
|
|
|
|
|
|
/* Fill the region */
|
|
|
|
buf_tiles = tile_manager_new ((x2 - x1), (y2 - y1), bytes);
|
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE);
|
|
|
|
bucket_fill_region (FG_BUCKET_FILL, &bufPR, NULL,
|
|
|
|
col, NULL, x1, y1, has_alpha);
|
|
|
|
|
|
|
|
/* Apply it to the image */
|
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), FALSE);
|
|
|
|
gimage_apply_image (gimage, drawable, &bufPR, TRUE,
|
|
|
|
gimp_context_get_opacity (context) * 255,
|
|
|
|
gimp_context_get_paint_mode (context),
|
|
|
|
NULL, x1, y1);
|
|
|
|
tile_manager_destroy (buf_tiles);
|
|
|
|
|
|
|
|
/* Update the displays */
|
|
|
|
drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
|
|
|
|
gdisplays_flush ();
|
|
|
|
|
|
|
|
gimp_remove_busy_cursors (NULL);
|
|
|
|
}
|