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); }
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(); } }
void Update() { // update animation counter x += Time.deltaTime; while (x > 1.0f) { x -= 1.0f; } // clear background with white Graphics2D g = buffer.NewGraphics2D(); g.Clear(RGBA_Bytes.White); // draw some lines float w = buffer.Width * x; for (int i = 0; i < 10; i++) { g.Line(x1: 0, y1: buffer.Height * i / 10, x2: w - w * i / 10, y2: 0, color: RGBA_Bytes.Black, strokeWidth: 3); } // draw some text TypeFacePrinter textPrinter = new TypeFacePrinter("Hello World!", 30, justification: Justification.Center); IVertexSource translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(buffer.Width / 2, 5)); g.Render(translatedText, RGBA_Bytes.Blue); // update texture data byte[] pixels = buffer.GetBuffer(); texture.LoadRawTextureData(pixels); texture.Apply(); }
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); }
public void CorectLineCounts() { var lines7 = @"; activate T0 ; move up a bit G91 G1 Z1 F1500 G90 ; do the switch to T0 G1 X-29.5 F6000 ; NO_PROCESSING"; var printer7 = new TypeFacePrinter(lines7); Assert.AreEqual(7, printer7.NumLines()); var lines8 = @"; activate T0 ; move up a bit G91 G1 Z1 F1500 G90 ; do the switch to T0 G1 X-29.5 F6000 ; NO_PROCESSING "; var printer8 = new TypeFacePrinter(lines8); Assert.AreEqual(8, printer8.NumLines()); }
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); }
private void AddCharacterMeshes(string currentText, TypeFacePrinter printer) { int newIndex = asynchMeshGroups.Count; StyledTypeFace typeFace = printer.TypeFaceStyle; for (int i = 0; i < currentText.Length; i++) { string letter = currentText[i].ToString(); TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace); if (CharacterHasMesh(letterPrinter, letter)) { Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2); asynchMeshGroups.Add(new MeshGroup(textMesh)); PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData(); newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i); asynchPlatingDatas.Add(newMeshInfo); asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity()); PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, null); ScaleRotateTranslate moved = asynchMeshGroupTransforms[newIndex]; moved.translation *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2)); asynchMeshGroupTransforms[newIndex] = moved; newIndex++; } processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length); } }
public TextWidget(string text, double x = 0, double y = 0, double pointSize = 12, Justification justification = Justification.Left, RGBA_Bytes textColor = new RGBA_Bytes(), bool ellipsisIfClipped = true, bool underline = false, RGBA_Bytes backgroundColor = new RGBA_Bytes()) { pointSize *= GlobalPointSizeScaleRatio; Selectable = false; DoubleBuffer = DoubleBufferDefault; AutoExpandBoundsToText = false; EllipsisIfClipped = ellipsisIfClipped; OriginRelativeParent = new Vector2(x, y); this.textColor = textColor; if (this.textColor.Alpha0To255 == 0) { // we assume it is the default if alpha 0. Also there is no reason to make a text color of this as it will draw nothing. this.textColor = RGBA_Bytes.Black; } if (backgroundColor.Alpha0To255 != 0) { BackgroundColor = backgroundColor; } base.Text = text; StyledTypeFace typeFaceStyle = new StyledTypeFace(LiberationSansFont.Instance, pointSize, underline); printer = new TypeFacePrinter(text, typeFaceStyle, justification: justification); LocalBounds = printer.LocalBounds; MinimumSize = new Vector2(LocalBounds.Width, LocalBounds.Height); }
public static SizeF MeasureStringStatic(string text, Font font, PointF origin, StringFormat format) { var tfp = new TypeFacePrinter(text, font.SizeInPoints); var bounds = tfp.LocalBounds; return(new SizeF((float)bounds.Width, (float)bounds.Height)); }
public DockingTabButton(string tabTitle, ThemeConfig theme) { this.grayBorder = theme.GetBorderColor(theme.IsDarkTheme ? 45 : 55); this.theme = theme; this.HAnchor = HAnchor.Fit; this.VAnchor = VAnchor.Fit | VAnchor.Center; this.AlignToRightEdge = true; this.MakeScrollable = false; this.Border = new BorderDouble(right: 6); this.BorderColor = grayBorder; this.Margin = new BorderDouble(2, 8, 0, 0); this.HoverColor = Color.Transparent; var printer = new TypeFacePrinter(tabTitle, theme.DefaultFontSize * GuiWidget.DeviceScale); var rotatedLabel = new VertexSourceApplyTransform( printer, Affine.NewRotation(MathHelper.DegreesToRadians(-90))); var textBounds = rotatedLabel.GetBounds(); var bounds = new RectangleDouble(printer.TypeFaceStyle.DescentInPixels, textBounds.Bottom, printer.TypeFaceStyle.AscentInPixels, textBounds.Top); rotatedLabel.Transform = ((Affine)rotatedLabel.Transform) * Affine.NewTranslation(new Vector2(-printer.TypeFaceStyle.DescentInPixels, -bounds.Bottom)); this.AddChild(buttonView = new GuiWidget(bounds.Width, bounds.Height) { DoubleBuffer = true, Margin = new BorderDouble(3, 1), Selectable = false }); buttonView.AfterDraw += (s, e) => { e.Graphics2D.Render(rotatedLabel, theme.TextColor); }; }
private void insertTextBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; BackgroundWorker backgroundWorker = (BackgroundWorker)sender; asynchMeshGroups.Clear(); asynchMeshGroupTransforms.Clear(); asynchPlatingDatas.Clear(); string currentText = (string)e.Argument; TypeFacePrinter printer = new TypeFacePrinter(currentText, new StyledTypeFace(boldTypeFace, 12)); Vector2 size = printer.GetSize(currentText); double centerOffset = -size.x / 2; double ratioPerMeshGroup = 1.0 / currentText.Length; double currentRatioDone = 0; for (int i = 0; i < currentText.Length; i++) { int newIndex = asynchMeshGroups.Count; TypeFacePrinter letterPrinter = new TypeFacePrinter(currentText[i].ToString(), new StyledTypeFace(boldTypeFace, 12)); Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, 10 + (i % 2)); if (textMesh.Faces.Count > 0) { asynchMeshGroups.Add(new MeshGroup(textMesh)); PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData(); newMeshInfo.xSpacing = printer.GetOffsetLeftOfCharacterIndex(i).x + centerOffset; asynchPlatingDatas.Add(newMeshInfo); asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity()); PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, (double progress0To1, string processingState, out bool continueProcessing) => { continueProcessing = true; int nextPercent = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100); backgroundWorker.ReportProgress(nextPercent); }); currentRatioDone += ratioPerMeshGroup; PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, newIndex); } backgroundWorker.ReportProgress((i + 1) * 95 / currentText.Length); } SetWordSpacing(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas); SetWordSize(asynchMeshGroups, asynchMeshGroupTransforms); SetWordHeight(asynchMeshGroups, asynchMeshGroupTransforms); if (createUnderline.Checked) { CreateUnderline(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas); } backgroundWorker.ReportProgress(95); }
public void TextWidgetVisibleTest() { GuiWidget rectangleWidget = new GuiWidget(100, 50); TextEditWidget itemToAdd = new TextEditWidget("test Item", 10, 10); rectangleWidget.AddChild(itemToAdd); rectangleWidget.DoubleBuffer = true; rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White); rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D()); ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA()); textOnly.NewGraphics2D().Clear(RGBA_Bytes.White); #if true TypeFacePrinter stringPrinter = new TypeFacePrinter("test Item", 12); IVertexSource offsetText = new VertexSourceApplyTransform(stringPrinter, Affine.NewTranslation(1, -stringPrinter.LocalBounds.Bottom)); textOnly.NewGraphics2D().Render(offsetText, RGBA_Bytes.Black); #else textOnly.NewGraphics2D().DrawString("test Item", 1, 1); #endif if (saveImagesForDebug) { ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga"); //ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga"); ImageTgaIO.Save(textOnly, "-textOnly.tga"); } Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing."); rectangleWidget.Close(); }
// TODO: These are not GDI+ compatible.. decide where to put them. // TODO: adjust measure string to handle "StringFormat.GenericTypographic" differently than normal padding public static SizeF MeasureStringStatic(string text, Font font) { // TODO: teach agg-sharp to render windows fonts var tfp = new TypeFacePrinter(text, font.SizeInPoints); var bounds = tfp.LocalBounds; return(new SizeF((float)bounds.Width, (float)bounds.Height)); }
public TextScrollWidget(List <string> sourceLines) { printer = new TypeFacePrinter("", new StyledTypeFace(ApplicationController.MonoSpacedTypeFace, 12)); printer.DrawFromHintedCache = true; this.allSourceLines = sourceLines; this.visibleLines = sourceLines; PrinterOutputCache.Instance.HasChanged.RegisterEvent(RecievedNewLine, ref unregisterEvents); }
public TextScrollWidget(PrinterConfig printer, List <string> sourceLines) { this.printer = new TypeFacePrinter("", new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), 12)); this.printer.DrawFromHintedCache = true; this.allSourceLines = sourceLines; this.visibleLines = sourceLines; printer.Connection.TerminalLog.HasChanged.RegisterEvent(RecievedNewLine, ref unregisterEvents); }
public override Task Rebuild() { this.DebugDepth("Rebuild"); var rebuildLock = RebuildLock(); return(Task.Run(() => { using (new CenterAndHeightMaintainer(this)) { bool valuesChanged = false; var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged); var nameToWrite = NameToWrite.Value(this); if (string.IsNullOrWhiteSpace(nameToWrite)) { Mesh = PlatonicSolids.CreateCube(20, 10, height); } else { Mesh = null; this.Children.Modify(list => { list.Clear(); var offest = 0.0; double pointsToMm = 0.352778; foreach (var letter in nameToWrite.ToCharArray()) { var style = new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), PointSize.Value(this)); var letterPrinter = new TypeFacePrinter(letter.ToString(), style) { ResolutionScale = 10 }; var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm)); list.Add(new Object3D() { Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height.Value(this)), Matrix = Matrix4X4.CreateTranslation(offest, 0, 0), Name = letter.ToString() }); offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm; } }); } } UiThread.RunOnIdle(() => { rebuildLock.Dispose(); Invalidate(InvalidateType.DisplayValues); Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); }); })); }
public static bool ShowMessageBox(String message, string caption, MessageType messageType = MessageType.OK) { string wrappedMessage = TypeFacePrinter.InsertCRs(message, 350, 12); StyledMessageBox messageBox = new StyledMessageBox(wrappedMessage, caption, messageType, null, 400, 300); bool okClicked = false; messageBox.ClickedOk += (sender, e) => { okClicked = true; }; messageBox.ShowAsSystemWindow(); return(okClicked); }
public TextScrollWidget(List <string> sourceLines) { string pathToFont = StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg")); printer = new TypeFacePrinter("", new StyledTypeFace(TypeFace.LoadFrom(pathToFont), 12)); printer.DrawFromHintedCache = true; this.allSourceLines = sourceLines; this.visibleLines = sourceLines; PrinterOutputCache.Instance.HasChanged.RegisterEvent(RecievedNewLine, ref unregisterEvents); }
public static bool ShowMessageBox(string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType) { string wrappedMessage = TypeFacePrinter.InsertCRs(message, 300, 12); StyledMessageBox messageBox = new StyledMessageBox(wrappedMessage, caption, messageType, extraWidgetsToAdd, 400, 300); bool okClicked = false; messageBox.ClickedOk += (sender, e) => { okClicked = true; }; messageBox.ShowAsSystemWindow(); return(okClicked); }
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); }
public TextScrollWidget(PrinterConfig printer, List <TerminalLine> sourceLines) { this.printer = printer; this.typeFacePrinter = new TypeFacePrinter("", new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), 12)); this.typeFacePrinter.DrawFromHintedCache = true; this.allSourceLines = sourceLines; this.visibleLines = sourceLines.Select(ld => ld.Line).ToList(); // Register listeners printer.TerminalLog.LineAdded += this.TerminalLog_LineAdded; printer.TerminalLog.LogCleared += this.TerminalLog_LogCleared; }
public TextScrollWidget(PrinterConfig printer, TerminalLog terminalLog) { this.printer = printer; this.typeFacePrinter = new TypeFacePrinter("", new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), 12)); this.typeFacePrinter.DrawFromHintedCache = true; this.terminalLog = terminalLog; this.visibleLines = terminalLog.AllLines().ToList(); // Register listeners printer.Connection.TerminalLog.LineAdded += this.TerminalLog_LineAdded; printer.Connection.TerminalLog.LogCleared += this.TerminalLog_LogCleared; }
private void AddCharacterMeshes(string currentText, TypeFacePrinter printer) { int newIndex = asyncMeshGroups.Count; StyledTypeFace typeFace = printer.TypeFaceStyle; for (int i = 0; i < currentText.Length; i++) { string letter = currentText[i].ToString(); TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace); if (CharacterHasMesh(letterPrinter, letter)) { #if true Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2); #else Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2); // this is the code to make rounded tops // convert the letterPrinter to clipper polygons List <List <IntPoint> > insetPoly = VertexSourceToPolygon.CreatePolygons(letterPrinter); // inset them ClipperOffset clipper = new ClipperOffset(); clipper.AddPaths(insetPoly, JoinType.jtMiter, EndType.etClosedPolygon); List <List <IntPoint> > solution = new List <List <IntPoint> >(); clipper.Execute(solution, 5.0); // convert them back into a vertex source // merge both the inset and original vertex sources together // convert the new vertex source into a mesh (trianglulate them) // offset the inner loop in z // create the polygons from the inner loop to a center point so that there is the rest of an approximation of the bubble // make the mesh for the bottom // add the top and bottom together // done #endif asyncMeshGroups.Add(new MeshGroup(textMesh)); PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData(); newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i); asyncPlatingDatas.Add(newMeshInfo); asyncMeshGroupTransforms.Add(ScaleRotateTranslate.Identity()); PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, newIndex, null); ScaleRotateTranslate moved = asyncMeshGroupTransforms[newIndex]; moved.translation *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2)); asyncMeshGroupTransforms[newIndex] = moved; newIndex++; } processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length); } }
public override Task Rebuild() { this.DebugDepth("Rebuild"); var rebuildLock = RebuildLock(); return(ApplicationController.Instance.Tasks.Execute( "Generating Text Meshes".Localize(), null, (reporter, cancellationToken) => { using (new CenterAndHeightMaintainer(this)) { if (string.IsNullOrWhiteSpace(NameToWrite)) { Mesh = PlatonicSolids.CreateCube(20, 10, Height); } else { Mesh = null; this.Children.Modify(list => { list.Clear(); var offest = 0.0; double pointsToMm = 0.352778; foreach (var letter in this.NameToWrite.ToCharArray()) { var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), this.PointSize)) { ResolutionScale = 10 }; var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm)); list.Add(new Object3D() { Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height), Matrix = Matrix4X4.CreateTranslation(offest, 0, 0), Name = letter.ToString() }); offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm; } }); } } rebuildLock.Dispose(); Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; })); }
public void AddTextField(string instructionsText, int pixelsFromLast) { GuiWidget spacer = new GuiWidget(10, pixelsFromLast); topToBottomControls.AddChild(spacer); string wrappedInstructions = TypeFacePrinter.InsertCRs(instructionsText, 400, 12); string wrappedInstructionsTabsToSpaces = wrappedInstructions.Replace("\t", " "); TextWidget instructionsWidget = new TextWidget(wrappedInstructionsTabsToSpaces, textColor: RGBA_Bytes.White); instructionsWidget.HAnchor = Agg.UI.HAnchor.ParentCenter; topToBottomControls.AddChild(instructionsWidget); }
public void DrawString(string text, Font font, Brush brush, float x, float y) { // TODO: handle different brushes // TODO: emulate GDI "bordering" of text? SolidBrush colorBrush = brush as SolidBrush; var s1 = new TypeFacePrinter(text, font.SizeInPoints, new MatterHackers.VectorMath.Vector2(0, 0), Justification.Left, Baseline.BoundsTop); var s2 = new VertexSourceApplyTransform(s1, Affine.NewScaling(1, -1)); if (x != 0.0f || y != 0.0f) { s2 = new VertexSourceApplyTransform(s2, Affine.NewTranslation(x, y)); } _InternalRender(s2, new RGBA_Bytes((uint)colorBrush.Color.ToArgb())); }
public void DrawString(string text, Font font, TypeFace typeFace, Brush brush, float x, float y, Justification justification = Justification.Left, Baseline baseline = Baseline.BoundsTop) { SolidBrush colorBrush = brush as SolidBrush; //var s1 = new TypeFacePrinter (text, font.SizeInPoints, new MatterHackers.VectorMath.Vector2 (0, 0), Justification.Left, Baseline.BoundsTop); var s1 = new TypeFacePrinter(text, new StyledTypeFace(typeFace, font.SizeInPoints, font.Underline), new MatterHackers.VectorMath.Vector2(0, 0), justification, baseline); var s2 = new VertexSourceApplyTransform(s1, Affine.NewScaling(1, -1)); if (x != 0.0f || y != 0.0f) { s2 = new VertexSourceApplyTransform(s2, Affine.NewTranslation(x, y)); } _InternalRender(s2, new RGBA_Bytes((uint)colorBrush.Color.ToArgb())); }
public override Task Rebuild() { this.DebugDepth("Rebuild"); var rebuildLock = RebuildLock(); return(ApplicationController.Instance.Tasks.Execute( "Mirror".Localize(), null, (reporter, cancellationToken) => { using (new CenterAndHeightMantainer(this)) { this.Children.Modify((List <IObject3D> list) => { list.Clear(); var offest = 0.0; double pointsToMm = 0.352778; foreach (var letter in NameToWrite.ToCharArray()) { var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), PointSize)) { ResolutionScale = 10 }; var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm)); IObject3D letterObject = new Object3D() { Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, Height) }; letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0); list.Add(letterObject); offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm; } }); } rebuildLock.Dispose(); Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; })); }
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); }
private void Rebuild(UndoBuffer undoBuffer) { this.DebugDepth("Rebuild"); using (RebuildLock()) { var aabb = this.GetAxisAlignedBoundingBox(); this.Children.Modify((list) => { list.Clear(); var offest = 0.0; double pointsToMm = 0.352778; foreach (var letter in NameToWrite.ToCharArray()) { var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), PointSize)) { ResolutionScale = 10 }; var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm)); IObject3D letterObject = new Object3D() { Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, Height) }; letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0); list.Add(letterObject); offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm; } }); if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); } } Invalidate(new InvalidateArgs(this, InvalidateType.Content)); }