static void SetCaretMode(CaretMode mode, TextEditorData data) { if (data.Caret.Mode == mode) { return; } data.Caret.Mode = mode; data.Document.RequestUpdate(new SinglePositionUpdate(data.Caret.Line, data.Caret.Column)); data.Document.CommitDocumentUpdate(); }
SemiTone Effect_ToneChanged_affect(SemiTone tone, Time time, int delta, CaretMode mode, MusicTrack track) { if (mode.HasFlag(CaretMode.Absolute)) { return(new SemiTone(delta)); } else if (!mode.HasFlag(CaretMode.Delta)) { throw new InvalidOperationException(); } if (mode.HasFlag(CaretMode.SemiTones)) { tone += delta; } else if (mode.HasFlag(CaretMode.WholeTones)) { var keysig = track .Adornment .KeySignatures .Intersecting(time) .First() .Value; if (delta > 0) { while (delta-- > 0) { tone = keysig.Right(tone); } } else if (delta < 0) { while (delta++ < 0) { tone = keysig.Left(tone); } } } else { throw new InvalidOperationException(); } return(tone); }
void Effect_ToneChanged(int tone, CaretMode mode) { var effectedarea = default(Duration); foreach (var trackkvp in NoteSelections) { var track = trackkvp.Key; foreach (var noteID in trackkvp.Value.Selected_Tone) { var note = track.Melody[noteID]; effectedarea = note.Duration.Union(effectedarea); var newtone = Effect_ToneChanged_affect( note.Tone, note.Duration.Start, tone, mode, track ); track.Melody.UpdateNote(note.ID, note.Duration, newtone); } } Cursor .Tone .Value = Effect_ToneChanged_affect( Cursor.Tone.Value, Cursor.Caret.Focus, tone, mode, ActiveTrack ); if (effectedarea != null) { InvalidateTime(effectedarea); } Refresh(); }
public void SetCaretMode(CaretMode mode) { SetCaretMode(mode, Data); }
/// <summary> /// Calculates the position at which to draw the text caret. /// </summary> private void UpdateCaret() { if (View == null || pendingTextLayout) return; var owner = TemplatedParent as Control; var isReadOnly = (owner != null && owner.GetValue<Boolean>(TextBox.IsReadOnlyProperty)); var fontFace = TextFontFace; var fontLineSpacing = (fontFace != null) ? fontFace.LineSpacing : 0; var fontLineSpacingHalf = (Int32)Math.Ceiling(fontLineSpacing / 2f); var styledCaretWidth = (Int32)Display.DipsToPixels(CaretWidth); var styledCaretThickness = (Int32)Display.DipsToPixels(CaretThickness); var caretAlignment = TextAlignment.Left; var caretRenderX = 0; var caretRenderY = 0; var caretRenderWidth = 0; var caretRenderHeight = 0; if (caretInsertionMode == CaretMode.Overwrite && !IsLineBreak(caretPosition) && !isReadOnly) { actualInsertionMode = CaretMode.Overwrite; var caretDefaultSize = GetDefaultSizeOfOverwriteCaret(); var caretX = 0; var caretY = 0; var caretWidth = caretDefaultSize.Width; var caretHeight = caretDefaultSize.Height; if (textLayoutStream.TotalLength > 0) { var glyphLineInfo = default(LineInfo); var glyphBounds = View.Resources.TextRenderer.GetGlyphBounds(textLayoutStream, caretPosition, out glyphLineInfo, true); caretX = glyphBounds.Left; caretY = glyphBounds.Top; caretWidth = glyphBounds.Width; caretBounds = new Ultraviolet.Rectangle(caretX, caretY, caretWidth, glyphBounds.Height); caretLineIndex = glyphLineInfo.LineIndex; } else { caretAlignment = (owner == null) ? TextAlignment.Left : owner.GetValue<TextAlignment>(TextBox.TextAlignmentProperty); caretBounds = new Ultraviolet.Rectangle(caretX, caretY, caretWidth, fontLineSpacing); caretLineIndex = 0; } caretRenderWidth = caretWidth; caretRenderHeight = Math.Min(caretBounds.Height, styledCaretThickness); caretRenderY = caretBounds.Bottom - caretRenderHeight; } else { actualInsertionMode = CaretMode.Insert; var caretDefaultSize = GetDefaultSizeOfInsertionCaret(); var caretX = 0; var caretY = 0; var caretWidth = caretDefaultSize.Width; var caretHeight = caretDefaultSize.Height; if (textLayoutStream.TotalLength > 0) { var lineInfo = default(LineInfo); var boundsGlyph = default(Ultraviolet.Rectangle?); var boundsInsert = View.Resources.TextRenderer.GetInsertionPointBounds(textLayoutStream, caretPosition, out lineInfo, out boundsGlyph); caretX = boundsInsert.X; caretY = boundsInsert.Y; caretWidth = (boundsGlyph.HasValue && boundsGlyph.Value.Width > 0) ? boundsGlyph.Value.Width : fontLineSpacingHalf; caretHeight = boundsInsert.Height; caretBounds = new Ultraviolet.Rectangle(caretX, caretY, caretWidth, caretHeight); caretLineIndex = lineInfo.LineIndex; } else { caretAlignment = (owner == null) ? TextAlignment.Left : owner.GetValue<TextAlignment>(TextBox.TextAlignmentProperty); caretBounds = new Ultraviolet.Rectangle(caretX, caretY, caretWidth, caretHeight); caretLineIndex = 0; } caretRenderWidth = Math.Min(caretBounds.Width, styledCaretWidth); caretRenderHeight = caretBounds.Height; caretRenderY = caretBounds.Top; } switch (caretAlignment) { case TextAlignment.Left: caretRenderX = caretBounds.Left; break; case TextAlignment.Center: caretRenderX = caretBounds.Center.X - (caretRenderWidth / 2); break; case TextAlignment.Right: caretRenderX = (caretBounds.Right - caretRenderWidth); break; } caretRenderBounds = new Ultraviolet.Rectangle(caretRenderX, caretRenderY, caretRenderWidth, caretRenderHeight); }
/// <summary> /// Toggles the editor's insertion mode. /// </summary> private void ToggleInsertionMode() { caretBlinkTimer = 0; caretInsertionMode = (caretInsertionMode == CaretMode.Insert) ? CaretMode.Overwrite : CaretMode.Insert; UpdateCaret(); }
private void CommandCenter_WhenPreviewTimeChanged(Time time, CaretMode mode) => Effect_TimeChanged(time, mode);
public void ChangeTone_Preview(int change, CaretMode mode) => Do(() => WhenPreviewToneChanged?.Invoke(change, mode));
private void CommandCenter_WhenTimeChanged(Time time, CaretMode mode) { // action was already handled by preview }
private void CommandCenter_WhenPreviewToneChanged(int tone, CaretMode mode) => Effect_ToneChanged(tone, mode);
private void CommandCenter_WhenToneChanged(int tone, CaretMode mode) { // action was already handled by preview }
public void ChangeTone(int change, CaretMode mode) => Do(() => WhenToneChanged?.Invoke(change, mode));
public void ChangeTime(Time change, CaretMode mode) => Do(() => WhenTimeChanged?.Invoke(change, mode));
public void SetCaretMode (CaretMode mode) { SetCaretMode (mode, Data); }
void Effect_TimeChanged(Time time, CaretMode mode) { var effectedarea = default(Duration); foreach (var trackkvp in NoteSelections) { var track = trackkvp.Key; foreach (var noteID in trackkvp.Value.Selected_Start.Union(trackkvp.Value.Selected_End)) { var is_start = trackkvp.Value.Selected_Start.Contains(noteID); var is_end = trackkvp.Value.Selected_End.Contains(noteID); var note = track.Melody[noteID]; var oldduration = note.Duration; var newduration = new Duration { Start = oldduration.Start, Length = oldduration.Length }; if (is_start) { if (mode == CaretMode.Absolute) { newduration.Start = time; } else if (mode == CaretMode.Delta) { newduration.Start += time; } } if (is_end) { if (mode == CaretMode.Absolute) { newduration.End = time; } else if (mode == CaretMode.Delta) { newduration.End += time; } } effectedarea = oldduration .Union(newduration) .Union(effectedarea); track.Melody.UpdateNote(note.ID, newduration, note.Tone); } } if (mode == CaretMode.Absolute) { Cursor.Caret.Focus = time; } else if (mode == CaretMode.Delta) { Cursor.Caret.Focus += time; } //TODO: update only the affected duration if (effectedarea != null) { InvalidateTime(effectedarea); } Refresh(); }
static void SetCaretMode (CaretMode mode, TextEditorData data) { if (data.Caret.Mode == mode) return; data.Caret.Mode = mode; data.Document.RequestUpdate (new SinglePositionUpdate (data.Caret.Line, data.Caret.Column)); data.Document.CommitDocumentUpdate (); }
public void ChangeTime_Preview(Time change, CaretMode mode) => Do(() => WhenPreviewTimeChanged?.Invoke(change, mode));