Example #1
0
        protected override void OnRender(RenderGraphics g)
        {
            var c = g.CreateCommandList();

            c.Transform.GetOrigin(out var ox, out var oy);

            // Background shadow.
            if (IsExpanded)
            {
                var fullscreenRect = new Rectangle(0, 0, ParentFormSize.Width, ParentFormSize.Height);
                fullscreenRect.Offset(-(int)ox, -(int)oy);
                c.FillRectangle(fullscreenRect, g.GetSolidBrush(Color.Black, 1.0f, popupRatio * 0.6f));
            }

            // Clear BG.
            var navBgRect = Rectangle.Empty;

            for (int i = 0; i < (int)ButtonType.Count; i++)
            {
                var btn = buttons[i];
                if (btn.Visible && btn.IsNavButton)
                {
                    navBgRect = navBgRect.IsEmpty ? btn.Rect : Rectangle.Union(navBgRect, btn.Rect);
                }
            }

            var bgRect = new Rectangle(0, 0, Width, Height);

            var navBgBrush = IsLandscape ?
                             g.GetHorizontalGradientBrush(Theme.DarkGreyLineColor1, buttonSize, 0.8f) :
                             g.GetVerticalGradientBrush(Theme.DarkGreyLineColor1, buttonSize, 0.8f);
            var bgBrush = IsLandscape ?
                          g.GetHorizontalGradientBrush(Theme.DarkGreyFillColor1, buttonSize, 0.8f) :
                          g.GetVerticalGradientBrush(Theme.DarkGreyFillColor1, buttonSize, 0.8f);

            c.FillRectangle(bgRect, bgBrush);
            c.FillRectangle(navBgRect, navBgBrush);

            // Buttons
            for (int i = 0; i < (int)ButtonType.Count; i++)
            {
                var btn = buttons[i];

                if (btn.Visible)
                {
                    var image = btn.GetRenderInfo(out var text, out var tint);
                    c.DrawBitmapAtlas(bmpButtonAtlas, (int)image, btn.IconX, btn.IconY, 1.0f, iconScaleFloat, tint);

                    if (!string.IsNullOrEmpty(text))
                    {
                        c.DrawText(text, buttonFont, btn.TextX, btn.TextY, ThemeResources.LightGreyFillBrush1, RenderTextFlags.Center | RenderTextFlags.Ellipsis, buttonSize, 0);
                    }
                }
            }

            // Dividing line.
            if (IsLandscape)
            {
                c.DrawLine(0, 0, 0, Height, ThemeResources.BlackBrush);
            }
            else
            {
                c.DrawLine(0, 0, Width, 0, ThemeResources.BlackBrush);
            }

            g.DrawCommandList(c);

            // List items.
            if (popupButtonIdx >= 0)
            {
                c = g.CreateCommandList();

                var rect = GetExpandedListRect();
                c.PushTranslation(rect.Left, rect.Top - scrollY);

                for (int i = 0; i < listItems.Length; i++)
                {
                    var item    = listItems[i];
                    var brush   = g.GetVerticalGradientBrush(item.Color, listItemSize, 0.8f);
                    var opacity = item.GetImageOpacity != null?item.GetImageOpacity(item) : 1.0f;

                    c.FillAndDrawRectangle(item.Rect, brush, ThemeResources.BlackBrush);
                    c.DrawBitmapAtlas(bmpButtonAtlas, item.ImageIndex, item.IconX, item.IconY, opacity, iconScaleFloat, Color.Black);

                    if (item.ExtraImageIndex >= 0)
                    {
                        var extraOpacity = item.GetExtraImageOpacity != null?item.GetExtraImageOpacity(item) : 1.0f;

                        c.DrawBitmapAtlas(bmpButtonAtlas, item.ExtraImageIndex, item.ExtraIconX, item.ExtraIconY, extraOpacity, iconScaleFloat, Color.Black);
                    }

                    c.DrawText(item.Text, i == popupSelectedIdx ? ThemeResources.FontMediumBold : ThemeResources.FontMedium, item.TextX, item.TextY, ThemeResources.BlackBrush, RenderTextFlags.Middle, 0, listItemSize);
                }

                c.PopTransform();

                var scrollBarRect = GetScrollBarRect();

                if ((Math.Abs(flingVelY) > 0.0f || captureOperation == CaptureOperation.MobilePan) && !scrollBarRect.IsEmpty)
                {
                    c.PushTranslation(rect.Left, rect.Top);
                    c.FillRectangle(GetScrollBarRect(), scrollBarBrush);
                    c.PopTransform();
                }

                if (IsLandscape)
                {
                    rect.Width = -rect.X;
                }
                else
                {
                    rect.Height = -rect.Y;
                }

                rect.Offset((int)Math.Round(ox), (int)Math.Round(oy));
                g.DrawCommandList(c, rect);
            }
        }