pidgin/gtkstyle.c

branch
trac-17174
changeset 38822
93c0cd117e1d
parent 38699
e7b5011e4728
child 39277
68c17ba18f33
equal deleted inserted replaced
38821:329cf2453fb8 38822:93c0cd117e1d
1 /*
2 * @file gtkstyle.c GTK+ Style utility functions
3 * @ingroup pidgin
4 */
5
6 /* pidgin
7 *
8 * Pidgin is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 *
26 */
27 #include "gtkstyle.h"
28
29 /* Assume light mode */
30 static gboolean dark_mode_cache = FALSE;
31
32 gboolean
33 pidgin_style_is_dark(GtkStyle *style) {
34 GdkColor bg;
35
36 if (!style) {
37 return dark_mode_cache;
38 }
39
40 bg = style->base[GTK_STATE_NORMAL];
41
42 if (bg.red != 0xFFFF || bg.green != 0xFFFF || bg.blue != 0xFFFF) {
43 dark_mode_cache = ((int) bg.red + (int) bg.green + (int) bg.blue) < (65536 * 3 / 2);
44 }
45
46 return dark_mode_cache;
47 }
48
49 void
50 pidgin_style_adjust_contrast(GtkStyle *style, GdkColor *color) {
51 if (pidgin_style_is_dark(style)) {
52 gdouble r, g, b, h, s, v;
53
54 r = ((gdouble) color->red) / 65535.0;
55 g = ((gdouble) color->green) / 65535.0;
56 b = ((gdouble) color->blue) / 65535.0;
57
58 gtk_rgb_to_hsv(r, g, b, &h, &s, &v);
59
60 v += 0.3;
61 v = v > 1.0 ? 1.0 : v;
62 s = 0.7;
63
64 gtk_hsv_to_rgb(h, s, v, &r, &g, &b);
65
66 color->red = (guint16) (r * 65535.0);
67 color->green = (guint16) (g * 65535.0);
68 color->blue = (guint16) (b * 65535.0);
69 }
70 }

mercurial