Exemplo n.º 1
0
        protected void DrawImage(Cairo.Context cr, Image image, double x, double y, double size)
        {
            var deltaX = size / 2 - image.Width / 2 + 0.5f;
            var deltaY = size / 2 - image.Height / 2 + 0.5f;

            cr.DrawImage(Editor, image, Math.Round(x + deltaX), Math.Round(y + deltaY));
        }
        public override void DrawForeground(MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
        {
            var tx = Math.Round(metrics.X + (metrics.Width - cache.errorPixbuf.Width) / 2) - 1;
            var ty = Math.Floor(metrics.Y + (metrics.Height - cache.errorPixbuf.Height) / 2);

            cr.Save();
            cr.Translate(tx, ty);
            cr.DrawImage(editor, errors.Any(e => e.IsError) ? cache.errorPixbuf : cache.warningPixbuf, 0, 0);
            cr.Restore();
        }
            public override void DrawForeground(TextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
            {
                isFailed = false;
                var  test        = NUnitService.Instance.SearchTestById(unitTest.UnitTestIdentifier);
                bool searchCases = false;

                Xwt.Drawing.Image icon = null;

                if (test != null)
                {
                    icon = test.StatusIcon;
                    var result = test.GetLastResult();
                    if (result == null)
                    {
                        searchCases = true;
                    }
                    else if (result.IsFailure)
                    {
                        failMessage = result.Message;
                        isFailed    = true;
                    }
                }
                else
                {
                    searchCases = true;
                }

                if (searchCases)
                {
                    foreach (var caseId in unitTest.TestCases)
                    {
                        test = NUnitService.Instance.SearchTestById(unitTest.UnitTestIdentifier + caseId);
                        if (test != null)
                        {
                            icon = test.StatusIcon;
                            var result = test.GetLastResult();
                            if (result != null && result.IsFailure)
                            {
                                failMessage = result.Message;
                                isFailed    = true;
                                break;
                            }
                        }
                    }
                }

                if (icon != null)
                {
                    if (icon.Width > metrics.Width || icon.Height > metrics.Height)
                    {
                        icon = icon.WithBoxSize(metrics.Width, metrics.Height);
                    }
                    cr.DrawImage(editor, icon, Math.Truncate(metrics.X + metrics.Width / 2 - icon.Width / 2), Math.Truncate(metrics.Y + metrics.Height / 2 - icon.Height / 2));
                }
            }
Exemplo n.º 4
0
        void DrawChangeSymbol(Cairo.Context ctx, Widget widget, double x, int width, BlockInfo block)
        {
            if (!IsChangeBlock(block.Type))
            {
                return;
            }

            if (block.Type == BlockType.Added)
            {
                var ix = x + (LeftPaddingBlock / 2) - (gutterAdded.Width / 2);
                var iy = block.YStart + ((block.YEnd - block.YStart) / 2 - gutterAdded.Height / 2);
                ctx.DrawImage(widget, gutterAdded, ix, iy);
            }
            else
            {
                var ix = x + (LeftPaddingBlock / 2) - (gutterRemoved.Width / 2);
                var iy = block.YStart + ((block.YEnd - block.YStart) / 2 - gutterRemoved.Height / 2);
                ctx.DrawImage(widget, gutterRemoved, ix, iy);
            }
        }
Exemplo n.º 5
0
        public override void DrawForeground(MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
        {
            double size            = metrics.Margin.Width;
            double borderLineWidth = cr.LineWidth;

            double x = Math.Floor(metrics.Margin.XOffset - borderLineWidth / 2);
            double y = Math.Floor(metrics.Y + (metrics.Height - size) / 2);

            var deltaX = size / 2 - DebugIcon.Width / 2 + 0.5f;
            var deltaY = size / 2 - DebugIcon.Height / 2 + 0.5f;

            cr.DrawImage(editor, DebugIcon, Math.Round(x + deltaX), Math.Round(y + deltaY));
        }
Exemplo n.º 6
0
        Rectangle DrawIcon(Cairo.Context ctx, Widget widget, Rectangle cell_area, CellRendererState flags)
        {
            int iconY    = cell_area.Y + ((cell_area.Height - (int)CategoryIcon.Height) / 2) + (Category == null ? 0 : topLevelTemplateHeadingYOffset);
            var iconRect = new Rectangle(cell_area.X + (int)Xpad, iconY, (int)CategoryIcon.Width, (int)CategoryIcon.Height);

            var img = CategoryIcon;

            if ((flags & Gtk.CellRendererState.Selected) != 0)
            {
                img = img.WithStyles("sel");
            }
            ctx.DrawImage(widget, img, iconRect.X, iconRect.Y);
            return(iconRect);
        }
        Rectangle DrawIcon(Cairo.Context ctx, Widget widget, Rectangle cell_area, CellRendererState flags)
        {
            var iconRect = new Rectangle(cell_area.X + (int)Xpad, cell_area.Y + (int)Ypad, (int)TemplateIcon.Width, (int)TemplateIcon.Height);

            var img = TemplateIcon;

            if ((flags & Gtk.CellRendererState.Selected) != 0)
            {
                img = img.WithStyles("sel");
            }
            ctx.DrawImage(widget, img, iconRect.X, iconRect.Y);

            return(iconRect);
        }
 protected override void Render(Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags)
 {
     Xwt.Drawing.Image image = this.GetImage();
     if (image == null)
     {
         return;
     }
     using (Cairo.Context s = CairoHelper.Create(window))
     {
         int num1 = cell_area.X + cell_area.Width / 2 - (int)(image.Width / 2.0);
         int num2 = cell_area.Y + cell_area.Height / 2 - (int)(image.Height / 2.0);
         s.DrawImage(widget, image, (double)num1, (double)num2);
     }
 }
Exemplo n.º 9
0
        protected virtual void DrawIcon(Cairo.Context ctx)
        {
            int x = Allocation.X + InternalPadding;
            int y = Allocation.Y + (Allocation.Height - (int)icon.Height) / 2;

            ctx.DrawImage(this, icon, x, y);
            if (AllowPinning && (mouseOver || pinned))
            {
                Xwt.Drawing.Image star;
                if (pinned)
                {
                    if (mouseOverStar)
                    {
                        star = starPinnedHover;
                    }
                    else
                    {
                        star = starPinned;
                    }
                }
                else
                {
                    if (mouseOverStar)
                    {
                        star = starNormalHover;
                    }
                    else
                    {
                        star = starNormal;
                    }
                }
                x = x + (int)icon.Width - (int)star.Width + 3;
                y = y + (int)icon.Height - (int)star.Height + 3;
                ctx.DrawImage(this, star, x, y);
                starRect = new Gdk.Rectangle(x, y, (int)star.Width, (int)star.Height);
            }
        }
Exemplo n.º 10
0
        public override void DrawForeground(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
        {
            if (statusIcon == null)
            {
                UpdateStatusIcon();
            }

            if (statusIcon != null)
            {
                if (statusIcon.Width > metrics.Width || statusIcon.Height > metrics.Height)
                {
                    statusIcon = statusIcon.WithBoxSize(metrics.Width, metrics.Height);
                }
                cr.DrawImage(editor, statusIcon, Math.Truncate(metrics.X + metrics.Width / 2 - statusIcon.Width / 2), Math.Truncate(metrics.Y + metrics.Height / 2 - statusIcon.Height / 2));
            }
        }
Exemplo n.º 11
0
        public override void DrawForeground(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
        {
            isFailed = false;
            bool searchCases = false;

            Xwt.Drawing.Image icon = host.GetStatusIcon(unitTest.UnitTestIdentifier);
            if (icon != null)
            {
                if (host.HasResult(unitTest.UnitTestIdentifier))
                {
                    searchCases = true;
                }
                else if (host.IsFailure(unitTest.UnitTestIdentifier))
                {
                    failMessage = host.GetMessage(unitTest.UnitTestIdentifier);
                    isFailed    = true;
                }
            }
            else
            {
                searchCases = true;
            }

            if (searchCases)
            {
                foreach (var caseId in unitTest.TestCases)
                {
                    icon = host.GetStatusIcon(unitTest.UnitTestIdentifier, caseId);
                    if (host.IsFailure(unitTest.UnitTestIdentifier, caseId))
                    {
                        failMessage = host.GetMessage(unitTest.UnitTestIdentifier, caseId);
                        isFailed    = true;
                        break;
                    }
                }
            }

            if (icon != null)
            {
                if (icon.Width > metrics.Width || icon.Height > metrics.Height)
                {
                    icon = icon.WithBoxSize(metrics.Width, metrics.Height);
                }
                cr.DrawImage(editor, icon, Math.Truncate(metrics.X + metrics.Width / 2 - icon.Width / 2), Math.Truncate(metrics.Y + metrics.Height / 2 - icon.Height / 2));
            }
        }
Exemplo n.º 12
0
 void RenderIcon(Cairo.Context context, Gdk.Pixbuf surface, double opacity)
 {
     context.DrawImage(this, surface.WithAlpha(opacity),
                       Allocation.X + (Allocation.Width - surface.Width) / 2,
                       Allocation.Y + (Allocation.Height - surface.Height) / 2);
 }
Exemplo n.º 13
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(e.Window);

            Gdk.Rectangle area = e.Area;

            if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage))
            {
                Pango.Layout messageLayout = new Pango.Layout(this.PangoContext);
                messageLayout.Alignment = Pango.Alignment.Center;
                messageLayout.Width     = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale);
                if (!string.IsNullOrEmpty(CustomMessage))
                {
                    messageLayout.SetText(CustomMessage);
                }
                else
                {
                    messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document."));
                }
                cr.MoveTo(Allocation.Width * 1 / 6, 12);
                cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                Pango.CairoHelper.ShowLayout(cr, messageLayout);
                messageLayout.Dispose();
                ((IDisposable)cr).Dispose();
                return(true);
            }

            var backColor = Style.Base(StateType.Normal).ToCairoColor();

            cr.SetSourceColor(backColor);
            cr.Rectangle(area.X, area.Y, area.Width, area.Height);
            cr.Fill();

            int xpos        = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0);
            int vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0);
            int ypos        = -vadjustment;
            ToolboxWidgetCategory lastCategory = null;
            int lastCategoryYpos = 0;

            cr.LineWidth = 1;

            Iterate(ref xpos, ref ypos, (category, itemDimension) => {
                ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

                if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension)))
                {
                    return(true);
                }
                cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                cr.SetSourceColor(Ide.Gui.Styles.PadCategoryBackgroundColor.ToCairoColor());
                cr.Fill();

                if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand)
                {
                    cr.MoveTo(xpos, ypos + 0.5);
                    cr.LineTo(itemDimension.Width, ypos + 0.5);
                }
                cr.MoveTo(0, ypos + itemDimension.Height - 0.5);
                cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5);
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor());
                cr.Stroke();

                headerLayout.SetMarkup(category.Text);
                int width, height;
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryLabelColor.ToCairoColor());
                headerLayout.GetPixelSize(out width, out height);
                cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                Pango.CairoHelper.ShowLayout(cr, headerLayout);

                var img = category.IsExpanded ? discloseUp : discloseDown;
                cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2));

                lastCategory     = category;
                lastCategoryYpos = ypos + itemDimension.Height;

                return(true);
            }, (curCategory, item, itemDimension) => {
                if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension)))
                {
                    return(true);
                }

                var icon = item.Icon;
                if (!icon.HasFixedSize)
                {
                    var maxIconSize     = Math.Min(itemDimension.Width, itemDimension.Height);
                    var fittingIconSize = maxIconSize > 32 ? Xwt.IconSize.Large : maxIconSize > 16 ? Xwt.IconSize.Medium : Xwt.IconSize.Small;
                    icon = item.Icon.WithSize(fittingIconSize);
                }
                if (item == SelectedItem)
                {
                    icon = icon.WithStyles("sel");
                    cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                    cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                    cr.Fill();
                }
                if (listMode || !curCategory.CanIconizeItems)
                {
                    cr.DrawImage(this, icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - icon.Height) / 2));
                    layout.SetMarkup(item.Text);
                    layout.Width = (int)((itemDimension.Width - ItemIconTextItemSpacing - iconSize.Width - ItemLeftPadding * 2) * Pango.Scale.PangoScale);
                    layout.GetPixelSize(out var width, out var height);
                    cr.SetSourceColor(Style.Text(item != SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor());
                    cr.MoveTo(xpos + ItemLeftPadding + iconSize.Width + ItemIconTextItemSpacing, ypos + Math.Round((double)(itemDimension.Height - height) / 2));
                    Pango.CairoHelper.ShowLayout(cr, layout);
                }
                else
                {
                    cr.DrawImage(this, icon, xpos + Math.Round((itemDimension.Width - icon.Width) / 2), ypos + Math.Round((itemDimension.Height - icon.Height) / 2));
                }

                if (item == mouseOverItem)
                {
                    cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor());
                    cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1);
                    cr.Stroke();
                }

                return(true);
            });

            ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

            if (lastCategory != null && lastCategory.AnimatingExpand)
            {
                // Closing line when animating the last group of the toolbox
                cr.MoveTo(area.X, ypos + 0.5);
                cr.RelLineTo(area.Width, 0);
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor());
                cr.Stroke();
            }

            ((IDisposable)cr).Dispose();
            return(true);
        }
Exemplo n.º 14
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(e.Window);

            Gdk.Rectangle area = e.Area;

            if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage))
            {
                Pango.Layout messageLayout = new Pango.Layout(this.PangoContext);
                messageLayout.Alignment = Pango.Alignment.Center;
                messageLayout.Width     = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale);
                if (!string.IsNullOrEmpty(CustomMessage))
                {
                    messageLayout.SetText(CustomMessage);
                }
                else
                {
                    messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document."));
                }
                cr.MoveTo(Allocation.Width * 1 / 6, 12);
                cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                Pango.CairoHelper.ShowLayout(cr, messageLayout);
                messageLayout.Dispose();
                ((IDisposable)cr).Dispose();
                return(true);
            }

            var backColor = Style.Base(StateType.Normal).ToCairoColor();

            cr.SetSourceColor(backColor);
            cr.Rectangle(area.X, area.Y, area.Width, area.Height);
            cr.Fill();

            int      xpos             = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0);
            int      vadjustment      = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0);
            int      ypos             = -vadjustment;
            Category lastCategory     = null;
            int      lastCategoryYpos = 0;

            Iterate(ref xpos, ref ypos, delegate(Category category, Gdk.Size itemDimension) {
                const int foldSegmentHeight = 8;

                ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

                cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                using (var pat = new Cairo.LinearGradient(xpos, ypos, xpos, ypos + itemDimension.Height)) {
                    pat.AddColorStop(0, CategoryBackgroundGradientStartColor);
                    pat.AddColorStop(1, CategoryBackgroundGradientEndColor);
                    cr.SetSource(pat);
                    cr.Fill();
                }
                if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand)
                {
                    cr.MoveTo(xpos, ypos + 0.5);
                    cr.LineTo(itemDimension.Width, ypos + 0.5);
                }
                cr.MoveTo(0, ypos + itemDimension.Height - 0.5);
                cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5);
                cr.SetSourceColor(CategoryBorderColor);
                cr.LineWidth = 1;
                cr.Stroke();

                headerLayout.SetText(category.Text);
                int width, height;
                cr.SetSourceColor(CategoryLabelColor);
                layout.GetPixelSize(out width, out height);
                cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                Pango.CairoHelper.ShowLayout(cr, headerLayout);

                var img = category.IsExpanded ? discloseUp : discloseDown;
                cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2));

                lastCategory     = category;
                lastCategoryYpos = ypos + itemDimension.Height;
            }, delegate(Category curCategory, Item item, Gdk.Size itemDimension) {
                if (item == SelectedItem)
                {
                    cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                    cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                    cr.Fill();
                }
                if (listMode || !curCategory.CanIconizeItems)
                {
                    cr.DrawImage(this, item.Icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - item.Icon.Height) / 2));
                    layout.SetText(item.Text);
                    int width, height;
                    layout.GetPixelSize(out width, out height);
                    cr.SetSourceColor(Style.Text(item != this.SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor());
                    cr.MoveTo(xpos + ItemLeftPadding + IconSize.Width + ItemIconTextItemSpacing, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                    Pango.CairoHelper.ShowLayout(cr, layout);
                }
                else
                {
                    cr.DrawImage(this, item.Icon, xpos + Math.Round((itemDimension.Width - item.Icon.Width) / 2), ypos + Math.Round((itemDimension.Height - item.Icon.Height) / 2));
                }

                if (item == mouseOverItem)
                {
                    cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor());
                    cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1);
                    cr.Stroke();
                }
            });

            ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

            if (lastCategory != null && lastCategory.AnimatingExpand)
            {
                // Closing line when animating the last group of the toolbox
                cr.MoveTo(area.X, ypos + 0.5);
                cr.RelLineTo(area.Width, 0);
                cr.SetSourceColor(CategoryBorderColor);
                cr.Stroke();
            }

            ((IDisposable)cr).Dispose();
            return(true);
        }
Exemplo n.º 15
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                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.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                    cr.ShowLayout(layout);

                    if (cat.Items.Count == 0)
                    {
                        continue;
                    }

                    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) + itemPadding * 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)
                        {
                            int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2;
                            cr.Rectangle(xPos, yPos, itemWidth, iconHeight);
                            cr.LineWidth = 1;
                            cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                            cr.Fill();
                        }
                        else if (item == hoverItem)
                        {
                            int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2;
                            cr.Rectangle(xPos + 0.5, yPos + 0.5, itemWidth - 1, iconHeight);
                            cr.LineWidth = 1;
                            cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                            cr.Stroke();
                        }
                        cr.SetSourceColor(Style.Text(item == ActiveItem? StateType.Selected : StateType.Normal).ToCairoColor());
                        cr.MoveTo(xPos + item.Icon.Width + 2 + itemPadding, yPos + (iconHeight - h) / 2);
                        layout.SetText(Ellipsize(item.ListTitle ?? item.Title, maxLength));
                        cr.ShowLayout(layout);
                        cr.DrawImage(this, item.Icon, (int)xPos + itemPadding,
                                     (int)(yPos + (iconHeight - item.Icon.Height) / 2));
                        yPos += iconHeight;
                        if (++curItem >= maxItems)
                        {
                            curItem = 0;
                            yPos    = startY;
                            xPos   += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2;
                            row++;
                        }
                    }


                    xPos += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2;
                }
                layout.Dispose();
            }
            return(true);
        }
Exemplo n.º 16
0
        protected override void OnDrawContent(Gdk.EventExpose evnt, Cairo.Context context)
        {
            context.LineWidth = 1;
            var alloc = ChildAllocation;
            var adjustedMarginSize = alloc.X - Allocation.X + headerMarginSize;

            var r = results.Where(res => res.Item2.Count > 0).ToArray();

            if (r.Any())
            {
                context.SetSourceColor(lightSearchBackground);
                context.Rectangle(Allocation.X, Allocation.Y, adjustedMarginSize, Allocation.Height);
                context.Fill();

                context.SetSourceColor(darkSearchBackground);
                context.Rectangle(Allocation.X + adjustedMarginSize, Allocation.Y, Allocation.Width - adjustedMarginSize, Allocation.Height);
                context.Fill();
                context.MoveTo(0.5 + Allocation.X + adjustedMarginSize, 0);
                context.LineTo(0.5 + Allocation.X + adjustedMarginSize, Allocation.Height);
                context.SetSourceColor(separatorLine);
                context.Stroke();
            }
            else
            {
                context.SetSourceRGB(1, 1, 1);
                context.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
                context.Fill();
            }

            double y = alloc.Y + yMargin;
            int    w, h;

            if (topItem != null)
            {
                headerLayout.SetText(GettextCatalog.GetString("Top Result"));
                headerLayout.GetPixelSize(out w, out h);
                context.MoveTo(alloc.Left + headerMarginSize - w - xMargin, y);
                context.SetSourceColor(headerColor);
                Pango.CairoHelper.ShowLayout(context, headerLayout);

                var category = topItem.Category;
                var dataSrc  = topItem.DataSource;
                var i        = topItem.Item;

                double x = alloc.X + xMargin + headerMarginSize;
                context.SetSourceRGB(0, 0, 0);
                layout.SetMarkup(GetRowMarkup(dataSrc[i]));
                layout.GetPixelSize(out w, out h);
                if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i)
                {
                    context.SetSourceColor(selectionBackgroundColor);
                    context.Rectangle(alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h);
                    context.Fill();
                    context.SetSourceRGB(1, 1, 1);
                }

                var px = dataSrc[i].Icon;
                if (px != null)
                {
                    context.DrawImage(this, px, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2);
                    x += px.Width + iconTextSpacing + marginIconSpacing;
                }

                context.MoveTo(x, y);
                context.SetSourceRGB(0, 0, 0);
                Pango.CairoHelper.ShowLayout(context, layout);

                y += h + itemSeparatorHeight;
            }

            foreach (var result in r)
            {
                var category = result.Item1;
                var dataSrc  = result.Item2;
                if (dataSrc.Count == 0)
                {
                    continue;
                }
                if (dataSrc.Count == 1 && topItem != null && topItem.DataSource == dataSrc)
                {
                    continue;
                }
                headerLayout.SetText(category.Name);
                headerLayout.GetPixelSize(out w, out h);

                if (y + h > Allocation.Height)
                {
                    break;
                }

                context.MoveTo(alloc.X + headerMarginSize - w - xMargin, y);
                context.SetSourceColor(headerColor);
                Pango.CairoHelper.ShowLayout(context, headerLayout);

                layout.Width = Pango.Units.FromPixels(Allocation.Width - adjustedMarginSize - 35);

                for (int i = 0; i < maxItems && i < dataSrc.Count; i++)
                {
                    if (topItem != null && topItem.Category == category && topItem.Item == i)
                    {
                        continue;
                    }
                    double x = alloc.X + xMargin + headerMarginSize;
                    context.SetSourceRGB(0, 0, 0);
                    layout.SetMarkup(GetRowMarkup(dataSrc[i]));
                    layout.GetPixelSize(out w, out h);
                    if (y + h + itemSeparatorHeight > Allocation.Height)
                    {
                        break;
                    }
                    if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i)
                    {
                        context.SetSourceColor(selectionBackgroundColor);
                        context.Rectangle(alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h);
                        context.Fill();
                        context.SetSourceRGB(1, 1, 1);
                    }

                    var px = dataSrc[i].Icon;
                    if (px != null)
                    {
                        context.DrawImage(this, px, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2);
                        x += px.Width + iconTextSpacing + marginIconSpacing;
                    }

                    context.MoveTo(x, y);
                    context.SetSourceRGB(0, 0, 0);
                    Pango.CairoHelper.ShowLayout(context, layout);

                    y += h + itemSeparatorHeight;
                }
                if (result != r.Last())
                {
                    y += categorySeparatorHeight;
                }
            }
            if (y == alloc.Y + yMargin)
            {
                context.SetSourceRGB(0, 0, 0);
                layout.SetMarkup(isInSearch ? GettextCatalog.GetString("Searching...") : GettextCatalog.GetString("No matches"));
                context.MoveTo(alloc.X + xMargin, y);
                Pango.CairoHelper.ShowLayout(context, layout);
            }
        }
 void DrawIndicator(Cairo.Context cr, Xwt.Drawing.Image img)
 {
     cr.DrawImage(this, img, Math.Round((Allocation.Width - img.Width) / 2), -1);
 }