Ejemplo n.º 1
0
        public override void Draw(Graphics gr, Point position, Range range)
        {
            //draw background
            if (BackgroundBrush != null)
            {
                TextStyle.ConfigureForShapes(gr);
                var rect = new Rectangle(position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth, range.tb.CharHeight);
                if (rect.Width == 0)
                {
                    return;
                }
                gr.FillRectangle(BackgroundBrush, rect);
                //
                if (ForegroundBrush != null)
                {
                    //draw text
                    TextStyle.ConfigureForText(gr);

                    var r = new Range(range.tb, range.Start.iChar, range.Start.iLine,
                                      Math.Min(range.tb[range.End.iLine].Count, range.End.iChar), range.End.iLine);
                    using (var style = new TextStyle(ForegroundBrush, null, FontStyle.Regular))
                        style.Draw(gr, new Point(position.X, position.Y - 1), r);
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (target == null)
            {
                return;
            }

            var zoom = this.Scale * 100 / target.Zoom;

            if (zoom <= float.Epsilon)
            {
                return;
            }

            //calc startPlace
            var r = target.VisibleRange;

            if (startPlace.iLine > r.Start.iLine)
            {
                startPlace.iLine = r.Start.iLine;
            }
            else
            {
                var endP = target.PlaceToPoint(r.End);
                endP.Offset(0, -(int)(ClientSize.Height / zoom) + target.CharHeight);
                var pp = target.PointToPlace(endP);
                if (pp.iLine > startPlace.iLine)
                {
                    startPlace.iLine = pp.iLine;
                }
            }
            startPlace.iChar = 0;
            //calc scroll pos
            var linesCount = target.Lines.Count;
            var sp1        = (float)r.Start.iLine / linesCount;
            var sp2        = (float)r.End.iLine / linesCount;

            //scale graphics
            e.Graphics.ScaleTransform(zoom, zoom);
            //draw text
            var size = new SizeF(ClientSize.Width / zoom, ClientSize.Height / zoom);

            target.DrawText(e.Graphics, startPlace, size.ToSize());

            //draw visible rect
            var p0 = target.PlaceToPoint(startPlace);
            var p1 = target.PlaceToPoint(r.Start);
            var p2 = target.PlaceToPoint(r.End);
            var y1 = p1.Y - p0.Y;
            var y2 = p2.Y + target.CharHeight - p0.Y;

            TextStyle.ConfigureForText(e.Graphics);

            using (var brush = new SolidBrush(Color.FromArgb(50, ForeColor)))
                using (var pen = new Pen(brush, 1 / zoom))
                {
                    var rect = new Rectangle(0, y1, (int)((ClientSize.Width - 1) / zoom), y2 - y1);
                    e.Graphics.FillRectangle(brush, rect);
                    e.Graphics.DrawRectangle(pen, rect);
                }

            //draw scrollbar
            if (scrollbarVisible)
            {
                e.Graphics.ResetTransform();
                TextStyle.ConfigureForShapes(e.Graphics);

                using (var brush = new SolidBrush(Color.FromArgb(200, ForeColor)))
                {
                    var rect = new RectangleF(ClientSize.Width - 3, ClientSize.Height * sp1, 2,
                                              ClientSize.Height * (sp2 - sp1));
                    e.Graphics.FillRectangle(brush, rect);
                }
            }

            needRepaint = false;
        }