Beispiel #1
0
 /// <summary>
 /// レイアウト行をテキストポイントからインデックスに変換する
 /// </summary>
 /// <param name="tp">テキストポイント表す</param>
 /// <returns>インデックスを返す</returns>
 public int GetIndexFromLayoutLine(TextPoint tp)
 {
     return(this.LayoutLines.GetIndexFromTextPoint(tp));
 }
Beispiel #2
0
        /// <summary>
        /// テキストポイントが含まれるように表示位置を調整します
        /// </summary>
        /// <param name="tp">テキストポイント</param>
        /// <param name="flow">調整方向</param>
        /// <returns>調整位置が変わったなら真。変わってないなら偽</returns>
        public (bool, Point) AdjustSrc(TextPoint tp, AdjustFlow flow)
        {
            bool   result   = false;
            Point  tpPoint  = new Point();
            double x        = this.CaretLocation.X;
            double y        = this.CaretLocation.Y;
            Point  relPoint = this.LayoutLines.GetLayout(tp.row).GetPostionFromIndex(tp.col);

            if (flow == AdjustFlow.Col || flow == AdjustFlow.Both)
            {
                x = relPoint.X;

                double left  = this.Src.X;
                double right = this.Src.X + this.render.TextArea.Width;

                if (x >= left && x <= right)    //xは表示領域にないにある
                {
                    x -= left;
                }
                else if (x > right) //xは表示領域の右側にある
                {
                    this.Document.Src = new SrcPoint(x - this.render.TextArea.Width + this.ScrollMarginWidth, this.Document.Src.Row, this.Document.Src.OffsetY);
                    if (this.Document.RightToLeft && this.Document.Src.X > 0)
                    {
                        System.Diagnostics.Debug.Assert(x > 0);
                        this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Document.Src.OffsetY);
                    }
                    else
                    {
                        x = this.render.TextArea.Width - this.ScrollMarginWidth;
                    }
                    result = true;
                }
                else if (x < left)    //xは表示領域の左側にある
                {
                    this.Document.Src = new SrcPoint(x - this.ScrollMarginWidth, this.Document.Src.Row, this.Document.Src.OffsetY);
                    if (!this.Document.RightToLeft && this.Document.Src.X < this.render.TextArea.X)
                    {
                        this.Document.Src = new SrcPoint(0, this.Document.Src.Row, this.Document.Src.OffsetY);
                    }
                    else
                    {
                        x = this.ScrollMarginWidth;
                    }
                    result = true;
                }
                x += this.render.TextArea.X;
            }

            if (flow == AdjustFlow.Row || flow == AdjustFlow.Both)
            {
                int PhyLineCountOnScreen = (int)(this.render.TextArea.Height / this.render.emSize.Height);
                //計算量を減らすため
                if (tp.row < this.Src.Row || this.Src.Row + PhyLineCountOnScreen * 2 < tp.row)
                {
                    this.Document.Src = new SrcPoint(this.Src.X, tp.row, -relPoint.Y);
                }

                //キャレットのY座標を求める
                double lineHeight    = this.render.emSize.Height;
                double caret_y       = this.Src.OffsetY; //src.rowからキャレット位置
                double alignedHeight = PhyLineCountOnScreen * lineHeight - lineHeight;
                for (int i = this.Src.Row; i < tp.row; i++)
                {
                    int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
                    int lineLength    = this.LayoutLines.GetLengthFromLineNumber(i);

                    if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
                    {
                        continue;
                    }
                    caret_y += this.LayoutLines.GetLayout(i).Height;
                }
                caret_y += relPoint.Y;

                if (caret_y < 0)
                {
                    this.Document.Src = new SrcPoint(this.Src.X, tp.row, -relPoint.Y);
                    y = 0;
                }
                else if (caret_y >= 0 && caret_y < alignedHeight)
                {
                    y = caret_y;
                }
                else if (caret_y >= alignedHeight)
                {
                    SrcPoint newsrc = this.GetNearstRowAndOffsetY(tp.row, -(alignedHeight - relPoint.Y));
                    this.Document.Src = new SrcPoint(this.Src.X, newsrc.Row, -newsrc.OffsetY);
                    y = alignedHeight;
                }
                y     += this.render.TextArea.Y;
                result = true;
            }

            if (result)
            {
                this.OnSrcChanged(null);
            }

            tpPoint.X = x;
            tpPoint.Y = y;

            return(result, tpPoint);
        }
 /// <summary>
 /// 行の高さを返す
 /// </summary>
 /// <param name="tp">テキストポイント</param>
 /// <returns>テキストポイントで指定された行の高さを返します</returns>
 public double GetLineHeight(TextPoint tp)
 {
     return(this.render.emSize.Height);
 }
Beispiel #4
0
        public Rectangle GetRectFromIndex(int index, int width, int height)
        {
            TextPoint tp = this.LayoutLines.GetTextPointFromIndex(index);

            return(this.GetRectFromTextPoint(tp, width, height));
        }
Beispiel #5
0
 public void Move(EditView view, TextPoint tp)
 {
     this.Rectangle = view.GetRectFromTextPoint(tp, Gripper.GripperWidth, Gripper.GripperWidth);
     this.HitArea   = view.GetRectFromTextPoint(tp, Gripper.HitAreaWidth, Gripper.HitAreaWidth);
 }