Ejemplo n.º 1
0
        bool OnSelectionExposeEvent(EventExpose evnt)
        {
            if (selection == Rectangle.Zero)
            {
                return(false);
            }

            Rectangle win_selection = ImageCoordsToWindow(selection);

            using (var evnt_region = evnt.Region.Copy()) {
                using (Region r = new Region()) {
                    r.UnionWithRect(win_selection);
                    evnt_region.Subtract(r);
                }

                using (Cairo.Context ctx = CairoHelper.Create(GdkWindow)) {
                    ctx.SetSourceRGBA(.5, .5, .5, .7);
                    CairoHelper.Region(ctx, evnt_region);
                    ctx.Fill();
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        //FIXME: respect damage regions not just the whole areas, and skip more work when possible
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (sections.Count == 0)
            {
                return(false);
            }

            var alloc = Allocation;

            int    bw            = (int)BorderWidth;
            double halfLineWidth = borderLineWidth / 2.0;
            int    bw2           = bw * 2;
            int    w             = alloc.Width - bw2;
            int    h             = alloc.Height - bw2;

            using (var cr = CairoHelper.Create(evnt.Window)) {
                CairoHelper.Region(cr, evnt.Region);
                cr.Clip();

                cr.Translate(alloc.X + bw, alloc.Y + bw);

                var borderCol = Convert(Style.Dark(StateType.Normal));
                cr.SetSourceColor(borderCol);
                cr.Rectangle(halfLineWidth, halfLineWidth, w - borderLineWidth, h - borderLineWidth);
                cr.LineWidth = borderLineWidth;
                cr.Stroke();

                cr.Translate(borderLineWidth, borderLineWidth);
                w = w - (2 * borderLineWidth);

                using (LinearGradient unselectedGrad = new LinearGradient(0, 0, 0, headerHeight),
                       hoverGrad = new LinearGradient(0, 0, 0, headerHeight),
                       selectedGrad = new LinearGradient(0, 0, 0, headerHeight)
                       )
                {
                    var unselectedCol     = Convert(Style.Mid(StateType.Normal));
                    var unselectedTextCol = Convert(Style.Text(StateType.Normal));
                    unselectedCol.A = 0.6;
                    unselectedGrad.AddColorStop(0, unselectedCol);
                    unselectedCol.A = 1;
                    unselectedGrad.AddColorStop(1, unselectedCol);

                    var hoverCol     = Convert(Style.Mid(StateType.Prelight));
                    var hoverTextCol = Convert(Style.Text(StateType.Prelight));
                    hoverCol.A = 0.6;
                    hoverGrad.AddColorStop(0, unselectedCol);
                    hoverCol.A = 1;
                    hoverGrad.AddColorStop(1, unselectedCol);

                    var selectedCol     = Convert(Style.Mid(StateType.Normal));
                    var selectedTextCol = Convert(Style.Text(StateType.Normal));
                    selectedCol.A = 0.6;
                    selectedGrad.AddColorStop(0, selectedCol);
                    selectedCol.A = 1;
                    selectedGrad.AddColorStop(1, selectedCol);

                    for (int i = 0; i < sections.Count; i++)
                    {
                        var  section  = sections[i];
                        bool isActive = activeIndex == i;
                        bool isHover  = hoverIndex == i;

                        cr.Rectangle(0, 0, w, headerHeight);
                        cr.SetSource(isActive? selectedGrad : (isHover? hoverGrad : unselectedGrad));
                        cr.Fill();

                        cr.SetSourceColor(isActive? selectedTextCol : (isHover? hoverTextCol : unselectedTextCol));
                        layout.SetText(section.Title);
                        layout.Ellipsize = Pango.EllipsizeMode.End;
                        layout.Width     = (int)((w - headerPadding - headerPadding) * Pango.Scale.PangoScale);
                        cr.MoveTo(headerPadding, headerPadding);
                        PangoCairoHelper.ShowLayout(cr, layout);

                        cr.MoveTo(-halfLineWidth, i > activeIndex? -halfLineWidth : headerHeight + halfLineWidth);
                        cr.RelLineTo(w + borderLineWidth, 0.0);
                        cr.SetSourceColor(borderCol);
                        cr.Stroke();

                        cr.Translate(0, headerHeight + borderLineWidth);
                        if (isActive)
                        {
                            cr.Translate(0, section.Child.Allocation.Height + borderLineWidth);
                        }
                    }
                }
            }

            PropagateExpose(sections[activeIndex].Child, evnt);
            return(true);           // base.OnExposeEvent (evnt);
        }