示例#1
0
        protected override void OnRenderInitialized(RenderGraphics g)
        {
            Debug.Assert((int)ButtonImageIndices.Count == ButtonImageNames.Length);
            Debug.Assert(Note.EffectCount == EffectImageIndices.Length);
            Debug.Assert(EnvelopeType.Count == EnvelopeImageIndices.Length);

            bmpButtonAtlas = g.CreateBitmapAtlasFromResources(ButtonImageNames);
            scrollBarBrush = g.CreateSolidBrush(Color.FromArgb(64, Color.Black));

            buttons[(int)ButtonType.Sequencer] = new Button {
                GetRenderInfo = GetSequencerRenderInfo, Click = OnSequencer, IsNavButton = true
            };
            buttons[(int)ButtonType.PianoRoll] = new Button {
                GetRenderInfo = GetPianoRollRenderInfo, Click = OnPianoRoll, IsNavButton = true
            };
            buttons[(int)ButtonType.Project] = new Button {
                GetRenderInfo = GetProjectExplorerInfo, Click = OnProjectExplorer, IsNavButton = true
            };
            buttons[(int)ButtonType.Channel] = new Button {
                GetRenderInfo = GetChannelRenderInfo, Click = OnChannel, ListItemClick = OnChannelItemClick, ListItemLongPress = OnChannelItemLongPress
            };
            buttons[(int)ButtonType.Instrument] = new Button {
                GetRenderInfo = GetInstrumentRenderingInfo, Click = OnInstrument, LongPress = OnInstrumentLongPress, ListItemClick = OnInstrumentItemClick, ListItemLongPress = OnInstrumentItemLongPress
            };
            buttons[(int)ButtonType.Envelope] = new Button {
                GetRenderInfo = GetEnvelopeRenderingInfo, Click = OnEnvelope, ListItemClick = OnEnvelopeItemClick
            };
            buttons[(int)ButtonType.Arpeggio] = new Button {
                GetRenderInfo = GetArpeggioRenderInfo, Click = OnArpeggio, LongPress = OnArpeggioLongPress, ListItemClick = OnArpeggioItemClick, ListItemLongPress = OnArpeggioItemLongPress
            };
            buttons[(int)ButtonType.Snap] = new Button {
                GetRenderInfo = GetSnapRenderInfo, Click = OnSnap, ListItemClick = OnSnapItemClick
            };
            buttons[(int)ButtonType.Effect] = new Button {
                GetRenderInfo = GetEffectRenderInfo, Click = OnEffect, ListItemClick = OnEffectItemClick
            };
            buttons[(int)ButtonType.DPCMEffect] = new Button {
                GetRenderInfo = GetDPCMEffectRenderInfo, Click = OnDPCMEffect, ListItemClick = OnDPCMEffectItemClick
            };
            buttons[(int)ButtonType.DPCMPlay] = new Button {
                GetRenderInfo = GetDPCMPlayRenderInfo, Click = OnDPCMPlay, LongPress = OnDPCMPlayLongPress
            };

            var screenSize = PlatformUtils.GetScreenResolution();
            var scale      = Math.Min(screenSize.Width, screenSize.Height) / 1080.0f;

            buttonFont     = scale > 1.2f ? ThemeResources.FontSmall : ThemeResources.FontVerySmall;
            buttonSize     = ScaleCustom(DefaultButtonSize, scale);
            buttonSizeNav  = ScaleCustom(DefaultNavButtonSize, scale);
            buttonIconPos1 = ScaleCustom(DefaultIconPos1, scale);
            buttonIconPos2 = ScaleCustom(DefaultIconPos2, scale);
            textPosTop     = ScaleCustom(DefaultTextPosTop, scale);
            listItemSize   = ScaleCustom(DefaultListItemSize, scale);
            listIconPos    = ScaleCustom(DefaultListIconPos, scale);
            scrollBarSizeX = ScaleCustom(DefaultScrollBarSizeX, scale);
            iconScaleFloat = ScaleCustomFloat(DefaultIconSize / (float)bmpButtonAtlas.GetElementSize(0).Width, scale);
        }
示例#2
0
        private void StartExpandingList(int idx, ListItem[] items)
        {
            var landscape = IsLandscape;

            var maxWidth  = landscape ? Math.Min(ParentFormSize.Width, ParentFormSize.Height) - buttonSize : Width;
            var maxHeight = landscape ? Height : listItemSize * 8;

            popupRect.X      = 0;
            popupRect.Y      = 0;
            popupRect.Width  = 0;
            popupRect.Height = items.Length * listItemSize + 1;

            for (int i = 0; i < items.Length; i++)
            {
                var item = items[i];
                var size = textPosTop + ThemeResources.FontMediumBold.MeasureString(item.Text) * 5 / 4;

                if (item.ExtraImageIndex >= 0)
                {
                    size += ScaleCustom(bmpButtonAtlas.GetElementSize(item.ExtraImageIndex).Width, iconScaleFloat);
                }

                popupRect.Width = Math.Max(popupRect.Width, size);
            }

            popupRect.Width  = Math.Min(popupRect.Width, maxWidth);
            popupRect.Height = Math.Min(popupRect.Height, maxHeight);

            if (landscape)
            {
                if (popupRect.Height != Height)
                {
                    popupRect.Y = (buttons[idx].Rect.Top + buttons[idx].Rect.Bottom) / 2 - popupRect.Height / 2;

                    if (popupRect.Top < 0)
                    {
                        popupRect.Y -= popupRect.Top;
                    }
                    else if (popupRect.Bottom > Height)
                    {
                        popupRect.Y -= (popupRect.Bottom - Height);
                    }
                }
            }
            else
            {
                if (popupRect.Width != Width)
                {
                    popupRect.X = (buttons[idx].Rect.Left + buttons[idx].Rect.Right) / 2 - popupRect.Width / 2;

                    if (popupRect.Left < 0)
                    {
                        popupRect.X -= popupRect.Left;
                    }
                    else if (popupRect.Right > Width)
                    {
                        popupRect.X -= (popupRect.Right - Width);
                    }
                }
            }

            var y = 0;

            for (int i = 0; i < items.Length; i++)
            {
                var item = items[i];

                item.Rect  = new Rectangle(0, y, popupRect.Width - 1, listItemSize);
                item.IconX = listIconPos;
                item.IconY = y + listIconPos;
                item.TextX = textPosTop;
                item.TextY = y;

                if (item.ExtraImageIndex >= 0)
                {
                    var extraIconSize = ScaleCustom(bmpButtonAtlas.GetElementSize(item.ExtraImageIndex).Width, iconScaleFloat);
                    item.ExtraIconX = popupRect.Width - listIconPos - extraIconSize;
                    item.ExtraIconY = y + (listItemSize - extraIconSize) / 2;
                }

                y += listItemSize;
            }

            minScrollY = 0;
            maxScrollY = y - popupRect.Height;

            popupButtonIdx = idx;
            popupRatio     = 0.0f;
            popupOpening   = true;
            popupClosing   = false;
            listItems      = items;
            flingVelY      = 0.0f;

            // Try to center selected item.
            scrollY = (int)((popupSelectedIdx + 0.5f) * listItemSize - popupRect.Height * 0.5f);
            ClampScroll();
        }
示例#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));
        }