Example #1
0
        internal void DrawItem(SKCanvas canvas)
        {
            if (Selected)
            {
                canvas.FillRectangle(Bounds, Theme.RibbonItemHighlightColor);
            }

            var image_size   = LogicalToDeviceUnits(32);
            var image_area   = new Rectangle(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Width);
            var image_bounds = DrawingExtensions.CenterSquare(image_area, image_size);

            image_bounds.Y = Bounds.Top + LogicalToDeviceUnits(3);

            if (Image != null)
            {
                canvas.DrawBitmap(Image, image_bounds);
            }

            if (!string.IsNullOrWhiteSpace(Text))
            {
                var font_size = LogicalToDeviceUnits(Theme.RibbonItemFontSize);

                canvas.Save();
                canvas.Clip(Bounds);

                var text_bounds = new Rectangle(Bounds.Left, image_bounds.Bottom + LogicalToDeviceUnits(3), Bounds.Width, Bounds.Bottom - image_bounds.Bottom - LogicalToDeviceUnits(3));

                canvas.DrawText(Text, Theme.UIFont, font_size, text_bounds, Theme.DarkTextColor, ContentAlignment.MiddleCenter);

                canvas.Restore();
            }
        }
Example #2
0
        internal void OnPaint(SKCanvas canvas)
        {
            var background_color = Selected ? Theme.RibbonItemHighlightColor : Theme.LightNeutralGray;

            canvas.FillRectangle(Bounds, background_color);

            var text_left = Bounds.Left + LogicalToDeviceUnits(7);

            if (Image != null)
            {
                var image_area   = new Rectangle(Bounds.Left, Bounds.Top, Bounds.Height, Bounds.Height);
                var image_bounds = DrawingExtensions.CenterSquare(image_area, LogicalToDeviceUnits(IMAGE_SIZE));

                canvas.DrawBitmap(Image, image_bounds);

                text_left += image_bounds.Width + LogicalToDeviceUnits(7);
            }

            var text_bounds = new Rectangle(text_left, Bounds.Top, Bounds.Width - text_left, Bounds.Height);

            canvas.DrawText(Text.Trim(), Theme.UIFont, LogicalToDeviceUnits(Theme.FontSize), text_bounds, Theme.DarkTextColor, ContentAlignment.MiddleLeft);
        }
Example #3
0
        public virtual void OnPaint(SKCanvas canvas)
        {
            var owner = OwnerControl;

            if (owner is Menu menu)
            {
                // Background
                var background_color = Hovered || IsDropDownOpened ? Theme.RibbonItemHighlightColor : Theme.NeutralGray;
                canvas.FillRectangle(Bounds, background_color);

                // Text
                var font_color = Theme.DarkTextColor;
                var font_size  = menu.LogicalToDeviceUnits(Theme.FontSize);

                canvas.DrawText(Text, Theme.UIFont, font_size, Bounds, font_color, ContentAlignment.MiddleCenter);

                return;
            }

            if (owner is ToolBar bar)
            {
                // Background
                var background_color = Hovered || IsDropDownOpened ? Theme.RibbonItemHighlightColor : Theme.NeutralGray;
                canvas.FillRectangle(Bounds, background_color);

                var bounds = Bounds;
                bounds.X += bar.LogicalToDeviceUnits(8);

                // Image
                if (Image != null)
                {
                    var image_size   = bar.LogicalToDeviceUnits(20);
                    var image_bounds = DrawingExtensions.CenterSquare(Bounds, image_size);
                    var image_rect   = new Rectangle(bounds.Left, image_bounds.Top, image_size, image_size);
                    canvas.DrawBitmap(Image, image_rect);

                    bounds.X += bar.LogicalToDeviceUnits(28);
                }
                else
                {
                    bounds.X += bar.LogicalToDeviceUnits(4);
                }

                // Text
                var font_color = Theme.DarkTextColor;
                var font_size  = bar.LogicalToDeviceUnits(Theme.FontSize);

                bounds.Y += 1;
                canvas.DrawText(Text, Theme.UIFont, font_size, bounds, font_color, ContentAlignment.MiddleLeft);
                bounds.Y -= 1;

                // Dropdown Arrow
                if (HasItems)
                {
                    var arrow_bounds = DrawingExtensions.CenterSquare(Bounds, 16);
                    var arrow_area   = new Rectangle(Bounds.Right - bar.LogicalToDeviceUnits(16) - 4, arrow_bounds.Top, 16, 16);
                    ControlPaint.DrawArrowGlyph(new PaintEventArgs(SKImageInfo.Empty, canvas, bar.Scaling), arrow_area, Theme.DarkTextColor, ArrowDirection.Down);
                }

                return;
            }

            if (owner is MenuDropDown dropdown)
            {
                // Background
                var background_color = Hovered || IsDropDownOpened ? Theme.RibbonItemHighlightColor : Theme.LightTextColor;
                canvas.FillRectangle(Bounds, background_color);

                // Image
                if (Image != null)
                {
                    var image_size   = dropdown.LogicalToDeviceUnits(16);
                    var image_bounds = DrawingExtensions.CenterSquare(Bounds, image_size);
                    var image_rect   = new Rectangle(Bounds.Left + dropdown.LogicalToDeviceUnits(6), image_bounds.Top, image_size, image_size);
                    canvas.DrawBitmap(Image, image_rect);
                }

                // Text
                var font_color = Theme.DarkTextColor;
                var font_size  = dropdown.LogicalToDeviceUnits(Theme.FontSize);
                var bounds     = Bounds;
                bounds.X += dropdown.LogicalToDeviceUnits(28);
                canvas.DrawText(Text, Theme.UIFont, font_size, bounds, font_color, ContentAlignment.MiddleLeft);

                // Dropdown Arrow
                if (HasItems)
                {
                    var arrow_bounds = DrawingExtensions.CenterSquare(Bounds, 16);
                    var arrow_area   = new Rectangle(Bounds.Right - dropdown.LogicalToDeviceUnits(16) - 4, arrow_bounds.Top, 16, 16);
                    ControlPaint.DrawArrowGlyph(new PaintEventArgs(SKImageInfo.Empty, canvas, dropdown.Scaling), arrow_area, Theme.DarkTextColor, ArrowDirection.Right);
                }

                return;
            }
        }