Commit c94147a1 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

cleaned up and simplified the FlareCenter code even more.

2004-10-13  Michael Natterer  <mitch@gimp.org>

	* plug-ins/common/flarefx.c: cleaned up and simplified the
	FlareCenter code even more.

	* plug-ins/common/nova.c: did the same changes for the NovaCenter
	stuff.

	Also added code which sets an appropriate cursor on "realize" to
	fix bug #90519, but GimpPreview currently prevents this from
	working correctly...
parent 8a5502f8
2004-10-13 Michael Natterer <mitch@gimp.org>
* plug-ins/common/flarefx.c: cleaned up and simplified the
FlareCenter code even more.
* plug-ins/common/nova.c: did the same changes for the NovaCenter
stuff.
Also added code which sets an appropriate cursor on "realize" to
fix bug #90519, but GimpPreview currently prevents this from
working correctly...
2004-10-13 Sven Neumann <sven@gimp.org>
* app/widgets/widgets-enums.[ch]: changed the description for
......
......@@ -55,15 +55,6 @@
#include "libgimp/stdplugins-intl.h"
/* --- Defines --- */
#define PREVIEW_MASK (GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON_MOTION_MASK)
#define PREVIEW 0x1
#define CURSOR 0x2
#define ALL 0xf
/* --- Typedefs --- */
typedef struct
{
......@@ -84,13 +75,11 @@ typedef struct REFLECT
typedef struct
{
GimpDrawable *drawable;
gint dwidth;
gint dheight;
gint bpp;
GtkWidget *coords;
gboolean cursor;
gint curx, cury; /* x,y of cursor in preview */
gint oldx, oldy;
GimpPreview *preview;
GtkWidget *coords;
gboolean cursor_drawn;
gint curx, cury; /* x,y of cursor in preview */
gint oldx, oldy;
} FlareCenter;
......@@ -106,20 +95,20 @@ static void FlareFX (GimpDrawable *drawable,
GimpPreview *preview);
static gboolean flare_dialog (GimpDrawable *drawable);
static GtkWidget * flare_center_create (GimpDrawable *drawable);
static void flare_center_destroy (GtkWidget *widget,
gpointer data);
static void flare_center_draw (FlareCenter *center,
gint update);
static GtkWidget * flare_center_create (GimpDrawable *drawable,
GimpPreview *preview);
static void flare_center_cursor_draw (FlareCenter *center);
static void flare_center_coords_update (GimpSizeEntry *coords,
FlareCenter *center);
static void flare_center_cursor_update (FlareCenter *center);
static void flare_center_preview_realize (GtkWidget *widget,
FlareCenter *center);
static gboolean flare_center_preview_expose (GtkWidget *widget,
GdkEvent *event,
GimpPreview *preview);
FlareCenter *center);
static gboolean flare_center_preview_events (GtkWidget *widget,
GdkEvent *event,
GimpPreview *preview);
FlareCenter *center);
static void mcolor (guchar *s,
gfloat h);
......@@ -179,7 +168,6 @@ static gint numref;
static GimpRGB color, glow, inner, outer, halo;
static Reflect ref1[19];
static gboolean show_cursor = TRUE;
static GtkWidget *preview;
/* --- Functions --- */
......@@ -212,8 +200,7 @@ query (void)
args, NULL);
gimp_plugin_menu_register ("plug_in_flarefx",
/* don't translate '<Image>' */
N_("<Image>/Filters/Light Effects"));
"<Image>/Filters/Light Effects");
}
static void
......@@ -312,8 +299,8 @@ flare_dialog (GimpDrawable *drawable)
{
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *preview;
GtkWidget *frame;
FlareCenter *center;
gboolean run;
gimp_ui_init ("flarefx", TRUE);
......@@ -333,26 +320,16 @@ flare_dialog (GimpDrawable *drawable)
gtk_widget_show (main_vbox);
preview = gimp_aspect_preview_new (drawable, &fvals.preview);
gtk_widget_add_events (GIMP_PREVIEW (preview)->area, PREVIEW_MASK);
gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview);
gtk_widget_add_events (GIMP_PREVIEW (preview)->area,
GDK_POINTER_MOTION_MASK);
gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
gtk_widget_show (preview);
g_signal_connect_swapped (preview, "invalidated",
G_CALLBACK (FlareFX),
drawable);
frame = flare_center_create (drawable);
center = g_object_get_data (G_OBJECT (frame), "center");
g_object_set_data (G_OBJECT (preview), "center", center);
g_signal_connect_after (GIMP_PREVIEW (preview)->area, "expose_event",
G_CALLBACK (flare_center_preview_expose),
preview);
g_signal_connect (GIMP_PREVIEW (preview)->area, "event",
G_CALLBACK (flare_center_preview_events),
preview);
frame = flare_center_create (drawable, GIMP_PREVIEW (preview));
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
......@@ -741,7 +718,8 @@ mrt4 (guchar *s,
*/
static GtkWidget *
flare_center_create (GimpDrawable *drawable)
flare_center_create (GimpDrawable *drawable,
GimpPreview *preview)
{
FlareCenter *center;
GtkWidget *frame;
......@@ -752,26 +730,21 @@ flare_center_create (GimpDrawable *drawable)
center = g_new0 (FlareCenter, 1);
center->drawable = drawable;
center->dwidth = gimp_drawable_width (drawable->drawable_id);
center->dheight = gimp_drawable_height (drawable->drawable_id);
center->bpp = gimp_drawable_bpp (drawable->drawable_id);
center->cursor = FALSE;
center->curx = 0;
center->cury = 0;
center->oldx = 0;
center->oldy = 0;
if (gimp_drawable_has_alpha (drawable->drawable_id))
center->bpp--;
center->drawable = drawable;
center->preview = preview;
center->cursor_drawn = FALSE;
center->curx = 0;
center->cury = 0;
center->oldx = 0;
center->oldy = 0;
frame = gimp_frame_new (_("Center of Flare Effect"));
g_object_set_data (G_OBJECT (frame), "center", center);
g_signal_connect (frame, "destroy",
G_CALLBACK (flare_center_destroy),
center);
g_signal_connect_swapped (frame, "destroy",
G_CALLBACK (g_free),
center);
image_ID = gimp_drawable_get_image (drawable->drawable_id);
gimp_image_get_resolution (image_ID, &res_x, &res_y);
......@@ -801,7 +774,6 @@ flare_center_create (GimpDrawable *drawable)
G_CALLBACK (flare_center_coords_update),
center);
/* show / hide cursor */
check = gtk_check_button_new_with_mnemonic (_("_Show cursor"));
gtk_table_attach (GTK_TABLE (center->coords), check, 0, 5, 2, 3,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
......@@ -815,21 +787,21 @@ flare_center_create (GimpDrawable *drawable)
G_CALLBACK (gimp_preview_invalidate),
preview);
flare_center_cursor_update (center);
g_signal_connect (preview->area, "realize",
G_CALLBACK (flare_center_preview_realize),
center);
g_signal_connect_after (preview->area, "expose_event",
G_CALLBACK (flare_center_preview_expose),
center);
g_signal_connect (preview->area, "event",
G_CALLBACK (flare_center_preview_events),
center);
center->cursor = FALSE; /* Make sure that the cursor has not been drawn */
flare_center_cursor_update (center);
return frame;
}
static void
flare_center_destroy (GtkWidget *widget,
gpointer data)
{
FlareCenter *center = data;
g_free (center);
}
/*
* Drawing CenterFrame
* if update & PREVIEW, draw preview
......@@ -837,65 +809,55 @@ flare_center_destroy (GtkWidget *widget,
*/
static void
flare_center_draw (FlareCenter *center,
gint update)
flare_center_cursor_draw (FlareCenter *center)
{
GtkWidget *prvw = GIMP_PREVIEW (preview)->area;
GtkWidget *prvw = center->preview->area;
gint width, height;
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
gimp_preview_get_size (center->preview, &width, &height);
if (update & PREVIEW)
{
center->cursor = FALSE;
}
gdk_gc_set_function (prvw->style->black_gc, GDK_INVERT);
if (update & CURSOR)
if (show_cursor)
{
gdk_gc_set_function (prvw->style->black_gc, GDK_INVERT);
if (show_cursor)
if (center->cursor_drawn)
{
if (center->cursor)
{
gdk_draw_line (prvw->window,
prvw->style->black_gc,
center->oldx, 1,
center->oldx,
height - 1);
gdk_draw_line (prvw->window,
prvw->style->black_gc,
1, center->oldy,
width - 1,
center->oldy);
}
gdk_draw_line (prvw->window,
prvw->style->black_gc,
center->curx, 1,
center->curx,
center->oldx, 1,
center->oldx,
height - 1);
gdk_draw_line (prvw->window,
prvw->style->black_gc,
1, center->cury,
1, center->oldy,
width - 1,
center->cury);
center->oldy);
}
/* current position of cursor is updated */
center->oldx = center->curx;
center->oldy = center->cury;
center->cursor = TRUE;
gdk_gc_set_function (prvw->style->black_gc, GDK_COPY);
gdk_draw_line (prvw->window,
prvw->style->black_gc,
center->curx, 1,
center->curx,
height - 1);
gdk_draw_line (prvw->window,
prvw->style->black_gc,
1, center->cury,
width - 1,
center->cury);
}
/* current position of cursor is updated */
center->oldx = center->curx;
center->oldy = center->cury;
center->cursor_drawn = TRUE;
gdk_gc_set_function (prvw->style->black_gc, GDK_COPY);
}
/*
* CenterFrame entry callback
*/
static void
flare_center_coords_update (GimpSizeEntry *coords,
FlareCenter *center)
......@@ -904,42 +866,55 @@ flare_center_coords_update (GimpSizeEntry *coords,
fvals.posy = gimp_size_entry_get_refval (coords, 1);
flare_center_cursor_update (center);
flare_center_draw (center, CURSOR);
gimp_preview_invalidate (GIMP_PREVIEW (preview));
flare_center_cursor_draw (center);
gimp_preview_invalidate (center->preview);
}
/*
* Update the cross cursor's coordinates accoding to pvals.[xy]center
* but not redraw it
*/
static void
flare_center_cursor_update (FlareCenter *center)
{
gint width, height;
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
gimp_preview_get_size (center->preview, &width, &height);
center->curx = fvals.posx * width / center->dwidth;
center->cury = fvals.posy * height / center->dheight;
center->curx = fvals.posx * width / center->drawable->width;
center->cury = fvals.posy * height / center->drawable->height;
center->curx = CLAMP (center->curx, 0, width - 1);
center->cury = CLAMP (center->cury, 0, height - 1);
}
/*
* Set the preview area'a cursor on realize
*/
static void
flare_center_preview_realize (GtkWidget *widget,
FlareCenter *center)
{
GdkDisplay *display = gtk_widget_get_display (widget);
GdkCursor *cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
gdk_window_set_cursor (widget->window, cursor);
gdk_cursor_unref (cursor);
}
/*
* Handle the expose event on the preview
*/
static gboolean
flare_center_preview_expose (GtkWidget *widget,
GdkEvent *event,
GimpPreview *preview)
FlareCenter *center)
{
FlareCenter *center;
center->cursor_drawn = FALSE;
center = g_object_get_data (G_OBJECT (preview), "center");
flare_center_cursor_update (center);
flare_center_draw (center, ALL);
flare_center_cursor_draw (center);
return FALSE;
}
......@@ -947,17 +922,14 @@ flare_center_preview_expose (GtkWidget *widget,
/*
* Handle other events on the preview
*/
static gboolean
flare_center_preview_events (GtkWidget *widget,
GdkEvent *event,
GimpPreview *preview)
FlareCenter *center)
{
FlareCenter *center;
gint width, height;
gint width, height;
center = g_object_get_data (G_OBJECT (preview), "center");
gimp_preview_get_size (preview, &width, &height);
gimp_preview_get_size (center->preview, &width, &height);
switch (event->type)
{
......@@ -968,17 +940,17 @@ flare_center_preview_events (GtkWidget *widget,
case GDK_BUTTON_PRESS:
gtk_widget_get_pointer (widget, &center->curx, &center->cury);
flare_center_draw (center, CURSOR);
flare_center_cursor_draw (center);
g_signal_handlers_block_by_func (center->coords,
flare_center_coords_update,
center);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 0,
center->curx * center->dwidth /
center->curx * center->drawable->width /
width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 1,
center->cury * center->dheight /
center->cury * center->drawable->height /
height);
g_signal_handlers_unblock_by_func (center->coords,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment