Пример #1
0
        protected override void OnDraw()
        {
            // 绘制定位线
            if (Cursor)
            {
                int tempStart = Start - 2 + Num * _note.GetSymbolWidth();
                DrawLine(tempStart, 0, tempStart, ParamsGetter.GetTotalHeight());
            }

            // 乐符纵坐标
            int yPosition = ParamsGetter.GetStaffCenterPosition() + _note.GetShift();

            int shift = _note.GetShift() / ParamsGetter.GetPitchPositionDiff();

            // 偏移线,当超过6的时候会画线。传入参数为shift,因为以左下角为原点
            DrawShiftLine(shift);
            // 绘制变音记号
            DrawAccidental(_note.GetAccidental(), yPosition);

            if (_note.GetDot() == 1)
            {
                DrawPoint(Start + ParamsGetter.GetDotePosition(), yPosition);
            }

            if (Type == 1) // 全音符
            {
                DrawSymbol("\uE12B", Start, yPosition);
                if (_note.HasChord())
                {
                    DrawChord();
                }
            }
            else
            {
                if (Type == 2) // 二分之一音符
                {
                    DrawSymbol("\uE12C", Start, yPosition);
                }
                else // 其余的所有
                {
                    DrawSymbol("\uE12D", Start, yPosition);
                }

                if (_note.IsUpOrDown())
                {
                    _stemX = Start + ParamsGetter.GetNoteRightShift(); // 符干向上时横坐标向右偏移
                    _stemY = yPosition;                                // 符干向上时纵坐标与乐符中心纵坐标位置相同
                    _tailX = Start + ParamsGetter.GetNoteTailUpLandscapeShift();
                    _tailY = _stemY + ParamsGetter.GetNoteStemHeight() - ParamsGetter.GetNoteTailDownPortraitShift();
                }
                else
                {
                    _stemX = Start - ParamsGetter.GetNoteLeftShift();         // 符干向下时横坐标向左偏移
                    _stemY = yPosition - ParamsGetter.GetNoteStemDownShift(); // 符干向下时纵坐标与乐符中心纵坐标位置偏移
                    _tailX = Start - ParamsGetter.GetNoteTailDownLandscapeShift();
                    _tailY = _stemY - ParamsGetter.GetNoteStemHeight() + ParamsGetter.GetNoteTailDownPortraitShift();
                }

                _beamX = _stemX;
                _beamY = _note.GetEnd();

                if (_note.HasChord())
                {
                    if (_note.IsUpOrDown())
                    {
                        int temp = _note.GetShift();
                        foreach (Note noteChord in _note.GetChordList())
                        {
                            if (temp > noteChord.GetShift())
                            {
                                temp = noteChord.GetShift();
                            }
                        }
                        _tailY = temp + ParamsGetter.GetNoteStemHeight();
                    }
                    DrawChord();
                }
                DrawStem(); // 画符干
                if (_note.IsSlur())
                {
                    DrawBeam(); // 画符杠
                }
                else
                {
                    DrawTail();
                }
            }
        }
Пример #2
0
 // 绘制偏移线
 private void DrawShiftLine(int shift)
 {
     if (shift > 4)
     {
         int num = (shift - 4) / 2 + 1;
         for (int i = 1; i < num; i++)
         {
             int y = ParamsGetter.GetStaffCenterPosition() + (4 + 2 * i) * ParamsGetter.GetPitchPositionDiff();
             DrawLine(Start - 4 - ParamsGetter.GetNoteLeftShift(), y, Start + 4 + ParamsGetter.GetNoteRightShift(), y);
         }
     }
     else if (shift < -4)
     {
         int num = (-4 - shift) / 2 + 1;
         for (int i = 1; i < num; i++)
         {
             int y = ParamsGetter.GetStaffCenterPosition() - (4 + 2 * i) * ParamsGetter.GetPitchPositionDiff();
             DrawLine(Start - 4 - ParamsGetter.GetNoteLeftShift(), y, Start + 4 + ParamsGetter.GetNoteRightShift(), y);
         }
     }
 }