Ejemplo n.º 1
0
 /// <summary>
 /// 指定したKeyTokenによって、このKeyTokenHolderのロックを解除できるかを調べます。
 /// 実際にロックを解除することは行いません。
 /// </summary>
 /// <param name="key">KeyTokenHolderのロックを解除できるかを確かめたいKeyToken</param>
 /// <returns>指定したKeyTokenによってロックを解除できるかどうか</returns>
 public bool CanUnLock(KeyToken key)
 {
     if (key == null || KeyToken == null)
     {
         return(false);
     }
     return(ReferenceEquals(key, KeyToken));
 }
Ejemplo n.º 2
0
        private static void SetEventToPutHold(
            MadcaDisplay display, NoteBook noteBook, IReadOnlyList <IReadOnlyScore> scores, OperationManager opManager, IReadOnlyEditorStatus status)
        {
            var box    = display.PictureBox;
            var env    = display.EditorLaneEnvironment;
            var holder = display.KeyTokenHolder;

            var     key = new KeyToken();
            HoldEnd end = null;

            box.MouseDown += (s, e) =>
            {
                if (holder.Locked)
                {
                    return;
                }
                if (status.EditorMode != EditorMode.Add || status.NoteMode != NoteMode.Hold)
                {
                    return;
                }
                var area = env.GetEditorLaneRegion(e.Location);
                if (area == EditorLaneRegion.Lane && e.Button == MouseButtons.Left)
                {
                    var res = PositionConverter.ConvertRealToVirtual(env, e.Location, status.BeatStride, scores, out Position position);
                    if (!res)
                    {
                        return;
                    }
                    var hold = new Hold(position.Lane, position.Timing, position.Timing + status.BeatStride, new NoteSize(status.NoteSize));
                    end = hold.HoldEnd;
                    opManager.AddAndInvokeOperation(new AddHoldOperation(noteBook, hold));
                    holder.Lock(key);
                }
            };

            box.MouseMove += (s, e) =>
            {
                if (!holder.CanUnLock(key))
                {
                    return;
                }
                var res = PositionConverter.ConvertRealToVirtual(env, e.Location, status.BeatStride, scores, out Position position);
                if (!res)
                {
                    return;
                }
                end.ReLocate(position.Lane, position.Timing);
            };

            box.MouseUp += (s, e) =>
            {
                if (!holder.UnLock(key))
                {
                    return;
                }
                end = null;
            };
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 指定したKeyTokenによって、このKeyTokenHolderのロックを解除します
 /// </summary>
 /// <param name="key">ロック解除のためのKeyToken</param>
 /// <returns>ロック解除に成功したかどうか</returns>
 public bool UnLock(KeyToken key)
 {
     if (!CanUnLock(key))
     {
         return(false);
     }
     KeyToken = null;
     return(true);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 指定したKeyTokenによって、このKeyTokenHolderをロックします
 /// </summary>
 /// <param name="key">ロックするためのKeyToken</param>
 /// <returns>ロックに成功したかどうか</returns>
 public bool Lock(KeyToken key)
 {
     if (Locked)
     {
         return(false);
     }
     KeyToken = key;
     return(true);
 }
Ejemplo n.º 5
0
        private void SetEventToDragLane()
        {
            Point?offset = null;
            Point?p      = null;
            var   key    = new KeyToken();

            PictureBox.MouseDown += (s, e) =>
            {
                if (KeyTokenHolder.Locked)
                {
                    return;
                }
                if (e.Button == MouseButtons.Middle && EditorLaneEnvironment.GetEditorLaneRegion(e.Location) == EditorLaneRegion.Lane)
                {
                    KeyTokenHolder.Lock(key);
                    offset            = new Point(EditorLaneEnvironment.OffsetXRaw, EditorLaneEnvironment.OffsetY);
                    p                 = e.Location;
                    PictureBox.Cursor = Cursors.Cross;
                }
            };
            PictureBox.MouseMove += (s, e) =>
            {
                if (!KeyTokenHolder.CanUnLock(key))
                {
                    return;
                }
                if (offset != null && p != null)
                {
                    editorLaneEnvironment.OffsetXRaw = offset.Value.X - (e.X - p.Value.X);
                    // NOTE: ある程度マウスが移動したときのみ縦方向の更新を行う(これをやらないと描画が不安定になる)
                    var diffY = offset.Value.Y + (e.Y - p.Value.Y) - EditorLaneEnvironment.OffsetY;
                    if (Math.Abs(diffY) > 10)
                    {
                        editorLaneEnvironment.OffsetY         += diffY;
                        previewDisplayEnvironment.TimingOffset = new TimingPosition(EditorLaneEnvironment.TimingUnitHeight.ToUInt(), EditorLaneEnvironment.OffsetY);
                    }
                }
            };
            PictureBox.MouseUp += (s, e) =>
            {
                if (!KeyTokenHolder.UnLock(key))
                {
                    return;
                }
                offset            = p = null;
                PictureBox.Cursor = Cursors.Default;
            };
        }
Ejemplo n.º 6
0
        private static void SetEventToReSizeNote(
            MadcaDisplay display, NoteBook noteBook, IReadOnlyList <IReadOnlyScore> scores, OperationManager opManager, IReadOnlyEditorStatus status)
        {
            var box    = display.PictureBox;
            var env    = display.EditorLaneEnvironment;
            var holder = display.KeyTokenHolder;

            var              key        = new KeyToken();
            NoteBase         note       = null;
            Position         prevPos    = null;
            NoteSize         prevSize   = null;
            Position         mouseBegin = null;
            SelectedNoteArea noteArea   = SelectedNoteArea.None;

            box.MouseDown += (s, e) =>
            {
                if (holder.Locked || status.EditorMode != EditorMode.Edit)
                {
                    return;
                }
                var area = env.GetEditorLaneRegion(e.Location);
                if (area == EditorLaneRegion.Lane && e.Button == MouseButtons.Left)
                {
                    if (!GetSelectedNote(e.Location, display, noteBook, out note))
                    {
                        return;
                    }
                    noteArea = note.SelectedNoteArea(e.Location, env);
                    if (!(noteArea == SelectedNoteArea.Left || noteArea == SelectedNoteArea.Right))
                    {
                        return;
                    }
                    prevPos  = new Position(note.Lane, note.Timing);
                    prevSize = new NoteSize(note.NoteSize);
                    var res = PositionConverter.ConvertRealToVirtual(env, e.Location, status.BeatStride, scores, out mouseBegin);
                    if (!res)
                    {
                        return;
                    }
                    holder.Lock(key);
                }
            };

            box.MouseMove += (s, e) =>
            {
                if (!holder.CanUnLock(key))
                {
                    return;
                }
                var res = PositionConverter.ConvertRealToVirtual(env, e.Location, status.BeatStride, scores, out Position position);
                if (!res)
                {
                    return;
                }
                var lane = position.Lane.RawLane - mouseBegin.Lane.RawLane;
                switch (noteArea)
                {
                case SelectedNoteArea.Left:
                {
                    var diff = prevSize.Size - lane;
                    if (1 <= diff && diff <= MadcaEnv.LaneCount)
                    {
                        note.ReLocate(new LanePotision(prevPos.Lane.RawLane + lane), note.Timing);
                    }
                    note.ReSize(new NoteSize(prevSize.Size - lane));
                    return;
                }

                case SelectedNoteArea.Right:
                {
                    note.ReSize(new NoteSize(prevSize.Size + lane));
                    return;
                }

                default: return;
                }
            };

            box.MouseUp += (s, e) =>
            {
                if (!holder.UnLock(key))
                {
                    return;
                }
                var ops = new List <Operation>();
                // TODO: 条件式要検討
                if (prevPos.Lane.RawLane != note.Lane.RawLane || prevPos.Timing != note.Timing)
                {
                    ops.Add(new ReLocateNoteOperation(note, prevPos, new Position(note.Lane, note.Timing)));
                }
                if (prevSize != note.NoteSize)
                {
                    ops.Add(new ReSizeNoteOperation(note, prevSize, note.NoteSize));
                }
                if (ops.Any())
                {
                    opManager.AddOperation(new CompositeOperation(ops.ToArray()));
                }
                note = null;
            };
        }
Ejemplo n.º 7
0
        private static void SetEventToReLocateNote(
            MadcaDisplay display, NoteBook noteBook, IReadOnlyList <IReadOnlyScore> scores, OperationManager opManager, IReadOnlyEditorStatus status)
        {
            var box    = display.PictureBox;
            var env    = display.EditorLaneEnvironment;
            var holder = display.KeyTokenHolder;

            var      key        = new KeyToken();
            NoteBase note       = null;
            Position prev       = null;
            Position mouseBegin = null;

            box.MouseDown += (s, e) =>
            {
                if (holder.Locked || status.EditorMode != EditorMode.Edit)
                {
                    return;
                }
                var area = env.GetEditorLaneRegion(e.Location);
                if (area == EditorLaneRegion.Lane && e.Button == MouseButtons.Left)
                {
                    if (!GetSelectedNote(e.Location, display, noteBook, out note))
                    {
                        return;
                    }
                    if (note.SelectedNoteArea(e.Location, env) != SelectedNoteArea.Center)
                    {
                        return;
                    }
                    prev = new Position(note.Lane, note.Timing);
                    var res = PositionConverter.ConvertRealToVirtual(env, e.Location, status.BeatStride, scores, out mouseBegin);
                    if (!res)
                    {
                        return;
                    }
                    holder.Lock(key);
                }
            };

            box.MouseMove += (s, e) =>
            {
                if (!holder.CanUnLock(key))
                {
                    return;
                }
                var res = PositionConverter.ConvertRealToVirtual(env, e.Location, status.BeatStride, scores, out Position position);
                if (!res)
                {
                    return;
                }
                var lane   = position.Lane.RawLane - mouseBegin.Lane.RawLane;
                var timing = position.Timing - mouseBegin.Timing;
                note.ReLocate(new LanePotision(prev.Lane.RawLane + lane), prev.Timing + timing);
            };

            box.MouseUp += (s, e) =>
            {
                if (!holder.UnLock(key))
                {
                    return;
                }
                // TODO: 条件式要検討
                if (prev.Lane.RawLane != note.Lane.RawLane || prev.Timing != note.Timing)
                {
                    opManager.AddOperation(new ReLocateNoteOperation(note, prev, new Position(note.Lane, note.Timing)));
                }
                note = null;
            };
        }