app/Makefile.am app/apptypes.h new widget.

2001-02-23  Michael Natterer  <mitch@gimp.org>

	* app/Makefile.am
	* app/apptypes.h
	* app/gimptoolinfopreview.[ch]: new widget.

	* app/gimppreview.c
	* app/tools/gimptoolinfo.c
	* app/gimpdnd.c: changed for the tool info preview. Still buggy
	and looks a bit funny at the moment :-)

	* app/commands.[ch]
	* app/menus.c: small new feature: shift-X toggles the whole context.
This commit is contained in:
Michael Natterer 2001-02-23 03:29:53 +00:00 committed by Michael Natterer
parent f765a8216f
commit 69ba1531cb
28 changed files with 706 additions and 10 deletions

View File

@ -1,3 +1,17 @@
2001-02-23 Michael Natterer <mitch@gimp.org>
* app/Makefile.am
* app/apptypes.h
* app/gimptoolinfopreview.[ch]: new widget.
* app/gimppreview.c
* app/tools/gimptoolinfo.c
* app/gimpdnd.c: changed for the tool info preview. Still buggy
and looks a bit funny at the moment :-)
* app/commands.[ch]
* app/menus.c: small new feature: shift-X toggles the whole context.
2001-02-23 Michael Natterer <mitch@gimp.org>
* app/Makefile.am

View File

@ -305,6 +305,8 @@ gimp_SOURCES = \
gimppatternpreview.c \
gimppreview.h \
gimppreview.c \
gimptoolinfopreview.h \
gimptoolinfopreview.c \
gtkwrapbox.c \
gtkwrapbox.h \
gtkhwrapbox.c \

View File

@ -1111,6 +1111,31 @@ tools_swap_colors_cmd_callback (GtkWidget *widget,
gimp_context_swap_colors (gimp_context_get_user ());
}
void
tools_swap_contexts_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
static GimpContext *swap_context = NULL;
static GimpContext *temp_context = NULL;
if (! swap_context)
{
swap_context = gimp_context_new ("Swap Context",
gimp_context_get_user ());
temp_context = gimp_context_new ("Temp Context", NULL);
}
gimp_context_copy_args (gimp_context_get_user (),
temp_context,
GIMP_CONTEXT_ALL_ARGS_MASK);
gimp_context_copy_args (swap_context,
gimp_context_get_user (),
GIMP_CONTEXT_ALL_ARGS_MASK);
gimp_context_copy_args (temp_context,
swap_context,
GIMP_CONTEXT_ALL_ARGS_MASK);
}
void
tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,

View File

@ -106,6 +106,7 @@ void layers_resize_to_image_cmd_callback (GtkWidget *, gpointer);
void tools_default_colors_cmd_callback (GtkWidget *, gpointer);
void tools_swap_colors_cmd_callback (GtkWidget *, gpointer);
void tools_swap_contexts_cmd_callback (GtkWidget *, gpointer);
void tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,
guint callback_action);

View File

@ -89,6 +89,7 @@ typedef struct _GimpBrushPreview GimpBrushPreview;
typedef struct _GimpPatternPreview GimpPatternPreview;
typedef struct _GimpPalettePreview GimpPalettePreview;
typedef struct _GimpGradientPreview GimpGradientPreview;
typedef struct _GimpToolInfoPreview GimpToolInfoPreview;
typedef struct _GimpContainerView GimpContainerView;
typedef struct _GimpContainerListView GimpContainerListView;

View File

@ -1111,6 +1111,31 @@ tools_swap_colors_cmd_callback (GtkWidget *widget,
gimp_context_swap_colors (gimp_context_get_user ());
}
void
tools_swap_contexts_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
static GimpContext *swap_context = NULL;
static GimpContext *temp_context = NULL;
if (! swap_context)
{
swap_context = gimp_context_new ("Swap Context",
gimp_context_get_user ());
temp_context = gimp_context_new ("Temp Context", NULL);
}
gimp_context_copy_args (gimp_context_get_user (),
temp_context,
GIMP_CONTEXT_ALL_ARGS_MASK);
gimp_context_copy_args (swap_context,
gimp_context_get_user (),
GIMP_CONTEXT_ALL_ARGS_MASK);
gimp_context_copy_args (temp_context,
swap_context,
GIMP_CONTEXT_ALL_ARGS_MASK);
}
void
tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,

View File

@ -106,6 +106,7 @@ void layers_resize_to_image_cmd_callback (GtkWidget *, gpointer);
void tools_default_colors_cmd_callback (GtkWidget *, gpointer);
void tools_swap_colors_cmd_callback (GtkWidget *, gpointer);
void tools_swap_contexts_cmd_callback (GtkWidget *, gpointer);
void tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,
guint callback_action);

View File

@ -131,7 +131,9 @@ gimp_tool_info_get_new_preview (GimpViewable *viewable,
{
GimpToolInfo *tool_info;
TempBuf *temp_buf;
guchar white[3] = { 255, 255, 255 };
guchar opaque[4] = { 0, 0, 0, 0 };
gint offset_x = 0;
gint offset_y = 0;
gint r, s, cnt;
guchar value;
guchar *data;
@ -151,11 +153,20 @@ gimp_tool_info_get_new_preview (GimpViewable *viewable,
tool_info = GIMP_TOOL_INFO (viewable);
temp_buf = temp_buf_new (width, height, 3, 0, 0, white);
#define TOOL_INFO_WIDTH 22
#define TOOL_INFO_HEIGHT 22
if (width > TOOL_INFO_WIDTH)
offset_x = (width - TOOL_INFO_WIDTH) / 2;
if (height > TOOL_INFO_HEIGHT)
offset_y = (height - TOOL_INFO_HEIGHT) / 2;
temp_buf = temp_buf_new (width, height, 4, 0, 0, opaque);
data = temp_buf_data (temp_buf);
p = data;
p = data + (offset_y * temp_buf->width * temp_buf->bytes);
for (r = 0; r < height; r++)
{
@ -168,10 +179,11 @@ gimp_tool_info_get_new_preview (GimpViewable *viewable,
*p++ = colors[value - 'a'][0];
*p++ = colors[value - 'a'][1];
*p++ = colors[value - 'a'][2];
*p++ = 255;
}
else
{
p += 3;
p += 4;
}
}
}

View File

@ -773,7 +773,7 @@ gimp_gtk_drag_source_set_by_type (GtkWidget *widget,
target_table = palette_target_table;
n_targets = palette_n_targets;
}
else if (type == GIMP_TYPE_TOOL)
else if (type == GIMP_TYPE_TOOL_INFO)
{
target_table = tool_target_table;
n_targets = tool_n_targets;

View File

@ -29,6 +29,8 @@
#include "apptypes.h"
#include "tools/gimptoolinfo.h"
#include "gimpbrush.h"
#include "gimpbrushpreview.h"
#include "gimpdrawable.h"
@ -43,6 +45,7 @@
#include "gimppattern.h"
#include "gimppatternpreview.h"
#include "gimppreview.h"
#include "gimptoolinfopreview.h"
#include "gimpviewable.h"
#include "image_render.h"
#include "temp_buf.h"
@ -310,6 +313,10 @@ gimp_preview_new (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);
@ -373,6 +380,10 @@ gimp_preview_new_full (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);

183
app/gimptoolinfopreview.c Normal file
View File

@ -0,0 +1,183 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpToolInfoPreview Widget
* Copyright (C) 2001 Michael Natterer
*
* 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>
#include "apptypes.h"
#include "tools/gimptoolinfo.h"
#include "gimpdnd.h"
#include "gimptoolinfopreview.h"
#include "temp_buf.h"
/* FIXME: make tool icons nicer */
#define TOOL_INFO_SIZE 22
static void gimp_tool_info_preview_class_init (GimpToolInfoPreviewClass *klass);
static void gimp_tool_info_preview_init (GimpToolInfoPreview *preview);
static void gimp_tool_info_preview_render (GimpPreview *preview);
static GtkWidget * gimp_tool_info_preview_create_popup (GimpPreview *preview);
static gboolean gimp_tool_info_preview_needs_popup (GimpPreview *preview);
static GimpViewable * gimp_tool_info_preview_drag_viewable (GtkWidget *widget,
gpointer data);
static GimpPreviewClass *parent_class = NULL;
GtkType
gimp_tool_info_preview_get_type (void)
{
static GtkType preview_type = 0;
if (! preview_type)
{
GtkTypeInfo preview_info =
{
"GimpToolInfoPreview",
sizeof (GimpToolInfoPreview),
sizeof (GimpToolInfoPreviewClass),
(GtkClassInitFunc) gimp_tool_info_preview_class_init,
(GtkObjectInitFunc) gimp_tool_info_preview_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
preview_type = gtk_type_unique (GIMP_TYPE_PREVIEW, &preview_info);
}
return preview_type;
}
static void
gimp_tool_info_preview_class_init (GimpToolInfoPreviewClass *klass)
{
GtkObjectClass *object_class;
GimpPreviewClass *preview_class;
object_class = (GtkObjectClass *) klass;
preview_class = (GimpPreviewClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_PREVIEW);
preview_class->render = gimp_tool_info_preview_render;
preview_class->create_popup = gimp_tool_info_preview_create_popup;
preview_class->needs_popup = gimp_tool_info_preview_needs_popup;
}
static void
gimp_tool_info_preview_init (GimpToolInfoPreview *tool_info_preview)
{
gimp_gtk_drag_source_set_by_type (GTK_WIDGET (tool_info_preview),
GDK_BUTTON2_MASK,
GIMP_TYPE_TOOL_INFO,
GDK_ACTION_COPY);
gimp_dnd_viewable_source_set (GTK_WIDGET (tool_info_preview),
GIMP_TYPE_TOOL_INFO,
gimp_tool_info_preview_drag_viewable,
NULL);
}
static void
gimp_tool_info_preview_render (GimpPreview *preview)
{
GimpToolInfo *tool_info;
TempBuf *temp_buf;
gint width;
gint height;
gint tool_info_width;
gint tool_info_height;
tool_info = GIMP_TOOL_INFO (preview->viewable);
tool_info_width = TOOL_INFO_SIZE;
tool_info_height = TOOL_INFO_SIZE;
width = preview->width;
height = preview->height;
if (width == tool_info_width &&
height == tool_info_height)
{
/* TODO once tool icons are finished */
}
else if (width <= tool_info_width &&
height <= tool_info_height)
{
/* dito */
}
temp_buf = gimp_viewable_get_new_preview (preview->viewable,
width, height);
gimp_preview_render_and_flush (preview,
temp_buf,
-1);
temp_buf_free (temp_buf);
}
static GtkWidget *
gimp_tool_info_preview_create_popup (GimpPreview *preview)
{
gint popup_width;
gint popup_height;
popup_width = TOOL_INFO_SIZE;
popup_height = TOOL_INFO_SIZE;
return gimp_preview_new_full (preview->viewable,
popup_width,
popup_height,
0,
TRUE, FALSE, FALSE);
}
static gboolean
gimp_tool_info_preview_needs_popup (GimpPreview *preview)
{
GimpToolInfo *tool_info;
gint tool_info_width;
gint tool_info_height;
tool_info = GIMP_TOOL_INFO (preview->viewable);
tool_info_width = TOOL_INFO_SIZE;
tool_info_height = TOOL_INFO_SIZE;
if (tool_info_width > preview->width || tool_info_height > preview->height)
return TRUE;
return FALSE;
}
static GimpViewable *
gimp_tool_info_preview_drag_viewable (GtkWidget *widget,
gpointer data)
{
return GIMP_PREVIEW (widget)->viewable;
}

61
app/gimptoolinfopreview.h Normal file
View File

@ -0,0 +1,61 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpToolInfoPreview Widget
* Copyright (C) 2001 Michael Natterer
*
* 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.
*/
#ifndef __GIMP_TOOL_INFO_PREVIEW_H__
#define __GIMP_TOOL_INFO_PREVIEW_H__
#include "gimppreview.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GIMP_TYPE_TOOL_INFO_PREVIEW (gimp_tool_info_preview_get_type ())
#define GIMP_TOOL_INFO_PREVIEW(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_TOOL_INFO_PREVIEW, GimpToolInfoPreview))
#define GIMP_TOOL_INFO_PREVIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_INFO_PREVIEW, GimpToolInfoPreviewClass))
#define GIMP_IS_TOOL_INFO_PREVIEW(obj) (GTK_CHECK_TYPE (obj, GIMP_TYPE_TOOL_INFO_PREVIEW))
#define GIMP_IS_TOOL_INFO_PREVIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_INFO_PREVIEW))
typedef struct _GimpToolInfoPreviewClass GimpToolInfoPreviewClass;
struct _GimpToolInfoPreview
{
GimpPreview parent_instance;
};
struct _GimpToolInfoPreviewClass
{
GimpPreviewClass parent_class;
};
GtkType gimp_tool_info_preview_get_type (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GIMP_TOOL_INFO_PREVIEW_H__ */

View File

@ -1111,6 +1111,31 @@ tools_swap_colors_cmd_callback (GtkWidget *widget,
gimp_context_swap_colors (gimp_context_get_user ());
}
void
tools_swap_contexts_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
static GimpContext *swap_context = NULL;
static GimpContext *temp_context = NULL;
if (! swap_context)
{
swap_context = gimp_context_new ("Swap Context",
gimp_context_get_user ());
temp_context = gimp_context_new ("Temp Context", NULL);
}
gimp_context_copy_args (gimp_context_get_user (),
temp_context,
GIMP_CONTEXT_ALL_ARGS_MASK);
gimp_context_copy_args (swap_context,
gimp_context_get_user (),
GIMP_CONTEXT_ALL_ARGS_MASK);
gimp_context_copy_args (temp_context,
swap_context,
GIMP_CONTEXT_ALL_ARGS_MASK);
}
void
tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,

View File

@ -106,6 +106,7 @@ void layers_resize_to_image_cmd_callback (GtkWidget *, gpointer);
void tools_default_colors_cmd_callback (GtkWidget *, gpointer);
void tools_swap_colors_cmd_callback (GtkWidget *, gpointer);
void tools_swap_contexts_cmd_callback (GtkWidget *, gpointer);
void tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,
guint callback_action);

View File

@ -1111,6 +1111,31 @@ tools_swap_colors_cmd_callback (GtkWidget *widget,
gimp_context_swap_colors (gimp_context_get_user ());
}
void
tools_swap_contexts_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
static GimpContext *swap_context = NULL;
static GimpContext *temp_context = NULL;
if (! swap_context)
{
swap_context = gimp_context_new ("Swap Context",
gimp_context_get_user ());
temp_context = gimp_context_new ("Temp Context", NULL);
}
gimp_context_copy_args (gimp_context_get_user (),
temp_context,
GIMP_CONTEXT_ALL_ARGS_MASK);
gimp_context_copy_args (swap_context,
gimp_context_get_user (),
GIMP_CONTEXT_ALL_ARGS_MASK);
gimp_context_copy_args (temp_context,
swap_context,
GIMP_CONTEXT_ALL_ARGS_MASK);
}
void
tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,

View File

@ -106,6 +106,7 @@ void layers_resize_to_image_cmd_callback (GtkWidget *, gpointer);
void tools_default_colors_cmd_callback (GtkWidget *, gpointer);
void tools_swap_colors_cmd_callback (GtkWidget *, gpointer);
void tools_swap_contexts_cmd_callback (GtkWidget *, gpointer);
void tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,
guint callback_action);

View File

@ -530,6 +530,8 @@ static GimpItemFactoryEntry image_entries[] =
"toolbox/toolbox.html#default_colors", NULL },
{ { N_("/Tools/Swap Colors"), "X", tools_swap_colors_cmd_callback, 0 },
"toolbox/toolbox.html#swap_colors", NULL },
{ { N_("/Tools/Swap Contexts"), "<shift>X", tools_swap_contexts_cmd_callback, 0 },
"toolbox/toolbox.html#swap_colors", NULL },
{ { "/Tools/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },

View File

@ -530,6 +530,8 @@ static GimpItemFactoryEntry image_entries[] =
"toolbox/toolbox.html#default_colors", NULL },
{ { N_("/Tools/Swap Colors"), "X", tools_swap_colors_cmd_callback, 0 },
"toolbox/toolbox.html#swap_colors", NULL },
{ { N_("/Tools/Swap Contexts"), "<shift>X", tools_swap_contexts_cmd_callback, 0 },
"toolbox/toolbox.html#swap_colors", NULL },
{ { "/Tools/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },

View File

@ -530,6 +530,8 @@ static GimpItemFactoryEntry image_entries[] =
"toolbox/toolbox.html#default_colors", NULL },
{ { N_("/Tools/Swap Colors"), "X", tools_swap_colors_cmd_callback, 0 },
"toolbox/toolbox.html#swap_colors", NULL },
{ { N_("/Tools/Swap Contexts"), "<shift>X", tools_swap_contexts_cmd_callback, 0 },
"toolbox/toolbox.html#swap_colors", NULL },
{ { "/Tools/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },

View File

@ -131,7 +131,9 @@ gimp_tool_info_get_new_preview (GimpViewable *viewable,
{
GimpToolInfo *tool_info;
TempBuf *temp_buf;
guchar white[3] = { 255, 255, 255 };
guchar opaque[4] = { 0, 0, 0, 0 };
gint offset_x = 0;
gint offset_y = 0;
gint r, s, cnt;
guchar value;
guchar *data;
@ -151,11 +153,20 @@ gimp_tool_info_get_new_preview (GimpViewable *viewable,
tool_info = GIMP_TOOL_INFO (viewable);
temp_buf = temp_buf_new (width, height, 3, 0, 0, white);
#define TOOL_INFO_WIDTH 22
#define TOOL_INFO_HEIGHT 22
if (width > TOOL_INFO_WIDTH)
offset_x = (width - TOOL_INFO_WIDTH) / 2;
if (height > TOOL_INFO_HEIGHT)
offset_y = (height - TOOL_INFO_HEIGHT) / 2;
temp_buf = temp_buf_new (width, height, 4, 0, 0, opaque);
data = temp_buf_data (temp_buf);
p = data;
p = data + (offset_y * temp_buf->width * temp_buf->bytes);
for (r = 0; r < height; r++)
{
@ -168,10 +179,11 @@ gimp_tool_info_get_new_preview (GimpViewable *viewable,
*p++ = colors[value - 'a'][0];
*p++ = colors[value - 'a'][1];
*p++ = colors[value - 'a'][2];
*p++ = 255;
}
else
{
p += 3;
p += 4;
}
}
}

View File

@ -773,7 +773,7 @@ gimp_gtk_drag_source_set_by_type (GtkWidget *widget,
target_table = palette_target_table;
n_targets = palette_n_targets;
}
else if (type == GIMP_TYPE_TOOL)
else if (type == GIMP_TYPE_TOOL_INFO)
{
target_table = tool_target_table;
n_targets = tool_n_targets;

View File

@ -530,6 +530,8 @@ static GimpItemFactoryEntry image_entries[] =
"toolbox/toolbox.html#default_colors", NULL },
{ { N_("/Tools/Swap Colors"), "X", tools_swap_colors_cmd_callback, 0 },
"toolbox/toolbox.html#swap_colors", NULL },
{ { N_("/Tools/Swap Contexts"), "<shift>X", tools_swap_contexts_cmd_callback, 0 },
"toolbox/toolbox.html#swap_colors", NULL },
{ { "/Tools/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },

View File

@ -29,6 +29,8 @@
#include "apptypes.h"
#include "tools/gimptoolinfo.h"
#include "gimpbrush.h"
#include "gimpbrushpreview.h"
#include "gimpdrawable.h"
@ -43,6 +45,7 @@
#include "gimppattern.h"
#include "gimppatternpreview.h"
#include "gimppreview.h"
#include "gimptoolinfopreview.h"
#include "gimpviewable.h"
#include "image_render.h"
#include "temp_buf.h"
@ -310,6 +313,10 @@ gimp_preview_new (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);
@ -373,6 +380,10 @@ gimp_preview_new_full (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);

View File

@ -29,6 +29,8 @@
#include "apptypes.h"
#include "tools/gimptoolinfo.h"
#include "gimpbrush.h"
#include "gimpbrushpreview.h"
#include "gimpdrawable.h"
@ -43,6 +45,7 @@
#include "gimppattern.h"
#include "gimppatternpreview.h"
#include "gimppreview.h"
#include "gimptoolinfopreview.h"
#include "gimpviewable.h"
#include "image_render.h"
#include "temp_buf.h"
@ -310,6 +313,10 @@ gimp_preview_new (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);
@ -373,6 +380,10 @@ gimp_preview_new_full (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);

View File

@ -0,0 +1,183 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpToolInfoPreview Widget
* Copyright (C) 2001 Michael Natterer
*
* 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>
#include "apptypes.h"
#include "tools/gimptoolinfo.h"
#include "gimpdnd.h"
#include "gimptoolinfopreview.h"
#include "temp_buf.h"
/* FIXME: make tool icons nicer */
#define TOOL_INFO_SIZE 22
static void gimp_tool_info_preview_class_init (GimpToolInfoPreviewClass *klass);
static void gimp_tool_info_preview_init (GimpToolInfoPreview *preview);
static void gimp_tool_info_preview_render (GimpPreview *preview);
static GtkWidget * gimp_tool_info_preview_create_popup (GimpPreview *preview);
static gboolean gimp_tool_info_preview_needs_popup (GimpPreview *preview);
static GimpViewable * gimp_tool_info_preview_drag_viewable (GtkWidget *widget,
gpointer data);
static GimpPreviewClass *parent_class = NULL;
GtkType
gimp_tool_info_preview_get_type (void)
{
static GtkType preview_type = 0;
if (! preview_type)
{
GtkTypeInfo preview_info =
{
"GimpToolInfoPreview",
sizeof (GimpToolInfoPreview),
sizeof (GimpToolInfoPreviewClass),
(GtkClassInitFunc) gimp_tool_info_preview_class_init,
(GtkObjectInitFunc) gimp_tool_info_preview_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
preview_type = gtk_type_unique (GIMP_TYPE_PREVIEW, &preview_info);
}
return preview_type;
}
static void
gimp_tool_info_preview_class_init (GimpToolInfoPreviewClass *klass)
{
GtkObjectClass *object_class;
GimpPreviewClass *preview_class;
object_class = (GtkObjectClass *) klass;
preview_class = (GimpPreviewClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_PREVIEW);
preview_class->render = gimp_tool_info_preview_render;
preview_class->create_popup = gimp_tool_info_preview_create_popup;
preview_class->needs_popup = gimp_tool_info_preview_needs_popup;
}
static void
gimp_tool_info_preview_init (GimpToolInfoPreview *tool_info_preview)
{
gimp_gtk_drag_source_set_by_type (GTK_WIDGET (tool_info_preview),
GDK_BUTTON2_MASK,
GIMP_TYPE_TOOL_INFO,
GDK_ACTION_COPY);
gimp_dnd_viewable_source_set (GTK_WIDGET (tool_info_preview),
GIMP_TYPE_TOOL_INFO,
gimp_tool_info_preview_drag_viewable,
NULL);
}
static void
gimp_tool_info_preview_render (GimpPreview *preview)
{
GimpToolInfo *tool_info;
TempBuf *temp_buf;
gint width;
gint height;
gint tool_info_width;
gint tool_info_height;
tool_info = GIMP_TOOL_INFO (preview->viewable);
tool_info_width = TOOL_INFO_SIZE;
tool_info_height = TOOL_INFO_SIZE;
width = preview->width;
height = preview->height;
if (width == tool_info_width &&
height == tool_info_height)
{
/* TODO once tool icons are finished */
}
else if (width <= tool_info_width &&
height <= tool_info_height)
{
/* dito */
}
temp_buf = gimp_viewable_get_new_preview (preview->viewable,
width, height);
gimp_preview_render_and_flush (preview,
temp_buf,
-1);
temp_buf_free (temp_buf);
}
static GtkWidget *
gimp_tool_info_preview_create_popup (GimpPreview *preview)
{
gint popup_width;
gint popup_height;
popup_width = TOOL_INFO_SIZE;
popup_height = TOOL_INFO_SIZE;
return gimp_preview_new_full (preview->viewable,
popup_width,
popup_height,
0,
TRUE, FALSE, FALSE);
}
static gboolean
gimp_tool_info_preview_needs_popup (GimpPreview *preview)
{
GimpToolInfo *tool_info;
gint tool_info_width;
gint tool_info_height;
tool_info = GIMP_TOOL_INFO (preview->viewable);
tool_info_width = TOOL_INFO_SIZE;
tool_info_height = TOOL_INFO_SIZE;
if (tool_info_width > preview->width || tool_info_height > preview->height)
return TRUE;
return FALSE;
}
static GimpViewable *
gimp_tool_info_preview_drag_viewable (GtkWidget *widget,
gpointer data)
{
return GIMP_PREVIEW (widget)->viewable;
}

View File

@ -0,0 +1,61 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpToolInfoPreview Widget
* Copyright (C) 2001 Michael Natterer
*
* 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.
*/
#ifndef __GIMP_TOOL_INFO_PREVIEW_H__
#define __GIMP_TOOL_INFO_PREVIEW_H__
#include "gimppreview.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GIMP_TYPE_TOOL_INFO_PREVIEW (gimp_tool_info_preview_get_type ())
#define GIMP_TOOL_INFO_PREVIEW(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_TOOL_INFO_PREVIEW, GimpToolInfoPreview))
#define GIMP_TOOL_INFO_PREVIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_INFO_PREVIEW, GimpToolInfoPreviewClass))
#define GIMP_IS_TOOL_INFO_PREVIEW(obj) (GTK_CHECK_TYPE (obj, GIMP_TYPE_TOOL_INFO_PREVIEW))
#define GIMP_IS_TOOL_INFO_PREVIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_INFO_PREVIEW))
typedef struct _GimpToolInfoPreviewClass GimpToolInfoPreviewClass;
struct _GimpToolInfoPreview
{
GimpPreview parent_instance;
};
struct _GimpToolInfoPreviewClass
{
GimpPreviewClass parent_class;
};
GtkType gimp_tool_info_preview_get_type (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GIMP_TOOL_INFO_PREVIEW_H__ */

View File

@ -29,6 +29,8 @@
#include "apptypes.h"
#include "tools/gimptoolinfo.h"
#include "gimpbrush.h"
#include "gimpbrushpreview.h"
#include "gimpdrawable.h"
@ -43,6 +45,7 @@
#include "gimppattern.h"
#include "gimppatternpreview.h"
#include "gimppreview.h"
#include "gimptoolinfopreview.h"
#include "gimpviewable.h"
#include "image_render.h"
#include "temp_buf.h"
@ -310,6 +313,10 @@ gimp_preview_new (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);
@ -373,6 +380,10 @@ gimp_preview_new_full (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);

View File

@ -29,6 +29,8 @@
#include "apptypes.h"
#include "tools/gimptoolinfo.h"
#include "gimpbrush.h"
#include "gimpbrushpreview.h"
#include "gimpdrawable.h"
@ -43,6 +45,7 @@
#include "gimppattern.h"
#include "gimppatternpreview.h"
#include "gimppreview.h"
#include "gimptoolinfopreview.h"
#include "gimpviewable.h"
#include "image_render.h"
#include "temp_buf.h"
@ -310,6 +313,10 @@ gimp_preview_new (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);
@ -373,6 +380,10 @@ gimp_preview_new_full (GimpViewable *viewable,
{
preview = gtk_type_new (GIMP_TYPE_PALETTE_PREVIEW);
}
else if (GIMP_IS_TOOL_INFO (viewable))
{
preview = gtk_type_new (GIMP_TYPE_TOOL_INFO_PREVIEW);
}
else
{
preview = gtk_type_new (GIMP_TYPE_PREVIEW);