[gthumb] added a custom GtkScale for the color selectors
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] added a custom GtkScale for the color selectors
- Date: Mon, 27 Aug 2012 12:53:51 +0000 (UTC)
commit c9db4eda2b194e8ba03f9841f47a5dffb7bf8e70
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Aug 27 13:28:44 2012 +0200
added a custom GtkScale for the color selectors
configure.ac | 13 +-
.../file_tools/gth-file-tool-adjust-colors.c | 49 ++-
extensions/file_tools/gth-file-tool-rotate.c | 25 +-
extensions/file_tools/gth-file-tool-sharpen.c | 21 +-
gthumb/Makefile.am | 26 ++-
gthumb/gth-color-scale.c | 417 ++++++++++++++++++++
gthumb/gth-color-scale.h | 75 ++++
gthumb/gth-window.c | 30 ++-
gthumb/gthumb.gresource.xml | 6 +
gthumb/gtk-utils.c | 41 --
gthumb/gtk-utils.h | 8 -
gthumb/resources/Makefile.am | 4 +
gthumb/resources/gthumb.css | 4 +
13 files changed, 618 insertions(+), 101 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index abaadfe..aa56b0b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
LT_INIT
-AC_SEARCH_LIBS([strerror],[cposix])
+AC_SEARCH_LIBS([strerror],[cposix], [])
AC_PROG_CC
AC_DIAGNOSE([obsolete],[AM_PROG_CC_STDC:
@@ -45,8 +45,9 @@ AC_C_BIGENDIAN
AC_PROG_CPP
AC_PROG_CXX
-AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
-AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
+AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal, glib-genmarshal)
+AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums, glib-mkenums)
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources, glib-compile-resources)
GNOME_COMMON_INIT
GNOME_DOC_INIT
@@ -156,11 +157,6 @@ AC_SUBST(GTHUMB_CFLAGS)
dnl ===========================================================================
-AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
-AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
-
-dnl ===========================================================================
-
SAVE_CFLAGS="$CFLAGS"
CFLAGS=""
AC_CHECK_LIB(m, floor,, AC_MSG_ERROR([math library not found]))
@@ -733,6 +729,7 @@ extensions/webalbums/data/albumthemes/NeatRound/Makefile
extensions/webalbums/data/albumthemes/Wiki/Makefile
extensions/webalbums/data/ui/Makefile
gthumb/Makefile
+gthumb/resources/Makefile
po/Makefile.in
tests/Makefile
])
diff --git a/extensions/file_tools/gth-file-tool-adjust-colors.c b/extensions/file_tools/gth-file-tool-adjust-colors.c
index f22a375..a015acb 100644
--- a/extensions/file_tools/gth-file-tool-adjust-colors.c
+++ b/extensions/file_tools/gth-file-tool-adjust-colors.c
@@ -464,27 +464,34 @@ gth_file_tool_adjust_colors_get_options (GthFileTool *base)
gtk_widget_show (self->priv->histogram_view);
gtk_box_pack_start (GTK_BOX (GET_WIDGET ("histogram_hbox")), self->priv->histogram_view, TRUE, TRUE, 0);
- self->priv->brightness_adj = gimp_scale_entry_new (GET_WIDGET ("brightness_hbox"),
- GTK_LABEL (GET_WIDGET ("brightness_label")),
- 0.0, -100.0, 100.0, 1.0, 10.0, 0);
- self->priv->contrast_adj = gimp_scale_entry_new (GET_WIDGET ("contrast_hbox"),
- GTK_LABEL (GET_WIDGET ("contrast_label")),
- 0.0, -100.0, 100.0, 1.0, 10.0, 0);
- self->priv->gamma_adj = gimp_scale_entry_new (GET_WIDGET ("gamma_hbox"),
- GTK_LABEL (GET_WIDGET ("gamma_label")),
- 0.0, -100.0, 100.0, 1.0, 10.0, 0);
- self->priv->saturation_adj = gimp_scale_entry_new (GET_WIDGET ("saturation_hbox"),
- GTK_LABEL (GET_WIDGET ("saturation_label")),
- 0.0, -100.0, 100.0, 1.0, 10.0, 0);
- self->priv->cyan_red_adj = gimp_scale_entry_new (GET_WIDGET ("cyan_red_hbox"),
- GTK_LABEL (GET_WIDGET ("cyan_red_label")),
- 0.0, -100.0, 100.0, 1.0, 10.0, 0);
- self->priv->magenta_green_adj = gimp_scale_entry_new (GET_WIDGET ("magenta_green_hbox"),
- GTK_LABEL (GET_WIDGET ("magenta_green_label")),
- 0.0, -100.0, 100.0, 1.0, 10.0, 0);
- self->priv->yellow_blue_adj = gimp_scale_entry_new (GET_WIDGET ("yellow_blue_hbox"),
- GTK_LABEL (GET_WIDGET ("yellow_blue_label")),
- 0.0, -100.0, 100.0, 1.0, 10.0, 0);
+ self->priv->brightness_adj = gth_color_scale_label_new (GET_WIDGET ("brightness_hbox"),
+ GTK_LABEL (GET_WIDGET ("brightness_label")),
+ GTH_COLOR_SCALE_BLACK_WHITE,
+ 0.0, -100.0, 100.0, 1.0, 1.0, "%+.0f");
+ self->priv->contrast_adj = gth_color_scale_label_new (GET_WIDGET ("contrast_hbox"),
+ GTK_LABEL (GET_WIDGET ("contrast_label")),
+ GTH_COLOR_SCALE_GRAY_BLACK,
+ 0.0, -100.0, 100.0, 1.0, 1.0, "%+.0f");
+ self->priv->gamma_adj = gth_color_scale_label_new (GET_WIDGET ("gamma_hbox"),
+ GTK_LABEL (GET_WIDGET ("gamma_label")),
+ GTH_COLOR_SCALE_WHITE_BLACK,
+ 0.0, -100.0, 100.0, 1.0, 1.0, "%+.0f");
+ self->priv->saturation_adj = gth_color_scale_label_new (GET_WIDGET ("saturation_hbox"),
+ GTK_LABEL (GET_WIDGET ("saturation_label")),
+ GTH_COLOR_SCALE_GRAY_WHITE,
+ 0.0, -100.0, 100.0, 1.0, 1.0, "%+.0f");
+ self->priv->cyan_red_adj = gth_color_scale_label_new (GET_WIDGET ("cyan_red_hbox"),
+ GTK_LABEL (GET_WIDGET ("cyan_red_label")),
+ GTH_COLOR_SCALE_CYAN_RED,
+ 0.0, -100.0, 100.0, 1.0, 1.0, "%+.0f");
+ self->priv->magenta_green_adj = gth_color_scale_label_new (GET_WIDGET ("magenta_green_hbox"),
+ GTK_LABEL (GET_WIDGET ("magenta_green_label")),
+ GTH_COLOR_SCALE_MAGENTA_GREEN,
+ 0.0, -100.0, 100.0, 1.0, 1.0, "%+.0f");
+ self->priv->yellow_blue_adj = gth_color_scale_label_new (GET_WIDGET ("yellow_blue_hbox"),
+ GTK_LABEL (GET_WIDGET ("yellow_blue_label")),
+ GTH_COLOR_SCALE_YELLOW_BLUE,
+ 0.0, -100.0, 100.0, 1.0, 1.0, "%+.0f");
g_signal_connect (GET_WIDGET ("ok_button"),
"clicked",
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index cbc0a2f..d9727aa 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -385,17 +385,20 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
self->priv->builder = _gtk_builder_new_from_file ("rotate-options.ui", "file_tools");
- self->priv->rotation_angle_adj = gimp_scale_entry_new (GET_WIDGET ("rotation_angle_hbox"),
- GTK_LABEL (GET_WIDGET ("rotation_angle_label")),
- 0.0, -180.0, 180.0, 0.1, 1.0, 1);
-
- self->priv->crop_p1_adj = gimp_scale_entry_new (GET_WIDGET ("crop_p1_hbox"),
- GTK_LABEL (GET_WIDGET ("crop_p1_label")),
- 1.0, 0.0, 1.0, 0.001, 0.01, 3);
-
- self->priv->crop_p2_adj = gimp_scale_entry_new (GET_WIDGET ("crop_p2_hbox"),
- GTK_LABEL (GET_WIDGET ("crop_p2_label")),
- 1.0, 0.0, 1.0, 0.001, 0.01, 3);
+ self->priv->rotation_angle_adj = gth_color_scale_label_new (GET_WIDGET ("rotation_angle_hbox"),
+ GTK_LABEL (GET_WIDGET ("rotation_angle_label")),
+ GTH_COLOR_SCALE_DEFAULT,
+ 0.0, -180.0, 180.0, 0.1, 1.0, "%+.1fÂ");
+
+ self->priv->crop_p1_adj = gth_color_scale_label_new (GET_WIDGET ("crop_p1_hbox"),
+ GTK_LABEL (GET_WIDGET ("crop_p1_label")),
+ GTH_COLOR_SCALE_DEFAULT,
+ 1.0, 0.0, 1.0, 0.001, 0.01, "%.3f");
+
+ self->priv->crop_p2_adj = gth_color_scale_label_new (GET_WIDGET ("crop_p2_hbox"),
+ GTK_LABEL (GET_WIDGET ("crop_p2_label")),
+ GTH_COLOR_SCALE_DEFAULT,
+ 1.0, 0.0, 1.0, 0.001, 0.01, "%.3f");
self->priv->crop_grid = _gtk_combo_box_new_with_texts (_("None"),
_("Rule of Thirds"),
diff --git a/extensions/file_tools/gth-file-tool-sharpen.c b/extensions/file_tools/gth-file-tool-sharpen.c
index 1eec56e..d5872a2 100644
--- a/extensions/file_tools/gth-file-tool-sharpen.c
+++ b/extensions/file_tools/gth-file-tool-sharpen.c
@@ -309,15 +309,18 @@ gth_file_tool_sharpen_get_options (GthFileTool *base)
gtk_widget_show_all (image_navigator);
gtk_box_pack_start (GTK_BOX (GET_WIDGET ("preview_hbox")), image_navigator, TRUE, TRUE, 0);
- self->priv->amount_adj = gimp_scale_entry_new (GET_WIDGET ("amount_hbox"),
- GTK_LABEL (GET_WIDGET ("amount_label")),
- DEFAULT_AMOUNT, 0.0, 500.0, 1.0, 10.0, 0);
- self->priv->radius_adj = gimp_scale_entry_new (GET_WIDGET ("radius_hbox"),
- GTK_LABEL (GET_WIDGET ("radius_label")),
- DEFAULT_RADIUS, 0.0, 10.0, 1.0, 1.0, 0);
- self->priv->threshold_adj = gimp_scale_entry_new (GET_WIDGET ("threshold_hbox"),
- GTK_LABEL (GET_WIDGET ("threshold_label")),
- DEFAULT_THRESHOLD, 0.0, 255.0, 1.0, 10.0, 0);
+ self->priv->amount_adj = gth_color_scale_label_new (GET_WIDGET ("amount_hbox"),
+ GTK_LABEL (GET_WIDGET ("amount_label")),
+ GTH_COLOR_SCALE_DEFAULT,
+ DEFAULT_AMOUNT, 0.0, 500.0, 1.0, 1.0, "%.0f");
+ self->priv->radius_adj = gth_color_scale_label_new (GET_WIDGET ("radius_hbox"),
+ GTK_LABEL (GET_WIDGET ("radius_label")),
+ GTH_COLOR_SCALE_DEFAULT,
+ DEFAULT_RADIUS, 0.0, 10.0, 1.0, 1.0, "%.0f");
+ self->priv->threshold_adj = gth_color_scale_label_new (GET_WIDGET ("threshold_hbox"),
+ GTK_LABEL (GET_WIDGET ("threshold_label")),
+ GTH_COLOR_SCALE_DEFAULT,
+ DEFAULT_THRESHOLD, 0.0, 255.0, 1.0, 1.0, "%.0f");
g_signal_connect (GET_WIDGET ("ok_button"),
"clicked",
diff --git a/gthumb/Makefile.am b/gthumb/Makefile.am
index 79aa888..0faa8e5 100644
--- a/gthumb/Makefile.am
+++ b/gthumb/Makefile.am
@@ -34,6 +34,7 @@ PUBLIC_HEADER_FILES = \
gth-async-task.h \
gth-buffer-data.h \
gth-browser.h \
+ gth-color-scale.h \
gth-dumb-notebook.h \
gth-duplicable.h \
gth-embedded-dialog.h \
@@ -137,12 +138,18 @@ PRIVATE_HEADER_FILES = \
main-migrate.h \
$(NULL)
+RESOURCES = \
+ gth-resources.c \
+ gth-resources.h \
+ $(NULL)
+
gthumb_SOURCES = \
$(ENUM_TYPES) \
$(MARSHALLERS) \
$(EXTERNAL) \
$(PUBLIC_HEADER_FILES) \
$(PRIVATE_HEADER_FILES) \
+ $(RESOURCES) \
cairo-scale.c \
cairo-utils.c \
dlg-location.c \
@@ -159,6 +166,7 @@ gthumb_SOURCES = \
gth-browser.c \
gth-browser-actions-callbacks.c \
gth-buffer-data.c \
+ gth-color-scale.c \
gth-dumb-notebook.c \
gth-duplicable.c \
gth-embedded-dialog.c \
@@ -352,18 +360,34 @@ AUTHORS.tab : $(top_srcdir)/AUTHORS
$(AM_V_GEN)( sed -e 's/^/"/' -e 's/$$/",/' < $(top_srcdir)/AUTHORS > $ tmp \
&& mv $ tmp $@ )
+RESOURCES_DEP = $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies gthumb.gresource.xml)
+
+gth-resources.c: gthumb.gresource.xml $(RESOURCES_DEP)
+ $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name gth $(srcdir)/gthumb.gresource.xml
+
+gth-resources.h: gthumb.gresource.xml $(RESOURCES_DEP)
+ $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name gth $(srcdir)/gthumb.gresource.xml
+
gthumbincludedir = $(includedir)/gthumb-$(GTHUMB_API_VERSION)
gthumbinclude_HEADERS = gthumb.h
gthumbsubincludedir = $(includedir)/gthumb-$(GTHUMB_API_VERSION)/gthumb
gthumbsubinclude_HEADERS = $(PUBLIC_HEADER_FILES)
-BUILT_SOURCES = AUTHORS.tab gthumb.h $(MARSHALLERS) $(ENUM_TYPES)
+BUILT_SOURCES = \
+ AUTHORS.tab \
+ gthumb.h \
+ $(MARSHALLERS) \
+ $(ENUM_TYPES) \
+ $(RESOURCES) \
+ $(NULL)
+
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = \
gth-marshal.list \
gthumb.h.template \
+ gthumb.gresource.xml \
make-header.sh
dist-hook:
diff --git a/gthumb/gth-color-scale.c b/gthumb/gth-color-scale.c
new file mode 100644
index 0000000..2f846f5
--- /dev/null
+++ b/gthumb/gth-color-scale.c
@@ -0,0 +1,417 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2012 Free Software Foundation, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include "gth-color-scale.h"
+#include "gth-enum-types.h"
+
+
+#define _GTK_STYLE_CLASS_COLOR "color"
+
+
+enum {
+ PROP_0,
+ PROP_SCALE_TYPE
+};
+
+
+struct _GthColorScalePrivate {
+ GthColorScaleType scale_type;
+ cairo_surface_t *surface;
+ int width;
+ int height;
+};
+
+
+G_DEFINE_TYPE (GthColorScale, gth_color_scale, GTK_TYPE_SCALE)
+
+
+static void
+gth_color_scale_finalize (GObject *object)
+{
+ GthColorScale *self;
+
+ g_return_if_fail (GTH_IS_COLOR_SCALE (object));
+
+ self = GTH_COLOR_SCALE (object);
+ cairo_surface_destroy (self->priv->surface);
+
+ G_OBJECT_CLASS (gth_color_scale_parent_class)->finalize (object);
+}
+
+
+static void
+gth_color_scale_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GthColorScale *self;
+
+ self = GTH_COLOR_SCALE (object);
+
+ switch (property_id) {
+ case PROP_SCALE_TYPE:
+ self->priv->scale_type = g_value_get_enum (value);
+ if (self->priv->scale_type != GTH_COLOR_SCALE_DEFAULT)
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), _GTK_STYLE_CLASS_COLOR);
+ break;
+ default:
+ break;
+ }
+}
+
+
+static void
+gth_color_scale_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GthColorScale *self;
+
+ self = GTH_COLOR_SCALE (object);
+
+ switch (property_id) {
+ case PROP_SCALE_TYPE:
+ g_value_set_enum (value, self->priv->scale_type);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+static void
+_gth_color_scale_get_surface_size (GthColorScale *self,
+ int *x_out,
+ int *y_out,
+ int *width_out,
+ int *height_out)
+{
+ GtkWidget *widget = GTK_WIDGET (self);
+ int focus_line_width;
+ int focus_padding;
+ int slider_width;
+ int slider_height;
+ cairo_rectangle_int_t bounding_box;
+ cairo_rectangle_int_t trough_rect;
+
+ gtk_widget_style_get (widget,
+ "focus-line-width", &focus_line_width,
+ "focus-padding", &focus_padding,
+ "slider-width", &slider_width,
+ "slider-length", &slider_height,
+ NULL);
+
+ bounding_box.width = gtk_widget_get_allocated_width (widget) - 2 * (focus_line_width + focus_padding);
+ bounding_box.height = gtk_widget_get_allocated_height (widget) - 2 * (focus_line_width + focus_padding);
+ bounding_box.x = focus_line_width + focus_padding;
+ bounding_box.y = focus_line_width + focus_padding;
+
+ if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL) {
+ trough_rect.x = bounding_box.x + 1;
+ trough_rect.width = bounding_box.width - 2;
+ trough_rect.height = 3;
+ trough_rect.y = bounding_box.y + ((bounding_box.height - trough_rect.height) / 2);
+ }
+ else {
+ trough_rect.y = bounding_box.y + 1;
+ trough_rect.height = bounding_box.height - 2;
+ trough_rect.width = 3;
+ trough_rect.x = bounding_box.x + ((bounding_box.width - trough_rect.width) / 2);
+ }
+
+ if (x_out) *x_out = trough_rect.x;
+ if (y_out) *y_out = trough_rect.y;
+ if (width_out) *width_out = trough_rect.width;
+ if (height_out) *height_out = trough_rect.height;
+}
+
+
+static void
+_gth_color_scale_update_surface (GthColorScale *self)
+{
+ int width;
+ int height;
+ cairo_pattern_t *pattern;
+ cairo_t *cr;
+
+ if (! gtk_widget_get_realized (GTK_WIDGET (self)))
+ return;
+
+ if (self->priv->scale_type == GTH_COLOR_SCALE_DEFAULT)
+ return;
+
+ _gth_color_scale_get_surface_size (self, NULL, NULL, &width, &height);
+
+ if ((self->priv->surface != NULL)
+ && (self->priv->width == width)
+ && (self->priv->height == height))
+ {
+ return;
+ }
+
+ cairo_surface_destroy (self->priv->surface);
+ self->priv->surface = NULL;
+
+ pattern = cairo_pattern_create_linear (0.0, 0.0, width, 0.0);
+
+ switch (self->priv->scale_type) {
+ case GTH_COLOR_SCALE_DEFAULT:
+ g_assert_not_reached ();
+ break;
+
+ case GTH_COLOR_SCALE_WHITE_BLACK:
+ cairo_pattern_add_color_stop_rgb (pattern, 0.0, 1.0, 1.0, 1.0);
+ cairo_pattern_add_color_stop_rgb (pattern, 1.0, 0.0, 0.0, 0.0);
+ break;
+
+ case GTH_COLOR_SCALE_BLACK_WHITE:
+ cairo_pattern_add_color_stop_rgb (pattern, 0.0, 0.0, 0.0, 0.0);
+ cairo_pattern_add_color_stop_rgb (pattern, 1.0, 1.0, 1.0, 1.0);
+ break;
+
+ case GTH_COLOR_SCALE_GRAY_BLACK:
+ cairo_pattern_add_color_stop_rgb (pattern, 0.0, 0.5, 0.5, 0.5);
+ cairo_pattern_add_color_stop_rgb (pattern, 1.0, 0.0, 0.0, 0.0);
+ break;
+
+ case GTH_COLOR_SCALE_GRAY_WHITE:
+ cairo_pattern_add_color_stop_rgb (pattern, 0.0, 0.5, 0.5, 0.5);
+ cairo_pattern_add_color_stop_rgb (pattern, 1.0, 1.0, 1.0, 1.0);
+ break;
+
+ case GTH_COLOR_SCALE_CYAN_RED:
+ cairo_pattern_add_color_stop_rgb (pattern, 0.0, 0.0, 1.0, 1.0);
+ cairo_pattern_add_color_stop_rgb (pattern, 1.0, 1.0, 0.0, 0.0);
+ break;
+
+ case GTH_COLOR_SCALE_MAGENTA_GREEN:
+ cairo_pattern_add_color_stop_rgb (pattern, 0.0, 1.0, 0.0, 1.0);
+ cairo_pattern_add_color_stop_rgb (pattern, 1.0, 0.0, 1.0, 0.0);
+ break;
+
+ case GTH_COLOR_SCALE_YELLOW_BLUE:
+ cairo_pattern_add_color_stop_rgb (pattern, 0.0, 1.0, 1.0, 0.0);
+ cairo_pattern_add_color_stop_rgb (pattern, 1.0, 0.0, 0.0, 1.0);
+ break;
+ }
+
+ self->priv->surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
+ cr = cairo_create (self->priv->surface);
+ cairo_set_source (cr, pattern);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_paint (cr);
+
+ cairo_pattern_destroy (pattern);
+ cairo_destroy (cr);
+}
+
+
+static gboolean
+gth_color_scale_draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ GthColorScale *self;
+ cairo_rectangle_int_t surface_rect;
+ cairo_pattern_t *pattern;
+
+ self = GTH_COLOR_SCALE (widget);
+
+ if (self->priv->scale_type == GTH_COLOR_SCALE_DEFAULT) {
+ GTK_WIDGET_CLASS (gth_color_scale_parent_class)->draw (widget, cr);
+ return FALSE;
+ }
+
+ _gth_color_scale_update_surface (self);
+ _gth_color_scale_get_surface_size (self,
+ &surface_rect.x,
+ &surface_rect.y,
+ &surface_rect.width,
+ &surface_rect.height);
+
+ cairo_save (cr);
+ cairo_translate (cr, surface_rect.x, surface_rect.y);
+ cairo_rectangle (cr, 0, 0, surface_rect.width, surface_rect.height);
+ pattern = cairo_pattern_create_for_surface (self->priv->surface);
+ if ((gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL)
+ && (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL))
+ {
+ cairo_matrix_t matrix;
+
+ cairo_matrix_init_scale (&matrix, -1, 1);
+ cairo_matrix_translate (&matrix, -surface_rect.width, 0);
+ cairo_pattern_set_matrix (pattern, &matrix);
+ }
+ cairo_set_source (cr, pattern);
+ cairo_fill (cr);
+ cairo_restore (cr);
+
+ cairo_pattern_destroy (pattern);
+
+ GTK_WIDGET_CLASS (gth_color_scale_parent_class)->draw (widget, cr);
+
+ return FALSE;
+}
+
+
+static void
+gth_color_scale_class_init (GthColorScaleClass *class)
+{
+ GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ g_type_class_add_private (class, sizeof (GthColorScalePrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = gth_color_scale_set_property;
+ object_class->get_property = gth_color_scale_get_property;
+ object_class->finalize = gth_color_scale_finalize;
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ widget_class->draw = gth_color_scale_draw;
+
+ g_object_class_install_property (object_class,
+ PROP_SCALE_TYPE,
+ g_param_spec_enum ("scale-type",
+ "Scale Type",
+ "The type of scale",
+ GTH_TYPE_COLOR_SCALE_TYPE,
+ GTH_COLOR_SCALE_DEFAULT,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+
+static void
+gth_color_scale_init (GthColorScale *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_COLOR_SCALE, GthColorScalePrivate);
+ self->priv->surface = NULL;
+ self->priv->width = -1;
+ self->priv->height = -1;
+}
+
+
+GtkWidget *
+gth_color_scale_new (GtkAdjustment *adjustment,
+ GthColorScaleType scale_type)
+{
+ return g_object_new (GTH_TYPE_COLOR_SCALE,
+ "adjustment", adjustment,
+ "scale-type", scale_type,
+ NULL);
+}
+
+
+/* -- gth_color_scale_label_new -- */
+
+
+typedef struct {
+ GtkWidget *value_label;
+ char *format;
+} ScaleData;
+
+
+static void
+scale_data_free (gpointer user_data)
+{
+ ScaleData *scale_data = user_data;
+
+ g_free (scale_data->format);
+ g_free (scale_data);
+}
+
+
+static void
+scale_value_changed (GtkAdjustment *adjustment,
+ gpointer user_data)
+{
+ ScaleData *scale_data = user_data;
+ double num;
+ char *value;
+ char *markup;
+
+ num = gtk_adjustment_get_value (adjustment);
+ value = g_strdup_printf (scale_data->format, num);
+ if ((num == 0.0) && ((value[0] == '-') || (value[0] == '+')))
+ value[0] = ' ';
+ markup = g_strdup_printf ("<small>%s</small>", value);
+ gtk_label_set_markup (GTK_LABEL (scale_data->value_label), markup);
+
+ g_free (markup);
+ g_free (value);
+}
+
+
+GtkAdjustment *
+gth_color_scale_label_new (GtkWidget *parent_box,
+ GtkLabel *related_label,
+ GthColorScaleType scale_type,
+ float value,
+ float lower,
+ float upper,
+ float step_increment,
+ float page_increment,
+ const char *format)
+{
+ ScaleData *scale_data;
+ GtkAdjustment *adj;
+ GtkWidget *scale;
+ GtkWidget *hbox;
+
+ adj = gtk_adjustment_new (value, lower, upper,
+ step_increment, page_increment,
+ 0.0);
+
+ scale_data = g_new (ScaleData, 1);
+ scale_data->format = g_strdup (format);
+ scale_data->value_label = gtk_label_new ("0");
+ g_object_set_data_full (G_OBJECT (adj), "gth-scale-data", scale_data, scale_data_free);
+
+ gtk_label_set_width_chars (GTK_LABEL (scale_data->value_label), 3);
+ gtk_misc_set_alignment (GTK_MISC (scale_data->value_label), 1.0, 0.5);
+ gtk_widget_show (scale_data->value_label);
+ g_signal_connect (adj,
+ "value-changed",
+ G_CALLBACK (scale_value_changed),
+ scale_data);
+
+ scale = gth_color_scale_new (adj, scale_type);
+ gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_RIGHT);
+ gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+ gtk_widget_show (scale);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
+ gtk_widget_show (hbox);
+ gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), scale_data->value_label, FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (parent_box), hbox, TRUE, TRUE, 0);
+
+ if (related_label != NULL)
+ gtk_label_set_mnemonic_widget (related_label, scale);
+
+ scale_value_changed (adj, scale_data);
+
+ return adj;
+}
diff --git a/gthumb/gth-color-scale.h b/gthumb/gth-color-scale.h
new file mode 100644
index 0000000..d9f67b4
--- /dev/null
+++ b/gthumb/gth-color-scale.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2012 The Free Software Foundation, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTH_COLOR_SCALE_H
+#define GTH_COLOR_SCALE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_COLOR_SCALE (gth_color_scale_get_type ())
+#define GTH_COLOR_SCALE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_COLOR_SCALE, GthColorScale))
+#define GTH_COLOR_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_COLOR_SCALE, GthColorScaleClass))
+#define GTH_IS_COLOR_SCALE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_COLOR_SCALE))
+#define GTH_IS_COLOR_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_COLOR_SCALE))
+#define GTH_COLOR_SCALE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTH_TYPE_COLOR_SCALE, GthColorScaleClass))
+
+typedef struct _GthColorScale GthColorScale;
+typedef struct _GthColorScaleClass GthColorScaleClass;
+typedef struct _GthColorScalePrivate GthColorScalePrivate;
+
+struct _GthColorScale {
+ GtkScale __parent;
+ GthColorScalePrivate *priv;
+};
+
+struct _GthColorScaleClass {
+ GtkScaleClass __parent;
+};
+
+typedef enum {
+ GTH_COLOR_SCALE_DEFAULT,
+ GTH_COLOR_SCALE_WHITE_BLACK,
+ GTH_COLOR_SCALE_BLACK_WHITE,
+ GTH_COLOR_SCALE_GRAY_BLACK,
+ GTH_COLOR_SCALE_GRAY_WHITE,
+ GTH_COLOR_SCALE_CYAN_RED,
+ GTH_COLOR_SCALE_MAGENTA_GREEN,
+ GTH_COLOR_SCALE_YELLOW_BLUE
+} GthColorScaleType;
+
+GType gth_color_scale_get_type (void);
+GtkWidget * gth_color_scale_new (GtkAdjustment *adjustment,
+ GthColorScaleType scale_type);
+GtkAdjustment * gth_color_scale_label_new (GtkWidget *parent_box,
+ GtkLabel *related_label,
+ GthColorScaleType scale_type,
+ float value,
+ float lower,
+ float upper,
+ float step_increment,
+ float page_increment,
+ const char *format);
+
+G_END_DECLS
+
+#endif /* GTH_COLOR_SCALE_H */
diff --git a/gthumb/gth-window.c b/gthumb/gth-window.c
index 69e72c9..e4c6b22 100644
--- a/gthumb/gth-window.c
+++ b/gthumb/gth-window.c
@@ -205,10 +205,36 @@ gth_window_real_set_current_page (GthWindow *window,
static void
gth_window_realize (GtkWidget *widget)
{
+ GdkScreen *screen;
+ GBytes *bytes;
+ gconstpointer css_data;
+ gsize css_data_size;
+ GtkCssProvider *css_provider;
+ GError *error = NULL;
+
GTK_WIDGET_CLASS (gth_window_parent_class)->realize (widget);
- gtk_icon_theme_append_search_path (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget)),
- GTHUMB_ICON_DIR);
+ screen = gtk_widget_get_screen (widget);
+ gtk_icon_theme_append_search_path (gtk_icon_theme_get_for_screen (screen), GTHUMB_ICON_DIR);
+
+ bytes = g_resources_lookup_data ("/org/gnome/gThumb/resources/gthumb.css", 0, &error);
+ if (bytes == NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ css_data = g_bytes_get_data (bytes, &css_data_size);
+ css_provider = gtk_css_provider_new ();
+ if (! gtk_css_provider_load_from_data (css_provider, css_data, css_data_size, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+ gtk_style_context_add_provider_for_screen (screen,
+ GTK_STYLE_PROVIDER (css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_THEME);
+
+ g_object_unref (css_provider);
}
diff --git a/gthumb/gthumb.gresource.xml b/gthumb/gthumb.gresource.xml
new file mode 100644
index 0000000..6bb8194
--- /dev/null
+++ b/gthumb/gthumb.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/gThumb">
+ <file compressed="true">resources/gthumb.css</file>
+ </gresource>
+</gresources>
diff --git a/gthumb/gtk-utils.c b/gthumb/gtk-utils.c
index 18b540f..224eb8f 100644
--- a/gthumb/gtk-utils.c
+++ b/gthumb/gtk-utils.c
@@ -980,47 +980,6 @@ _gtk_menu_ask_drag_drop_action (GtkWidget *widget,
}
-GtkAdjustment *
-gimp_scale_entry_new (GtkWidget *parent_box,
- GtkLabel *label,
- float value,
- float lower,
- float upper,
- float step_increment,
- float page_increment,
- int digits)
-{
- GtkAdjustment *adj;
- GtkWidget *spinbutton;
- GtkWidget *scale;
- GtkWidget *hbox;
-
- adj = gtk_adjustment_new (value, lower, upper,
- step_increment, page_increment,
- 0.0);
-
- spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adj), page_increment, 0);
- gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), digits);
- gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 4);
-
- scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT (adj));
- gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
- gtk_scale_set_digits (GTK_SCALE (scale), digits);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
- gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
-
- gtk_box_pack_start (GTK_BOX (parent_box), hbox, TRUE, TRUE, 0);
- gtk_widget_show_all (hbox);
-
- if (label != NULL)
- gtk_label_set_mnemonic_widget (label, scale);
-
- return (GtkAdjustment *) adj;
-}
-
-
static gboolean
_gdk_rgba_shade (GdkRGBA *color,
GdkRGBA *result,
diff --git a/gthumb/gtk-utils.h b/gthumb/gtk-utils.h
index 278896d..4e8a2f3 100644
--- a/gthumb/gtk-utils.h
+++ b/gthumb/gtk-utils.h
@@ -126,14 +126,6 @@ void _gtk_info_bar_clear_action_area (GtkInfoBar *in
GdkDragAction _gtk_menu_ask_drag_drop_action (GtkWidget *widget,
GdkDragAction actions,
guint32 activate_time);
-GtkAdjustment * gimp_scale_entry_new (GtkWidget *parent_box,
- GtkLabel *label,
- float value,
- float lower,
- float upper,
- float step_increment,
- float page_increment,
- int digits);
gboolean _gdk_rgba_darker (GdkRGBA *color,
GdkRGBA *result);
gboolean _gdk_rgba_lighter (GdkRGBA *color,
diff --git a/gthumb/resources/Makefile.am b/gthumb/resources/Makefile.am
new file mode 100644
index 0000000..9265f7c
--- /dev/null
+++ b/gthumb/resources/Makefile.am
@@ -0,0 +1,4 @@
+EXTRA_DIST = \
+ gthumb.css
+
+-include $(top_srcdir)/git.mk
\ No newline at end of file
diff --git a/gthumb/resources/gthumb.css b/gthumb/resources/gthumb.css
new file mode 100644
index 0000000..d702d01
--- /dev/null
+++ b/gthumb/resources/gthumb.css
@@ -0,0 +1,4 @@
+GthColorScale.trough.color {
+ box-shadow: none;
+ background: transparent;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]