private static void SetEventToPutNote( MadcaDisplay display, NoteBook noteBook, IReadOnlyList <IReadOnlyScore> scores, OperationManager opManager, IReadOnlyEditorStatus status) { var box = display.PictureBox; var laneEnv = display.EditorLaneEnvironment; box.MouseDown += (s, e) => { if (status.EditorMode != EditorMode.Add || status.NoteMode == NoteMode.Hold || status.NoteMode == NoteMode.Field) { return; } var area = laneEnv.GetEditorLaneRegion(e.Location); if (area == EditorLaneRegion.Lane && e.Button == MouseButtons.Left) { var res = PositionConverter.ConvertRealToVirtual(laneEnv, e.Location, status.BeatStride, scores, out Position position); if (!res) { return; } var note = MyUtil.NoteFactory(position.Lane, position.Timing, new NoteSize(status.NoteSize), status.NoteMode); if (note is null) { return; } // HACK: この辺の処理どうしようかな opManager.AddAndInvokeOperation(new AddShortNoteOperation(noteBook, note)); } }; }
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; }; }
private static void SetEventToDrawPreviewNote( MadcaDisplay display, IReadOnlyList <IReadOnlyScore> scores, IReadOnlyEditorStatus status) { var box = display.PictureBox; var laneEnv = display.EditorLaneEnvironment; var previewEnv = display.PreviewDisplayEnvironment; var holder = display.KeyTokenHolder; var note = new PreviewNote(new LanePotision(0), new TimingPosition(1, 0), new NoteSize(status.NoteSize)); bool visible = false; box.MouseMove += (s, e) => { if (holder.Locked || status.EditorMode != EditorMode.Add) { visible = false; return; } var area = laneEnv.GetEditorLaneRegion(e.Location); if (area == EditorLaneRegion.Lane) { visible = true; var res = PositionConverter.ConvertRealToVirtual(laneEnv, e.Location, status.BeatStride, scores, out Position position); if (res) { note.ReLocate(position.Lane, position.Timing); } } else { visible = false; } }; box.Paint += (s, e) => { if (visible) { note.ReSize(new NoteSize(status.NoteSize)); note.SelectedNote = status.NoteMode.ToNoteType(); NoteDrawer.DrawToLane(e.Graphics, laneEnv, note); NoteDrawer.DrawToPreview(e.Graphics, previewEnv, note); } }; }
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; }; }
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; }; }