~ubuntu-branches/ubuntu/precise/shotwell/precise-updates

« back to all changes in this revision

Viewing changes to src/CheckerboardLayout.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-02-21 13:52:58 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20120221135258-uffg1nm9ifpy2yoh
Tags: 0.11.92-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2009-2011 Yorba Foundation
 
1
/* Copyright 2009-2012 Yorba Foundation
2
2
 *
3
3
 * This software is licensed under the GNU LGPL (version 2.1 or later).
4
4
 * See the COPYING file in this distribution. 
460
460
        return null;
461
461
    }
462
462
    
463
 
    public void paint(Cairo.Context ctx, Gdk.Color bg_color, Gdk.Color selected_color,
464
 
        Gdk.Color text_color, Gdk.Color? border_color) {
 
463
    public void paint(Cairo.Context ctx, Gdk.RGBA bg_color, Gdk.RGBA selected_color,
 
464
        Gdk.RGBA text_color, Gdk.RGBA? border_color) {
465
465
        // calc the top-left point of the pixbuf
466
466
        Gdk.Point pixbuf_origin = Gdk.Point();
467
467
        pixbuf_origin.x = allocation.x + FRAME_WIDTH + BORDER_WIDTH;
468
468
        pixbuf_origin.y = allocation.y + FRAME_WIDTH + BORDER_WIDTH;
469
469
        
470
470
        ctx.set_line_width(FRAME_WIDTH);
471
 
        Gdk.cairo_set_source_color(ctx, selected_color);
 
471
        ctx.set_source_rgba(selected_color.red, selected_color.green, selected_color.blue,
 
472
            selected_color.alpha);
472
473
 
473
474
        // draw shadow
474
475
        if (border_color != null) {
492
493
        // draw border
493
494
        if (border_color != null) {
494
495
            ctx.save();
495
 
            Gdk.cairo_set_source_color(ctx, border_color);
 
496
            ctx.set_source_rgba(border_color.red, border_color.green, border_color.blue,
 
497
                border_color.alpha);
496
498
            paint_border(ctx, pixbuf_dim, pixbuf_origin, BORDER_WIDTH);
497
499
            ctx.restore();
498
500
        }
499
501
        
500
502
        if (display_pixbuf != null) {
501
503
            ctx.save();
502
 
            Gdk.cairo_set_source_color(ctx, bg_color);
 
504
            ctx.set_source_rgba(bg_color.red, bg_color.green, bg_color.blue, bg_color.alpha);
503
505
            paint_image(ctx, display_pixbuf, pixbuf_origin);
504
506
            ctx.restore();
505
507
        }
506
508
        
507
 
        Gdk.cairo_set_source_color(ctx, text_color);
 
509
        ctx.set_source_rgba(text_color.red, text_color.green, text_color.blue, text_color.alpha);
508
510
        
509
511
        // title and subtitles are LABEL_PADDING below bottom of pixbuf
510
512
        int text_y = allocation.y + FRAME_WIDTH + pixbuf_dim.height + FRAME_WIDTH + LABEL_PADDING;
511
513
        if (title != null && title_visible) {
512
514
            // get the layout sized so its with is no more than the pixbuf's
513
515
            // resize the text width to be no more than the pixbuf's
514
 
            title.allocation = { allocation.x + FRAME_WIDTH, text_y, pixbuf_dim.width,
515
 
                title.get_height() };
 
516
            title.allocation.x = allocation.x + FRAME_WIDTH;
 
517
            title.allocation.y = text_y;
 
518
            title.allocation.width = pixbuf_dim.width;
 
519
            title.allocation.height = title.get_height();
516
520
            
517
521
            ctx.move_to(title.allocation.x, title.allocation.y);
518
522
            Pango.cairo_show_layout(ctx, title.get_pango_layout(pixbuf_dim.width));
521
525
        }
522
526
        
523
527
        if (subtitle != null && subtitle_visible) {
524
 
            subtitle.allocation = { allocation.x + FRAME_WIDTH, text_y, pixbuf_dim.width,
525
 
                subtitle.get_height() };
 
528
            subtitle.allocation.x = allocation.x + FRAME_WIDTH;
 
529
            subtitle.allocation.y = text_y;
 
530
            subtitle.allocation.width = pixbuf_dim.width;
 
531
            subtitle.allocation.height = subtitle.get_height();
526
532
            
527
533
            ctx.move_to(subtitle.allocation.x, subtitle.allocation.y);
528
534
            Pango.cairo_show_layout(ctx, subtitle.get_pango_layout(pixbuf_dim.width));
530
536
            // increment text_y if more text lines follow
531
537
        }
532
538
        
533
 
        Gdk.cairo_set_source_color(ctx, selected_color);
 
539
        ctx.set_source_rgba(selected_color.red, selected_color.green, selected_color.blue,
 
540
            selected_color.alpha);
534
541
        
535
542
        // draw trinkets last
536
543
        Gdk.Pixbuf? trinket = get_bottom_left_trinket(TRINKET_SCALE);
690
697
    private Gtk.Adjustment hadjustment = null;
691
698
    private Gtk.Adjustment vadjustment = null;
692
699
    private string message = null;
693
 
    private Gdk.Color selected_color;
694
 
    private Gdk.Color unselected_color;
695
 
    private Gdk.Color border_color;
696
 
    private Gdk.Color bg_color;
 
700
    private Gdk.RGBA selected_color;
 
701
    private Gdk.RGBA unselected_color;
 
702
    private Gdk.RGBA border_color;
 
703
    private Gdk.RGBA bg_color;
697
704
    private Gdk.Rectangle visible_page = Gdk.Rectangle();
698
705
    private int last_width = 0;
699
706
    private int columns = 0;
726
733
        view.items_selected.connect(on_items_selection_changed);
727
734
        view.items_unselected.connect(on_items_selection_changed);
728
735
        
729
 
        modify_bg(Gtk.StateType.NORMAL, Config.Facade.get_instance().get_bg_color());
 
736
        override_background_color(Gtk.StateFlags.NORMAL, Config.Facade.get_instance().get_bg_color());
730
737
 
731
738
        Config.Facade.get_instance().colors_changed.connect(on_colors_changed);
732
739
 
1565
1572
            assert(ypadding >= 0);
1566
1573
            
1567
1574
            // save pixel and grid coordinates
1568
 
            item.allocation = { x + xpadding, y + ypadding, req.width, req.height };
 
1575
            item.allocation.x = x + xpadding;
 
1576
            item.allocation.y = y + ypadding;
 
1577
            item.allocation.width = req.width;
 
1578
            item.allocation.height = req.height;
1569
1579
            item.set_grid_coordinates(col, row);
1570
1580
            
1571
1581
            // add to current row in spatial data structure
1661
1671
 
1662
1672
    private void set_colors(bool in_focus = true) {
1663
1673
        // set up selected/unselected colors
1664
 
        selected_color = fetch_color(
1665
 
            Config.Facade.get_instance().get_selected_color(in_focus).to_string());
1666
 
        unselected_color = fetch_color(
1667
 
            Config.Facade.get_instance().get_unselected_color().to_string());
1668
 
        border_color = fetch_color(
1669
 
            Config.Facade.get_instance().get_border_color().to_string());
1670
 
        bg_color = this.get_style().bg[Gtk.StateType.NORMAL];
 
1674
        selected_color = Config.Facade.get_instance().get_selected_color(in_focus);
 
1675
        unselected_color =  Config.Facade.get_instance().get_unselected_color();
 
1676
        border_color =  Config.Facade.get_instance().get_border_color();
 
1677
        bg_color = get_style_context().get_background_color(Gtk.StateFlags.NORMAL);
1671
1678
    }
1672
1679
    
1673
1680
    public override void size_allocate(Gtk.Allocation allocation) {
1713
1720
            int y = allocation.height - text_height;
1714
1721
            y = (y > 0) ? y / 2 : 0;
1715
1722
            
1716
 
            Gdk.cairo_set_source_color(ctx, unselected_color);
 
1723
            ctx.set_source_rgb(unselected_color.red, unselected_color.green, unselected_color.blue);
1717
1724
            ctx.move_to(x, y);
1718
1725
            Pango.cairo_show_layout(ctx, pango_layout);
1719
1726
        }
1742
1749
        
1743
1750
        // pixelate selection rectangle interior
1744
1751
        if (visible_band.width > 1 && visible_band.height > 1) {
1745
 
            set_source_color_with_alpha(ctx, selected_color, SELECTION_ALPHA);
 
1752
            ctx.set_source_rgba(selected_color.red, selected_color.green, selected_color.blue,
 
1753
                SELECTION_ALPHA);
1746
1754
            ctx.rectangle(visible_band.x, visible_band.y, visible_band.width,
1747
1755
                visible_band.height);
1748
1756
            ctx.fill();
1753
1761
        // http://cairographics.org/FAQ/#sharp_lines
1754
1762
        ctx.set_line_width(1.0);
1755
1763
        ctx.set_line_cap(Cairo.LineCap.SQUARE);
1756
 
        Gdk.cairo_set_source_color(ctx, selected_color);
 
1764
        ctx.set_source_rgb(selected_color.red, selected_color.green, selected_color.blue);
1757
1765
        ctx.rectangle((double) selection_band.x + 0.5, (double) selection_band.y + 0.5,
1758
1766
            (double) selection_band.width - 1.0, (double) selection_band.height - 1.0);
1759
1767
        ctx.stroke();
1766
1774
    }
1767
1775
    
1768
1776
    private void on_colors_changed() {
1769
 
        modify_bg(Gtk.StateType.NORMAL, Config.Facade.get_instance().get_bg_color());
 
1777
        override_background_color(Gtk.StateFlags.NORMAL, Config.Facade.get_instance().get_bg_color());
1770
1778
        set_colors();
1771
1779
    }
1772
1780