コード例 #1
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            TypeFacePrinter printer = new TypeFacePrinter();

            printer.DrawFromHintedCache = true;

            RectangleDouble Bounds = LocalBounds;

            double y = LocalBounds.Bottom + printer.TypeFaceStyle.EmSizeInPixels * (TOTOL_POW2 - 1) + 5;

            for (int index = lineCount; index < lineCount + TOTOL_POW2; index++)
            {
                if (y > LocalBounds.Top)
                {
                    y -= printer.TypeFaceStyle.EmSizeInPixels;
                    continue;
                }
                int arrayIndex = (index % TOTOL_POW2);
                if (lines[arrayIndex] != null)
                {
                    printer.Text   = lines[arrayIndex];
                    printer.Origin = new Vector2(Bounds.Left + 2, y);
                    printer.Render(graphics2D, TextColor);
                }
                y -= printer.TypeFaceStyle.EmSizeInPixels;
                if (y < -printer.TypeFaceStyle.EmSizeInPixels)
                {
                    break;
                }
            }

            base.OnDraw(graphics2D);
        }
コード例 #2
0
        private void View3DWidget_AfterDraw(object sender, DrawEventArgs e)
        {
            if (view3DWidget?.HasBeenClosed == false && this.TrackingObject != null)
            {
                // Account for loading items in InsertionGroups - inherit parent transform
                var offset = TrackingObject.Parent?.Matrix ?? Matrix4X4.Identity;

                AxisAlignedBoundingBox bounds = TrackingObject.GetAxisAlignedBoundingBox(offset);

                Vector3 renderPosition    = bounds.GetBottomCorner(2);
                Vector2 cornerScreenSpace = view3DWidget.Object3DControlLayer.World.GetScreenPosition(renderPosition) - new Vector2(20, 10) * GuiWidget.DeviceScale;

                e.Graphics2D.PushTransform();
                Affine currentGraphics2DTransform = e.Graphics2D.GetTransform();
                Affine accumulatedTransform       = currentGraphics2DTransform * Affine.NewTranslation(cornerScreenSpace.X, cornerScreenSpace.Y);
                e.Graphics2D.SetTransform(accumulatedTransform);

                progressBar.OnDraw(e.Graphics2D);

                if (!string.IsNullOrEmpty(this.State))
                {
                    var stringPrinter = new TypeFacePrinter(this.State, 9, new Vector2(0, -20));
                    var textBounds    = stringPrinter.LocalBounds;
                    textBounds.Inflate(textBounds.Height / 4);
                    e.Graphics2D.Render(new RoundedRect(textBounds, textBounds.Height / 4), theme.BackgroundColor);
                    stringPrinter.Render(e.Graphics2D, theme.TextColor);
                }

                e.Graphics2D.PopTransform();
            }
        }
コード例 #3
0
        public void DrawString(string text,
                               double x,
                               double y,
                               double pointSize            = 12,
                               Justification justification = Justification.Left,
                               Baseline baseline           = Baseline.Text,
                               Color color             = default(Color),
                               bool drawFromHintedCach = false,
                               Color backgroundColor   = default(Color),
                               bool bold = false)
        {
            TypeFacePrinter stringPrinter = new TypeFacePrinter(text, pointSize, new Vector2(x, y), justification, baseline, bold);

            if (color.Alpha0To255 == 0)
            {
                color = Color.Black;
            }

            if (backgroundColor.Alpha0To255 != 0)
            {
                FillRectangle(stringPrinter.LocalBounds, backgroundColor);
            }

            stringPrinter.DrawFromHintedCache = drawFromHintedCach;
            stringPrinter.Render(this, color);
        }
コード例 #4
0
        public void DisplaySizeInfo(Graphics2D graphics2D, Vector2 widthDisplayCenter, double size)
        {
            string displayString = formatString.FormatWith(size);

            if (measureDisplayImage == null || measureDisplayedString != displayString)
            {
                measureDisplayedString = displayString;
                TypeFacePrinter printer           = new TypeFacePrinter(measureDisplayedString, 16);
                TypeFacePrinter unitPrinter       = new TypeFacePrinter(unitsString, 10);
                Double          unitPrinterOffset = 1;

                BorderDouble margin = new BorderDouble(5);
                printer.Origin = new Vector2(margin.Left, margin.Bottom);
                RectangleDouble bounds = printer.LocalBounds;

                unitPrinter.Origin = new Vector2(bounds.Right + unitPrinterOffset, margin.Bottom);
                RectangleDouble unitPrinterBounds = unitPrinter.LocalBounds;

                measureDisplayImage = new ImageBuffer((int)(bounds.Width + margin.Width + unitPrinterBounds.Width + unitPrinterOffset), (int)(bounds.Height + margin.Height));
                // make sure the texture has mipmaps (so it can reduce well)
                ImageGlPlugin glPlugin      = ImageGlPlugin.GetImageGlPlugin(measureDisplayImage, true);
                Graphics2D    widthGraphics = measureDisplayImage.NewGraphics2D();
                widthGraphics.Clear(new RGBA_Bytes(RGBA_Bytes.White, 128));
                printer.Render(widthGraphics, RGBA_Bytes.Black);
                unitPrinter.Render(widthGraphics, RGBA_Bytes.Black);
            }

            widthDisplayCenter -= new Vector2(measureDisplayImage.Width / 2, measureDisplayImage.Height / 2);
            graphics2D.Render(measureDisplayImage, widthDisplayCenter);
        }
コード例 #5
0
ファイル: TextWidget.cs プロジェクト: Amitkapadi/agg-sharp
        public override void OnDraw(Graphics2D graphics2D)
        {
            graphics2D.PushTransform();

            int numLines = Text.Split('\n').Length - 1;

            if (Text.Contains("\r"))
            {
                throw new Exception("These should have be converted to \n.");
            }

            double yOffsetForText = Printer.TypeFaceStyle.EmSizeInPixels * numLines;
            double xOffsetForText = 0;

            switch (printer.Justification)
            {
            case Justification.Left:
                break;

            case Justification.Center:
                xOffsetForText = (Width - Printer.LocalBounds.Width) / 2;
                break;

            case Justification.Right:
                xOffsetForText = Width - Printer.LocalBounds.Width;
                break;

            default:
                throw new NotImplementedException();
            }
            graphics2D.SetTransform(graphics2D.GetTransform() * Affine.NewTranslation(xOffsetForText, yOffsetForText));

            RGBA_Bytes currentColor = this.textColor;

            if (EllipsisIfClipped && Printer.LocalBounds.Width > LocalBounds.Width)             // only do this if it's static text
            {
                TypeFacePrinter shortTextPrinter = Printer;
                shortTextPrinter.DrawFromHintedCache = Printer.DrawFromHintedCache;
                while (shortTextPrinter.LocalBounds.Width > LocalBounds.Width && shortTextPrinter.Text.Length > 4)
                {
                    shortTextPrinter = new TypeFacePrinter(shortTextPrinter.Text.Substring(0, shortTextPrinter.Text.Length - 4).TrimEnd(spaceTrim) + "...", Printer);
                }
                shortTextPrinter.Render(graphics2D, currentColor);
            }
            else
            {
                // it all fits or it's editable (if editable it will need to be offset/scrolled sometimes).
                Printer.Render(graphics2D, currentColor);
            }

            graphics2D.PopTransform();

            base.OnDraw(graphics2D);
        }
コード例 #6
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            RectangleDouble Bounds = LocalBounds;

            int numLinesToDraw = NumVisibleLines;

            double y = LocalBounds.Bottom + printer.TypeFaceStyle.EmSizeInPixels * numLinesToDraw;

            using (TimedLock.Lock(visibleLines, ""))
            {
                using (TimedLock.Lock(this, "DrawingLines"))
                {
                    int startLineIndex = visibleLines.Count - numLinesToDraw;
                    if (forceStartLine != -1)
                    {
                        y = LocalBounds.Top;

                        if (forceStartLine > visibleLines.Count - numLinesToDraw)
                        {
                            forceStartLine = -1;
                        }
                        else
                        {
                            // make sure we show all the lines we can
                            startLineIndex = Math.Min(forceStartLine, startLineIndex);
                        }
                    }
                    int endLineIndex = visibleLines.Count;
                    for (int lineIndex = startLineIndex; lineIndex < endLineIndex; lineIndex++)
                    {
                        if (lineIndex >= 0)
                        {
                            if (visibleLines[lineIndex] != null)
                            {
                                printer.Text   = visibleLines[lineIndex];
                                printer.Origin = new Vector2(Bounds.Left + 2, y);
                                printer.Render(graphics2D, TextColor);
                            }
                        }
                        y -= printer.TypeFaceStyle.EmSizeInPixels;
                        if (y < -printer.TypeFaceStyle.EmSizeInPixels)
                        {
                            break;
                        }
                    }
                }
            }

            base.OnDraw(graphics2D);
        }
コード例 #7
0
ファイル: Graphics2D.cs プロジェクト: Frank-Buss/utest
        public void DrawString(string Text, double x, double y, double pointSize = 12,
                               Justification justification = Justification.Left, Baseline baseline     = Baseline.Text,
                               RGBA_Bytes color            = new RGBA_Bytes(), bool drawFromHintedCach = false, RGBA_Bytes backgroundColor = new RGBA_Bytes())
        {
            TypeFacePrinter stringPrinter = new TypeFacePrinter(Text, pointSize, new Vector2(x, y), justification, baseline);

            if (color.Alpha0To255 == 0)
            {
                color = RGBA_Bytes.Black;
            }

            if (backgroundColor.Alpha0To255 != 0)
            {
                FillRectangle(stringPrinter.LocalBounds, backgroundColor);
            }

            stringPrinter.DrawFromHintedCache = drawFromHintedCach;
            stringPrinter.Render(this, color);
        }