Example #1
0
        protected void RenderDebug(RenderGraphics g)
        {
#if DEBUG
            if (PlatformUtils.IsMobile)
            {
                var c = g.CreateCommandList();
                c.FillRectangle(lastX - 30, lastY - 30, lastX + 30, lastY + 30, ThemeResources.WhiteBrush);
                g.DrawCommandList(c);
            }
#endif
        }
Example #2
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);
            }
        }
Example #3
0
        protected void RenderPiano(RenderGraphics g)
        {
            int minVisibleOctave = Utils.Clamp((int)Math.Floor(scrollX / (float)octaveSizeX), 0, NumOctaves);
            int maxVisibleOctave = Utils.Clamp((int)Math.Ceiling((scrollX + Width) / (float)octaveSizeX), 0, NumOctaves);

            var cb = g.CreateCommandList();
            var cp = g.CreateCommandList();

            // Background (white keys)
            cb.FillRectangle(0, 0, Width, Height, whiteKeyBrush);

            // Highlighted note.
            var playOctave = Note.IsMusicalNote(highlightAbsNote) ? (highlightAbsNote - 1) / 12 : -1;
            var playNote   = Note.IsMusicalNote(highlightAbsNote) ? (highlightAbsNote - 1) % 12 : -1;

            if (playNote >= 0 && !IsBlackKey(playNote))
            {
                cp.FillRectangle(GetKeyRectangle(playOctave, playNote), whiteKeyPressedBrush);
            }

            var color = Color.Empty;

            // Early pass for DPCM white keys
            for (int i = minVisibleOctave; i < maxVisibleOctave; i++)
            {
                for (int j = 0; j < 12; j++)
                {
                    if (!IsBlackKey(j) && GetDPCMKeyColor(i * 12 + j + 1, ref color))
                    {
                        cp.FillRectangle(GetKeyRectangle(i, j), g.GetVerticalGradientBrush(Theme.Darken(color, 20), color, Height));
                    }
                }
            }

            // Black keys
            for (int i = minVisibleOctave; i < maxVisibleOctave; i++)
            {
                for (int j = 0; j < 12; j++)
                {
                    if (IsBlackKey(j))
                    {
                        var brush = playOctave == i && playNote == j ? blackKeyPressedBrush : blackKeyBrush;
                        if (GetDPCMKeyColor(i * 12 + j + 1, ref color))
                        {
                            brush = g.GetVerticalGradientBrush(Theme.Darken(color, 40), Theme.Darken(color, 20), Height / 2);
                        }
                        cp.FillRectangle(GetKeyRectangle(i, j), brush);
                    }
                }
            }

            // Lines between white keys
            for (int i = minVisibleOctave; i < maxVisibleOctave; i++)
            {
                for (int j = 0; j < 12; j++)
                {
                    if (!IsBlackKey(j))
                    {
                        var groupStart = j == 0 || j == 5;
                        var x          = GetKeyRectangle(i, j).X;
                        var y          = groupStart ? 0 : Height / 2;
                        var brush      = groupStart ? ThemeResources.BlackBrush : ThemeResources.DarkGreyFillBrush2;
                        cp.DrawLine(x, y, x, Height, brush);
                    }
                }
            }

            // Top line
            cp.DrawLine(0, 0, Width, 0, ThemeResources.BlackBrush);

            // Octave labels
            for (int i = minVisibleOctave; i < maxVisibleOctave; i++)
            {
                var r = GetKeyRectangle(i, 0);
                cp.DrawText("C" + i, ThemeResources.FontSmall, r.X, r.Y, ThemeResources.BlackBrush, RenderTextFlags.BottomCenter, r.Width, r.Height - ThemeResources.FontSmall.Size);
            }

            // Drag images
            for (int i = minVisibleOctave; i < maxVisibleOctave; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    var r = GetPanRectangle(i, j);
                    if (!r.IsEmpty)
                    {
                        var size       = bmpButtonAtlas.GetElementSize((int)ButtonImageIndices.MobilePianoDrag);
                        var scale      = Math.Min(r.Width, r.Height) / (float)Math.Min(size.Width, size.Height);
                        var posX       = r.X + r.Width / 2 - (int)(size.Width * scale / 2);
                        var posY       = r.Height / 2 - (int)(size.Height * scale / 2);
                        var imageIndex = App.IsRecording && j == 1 ? (int)ButtonImageIndices.MobilePianoRest : (int)ButtonImageIndices.MobilePianoDrag;
                        cp.DrawBitmapAtlas(bmpButtonAtlas, imageIndex, posX, posY, 0.25f, scale, Color.Black);
                    }
                }
            }

            //if ((editMode == EditionMode.Channel || editMode == EditionMode.DPCMMapping) && ThemeResources.FontSmall.Size < noteSizeY)
            //    r.cp.DrawText("C" + i, ThemeResources.FontSmall, r.g.WindowScaling, octaveBaseX - noteSizeY + 1, ThemeResources.BlackBrush, RenderTextFlags.Middle, whiteKeySizeX - r.g.WindowScaling * 2, noteSizeY - 1);
            //if ((i == playOctave && j == playNote) || (draggingNote && (i == dragOctave && j == dragNote)))
            //    r.cp.FillRectangle(GetKeyRectangle(i, j), blackKeyPressedBrush);

            g.DrawCommandList(cb);
            g.DrawCommandList(cp, new Rectangle(0, 0, Width, Height));
        }