示例#1
0
文件: TextTool.cs 项目: xxgreg/Pinta
        private Point TextPositionToPoint(Position p)
        {
            Point pf = new Point (0, 0);

            Size sz = StringSize (((string)lines[p.Line]).Substring (0, p.Offset));
            Size fullSz = StringSize ((string)lines[p.Line]);

            switch (Alignment) {
            case TextAlignment.Left:
                pf = new Point (clickPoint.X + sz.Width, clickPoint.Y + (sz.Height * p.Line));
                break;

            case TextAlignment.Center:
                pf = new Point (clickPoint.X + (sz.Width - (fullSz.Width / 2)), clickPoint.Y + (sz.Height * p.Line));
                break;

            case TextAlignment.Right:
                pf = new Point (clickPoint.X + (sz.Width - fullSz.Width), clickPoint.Y + (sz.Height * p.Line));
                break;
            default:

                throw new System.ComponentModel.InvalidEnumArgumentException ("Invalid Alignment");
            }

            return pf;
        }
示例#2
0
文件: TextTool.cs 项目: xxgreg/Pinta
        private Position PointToTextPosition(Point pf)
        {
            int dx = pf.X - clickPoint.X;
            int dy = pf.Y - clickPoint.Y;
            int line = (int)Math.Floor (dy / (float)this.sizes[0].Height);

            if (line < 0) {
                line = 0;
            } else if (line >= lines.Count) {
                line = lines.Count - 1;
            }

            int offset = FindOffsetPosition (dx, (string)lines[line], line);
            Position p = new Position (line, offset);

            if (p.Offset >= ((string)lines[p.Line]).Length) {
                p.Offset = ((string)lines[p.Line]).Length;
            }

            return p;
        }
示例#3
0
        private int PositionToIndex(Position p)
        {
            int index = 0;

            for (int i = 0; i < p.Line; i++)
                index += StringToByteSize(lines[i]) + 1;

            index += StringToByteSize(lines[p.Line].Substring(0, p.Offset));
            return index;
        }
示例#4
0
        public Point TextPositionToPoint(Position p)
        {
            int index = PositionToIndex (p);

            var rect = layout.IndexToPos (index);

            int x = Pango.Units.ToPixels (rect.X) + origin.X;
            int y = Pango.Units.ToPixels (rect.Y) + origin.Y;

            return new Point (x, y);
        }
示例#5
0
 public void SetCursorPosition(Position position)
 {
     linePos = position.Line;
     textPos = position.Offset;
 }
示例#6
0
        public void SetCursorPosition(Position position, bool clearSelection)
        {
            linePos = position.Line;
            textPos = position.Offset;

            if (clearSelection)
                selectionRelativeIndex = 0;
        }