Example #1
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaint(ctx, bounds);

            bounds.Offset(Padding.Left, Padding.Top);

            int lineHeight = RowManager.LineHeight;
            int offsetY    = (int)ScrollOffsetY;

            int      rowIndex = RowManager.FirstParagraphOnScreen;
            IGUIFont font     = RowManager.Font;

            try {
                while (rowIndex < RowManager.Paragraphs.Count)
                {
                    Paragraph para      = RowManager.Paragraphs[rowIndex];
                    Rectangle rowBounds = new Rectangle((int)bounds.Left + (int)ScrollOffsetX,
                                                        (int)(bounds.Top + para.Top + offsetY),
                                                        (int)bounds.Width,
                                                        lineHeight);

                    var glyphLines = para.ToGlyphs();

                    foreach (var line in glyphLines)
                    {
                        if (rowBounds.Bottom > bounds.Top)
                        {
                            font.Begin(ctx);
                            font.PrintTextLine(line.Select(g => g.Glyph).ToArray(), rowBounds, Style.ForeColorBrush.Color);
                            font.End();
                        }
                        rowBounds.Offset(0, lineHeight);
                        if (rowBounds.Top > bounds.Bottom)
                        {
                            break;
                        }
                    }

                    if (rowBounds.Top > bounds.Bottom)
                    {
                        break;
                    }

                    rowIndex++;
                }

                if (CursorOn && CursorVisible)
                {
                    RectangleF CursorRectangle = RowManager.CalcCursorRectangle();
                    int        x  = Math.Max((int)bounds.Left + 1, (int)(CursorRectangle.X + bounds.Left + ScrollOffsetX + 0.5f));
                    float      y1 = CursorRectangle.Top + bounds.Top + ScrollOffsetY + 2;
                    float      y2 = y1 + CursorRectangle.Height - 4;
                    ctx.DrawLine(CursorPen, x, y1, x, y2);
                }
            } catch (Exception ex) {
                ex.LogError();
            }
        }
Example #2
0
        public static SizeF DrawString(this IGUIContext ctx, string text, IGUIFont font, Brush brush, float x, float y, FontFormat format)
        {
            if (ctx == null)
            {
                return(SizeF.Empty);
            }

            SizeF contentSize = font.Measure(text);

            switch (format.HAlign)
            {
            case Alignment.Near:
                break;

            case Alignment.Center:
                x -= contentSize.Width / 2f;
                break;

            case Alignment.Far:
                x -= contentSize.Width;
                break;
            }

            // ToDo: Was soll das hier noch ?
            switch (format.VAlign)
            {
            case Alignment.Near:
                y -= contentSize.Height / 2f;
                break;

            case Alignment.Center:
                y += contentSize.Height / 2f;
                break;

            case Alignment.Far:
            case Alignment.Baseline:
                y += contentSize.Height / 2;
                break;
            }

            SizeF retVal;

            font.Begin(ctx);
            Color c = Color.Empty;

            if (brush != null)
            {
                c = brush.Color;
            }
            retVal = font.Print(text, new RectangleF(x, y, contentSize.Width, contentSize.Height), format, c);
            font.End();
            return(retVal);
        }
Example #3
0
        public static SizeF DrawSelectedString(this IGUIContext ctx, string text, IGUIFont font, int selStart, int selLength, RectangleF rect, float offsetX, FontFormat format, Color foreColor, Color selectionBackColor, Color selectionForeColor)
        {
            if (ctx == null || text == null)
            {
                return(SizeF.Empty);
            }

            SizeF retVal;

            font.Begin(ctx);
            retVal = font.PrintSelectedString(text, selStart, selLength, rect, offsetX, format, foreColor, selectionBackColor, selectionForeColor);
            font.End();
            return(retVal);
        }
Example #4
0
        public void PrintTextLine(IGUIContext ctx, string fontTag, uint[] glyphs, RectangleF bounds, Color foreColor)
        {
            IGUIFont font = FontByTag(fontTag);

            if (font == null)
            {
                return;
            }
            font.Begin(ctx);
            try {
                font.PrintTextLine(glyphs, bounds, foreColor);
            } catch (Exception ex) {
                ex.LogError();
            }
            finally {
                font.End();
            }
        }
Example #5
0
        public SizeF PrintSelectedString(IGUIContext ctx, string fontTag, string text, int selStart, int selLength, RectangleF bounds, float offsetX, FontFormat format, Color foreColor, Color selectionBackColor, Color selectionForeColor)
        {
            IGUIFont font = FontByTag(fontTag);

            if (font == null)
            {
                return(SizeF.Empty);
            }
            font.Begin(ctx);
            try {
                return(font.PrintSelectedString(text, selStart, selLength, bounds, offsetX, format, foreColor, selectionBackColor, selectionForeColor));
            } catch (Exception ex) {
                ex.LogError();
                return(SizeF.Empty);
            }
            finally {
                font.End();
            }
        }
Example #6
0
        public SizeF Print(IGUIContext ctx, string fontTag, string text, RectangleF bounds, FontFormat format, Color color = default(Color))
        {
            IGUIFont font = FontByTag(fontTag);

            if (font == null)
            {
                return(SizeF.Empty);
            }

            font.Begin(ctx);
            try {
                return(font.Print(text, bounds, format, color));
            } catch (Exception ex) {
                ex.LogError();
                return(SizeF.Empty);
            }
            finally {
                font.End();
            }
        }
Example #7
0
        public static SizeF DrawString(this IGUIContext ctx, string text, IGUIFont font, Brush brush, RectangleF rect, FontFormat format)
        {
            if (ctx == null || text == null)
            {
                return(SizeF.Empty);
            }

            SizeF retVal;

            Color c = Color.Empty;

            if (brush != null)
            {
                c = brush.Color;
            }

            font.Begin(ctx);
            retVal = font.Print(text, rect, format, c);
            font.End();
            return(retVal);
        }