Commit 1e08aa1e authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer
Browse files

app/color_area.[ch] app/color_panel.[ch] enabled dnd for colors

1999-08-22  Michael Natterer  <mitschel@cs.tu-berlin.de>

	* app/color_area.[ch]
	* app/color_panel.[ch]
	* app/gimpdnd.[ch]: enabled dnd for colors (compatible with the
	standard gtk/gnome color dnd). The color selection is now invoked
	on a real click, not on button_down to avoid confusion with dnd.

	* app/channels_dialog.c
	* app/disp_callbacks.c
	* app/interface.c
	* app/layers_dialog.c: minor dnd updates/fixes.

	* app/channel.[ch]
	* app/channel_pvt.h
	* app/docindex.[ch]
	* app/docindexif.[ch]
	* app/drawable.[ch]
	* app/floating_sel.c
	* app/gimage.[ch]
	* app/gimage_mask.c
	* app/gimpdrawable.[ch]
	* app/gimpdrawableP.h
	* app/gimpimage.[ch]
	* app/gimpimageP.h
	* app/layer.[ch]
	* app/layer_pvt.h
	* app/undo.c
	* app/xcf.c: wanted to do some s/int/gboolean/ in the layer files
	where appropriate and found myself spending the whole night doing
	a big code review for layers/channels/drawables/images:
	s/int/gboolean/, s/<type>/g<type>/, lots of indentation, removed
	some old global variables and deprecated functions, #include
	cleanups, proper prototypes, copyright headers, ...
parent 51f7bf23
1999-08-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/color_area.[ch]
* app/color_panel.[ch]
* app/gimpdnd.[ch]: enabled dnd for colors (compatible with the
standard gtk/gnome color dnd). The color selection is now invoked
on a real click, not on button_down to avoid confusion with dnd.
* app/channels_dialog.c
* app/disp_callbacks.c
* app/interface.c
* app/layers_dialog.c: minor dnd updates/fixes.
* app/channel.[ch]
* app/channel_pvt.h
* app/docindex.[ch]
* app/docindexif.[ch]
* app/drawable.[ch]
* app/floating_sel.c
* app/gimage.[ch]
* app/gimage_mask.c
* app/gimpdrawable.[ch]
* app/gimpdrawableP.h
* app/gimpimage.[ch]
* app/gimpimageP.h
* app/layer.[ch]
* app/layer_pvt.h
* app/undo.c
* app/xcf.c: wanted to do some s/int/gboolean/ in the layer files
where appropriate and found myself spending the whole night doing
a big code review for layers/channels/drawables/images:
s/int/gboolean/, s/<type>/g<type>/, lots of indentation, removed
some old global variables and deprecated functions, #include
cleanups, proper prototypes, copyright headers, ...
1999-08-22 Tomas Ogren <stric@ing.umu.se>
* app/bucket_fill.c
......
This diff is collapsed.
......@@ -38,88 +38,91 @@ typedef enum
/* Half way point where a region is no longer visible in a selection */
#define HALF_WAY 127
/* structure declarations */
#define GIMP_TYPE_CHANNEL (gimp_channel_get_type ())
#define GIMP_CHANNEL(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_CHANNEL, GimpChannel))
#define GIMP_CHANNEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CHANNEL, GimpChannelClass))
#define GIMP_IS_CHANNEL(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_CHANNEL))
#define GIMP_IS_CHANNEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CHANNEL))
/* structure declarations */
#define GIMP_TYPE_CHANNEL (gimp_channel_get_type ())
#define GIMP_CHANNEL(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_CHANNEL, GimpChannel))
#define GIMP_CHANNEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CHANNEL, GimpChannelClass))
#define GIMP_IS_CHANNEL(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_CHANNEL))
#define GIMP_IS_CHANNEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CHANNEL))
GtkType gimp_channel_get_type (void);
/* Special undo type */
typedef struct _channel_undo ChannelUndo;
typedef struct _ChannelUndo ChannelUndo;
struct _channel_undo
struct _ChannelUndo
{
Channel * channel; /* the actual channel */
int prev_position; /* former position in list */
Channel * prev_channel; /* previous active channel */
int undo_type; /* is this a new channel undo */
/* or a remove channel undo? */
Channel *channel; /* the actual channel */
gint prev_position; /* former position in list */
Channel *prev_channel; /* previous active channel */
gint undo_type; /* is this a new channel undo */
/* or a remove channel undo? */
};
/* Special undo type */
typedef struct _mask_undo MaskUndo;
typedef struct _MaskUndo MaskUndo;
struct _mask_undo
struct _MaskUndo
{
TileManager * tiles; /* the actual mask */
int x, y; /* offsets */
TileManager *tiles; /* the actual mask */
gint x, y; /* offsets */
};
/* function declarations */
/* function declarations */
Channel * channel_new (GimpImage*, int, int, char *, int, unsigned char *);
Channel * channel_copy (Channel *);
Channel * channel_ref (Channel *);
void channel_unref (Channel *);
Channel * channel_new (GimpImage*,
gint, gint, gchar *, gint, guchar *);
Channel * channel_copy (Channel *);
Channel * channel_ref (Channel *);
void channel_unref (Channel *);
char * channel_get_name (Channel *);
void channel_set_name (Channel *, char *);
gchar * channel_get_name (Channel *);
void channel_set_name (Channel *, gchar *);
int channel_get_opacity (Channel *);
void channel_set_opacity (Channel *, int );
gint channel_get_opacity (Channel *);
void channel_set_opacity (Channel *, gint);
char * channel_get_color (Channel *);
gchar * channel_get_color (Channel *);
void channel_set_color (Channel *, gchar *);
Channel * channel_get_ID (int);
void channel_delete (Channel *);
void channel_scale (Channel *, int, int);
void channel_resize (Channel *, int, int, int, int);
void channel_update (Channel *);
Channel * channel_get_ID (gint);
void channel_delete (Channel *);
void channel_scale (Channel *, gint, gint);
void channel_resize (Channel *, gint, gint, gint, gint);
void channel_update (Channel *);
/* access functions */
/* access functions */
unsigned char * channel_data (Channel *);
int channel_toggle_visibility (Channel *);
TempBuf * channel_preview (Channel *, int, int);
gboolean channel_toggle_visibility (Channel *);
TempBuf * channel_preview (Channel *, gint, gint);
void channel_invalidate_previews (GimpImage*);
Tattoo channel_get_tattoo(const Channel *);
Tattoo channel_get_tattoo (const Channel *);
/* selection mask functions */
Channel * channel_new_mask (GimpImage*, int, int);
int channel_boundary (Channel *, BoundSeg **, BoundSeg **,
int *, int *, int, int, int, int);
int channel_bounds (Channel *, int *, int *, int *, int *);
int channel_value (Channel *, int, int);
int channel_is_empty (Channel *);
void channel_add_segment (Channel *, int, int, int, int);
void channel_sub_segment (Channel *, int, int, int, int);
void channel_inter_segment (Channel *, int, int, int, int);
void channel_combine_rect (Channel *, int, int, int, int, int);
void channel_combine_ellipse (Channel *, int, int, int, int, int, int);
void channel_combine_mask (Channel *, Channel *, int, int, int);
Channel * channel_new_mask (GimpImage *, gint, gint);
gboolean channel_boundary (Channel *, BoundSeg **, BoundSeg **,
gint *, gint *, gint, gint, gint, gint);
gboolean channel_bounds (Channel *,
gint *, gint *, gint *, gint *);
gint channel_value (Channel *, gint, gint);
gboolean channel_is_empty (Channel *);
void channel_add_segment (Channel *, gint, gint, gint, gint);
void channel_sub_segment (Channel *, gint, gint, gint, gint);
void channel_inter_segment (Channel *, gint, gint, gint, gint);
void channel_combine_rect (Channel *,
ChannelOps, gint, gint, gint, gint);
void channel_combine_ellipse (Channel *,
ChannelOps,
gint, gint, gint, gint, gboolean);
void channel_combine_mask (Channel *, Channel *,
ChannelOps, gint, gint);
void channel_feather (Channel *, Channel *,
double, double,
int, int, int);
gdouble, gdouble,
ChannelOps, gint, gint);
void channel_push_undo (Channel *);
void channel_clear (Channel *);
void channel_invert (Channel *);
......@@ -127,21 +130,20 @@ void channel_sharpen (Channel *);
void channel_all (Channel *);
void channel_border (Channel * channel,
int radius_x,
int radius_y);
gint radius_x,
gint radius_y);
void channel_grow (Channel * channel,
int radius_x,
int radius_y);
gint radius_x,
gint radius_y);
void channel_shrink (Channel * channel,
int radius_x,
int radius_y,
int edge_lock);
gint radius_x,
gint radius_y,
gboolean edge_lock);
void channel_translate (Channel *, int, int);
void channel_translate (Channel *, gint, gint);
void channel_load (Channel *, Channel *);
void channel_invalidate_bounds (Channel *);
extern int channel_get_count;
void channel_invalidate_bounds (Channel *);
#define drawable_channel GIMP_IS_CHANNEL
......
......@@ -30,21 +30,21 @@ struct _GimpChannel
{
GimpDrawable drawable;
unsigned char col[3]; /* RGB triplet for channel color*/
int opacity; /* Channel opacity */
int show_masked; /* Show masked areas--as */
/* opposed to selected areas */
guchar col[3]; /* RGB triplet for channel color */
gint opacity; /* Channel opacity */
gboolean show_masked; /* Show masked areas--as */
/* opposed to selected areas */
/* Selection mask variables */
int boundary_known; /* is the current boundary valid*/
BoundSeg *segs_in; /* outline of selected region */
BoundSeg *segs_out; /* outline of selected region */
int num_segs_in; /* number of lines in boundary */
int num_segs_out; /* number of lines in boundary */
int empty; /* is the region empty? */
int bounds_known; /* recalculate the bounds? */
int x1, y1; /* coordinates for bounding box */
int x2, y2; /* lower right hand coordinate */
gboolean boundary_known; /* is the current boundary valid */
BoundSeg *segs_in; /* outline of selected region */
BoundSeg *segs_out; /* outline of selected region */
gint num_segs_in; /* number of lines in boundary */
gint num_segs_out; /* number of lines in boundary */
gboolean empty; /* is the region empty? */
gboolean bounds_known; /* recalculate the bounds? */
gint x1, y1; /* coordinates for bounding box */
gint x2, y2; /* lower right hand coordinate */
};
struct _GimpChannelClass
......
......@@ -1085,13 +1085,13 @@ channels_dialog_drag_new_channel_callback (GtkWidget *widget,
gint y,
guint time)
{
GtkWidget *src_widget;
ChannelWidget *src;
GtkWidget *src_widget;
gboolean return_val = FALSE;
if ((src_widget = gtk_drag_get_source_widget (context)))
{
ChannelWidget *src;
src
= (ChannelWidget *) gtk_object_get_user_data (GTK_OBJECT (src_widget));
......@@ -1149,13 +1149,13 @@ channels_dialog_drag_duplicate_channel_callback (GtkWidget *widget,
gint y,
guint time)
{
GtkWidget *src_widget;
ChannelWidget *src;
GtkWidget *src_widget;
gboolean return_val = FALSE;
if ((src_widget = gtk_drag_get_source_widget (context)))
{
ChannelWidget *src;
src
= (ChannelWidget *) gtk_object_get_user_data (GTK_OBJECT (src_widget));
......@@ -1180,13 +1180,13 @@ channels_dialog_drag_channel_to_sel_callback (GtkWidget *widget,
gint y,
guint time)
{
GtkWidget *src_widget;
ChannelWidget *src;
GtkWidget *src_widget;
gboolean return_val = FALSE;
if ((src_widget = gtk_drag_get_source_widget (context)))
{
ChannelWidget *src;
src
= (ChannelWidget *) gtk_object_get_user_data (GTK_OBJECT (src_widget));
......@@ -1211,13 +1211,13 @@ channels_dialog_drag_delete_channel_callback (GtkWidget *widget,
gint y,
guint time)
{
GtkWidget *src_widget;
ChannelWidget *src;
GtkWidget *src_widget;
gboolean return_val = FALSE;
if ((src_widget = gtk_drag_get_source_widget (context)))
{
ChannelWidget *src;
src
= (ChannelWidget *) gtk_object_get_user_data (GTK_OBJECT (src_widget));
......@@ -1513,7 +1513,8 @@ channel_widget_drag_begin_callback (GtkWidget *widget,
(ChannelWidget *) gtk_object_get_user_data (GTK_OBJECT (widget));
gimp_dnd_set_drawable_preview_icon (widget, context,
GIMP_DRAWABLE (channel_widget->channel));
GIMP_DRAWABLE (channel_widget->channel),
channel_widget->channel_preview->style->black_gc);
}
static gboolean
......@@ -1860,7 +1861,8 @@ channel_widget_preview_events (GtkWidget *widget,
valid = GIMP_DRAWABLE(channel_widget->channel)->preview_valid;
break;
default:
valid = gimage_preview_valid (channel_widget->gimage, channel_widget->type);
valid = gimage_preview_valid (channel_widget->gimage,
channel_widget->type);
break;
}
......@@ -2238,7 +2240,8 @@ channel_widget_channel_flush (GtkWidget *widget,
update_preview = !GIMP_DRAWABLE(channel_widget->channel)->preview_valid;
break;
default:
update_preview = !gimage_preview_valid (channel_widget->gimage, channel_widget->type);
update_preview = !gimage_preview_valid (channel_widget->gimage,
channel_widget->type);
break;
}
......
......@@ -22,35 +22,66 @@
#include "color_area.h"
#include "color_notebook.h"
#include "colormaps.h"
#include "gimpdnd.h"
#include "palette.h"
#define FORE_AREA 0
#define BACK_AREA 1
#define SWAP_AREA 2
#define DEF_AREA 3
typedef enum
{
FORE_AREA,
BACK_AREA,
SWAP_AREA,
DEF_AREA,
INVALID_AREA
} ColorAreaTarget;
/* local function prototypes */
static void color_area_drag_begin (GtkWidget *, GdkDragContext *, gpointer);
static void color_area_drag_end (GtkWidget *, GdkDragContext *, gpointer);
static void color_area_drop_handle (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint time,
gpointer data);
static void color_area_drag_handle (GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection_data,
guint info,
guint time,
gpointer data);
/* Global variables */
int active_color = 0;
gint active_color = 0;
/* Static variables */
static GdkGC *color_area_gc = NULL;
static GtkWidget *color_area = NULL;
static GdkPixmap *color_area_pixmap = NULL;
static GdkPixmap *default_pixmap = NULL;
static GdkPixmap *swap_pixmap = NULL;
static ColorNotebookP color_notebook = NULL;
static int color_notebook_active = 0;
static int edit_color;
static unsigned char revert_fg_r, revert_fg_g, revert_fg_b;
static unsigned char revert_bg_r, revert_bg_g, revert_bg_b;
static GdkGC *color_area_gc = NULL;
static GtkWidget *color_area = NULL;
static GdkPixmap *color_area_pixmap = NULL;
static GdkPixmap *default_pixmap = NULL;
static GdkPixmap *swap_pixmap = NULL;
static ColorNotebookP color_notebook = NULL;
static gboolean color_notebook_active = FALSE;
static gint edit_color;
static guchar revert_fg_r, revert_fg_g, revert_fg_b;
static guchar revert_bg_r, revert_bg_g, revert_bg_b;
/* dnd structures */
static GtkTargetEntry color_area_target_table[] =
{
GIMP_TARGET_COLOR
};
static guint n_color_area_targets = (sizeof (color_area_target_table) /
sizeof (color_area_target_table[0]));
/* Local functions */
static int
color_area_target (int x,
int y)
static ColorAreaTarget
color_area_target (gint x,
gint y)
{
int rect_w, rect_h;
int width, height;
gint rect_w, rect_h;
gint width, height;
gdk_window_get_size (color_area_pixmap, &width, &height);
......@@ -76,15 +107,20 @@ color_area_target (int x,
void
color_area_draw_rect (GdkDrawable *drawable,
GdkGC *gc,
gint x, gint y, gint width, gint height,
unsigned char r, unsigned char g, unsigned char b)
GdkGC *gc,
gint x,
gint y,
gint width,
gint height,
guchar r,
guchar g,
guchar b)
{
static unsigned char *color_area_rgb_buf = NULL;
static guchar *color_area_rgb_buf = NULL;
static gint color_area_rgb_buf_size;
static gint rowstride;
gint xx, yy;
unsigned char *bp;
guchar *bp;
rowstride = 3 * ((width + 3) & -4);
if (color_area_rgb_buf == NULL ||
......@@ -118,11 +154,11 @@ color_area_draw (void)
{
GdkColor *win_bg;
GdkColor fg, bg, bd;
int rect_w, rect_h;
int width, height;
int def_width, def_height;
int swap_width, swap_height;
unsigned char r, g, b;
gint rect_w, rect_h;
gint width, height;
gint def_width, def_height;
gint swap_width, swap_height;
guchar r, g, b;
/* Check we haven't gotten initial expose yet,
* no point in drawing anything */
......@@ -193,38 +229,39 @@ color_area_draw (void)
}
static void
color_area_select_callback (int r,
int g,
int b,
ColorNotebookState state,
void *client_data)
color_area_select_callback (gint r,
gint g,
gint b,
ColorNotebookState state,
void *client_data)
{
if (color_notebook)
{
switch (state) {
case COLOR_NOTEBOOK_OK:
color_notebook_hide (color_notebook);
color_notebook_active = 0;
/* Fallthrough */
case COLOR_NOTEBOOK_UPDATE:
if (edit_color == FOREGROUND)
palette_set_foreground (r, g, b);
else
palette_set_background (r, g, b);
break;
case COLOR_NOTEBOOK_CANCEL:
color_notebook_hide (color_notebook);
color_notebook_active = 0;
palette_set_foreground (revert_fg_r, revert_fg_g, revert_fg_b);
palette_set_background (revert_bg_r, revert_bg_g, revert_bg_b);
}
switch (state)
{
case COLOR_NOTEBOOK_OK:
color_notebook_hide (color_notebook);
color_notebook_active = FALSE;
/* Fallthrough */
case COLOR_NOTEBOOK_UPDATE:
if (edit_color == FOREGROUND)
palette_set_foreground (r, g, b);
else
palette_set_background (r, g, b);
break;
case COLOR_NOTEBOOK_CANCEL:
color_notebook_hide (color_notebook);
color_notebook_active = FALSE;
palette_set_foreground (revert_fg_r, revert_fg_g, revert_fg_b);
palette_set_background (revert_bg_r, revert_bg_g, revert_bg_b);
}
}
}
static void
color_area_edit (void)
{
unsigned char r, g, b;
guchar r, g, b;
if (!color_notebook_active)
{
......@@ -244,17 +281,21 @@ color_area_edit (void)
if (! color_notebook)
{
color_notebook = color_notebook_new (r, g, b, color_area_select_callback, NULL, TRUE);
color_notebook_active = 1;
color_notebook = color_notebook_new (r, g, b, color_area_select_callback,
NULL, TRUE);
color_notebook_active = TRUE;
}
else
{
if (! color_notebook_active)
color_notebook_show (color_notebook);
{
color_notebook_show (color_notebook);
color_notebook_active = TRUE;
}
else
gdk_window_raise (color_notebook->shell->window);
color_notebook_set_color (color_notebook, r, g, b, 1);
color_notebook_set_color (color_notebook, r, g, b, TRUE);
}
}
......@@ -262,8 +303,10 @@ static gint
color_area_events (GtkWidget *widget,
GdkEvent *event)
{
GdkEventButton *bevent;
int target;
GdkEventButton *bevent;
ColorAreaTarget target;
static ColorAreaTarget press_target = INVALID_AREA;
switch (event->type)
{
......@@ -274,7 +317,6 @@ color_area_events (GtkWidget *widget,
color_area_pixmap = gdk_pixmap_new (widget->window,
widget->allocation.width,
widget->allocation.height, -1);
break;
case GDK_EXPOSE:
......@@ -290,32 +332,53 @@ color_area_events (GtkWidget *widget,
case GDK_BUTTON_PRESS:
bevent = (GdkEventButton *) event;
if (bevent->button == 1)
press_target = color_area_target (bevent->x, bevent->y);
break;
case GDK_BUTTON_RELEASE:
bevent = (GdkEventButton *) event;
if (bevent->button == 1)
{
switch ((target = color_area_target (bevent->x, bevent->y)))
target = color_area_target (bevent->x, bevent->y);
if (target == press_target)
{
case FORE_AREA:
case BACK_AREA:
if (target == active_color)
color_area_edit ();
else
switch (target)
{
active_color = target;
case FORE_AREA:
case BACK_AREA:
if (target == active_color)
{
color_area_edit ();
}
else
{
active_color = target;
color_area_draw ();