コード例 #1
0
        void StartExpandAnimation(ToolboxWidgetCategory cat)
        {
            if (tweener != null)
            {
                tweener.Stop();
            }

            cat.AnimatingExpand   = true;
            cat.AnimationPosition = 0.0f;

            tweener = new Xwt.Motion.Tweener(animationDurationMs, 10)
            {
                Easing = Xwt.Motion.Easing.SinOut
            };
            tweener.ValueUpdated += (sender, e) => {
                cat.AnimationPosition = tweener.Value;
                QueueDraw();
            };
            tweener.Finished += (sender, e) => {
                cat.AnimatingExpand = false;
                QueueDraw();
            };
            tweener.Start();
            QueueDraw();
        }
コード例 #2
0
 protected override bool OnButtonPressEvent(Gdk.EventButton e)
 {
     this.GrabFocus();
     HideTooltipWindow();
     if (this.mouseOverItem is ToolboxWidgetCategory)
     {
         if (!e.TriggersContextMenu() && e.Button == 1 && e.Type == EventType.ButtonPress)
         {
             ToolboxWidgetCategory mouseOverCateogry = (ToolboxWidgetCategory)this.mouseOverItem;
             SetCategoryExpanded(mouseOverCateogry, !mouseOverCateogry.IsExpanded);
             return(true);
         }
         this.SelectedItem = mouseOverItem;
         this.QueueResize();
     }
     else
     {
         this.SelectedItem = mouseOverItem;
         this.QueueDraw();
     }
     if (e.TriggersContextMenu())
     {
         if (DoPopupMenu != null)
         {
             DoPopupMenu(e);
             return(true);
         }
     }
     else if (e.Type == EventType.TwoButtonPress && this.SelectedItem != null)
     {
         this.OnActivateSelectedItem(EventArgs.Empty);
         return(true);
     }
     return(base.OnButtonPressEvent(e));
 }
コード例 #3
0
 void SetCategoryExpanded(ToolboxWidgetCategory cat, bool expanded)
 {
     if (cat.IsExpanded == expanded)
     {
         return;
     }
     cat.IsExpanded = expanded;
     StartExpandAnimation(cat);
 }
コード例 #4
0
        bool IterateItems(ToolboxWidgetCategory category, ref int xpos, ref int ypos, Func <ToolboxWidgetCategory, ToolboxWidgetItem, Size, bool> action)
        {
            if (listMode || !category.CanIconizeItems)
            {
                foreach (ToolboxWidgetItem item in category.Items)
                {
                    if (!item.IsVisible)
                    {
                        continue;
                    }

                    int x, y = item.ItemHeight;

                    if (y == 0)
                    {
                        layout.SetMarkup(item.Text);
                        layout.GetPixelSize(out x, out y);
                        y  = Math.Max(iconSize.Height, y);
                        y += ItemTopBottomPadding * 2;
                        item.ItemHeight = y;
                    }

                    xpos = 0;
                    if (action != null && !action(category, item, new Gdk.Size(Allocation.Width, y)))
                    {
                        return(false);
                    }

                    ypos += y;
                }
                return(true);
            }
            foreach (ToolboxWidgetItem item in category.Items)
            {
                if (!item.IsVisible)
                {
                    continue;
                }
                if (xpos + iconSize.Width >= this.Allocation.Width)
                {
                    xpos  = 0;
                    ypos += iconSize.Height;
                }
                if (action != null && !action(category, item, iconSize))
                {
                    return(false);
                }
                xpos += iconSize.Width;
            }
            ypos += iconSize.Height;
            return(true);
        }
コード例 #5
0
        public void AddCategory(ToolboxWidgetCategory category)
        {
            categories.Add(category);
            foreach (ToolboxWidgetItem item in category.Items)
            {
                if (item.Icon == null)
                {
                    continue;
                }

                this.iconSize.Width  = Math.Max(this.iconSize.Width, (int)item.Icon.Width);
                this.iconSize.Height = Math.Max(this.iconSize.Height, (int)item.Icon.Height);
            }
        }
コード例 #6
0
        ToolboxWidgetCategory GetCategory(ToolboxWidgetItem item)
        {
            ToolboxWidgetCategory result = null;
            int xpos = 0, ypos = 0;

            Iterate(ref xpos, ref ypos, null, (curCategory, innerItem, itemDimension) => {
                if (innerItem == item)
                {
                    result = curCategory;
                    return(false);
                }
                return(true);
            });
            return(result);
        }
コード例 #7
0
        ToolboxWidgetCategory GetNextCategory(ToolboxWidgetCategory category)
        {
            ToolboxWidgetCategory result = category;
            ToolboxWidgetCategory last = null;
            int xpos = 0, ypos = 0;

            Iterate(ref xpos, ref ypos, (curCategory, itemDimension) => {
                if (last == category)
                {
                    result = curCategory;
                    return(false);
                }
                last = curCategory;
                return(true);
            }, null);
            return(result);
        }
コード例 #8
0
        ToolboxWidgetItem GetItemAbove(ToolboxWidgetItem item)
        {
            ToolboxWidgetCategory itemCategory = GetCategory(item);
            ToolboxWidgetItem     result       = item;

            Gdk.Rectangle rect = GetItemExtends(item);
            int           xpos = 0, ypos = 0;

            Iterate(ref xpos, ref ypos, null, (curCategory, curItem, itemDimension) => {
                if (ypos < rect.Y && xpos == rect.X && curCategory == itemCategory)
                {
                    result = curItem;
                    return(false);
                }
                return(true);
            });
            return(result);
        }
コード例 #9
0
        void ProcessExpandAnimation(Cairo.Context cr, ToolboxWidgetCategory lastCategory, int lastCategoryYpos, Cairo.Color backColor, Gdk.Rectangle area, ref int ypos)
        {
            if (lastCategory != null && lastCategory.AnimatingExpand)
            {
                int newypos;
                if (lastCategory.IsExpanded)
                {
                    newypos = lastCategoryYpos + (int)(lastCategory.AnimationPosition * (ypos - lastCategoryYpos));
                }
                else
                {
                    newypos = ypos - (int)(lastCategory.AnimationPosition * (ypos - lastCategoryYpos));
                }

                // Clear the area where the category will be drawn since it will be
                // drawn over the items being hidden/shown
                cr.SetSourceColor(backColor);
                cr.Rectangle(area.X, newypos, area.Width, ypos - lastCategoryYpos);
                cr.Fill();
                ypos = newypos;
            }
        }
コード例 #10
0
ファイル: Toolbox.cs プロジェクト: dgjbss/MonoDevelopWin
 void AddItems(IEnumerable <ItemToolboxNode> nodes)
 {
     foreach (ItemToolboxNode itbn in nodes)
     {
         var newItem = new ToolboxWidgetItem(itbn);
         if (!categories.ContainsKey(itbn.Category))
         {
             var cat = new ToolboxWidgetCategory(itbn.Category);
             int prio;
             if (!categoryPriorities.TryGetValue(itbn.Category, out prio))
             {
                 prio = -1;
             }
             cat.Priority = prio;
             categories[itbn.Category] = cat;
         }
         if (newItem.Text != null)
         {
             categories[itbn.Category].Add(newItem);
         }
     }
 }
コード例 #11
0
        protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
        {
            ToolboxWidgetItem nextItem;

            // Handle keyboard toolip popup
            if ((evnt.Key == Gdk.Key.F1 && (evnt.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask))
            {
                if (this.SelectedItem != null)
                {
                    int           vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0);
                    Gdk.Rectangle rect        = GetItemExtends(SelectedItem);
                    ShowTooltip(SelectedItem, 0, rect.X, rect.Bottom - vadjustment);
                }
                return(true);
            }

            switch (evnt.Key)
            {
            case Gdk.Key.KP_Enter:
            case Gdk.Key.Return:
                if (this.SelectedItem != null)
                {
                    this.OnActivateSelectedItem(EventArgs.Empty);
                }
                return(true);

            case Gdk.Key.KP_Up:
            case Gdk.Key.Up:
                if (this.listMode || this.SelectedItem is ToolboxWidgetCategory)
                {
                    this.SelectedItem = GetPrevItem(this.SelectedItem);
                }
                else
                {
                    nextItem          = GetItemAbove(this.SelectedItem);
                    this.SelectedItem = nextItem != this.SelectedItem ? nextItem : GetCategory(this.SelectedItem);
                }
                this.QueueDraw();
                return(true);

            case Gdk.Key.KP_Down:
            case Gdk.Key.Down:
                if (this.listMode || this.SelectedItem is ToolboxWidgetCategory)
                {
                    this.SelectedItem = GetNextItem(this.SelectedItem);
                }
                else
                {
                    nextItem = GetItemBelow(this.SelectedItem);
                    if (nextItem == this.SelectedItem)
                    {
                        ToolboxWidgetCategory category = GetCategory(this.SelectedItem);
                        nextItem = GetNextCategory(category);
                        if (nextItem == category)
                        {
                            nextItem = this.SelectedItem;
                        }
                    }
                    this.SelectedItem = nextItem;
                }
                this.QueueDraw();
                return(true);

            case Gdk.Key.KP_Left:
            case Gdk.Key.Left:
                if (this.SelectedItem is ToolboxWidgetCategory)
                {
                    SetCategoryExpanded((ToolboxWidgetCategory)this.SelectedItem, false);
                }
                else
                {
                    if (this.listMode)
                    {
                        this.SelectedItem = GetCategory(this.SelectedItem);
                    }
                    else
                    {
                        this.SelectedItem = GetItemLeft(this.SelectedItem);
                    }
                }
                this.QueueDraw();
                return(true);

            case Gdk.Key.KP_Right:
            case Gdk.Key.Right:
                if (this.SelectedItem is ToolboxWidgetCategory selectedCategory)
                {
                    if (selectedCategory.IsExpanded)
                    {
                        if (selectedCategory.ItemCount > 0)
                        {
                            this.SelectedItem = selectedCategory.Items [0];
                        }
                    }
                    else
                    {
                        SetCategoryExpanded(selectedCategory, true);
                    }
                }
                else
                {
                    if (this.listMode)
                    {
                        // nothing
                    }
                    else
                    {
                        this.SelectedItem = GetItemRight(this.SelectedItem);
                    }
                }
                this.QueueDraw();
                return(true);
            }
            return(false);
        }
コード例 #12
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);
        }