~unico-team/unico/trunk

« back to all changes in this revision

Viewing changes to unico/unico-draw.c

  • Committer: Ken VanDine
  • Date: 2012-08-08 16:28:32 UTC
  • mfrom: (139 refactor)
  • mto: (139.1.1 unico)
  • mto: This revision was merged to the branch mainline in revision 140.
  • Revision ID: ken.vandine@canonical.com-20120808162832-vmgto6docfq65f4d
New snapshot from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "unico-draw.h"
29
29
#include "unico-support.h"
30
30
#include "unico-types.h"
31
 
#include "gtkroundedboxprivate.h"
32
31
 
33
 
/* draw a texture placed on the centroid */
34
32
static gboolean
35
 
draw_centroid_texture (GtkThemingEngine *engine,
36
 
                       cairo_t          *cr,
37
 
                       gdouble           x,
38
 
                       gdouble           y,
39
 
                       gdouble           width,
40
 
                       gdouble           height)
 
33
draw_arrow_texture (GtkThemingEngine *engine,
 
34
                    cairo_t          *cr,
 
35
                    gdouble           angle,
 
36
                    gdouble           x,
 
37
                    gdouble           y,
 
38
                    gdouble           size)
41
39
{
42
40
  GtkStateFlags state;
43
41
  GValue value = { 0, };
47
45
 
48
46
  state = gtk_theming_engine_get_state (engine);
49
47
 
50
 
  gtk_theming_engine_get_property (engine, "-unico-centroid-texture", state, &value);
 
48
  gtk_theming_engine_get_property (engine, "-unico-arrow-texture", state, &value);
51
49
 
52
50
  if (!G_VALUE_HOLDS_BOXED (&value))
53
51
    return FALSE;
62
60
    {
63
61
      cairo_save (cr);
64
62
 
65
 
      cairo_set_source_surface (cr, surface, (gint) (x + width / 2 - cairo_image_surface_get_width (surface) / 2),
66
 
                                             (gint) (y + height / 2 - cairo_image_surface_get_height (surface) / 2));
 
63
      cairo_translate (cr, (gint) (x + size / 2), (gint) (y + size / 2));
 
64
      cairo_rotate (cr, angle);
 
65
 
 
66
      cairo_set_source_surface (cr, surface, - cairo_image_surface_get_width (surface) / 2,
 
67
                                             - cairo_image_surface_get_height (surface) / 2);
67
68
      cairo_paint (cr);
68
69
 
69
70
      cairo_restore (cr);
78
79
}
79
80
 
80
81
static void
81
 
unico_draw_activity (DRAW_ARGS)
82
 
{
83
 
  /* playground for effects */
84
 
  unico_cairo_draw_background (engine, cr,
85
 
                               x, y, width, height,
86
 
                               0, gtk_theming_engine_get_junction_sides (engine));
87
 
  unico_cairo_draw_frame (engine, cr,
88
 
                          x, y, width, height,
89
 
                          0, gtk_theming_engine_get_junction_sides (engine));
90
 
}
91
 
 
92
 
static void
93
82
unico_draw_arrow (GtkThemingEngine *engine,
94
83
                  cairo_t          *cr,
95
84
                  gdouble           angle,
101
90
  GdkRGBA color;
102
91
  gdouble size_reduction = 4;
103
92
 
 
93
  if (draw_arrow_texture (engine, cr, angle, x, y, size))
 
94
    return;
 
95
 
104
96
  state = gtk_theming_engine_get_state (engine);
105
97
 
106
98
  gtk_theming_engine_get_color (engine, state, &color);
134
126
}
135
127
 
136
128
static void
137
 
unico_draw_cell_background (DRAW_ARGS,
138
 
                            GtkRegionFlags flags)
139
 
{
140
 
  GtkJunctionSides junction;
141
 
  guint hidden_side;
142
 
 
143
 
  junction = GTK_JUNCTION_RIGHT | GTK_JUNCTION_LEFT;
144
 
 
145
 
  hidden_side = SIDE_RIGHT | SIDE_LEFT;
146
 
 
147
 
  if ((flags & GTK_REGION_FIRST) != 0)
148
 
    {
149
 
      junction &= ~(GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMLEFT);
150
 
      hidden_side &= ~(SIDE_LEFT);
151
 
    }
152
 
  if ((flags & GTK_REGION_LAST) != 0)
153
 
    {
154
 
      junction &= ~(GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMRIGHT);
155
 
      hidden_side &= ~(SIDE_RIGHT);
156
 
    }
157
 
 
158
 
  unico_cairo_draw_background (engine, cr,
159
 
                               x, y, width, height,
160
 
                               hidden_side, junction);
161
 
}
162
 
 
163
 
static void
164
 
unico_draw_cell_frame (DRAW_ARGS,
165
 
                       GtkRegionFlags flags)
166
 
{
167
 
  GtkJunctionSides junction;
168
 
  guint hidden_side;
169
 
 
170
 
  junction = GTK_JUNCTION_RIGHT | GTK_JUNCTION_LEFT;
171
 
 
172
 
  hidden_side = SIDE_RIGHT | SIDE_LEFT;
173
 
 
174
 
  if ((flags & GTK_REGION_FIRST) != 0)
175
 
    {
176
 
      junction &= ~(GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMLEFT);
177
 
      hidden_side &= ~(SIDE_LEFT);
178
 
    }
179
 
  if ((flags & GTK_REGION_LAST) != 0)
180
 
    {
181
 
      junction &= ~(GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMRIGHT);
182
 
      hidden_side &= ~(SIDE_RIGHT);
183
 
    }
184
 
 
185
 
  unico_cairo_draw_frame (engine, cr,
186
 
                          x, y, width, height,
187
 
                          hidden_side, junction);
188
 
}
189
 
 
190
 
static void
191
 
unico_draw_check (DRAW_ARGS)
192
 
{
193
 
  GtkStateFlags state;
194
 
  gboolean in_menu;
195
 
  gboolean draw_bullet, inconsistent;
196
 
 
197
 
  state = gtk_theming_engine_get_state (engine);
198
 
 
199
 
  in_menu = gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_MENUITEM);
200
 
  inconsistent = (state & GTK_STATE_FLAG_INCONSISTENT) != 0;
201
 
  draw_bullet = (state & GTK_STATE_FLAG_ACTIVE) != 0;
202
 
  draw_bullet |= inconsistent;
203
 
 
204
 
  if (!in_menu)
205
 
    {
206
 
      unico_cairo_draw_background (engine, cr,
207
 
                                   x, y, width, height,
208
 
                                   0, gtk_theming_engine_get_junction_sides (engine));
209
 
      unico_cairo_draw_frame (engine, cr,
210
 
                              x, y, width, height,
211
 
                              0, gtk_theming_engine_get_junction_sides (engine));
212
 
    }
213
 
 
214
 
  if (draw_bullet)
215
 
    {
216
 
      GdkRGBA *bullet_color;
217
 
 
218
 
      gtk_theming_engine_get (engine, state,
219
 
                              "-unico-bullet-color", &bullet_color,
220
 
                              NULL);
221
 
 
222
 
      cairo_translate (cr, x, y);
223
 
      cairo_scale (cr, width / 18.0, height / 18.0);
224
 
 
225
 
      if (inconsistent)
226
 
        {
227
 
          GdkRGBA *bullet_outline_color;
228
 
 
229
 
          gtk_theming_engine_get (engine, state,
230
 
                                  "-unico-bullet-outline-color", &bullet_outline_color,
231
 
                                  NULL);
232
 
 
233
 
          /* thick's outline */
234
 
          cairo_rectangle (cr, 3.5, 7, 11, 4);
235
 
 
236
 
          gdk_cairo_set_source_rgba (cr, bullet_outline_color);
237
 
          cairo_fill (cr);
238
 
 
239
 
          cairo_rectangle (cr, 4.5, 8, 9, 2);
240
 
 
241
 
          gdk_rgba_free (bullet_outline_color);
242
 
        }
243
 
      else
244
 
        {
245
 
          if (in_menu)
246
 
            cairo_translate (cr, 2.0, 3.0);
247
 
          else
248
 
            {
249
 
              GdkRGBA *bullet_outline_color;
250
 
 
251
 
              gtk_theming_engine_get (engine, state,
252
 
                                      "-unico-bullet-outline-color", &bullet_outline_color,
253
 
                                      NULL);
254
 
 
255
 
              /* thick's outline */
256
 
              cairo_move_to (cr, 5.0, 5.65);
257
 
              cairo_line_to (cr, 8.95, 9.57);
258
 
              cairo_line_to (cr, 16.0, 2.54);
259
 
              cairo_line_to (cr, 16.0, 8.36);
260
 
              cairo_line_to (cr, 10.6, 15.1);
261
 
              cairo_line_to (cr, 7.6, 15.1);
262
 
              cairo_line_to (cr, 2.95, 10.48);
263
 
              cairo_line_to (cr, 2.95, 7.65);
264
 
              cairo_close_path (cr);
265
 
 
266
 
              gdk_cairo_set_source_rgba (cr, bullet_outline_color);
267
 
              cairo_fill (cr);
268
 
 
269
 
              cairo_translate (cr, 4.0, 2.0);
270
 
 
271
 
              gdk_rgba_free (bullet_outline_color);
272
 
            }
273
 
 
274
 
          /* thick */
275
 
          cairo_move_to (cr, 0.0, 6.0);
276
 
          cairo_line_to (cr, 0.0, 8.0);
277
 
          cairo_line_to (cr, 4.0, 12.0);
278
 
          cairo_line_to (cr, 6.0, 12.0);
279
 
          cairo_line_to (cr, 15.0, 1.0);
280
 
          cairo_line_to (cr, 15.0, 0.0);
281
 
          cairo_line_to (cr, 14.0, 0.0);
282
 
          cairo_line_to (cr, 5.0, 9.0);
283
 
          cairo_line_to (cr, 1.0, 5.0);
284
 
          cairo_close_path (cr);
285
 
        }
286
 
 
287
 
      gdk_cairo_set_source_rgba (cr, bullet_color);
288
 
      cairo_fill (cr);
289
 
 
290
 
      gdk_rgba_free (bullet_color);
291
 
    }
292
 
}
293
 
 
294
 
static void
295
 
unico_draw_common (DRAW_ARGS)
296
 
{
297
 
  unico_cairo_draw_background (engine, cr,
298
 
                               x, y, width, height,
299
 
                               0, gtk_theming_engine_get_junction_sides (engine));
300
 
  unico_cairo_draw_frame (engine, cr,
301
 
                          x, y, width, height,
302
 
                          0, gtk_theming_engine_get_junction_sides (engine));
303
 
}
304
 
 
305
 
static void
306
 
unico_draw_common_background (DRAW_ARGS)
307
 
{
308
 
  unico_cairo_draw_background (engine, cr,
309
 
                               x, y, width, height,
310
 
                               0, gtk_theming_engine_get_junction_sides (engine));
311
 
}
312
 
 
313
 
static void
314
 
unico_draw_common_frame (DRAW_ARGS)
315
 
{
316
 
  unico_cairo_draw_frame (engine, cr,
317
 
                          x, y, width, height,
318
 
                          0, gtk_theming_engine_get_junction_sides (engine));
319
 
}
320
 
 
321
 
static void
322
129
unico_draw_expander (DRAW_ARGS)
323
130
{
324
131
  GtkStateFlags state;
359
166
}
360
167
 
361
168
static void
362
 
unico_draw_extension (DRAW_ARGS,
363
 
                      GtkPositionType gap_side)
364
 
{
365
 
  GtkBorder border;
366
 
  GtkBorder *outer_border;
367
 
  GtkJunctionSides junction = 0;
368
 
  GtkStateFlags state;
369
 
  gboolean has_outer_stroke = FALSE;
370
 
  gdouble bg_offset = 0;
371
 
  guint hidden_side = 0;
372
 
 
373
 
  state = gtk_theming_engine_get_state (engine); 
374
 
 
375
 
  gtk_theming_engine_get (engine, state,
376
 
                          "-unico-outer-stroke-width", &outer_border,
377
 
                          NULL);
378
 
  gtk_theming_engine_get_border (engine, state, &border);
379
 
 
380
 
  if (!unico_gtk_border_is_zero (outer_border))
381
 
    has_outer_stroke = TRUE;
382
 
 
383
 
  cairo_save (cr);
384
 
 
385
 
  /* FIXME doesn't work properly with not homogenuos border-width,
386
 
   * especially between tab and notebook.
387
 
   * I guess the issue comes from the fact draw_background
388
 
   * is looking at border dimensions while we're not,
389
 
   * or we're doing it wrong.
390
 
   * draw_background is looking at SIDE_BOTTOM and
391
 
   * sets border to 0 for this side */
392
 
  switch (gap_side)
393
 
  {
394
 
    case GTK_POS_TOP:
395
 
      junction = GTK_JUNCTION_TOP;
396
 
      hidden_side = SIDE_TOP;
397
 
 
398
 
      if (has_outer_stroke)
399
 
        {
400
 
          y -= outer_border->bottom;
401
 
          height += outer_border->bottom;
402
 
        }
403
 
 
404
 
      if ((state & GTK_STATE_FLAG_ACTIVE) != 0)
405
 
        bg_offset = border.bottom;
406
 
 
407
 
      cairo_translate (cr, x + width, y + height);
408
 
      cairo_rotate (cr, G_PI);
409
 
      break;
410
 
    default:
411
 
    case GTK_POS_BOTTOM:
412
 
      junction = GTK_JUNCTION_BOTTOM;
413
 
      hidden_side = SIDE_BOTTOM;
414
 
 
415
 
      if (has_outer_stroke)
416
 
        height += outer_border->top;
417
 
 
418
 
      if ((state & GTK_STATE_FLAG_ACTIVE) != 0)
419
 
        bg_offset = border.top;
420
 
 
421
 
      cairo_translate (cr, x, y);
422
 
      break;
423
 
    case GTK_POS_LEFT:
424
 
      junction = GTK_JUNCTION_LEFT;
425
 
      hidden_side = SIDE_LEFT;
426
 
 
427
 
      if (has_outer_stroke)
428
 
        {
429
 
          x -= outer_border->right;
430
 
          width += outer_border->right;
431
 
        }
432
 
 
433
 
      if ((state & GTK_STATE_FLAG_ACTIVE) != 0)
434
 
        bg_offset = border.right;
435
 
 
436
 
      cairo_translate (cr, x + width, y);
437
 
      cairo_rotate (cr, G_PI / 2);
438
 
      break;
439
 
    case GTK_POS_RIGHT:
440
 
      junction = GTK_JUNCTION_RIGHT;
441
 
      hidden_side = SIDE_RIGHT;
442
 
 
443
 
      if (has_outer_stroke)
444
 
        width += outer_border->left;
445
 
 
446
 
      if ((state & GTK_STATE_FLAG_ACTIVE) != 0)
447
 
        bg_offset = border.left;
448
 
 
449
 
      cairo_translate (cr, x, y + height);
450
 
      cairo_rotate (cr, - G_PI / 2);
451
 
      break;
452
 
  }
453
 
 
454
 
  if (gap_side == GTK_POS_TOP ||
455
 
      gap_side == GTK_POS_BOTTOM)
456
 
    unico_cairo_draw_background (engine, cr, 0, 0, width, height + bg_offset, SIDE_BOTTOM, GTK_JUNCTION_BOTTOM);
457
 
  else
458
 
    unico_cairo_draw_background (engine, cr, 0, 0, height, width + bg_offset, SIDE_BOTTOM, GTK_JUNCTION_BOTTOM);
459
 
  cairo_restore (cr);
460
 
 
461
 
  /* FIXME the frame on bottom bar has the wrong gradient,
462
 
   * while should be reflected */
463
 
  unico_cairo_draw_frame (engine, cr, x, y, width, height, hidden_side, junction);
464
 
 
465
 
  gtk_border_free (outer_border);
466
 
}
467
 
 
468
 
static void
469
169
unico_draw_focus (DRAW_ARGS)
470
170
{
471
 
  GdkRGBA *fill_color, *border_color, *outer_stroke_color;
 
171
  GdkRGBA *fill_color, *border_color;
472
172
  GtkStateFlags state;
473
173
  gint focus_pad, line_width;
474
174
  gint radius;
475
175
 
476
176
  state = gtk_theming_engine_get_state (engine);
477
177
 
 
178
  gtk_theming_engine_get_style (engine,
 
179
                                "focus-padding", &focus_pad,
 
180
                                "focus-line-width", &line_width,
 
181
                                NULL);
 
182
 
 
183
  /* Skip rendering if focus-line-width is 0 or less. */
 
184
  if (line_width < 1)
 
185
    return;
 
186
 
478
187
  gtk_theming_engine_get (engine, state,
479
188
                          "-unico-focus-border-color", &border_color,
480
189
                          "-unico-focus-border-radius", &radius,
481
190
                          "-unico-focus-fill-color", &fill_color,
482
 
                          "-unico-focus-outer-stroke-color", &outer_stroke_color,
483
191
                          NULL);
484
 
  gtk_theming_engine_get_style (engine,
485
 
                                "focus-padding", &focus_pad,
486
 
                                "focus-line-width", &line_width,
487
 
                                NULL);  
488
192
 
489
193
  x += focus_pad;
490
194
  y += focus_pad;
502
206
  gdk_cairo_set_source_rgba (cr, fill_color);
503
207
  cairo_fill (cr);
504
208
 
505
 
  /* second layer, outer stroke */
506
 
  unico_cairo_round_rect_inner (cr, x - line_width, y - line_width,
507
 
                                    width + line_width * 2, height + line_width * 2,
508
 
                                    radius + 1, SIDE_ALL, GTK_JUNCTION_NONE);
509
 
  gdk_cairo_set_source_rgba (cr, outer_stroke_color);
510
 
  cairo_stroke (cr);
511
 
 
512
 
  /* third layer, border */
 
209
  /* second layer, border */
513
210
  unico_cairo_round_rect_inner (cr, x, y,
514
211
                                    width, height,
515
212
                                    radius, SIDE_ALL, GTK_JUNCTION_NONE);
520
217
 
521
218
  gdk_rgba_free (border_color);
522
219
  gdk_rgba_free (fill_color);
523
 
  gdk_rgba_free (outer_stroke_color);
524
 
}
525
 
 
526
 
static void
527
 
unico_draw_frame_gap (DRAW_ARGS,
528
 
                      GtkPositionType gap_side,
529
 
                      gdouble         xy0_gap,
530
 
                      gdouble         xy1_gap)
531
 
{
532
 
  GtkBorder border;
533
 
  GtkBorder *outer_border;
534
 
  /*GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
535
 
  GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;*/
536
 
  GtkJunctionSides junction;
537
 
  GtkStateFlags state;
538
 
  gboolean has_outer_stroke = FALSE;
539
 
  gdouble x0, y0, x1, y1, xc, yc, wc, hc;
540
 
 
541
 
  xc = yc = wc = hc = 0;
542
 
 
543
 
  junction = gtk_theming_engine_get_junction_sides (engine);
544
 
 
545
 
  state = gtk_theming_engine_get_state (engine);
546
 
 
547
 
  /* NOTE: Border radius is disabled due to it not working in GTK+ 3.5 */
548
 
  gtk_theming_engine_get (engine, state,
549
 
                          /* Can't use border-radius as it's an int for
550
 
                           * backwards compat */
551
 
                          /*"border-top-left-radius", &top_left_radius,
552
 
                          "border-top-right-radius", &top_right_radius,
553
 
                          "border-bottom-right-radius", &bottom_right_radius,
554
 
                          "border-bottom-left-radius", &bottom_left_radius,*/
555
 
                          "-unico-outer-stroke-width", &outer_border,
556
 
                          NULL);
557
 
  gtk_theming_engine_get_border (engine, state, &border);
558
 
 
559
 
  if (!unico_gtk_border_is_zero (outer_border))
560
 
    has_outer_stroke = TRUE;
561
 
 
562
 
  cairo_save (cr);
563
 
 
564
 
  switch (gap_side)
565
 
  {
566
 
    case GTK_POS_TOP:
567
 
      xc = x + xy0_gap + border.left;
568
 
      yc = y;
569
 
      wc = MAX (xy1_gap - xy0_gap - (border.left + border.right), 0);
570
 
      hc = border.top * 2;
571
 
 
572
 
      if (has_outer_stroke)
573
 
        {
574
 
          xc += outer_border->left;
575
 
          wc = MAX (xy1_gap - xy0_gap - (outer_border->left + outer_border->right) - (border.left + border.right), 0);
576
 
          hc += outer_border->top;
577
 
        }
578
 
 
579
 
      /*if (xy0_gap < _gtk_css_number_get (&top_left_radius->horizontal, width))
580
 
        junction |= GTK_JUNCTION_CORNER_TOPLEFT;
581
 
 
582
 
      if (xy1_gap > width - _gtk_css_number_get (&top_right_radius->horizontal, width))
583
 
        junction |= GTK_JUNCTION_CORNER_TOPRIGHT;*/
584
 
 
585
 
      break;
586
 
    default:
587
 
    case GTK_POS_BOTTOM:
588
 
      xc = x + xy0_gap + border.left;
589
 
      yc = y + height - border.bottom * 2;
590
 
      wc = MAX (xy1_gap - xy0_gap - (border.left + border.right), 0);
591
 
      hc = border.bottom * 2;
592
 
 
593
 
      if (has_outer_stroke)
594
 
        {
595
 
          xc += outer_border->left;
596
 
          yc -= outer_border->bottom;
597
 
          wc = MAX (xy1_gap - xy0_gap - (outer_border->left + outer_border->right) - (border.left + border.right), 0);
598
 
          hc += outer_border->bottom;
599
 
        }
600
 
 
601
 
      /*if (xy0_gap < _gtk_css_number_get (&bottom_left_radius->horizontal, width))
602
 
        junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
603
 
 
604
 
      if (xy1_gap > width - _gtk_css_number_get (&bottom_right_radius->horizontal, width))
605
 
        junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;*/
606
 
 
607
 
      break;
608
 
    case GTK_POS_LEFT:
609
 
      xc = x;
610
 
      yc = y + xy0_gap + border.top;
611
 
      wc = border.left * 2;
612
 
      hc = MAX (xy1_gap - xy0_gap - (border.top + border.bottom), 0);
613
 
 
614
 
      if (has_outer_stroke)
615
 
        {
616
 
          yc += outer_border->top;
617
 
          wc += outer_border->left;
618
 
          hc = MAX (xy1_gap - xy0_gap - (outer_border->top + outer_border->bottom) - (border.top + border.bottom), 0);
619
 
        }
620
 
 
621
 
      /*if (xy0_gap < _gtk_css_number_get (&top_left_radius->vertical, height))
622
 
        junction |= GTK_JUNCTION_CORNER_TOPLEFT;
623
 
 
624
 
      if (xy1_gap > height - _gtk_css_number_get (&bottom_left_radius->vertical, height))
625
 
        junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;*/
626
 
 
627
 
      break;
628
 
    case GTK_POS_RIGHT:
629
 
      xc = x + width - border.right * 2;
630
 
      yc = y + xy0_gap + border.top;
631
 
      wc = border.right * 2;
632
 
      hc = MAX (xy1_gap - xy0_gap - (border.top + border.bottom), 0);
633
 
 
634
 
      if (has_outer_stroke)
635
 
        {
636
 
          xc -= outer_border->right;
637
 
          yc += outer_border->top;
638
 
          wc += outer_border->right;
639
 
          hc = MAX (xy1_gap - xy0_gap - (outer_border->top + outer_border->bottom) - (border.top + border.bottom), 0);
640
 
        }
641
 
 
642
 
      /*if (xy0_gap < _gtk_css_number_get (&top_right_radius->vertical, height))
643
 
        junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
644
 
 
645
 
      if (xy1_gap > height - _gtk_css_number_get (&bottom_right_radius->vertical, height))
646
 
        junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;*/
647
 
 
648
 
      break;
649
 
  }
650
 
 
651
 
  /* clip the gap */
652
 
  cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
653
 
  cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
654
 
  cairo_rectangle (cr, x0, yc, xc - x0, hc);
655
 
  cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
656
 
  cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
657
 
  cairo_clip (cr);
658
 
 
659
 
  /* draw the frame, gap area will not be drawn */
660
 
  unico_cairo_draw_frame (engine, cr, x, y, width, height, 0, junction);
661
 
 
662
 
  cairo_restore (cr);
663
 
 
664
 
  /*g_free (top_left_radius);
665
 
  g_free (top_right_radius);
666
 
  g_free (bottom_right_radius);
667
 
  g_free (bottom_left_radius);*/
668
 
  gtk_border_free (outer_border);
669
 
}
670
 
 
671
 
static void
672
 
unico_draw_grip (DRAW_ARGS)
673
 
{
674
 
  GdkRGBA border_color;
675
 
  GdkRGBA *inner_stroke_color;
676
 
  GtkStateFlags state;
677
 
  gint lx, ly;
678
 
 
679
 
  if (draw_centroid_texture (engine, cr, x, y, width, height))
680
 
    return;
681
 
 
682
 
  state = gtk_theming_engine_get_state (engine);
683
 
 
684
 
  gtk_theming_engine_get (engine, state,
685
 
                          "-unico-inner-stroke-color", &inner_stroke_color,
686
 
                          NULL);
687
 
  gtk_theming_engine_get_border_color (engine, state, &border_color);
688
 
 
689
 
  for (ly = 0; ly < 4; ly++)
690
 
    {
691
 
      /* vertically, four rows of dots */
692
 
      for (lx = 0; lx <= ly; lx++)
693
 
        {
694
 
          /* horizontally */
695
 
          int ny = (3.5 - ly) * 3;
696
 
          int nx = lx * 3;
697
 
 
698
 
          gdk_cairo_set_source_rgba (cr, inner_stroke_color);
699
 
          cairo_rectangle (cr, x + width - nx - 1, y + height - ny - 1, 2, 2);
700
 
          cairo_fill (cr);
701
 
 
702
 
          gdk_cairo_set_source_rgba (cr, &border_color);
703
 
          cairo_rectangle (cr, x + width - nx - 1, y + height - ny - 1, 1, 1);
704
 
          cairo_fill (cr);
705
 
        }
706
 
    }
707
 
 
708
 
  gdk_rgba_free (inner_stroke_color);
709
 
}
710
 
 
711
 
static void
712
 
unico_draw_handle (DRAW_ARGS)
713
 
{
714
 
  GtkBorder border;
715
 
  GtkStateFlags state;
716
 
  gdouble line_width;
717
 
  gint i, bar_y, num_bars, bar_spacing, bar_width, bar_height;
718
 
 
719
 
  state = gtk_theming_engine_get_state (engine);
720
 
  gtk_theming_engine_get_border (engine, state, &border);
721
 
 
722
 
  unico_cairo_draw_background (engine, cr,
723
 
                               x - border.left, y - border.top,
724
 
                               width + border.left + border.right, height + border.top + border.bottom,
725
 
                               0, GTK_JUNCTION_NONE);
726
 
 
727
 
  if (draw_centroid_texture (engine, cr, x, y, width, height))
728
 
    return;
729
 
 
730
 
  unico_get_line_width (engine, &line_width);
731
 
 
732
 
  if (line_width < 1)
733
 
    return;
734
 
 
735
 
  bar_y = 1;
736
 
  num_bars = 3;
737
 
  bar_spacing = 3;
738
 
  bar_width = 3;
739
 
  bar_height = num_bars * bar_spacing * line_width;
740
 
 
741
 
  cairo_save (cr);
742
 
 
743
 
  cairo_translate (cr, x + (gint) (width / 2), y + (gint) (height / 2));
744
 
 
745
 
  if (height > width)
746
 
    cairo_translate (cr, - bar_width / 2 - 0.5, - bar_height / 2 + 0.5);
747
 
  else
748
 
    {
749
 
      cairo_translate (cr, - bar_height / 2 + 0.5, bar_width / 2 + 0.5);
750
 
      cairo_rotate (cr, - G_PI / 2);
751
 
    }
752
 
 
753
 
  for (i = 0; i < num_bars; i++)
754
 
    {
755
 
      /* draw bars */
756
 
      cairo_move_to (cr, 0, bar_y);
757
 
      cairo_line_to (cr, bar_width, bar_y);
758
 
      unico_cairo_set_source_border (engine, cr, bar_width, line_width);
759
 
      cairo_stroke (cr);
760
 
 
761
 
      cairo_move_to (cr, 0, bar_y + line_width);
762
 
      cairo_line_to (cr, bar_width, bar_y + line_width);
763
 
      unico_cairo_set_source_inner_stroke (engine, cr, bar_width, line_width);
764
 
      cairo_stroke (cr);
765
 
 
766
 
      bar_y += bar_spacing;
767
 
    }
768
 
 
769
 
  cairo_restore (cr);
770
 
}
771
 
 
772
 
static void
773
 
unico_draw_line (GtkThemingEngine *engine,
774
 
                 cairo_t          *cr,
775
 
                 gdouble           x0,
776
 
                 gdouble           y0,
777
 
                 gdouble           x1,
778
 
                 gdouble           y1)
779
 
{
780
 
  /* line endings */
781
 
  if (y0 == y1)
782
 
    {
783
 
      y0 += 0.5;
784
 
      y1 += 0.5;
785
 
      x0 += 0.5;
786
 
      x1 -= 0.5;
787
 
    }
788
 
  else if (x0 == x1)
789
 
    {
790
 
      x0 += 0.5;
791
 
      x1 += 0.5;
792
 
      y0 += 0.5;
793
 
      y1 -= 0.5;
794
 
    }
795
 
 
796
 
  cairo_move_to (cr, x0, y0);
797
 
  cairo_line_to (cr, x1, y1);
798
 
  unico_cairo_set_source_border (engine, cr, MAX (x1 - x0, 1), MAX (y1 - y0, 1));
799
 
  cairo_stroke (cr);
800
 
}
801
 
 
802
 
static void
803
 
unico_draw_notebook (DRAW_ARGS,
804
 
                     GtkPositionType gap_side,
805
 
                     gdouble         xy0_gap,
806
 
                     gdouble         xy1_gap)
807
 
{
808
 
  unico_cairo_draw_background (engine, cr,
809
 
                               x, y, width, height,
810
 
                               0, gtk_theming_engine_get_junction_sides (engine));
811
 
  unico_draw_frame_gap (engine, cr,
812
 
                        x, y, width, height,
813
 
                        gap_side, xy0_gap, xy1_gap);
814
 
}
815
 
 
816
 
static void
817
 
unico_draw_radio (DRAW_ARGS)
818
 
{
819
 
  GtkStateFlags state;
820
 
  gboolean in_menu;
821
 
  gboolean draw_bullet, inconsistent;
822
 
 
823
 
  state = gtk_theming_engine_get_state (engine);
824
 
 
825
 
  in_menu = gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_MENUITEM);
826
 
  inconsistent = (state & GTK_STATE_FLAG_INCONSISTENT) != 0;
827
 
  draw_bullet = (state & GTK_STATE_FLAG_ACTIVE) != 0;
828
 
  draw_bullet |= inconsistent;
829
 
 
830
 
  if (!in_menu)
831
 
    {
832
 
      unico_cairo_draw_background (engine, cr,
833
 
                                   x, y, width, height,
834
 
                                   0, gtk_theming_engine_get_junction_sides (engine));
835
 
      unico_cairo_draw_frame (engine, cr,
836
 
                              x, y, width, height,
837
 
                              0, gtk_theming_engine_get_junction_sides (engine));
838
 
    }
839
 
 
840
 
  if (draw_bullet)
841
 
    {
842
 
      GdkRGBA *bullet_color;
843
 
 
844
 
      gtk_theming_engine_get (engine, state,
845
 
                              "-unico-bullet-color", &bullet_color,
846
 
                              NULL);
847
 
 
848
 
      if (inconsistent)
849
 
        {
850
 
          GdkRGBA *bullet_outline_color;
851
 
 
852
 
          gtk_theming_engine_get (engine, state,
853
 
                                  "-unico-bullet-outline-color", &bullet_outline_color,
854
 
                                  NULL);
855
 
 
856
 
          /* bullet's outline */
857
 
          cairo_rectangle (cr, x + width / 2.0 - (width + height) / 4.0 + 3, y + height / 2.0 - 2,
858
 
                               (width + height) / 4.0 + 2, 4);
859
 
 
860
 
          gdk_cairo_set_source_rgba (cr, bullet_outline_color);
861
 
          cairo_fill (cr);
862
 
 
863
 
          cairo_rectangle (cr, x + width / 2.0 - (width + height) / 4.0 + 4, y + height / 2.0 - 1,
864
 
                               (width + height) / 4.0, 2);
865
 
 
866
 
          gdk_rgba_free (bullet_outline_color);
867
 
        }
868
 
      else
869
 
        {
870
 
          if (in_menu)
871
 
            cairo_arc (cr, x + width / 2.0, y + height / 2.0,
872
 
                           (width + height) / 4.0 - 4, 0, G_PI * 2);
873
 
          else
874
 
            {
875
 
              GdkRGBA *bullet_outline_color;
876
 
 
877
 
              gtk_theming_engine_get (engine, state,
878
 
                                      "-unico-bullet-outline-color", &bullet_outline_color,
879
 
                                      NULL);
880
 
 
881
 
              /* bullet's outline */
882
 
              cairo_arc (cr, x + width / 2.0, y + height / 2.0,
883
 
                             (width + height) / 4.0 - 4, 0, G_PI * 2);
884
 
              gdk_cairo_set_source_rgba (cr, bullet_outline_color);
885
 
              cairo_fill (cr);
886
 
 
887
 
              cairo_arc (cr, x + width / 2.0, y + height / 2.0,
888
 
                             (width + height) / 4.0 - 5, 0, G_PI * 2);
889
 
 
890
 
              gdk_rgba_free (bullet_outline_color);
891
 
            }
892
 
        }
893
 
 
894
 
      /* bullet */
895
 
      gdk_cairo_set_source_rgba (cr, bullet_color);
896
 
      cairo_fill (cr);
897
 
 
898
 
      gdk_rgba_free (bullet_color);
899
 
    }
900
 
}
901
 
 
902
 
static void
903
 
unico_draw_separator (DRAW_ARGS)
904
 
{
905
 
  gdouble line_width;
906
 
 
907
 
  unico_get_line_width (engine, &line_width);
908
 
 
909
 
  if (line_width == 0)
910
 
    return;
911
 
 
912
 
  /* FIXME right code should be
913
 
   * if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_VERTICAL))
914
 
   * but doesn't work for separator tool item. */
915
 
  if (width > height)
916
 
    {
917
 
      cairo_move_to (cr, x, y + (gint) (height / 2) + line_width / 2);
918
 
      cairo_line_to (cr, x + width, y + (gint) (height / 2) + line_width / 2);
919
 
      unico_cairo_set_source_inner_stroke (engine, cr, width, line_width);
920
 
      cairo_stroke (cr);
921
 
 
922
 
      cairo_move_to (cr, x, y + (gint) (height / 2) - line_width / 2);
923
 
      cairo_line_to (cr, x + width, y + (gint) (height / 2) - line_width / 2);
924
 
      unico_cairo_set_source_border (engine, cr, width, line_width);
925
 
      cairo_stroke (cr);
926
 
    }
927
 
  else
928
 
    {
929
 
      cairo_move_to (cr, x + (gint) (width / 2) + line_width / 2, y);
930
 
      cairo_line_to (cr, x + (gint) (width / 2) + line_width / 2, y + height);
931
 
      unico_cairo_set_source_inner_stroke (engine, cr, line_width, height);
932
 
      cairo_stroke (cr);
933
 
 
934
 
      cairo_move_to (cr, x + (gint) (width / 2) - line_width / 2, y);
935
 
      cairo_line_to (cr, x + (gint) (width / 2) - line_width / 2, y + height);
936
 
      unico_cairo_set_source_border (engine, cr, line_width, height);
937
 
      cairo_stroke (cr);
938
 
    }
939
 
}
940
 
 
941
 
static void
942
 
unico_draw_slider (DRAW_ARGS,
943
 
                   GtkOrientation orientation)
944
 
{
945
 
  /* use orientation, if needed */
946
 
  unico_cairo_draw_background (engine, cr,
947
 
                               x, y, width, height,
948
 
                               0, gtk_theming_engine_get_junction_sides (engine));
949
 
 
950
 
  draw_centroid_texture (engine, cr, x, y, width, height);
951
 
 
952
 
  unico_cairo_draw_frame (engine, cr,
953
 
                          x, y, width, height,
954
 
                          0, gtk_theming_engine_get_junction_sides (engine));
955
 
}
956
 
 
957
 
static void
958
 
unico_draw_spinbutton_background (DRAW_ARGS)
959
 
{
960
 
  GtkBorder border, *outer_border;
961
 
  GtkJunctionSides junction;
962
 
  GtkStateFlags state;
963
 
 
964
 
  junction = gtk_theming_engine_get_junction_sides (engine);
965
 
 
966
 
  state = gtk_theming_engine_get_state (engine);
967
 
 
968
 
  gtk_theming_engine_get (engine, state,
969
 
                          "-unico-outer-stroke-width", &outer_border,
970
 
                          NULL);
971
 
  gtk_theming_engine_get_border (engine, state, &border);
972
 
 
973
 
  cairo_save (cr);
974
 
 
975
 
  cairo_rectangle (cr, x, y, width, height);
976
 
  cairo_clip (cr);
977
 
 
978
 
  if (!(junction & GTK_JUNCTION_CORNER_TOPRIGHT))
979
 
    {
980
 
      y = ceil (y);
981
 
      height = floor (height);
982
 
      height += border.bottom + outer_border->bottom;
983
 
    }
984
 
  else
985
 
    {
986
 
      y = floor (y);
987
 
      height = ceil (height);
988
 
      y -= outer_border->top;
989
 
      height += outer_border->bottom;
990
 
    }
991
 
 
992
 
  unico_cairo_draw_background (engine, cr,
993
 
                               x, y, width, height,
994
 
                               0, junction);
995
 
 
996
 
  cairo_restore (cr);
997
 
 
998
 
  gtk_border_free (outer_border);
999
 
}
1000
 
 
1001
 
static void
1002
 
unico_draw_spinbutton_frame (DRAW_ARGS)
1003
 
{
1004
 
  GtkBorder border, *outer_border;
1005
 
  GtkJunctionSides junction;
1006
 
  GtkStateFlags state;
1007
 
 
1008
 
  junction = gtk_theming_engine_get_junction_sides (engine);
1009
 
 
1010
 
  state = gtk_theming_engine_get_state (engine);
1011
 
 
1012
 
  gtk_theming_engine_get (engine, state,
1013
 
                          "-unico-outer-stroke-width", &outer_border,
1014
 
                          NULL);
1015
 
  gtk_theming_engine_get_border (engine, state, &border);
1016
 
 
1017
 
  cairo_save (cr);
1018
 
 
1019
 
  cairo_rectangle (cr, x, y, width, height);
1020
 
  cairo_clip (cr);
1021
 
 
1022
 
  if (!(junction & GTK_JUNCTION_CORNER_TOPRIGHT))
1023
 
    {
1024
 
      y = ceil (y);
1025
 
      height = floor (height);
1026
 
      height += border.bottom + outer_border->bottom;
1027
 
    }
1028
 
  else
1029
 
    {
1030
 
      y = floor (y);
1031
 
      height = ceil (height);
1032
 
      y -= outer_border->top;
1033
 
      height += outer_border->bottom;
1034
 
    }
1035
 
 
1036
 
  unico_cairo_draw_frame (engine, cr,
1037
 
                          x, y, width, height,
1038
 
                          0, junction);
1039
 
 
1040
 
  cairo_restore (cr);
1041
 
 
1042
 
  gtk_border_free (outer_border);
1043
220
}
1044
221
 
1045
222
void
1047
224
{
1048
225
  g_assert (functions);
1049
226
 
1050
 
  functions->draw_activity                      = unico_draw_activity;
1051
 
  functions->draw_arrow                         = unico_draw_arrow;
1052
 
  functions->draw_cell_background               = unico_draw_cell_background;
1053
 
  functions->draw_cell_frame                    = unico_draw_cell_frame;
1054
 
  functions->draw_check                         = unico_draw_check;
1055
 
  functions->draw_common                        = unico_draw_common;
1056
 
  functions->draw_common_background             = unico_draw_common_background;
1057
 
  functions->draw_common_frame                  = unico_draw_common_frame;
1058
 
  functions->draw_expander                      = unico_draw_expander;
1059
 
  functions->draw_extension                     = unico_draw_extension;
1060
 
  functions->draw_focus                         = unico_draw_focus;
1061
 
  functions->draw_frame_gap                     = unico_draw_frame_gap;
1062
 
  functions->draw_grip                          = unico_draw_grip;
1063
 
  functions->draw_handle                        = unico_draw_handle;
1064
 
  functions->draw_line                          = unico_draw_line;
1065
 
  functions->draw_notebook                      = unico_draw_notebook;
1066
 
  functions->draw_radio                         = unico_draw_radio;
1067
 
  functions->draw_separator                     = unico_draw_separator;
1068
 
  functions->draw_slider                        = unico_draw_slider;
1069
 
  functions->draw_spinbutton_background         = unico_draw_spinbutton_background;
1070
 
  functions->draw_spinbutton_frame              = unico_draw_spinbutton_frame;
 
227
  functions->draw_arrow    = unico_draw_arrow;
 
228
  functions->draw_expander = unico_draw_expander;
 
229
  functions->draw_focus    = unico_draw_focus;
1071
230
}