File indexing completed on 2024-04-28 16:55:25
0001 /* 0002 * Copyright © 2006 Novell, Inc. 0003 * 0004 * This program is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU General Public License 0006 * as published by the Free Software Foundation; either version 2 0007 * of the License, or (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 * 0018 */ 0019 0020 /////////////////////////////////////////////////// 0021 //emerald stuff 0022 #include <engine.h> 0023 0024 #if 0 0025 void copy_from_defaults_if_needed() 0026 { 0027 gchar * opath = g_strdup_printf("%s/.emerald/theme",g_get_home_dir()); 0028 gchar * fcont; 0029 gsize len=0; 0030 g_mkdir_with_parents(opath,0755); 0031 g_free(opath); 0032 opath = g_strdup_printf("%s/.emerald/settings.ini",g_get_home_dir()); 0033 if (!g_file_test(opath,G_FILE_TEST_EXISTS)) 0034 { 0035 if (g_file_get_contents(DEFSETTINGSFILE,&fcont,&len,NULL)) 0036 { 0037 g_file_set_contents(opath,fcont,len,NULL); 0038 g_free(fcont); 0039 } 0040 } 0041 g_free(opath); 0042 opath = g_strdup_printf("%s/.emerald/theme/theme.ini",g_get_home_dir()); 0043 if (!g_file_test(opath,G_FILE_TEST_EXISTS)) 0044 { 0045 GDir * d; 0046 d = g_dir_open(DEFTHEMEDIR,0,NULL); 0047 if (d) 0048 { 0049 gchar * n; 0050 while(n=g_dir_read_name(d)) 0051 { 0052 gchar * ipath = g_strdup_printf("%s/%s",DEFTHEMEDIR,n); 0053 gchar * npath = g_strdup_printf("%s/.emerald/theme/%s",g_get_home_dir(),n); 0054 if (g_file_get_contents(ipath,&fcont,&len,NULL)) 0055 { 0056 g_file_set_contents(npath,fcont,len,NULL); 0057 g_free(fcont); 0058 } 0059 g_free(ipath); 0060 g_free(npath); 0061 } 0062 g_dir_close(d); 0063 } 0064 } 0065 g_free(opath); 0066 } 0067 #endif 0068 0069 gchar * make_filename(const gchar * sect, const gchar * key, const gchar * ext) 0070 { 0071 return g_strdup_printf("%s/.emerald/theme/%s.%s.%s",g_get_home_dir(),sect,key,ext); 0072 } 0073 void cairo_set_source_alpha_color(cairo_t * cr, alpha_color * c) 0074 { 0075 cairo_set_source_rgba(cr,c->color.r,c->color.g,c->color.b,c->alpha); 0076 } 0077 void load_color_setting(GKeyFile * f, decor_color_t * color, const gchar * key, const gchar * sect) 0078 { 0079 GdkColor c; 0080 gchar * s = g_key_file_get_string(f,sect,key,NULL); 0081 if (s) 0082 { 0083 gdk_color_parse(s,&c); 0084 color->r = c.red/65536.0; 0085 color->g = c.green/65536.0; 0086 color->b = c.blue/65536.0; 0087 g_free(s); 0088 } 0089 } 0090 void load_shadow_color_setting(GKeyFile * f, gint sc[3], const gchar * key, const gchar * sect) 0091 { 0092 GdkColor c; 0093 gchar * s = g_key_file_get_string(f,sect,key,NULL); 0094 if (s) 0095 { 0096 gdk_color_parse(s,&c); 0097 sc[0]=c.red; 0098 sc[1]=c.green; 0099 sc[2]=c.blue; 0100 g_free(s); 0101 } 0102 } 0103 void load_float_setting(GKeyFile * f, gdouble * d, const gchar * key, const gchar * sect) 0104 { 0105 gchar * s = g_key_file_get_string(f,sect,key,NULL); 0106 if (s) 0107 { 0108 *d = g_ascii_strtod(s,NULL); 0109 g_free(s); 0110 } 0111 } 0112 void load_int_setting(GKeyFile * f, gint * i, const gchar * key, const gchar * sect) 0113 { 0114 GError * e = NULL; 0115 gint ii = g_key_file_get_integer(f,sect,key,&e); 0116 if (!e) 0117 *i=ii; 0118 } 0119 void load_bool_setting(GKeyFile * f, gboolean * b, const gchar * key, const gchar * sect) 0120 { 0121 GError * e = NULL; 0122 gboolean bb = g_key_file_get_boolean(f,sect,key,&e); 0123 if (!e) 0124 *b=bb; 0125 } 0126 void load_font_setting(GKeyFile * f, PangoFontDescription ** fd, const gchar * key, const gchar * sect) 0127 { 0128 gchar * s = g_key_file_get_string(f,sect,key,NULL); 0129 if (s) 0130 { 0131 #if 0 0132 if (*fd) 0133 pango_font_description_free(*fd); 0134 *fd = pango_font_description_from_string(s); 0135 #endif 0136 g_free(s); 0137 } 0138 } 0139 void load_string_setting(GKeyFile * f, gchar ** s, const gchar * key, const gchar * sect) 0140 { 0141 gchar * st = g_key_file_get_string(f,sect,key,NULL); 0142 if (st) 0143 { 0144 if (*s) 0145 g_free(*s); 0146 *s = st; 0147 } 0148 } 0149 void 0150 rounded_rectangle (cairo_t *cr, 0151 double x, 0152 double y, 0153 double w, 0154 double h, 0155 int corner, 0156 window_settings * ws, 0157 double radius) 0158 { 0159 if (radius==0) 0160 corner=0; 0161 0162 if (corner & CORNER_TOPLEFT) 0163 cairo_move_to (cr, x + radius, y); 0164 else 0165 cairo_move_to (cr, x, y); 0166 0167 if (corner & CORNER_TOPRIGHT) 0168 cairo_arc (cr, x + w - radius, y + radius, radius, 0169 M_PI * 1.5, M_PI * 2.0); 0170 else 0171 cairo_line_to (cr, x + w, y); 0172 0173 if (corner & CORNER_BOTTOMRIGHT) 0174 cairo_arc (cr, x + w - radius, y + h - radius, radius, 0175 0.0, M_PI * 0.5); 0176 else 0177 cairo_line_to (cr, x + w, y + h); 0178 0179 if (corner & CORNER_BOTTOMLEFT) 0180 cairo_arc (cr, x + radius, y + h - radius, radius, 0181 M_PI * 0.5, M_PI); 0182 else 0183 cairo_line_to (cr, x, y + h); 0184 0185 if (corner & CORNER_TOPLEFT) 0186 cairo_arc (cr, x + radius, y + radius, radius, M_PI, M_PI * 1.5); 0187 else 0188 cairo_line_to (cr, x, y); 0189 } 0190 0191 void 0192 fill_rounded_rectangle (cairo_t *cr, 0193 double x, 0194 double y, 0195 double w, 0196 double h, 0197 int corner, 0198 alpha_color * c0, 0199 alpha_color * c1, 0200 int gravity, 0201 window_settings * ws, 0202 double radius) 0203 { 0204 cairo_pattern_t *pattern; 0205 0206 rounded_rectangle (cr, x, y, w, h, corner,ws,radius); 0207 0208 if (gravity & SHADE_RIGHT) 0209 { 0210 x = x + w; 0211 w = -w; 0212 } 0213 else if (!(gravity & SHADE_LEFT)) 0214 { 0215 x = w = 0; 0216 } 0217 0218 if (gravity & SHADE_BOTTOM) 0219 { 0220 y = y + h; 0221 h = -h; 0222 } 0223 else if (!(gravity & SHADE_TOP)) 0224 { 0225 y = h = 0; 0226 } 0227 0228 if (w && h) 0229 { 0230 cairo_matrix_t matrix; 0231 0232 pattern = cairo_pattern_create_radial (0.0, 0.0, 0.0, 0.0, 0.0, w); 0233 0234 cairo_matrix_init_scale (&matrix, 1.0, w / h); 0235 cairo_matrix_translate (&matrix, -(x + w), -(y + h)); 0236 0237 cairo_pattern_set_matrix (pattern, &matrix); 0238 } 0239 else 0240 { 0241 pattern = cairo_pattern_create_linear (x + w, y + h, x, y); 0242 } 0243 0244 cairo_pattern_add_color_stop_rgba (pattern, 0.0, c0->color.r, c0->color.g, 0245 c0->color.b,c0->alpha); 0246 0247 cairo_pattern_add_color_stop_rgba (pattern, 1.0, c1->color.r, c1->color.g, 0248 c1->color.b,c1->alpha); 0249 0250 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD); 0251 0252 cairo_set_source (cr, pattern); 0253 cairo_fill (cr); 0254 cairo_pattern_destroy (pattern); 0255 } 0256 0257