2000-05-08 09:23:30 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2000-05-31 14:15:06 +08:00
|
|
|
*
|
|
|
|
* gimppatternmenu.c
|
2000-05-08 09:23:30 +08:00
|
|
|
* Copyright (C) 1998 Andy Thomas
|
1998-10-02 06:09:01 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-10-02 06:09:01 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
2000-05-08 09:23:30 +08:00
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
1998-10-02 06:09:01 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-10-02 06:09:01 +08:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2000-05-08 09:23:30 +08:00
|
|
|
*/
|
|
|
|
|
2002-05-14 07:30:23 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2002-01-30 22:54:27 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning GTK_DISABLE_DEPRECATED
|
|
|
|
#endif
|
|
|
|
#undef GTK_DISABLE_DEPRECATED
|
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimpui.h"
|
|
|
|
|
2003-06-17 17:43:14 +08:00
|
|
|
#include "libgimp-intl.h"
|
|
|
|
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
#define PATTERN_SELECT_DATA_KEY "gimp-pattern-select-data"
|
|
|
|
#define CELL_SIZE 20
|
1998-10-02 06:09:01 +08:00
|
|
|
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
typedef struct _PatternSelect PatternSelect;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
struct _PatternSelect
|
2000-05-08 09:23:30 +08:00
|
|
|
{
|
2003-06-17 17:43:14 +08:00
|
|
|
gchar *title;
|
|
|
|
GimpRunPatternCallback callback;
|
2003-07-01 23:06:06 +08:00
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
GtkWidget *preview;
|
2000-05-31 14:15:06 +08:00
|
|
|
GtkWidget *button;
|
2003-07-01 23:06:06 +08:00
|
|
|
|
|
|
|
GtkWidget *popup;
|
|
|
|
|
2000-05-31 14:15:06 +08:00
|
|
|
gchar *pattern_name; /* Local copy */
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint bytes;
|
2003-06-17 17:43:14 +08:00
|
|
|
guchar *mask_data; /* local copy */
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
const gchar *temp_pattern_callback;
|
|
|
|
};
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
static void gimp_pattern_select_widget_callback (const gchar *name,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint bytes,
|
|
|
|
const guchar *mask_data,
|
|
|
|
gboolean closing,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_pattern_select_widget_clicked (GtkWidget *widget,
|
|
|
|
PatternSelect *pattern_sel);
|
|
|
|
static void gimp_pattern_select_widget_destroy (GtkWidget *widget,
|
|
|
|
PatternSelect *pattern_sel);
|
|
|
|
static gboolean gimp_pattern_select_preview_events (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
PatternSelect *pattern_sel);
|
|
|
|
static void gimp_pattern_select_preview_update (GtkWidget *preview,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint bytes,
|
|
|
|
const guchar *mask_data);
|
|
|
|
static void gimp_pattern_select_popup_open (PatternSelect *pattern_sel,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
|
|
|
static void gimp_pattern_select_popup_close (PatternSelect *pattern_sel);
|
2003-06-17 21:15:37 +08:00
|
|
|
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/**
|
|
|
|
* gimp_pattern_select_widget_new:
|
|
|
|
* @title: Title of the dialog to use or %NULL to use the default title.
|
|
|
|
* @pattern_name: Initial pattern name or %NULL to use current selection.
|
|
|
|
* @callback: A function to call when the selected pattern changes.
|
|
|
|
* @data: A pointer to arbitary data to be used in the call to @callback.
|
|
|
|
*
|
|
|
|
* Creates a new #GtkWidget that completely controls the selection of
|
|
|
|
* a pattern. This widget is suitable for placement in a table in a
|
|
|
|
* plug-in dialog.
|
|
|
|
*
|
|
|
|
* Returns: A #GtkWidget that you can use in your UI.
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_pattern_select_widget_new (const gchar *title,
|
|
|
|
const gchar *pattern_name,
|
|
|
|
GimpRunPatternCallback callback,
|
|
|
|
gpointer data)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
PatternSelect *pattern_sel;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
gint mask_data_size;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_return_val_if_fail (callback != NULL, NULL);
|
2003-06-17 21:15:37 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (! title)
|
|
|
|
title = _("Pattern Selection");
|
|
|
|
|
|
|
|
pattern_sel = g_new0 (PatternSelect, 1);
|
|
|
|
|
|
|
|
pattern_sel->title = g_strdup (title);
|
|
|
|
pattern_sel->callback = callback;
|
|
|
|
pattern_sel->data = data;
|
2003-06-17 21:15:37 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
2003-06-17 21:15:37 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
|
2003-06-17 21:15:37 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
pattern_sel->preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
|
|
gtk_widget_set_events (pattern_sel->preview,
|
|
|
|
GDK_EXPOSURE_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK);
|
|
|
|
gtk_preview_size (GTK_PREVIEW (pattern_sel->preview), CELL_SIZE, CELL_SIZE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), pattern_sel->preview);
|
|
|
|
gtk_widget_show (pattern_sel->preview);
|
|
|
|
|
|
|
|
g_signal_connect (pattern_sel->preview, "event",
|
|
|
|
G_CALLBACK (gimp_pattern_select_preview_events),
|
|
|
|
pattern_sel);
|
|
|
|
|
|
|
|
pattern_sel->button = gtk_button_new_with_label (" ... ");
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), pattern_sel->button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (pattern_sel->button);
|
|
|
|
|
|
|
|
g_signal_connect (pattern_sel->button, "clicked",
|
|
|
|
G_CALLBACK (gimp_pattern_select_widget_clicked),
|
|
|
|
pattern_sel);
|
|
|
|
g_signal_connect (pattern_sel->button, "destroy",
|
|
|
|
G_CALLBACK (gimp_pattern_select_widget_destroy),
|
|
|
|
pattern_sel);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/* Do initial pattern setup */
|
|
|
|
pattern_sel->pattern_name =
|
|
|
|
gimp_patterns_get_pattern_data (pattern_name,
|
|
|
|
&pattern_sel->width,
|
|
|
|
&pattern_sel->height,
|
|
|
|
&pattern_sel->bytes,
|
|
|
|
&mask_data_size,
|
|
|
|
&pattern_sel->mask_data);
|
|
|
|
|
|
|
|
if (pattern_sel->pattern_name)
|
|
|
|
gimp_pattern_select_preview_update (pattern_sel->preview,
|
|
|
|
pattern_sel->width,
|
|
|
|
pattern_sel->height,
|
|
|
|
pattern_sel->bytes,
|
|
|
|
pattern_sel->mask_data);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (hbox), PATTERN_SELECT_DATA_KEY, pattern_sel);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
return hbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_pattern_select_widget_close:
|
|
|
|
* @widget: A pattern select widget.
|
|
|
|
*
|
|
|
|
* Closes the popup window associated with @widget.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_pattern_select_widget_close (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
PatternSelect *pattern_sel;
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
pattern_sel = g_object_get_data (G_OBJECT (widget), PATTERN_SELECT_DATA_KEY);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_return_if_fail (pattern_sel != NULL);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (pattern_sel->temp_pattern_callback)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_pattern_select_destroy (pattern_sel->temp_pattern_callback);
|
|
|
|
pattern_sel->temp_pattern_callback = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_pattern_select_widget_set:
|
|
|
|
* @widget: A pattern select widget.
|
|
|
|
* @pattern_name: Pattern name to set. NULL means no change.
|
|
|
|
*
|
|
|
|
* Sets the current pattern for the pattern select widget. Calls the
|
|
|
|
* callback function if one was supplied in the call to
|
|
|
|
* gimp_pattern_select_widget_new().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_pattern_select_widget_set (GtkWidget *widget,
|
|
|
|
const gchar *pattern_name)
|
|
|
|
{
|
|
|
|
PatternSelect *pattern_sel;
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
pattern_sel = g_object_get_data (G_OBJECT (widget), PATTERN_SELECT_DATA_KEY);
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_return_if_fail (pattern_sel != NULL);
|
|
|
|
|
|
|
|
if (pattern_sel->temp_pattern_callback)
|
|
|
|
{
|
|
|
|
gimp_patterns_set_popup (pattern_sel->temp_pattern_callback,
|
|
|
|
pattern_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint bytes;
|
|
|
|
gint mask_data_size;
|
|
|
|
guint8 *mask_data;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = gimp_patterns_get_pattern_data (pattern_name,
|
|
|
|
&width,
|
|
|
|
&height,
|
|
|
|
&bytes,
|
|
|
|
&mask_data_size,
|
|
|
|
&mask_data);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
gimp_pattern_select_widget_callback (name, width, height, bytes,
|
|
|
|
mask_data, FALSE, pattern_sel);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
g_free (mask_data);
|
|
|
|
}
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
2003-07-01 23:06:06 +08:00
|
|
|
}
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pattern_select_widget_callback (const gchar *name,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint bytes,
|
|
|
|
const guchar *mask_data,
|
|
|
|
gboolean closing,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
PatternSelect *pattern_sel = (PatternSelect *) data;
|
|
|
|
|
|
|
|
g_free (pattern_sel->pattern_name);
|
|
|
|
g_free (pattern_sel->mask_data);
|
|
|
|
|
|
|
|
pattern_sel->pattern_name = g_strdup (name);
|
|
|
|
pattern_sel->width = width;
|
|
|
|
pattern_sel->height = height;
|
|
|
|
pattern_sel->bytes = bytes;
|
|
|
|
pattern_sel->mask_data = g_memdup (mask_data, width * height * bytes);
|
|
|
|
|
|
|
|
gimp_pattern_select_preview_update (pattern_sel->preview,
|
|
|
|
width, height, bytes, mask_data);
|
|
|
|
|
|
|
|
if (pattern_sel->callback)
|
|
|
|
pattern_sel->callback (name, width, height, bytes,
|
|
|
|
mask_data, closing, pattern_sel->data);
|
|
|
|
|
|
|
|
if (closing)
|
|
|
|
pattern_sel->temp_pattern_callback = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pattern_select_widget_clicked (GtkWidget *widget,
|
|
|
|
PatternSelect *pattern_sel)
|
|
|
|
{
|
|
|
|
if (pattern_sel->temp_pattern_callback)
|
|
|
|
{
|
|
|
|
/* calling gimp_patterns_set_popup() raises the dialog */
|
|
|
|
gimp_patterns_set_popup (pattern_sel->temp_pattern_callback,
|
|
|
|
pattern_sel->pattern_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pattern_sel->temp_pattern_callback =
|
|
|
|
gimp_pattern_select_new (pattern_sel->title,
|
|
|
|
pattern_sel->pattern_name,
|
|
|
|
gimp_pattern_select_widget_callback,
|
|
|
|
pattern_sel);
|
|
|
|
}
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_pattern_select_widget_destroy (GtkWidget *widget,
|
|
|
|
PatternSelect *pattern_sel)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
if (pattern_sel->temp_pattern_callback)
|
2003-06-17 21:15:37 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_pattern_select_destroy (pattern_sel->temp_pattern_callback);
|
|
|
|
pattern_sel->temp_pattern_callback = NULL;
|
2003-06-17 21:15:37 +08:00
|
|
|
}
|
2003-07-01 23:06:06 +08:00
|
|
|
|
|
|
|
g_free (pattern_sel->title);
|
|
|
|
g_free (pattern_sel->pattern_name);
|
|
|
|
g_free (pattern_sel->mask_data);
|
|
|
|
g_free (pattern_sel);
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_pattern_select_preview_events (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
PatternSelect *pattern_sel)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
|
|
|
GdkEventButton *bevent;
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (pattern_sel->mask_data)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
|
|
|
|
if (bevent->button == 1)
|
|
|
|
{
|
2000-05-08 09:23:30 +08:00
|
|
|
gtk_grab_add (widget);
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_pattern_select_popup_open (pattern_sel,
|
|
|
|
bevent->x, bevent->y);
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_BUTTON_RELEASE:
|
|
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
|
|
|
|
if (bevent->button == 1)
|
|
|
|
{
|
2000-05-08 09:23:30 +08:00
|
|
|
gtk_grab_remove (widget);
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_pattern_select_popup_close (pattern_sel);
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
break;
|
2003-07-01 23:06:06 +08:00
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_pattern_select_preview_update (GtkWidget *preview,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint bytes,
|
|
|
|
const guchar *mask_data)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-06-17 17:43:14 +08:00
|
|
|
const guchar *src;
|
|
|
|
guchar *buf;
|
|
|
|
gint x, y;
|
2000-05-08 09:23:30 +08:00
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
/* Draw the pattern */
|
2003-06-17 17:43:14 +08:00
|
|
|
buf = g_new (guchar, width * 3);
|
1998-10-02 06:09:01 +08:00
|
|
|
src = mask_data;
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2000-05-08 09:23:30 +08:00
|
|
|
for (y = 0; y < CELL_SIZE && y < height; y++)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-06-17 17:43:14 +08:00
|
|
|
switch (bytes)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
for (x = 0; x < width && x < CELL_SIZE; x++)
|
|
|
|
{
|
|
|
|
buf[x*3+0] = src[x];
|
|
|
|
buf[x*3+1] = src[x];
|
|
|
|
buf[x*3+2] = src[x];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
for (x = 0; x < width && x < CELL_SIZE; x++)
|
|
|
|
{
|
|
|
|
buf[x*3+0] = src[x*3+0];
|
|
|
|
buf[x*3+1] = src[x*3+1];
|
|
|
|
buf[x*3+2] = src[x*3+2];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
2003-06-17 17:43:14 +08:00
|
|
|
0, y, (width < CELL_SIZE) ? width : CELL_SIZE);
|
1998-10-02 06:09:01 +08:00
|
|
|
src += width * bytes;
|
|
|
|
}
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2000-05-08 09:23:30 +08:00
|
|
|
g_free (buf);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_widget_queue_draw (preview);
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-01 23:06:06 +08:00
|
|
|
gimp_pattern_select_popup_open (PatternSelect *pattern_sel,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *preview;
|
|
|
|
const guchar *src;
|
|
|
|
guchar *buf;
|
|
|
|
gint x_org;
|
|
|
|
gint y_org;
|
|
|
|
gint scr_w;
|
|
|
|
gint scr_h;
|
2003-06-17 17:43:14 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (pattern_sel->popup)
|
|
|
|
gimp_pattern_select_popup_close (pattern_sel);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
if (pattern_sel->width <= CELL_SIZE && pattern_sel->height <= CELL_SIZE)
|
|
|
|
return;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
pattern_sel->popup = gtk_window_new (GTK_WINDOW_POPUP);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
2000-05-08 09:23:30 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (pattern_sel->popup), frame);
|
2000-05-08 09:23:30 +08:00
|
|
|
gtk_widget_show (frame);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
|
|
gtk_preview_size (GTK_PREVIEW (preview),
|
|
|
|
pattern_sel->width, pattern_sel->height);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview);
|
|
|
|
gtk_widget_show (preview);
|
|
|
|
|
|
|
|
/* decide where to put the popup */
|
|
|
|
gdk_window_get_origin (pattern_sel->preview->window, &x_org, &y_org);
|
|
|
|
scr_w = gdk_screen_width ();
|
|
|
|
scr_h = gdk_screen_height ();
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
x = x_org + x - (pattern_sel->width / 2);
|
|
|
|
y = y_org + y - (pattern_sel->height / 2);
|
|
|
|
x = (x < 0) ? 0 : x;
|
|
|
|
y = (y < 0) ? 0 : y;
|
|
|
|
x = (x + pattern_sel->width > scr_w) ? scr_w - pattern_sel->width : x;
|
|
|
|
y = (y + pattern_sel->height > scr_h) ? scr_h - pattern_sel->height : y;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_window_move (GTK_WINDOW (pattern_sel->popup), x, y);
|
2000-05-08 09:23:30 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/* Draw the pattern */
|
|
|
|
buf = g_new (guchar, pattern_sel->width * 3);
|
|
|
|
src = pattern_sel->mask_data;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
for (y = 0; y < pattern_sel->height; y++)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
switch (pattern_sel->bytes)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
for (x = 0; x < pattern_sel->width; x++)
|
|
|
|
{
|
|
|
|
buf[x*3+0] = src[x];
|
|
|
|
buf[x*3+1] = src[x];
|
|
|
|
buf[x*3+2] = src[x];
|
|
|
|
}
|
|
|
|
break;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
case 3:
|
|
|
|
for (x = 0; x < pattern_sel->width; x++)
|
|
|
|
{
|
|
|
|
buf[x*3+0] = src[x*3+0];
|
|
|
|
buf[x*3+1] = src[x*3+1];
|
|
|
|
buf[x*3+2] = src[x*3+2];
|
|
|
|
}
|
|
|
|
break;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
|
|
|
0, y, pattern_sel->width);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
src += pattern_sel->width * pattern_sel->bytes;
|
|
|
|
}
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
g_free (buf);
|
2000-05-08 09:23:30 +08:00
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_widget_show (pattern_sel->popup);
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
static void
|
|
|
|
gimp_pattern_select_popup_close (PatternSelect *pattern_sel)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
if (pattern_sel->popup)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-07-01 23:06:06 +08:00
|
|
|
gtk_widget_destroy (pattern_sel->popup);
|
|
|
|
pattern_sel->popup = NULL;
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
}
|