2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-02-07 08:06:58 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-08-26 22:20:30 +08:00
|
|
|
* gimpviewrendererbrush.c
|
2003-03-01 11:53:41 +08:00
|
|
|
* 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/gimpbrushpipe.h"
|
2004-09-07 07:55:24 +08:00
|
|
|
#include "core/gimpbrushgenerated.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
#include "gimpviewrendererbrush.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2007-11-05 04:30:38 +08:00
|
|
|
static void gimp_view_renderer_brush_finalize (GObject *object);
|
|
|
|
static void gimp_view_renderer_brush_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
|
|
|
static void gimp_view_renderer_brush_draw (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget,
|
|
|
|
cairo_t *cr,
|
|
|
|
const GdkRectangle *area);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2007-11-05 04:30:38 +08:00
|
|
|
static gboolean gimp_view_renderer_brush_render_timeout (gpointer data);
|
2001-02-07 08:06:58 +08:00
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
G_DEFINE_TYPE (GimpViewRendererBrush, gimp_view_renderer_brush,
|
2006-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_VIEW_RENDERER)
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_view_renderer_brush_parent_class
|
2001-02-07 08:06:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_brush_class_init (GimpViewRendererBrushClass *klass)
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2004-09-09 19:58:49 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpViewRendererClass *renderer_class = GIMP_VIEW_RENDERER_CLASS (klass);
|
2001-02-07 08:06:58 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
object_class->finalize = gimp_view_renderer_brush_finalize;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
renderer_class->render = gimp_view_renderer_brush_render;
|
2007-11-05 04:30:38 +08:00
|
|
|
renderer_class->draw = gimp_view_renderer_brush_draw;
|
2001-02-07 08:06:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_brush_init (GimpViewRendererBrush *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
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_brush_finalize (GObject *object)
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2004-08-26 22:20:30 +08:00
|
|
|
GimpViewRendererBrush *renderer = GIMP_VIEW_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
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_brush_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget)
|
2001-02-07 11:14:38 +08:00
|
|
|
{
|
2004-09-09 19:58:49 +08:00
|
|
|
GimpViewRendererBrush *renderbrush = GIMP_VIEW_RENDERER_BRUSH (renderer);
|
2004-08-26 22:20:30 +08:00
|
|
|
TempBuf *temp_buf;
|
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
|
|
|
temp_buf = gimp_viewable_get_new_preview (renderer->viewable,
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->context,
|
2003-03-01 11:53:41 +08:00
|
|
|
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
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_renderer_render_surface (renderer, temp_buf, -1,
|
|
|
|
GIMP_VIEW_BG_WHITE,
|
|
|
|
GIMP_VIEW_BG_WHITE);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
|
|
|
|
2006-05-11 04:23:28 +08:00
|
|
|
if (GIMP_IS_BRUSH_PIPE (renderer->viewable))
|
2004-08-26 06:31:44 +08:00
|
|
|
{
|
|
|
|
renderbrush->pipe_animation_index = 0;
|
|
|
|
renderbrush->pipe_timeout_id =
|
2004-08-26 22:20:30 +08:00
|
|
|
g_timeout_add (300, gimp_view_renderer_brush_render_timeout,
|
2003-03-01 11:53:41 +08:00
|
|
|
renderbrush);
|
2004-08-26 06:31:44 +08:00
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2001-02-08 02:01:54 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_renderer_render_surface (renderer, temp_buf, -1,
|
|
|
|
GIMP_VIEW_BG_WHITE,
|
|
|
|
GIMP_VIEW_BG_WHITE);
|
2003-03-01 20:55:43 +08:00
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
2001-02-07 11:14:38 +08:00
|
|
|
}
|
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
static gboolean
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_brush_render_timeout (gpointer data)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2004-09-09 19:58:49 +08:00
|
|
|
GimpViewRendererBrush *renderbrush = GIMP_VIEW_RENDERER_BRUSH (data);
|
|
|
|
GimpViewRenderer *renderer = GIMP_VIEW_RENDERER (data);
|
2004-08-26 22:20:30 +08:00
|
|
|
GimpBrushPipe *brush_pipe;
|
|
|
|
GimpBrush *brush;
|
|
|
|
TempBuf *temp_buf;
|
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),
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->context,
|
2004-08-26 06:31:44 +08:00
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2005-06-05 08:03:24 +08:00
|
|
|
if (temp_buf->width < renderer->width)
|
|
|
|
temp_buf->x = (renderer->width - temp_buf->width) / 2;
|
|
|
|
|
|
|
|
if (temp_buf->height < renderer->height)
|
|
|
|
temp_buf->y = (renderer->height - temp_buf->height) / 2;
|
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_renderer_render_surface (renderer, temp_buf, -1,
|
|
|
|
GIMP_VIEW_BG_WHITE,
|
|
|
|
GIMP_VIEW_BG_WHITE);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_update (renderer);
|
2002-11-07 18:18:20 +08:00
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
2007-11-05 04:30:38 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_view_renderer_brush_draw (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget,
|
|
|
|
cairo_t *cr,
|
|
|
|
const GdkRectangle *area)
|
|
|
|
{
|
|
|
|
GIMP_VIEW_RENDERER_CLASS (parent_class)->draw (renderer, widget, cr, area);
|
|
|
|
|
|
|
|
#define INDICATOR_WIDTH 7
|
|
|
|
#define INDICATOR_HEIGHT 7
|
|
|
|
|
|
|
|
if (renderer->width >= INDICATOR_WIDTH * 2 &&
|
|
|
|
renderer->height >= INDICATOR_HEIGHT * 2)
|
|
|
|
{
|
|
|
|
gboolean pipe = GIMP_IS_BRUSH_PIPE (renderer->viewable);
|
|
|
|
gboolean generated = GIMP_IS_BRUSH_GENERATED (renderer->viewable);
|
|
|
|
gint brush_width;
|
|
|
|
gint brush_height;
|
|
|
|
|
|
|
|
if (generated || pipe)
|
|
|
|
{
|
|
|
|
cairo_move_to (cr, area->x + area->width, area->y + area->height);
|
|
|
|
cairo_rel_line_to (cr, - INDICATOR_WIDTH, 0);
|
|
|
|
cairo_rel_line_to (cr, INDICATOR_WIDTH, - INDICATOR_HEIGHT);
|
|
|
|
cairo_rel_line_to (cr, 0, INDICATOR_HEIGHT);
|
|
|
|
|
|
|
|
if (pipe)
|
|
|
|
cairo_set_source_rgb (cr, 1.0, 0.5, 0.5);
|
|
|
|
else
|
|
|
|
cairo_set_source_rgb (cr, 0.5, 0.6, 1.0);
|
|
|
|
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_viewable_get_size (renderer->viewable, &brush_width, &brush_height);
|
|
|
|
|
|
|
|
if (renderer->width < brush_width || renderer->height < brush_height)
|
|
|
|
{
|
|
|
|
cairo_move_to (cr,
|
|
|
|
area->x + area->width - INDICATOR_WIDTH + 1,
|
|
|
|
area->y + area->height - INDICATOR_HEIGHT / 2.0);
|
|
|
|
cairo_rel_line_to (cr, INDICATOR_WIDTH - 2, 0);
|
|
|
|
|
|
|
|
cairo_move_to (cr,
|
|
|
|
area->x + area->width - INDICATOR_WIDTH / 2.0,
|
|
|
|
area->y + area->height - INDICATOR_HEIGHT + 1);
|
|
|
|
cairo_rel_line_to (cr, 0, INDICATOR_WIDTH - 2);
|
|
|
|
|
|
|
|
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
|
|
|
|
cairo_set_line_width (cr, 1);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef INDICATOR_WIDTH
|
|
|
|
#undef INDICATOR_HEIGHT
|
|
|
|
}
|