don't use gimp_drawable_configure() to resize the text layer, it should

2003-01-31  Sven Neumann  <sven@gimp.org>

	* app/text/gimptextlayer.c: don't use gimp_drawable_configure() to
	resize the text layer, it should only ever be called once. Take
	the logical rectangle into account when calculating the layer size
	and text position.

	* app/tools/gimptexttool.[ch]: added basic text editing
	functionality. Needs more work ...

	* themes/Default/images/Makefile.am
	* themes/Default/images/stock-gravity-east-24.png
	* themes/Default/images/stock-gravity-north-24.png
	* themes/Default/images/stock-gravity-north-east-24.png
	* themes/Default/images/stock-gravity-north-west-24.png
	* themes/Default/images/stock-gravity-south-24.png
	* themes/Default/images/stock-gravity-south-east-24.png
	* themes/Default/images/stock-gravity-south-west-24.png

	* themes/Default/images/stock-gravity-west-24.png: added new icons
	for yet-to-written GimpGravityChooser(?) widget. Artwork
	shamelessly taken from Jimmac's XFree cursors.

	* libgimpwidgets/gimpstock.[ch]: added stock items for the new icons.
This commit is contained in:
Sven Neumann 2003-01-31 18:57:10 +00:00 committed by Sven Neumann
parent 794885e297
commit 5e2c14ba8c
15 changed files with 196 additions and 101 deletions

View File

@ -1,3 +1,28 @@
2003-01-31 Sven Neumann <sven@gimp.org>
* app/text/gimptextlayer.c: don't use gimp_drawable_configure() to
resize the text layer, it should only ever be called once. Take
the logical rectangle into account when calculating the layer size
and text position.
* app/tools/gimptexttool.[ch]: added basic text editing
functionality. Needs more work ...
* themes/Default/images/Makefile.am
* themes/Default/images/stock-gravity-east-24.png
* themes/Default/images/stock-gravity-north-24.png
* themes/Default/images/stock-gravity-north-east-24.png
* themes/Default/images/stock-gravity-north-west-24.png
* themes/Default/images/stock-gravity-south-24.png
* themes/Default/images/stock-gravity-south-east-24.png
* themes/Default/images/stock-gravity-south-west-24.png
* themes/Default/images/stock-gravity-west-24.png: added new icons
for yet-to-written GimpGravityChooser(?) widget. Artwork
shamelessly taken from Jimmac's XFree cursors.
* libgimpwidgets/gimpstock.[ch]: added stock items for the new icons.
2003-01-31 Michael Natterer <mitch@gimp.org>
* app/core/gimpitem.[ch]: added gimp_item_configure() and

View File

@ -50,20 +50,17 @@ static TempBuf * gimp_text_layer_get_preview (GimpViewable *viewable,
gint width,
gint height);
static PangoLayout * gimp_text_layer_layout_new (GimpTextLayer *layer);
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
static gboolean gimp_text_layer_position_layout (GimpTextLayer *layer,
PangoLayout *layout,
gint *x,
gint *y,
gint *width,
gint *height);
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
PangoLayout *layout,
gint x,
gint y);
static PangoLayout * gimp_text_layer_layout_new (GimpTextLayer *layer);
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
static gboolean gimp_text_layer_position_layout (GimpTextLayer *layer,
PangoLayout *layout,
PangoRectangle *pos);
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
PangoLayout *layout,
gint x,
gint y);
static PangoContext * gimp_image_get_pango_context (GimpImage *image);
static PangoContext * gimp_image_get_pango_context (GimpImage *image);
static GimpLayerClass *parent_class = NULL;
@ -156,7 +153,11 @@ gimp_text_layer_new (GimpImage *image,
layer = g_object_new (GIMP_TYPE_TEXT_LAYER, NULL);
gimp_item_set_image (GIMP_ITEM (layer), image);
gimp_drawable_configure (GIMP_DRAWABLE (layer),
image,
0, 0, 0, 0,
gimp_image_base_type_with_alpha (image),
NULL);
layer->text = g_object_ref (text);
@ -209,65 +210,65 @@ gimp_text_layer_get_preview (GimpViewable *viewable,
width, height);
}
static gboolean
gimp_text_layer_render (GimpTextLayer *layer)
{
GimpImage *image;
GimpDrawable *drawable;
PangoLayout *layout;
gchar *name;
gchar *newline;
gint x, y;
gint width, height;
GimpImage *image;
GimpDrawable *drawable;
PangoLayout *layout;
PangoRectangle pos;
gchar *name;
gchar *newline;
layout = gimp_text_layer_layout_new (layer);
if (!gimp_text_layer_position_layout (layer, layout,
&x, &y, &width, &height))
if (!gimp_text_layer_position_layout (layer, layout, &pos))
{
g_object_unref (layout);
return FALSE;
}
newline = strchr (layer->text->text, '\n');
if (newline)
name = g_strndup (layer->text->text, newline - layer->text->text);
else
name = layer->text->text;
image = gimp_item_get_image (GIMP_ITEM (layer));
drawable = GIMP_DRAWABLE (layer);
if (width != gimp_drawable_width (drawable) ||
height != gimp_drawable_height (drawable))
if (pos.width != gimp_drawable_width (drawable) ||
pos.height != gimp_drawable_height (drawable))
{
gimp_drawable_update (GIMP_DRAWABLE (layer),
0, 0,
gimp_drawable_width (drawable),
gimp_drawable_height (drawable));
gimp_drawable_configure (drawable,
image,
drawable->offset_x,
drawable->offset_y,
width, height,
gimp_image_base_type_with_alpha (image),
name);
drawable->width = pos.width;
drawable->height = pos.height;
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
drawable->tiles = tile_manager_new (drawable->width,
drawable->height,
drawable->bytes);
gimp_viewable_size_changed (GIMP_VIEWABLE (layer));
}
else
{
gimp_object_set_name (GIMP_OBJECT (layer), name);
}
newline = strchr (layer->text->text, '\n');
if (newline)
g_free (name);
{
name = g_strndup (layer->text->text, newline - layer->text->text);
gimp_object_set_name (GIMP_OBJECT (layer), name);
g_free (name);
}
else
{
gimp_object_set_name (GIMP_OBJECT (layer), layer->text->text);
}
gimp_text_layer_render_layout (layer, layout, x, y);
gimp_text_layer_render_layout (layer, layout, pos.x, pos.y);
g_object_unref (layout);
gimp_drawable_update (drawable, 0, 0, pos.width, pos.height);
gimp_image_flush (image);
return TRUE;
@ -328,16 +329,15 @@ gimp_text_layer_layout_new (GimpTextLayer *layer)
}
static gboolean
gimp_text_layer_position_layout (GimpTextLayer *layer,
PangoLayout *layout,
gint *x,
gint *y,
gint *width,
gint *height)
gimp_text_layer_position_layout (GimpTextLayer *layer,
PangoLayout *layout,
PangoRectangle *pos)
{
GimpText *text;
PangoRectangle ink;
PangoRectangle logical;
gint x1, y1;
gint x2, y2;
gboolean fixed;
text = layer->text;
@ -360,8 +360,13 @@ gimp_text_layer_position_layout (GimpTextLayer *layer,
if (ink.height > 8192) ink.height = 8192;
}
*width = fixed ? text->fixed_width : ink.width;
*height = fixed ? text->fixed_height : ink.height;
x1 = MIN (0, logical.x);
y1 = MIN (0, logical.y);
x2 = MAX (ink.x + ink.width, logical.x + logical.width);
y2 = MAX (ink.y + ink.height, logical.y + logical.height);
pos->width = fixed ? text->fixed_width : x2 - x1;
pos->height = fixed ? text->fixed_height : y2 - y1;
/* border should only be used by the compatibility API;
we assume that gravity is CENTER
@ -370,12 +375,12 @@ gimp_text_layer_position_layout (GimpTextLayer *layer,
{
fixed = TRUE;
*width = ink.width + 2 * text->border;
*height = ink.height + 2 * text->border;
pos->width += 2 * text->border;
pos->height += 2 * text->border;
}
*x = - ink.x;
*y = - ink.y;
pos->x = - ink.x;
pos->y = - ink.y;
if (!fixed)
return TRUE;
@ -390,13 +395,13 @@ gimp_text_layer_position_layout (GimpTextLayer *layer,
case GIMP_GRAVITY_CENTER:
case GIMP_GRAVITY_NORTH:
case GIMP_GRAVITY_SOUTH:
*x += (*width - ink.width) / 2;
pos->x += (pos->width - logical.width) / 2;
break;
case GIMP_GRAVITY_NORTH_EAST:
case GIMP_GRAVITY_SOUTH_EAST:
case GIMP_GRAVITY_EAST:
*x += (*width - ink.width);
pos->x += (pos->width - logical.width);
break;
}
@ -410,13 +415,13 @@ gimp_text_layer_position_layout (GimpTextLayer *layer,
case GIMP_GRAVITY_CENTER:
case GIMP_GRAVITY_WEST:
case GIMP_GRAVITY_EAST:
*y += (*height - ink.height) / 2;
pos->y += (pos->height - logical.height) / 2;
break;
case GIMP_GRAVITY_SOUTH:
case GIMP_GRAVITY_SOUTH_WEST:
case GIMP_GRAVITY_SOUTH_EAST:
*y += (*height - ink.height);
pos->y += (pos->height - logical.height);
break;
}
@ -451,8 +456,6 @@ gimp_text_layer_render_layout (GimpTextLayer *layer,
apply_mask_to_region (&textPR, &maskPR, OPAQUE_OPACITY);
tile_manager_destroy (mask);
gimp_drawable_update (drawable, 0, 0, width, height);
}

View File

@ -32,8 +32,6 @@
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "core/gimplayer-floating-sel.h"
#include "core/gimptoolinfo.h"
#include "text/gimptext.h"
@ -44,7 +42,6 @@
#include "display/gimpdisplay.h"
#include "gimpeditselectiontool.h"
#include "gimptexttool.h"
#include "tool_options.h"
@ -111,7 +108,10 @@ static void text_tool_cursor_update (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp);
static void text_tool_render (GimpTextTool *text_tool);
static void gimp_text_tool_connect (GimpTextTool *tool,
GimpText *text);
static void text_tool_create_layer (GimpTextTool *text_tool);
static GimpToolOptions * text_tool_options_new (GimpToolInfo *tool_info);
static void text_tool_options_reset (GimpToolOptions *tool_options);
@ -203,7 +203,9 @@ static void
gimp_text_tool_init (GimpTextTool *text_tool)
{
GimpTool *tool = GIMP_TOOL (text_tool);
text_tool->text = NULL;
text_tool->buffer = gtk_text_buffer_new (NULL);
gtk_text_buffer_set_text (text_tool->buffer, "Eeek, it's The GIMP", -1);
@ -241,6 +243,8 @@ text_tool_control (GimpTool *tool,
case HALT:
if (GIMP_TEXT_TOOL (tool)->editor)
gtk_widget_destroy (GIMP_TEXT_TOOL (tool)->editor);
gimp_text_tool_connect (GIMP_TEXT_TOOL (tool), NULL);
break;
default:
@ -258,7 +262,8 @@ text_tool_button_press (GimpTool *tool,
GimpDisplay *gdisp)
{
GimpTextTool *text_tool;
GimpLayer *layer;
GimpDrawable *drawable;
GimpText *text = NULL;
text_tool = GIMP_TEXT_TOOL (tool);
@ -270,15 +275,21 @@ text_tool_button_press (GimpTool *tool,
text_tool->click_x = coords->x;
text_tool->click_y = coords->y;
if ((layer = gimp_image_pick_correlate_layer (gdisp->gimage,
text_tool->click_x,
text_tool->click_y)))
/* if there is a floating selection, and this aint it, use the move tool */
if (gimp_layer_is_floating_sel (layer))
{
init_edit_selection (tool, gdisp, coords, EDIT_LAYER_TRANSLATE);
return;
}
drawable = gimp_image_active_drawable (gdisp->gimage);
if (drawable && GIMP_IS_TEXT_LAYER (drawable))
{
coords->x -= drawable->offset_x;
coords->y -= drawable->offset_y;
if (coords->x > 0 && coords->x < drawable->width &&
coords->y > 0 && coords->y < drawable->height)
{
text = gimp_text_layer_get_text (GIMP_TEXT_LAYER (drawable));
}
}
gimp_text_tool_connect (GIMP_TEXT_TOOL (tool), text);
text_tool_editor (text_tool);
}
@ -299,22 +310,11 @@ text_tool_cursor_update (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpLayer *layer;
layer = gimp_image_pick_correlate_layer (gdisp->gimage,
coords->x, coords->y);
gimp_tool_control_set_cursor_modifier (tool->control,
(layer &&
gimp_layer_is_floating_sel (layer)) ?
GIMP_CURSOR_MODIFIER_MOVE :
GIMP_CURSOR_MODIFIER_NONE);
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
}
static void
text_tool_render (GimpTextTool *text_tool)
text_tool_create_layer (GimpTextTool *text_tool)
{
TextOptions *options;
GimpImage *gimage;
@ -326,6 +326,8 @@ text_tool_render (GimpTextTool *text_tool)
GtkTextIter start_iter;
GtkTextIter end_iter;
g_return_if_fail (text_tool->text == NULL);
options = (TextOptions *) GIMP_TOOL (text_tool)->tool_info->tool_options;
gimage = text_tool->gdisp->gimage;
@ -344,7 +346,8 @@ text_tool_render (GimpTextTool *text_tool)
if (!str)
return;
gimp_context_get_foreground (gimp_get_current_context (gimage->gimp), &color);
gimp_context_get_foreground (gimp_get_current_context (gimage->gimp),
&color);
text = GIMP_TEXT (g_object_new (GIMP_TYPE_TEXT,
"text", str,
@ -369,20 +372,31 @@ text_tool_render (GimpTextTool *text_tool)
GIMP_DRAWABLE (layer)->offset_x = text_tool->click_x;
GIMP_DRAWABLE (layer)->offset_y = text_tool->click_y;
/* If there is a selection mask clear it--
* this might not always be desired, but in general,
* it seems like the correct behavior.
*/
if (! gimp_image_mask_is_empty (gimage))
gimp_image_mask_clear (gimage);
floating_sel_attach (layer, gimp_image_active_drawable (gimage));
gimp_image_add_layer (gimage, layer, -1);
undo_push_group_end (gimage);
gimp_image_flush (gimage);
}
static void
gimp_text_tool_connect (GimpTextTool *tool,
GimpText *text)
{
if (tool->text == text)
return;
if (tool->text)
{
g_object_unref (tool->text);
tool->text = NULL;
}
if (text)
tool->text = g_object_ref (text);
}
/* tool options stuff */
static GimpToolOptions *
@ -418,7 +432,7 @@ text_tool_options_new (GimpToolInfo *tool_info)
options->font_selection = gimp_font_selection_new (NULL);
gimp_font_selection_set_fontname
gimp_font_selection_set_fontname
(GIMP_FONT_SELECTION (options->font_selection), DEFAULT_FONT);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
@ -579,7 +593,25 @@ text_tool_editor_ok (GimpTextTool *text_tool)
{
gtk_widget_destroy (text_tool->editor);
text_tool_render (text_tool);
if (text_tool->text)
{
GtkTextIter start_iter;
GtkTextIter end_iter;
gchar *str;
gtk_text_buffer_get_bounds (text_tool->buffer, &start_iter, &end_iter);
str = gtk_text_buffer_get_text (text_tool->buffer,
&start_iter, &end_iter, FALSE);
if (str)
{
g_object_set (G_OBJECT (text_tool->text), "text", str, NULL);
g_free (str);
}
}
else
{
text_tool_create_layer (text_tool);
}
}
static void

View File

@ -39,6 +39,7 @@ struct _GimpTextTool
gint click_y;
GimpDisplay *gdisp;
GimpText *text;
GtkTextBuffer *buffer;
GtkWidget *editor;

View File

@ -97,6 +97,15 @@ static GtkStockItem gimp_stock_items[] =
{ GIMP_STOCK_RESET, N_("_Reset"), 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_VISIBLE, N_("Visible"), 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_EAST, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_NORTH, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_NORTH_EAST, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_NORTH_WEST, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_SOUTH, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_SOUTH_EAST, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_SOUTH_WEST, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_GRAVITY_WEST, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_HCHAIN, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_HCHAIN_BROKEN, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_VCHAIN, NULL, 0, 0, LIBGIMP_DOMAIN },
@ -210,6 +219,14 @@ gimp_stock_button_pixbufs[] =
{ GIMP_STOCK_VCHAIN, stock_vchain_24 },
{ GIMP_STOCK_VCHAIN_BROKEN, stock_vchain_broken_24 },
{ GIMP_STOCK_GRAVITY_EAST, stock_gravity_east_24 },
{ GIMP_STOCK_GRAVITY_NORTH, stock_gravity_north_24 },
{ GIMP_STOCK_GRAVITY_NORTH_EAST, stock_gravity_north_east_24 },
{ GIMP_STOCK_GRAVITY_NORTH_WEST, stock_gravity_north_west_24 },
{ GIMP_STOCK_GRAVITY_SOUTH, stock_gravity_south_24 },
{ GIMP_STOCK_GRAVITY_SOUTH_EAST, stock_gravity_south_east_24 },
{ GIMP_STOCK_GRAVITY_SOUTH_WEST, stock_gravity_south_west_24 },
{ GIMP_STOCK_COLOR_PICKER_BLACK, stock_color_picker_black_18 },
{ GIMP_STOCK_COLOR_PICKER_GRAY, stock_color_picker_gray_18 },
{ GIMP_STOCK_COLOR_PICKER_WHITE, stock_color_picker_white_18 },

View File

@ -39,6 +39,15 @@ G_BEGIN_DECLS
#define GIMP_STOCK_RESET "gimp-reset"
#define GIMP_STOCK_VISIBLE "gimp-visible"
#define GIMP_STOCK_GRAVITY_EAST "gimp-gravity-east"
#define GIMP_STOCK_GRAVITY_NORTH "gimp-gravity-north"
#define GIMP_STOCK_GRAVITY_NORTH_EAST "gimp-gravity-north-east"
#define GIMP_STOCK_GRAVITY_NORTH_WEST "gimp-gravity-north-west"
#define GIMP_STOCK_GRAVITY_SOUTH "gimp-gravity-south"
#define GIMP_STOCK_GRAVITY_SOUTH_EAST "gimp-gravity-south-east"
#define GIMP_STOCK_GRAVITY_SOUTH_WEST "gimp-gravity-south-west"
#define GIMP_STOCK_GRAVITY_WEST "gimp-gravity-west"
#define GIMP_STOCK_HCHAIN "gimp-hchain"
#define GIMP_STOCK_HCHAIN_BROKEN "gimp-hchain-broken"
#define GIMP_STOCK_VCHAIN "gimp-vchain"

View File

@ -50,6 +50,14 @@ STOCK_BUTTON_IMAGES = \
stock-duplicate-16.png \
stock-edit-16.png \
stock-eye-20.png \
stock-gravity-east-24.png \
stock-gravity-north-24.png \
stock-gravity-north-east-24.png \
stock-gravity-north-west-24.png \
stock-gravity-south-24.png \
stock-gravity-south-east-24.png \
stock-gravity-south-west-24.png \
stock-gravity-west-24.png \
stock-line-spacing-22.png \
stock-linked-20.png \
stock-letter-spacing-22.png \

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 B