[gimp] app: make the text style editor aware of the image's resolution
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: make the text style editor aware of the image's resolution
- Date: Sun, 28 Feb 2010 13:21:31 +0000 (UTC)
commit 1c8b01f01234395d78a9b57f0b7adbefe1aff639
Author: Michael Natterer <mitch gimp org>
Date: Sun Feb 28 14:20:56 2010 +0100
app: make the text style editor aware of the image's resolution
Needed for adding proper text size controls.
app/tools/gimptexttool-editor.c | 23 +++++++++++++-
app/widgets/gimptextstyleeditor.c | 62 ++++++++++++++++++++++++++++++++++---
app/widgets/gimptextstyleeditor.h | 9 +++++-
3 files changed, 87 insertions(+), 7 deletions(-)
---
diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c
index 93df349..3751218 100644
--- a/app/tools/gimptexttool-editor.c
+++ b/app/tools/gimptexttool-editor.c
@@ -30,6 +30,8 @@
#include "tools-types.h"
+#include "core/gimpimage.h"
+
#include "text/gimptext.h"
#include "text/gimptextlayout.h"
@@ -157,6 +159,9 @@ gimp_text_tool_editor_start (GimpTextTool *text_tool)
if (! text_tool->style_overlay)
{
+ gdouble xres = 1.0;
+ gdouble yres = 1.0;
+
text_tool->style_overlay = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (text_tool->style_overlay),
GTK_SHADOW_OUT);
@@ -166,7 +171,11 @@ gimp_text_tool_editor_start (GimpTextTool *text_tool)
gimp_overlay_box_set_child_opacity (GIMP_OVERLAY_BOX (shell->canvas),
text_tool->style_overlay, 0.7);
- text_tool->style_editor = gimp_text_style_editor_new (text_tool->buffer);
+ if (text_tool->image)
+ gimp_image_get_resolution (text_tool->image, &xres, &yres);
+
+ text_tool->style_editor = gimp_text_style_editor_new (text_tool->buffer,
+ xres, yres);
gtk_container_add (GTK_CONTAINER (text_tool->style_overlay),
text_tool->style_editor);
gtk_widget_show (text_tool->style_editor);
@@ -197,6 +206,18 @@ gimp_text_tool_editor_position (GimpTextTool *text_tool)
text_tool->style_overlay,
x + 2,
y - requisition.height - 6);
+
+ if (text_tool->image)
+ {
+ gdouble xres, yres;
+
+ gimp_image_get_resolution (text_tool->image, &xres, &yres);
+
+ g_object_set (text_tool->style_editor,
+ "resolution-x", xres,
+ "resolution-y", yres,
+ NULL);
+ }
}
}
diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c
index e49a5ff..d270398 100644
--- a/app/widgets/gimptextstyleeditor.c
+++ b/app/widgets/gimptextstyleeditor.c
@@ -23,6 +23,8 @@
#include <gegl.h>
#include <gtk/gtk.h>
+#include "libgimpbase/gimpbase.h"
+
#include "widgets-types.h"
#include "gimptextbuffer.h"
@@ -32,7 +34,9 @@
enum
{
PROP_0,
- PROP_BUFFER
+ PROP_BUFFER,
+ PROP_RESOLUTION_X,
+ PROP_RESOLUTION_Y
};
@@ -86,6 +90,24 @@ gimp_text_style_editor_class_init (GimpTextStyleEditorClass *klass)
GIMP_TYPE_TEXT_BUFFER,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (object_class, PROP_RESOLUTION_X,
+ g_param_spec_double ("resolution-x",
+ NULL, NULL,
+ GIMP_MIN_RESOLUTION,
+ GIMP_MAX_RESOLUTION,
+ 1.0,
+ GIMP_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (object_class, PROP_RESOLUTION_Y,
+ g_param_spec_double ("resolution-y",
+ NULL, NULL,
+ GIMP_MIN_RESOLUTION,
+ GIMP_MAX_RESOLUTION,
+ 1.0,
+ GIMP_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
}
static void
@@ -108,6 +130,11 @@ gimp_text_style_editor_init (GimpTextStyleEditor *editor)
image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (editor->clear_button), image);
gtk_widget_show (image);
+
+ editor->size_label = gtk_label_new ("0.0");
+ gtk_misc_set_padding (GTK_MISC (editor->size_label), 2, 0);
+ gtk_box_pack_end (GTK_BOX (editor), editor->size_label, FALSE, FALSE, 0);
+ gtk_widget_show (editor->size_label);
}
static GObject *
@@ -201,6 +228,12 @@ gimp_text_style_editor_set_property (GObject *object,
case PROP_BUFFER:
editor->buffer = g_value_dup_object (value);
break;
+ case PROP_RESOLUTION_X:
+ editor->resolution_x = g_value_get_double (value);
+ break;
+ case PROP_RESOLUTION_Y:
+ editor->resolution_y = g_value_get_double (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -221,6 +254,12 @@ gimp_text_style_editor_get_property (GObject *object,
case PROP_BUFFER:
g_value_set_object (value, editor->buffer);
break;
+ case PROP_RESOLUTION_X:
+ g_value_set_double (value, editor->resolution_x);
+ break;
+ case PROP_RESOLUTION_Y:
+ g_value_set_double (value, editor->resolution_y);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -232,12 +271,18 @@ gimp_text_style_editor_get_property (GObject *object,
/* public functions */
GtkWidget *
-gimp_text_style_editor_new (GimpTextBuffer *buffer)
+gimp_text_style_editor_new (GimpTextBuffer *buffer,
+ gdouble resolution_x,
+ gdouble resolution_y)
{
g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), NULL);
+ g_return_val_if_fail (resolution_x > 0.0, NULL);
+ g_return_val_if_fail (resolution_y > 0.0, NULL);
return g_object_new (GIMP_TYPE_TEXT_STYLE_EDITOR,
- "buffer", buffer,
+ "buffer", buffer,
+ "resolution-x", resolution_x,
+ "resolution-y", resolution_y,
NULL);
}
@@ -440,11 +485,14 @@ gimp_text_style_editor_update (GimpTextStyleEditor *editor)
if (! data.any_active)
break;
}
+
+ gtk_label_set_text (GTK_LABEL (editor->size_label), "---");
}
else
{
- UpdateTogglesData data;
- GtkTextIter cursor;
+ UpdateTogglesData data;
+ GtkTextIter cursor;
+ gchar *str;
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
gtk_text_buffer_get_insert (buffer));
@@ -458,6 +506,10 @@ gimp_text_style_editor_update (GimpTextStyleEditor *editor)
(GHFunc) gimp_text_style_editor_update_cursor,
&data);
+ str = g_strdup_printf ("%0.2f", editor->resolution_y);
+ gtk_label_set_text (GTK_LABEL (editor->size_label), str);
+ g_free (str);
+
g_slist_free (data.tags);
g_slist_free (data.tags_on);
g_slist_free (data.tags_off);
diff --git a/app/widgets/gimptextstyleeditor.h b/app/widgets/gimptextstyleeditor.h
index a070b44..4dbe5b4 100644
--- a/app/widgets/gimptextstyleeditor.h
+++ b/app/widgets/gimptextstyleeditor.h
@@ -38,12 +38,17 @@ struct _GimpTextStyleEditor
GimpTextBuffer *buffer;
+ gdouble resolution_x;
+ gdouble resolution_y;
+
GtkWidget *clear_button;
GtkWidget *bold_toggle;
GtkWidget *italic_toggle;
GtkWidget *underline_toggle;
GtkWidget *strikethrough_toggle;
+ GtkWidget *size_label;
+
GList *toggles;
GHashTable *tag_to_toggle_hash;
};
@@ -56,7 +61,9 @@ struct _GimpTextStyleEditorClass
GType gimp_text_style_editor_get_type (void) G_GNUC_CONST;
-GtkWidget * gimp_text_style_editor_new (GimpTextBuffer *buffer);
+GtkWidget * gimp_text_style_editor_new (GimpTextBuffer *buffer,
+ gdouble resolution_x,
+ gdouble resolution_y);
GList * gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]