[geany/geany] e185f4: Merge pull request #1536 from vfaronov/fix-color-chooser
Enrico Tröger
git-noreply at xxxxx
Sat Jul 15 10:37:12 UTC 2017
Branch: refs/heads/master
Author: Enrico Tröger <enrico.troeger at uvena.de>
Committer: GitHub <noreply at github.com>
Date: Sat, 15 Jul 2017 10:37:12 UTC
Commit: e185f4784f1d93f2b9b322ee9ba132ba286607ab
https://github.com/geany/geany/commit/e185f4784f1d93f2b9b322ee9ba132ba286607ab
Log Message:
-----------
Merge pull request #1536 from vfaronov/fix-color-chooser
Fix converting color to hex for insertion
Modified Paths:
--------------
src/utils.c
src/win32.c
Modified: src/utils.c
14 lines changed, 9 insertions(+), 5 deletions(-)
===================================================================
@@ -451,10 +451,14 @@ const gchar *utils_path_skip_root(const gchar *path)
}
+/* Convert a fractional @a val in the range [0, 1] to a whole value in the range [0, @a factor].
+ * In particular, this is used for converting a @c GdkColor to the "#RRGGBB" format in a way that
+ * agrees with GTK+, so the "#RRGGBB" in the color picker is the same "#RRGGBB" that is inserted
+ * into the document. See https://github.com/geany/geany/issues/1527
+ */
gdouble utils_scale_round(gdouble val, gdouble factor)
{
- /*val = floor(val * factor + 0.5);*/
- val = floor(val);
+ val = floor(val * factor + 0.5);
val = MAX(val, 0);
val = MIN(val, factor);
@@ -881,9 +885,9 @@ gchar *utils_get_hex_from_color(GdkColor *color)
g_return_val_if_fail(color != NULL, NULL);
return g_strdup_printf("#%02X%02X%02X",
- (guint) (utils_scale_round(color->red / 256, 255)),
- (guint) (utils_scale_round(color->green / 256, 255)),
- (guint) (utils_scale_round(color->blue / 256, 255)));
+ (guint) (utils_scale_round(color->red / 65535.0, 255)),
+ (guint) (utils_scale_round(color->green / 65535.0, 255)),
+ (guint) (utils_scale_round(color->blue / 65535.0, 255)));
}
Modified: src/win32.c
5 lines changed, 1 insertions(+), 4 deletions(-)
===================================================================
@@ -626,10 +626,7 @@ void win32_show_color_dialog(const gchar *colour)
{
rgb_current = cc.rgbResult;
g_snprintf(hex, 11, "#%02X%02X%02X",
- (guint) (utils_scale_round(GetRValue(rgb_current), 255)),
- (guint) (utils_scale_round(GetGValue(rgb_current), 255)),
- (guint) (utils_scale_round(GetBValue(rgb_current), 255)));
-
+ GetRValue(rgb_current), GetGValue(rgb_current), GetBValue(rgb_current));
editor_insert_color(doc->editor, hex);
}
g_free(hex);
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list