2001-02-07 08:06:58 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-03-01 11:53:41 +08:00
|
|
|
* gimppreviewrendererbrush.c
|
|
|
|
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
|
2001-02-07 08:06:58 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-05-08 11:48:54 +08:00
|
|
|
#include "widgets-types.h"
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
#include "core/gimpbrushpipe.h"
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
#include "gimppreviewrendererbrush.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static void gimp_preview_renderer_brush_class_init (GimpPreviewRendererBrushClass *klass);
|
2003-03-04 01:19:30 +08:00
|
|
|
static void gimp_preview_renderer_brush_init (GimpPreviewRendererBrush *renderer);
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static void gimp_preview_renderer_brush_finalize (GObject *object);
|
|
|
|
static void gimp_preview_renderer_brush_render (GimpPreviewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static gboolean gimp_preview_renderer_brush_render_timeout (gpointer data);
|
2001-02-07 08:06:58 +08:00
|
|
|
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static GimpPreviewRendererClass *parent_class = NULL;
|
2001-02-07 08:06:58 +08:00
|
|
|
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
GType
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_brush_get_type (void)
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
static GType renderer_type = 0;
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (! renderer_type)
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
static const GTypeInfo renderer_info =
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
sizeof (GimpPreviewRendererBrushClass),
|
2001-10-17 19:33:43 +08:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2003-03-01 11:53:41 +08:00
|
|
|
(GClassInitFunc) gimp_preview_renderer_brush_class_init,
|
2001-10-17 19:33:43 +08:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2003-03-01 11:53:41 +08:00
|
|
|
sizeof (GimpPreviewRendererBrush),
|
2001-10-17 19:33:43 +08:00
|
|
|
0, /* n_preallocs */
|
2003-03-01 11:53:41 +08:00
|
|
|
(GInstanceInitFunc) gimp_preview_renderer_brush_init,
|
2001-02-07 08:06:58 +08:00
|
|
|
};
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer_type = g_type_register_static (GIMP_TYPE_PREVIEW_RENDERER,
|
|
|
|
"GimpPreviewRendererBrush",
|
|
|
|
&renderer_info, 0);
|
2001-02-07 08:06:58 +08:00
|
|
|
}
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
return renderer_type;
|
2001-02-07 08:06:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_brush_class_init (GimpPreviewRendererBrushClass *klass)
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpPreviewRendererClass *renderer_class;
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
renderer_class = GIMP_PREVIEW_RENDERER_CLASS (klass);
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
object_class->finalize = gimp_preview_renderer_brush_finalize;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer_class->render = gimp_preview_renderer_brush_render;
|
2001-02-07 08:06:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_brush_init (GimpPreviewRendererBrush *renderer)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2003-03-03 20:59:03 +08:00
|
|
|
renderer->pipe_timeout_id = 0;
|
|
|
|
renderer->pipe_animation_index = 0;
|
2001-02-08 04:35:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_brush_finalize (GObject *object)
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
GimpPreviewRendererBrush *renderer;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer = GIMP_PREVIEW_RENDERER_BRUSH (object);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->pipe_timeout_id)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
g_source_remove (renderer->pipe_timeout_id);
|
|
|
|
renderer->pipe_timeout_id = 0;
|
2001-02-08 04:35:18 +08:00
|
|
|
}
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-07 08:06:58 +08:00
|
|
|
}
|
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_brush_render (GimpPreviewRenderer *renderer,
|
|
|
|
GtkWidget *widget)
|
2001-02-07 11:14:38 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
GimpPreviewRendererBrush *renderbrush;
|
|
|
|
GimpBrush *brush;
|
|
|
|
TempBuf *temp_buf;
|
|
|
|
gint brush_width;
|
|
|
|
gint brush_height;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderbrush = GIMP_PREVIEW_RENDERER_BRUSH (renderer);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderbrush->pipe_timeout_id)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
g_source_remove (renderbrush->pipe_timeout_id);
|
|
|
|
renderbrush->pipe_timeout_id = 0;
|
2001-02-08 04:35:18 +08:00
|
|
|
}
|
2001-02-07 11:14:38 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
brush = GIMP_BRUSH (renderer->viewable);
|
2001-02-07 11:14:38 +08:00
|
|
|
brush_width = brush->mask->width;
|
|
|
|
brush_height = brush->mask->height;
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
temp_buf = gimp_viewable_get_new_preview (renderer->viewable,
|
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (temp_buf->width < renderer->width)
|
|
|
|
temp_buf->x = (renderer->width - temp_buf->width) / 2;
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (temp_buf->height < renderer->height)
|
|
|
|
temp_buf->y = (renderer->height - temp_buf->height) / 2;
|
2001-02-07 11:14:38 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->is_popup)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2003-03-04 01:19:30 +08:00
|
|
|
gimp_preview_renderer_render_buffer (renderer, temp_buf, -1,
|
|
|
|
GIMP_PREVIEW_BG_WHITE,
|
|
|
|
GIMP_PREVIEW_BG_WHITE);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
|
|
|
|
|
|
|
if (GIMP_IS_BRUSH_PIPE (brush))
|
|
|
|
{
|
2003-03-03 20:59:03 +08:00
|
|
|
#if 0
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->width != brush_width ||
|
|
|
|
renderer->height != brush_height)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
|
|
|
g_warning ("%s(): non-fullsize pipe popups are not supported yet.",
|
|
|
|
G_GNUC_FUNCTION);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-03 20:59:03 +08:00
|
|
|
#endif
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
renderbrush->pipe_animation_index = 0;
|
|
|
|
renderbrush->pipe_timeout_id =
|
2003-03-01 11:53:41 +08:00
|
|
|
g_timeout_add (300, gimp_preview_renderer_brush_render_timeout,
|
|
|
|
renderbrush);
|
2001-02-08 04:35:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2001-02-08 02:01:54 +08:00
|
|
|
|
2003-03-04 01:19:30 +08:00
|
|
|
gimp_preview_renderer_render_buffer (renderer, temp_buf, -1,
|
|
|
|
GIMP_PREVIEW_BG_WHITE,
|
|
|
|
GIMP_PREVIEW_BG_WHITE);
|
2003-03-01 20:55:43 +08:00
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
|
|
|
|
2003-02-27 00:17:10 +08:00
|
|
|
#define INDICATOR_WIDTH 7
|
|
|
|
#define INDICATOR_HEIGHT 7
|
2001-02-07 11:14:38 +08:00
|
|
|
|
2003-03-01 20:55:43 +08:00
|
|
|
if (renderer->width >= INDICATOR_WIDTH * 2 &&
|
|
|
|
renderer->height >= INDICATOR_HEIGHT * 2&&
|
2003-03-01 11:53:41 +08:00
|
|
|
(renderer->width < brush_width ||
|
|
|
|
renderer->height < brush_height ||
|
2003-02-27 00:17:10 +08:00
|
|
|
GIMP_IS_BRUSH_PIPE (brush)))
|
2001-02-07 11:14:38 +08:00
|
|
|
{
|
2003-02-27 00:17:10 +08:00
|
|
|
#define WHT { 255, 255, 255 }
|
|
|
|
#define BLK { 0, 0, 0 }
|
|
|
|
#define RED { 255, 127, 127 }
|
|
|
|
|
2001-02-07 11:14:38 +08:00
|
|
|
static const guchar scale_indicator_bits[7][7][3] =
|
|
|
|
{
|
|
|
|
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT },
|
|
|
|
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
|
|
|
|
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
|
|
|
|
{ WHT, BLK, BLK, BLK, BLK, BLK, WHT },
|
|
|
|
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
|
|
|
|
{ WHT, WHT, WHT, BLK, WHT, WHT, WHT },
|
|
|
|
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const guchar scale_pipe_indicator_bits[7][7][3] =
|
|
|
|
{
|
|
|
|
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT },
|
|
|
|
{ WHT, WHT, WHT, BLK, WHT, WHT, RED },
|
|
|
|
{ WHT, WHT, WHT, BLK, WHT, RED, RED },
|
|
|
|
{ WHT, BLK, BLK, BLK, BLK, BLK, RED },
|
|
|
|
{ WHT, WHT, WHT, BLK, RED, RED, RED },
|
|
|
|
{ WHT, WHT, RED, BLK, RED, RED, RED },
|
|
|
|
{ WHT, RED, RED, RED, RED, RED, RED }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const guchar pipe_indicator_bits[7][7][3] =
|
|
|
|
{
|
|
|
|
{ WHT, WHT, WHT, WHT, WHT, WHT, WHT },
|
|
|
|
{ WHT, WHT, WHT, WHT, WHT, WHT, RED },
|
|
|
|
{ WHT, WHT, WHT, WHT, WHT, RED, RED },
|
|
|
|
{ WHT, WHT, WHT, WHT, RED, RED, RED },
|
|
|
|
{ WHT, WHT, WHT, RED, RED, RED, RED },
|
|
|
|
{ WHT, WHT, RED, RED, RED, RED, RED },
|
|
|
|
{ WHT, RED, RED, RED, RED, RED, RED }
|
|
|
|
};
|
|
|
|
|
2003-02-27 00:17:10 +08:00
|
|
|
#undef WHT
|
|
|
|
#undef BLK
|
|
|
|
#undef RED
|
|
|
|
|
|
|
|
guchar *buf;
|
2003-03-01 20:55:43 +08:00
|
|
|
guchar *b;
|
2003-02-27 00:17:10 +08:00
|
|
|
gint x, y;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gboolean alpha;
|
|
|
|
gboolean pipe;
|
|
|
|
gboolean scale;
|
2001-02-07 11:14:38 +08:00
|
|
|
|
2003-03-01 20:55:43 +08:00
|
|
|
offset_x = renderer->width - INDICATOR_WIDTH;
|
|
|
|
offset_y = renderer->height - INDICATOR_HEIGHT;
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2003-03-01 20:55:43 +08:00
|
|
|
buf = renderer->buffer + (offset_y * renderer->rowstride +
|
|
|
|
offset_x * renderer->bytes);
|
2003-02-27 00:17:10 +08:00
|
|
|
|
|
|
|
pipe = GIMP_IS_BRUSH_PIPE (brush);
|
2003-03-01 11:53:41 +08:00
|
|
|
scale = (renderer->width < brush_width ||
|
|
|
|
renderer->height < brush_height);
|
2003-03-01 20:55:43 +08:00
|
|
|
alpha = (renderer->bytes == 4);
|
2003-02-27 00:17:10 +08:00
|
|
|
|
|
|
|
for (y = 0; y < INDICATOR_HEIGHT; y++)
|
2001-02-07 11:14:38 +08:00
|
|
|
{
|
2003-03-01 20:55:43 +08:00
|
|
|
b = buf;
|
|
|
|
|
2003-02-27 00:17:10 +08:00
|
|
|
for (x = 0; x < INDICATOR_WIDTH; x++)
|
2001-02-07 11:14:38 +08:00
|
|
|
{
|
2003-02-27 00:17:10 +08:00
|
|
|
if (scale)
|
|
|
|
{
|
|
|
|
if (pipe)
|
|
|
|
{
|
2003-03-01 20:55:43 +08:00
|
|
|
*b++ = scale_pipe_indicator_bits[y][x][0];
|
|
|
|
*b++ = scale_pipe_indicator_bits[y][x][1];
|
|
|
|
*b++ = scale_pipe_indicator_bits[y][x][2];
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-03-01 20:55:43 +08:00
|
|
|
*b++ = scale_indicator_bits[y][x][0];
|
|
|
|
*b++ = scale_indicator_bits[y][x][1];
|
|
|
|
*b++ = scale_indicator_bits[y][x][2];
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pipe)
|
|
|
|
{
|
2003-03-01 20:55:43 +08:00
|
|
|
*b++ = pipe_indicator_bits[y][x][0];
|
|
|
|
*b++ = pipe_indicator_bits[y][x][1];
|
|
|
|
*b++ = pipe_indicator_bits[y][x][2];
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (alpha)
|
2003-03-01 20:55:43 +08:00
|
|
|
*b++ = 255;
|
2001-02-07 11:14:38 +08:00
|
|
|
}
|
|
|
|
|
2003-03-01 20:55:43 +08:00
|
|
|
buf += renderer->rowstride;
|
2001-02-07 11:14:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-27 00:17:10 +08:00
|
|
|
#undef INDICATOR_WIDTH
|
|
|
|
#undef INDICATOR_HEIGHT
|
2001-02-07 11:14:38 +08:00
|
|
|
}
|
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
static gboolean
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_brush_render_timeout (gpointer data)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
GimpPreviewRendererBrush *renderbrush;
|
|
|
|
GimpPreviewRenderer *renderer;
|
|
|
|
GimpBrushPipe *brush_pipe;
|
|
|
|
GimpBrush *brush;
|
|
|
|
TempBuf *temp_buf;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderbrush = GIMP_PREVIEW_RENDERER_BRUSH (data);
|
|
|
|
renderer = GIMP_PREVIEW_RENDERER (data);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (! renderer->viewable)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2003-03-03 20:59:03 +08:00
|
|
|
renderbrush->pipe_timeout_id = 0;
|
|
|
|
renderbrush->pipe_animation_index = 0;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
brush_pipe = GIMP_BRUSH_PIPE (renderer->viewable);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderbrush->pipe_animation_index++;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderbrush->pipe_animation_index >= brush_pipe->nbrushes)
|
|
|
|
renderbrush->pipe_animation_index = 0;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2002-11-07 18:18:20 +08:00
|
|
|
brush =
|
2003-03-01 11:53:41 +08:00
|
|
|
GIMP_BRUSH (brush_pipe->brushes[renderbrush->pipe_animation_index]);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
|
|
|
temp_buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (brush),
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-04 01:19:30 +08:00
|
|
|
gimp_preview_renderer_render_buffer (renderer, temp_buf, -1,
|
|
|
|
GIMP_PREVIEW_BG_WHITE,
|
|
|
|
GIMP_PREVIEW_BG_WHITE);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
gimp_preview_renderer_update (renderer);
|
2002-11-07 18:18:20 +08:00
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|