~mjz/awn/uber-lucido

« back to all changes in this revision

Viewing changes to src/awn-background-lucido.c

  • Committer: Ulbadulba
  • Date: 2010-05-13 11:39:42 UTC
  • Revision ID: albyrock87@gmail.com-20100513113942-qditjpqgb9kgjroq
Formatting done. Old code deleted. Author to me. Curves symmetry now controls symmetry. New option Stripe Width added, but it brokes awnSettings.py, why?

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *  along with this program; if not, write to the Free Software
16
16
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
17
17
 *
18
 
 *  Author : Michal Hruby <michal.mhr@gmail.com>
 
18
 *  Author : Alberto Aldegheri <albyrock87+dev@gmail.com>
19
19
 *
20
20
 */
21
21
 
28
28
#include "awn-background-lucido.h"
29
29
#include "awn-applet-manager.h"
30
30
 
31
 
G_DEFINE_TYPE (AwnBackgroundLucido, awn_background_lucido, AWN_TYPE_BACKGROUND_FLAT)
 
31
G_DEFINE_TYPE(AwnBackgroundLucido, awn_background_lucido, AWN_TYPE_BACKGROUND_FLAT)
32
32
 
33
33
#define AWN_BACKGROUND_LUCIDO_GET_PRIVATE(obj) ( \
34
 
  G_TYPE_INSTANCE_GET_PRIVATE (obj, AWN_TYPE_BACKGROUND_LUCIDO, \
35
 
  AwnBackgroundLucidoPrivate))
36
 
 
37
 
struct _AwnBackgroundLucidoPrivate
38
 
{
39
 
  gint radius;
40
 
  gint top_pad;
41
 
 
42
 
  gboolean in_corner;
43
 
 
44
 
  GtkWidget *separator;
45
 
};
46
 
 
47
 
static void awn_background_lucido_draw (AwnBackground  *bg,
48
 
                                      cairo_t        *cr,
49
 
                                      GtkPositionType  position,
50
 
                                      GdkRectangle   *area);
51
 
 
52
 
static void awn_background_lucido_get_shape_mask (AwnBackground  *bg,
53
 
                                                cairo_t        *cr,
54
 
                                                GtkPositionType  position,
55
 
                                                GdkRectangle   *area);
56
 
 
57
 
static void awn_background_lucido_padding_request (AwnBackground *bg,
58
 
                                                 GtkPositionType position,
59
 
                                                 guint *padding_top,
60
 
                                                 guint *padding_bottom,
61
 
                                                 guint *padding_left,
62
 
                                                 guint *padding_right);
63
 
 
64
 
static void
65
 
awn_background_lucido_constructed (GObject *object)
66
 
{
67
 
  G_OBJECT_CLASS (awn_background_lucido_parent_class)->constructed (object);
68
 
}
69
 
 
70
 
static void
71
 
awn_background_lucido_dispose (GObject *object)
72
 
{
73
 
  G_OBJECT_CLASS (awn_background_lucido_parent_class)->dispose (object);
74
 
}
75
 
 
76
 
static void
77
 
awn_background_lucido_class_init (AwnBackgroundLucidoClass *klass)
78
 
{
79
 
  AwnBackgroundClass *bg_class = AWN_BACKGROUND_CLASS (klass);
80
 
 
81
 
  GObjectClass *obj_class = G_OBJECT_CLASS (klass);
 
34
    G_TYPE_INSTANCE_GET_PRIVATE (obj, AWN_TYPE_BACKGROUND_LUCIDO, \
 
35
                                 AwnBackgroundLucidoPrivate))
 
36
 
 
37
static void awn_background_lucido_draw(AwnBackground  *bg,
 
38
                                       cairo_t        *cr,
 
39
                                       GtkPositionType  position,
 
40
                                       GdkRectangle   *area);
 
41
 
 
42
static void awn_background_lucido_get_shape_mask(AwnBackground  *bg,
 
43
                                                  cairo_t        *cr,
 
44
                                                  GtkPositionType  position,
 
45
                                                  GdkRectangle   *area);
 
46
 
 
47
static void awn_background_lucido_padding_request(AwnBackground *bg,
 
48
                                                    GtkPositionType position,
 
49
                                                    guint *padding_top,
 
50
                                                    guint *padding_bottom,
 
51
                                                    guint *padding_left,
 
52
                                                    guint *padding_right);
 
53
 
 
54
static void
 
55
awn_background_lucido_constructed(GObject *object)
 
56
{
 
57
  G_OBJECT_CLASS(awn_background_lucido_parent_class)->constructed(object);
 
58
}
 
59
 
 
60
static void
 
61
awn_background_lucido_dispose(GObject *object)
 
62
{
 
63
  G_OBJECT_CLASS(awn_background_lucido_parent_class)->dispose(object);
 
64
}
 
65
 
 
66
static void
 
67
awn_background_lucido_class_init(AwnBackgroundLucidoClass *klass)
 
68
{
 
69
  AwnBackgroundClass *bg_class = AWN_BACKGROUND_CLASS(klass);
 
70
 
 
71
  GObjectClass *obj_class = G_OBJECT_CLASS(klass);
82
72
  obj_class->constructed  = awn_background_lucido_constructed;
83
73
  obj_class->dispose = awn_background_lucido_dispose;
84
74
 
87
77
  bg_class->get_shape_mask = awn_background_lucido_get_shape_mask;
88
78
  bg_class->get_input_shape_mask = awn_background_lucido_get_shape_mask;
89
79
 
90
 
  g_type_class_add_private (obj_class, sizeof (AwnBackgroundLucidoPrivate));
91
80
}
92
81
 
93
 
 
94
82
static void
95
 
awn_background_lucido_init (AwnBackgroundLucido *bg)
 
83
awn_background_lucido_init(AwnBackgroundLucido *bg)
96
84
{
97
 
  bg->priv = AWN_BACKGROUND_LUCIDO_GET_PRIVATE (bg);
98
85
 
99
 
  GtkWidget *image = gtk_image_new ();
100
 
  bg->priv->separator = image;
101
86
}
102
87
 
103
 
AwnBackground * 
104
 
awn_background_lucido_new (DesktopAgnosticConfigClient *client, AwnPanel *panel)
 
88
AwnBackground *
 
89
awn_background_lucido_new(DesktopAgnosticConfigClient *client, AwnPanel *panel)
105
90
{
106
91
  AwnBackground *bg;
107
92
 
108
 
  bg = g_object_new (AWN_TYPE_BACKGROUND_LUCIDO,
109
 
                     "client", client,
110
 
                     "panel", panel,
111
 
                     NULL);
 
93
  bg = g_object_new(AWN_TYPE_BACKGROUND_LUCIDO,
 
94
                    "client", client,
 
95
                    "panel", panel,
 
96
                    NULL);
112
97
  return bg;
113
98
}
114
99
 
116
101
 * Drawing functions
117
102
 */
118
103
 
119
 
static void 
120
 
_background_lucido_path_create(  cairo_t *cr,
121
 
                                  gdouble x,
122
 
                                  gdouble y,
123
 
                                  gint w,
124
 
                                  gint h,
125
 
                                  gfloat fill,
126
 
                                  gfloat dcurve,
127
 
                                  gint internal )
128
 
{    
129
 
  if(fill>0.5)
130
 
    fill-=0.5;
131
 
  gdouble dx = w*fill;
132
 
  gdouble x1 = x+dx+dcurve;
133
 
  gdouble x2 = x+w-dx-dcurve;
134
 
  gdouble y2 = y+h;
135
 
  if(fill>0.9)
136
 
  {
137
 
    if(internal)
138
 
      return;
139
 
//  cairo_new_path(cr);
140
 
    cairo_rectangle(cr,x,y,x+w,y2);
141
 
    return;
142
 
  }
 
104
static void
 
105
_background_lucido_path_create(cairo_t *cr,
 
106
                               gdouble x,
 
107
                               gdouble y,
 
108
                               gint w,
 
109
                               gint h,
 
110
                               gfloat stripe,
 
111
                               gfloat dcurve,
 
112
                               gfloat symmetry,
 
113
                               gint internal)
 
114
{
 
115
 
 
116
  gdouble dx = ( w - stripe * w );
 
117
  gdouble x1 = x + dx * symmetry + dcurve;
 
118
  gdouble x2 = x + w - dx * ( 1.0 - symmetry ) - dcurve;
 
119
  gdouble y2 = y + h;
 
120
 
143
121
  cairo_new_path(cr);
 
122
 
144
123
  if(internal)
145
 
  { 
146
 
    cairo_move_to(cr,x+dx,y);
147
 
    
148
 
    cairo_curve_to(cr,x1,y,x1,y2-5,x1+dcurve,y2-5);
149
 
    
150
 
    cairo_line_to(cr,x2-dcurve,y2-5);
151
 
    
152
 
    cairo_curve_to(cr,x2,y2-5,x2,y,x2+dcurve,y);
153
 
  }else{
154
 
    cairo_move_to(cr,x,y);
155
 
    cairo_line_to(cr,x+dx,y);
156
 
    
157
 
    cairo_curve_to(cr,x1,y,x1,y2-5,x1+dcurve,y2-5);
158
 
    
159
 
    cairo_line_to(cr,x2-dcurve,y2-5);
160
 
    
161
 
    cairo_curve_to(cr,x2,y2-5,x2,y,x2+dcurve,y);
162
 
    
163
 
    cairo_line_to(cr,x+w,y);
164
 
          cairo_line_to(cr,x+w,y2);
165
 
          cairo_line_to(cr,x,y2);                                               
166
 
        }
167
 
        cairo_close_path(cr);
 
124
  {
 
125
    cairo_move_to(cr, x1 - dcurve, y);
 
126
 
 
127
    cairo_curve_to(cr, x1, y, x1, y2 - 5, x1 + dcurve, y2 - 5);
 
128
 
 
129
    cairo_line_to(cr, x2 - dcurve, y2 - 5);
 
130
 
 
131
    cairo_curve_to(cr, x2, y2 - 5, x2, y, x2 + dcurve, y);
 
132
  }
 
133
  else
 
134
  {
 
135
    cairo_move_to(cr, x, y);
 
136
    cairo_line_to(cr, x1 - dcurve, y);
 
137
 
 
138
    cairo_curve_to(cr, x1, y, x1, y2 - 5, x1 + dcurve, y2 - 5);
 
139
 
 
140
    cairo_line_to(cr, x2 - dcurve, y2 - 5);
 
141
 
 
142
    cairo_curve_to(cr, x2, y2 - 5, x2, y, x2 + dcurve, y);
 
143
 
 
144
    cairo_line_to(cr, x + w, y);
 
145
    cairo_line_to(cr, x + w, y2);
 
146
    cairo_line_to(cr, x, y2);
 
147
  }
 
148
 
 
149
  cairo_close_path(cr);
168
150
}
169
151
static void
170
 
draw_top_bottom_background (AwnBackground  *bg,
171
 
                            cairo_t        *cr,
172
 
                            gint            width,
173
 
                            gint            height)
 
152
draw_top_bottom_background(AwnBackground  *bg,
 
153
                           cairo_t        *cr,
 
154
                           gint            width,
 
155
                           gint            height)
174
156
{
175
157
  cairo_pattern_t *pat;
176
158
  cairo_pattern_t *pat_hi;
177
159
 
178
160
  /* Make sure the bar gets drawn on the 0.5 pixels (for sharp edges) */
179
 
  cairo_translate (cr, 0.5, 0.5);
 
161
  cairo_translate(cr, 0.5, 0.5);
180
162
 
181
163
  /* Basic set-up */
182
 
  cairo_set_line_width (cr, 1.0);
183
 
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
164
  cairo_set_line_width(cr, 1.0);
 
165
  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
184
166
 
185
 
  if (gtk_widget_is_composited (GTK_WIDGET (bg->panel)) == FALSE)
 
167
  if(gtk_widget_is_composited(GTK_WIDGET(bg->panel)) == FALSE)
186
168
  {
187
169
    goto paint_lines;
188
170
  }
189
 
  
190
 
  gfloat fill = bg->curves_symmetry;
 
171
 
 
172
  gfloat fill = bg->stripe_width;
191
173
  gfloat curve_width = bg->curviness;
 
174
  gfloat symmetry = bg->curves_symmetry;
192
175
 
193
176
  /* Prepare the internal background */
194
 
  pat = cairo_pattern_create_linear (0, 0, 0, height);
195
 
  awn_cairo_pattern_add_color_stop_color (pat, 0.0, bg->border_color);
196
 
  awn_cairo_pattern_add_color_stop_color (pat, 1.0, bg->hilight_color);
197
 
  
 
177
  pat = cairo_pattern_create_linear(0, 0, 0, height);
 
178
  awn_cairo_pattern_add_color_stop_color(pat, 0.0, bg->border_color);
 
179
  awn_cairo_pattern_add_color_stop_color(pat, 1.0, bg->hilight_color);
 
180
 
198
181
  /* Draw the internal background  */
199
 
  cairo_save (cr);
200
 
  _background_lucido_path_create(cr,-1,0,width+2,height,fill,curve_width,1);  
201
 
  cairo_clip (cr);
202
 
  cairo_set_source (cr, pat);
203
 
  cairo_paint (cr);
204
 
  cairo_restore (cr);
205
 
  cairo_pattern_destroy (pat);
206
 
  
 
182
  cairo_save(cr);
 
183
  _background_lucido_path_create(cr, -1, 0, width + 2, height,
 
184
                                 fill, curve_width, symmetry, 1);
 
185
  cairo_clip(cr);
 
186
  cairo_set_source(cr, pat);
 
187
  cairo_paint(cr);
 
188
  cairo_restore(cr);
 
189
  cairo_pattern_destroy(pat);
 
190
 
207
191
  /* Draw internal pattern if needed */
208
 
  if( fill<0.5 && bg->enable_pattern && bg->pattern )
 
192
  if(fill < 0.5 && bg->enable_pattern && bg->pattern)
209
193
  {
210
194
    /* Prepare pattern */
211
 
    pat = cairo_pattern_create_for_surface (bg->pattern);
212
 
    cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
 
195
    pat = cairo_pattern_create_for_surface(bg->pattern);
 
196
    cairo_pattern_set_extend(pat, CAIRO_EXTEND_REPEAT);
213
197
    /* Draw */
214
 
    cairo_save (cr);
215
 
    _background_lucido_path_create(cr,-1,0,width+2,height,fill,curve_width,1);  
216
 
    cairo_clip (cr);
217
 
    cairo_set_source (cr, pat);
218
 
    cairo_paint (cr);
219
 
    cairo_restore (cr);
220
 
    cairo_pattern_destroy (pat);
 
198
    cairo_save(cr);
 
199
    _background_lucido_path_create(cr, -1, 0, width + 2, height,
 
200
                                   fill, curve_width, symmetry , 1);
 
201
    cairo_clip(cr);
 
202
    cairo_set_source(cr, pat);
 
203
    cairo_paint(cr);
 
204
    cairo_restore(cr);
 
205
    cairo_pattern_destroy(pat);
221
206
  }
222
 
  
 
207
 
223
208
  /* Draw the hi-light (internal) */
224
 
  pat_hi = cairo_pattern_create_linear (0, 0, 0, (height/3.0));
225
 
  awn_cairo_pattern_add_color_stop_color (pat_hi, 0.0, bg->g_histep_1);
226
 
  awn_cairo_pattern_add_color_stop_color (pat_hi, 1.0, bg->g_histep_2);
227
 
  cairo_rectangle (cr,0,0,width,height/3.0);
228
 
  cairo_set_source (cr, pat_hi);
229
 
  cairo_fill (cr);
230
 
  cairo_pattern_destroy (pat_hi);
231
 
  /**/  
232
 
  
233
 
  /* Prepare external background */  
234
 
  pat = cairo_pattern_create_linear (0, 0, 0, height);
235
 
  awn_cairo_pattern_add_color_stop_color (pat, 0.0, bg->g_step_1);
236
 
  awn_cairo_pattern_add_color_stop_color (pat, 1.0, bg->g_step_2);
 
209
  pat_hi = cairo_pattern_create_linear(0, 0, 0, (height / 3.0));
 
210
  awn_cairo_pattern_add_color_stop_color(pat_hi, 0.0, bg->g_histep_1);
 
211
  awn_cairo_pattern_add_color_stop_color(pat_hi, 1.0, bg->g_histep_2);
 
212
  cairo_rectangle(cr, 0, 0, width, height / 3.0);
 
213
  cairo_set_source(cr, pat_hi);
 
214
  cairo_fill(cr);
 
215
  cairo_pattern_destroy(pat_hi);
 
216
  /**/
 
217
 
 
218
  /* Prepare external background */
 
219
  pat = cairo_pattern_create_linear(0, 0, 0, height);
 
220
  awn_cairo_pattern_add_color_stop_color(pat, 0.0, bg->g_step_1);
 
221
  awn_cairo_pattern_add_color_stop_color(pat, 1.0, bg->g_step_2);
237
222
  /* Draw the external background  */
238
 
  cairo_save (cr);
239
 
  _background_lucido_path_create(cr,-1,0,width+2,height,fill,curve_width,0);  
240
 
  cairo_clip (cr);
241
 
  cairo_set_source (cr, pat);
242
 
  cairo_paint (cr);
243
 
  cairo_restore (cr);
244
 
  cairo_pattern_destroy (pat);
245
 
  
 
223
  cairo_save(cr);
 
224
  _background_lucido_path_create(cr, -1, 0, width + 2, height,
 
225
                                 fill, curve_width, symmetry, 0);
 
226
  cairo_clip(cr);
 
227
  cairo_set_source(cr, pat);
 
228
  cairo_paint(cr);
 
229
  cairo_restore(cr);
 
230
  cairo_pattern_destroy(pat);
 
231
 
246
232
  /* Draw external pattern if needed */
247
 
  if( fill>0.5 && bg->enable_pattern && bg->pattern )
 
233
  if(fill > 0.5 && bg->enable_pattern && bg->pattern)
248
234
  {
249
235
    /* Prepare pattern */
250
 
    pat = cairo_pattern_create_for_surface (bg->pattern);
251
 
    cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
 
236
    pat = cairo_pattern_create_for_surface(bg->pattern);
 
237
    cairo_pattern_set_extend(pat, CAIRO_EXTEND_REPEAT);
252
238
    /* Draw */
253
 
    cairo_save (cr);
254
 
    _background_lucido_path_create(cr,-1,0,width+2,height,fill,curve_width,0);  
255
 
    cairo_clip (cr);
256
 
    cairo_set_source (cr, pat);
257
 
    cairo_paint (cr);
258
 
    cairo_restore (cr);
259
 
    cairo_pattern_destroy (pat);
 
239
    cairo_save(cr);
 
240
    _background_lucido_path_create(cr, -1, 0, width + 2, height,
 
241
                                   fill, curve_width, symmetry, 0);
 
242
    cairo_clip(cr);
 
243
    cairo_set_source(cr, pat);
 
244
    cairo_paint(cr);
 
245
    cairo_restore(cr);
 
246
    cairo_pattern_destroy(pat);
260
247
  }
261
248
 
262
249
  return;
263
250
  // if not composited
264
 
  paint_lines:
 
251
paint_lines:
265
252
 
266
253
  /* Internal border */
267
 
  awn_cairo_set_source_color (cr, bg->hilight_color);
268
 
  //draw_rect (bg, cr, position, 1, 1, width-3, height+3, align, expand);
269
 
  cairo_rectangle (cr,1,1,width-3,height+3);
270
 
  cairo_stroke (cr);
 
254
  awn_cairo_set_source_color(cr, bg->hilight_color);
 
255
  cairo_rectangle(cr, 1, 1, width - 3, height + 3);
 
256
  cairo_stroke(cr);
271
257
 
272
258
  /* External border */
273
 
  awn_cairo_set_source_color (cr, bg->border_color);
274
 
  //draw_rect (bg, cr, position, 0, 0, width-1, height+3, align, expand);
275
 
  cairo_rectangle (cr,1,1,width-1,height+3);
276
 
  cairo_stroke (cr);/**/
 
259
  awn_cairo_set_source_color(cr, bg->border_color);
 
260
  cairo_rectangle(cr, 1, 1, width - 1, height + 3);
 
261
  cairo_stroke(cr); /**/
277
262
}
278
263
 
279
264
 
280
265
static
281
 
void awn_background_lucido_padding_request (AwnBackground *bg,
282
 
                                          GtkPositionType position,
283
 
                                          guint *padding_top,
284
 
                                          guint *padding_bottom,
285
 
                                          guint *padding_left,
286
 
                                          guint *padding_right)
 
266
void awn_background_lucido_padding_request(AwnBackground *bg,
 
267
    GtkPositionType position,
 
268
    guint *padding_top,
 
269
    guint *padding_bottom,
 
270
    guint *padding_left,
 
271
    guint *padding_right)
287
272
{
288
 
  AWN_BACKGROUND_CLASS (awn_background_lucido_parent_class)->padding_request (
289
 
      bg, position, padding_top, padding_bottom, padding_left, padding_right);
 
273
  AWN_BACKGROUND_CLASS(awn_background_lucido_parent_class)->padding_request(
 
274
    bg, position, padding_top, padding_bottom, padding_left, padding_right);
290
275
}
291
276
 
292
277
 
293
278
 
294
 
static void 
295
 
awn_background_lucido_draw (          AwnBackground  *bg,
296
 
                                      cairo_t        *cr,
297
 
                                      GtkPositionType  position,
298
 
                                      GdkRectangle   *area)
 
279
static void
 
280
awn_background_lucido_draw(AwnBackground  *bg,
 
281
                           cairo_t        *cr,
 
282
                           GtkPositionType  position,
 
283
                           GdkRectangle   *area)
299
284
{
300
285
  gint temp;
301
286
  gint x = area->x, y = area->y;
302
287
  gint width = area->width, height = area->height;
303
 
  cairo_save (cr);
 
288
  cairo_save(cr);
304
289
 
305
 
  switch (position)
 
290
  switch(position)
306
291
  {
307
292
    case GTK_POS_RIGHT:
308
 
      cairo_translate (cr, x, y+height);
309
 
      cairo_rotate (cr, M_PI * 1.5);
 
293
      cairo_translate(cr, x, y + height);
 
294
      cairo_rotate(cr, M_PI * 1.5);
310
295
      temp = width;
311
 
      width = height; height = temp;
 
296
      width = height;
 
297
      height = temp;
312
298
      break;
313
299
    case GTK_POS_LEFT:
314
 
      cairo_translate (cr, x+width, y);
315
 
      cairo_rotate (cr, M_PI * 0.5);
 
300
      cairo_translate(cr, x + width, y);
 
301
      cairo_rotate(cr, M_PI * 0.5);
316
302
      temp = width;
317
 
      width = height; height = temp;
 
303
      width = height;
 
304
      height = temp;
318
305
      break;
319
306
    case GTK_POS_TOP:
320
 
      cairo_translate (cr, x+width, y+height);
321
 
      cairo_rotate (cr, M_PI);
 
307
      cairo_translate(cr, x + width, y + height);
 
308
      cairo_rotate(cr, M_PI);
322
309
      break;
323
310
    default:
324
 
      cairo_translate (cr, x, y);
 
311
      cairo_translate(cr, x, y);
325
312
      break;
326
313
  }
327
314
 
328
 
  draw_top_bottom_background (bg, cr, width, height);
 
315
  draw_top_bottom_background(bg, cr, width, height);
329
316
 
330
 
  cairo_restore (cr);
 
317
  cairo_restore(cr);
331
318
}
332
319
 
333
 
static void 
334
 
awn_background_lucido_get_shape_mask (AwnBackground  *bg,
335
 
                                    cairo_t        *cr, 
336
 
                                    GtkPositionType  position,
337
 
                                    GdkRectangle   *area)
 
320
static void
 
321
awn_background_lucido_get_shape_mask(AwnBackground  *bg,
 
322
                                     cairo_t        *cr,
 
323
                                     GtkPositionType  position,
 
324
                                     GdkRectangle   *area)
338
325
{
339
 
  AWN_BACKGROUND_CLASS (awn_background_lucido_parent_class)->get_shape_mask (
340
 
      bg, cr, position, area);
 
326
  AWN_BACKGROUND_CLASS(awn_background_lucido_parent_class)->get_shape_mask(
 
327
    bg, cr, position, area);
341
328
}
342
329
 
343
330
/* vim: set et ts=2 sts=2 sw=2 : */