File indexing completed on 2024-05-12 17:10:52
0001 /* 0002 * Line theme engine 0003 * 0004 * line.c 0005 * 0006 * Copyright (C) 2006 Quinn Storm <livinglatexkali@gmail.com> 0007 * Copyright (C) 2007 Patrick Niklaus <patrick.niklaus@googlemail.com> 0008 * 0009 * This program is free software; you can redistribute it and/or 0010 * modify it under the terms of the GNU General Public License 0011 * as published by the Free Software Foundation; either version 2 0012 * of the License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU General Public License 0020 * along with this program; if not, write to the Free Software 0021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0022 * 0023 */ 0024 0025 #include <emerald.h> 0026 #include <engine.h> 0027 0028 #include "line_engine.h" 0029 0030 #define SECT "line_settings" 0031 0032 #define SHADOW_FIX 0033 0034 /* 0035 * color privates 0036 */ 0037 typedef struct _private_fs 0038 { 0039 alpha_color border; 0040 alpha_color title_bar; 0041 } private_fs; 0042 0043 /* 0044 * settings privates 0045 */ 0046 typedef struct _private_ws 0047 { 0048 } private_ws; 0049 0050 void get_meta_info (EngineMetaInfo * emi) 0051 { 0052 emi->version = g_strdup("0.1"); 0053 emi->description = g_strdup(_("Based on original legacy")); 0054 emi->last_compat = g_strdup("0.0"); // old themes still compatible 0055 emi->icon = gdk_pixbuf_new_from_inline(-1, my_pixbuf, TRUE, NULL); 0056 } 0057 0058 #ifdef SHADOW_FIX 0059 static void draw_shadow_background(decor_t * d, cairo_t * cr) 0060 { 0061 cairo_matrix_t matrix; 0062 double w, x2; 0063 gint width, height; 0064 gint left, right, top, bottom; 0065 window_settings *ws = d->fs->ws; 0066 0067 if (!ws->large_shadow_pixmap) 0068 { 0069 cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); 0070 cairo_paint(cr); 0071 0072 return; 0073 } 0074 0075 gdk_drawable_get_size(ws->large_shadow_pixmap, &width, &height); 0076 0077 left = ws->left_space + ws->left_corner_space; 0078 right = ws->right_space + ws->right_corner_space; 0079 top = ws->top_space + ws->top_corner_space; 0080 bottom = ws->bottom_space + ws->bottom_corner_space; 0081 0082 if (d->width - left - right < 0) 0083 { 0084 left = d->width / 2; 0085 right = d->width - left; 0086 } 0087 0088 if (d->height - top - bottom < 0) 0089 { 0090 top = d->height / 2; 0091 bottom = d->height - top; 0092 } 0093 0094 w = d->width - left - right; 0095 0096 x2 = d->width - right; 0097 0098 /* top left */ 0099 cairo_matrix_init_identity(&matrix); 0100 cairo_pattern_set_matrix(ws->shadow_pattern, &matrix); 0101 cairo_set_source(cr, ws->shadow_pattern); 0102 cairo_rectangle(cr, 0.0, 0.0, left, top); 0103 cairo_fill(cr); 0104 0105 /* top */ 0106 if (w > 0) 0107 { 0108 cairo_matrix_init_translate(&matrix, left, 0.0); 0109 cairo_matrix_scale(&matrix, 1.0 / w, 1.0); 0110 cairo_matrix_translate(&matrix, -left, 0.0); 0111 cairo_pattern_set_matrix(ws->shadow_pattern, &matrix); 0112 cairo_set_source(cr, ws->shadow_pattern); 0113 cairo_rectangle(cr, left, 0.0, w, top); 0114 cairo_fill(cr); 0115 } 0116 0117 0118 /* top right */ 0119 cairo_matrix_init_translate(&matrix, width - right - x2, 0.0); 0120 cairo_pattern_set_matrix(ws->shadow_pattern, &matrix); 0121 cairo_set_source(cr, ws->shadow_pattern); 0122 cairo_rectangle(cr, x2, 0.0, right, top); 0123 cairo_clip_preserve(cr); 0124 cairo_fill(cr); 0125 } 0126 #endif 0127 0128 void engine_draw_frame (decor_t * d, cairo_t * cr) 0129 { 0130 frame_settings *fs = d->fs; 0131 private_fs *pfs = fs->engine_fs; 0132 window_settings *ws = fs->ws; 0133 0134 double x1, y1, x2, y2; 0135 0136 x1 = ws->left_space - ws->win_extents.left; 0137 y1 = ws->top_space - ws->win_extents.top; 0138 x2 = d->width - ws->right_space + ws->win_extents.right; 0139 y2 = d->height - ws->bottom_space + ws->win_extents.bottom; 0140 int top; 0141 top = ws->win_extents.top + ws->titlebar_height; 0142 0143 double m1 = MIN(ws->win_extents.left, ws->win_extents.right); 0144 double m2 = MIN(ws->win_extents.top, ws->win_extents.bottom); 0145 0146 double border_width = MIN(m1, m2); 0147 double border_offset = border_width/2.0; 0148 0149 cairo_set_line_width (cr, border_width); 0150 0151 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); 0152 0153 rounded_rectangle (cr, 0154 x1 + border_offset, 0155 y1 + top - border_offset, 0156 x2 - x1 - border_width, 0157 y2 - y1 - top, 0158 0, ws, 0); 0159 cairo_set_source_alpha_color(cr, &pfs->border); 0160 cairo_stroke (cr); 0161 0162 // title bar 0163 if (pfs->title_bar.alpha != 0.0) { 0164 rounded_rectangle (cr, 0165 x1, 0166 y1, 0167 x2 - x1, 0168 top, 0169 0, ws, 0); 0170 cairo_set_source_alpha_color(cr, &pfs->title_bar); 0171 cairo_fill(cr); 0172 } else { 0173 cairo_save(cr); 0174 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); 0175 cairo_rectangle (cr, 0.0, 0.0, d->width, top + y1 - border_width); 0176 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); 0177 cairo_fill(cr); 0178 cairo_restore(cr); 0179 0180 // FIXME => find a proper solution for this 0181 #ifdef SHADOW_FIX 0182 cairo_rectangle (cr, 0.0, 0.0, d->width, top + y1 - border_width); 0183 cairo_clip(cr); 0184 cairo_translate(cr, 0.0, ws->top_space + ws->win_extents.top); 0185 draw_shadow_background(d, cr); 0186 cairo_translate(cr, 0.0, -ws->top_space - ws->win_extents.top); 0187 #endif 0188 } 0189 } 0190 0191 void load_engine_settings(GKeyFile * f, window_settings * ws) 0192 { 0193 PFACS(border); 0194 PFACS(title_bar); 0195 } 0196 0197 void init_engine(window_settings * ws) 0198 { 0199 private_fs * pfs; 0200 private_ws * pws; 0201 0202 pws = malloc(sizeof(private_ws)); 0203 ws->engine_ws = pws; 0204 bzero(pws,sizeof(private_ws)); 0205 0206 pfs = malloc(sizeof(private_fs)); 0207 ws->fs_act->engine_fs = pfs; 0208 bzero(pfs, sizeof(private_fs)); 0209 ACOLOR(border, 0.0, 0.0, 0.0, 1.0); 0210 ACOLOR(title_bar, 0.0, 0.0, 0.0, 0.3); 0211 0212 pfs = malloc(sizeof(private_fs)); 0213 ws->fs_inact->engine_fs = pfs; 0214 bzero(pfs,sizeof(private_fs)); 0215 ACOLOR(border, 0.0, 0.0, 0.0, 1.0); 0216 ACOLOR(title_bar, 0.0, 0.0, 0.0, 0.0); 0217 } 0218 0219 void fini_engine(window_settings * ws) 0220 { 0221 free(ws->fs_act->engine_fs); 0222 free(ws->fs_inact->engine_fs); 0223 } 0224 #if 0 0225 void my_engine_settings(GtkWidget * hbox, gboolean active) 0226 { 0227 GtkWidget * vbox; 0228 GtkWidget * scroller; 0229 vbox = gtk_vbox_new(FALSE,2); 0230 gtk_box_pack_startC(hbox, vbox, TRUE, TRUE, 0); 0231 gtk_box_pack_startC(vbox, gtk_label_new(active?"Active Window":"Inactive Window"), FALSE, FALSE, 0); 0232 gtk_box_pack_startC(vbox, gtk_hseparator_new(), FALSE, FALSE, 0); 0233 scroller = gtk_scrolled_window_new(NULL,NULL); 0234 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); 0235 gtk_box_pack_startC(vbox, scroller, TRUE, TRUE, 0); 0236 0237 table_new(3, FALSE, FALSE); 0238 0239 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroller), GTK_WIDGET(get_current_table())); 0240 0241 make_labels(_("Colors")); 0242 table_append_separator(); 0243 ACAV(_("Outer Frame Blend"), "border", SECT); 0244 ACAV(_("Title Bar"), "title_bar", SECT); 0245 } 0246 0247 void layout_engine_colors(GtkWidget * vbox) 0248 { 0249 GtkWidget * hbox; 0250 hbox = gtk_hbox_new(FALSE, 2); 0251 gtk_box_pack_startC(vbox, hbox, TRUE, TRUE, 0); 0252 my_engine_settings(hbox, TRUE); 0253 gtk_box_pack_startC(hbox, gtk_vseparator_new(), FALSE, FALSE, 0); 0254 my_engine_settings(hbox, FALSE); 0255 } 0256 0257 void layout_engine_settings(GtkWidget * vbox) 0258 { 0259 GtkWidget * note; 0260 note = gtk_notebook_new(); 0261 gtk_box_pack_startC(vbox, note, TRUE, TRUE, 0); 0262 layout_engine_colors(build_notebook_page(_("Colors"), note)); 0263 } 0264 #endif