예제 #1
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                cr.LineWidth = 1;
                cr.Rectangle(0, 0, Allocation.Width, 16);
                var pattern = new Cairo.LinearGradient(0, 0, 0, 16);
                pattern.AddColorStop(0, new Cairo.Color(0.6, 0.8, 0.6));
                pattern.AddColorStop(1, new Cairo.Color(0.8, 1.0, 0.8));
                cr.Pattern = pattern;
                cr.Fill();
                cr.Rectangle(0, 16, Allocation.Width, Allocation.Height - 16);
                pattern = new Cairo.LinearGradient(0, 16, 0, Allocation.Height);
                pattern.AddColorStop(0, new Cairo.Color(0.8, 1.0, 0.8));
                pattern.AddColorStop(1, new Cairo.Color(0.6, 0.8, 0.6));
                cr.Pattern = pattern;
                cr.Fill();

                cr.Line(0, 0, Allocation.Width, 0);
                cr.Color = new Cairo.Color(0.4, 0.6, 0.4);
                cr.Stroke();

                double xPos = padding, yPos = padding;
                var    layout = PangoUtil.CreateLayout(this);
                int    w, h;
                layout.SetText(new string ('X', maxLength));
                layout.GetPixelSize(out w, out h);

                foreach (Category cat in categories)
                {
                    yPos = padding;
                    cr.MoveTo(xPos, yPos);
                    layout.SetMarkup("<b>" + cat.Title + "</b>");
                    cr.Color = (HslColor)Style.Text(StateType.Normal);
                    cr.ShowLayout(layout);
                    layout.SetMarkup("");
                    int w2, h2;
                    layout.GetPixelSize(out w2, out h2);
                    yPos += h2;
                    yPos += headerDistance;
                    var startY     = yPos;
                    int curItem    = 0;
                    int row        = 0;
                    var iconHeight = Math.Max(h, cat.Items[0].Icon.Height + 2);
                    if (cat.FirstVisibleItem > 0)
                    {
                        Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None,
                                             new Rectangle((int)xPos, (int)yPos, w, h),
                                             this,
                                             "",
                                             ArrowType.Up,
                                             true,
                                             (int)xPos,
                                             (int)yPos,
                                             w,
                                             h);
                        yPos += iconHeight;
                        curItem++;
                    }

                    for (int i = cat.FirstVisibleItem; i < cat.Items.Count; i++)
                    {
                        var item = cat.Items[i];

                        if (curItem + 1 >= maxItems && row + 1 >= maxRows && i + 1 < cat.Items.Count)
                        {
                            Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None,
                                                 new Rectangle((int)xPos, (int)yPos, w, h),
                                                 this,
                                                 "",
                                                 ArrowType.Down,
                                                 true,
                                                 (int)xPos,
                                                 (int)yPos,
                                                 w,
                                                 h);
                            break;
                        }

                        if (item == ActiveItem)
                        {
                            cr.Rectangle(xPos + 0.5, yPos + 0.5, w + item.Icon.Width + 2, iconHeight);

                            pattern = new Cairo.LinearGradient(xPos, yPos, xPos, yPos + iconHeight * 2);
                            pattern.AddColorStop(0, (HslColor)Style.Base(StateType.Selected));
                            pattern.AddColorStop(1, new Cairo.Color(0.8, 1.0, 0.8));
                            cr.Pattern = pattern;
                            cr.FillPreserve();

                            cr.Color = (HslColor)Style.Base(StateType.Selected);
                            cr.Stroke();
                            cr.Color = (HslColor)Style.Text(StateType.Selected);
                        }
                        else if (item == hoverItem)
                        {
                            cr.Rectangle(xPos + 0.5, yPos + 0.5, w + item.Icon.Width + 2, iconHeight);
                            pattern = new Cairo.LinearGradient(xPos, yPos, xPos, yPos + iconHeight);
                            pattern.AddColorStop(0, new Cairo.Color(0.6, 0.8, 0.6));
                            pattern.AddColorStop(1, new Cairo.Color(0.8, 1.0, 0.8));
                            cr.Pattern = pattern;
                            cr.Fill();
                            cr.Color = (HslColor)Style.Text(StateType.Normal);
                        }
                        else
                        {
                            cr.Color = (HslColor)Style.Text(StateType.Normal);
                        }
                        cr.MoveTo(xPos + item.Icon.Width + 2, yPos + (iconHeight - h) / 2);
                        layout.SetText(Ellipsize(item.ListTitle ?? item.Title, maxLength));
                        cr.ShowLayout(layout);
                        e.Window.DrawPixbuf(Style.BaseGC(StateType.Normal), item.Icon, 0, 0, (int)xPos, (int)(yPos + (iconHeight - item.Icon.Height) / 2), item.Icon.Width, item.Icon.Height, RgbDither.None, 0, 0);

                        yPos += iconHeight;
                        if (++curItem >= maxItems)
                        {
                            curItem = 0;
                            yPos    = startY;
                            xPos   += w + cat.Items[0].Icon.Width + 2 + padding;
                            row++;
                        }
                    }


                    xPos += w + cat.Items[0].Icon.Width + 2 + padding;
                }
                layout.Dispose();
            }
            return(true);
        }
예제 #2
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            Gdk.Rectangle rect = Allocation;

            //Gdk.Rectangle.Right and Bottom are inconsistent
            int right = rect.X + rect.Width, bottom = rect.Y + rect.Height;

            var bcolor = backgroundColorSet ? BackgroundColor : Style.Background(Gtk.StateType.Normal);

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                if (GradientBackround)
                {
                    cr.NewPath();
                    cr.MoveTo(rect.X, rect.Y);
                    cr.RelLineTo(rect.Width, 0);
                    cr.RelLineTo(0, rect.Height);
                    cr.RelLineTo(-rect.Width, 0);
                    cr.RelLineTo(0, -rect.Height);
                    cr.ClosePath();
                    using (Cairo.Gradient pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, bottom)) {
                        pat.AddColorStop(0, bcolor.ToCairoColor());
                        HslColor gcol = bcolor;
                        gcol.L -= 0.1;
                        if (gcol.L < 0)
                        {
                            gcol.L = 0;
                        }
                        pat.AddColorStop(1, gcol);
                        cr.SetSource(pat);
                        cr.Fill();
                    }
                }
                else
                {
                    if (backgroundColorSet)
                    {
                        Gdk.GC gc = new Gdk.GC(GdkWindow);
                        gc.RgbFgColor = bcolor;
                        evnt.Window.DrawRectangle(gc, true, rect.X, rect.Y, rect.Width, rect.Height);
                        gc.Dispose();
                    }
                }

                cr.Dispose();
            } // using

            base.OnExposeEvent(evnt);

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                cr.SetSourceColor((HslColor)Style.Dark(Gtk.StateType.Normal));

                double y = rect.Y + topMargin / 2d;
                cr.LineWidth = topMargin;
                cr.Line(rect.X, y, right, y);
                cr.Stroke();

                y            = bottom - bottomMargin / 2d;
                cr.LineWidth = bottomMargin;
                cr.Line(rect.X, y, right, y);
                cr.Stroke();

                double x = rect.X + leftMargin / 2d;
                cr.LineWidth = leftMargin;
                cr.Line(x, rect.Y, x, bottom);
                cr.Stroke();

                x            = right - rightMargin / 2d;
                cr.LineWidth = rightMargin;
                cr.Line(x, rect.Y, x, bottom);
                cr.Stroke();

                cr.Dispose();

                return(false);
            }
        }
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            Gdk.Rectangle rect = Allocation;

            //Gdk.Rectangle.Right and Bottom are inconsistent
            int right = rect.X + rect.Width, bottom = rect.Y + rect.Height;

            if (GradientBackround)
            {
                HslColor gcol = Style.Background(Gtk.StateType.Normal);

                using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window))
                {
                    cr.NewPath();
                    cr.MoveTo(rect.X, rect.Y);
                    cr.RelLineTo(rect.Width, 0);
                    cr.RelLineTo(0, rect.Height);
                    cr.RelLineTo(-rect.Width, 0);
                    cr.RelLineTo(0, -rect.Height);
                    cr.ClosePath();
                    Cairo.Gradient pat    = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, bottom);
                    Cairo.Color    color1 = gcol;
                    pat.AddColorStop(0, color1);
                    gcol.L -= 0.1;
                    if (gcol.L < 0)
                    {
                        gcol.L = 0;
                    }
                    pat.AddColorStop(1, gcol);
                    cr.Pattern = pat;
                    cr.FillPreserve();
                }
            }

            bool res = base.OnExposeEvent(evnt);

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window))
            {
                cr.Color = (HslColor)Style.Dark(Gtk.StateType.Normal);

                double y = rect.Y + topMargin / 2d;
                cr.LineWidth = topMargin;
                cr.Line(rect.X, y, right, y);
                cr.Stroke();

                y            = bottom - bottomMargin / 2d;
                cr.LineWidth = bottomMargin;
                cr.Line(rect.X, y, right, y);
                cr.Stroke();

                double x = rect.X + leftMargin / 2d;
                cr.LineWidth = leftMargin;
                cr.Line(x, rect.Y, x, bottom);
                cr.Stroke();

                x            = right - rightMargin / 2d;
                cr.LineWidth = rightMargin;
                cr.Line(x, rect.Y, x, bottom);
                cr.Stroke();
            }

            return(res);
        }
예제 #4
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            Gdk.Rectangle rect = Allocation;

            if (GradientBackround)
            {
                HslColor gcol = Style.Background(Gtk.StateType.Normal);

                using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) {
                    cr.NewPath();
                    cr.MoveTo(rect.X, rect.Y);
                    cr.RelLineTo(rect.Width, 0);
                    cr.RelLineTo(0, rect.Height);
                    cr.RelLineTo(-rect.Width, 0);
                    cr.RelLineTo(0, -rect.Height);
                    cr.ClosePath();
                    Cairo.Gradient pat    = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Bottom);
                    Cairo.Color    color1 = gcol;
                    pat.AddColorStop(0, color1);
                    gcol.L -= 0.1;
                    if (gcol.L < 0)
                    {
                        gcol.L = 0;
                    }
                    pat.AddColorStop(1, gcol);
                    cr.Pattern = pat;
                    cr.FillPreserve();
                }
            }

            bool res = base.OnExposeEvent(evnt);

            //for some reason we seem to need to paint a sightly bigger box to align with the header
            //even though the allocation appears to be the same
            rect.Width  += 1;
            rect.Height += 1;

            using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) {
                cr.Color = (HslColor)Style.Dark(Gtk.StateType.Normal);

                double y = rect.Y + topMargin / 2d;
                cr.LineWidth = topMargin;
                cr.Line(rect.X, y, rect.Right, y);
                cr.Stroke();

                y            = rect.Bottom - bottomMargin / 2d;
                cr.LineWidth = bottomMargin;
                cr.Line(rect.X, y, rect.Right, y);
                cr.Stroke();

                double x = rect.X + leftMargin / 2d;
                cr.LineWidth = leftMargin;
                cr.Line(x, rect.Y, x, rect.Bottom);
                cr.Stroke();

                x            = rect.Right - rightMargin / 2d;
                cr.LineWidth = rightMargin;
                cr.Line(x, rect.Y, x, rect.Bottom);
                cr.Stroke();
            }

            return(res);
        }