protected virtual TextIndex GetNextIndex(TextIndex currentIndex)
        {
            var nextIndex = TextIndexUtils.ToStringIndex(currentIndex);
            var nextState = TextIndexUtils.ReverseState(currentIndex.State);

            return(new TextIndex(nextIndex, nextState));
        }
Beispiel #2
0
        protected override bool OnMouseMove(MouseMoveEvent e)
        {
            if (lyricManager == null)
            {
                return(false);
            }

            if (!isTrigger(state.Mode))
            {
                return(false);
            }

            if (state.Mode == Mode.TimeTagEditMode)
            {
                var position = ToLocalSpace(e.ScreenSpaceMousePosition).X / 2;
                var index    = drawableLyric.GetHoverIndex(position);
                state.MoveHoverCaretToTargetPosition(new TimeTagIndexCaretPosition(Lyric, index));
            }
            else
            {
                var position = ToLocalSpace(e.ScreenSpaceMousePosition).X / 2;
                var index    = drawableLyric.GetHoverIndex(position);
                state.MoveHoverCaretToTargetPosition(new TextCaretPosition(Lyric, TextIndexUtils.ToStringIndex(index)));
            }

            return(base.OnMouseMove(e));
        }
Beispiel #3
0
            protected override bool OnMouseMove(MouseMoveEvent e)
            {
                if (lyricManager == null)
                {
                    return(false);
                }

                if (!state.CaretEnabled)
                {
                    return(false);
                }

                var position = ToLocalSpace(e.ScreenSpaceMousePosition).X;

                switch (state.Mode)
                {
                case LyricEditorMode.Manage:
                    var cuttingLyricStringIndex = Math.Clamp(TextIndexUtils.ToStringIndex(lyricPiece.GetHoverIndex(position)), 0, Lyric.Text.Length - 1);
                    state.MoveHoverCaretToTargetPosition(new TextCaretPosition(Lyric, cuttingLyricStringIndex));
                    break;

                case LyricEditorMode.Typing:
                    var typingStringIndex = TextIndexUtils.ToStringIndex(lyricPiece.GetHoverIndex(position));
                    state.MoveHoverCaretToTargetPosition(new TextCaretPosition(Lyric, typingStringIndex));
                    break;

                case LyricEditorMode.EditRubyRomaji:
                    state.MoveHoverCaretToTargetPosition(new NavigateCaretPosition(Lyric));
                    break;

                case LyricEditorMode.CreateTimeTag:
                    var textIndex = lyricPiece.GetHoverIndex(position);
                    state.MoveHoverCaretToTargetPosition(new TimeTagIndexCaretPosition(Lyric, textIndex));
                    break;

                case LyricEditorMode.RecordTimeTag:
                    var timeTag = lyricPiece.GetHoverTimeTag(position);
                    state.MoveHoverCaretToTargetPosition(new TimeTagCaretPosition(Lyric, timeTag));
                    break;

                case LyricEditorMode.AdjustTimeTag:
                case LyricEditorMode.CreateNote:
                case LyricEditorMode.CreateNotePosition:
                case LyricEditorMode.AdjustNote:
                case LyricEditorMode.Layout:
                case LyricEditorMode.Singer:
                    state.MoveHoverCaretToTargetPosition(new NavigateCaretPosition(Lyric));
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(state.Mode));
                }

                return(base.OnMouseMove(e));
            }
Beispiel #4
0
            public override bool HandleScale(Vector2 scale, Anchor anchor)
            {
                deltaPosition += scale.X;

                // this feature only works if only select one ruby / romaji tag.
                var selectedTextTag = SelectedItems.FirstOrDefault();

                if (selectedTextTag == null)
                {
                    return(false);
                }

                // get real left-side and right-side position
                var rect = editorLyricPiece.GetTextTagPosition(selectedTextTag);

                switch (anchor)
                {
                case Anchor.CentreLeft:
                    var leftPosition = rect.Left + deltaPosition;
                    var startIndex   = TextIndexUtils.ToStringIndex(editorLyricPiece.GetHoverIndex(leftPosition));
                    if (startIndex >= selectedTextTag.EndIndex)
                    {
                        return(false);
                    }

                    selectedTextTag.StartIndex = startIndex;
                    return(true);

                case Anchor.CentreRight:
                    var rightPosition = rect.Right + deltaPosition;
                    var endIndex      = TextIndexUtils.ToStringIndex(editorLyricPiece.GetHoverIndex(rightPosition));
                    if (endIndex <= selectedTextTag.StartIndex)
                    {
                        return(false);
                    }

                    selectedTextTag.EndIndex = endIndex;
                    return(true);

                default:
                    return(false);
                }
            }
Beispiel #5
0
        public Note[] CreateNotes(Lyric lyric)
        {
            var timeTags = TimeTagsUtils.ToDictionary(lyric.TimeTags);
            var notes    = new List <Note>();

            foreach (var timeTag in timeTags)
            {
                var(key, endTime) = timeTags.GetNext(timeTag);

                if (key.Index <= 0)
                {
                    continue;
                }

                var startTime = timeTag.Value;

                int startIndex = timeTag.Key.Index;
                int endIndex   = TextIndexUtils.ToStringIndex(key);

                var text = lyric.Text[startIndex..endIndex];
Beispiel #6
0
        protected override bool ApplySnapResult(SelectionBlueprint <ITextTag>[] blueprints, SnapResult result)
        {
            if (!base.ApplySnapResult(blueprints, result))
            {
                return(false);
            }

            // handle lots of ruby / romaji drag position changed.
            var items = blueprints.Select(x => x.Item).ToArray();

            if (!items.Any())
            {
                return(false);
            }

            var leftPosition = ToLocalSpace(result.ScreenSpacePosition).X;
            var startIndex   = TextIndexUtils.ToStringIndex(editorLyricPiece.GetHoverIndex(leftPosition));
            var diff         = startIndex - items.First().StartIndex;

            if (diff == 0)
            {
                return(false);
            }

            foreach (var item in items)
            {
                var newStartIndex = item.StartIndex + diff;
                var newEndIndex   = item.EndIndex + diff;
                if (!LyricUtils.AbleToInsertTextTagAtIndex(Lyric, newStartIndex) || !LyricUtils.AbleToInsertTextTagAtIndex(Lyric, newEndIndex))
                {
                    continue;
                }

                item.StartIndex = newStartIndex;
                item.EndIndex   = newEndIndex;
            }

            return(true);
        }
Beispiel #7
0
        public void TestToStringIndex(int index, TextIndex.IndexState state, int actualIndex)
        {
            var textIndex = new TextIndex(index, state);

            Assert.AreEqual(TextIndexUtils.ToStringIndex(textIndex), actualIndex);
        }