Exemple #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();
            }
        }
        public override void Flush()
        {
            if (Count > 0)
            {
                using (new PaintWrapper(RenderingFlags.HighQuality))
                {
                    IGUIFont lastInitializedFont = null;

                    //GL.Scale ((float)GFX.OriginalWidth / GFX.Width, (float)GFX.OriginalHeight / GFX.Height, 1);

                    //foreach (StringDrawingBufferRow row in this) {
                    while (Count > 0)
                    {
                        StringDrawingBufferRow row = Queue.Dequeue();
                        if (row.Font != null)
                        {
                            if (row.Font != lastInitializedFont)
                            {
                                if (lastInitializedFont != null)
                                {
                                    lastInitializedFont.End();
                                }

                                row.Font.Begin(GFX);
                                lastInitializedFont = row.Font;
                            }

                            /***
                             * GL.PushMatrix();
                             * GL.Translate(row.Rect.Left, row.Rect.Top, 0);
                             * row.Font.Print(row.Text, row.Rect, FontFormat.DefaultSingleLine);
                             * GL.PopMatrix();
                             ***/

                            row.Font.Print(row.Text, row.Rect, FontFormat.DefaultSingleLine);
                        }
                    }

                    if (lastInitializedFont != null)
                    {
                        lastInitializedFont.End();
                    }
                }
            }
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
        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();
            }
        }
        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();
            }
        }
        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();
            }
        }
Exemple #8
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);
        }