Commit d7cff079 authored by Matthias Clasen's avatar Matthias Clasen

Misc cleanups

parent ed5aa953
......@@ -114,6 +114,13 @@ gtk_color_chooser_default_init (GtkColorChooserInterface *iface)
1, G_TYPE_STRING);
}
void
_gtk_color_chooser_color_activated (GtkColorChooser *chooser,
const GdkRGBA *color)
{
g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color);
}
/**
* gtk_color_chooser_get_rgba:
* @chooser: a #GtkColorChooser
......@@ -149,13 +156,6 @@ gtk_color_chooser_set_rgba (GtkColorChooser *chooser,
GTK_COLOR_CHOOSER_GET_IFACE (chooser)->set_rgba (chooser, color);
}
void
_gtk_color_chooser_color_activated (GtkColorChooser *chooser,
const GdkRGBA *color)
{
g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color);
}
/**
* gtk_color_chooser_get_use_alpha:
* @chooser: a #GtkColorChooser
......
......@@ -24,7 +24,6 @@
#include "gtkcolorchooserwidget.h"
#include "gtkcoloreditor.h"
#include "gtkcolorswatch.h"
#include "gtkcolorutils.h"
#include "gtkbox.h"
#include "gtkgrid.h"
#include "gtklabel.h"
......@@ -64,6 +63,7 @@ struct _GtkColorChooserWidgetPrivate
{
GtkWidget *palette;
GtkWidget *editor;
GtkSizeGroup *size_group;
GtkWidget *colors;
GtkWidget *grays;
......@@ -71,9 +71,8 @@ struct _GtkColorChooserWidgetPrivate
GtkWidget *button;
GtkColorSwatch *current;
gboolean use_alpha;
GtkSizeGroup *size_group;
gboolean use_alpha;
GSettings *settings;
};
......@@ -100,10 +99,12 @@ select_swatch (GtkColorChooserWidget *cc,
if (cc->priv->current == swatch)
return;
if (cc->priv->current != NULL)
gtk_color_swatch_set_selected (cc->priv->current, FALSE);
gtk_color_swatch_set_selected (swatch, TRUE);
cc->priv->current = swatch;
gtk_color_swatch_get_rgba (swatch, &color);
g_settings_set (cc->priv->settings, "selected-color", "(bdddd)",
TRUE, color.red, color.green, color.blue, color.alpha);
......@@ -111,26 +112,6 @@ select_swatch (GtkColorChooserWidget *cc,
g_object_notify (G_OBJECT (cc), "rgba");
}
static void save_custom_colors (GtkColorChooserWidget *cc);
static void
button_activate (GtkColorSwatch *swatch,
GtkColorChooserWidget *cc)
{
GdkRGBA color;
/* somewhat random, makes the hairline nicely visible */
color.red = 0.75;
color.green = 0.25;
color.blue = 0.25;
color.alpha = 1.0;
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
gtk_widget_hide (cc->priv->palette);
gtk_widget_show (cc->priv->editor);
}
static void
swatch_activate (GtkColorSwatch *swatch,
GtkColorChooserWidget *cc)
......@@ -163,7 +144,8 @@ swatch_selected (GtkColorSwatch *swatch,
}
static void
connect_swatch_signals (GtkWidget *p, gpointer data)
connect_swatch_signals (GtkWidget *p,
gpointer data)
{
g_signal_connect (p, "activate", G_CALLBACK (swatch_activate), data);
g_signal_connect (p, "customize", G_CALLBACK (swatch_customize), data);
......@@ -171,17 +153,23 @@ connect_swatch_signals (GtkWidget *p, gpointer data)
}
static void
connect_button_signals (GtkWidget *p, gpointer data)
button_activate (GtkColorSwatch *swatch,
GtkColorChooserWidget *cc)
{
g_signal_connect (p, "activate", G_CALLBACK (button_activate), data);
/* somewhat random, makes the hairline nicely visible */
GdkRGBA color = { 0.75, 0.25, 0.25, 1.0 };
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
gtk_widget_hide (cc->priv->palette);
gtk_widget_show (cc->priv->editor);
}
static void
connect_custom_signals (GtkWidget *p, gpointer data)
connect_button_signals (GtkWidget *p,
gpointer data)
{
connect_swatch_signals (p, data);
g_signal_connect_swapped (p, "notify::color",
G_CALLBACK (save_custom_colors), data);
g_signal_connect (p, "activate", G_CALLBACK (button_activate), data);
}
static void
......@@ -200,16 +188,72 @@ save_custom_colors (GtkColorChooserWidget *cc)
{
i++;
if (gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (child), &color))
{
g_variant_builder_add (&builder, "(dddd)",
color.red, color.green, color.blue, color.alpha);
}
g_variant_builder_add (&builder, "(dddd)",
color.red, color.green, color.blue, color.alpha);
}
variant = g_variant_builder_end (&builder);
g_settings_set_value (cc->priv->settings, "custom-colors", variant);
}
static void
connect_custom_signals (GtkWidget *p,
gpointer data)
{
connect_swatch_signals (p, data);
g_signal_connect_swapped (p, "notify::rgba",
G_CALLBACK (save_custom_colors), data);
}
static void
gtk_color_chooser_widget_set_use_alpha (GtkColorChooserWidget *cc,
gboolean use_alpha)
{
GtkWidget *grids[3];
gint i;
GList *children, *l;
GtkWidget *swatch;
cc->priv->use_alpha = use_alpha;
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cc->priv->editor), use_alpha);
grids[0] = cc->priv->colors;
grids[1] = cc->priv->grays;
grids[2] = cc->priv->custom;
for (i = 0; i < 3; i++)
{
children = gtk_container_get_children (GTK_CONTAINER (grids[i]));
for (l = children; l; l = l->next)
{
swatch = l->data;
gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (swatch), use_alpha);
}
g_list_free (children);
}
gtk_widget_queue_draw (GTK_WIDGET (cc));
}
static void
gtk_color_chooser_widget_set_show_editor (GtkColorChooserWidget *cc,
gboolean show_editor)
{
if (show_editor)
{
GdkRGBA color = { 0.75, 0.25, 0.25, 1.0 };
if (cc->priv->current)
gtk_color_swatch_get_rgba (cc->priv->current, &color);
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
}
gtk_widget_set_visible (cc->priv->editor, show_editor);
gtk_widget_set_visible (cc->priv->palette, !show_editor);
}
/* UI construction {{{1 */
static void
gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
{
......@@ -290,7 +334,6 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
for (i = 0; i < 9; i++)
{
gdk_rgba_parse (&color, default_grayscale[i]);
color.alpha = 1.0;
p = gtk_color_swatch_new ();
connect_swatch_signals (p, cc);
......@@ -378,6 +421,8 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
gtk_size_group_add_widget (cc->priv->size_group, alignment);
}
/* GObject implementation {{{1 */
static void
gtk_color_chooser_widget_get_property (GObject *object,
guint prop_id,
......@@ -409,44 +454,6 @@ gtk_color_chooser_widget_get_property (GObject *object,
}
}
static void
gtk_color_chooser_widget_set_use_alpha (GtkColorChooserWidget *cc,
gboolean use_alpha)
{
GtkWidget *grids[3];
gint i;
GList *children, *l;
GtkWidget *swatch;
cc->priv->use_alpha = use_alpha;
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cc->priv->editor), use_alpha);
grids[0] = cc->priv->colors;
grids[1] = cc->priv->grays;
grids[2] = cc->priv->custom;
for (i = 0; i < 3; i++)
{
children = gtk_container_get_children (GTK_CONTAINER (grids[i]));
for (l = children; l; l = l->next)
{
swatch = l->data;
gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (swatch), use_alpha);
}
g_list_free (children);
}
gtk_widget_queue_draw (GTK_WIDGET (cc));
}
static void
gtk_color_chooser_widget_set_show_editor (GtkColorChooserWidget *cc,
gboolean show_editor)
{
gtk_widget_set_visible (cc->priv->editor, show_editor);
gtk_widget_set_visible (cc->priv->palette, !show_editor);
}
static void
gtk_color_chooser_widget_set_property (GObject *object,
guint prop_id,
......@@ -514,6 +521,8 @@ gtk_color_chooser_widget_class_init (GtkColorChooserWidgetClass *class)
g_type_class_add_private (object_class, sizeof (GtkColorChooserWidgetPrivate));
}
/* GtkColorChooser implementation {{{1 */
static void
gtk_color_chooser_widget_get_rgba (GtkColorChooser *chooser,
GdkRGBA *color)
......@@ -615,6 +624,8 @@ gtk_color_chooser_widget_iface_init (GtkColorChooserInterface *iface)
iface->set_rgba = gtk_color_chooser_widget_set_rgba;
}
/* Public API {{{1 */
/**
* gtk_color_chooser_widget_new:
*
......@@ -629,3 +640,5 @@ gtk_color_chooser_widget_new (void)
{
return g_object_new (GTK_TYPE_COLOR_CHOOSER_WIDGET, NULL);
}
/* vim:set foldmethod=marker: */
......@@ -30,16 +30,15 @@
#include "config.h"
#include "gtkcolorchooserprivate.h"
#include "gtkcoloreditor.h"
#include "gtkcolorchooserprivate.h"
#include "gtkcolorplane.h"
#include "gtkcolorscale.h"
#include "gtkcolorswatch.h"
#include "gtkcolorutils.h"
#include "gtkgrid.h"
#include "gtkorientable.h"
#include "gtkaspectframe.h"
#include "gtkdrawingarea.h"
#include "gtkentry.h"
#include "gtkoverlay.h"
#include "gtkadjustment.h"
......@@ -75,7 +74,7 @@ struct _GtkColorEditorPrivate
GtkAdjustment *a_adj;
guint text_changed : 1;
guint use_alpha : 1;
guint use_alpha : 1;
};
enum
......@@ -101,21 +100,15 @@ scale_round (gdouble value, gdouble scale)
}
static void
update_entry (GtkColorEditor *editor)
entry_set_rgba (GtkColorEditor *editor,
const GdkRGBA *color)
{
gchar *text;
gdouble h, s, v;
gdouble r, g, b;
h = gtk_adjustment_get_value (editor->priv->h_adj);
s = gtk_adjustment_get_value (editor->priv->s_adj);
v = gtk_adjustment_get_value (editor->priv->v_adj);
gtk_hsv_to_rgb (h, s, v, &r, &g, &b);
text = g_strdup_printf ("#%02X%02X%02X",
scale_round (r, 255),
scale_round (g, 255),
scale_round (b, 255));
scale_round (color->red, 255),
scale_round (color->green, 255),
scale_round (color->blue, 255));
gtk_entry_set_text (GTK_ENTRY (editor->priv->entry), text);
editor->priv->text_changed = FALSE;
g_free (text);
......@@ -164,16 +157,20 @@ static void
hsv_changed (GtkColorEditor *editor)
{
GdkRGBA color;
gdouble h, s, v;
gdouble h, s, v, a;
h = gtk_adjustment_get_value (editor->priv->h_adj);
s = gtk_adjustment_get_value (editor->priv->s_adj);
v = gtk_adjustment_get_value (editor->priv->v_adj);
a = gtk_adjustment_get_value (editor->priv->a_adj);
gtk_hsv_to_rgb (h, s, v, &color.red, &color.green, &color.blue);
color.alpha = gtk_adjustment_get_value (editor->priv->a_adj);
update_entry (editor);
color.alpha = a;
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->priv->swatch), &color);
gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->priv->a_slider), &color);
entry_set_rgba (editor, &color);
g_object_notify (G_OBJECT (editor), "rgba");
}
......@@ -300,7 +297,8 @@ get_child_position (GtkOverlay *overlay,
}
static void
value_changed (GtkAdjustment *a, GtkAdjustment *as)
value_changed (GtkAdjustment *a,
GtkAdjustment *as)
{
gdouble scale;
......@@ -311,7 +309,8 @@ value_changed (GtkAdjustment *a, GtkAdjustment *as)
}
static GtkAdjustment *
scaled_adjustment (GtkAdjustment *a, gdouble scale)
scaled_adjustment (GtkAdjustment *a,
gdouble scale)
{
GtkAdjustment *as;
......@@ -329,7 +328,9 @@ scaled_adjustment (GtkAdjustment *a, gdouble scale)
}
static gboolean
popup_draw (GtkWidget *popup, cairo_t *cr, GtkColorEditor *editor)
popup_draw (GtkWidget *popup,
cairo_t *cr,
GtkColorEditor *editor)
{
GtkStyleContext *context;
gint width, height;
......@@ -344,14 +345,40 @@ popup_draw (GtkWidget *popup, cairo_t *cr, GtkColorEditor *editor)
return FALSE;
}
static GtkWidget *
create_popup (GtkColorEditor *editor,
GtkWidget *attach,
GtkWidget *contents)
{
GtkWidget *popup;
popup = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_alignment_set_padding (GTK_ALIGNMENT (popup), 12, 12, 12, 12);
gtk_style_context_add_class (gtk_widget_get_style_context (popup), GTK_STYLE_CLASS_TOOLTIP);
gtk_container_add (GTK_CONTAINER (popup), contents);
gtk_widget_show_all (popup);
gtk_widget_hide (popup);
gtk_widget_set_no_show_all (popup, TRUE);
g_signal_connect (popup, "draw", G_CALLBACK (popup_draw), editor);
gtk_overlay_add_overlay (GTK_OVERLAY (editor->priv->overlay), popup);
g_signal_connect (attach, "popup-menu", G_CALLBACK (popup_edit), editor);
return popup;
}
static void
gtk_color_editor_init (GtkColorEditor *editor)
{
GtkWidget *grid;
GtkWidget *box;
GtkWidget *slider;
GtkWidget *alignment;
GtkAdjustment *adj;
GtkWidget *entry;
GtkWidget *swatch;
GtkAdjustment *h_adj, *s_adj, *v_adj, *a_adj;
GdkRGBA transparent = { 0, 0, 0, 0 };
editor->priv = G_TYPE_INSTANCE_GET_PRIVATE (editor,
......@@ -359,60 +386,53 @@ gtk_color_editor_init (GtkColorEditor *editor)
GtkColorEditorPrivate);
editor->priv->use_alpha = TRUE;
editor->priv->h_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->s_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->v_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->a_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
g_object_ref_sink (editor->priv->h_adj);
g_object_ref_sink (editor->priv->s_adj);
g_object_ref_sink (editor->priv->v_adj);
g_object_ref_sink (editor->priv->a_adj);
g_signal_connect_swapped (editor->priv->h_adj, "value-changed",
G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (editor->priv->s_adj, "value-changed",
G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (editor->priv->a_adj, "value-changed",
G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (editor->priv->v_adj, "value-changed",
G_CALLBACK (hsv_changed), editor);
editor->priv->h_adj = h_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->s_adj = s_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->v_adj = v_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->a_adj = a_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
gtk_widget_push_composite_child ();
g_object_ref_sink (h_adj);
g_object_ref_sink (s_adj);
g_object_ref_sink (v_adj);
g_object_ref_sink (a_adj);
editor->priv->overlay = gtk_overlay_new ();
gtk_widget_override_background_color (editor->priv->overlay, 0, &transparent);
editor->priv->grid = grid = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
g_signal_connect_swapped (h_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (s_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (v_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (a_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
gtk_widget_push_composite_child ();
editor->priv->swatch = gtk_color_swatch_new ();
gtk_widget_set_sensitive (editor->priv->swatch, FALSE);
gtk_color_swatch_set_corner_radii (GTK_COLOR_SWATCH (editor->priv->swatch), 2, 2, 2, 2);
/* Construct the main UI */
editor->priv->swatch = swatch = gtk_color_swatch_new ();
gtk_widget_set_sensitive (swatch, FALSE);
gtk_color_swatch_set_corner_radii (GTK_COLOR_SWATCH (swatch), 2, 2, 2, 2);
editor->priv->entry = gtk_entry_new ();
g_signal_connect (editor->priv->entry, "activate",
G_CALLBACK (entry_apply), editor);
g_signal_connect (editor->priv->entry, "notify::text",
G_CALLBACK (entry_text_changed), editor);
g_signal_connect (editor->priv->entry, "focus-out-event",
G_CALLBACK (entry_focus_out), editor);
editor->priv->entry = entry = gtk_entry_new ();
g_signal_connect (entry, "activate", G_CALLBACK (entry_apply), editor);
g_signal_connect (entry, "notify::text", G_CALLBACK (entry_text_changed), editor);
g_signal_connect (entry, "focus-out-event", G_CALLBACK (entry_focus_out), editor);
editor->priv->h_slider = slider = gtk_color_scale_new (editor->priv->h_adj,
GTK_COLOR_SCALE_HUE);
editor->priv->h_slider = slider = gtk_color_scale_new (h_adj, GTK_COLOR_SCALE_HUE);
gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_VERTICAL);
if (gtk_widget_get_direction (slider) == GTK_TEXT_DIR_RTL)
gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
gtk_style_context_add_class (gtk_widget_get_style_context (slider),
GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
else
gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
gtk_style_context_add_class (gtk_widget_get_style_context (slider),
GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
editor->priv->sv_plane = gtk_color_plane_new (h_adj, s_adj, v_adj);
gtk_widget_set_size_request (editor->priv->sv_plane, 300, 300);
editor->priv->a_slider = slider = gtk_color_scale_new (editor->priv->a_adj,
GTK_COLOR_SCALE_ALPHA);
editor->priv->a_slider = slider = gtk_color_scale_new (a_adj, GTK_COLOR_SCALE_ALPHA);
gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_HORIZONTAL);
gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
gtk_style_context_add_class (gtk_widget_get_style_context (slider),
GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
editor->priv->sv_plane = gtk_color_plane_new (editor->priv->h_adj,
editor->priv->s_adj,
editor->priv->v_adj);
gtk_widget_set_size_request (editor->priv->sv_plane, 300, 300);
editor->priv->grid = grid = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
gtk_grid_attach (GTK_GRID (grid), editor->priv->swatch, 1, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), editor->priv->entry, 2, 0, 1, 1);
......@@ -425,96 +445,60 @@ gtk_color_editor_init (GtkColorEditor *editor)
*/
alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 30, 30);
gtk_container_add (GTK_CONTAINER (editor->priv->overlay), alignment);
gtk_container_add (GTK_CONTAINER (alignment), grid);
editor->priv->sv_popup = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_style_context_add_class (gtk_widget_get_style_context (editor->priv->sv_popup),
GTK_STYLE_CLASS_TOOLTIP);
gtk_alignment_set_padding (GTK_ALIGNMENT (editor->priv->sv_popup), 12, 12, 12, 12);
editor->priv->overlay = gtk_overlay_new ();
gtk_widget_override_background_color (editor->priv->overlay, 0, &transparent);
gtk_container_add (GTK_CONTAINER (editor->priv->overlay), alignment);
/* Construct the sv popup */
editor->priv->s_entry = entry = gtk_spin_button_new (scaled_adjustment (s_adj, 100), 1, 0);
g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);
editor->priv->v_entry = entry = gtk_spin_button_new (scaled_adjustment (v_adj, 100), 1, 0);
g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
adj = scaled_adjustment (editor->priv->s_adj, 100);
editor->priv->s_entry = gtk_spin_button_new (adj, 1, 0);
g_signal_connect (editor->priv->s_entry, "key-press-event",
G_CALLBACK (popup_key_press), editor);
adj = scaled_adjustment (editor->priv->v_adj, 100);
editor->priv->v_entry = gtk_spin_button_new (adj, 1, 0);
g_signal_connect (editor->priv->v_entry, "key-press-event",
G_CALLBACK (popup_key_press), editor);
gtk_container_add (GTK_CONTAINER (editor->priv->sv_popup), grid);
gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "S")), 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), editor->priv->s_entry, 1, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "V")), 0, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), editor->priv->v_entry, 1, 1, 1, 1);
gtk_widget_show_all (editor->priv->sv_popup);
gtk_widget_hide (editor->priv->sv_popup);
gtk_widget_set_no_show_all (editor->priv->sv_popup, TRUE);
gtk_overlay_add_overlay (GTK_OVERLAY (editor->priv->overlay), editor->priv->sv_popup);
g_signal_connect (editor->priv->sv_popup, "draw",
G_CALLBACK (popup_draw), editor);
g_signal_connect (editor->priv->sv_plane, "popup-menu",
G_CALLBACK (popup_edit), editor);
editor->priv->h_popup = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_style_context_add_class (gtk_widget_get_style_context (editor->priv->h_popup),
GTK_STYLE_CLASS_TOOLTIP);
gtk_alignment_set_padding (GTK_ALIGNMENT (editor->priv->h_popup), 12, 12, 12, 12);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
adj = scaled_adjustment (editor->priv->h_adj, 100);
editor->priv->h_entry = gtk_spin_button_new (adj, 1, 0);
g_signal_connect (editor->priv->h_entry, "key-press-event",
G_CALLBACK (popup_key_press), editor);
gtk_container_add (GTK_CONTAINER (editor->priv->h_popup), box);
gtk_container_add (GTK_CONTAINER (box), gtk_label_new (C_("Color channel", "H")));
gtk_container_add (GTK_CONTAINER (box), editor->priv->h_entry);
gtk_widget_show_all (editor->priv->h_popup);
gtk_widget_hide (editor->priv->h_popup);
gtk_widget_set_no_show_all (editor->priv->h_popup, TRUE);
gtk_overlay_add_overlay (GTK_OVERLAY (editor->priv->overlay), editor->priv->h_popup);
g_signal_connect (editor->priv->h_popup, "draw",
G_CALLBACK (popup_draw), editor);
g_signal_connect (editor->priv->h_slider, "popup-menu",
G_CALLBACK (popup_edit), editor);
editor->priv->a_popup = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_style_context_add_class (gtk_widget_get_style_context (editor->priv->a_popup),
GTK_STYLE_CLASS_TOOLTIP);
gtk_alignment_set_padding (GTK_ALIGNMENT (editor->priv->a_popup), 12, 12, 12, 12);
editor->priv->sv_popup = create_popup (editor, editor->priv->sv_plane, grid);
/* Construct the h popup */
editor->priv->h_entry = entry = gtk_spin_button_new (scaled_adjustment (h_adj, 100), 1, 0);
g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "H")), 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), editor->priv->h_entry, 1, 0, 1, 1);
editor->priv->h_popup = create_popup (editor, editor->priv->h_slider, grid);
/* Construct the a popup */
editor->priv->a_entry = entry = gtk_spin_button_new (scaled_adjustment (a_adj, 100), 1, 0);
g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
adj = scaled_adjustment (editor->priv->a_adj, 100);
editor->priv->a_entry = gtk_spin_button_new (adj, 1, 0);
g_signal_connect (editor->priv->a_entry, "key-press-event",
G_CALLBACK (popup_key_press), editor);
gtk_container_add (GTK_CONTAINER (editor->priv->a_popup), grid);
gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "A")), 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), editor->priv->a_entry, 1, 0, 1, 1);
gtk_widget_show_all (editor->priv->a_popup);
gtk_widget_hide (editor->priv->a_popup);
gtk_widget_set_no_show_all (editor->priv->a_popup, TRUE);
gtk_overlay_add_overlay (GTK_OVERLAY (editor->priv->overlay), editor->priv->a_popup);
g_signal_connect (editor->priv->a_popup, "draw",
G_CALLBACK (popup_draw), editor);
g_signal_connect (editor->priv->a_slider, "popup-menu",
G_CALLBACK (popup_edit), editor);
editor->priv->a_popup = create_popup (editor, editor->priv->a_slider, grid);
g_signal_connect (editor->priv->overlay, "get-child-position",
G_CALLBACK (get_child_position), editor);
g_signal_connect (editor, "notify::visible",
G_CALLBACK (dismiss_current_popup), NULL);
/* Hook up popup positioning */
g_signal_connect (editor->priv->overlay, "get-child-position", G_CALLBACK (get_child_position), editor);
g_signal_connect (editor, "notify::visible", G_CALLBACK (dismiss_current_popup), NULL);
gtk_widget_show_all (editor->priv->overlay);
gtk_container_add (GTK_CONTAINER (editor), editor->priv->overlay);
gtk_widget_pop_composite_child ();
}
......@@ -635,12 +619,10 @@ gtk_color_editor_set_rgba (GtkColorChooser *chooser,
gtk_adjustment_set_value (editor->priv->s_adj, s);
gtk_adjustment_set_value (editor->priv->v_adj, v);
gtk_adjustment_set_value (editor->priv->a_adj, color->alpha);
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->priv->swatch), color);
gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->priv->a_slider), color);
update_entry (editor);
gtk_widget_queue_draw (GTK_WIDGET (editor));
entry_set_rgba (editor, color);
g_object_notify (G_OBJECT (editor), "rgba");
}
......
......@@ -21,10 +21,7 @@
#include "gtkcolorplane.h"
#include "gtkcolorutils.h"
#include "gtkcontainer.h"
#include "gtkaccessible.h"
#include "gtkwindow.h"
#include "gtkbutton.h"
#include "gtkintl.h"
struct _GtkColorPlanePrivate
......@@ -34,15 +31,32 @@ struct _GtkColorPlanePrivate
GtkAdjustment *v_adj;
cairo_surface_t *surface;
gint x, y;
gboolean in_drag;
};
G_DEFINE_TYPE (GtkColorPlane, gtk_color_plane, GTK_TYPE_DRAWING_AREA)
static void
sv_to_xy (GtkColorPlane *plane,
gint *x,
gint *y)
{
gdouble s, v;
gint width, height;
width = gtk_widget_get_allocated_width (GTK_WIDGET (plane));
height = gtk_widget_get_allocated_height (GTK_WIDGET (plane));
s = gtk_adjustment_get_value (plane->priv->s_adj);
v = gtk_adjustment_get_value (plane->priv->v_adj);
*x = CLAMP (width * v, 0, width - 1);
*y = CLAMP (height * (1 - s), 0, height - 1);
}
static gboolean