protected override void Initialize(DemoConfiguration demoConfiguration) { base.Initialize(demoConfiguration); // Initialize a TextFormat TextFormat = new TextFormat(FactoryDWrite, "Calibri", 128) {TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center}; RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype; // Initialize a TextLayout TextLayout = new TextLayout(FactoryDWrite, "SharpDX D2D1 - DWrite", TextFormat, demoConfiguration.Width, demoConfiguration.Height); }
public FpsDxLayer(D2D.RenderTarget renderTarget, DxLoadObject settings, OsuModel osuModel) : base(renderTarget, settings, osuModel) { _whiteBrush = new D2D.SolidColorBrush(RenderTarget, new Mathe.RawColor4(1, 1, 1, 1)); _textFormat = new DW.TextFormat(_factoryWrite, "Microsoft YaHei", 12); _bufferSw = new Stopwatch(); _bufferSw.Start(); }
public TextLayoutParameters( DWrite.Factory factory, string name, float pointSize, bool bold, bool italic, bool underline, bool strikeout, Size2F dpi) { this.FontName = name; this.PointSize = pointSize; this.DipSize = Helpers.GetFontSize(pointSize); this.Weight = bold ? DWrite.FontWeight.Bold : DWrite.FontWeight.Normal; this.Style = italic ? DWrite.FontStyle.Italic : DWrite.FontStyle.Normal; this.Underline = underline; this.StrikeOut = strikeout; using (var textFormat = new DWrite.TextFormat(factory, this.FontName, this.Weight, this.Style, this.DipSize)) using (var textLayout = new DWrite.TextLayout(factory, "A", textFormat, 1000, 1000)) { this.LineHeight = Helpers.AlignToPixel(textLayout.Metrics.Height, dpi.Height); this.CharWidth = Helpers.AlignToPixel(textLayout.OverhangMetrics.Left + (1000 + textLayout.OverhangMetrics.Right), dpi.Width); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); // Direct2D var renderTargetProperties = new RenderTargetProperties() { PixelFormat = new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Ignore) }; var hwndRenderTargetProperties = new HwndRenderTargetProperties() { Hwnd = this.Handle, PixelSize = new Size2(bounds.Width, bounds.Height), PresentOptions = PresentOptions.Immediately, }; renderTarget = new WindowRenderTarget(factory, renderTargetProperties, hwndRenderTargetProperties); var bitmapProperties = new BitmapProperties() { PixelFormat = new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Ignore) }; bitmap = new SharpDX.Direct2D1.Bitmap(renderTarget, new Size2(bounds.Width, bounds.Height), bitmapProperties); textFormat = new TextFormat(directWriteFacrtory, "Arial", FontWeight.Normal, SharpDX.DirectWrite.FontStyle.Normal, 96.0f); textFormat.ParagraphAlignment = ParagraphAlignment.Center; textFormat.TextAlignment = TextAlignment.Center; solidColorBrush = new SolidColorBrush(renderTarget, Color4.White); }
public FormattedTextImpl( string text, string fontFamily, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight, TextWrapping wrapping) { var factory = AvaloniaLocator.Current.GetService <DWrite.Factory>(); using (var format = new DWrite.TextFormat( factory, fontFamily, (DWrite.FontWeight)fontWeight, (DWrite.FontStyle)fontStyle, (float)fontSize)) { format.WordWrapping = wrapping == TextWrapping.Wrap ? DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap; TextLayout = new DWrite.TextLayout( factory, text ?? string.Empty, format, float.MaxValue, float.MaxValue); } TextLayout.TextAlignment = textAlignment.ToDirect2D(); }
public virtual void Initialize(DeviceManager deviceManager) { sceneColorBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Color.Blue); textFormat = new TextFormat(deviceManager.FactoryDirectWrite, "Calibri", 20) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Center }; clock = Stopwatch.StartNew(); deviceManager.ContextDirect2D.TextAntialiasMode = TextAntialiasMode.Grayscale; }
public FormattedTextImpl( string text, string fontFamily, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { var factory = Locator.Current.GetService<DWrite.Factory>(); var format = new DWrite.TextFormat( factory, fontFamily, (DWrite.FontWeight)fontWeight, (DWrite.FontStyle)fontStyle, (float)fontSize); TextLayout = new DWrite.TextLayout( factory, text ?? string.Empty, format, float.MaxValue, float.MaxValue); TextLayout.TextAlignment = textAlignment.ToDirect2D(); }
public MenuItem(Theme theme, TextFormat font, float x, float y, float width, float height, Menu parentMenu, string text, string extraData) : base(theme, font, x, y, width, height) { this.parentMenu = parentMenu; this.Text = text; this.extraData = extraData; }
public static void WatermarkText(Stream imageStream, Stream outputStream, string watermark, string font = "Times New Roman", float fontSize = 30.0f, int colorARGB = TransparentWhite) { using (var wic = new WIC.ImagingFactory2()) using (var d2d = new D2D.Factory()) using (var image = CreateWicImage(wic, imageStream)) using (var wicBitmap = new WIC.Bitmap(wic, image.Size.Width, image.Size.Height, WIC.PixelFormat.Format32bppPBGRA, WIC.BitmapCreateCacheOption.CacheOnDemand)) using (var target = new D2D.WicRenderTarget(d2d, wicBitmap, new D2D.RenderTargetProperties())) using (var bmpPicture = D2D.Bitmap.FromWicBitmap(target, image)) using (var dwriteFactory = new DWrite.Factory()) using (var brush = new D2D.SolidColorBrush(target, new Color(colorARGB))) { target.BeginDraw(); { target.DrawBitmap(bmpPicture, new RectangleF(0, 0, target.Size.Width, target.Size.Height), 1.0f, D2D.BitmapInterpolationMode.Linear); target.DrawRectangle(new RectangleF(0, 0, target.Size.Width, target.Size.Height), brush); var textFormat = new DWrite.TextFormat(dwriteFactory, font, DWrite.FontWeight.Bold, DWrite.FontStyle.Normal, fontSize) { ParagraphAlignment = DWrite.ParagraphAlignment.Far, TextAlignment = DWrite.TextAlignment.Trailing, }; target.DrawText(watermark, textFormat, new RectangleF(0, 0, target.Size.Width, target.Size.Height), brush); } target.EndDraw(); SaveD2DBitmap(wic, wicBitmap, outputStream); } }
public Radar(CSGOTheme theme, TextFormat font, float resolution) : base(theme, font) { this.Width = 256f; this.Height = 256f; this.dotSize = 6f; this.viewX = 24f; this.viewY = 48f; }
public FormattedTextImpl( string text, string fontFamily, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight, TextWrapping wrapping) { var factory = AvaloniaLocator.Current.GetService<DWrite.Factory>(); using (var format = new DWrite.TextFormat( factory, fontFamily, (DWrite.FontWeight)fontWeight, (DWrite.FontStyle)fontStyle, (float)fontSize)) { format.WordWrapping = wrapping == TextWrapping.Wrap ? DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap; TextLayout = new DWrite.TextLayout( factory, text ?? string.Empty, format, float.MaxValue, float.MaxValue); } TextLayout.TextAlignment = textAlignment.ToDirect2D(); }
public FormattedTextImpl( string text, string fontFamily, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { var factory = PerspexLocator.Current.GetService <DWrite.Factory>(); using (var format = new DWrite.TextFormat( factory, fontFamily, (DWrite.FontWeight)fontWeight, (DWrite.FontStyle)fontStyle, (float)fontSize)) { TextLayout = new DWrite.TextLayout( factory, text ?? string.Empty, format, float.MaxValue, float.MaxValue); } TextLayout.TextAlignment = textAlignment.ToDirect2D(); }
public DrawableText(string t, string name, float size, DeviceContext DC) : base(DC) { text += t; wfactory = new SharpDX.DirectWrite.Factory(); wformat = new SharpDX.DirectWrite.TextFormat(wfactory, name, size); this.AddUpdateProcess(() => { drawtime += 1; if (drawtime > 60) { drawtime = 0; } int fpt = 60 / Speed; if (bufferChars.Count != 0 && drawtime % fpt == 0) { text += bufferChars[0]; bufferChars.RemoveAt(0); } return(true); }); }
public Label(Theme theme, TextFormat font, float x, float y, float width, float height, string text) : base(theme, font, x, y, width, height) { this.Text = text; this.align = HorizontalAlign.Left; this.castShadow = false; }
public ListPanel(Theme theme, TextFormat font, float x, float y, float width, float height, float paddingX, float paddingY, float spaceY) : base(theme, font, x, y, width, height) { this.paddingX = paddingX; this.paddingY = paddingY; this.spaceY = spaceY; }
public InfoText(SharpDX.Direct3D11.Device device, int width, int height) { _immediateContext = device.ImmediateContext; _rect.Size = new Size2F(width, height); _bitmapSize = width * height * 4; IsEnabled = true; using (var factoryWic = new SharpDX.WIC.ImagingFactory()) { _wicBitmap = new SharpDX.WIC.Bitmap(factoryWic, width, height, _pixelFormat, SharpDX.WIC.BitmapCreateCacheOption.CacheOnLoad); } var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default, new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None, SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT); using (var factory2D = new SharpDX.Direct2D1.Factory()) { _wicRenderTarget = new WicRenderTarget(factory2D, _wicBitmap, renderTargetProperties); _wicRenderTarget.TextAntialiasMode = TextAntialiasMode.Default; } using (var factoryDWrite = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared)) { _textFormat = new TextFormat(factoryDWrite, "Tahoma", 20); } Color4 color = new Color4(1, 1, 1, 1); _sceneColorBrush = new SolidColorBrush(_wicRenderTarget, color); _clearColor = color; _clearColor.Alpha = 0; _renderTexture = new Texture2D(device, new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, Format = Format.R8G8B8A8_UNorm, Height = height, Width = width, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Dynamic }); OverlayBufferRes = new ShaderResourceView(device, _renderTexture, new ShaderResourceViewDescription() { Format = _renderTexture.Description.Format, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource() { MipLevels = 1, MostDetailedMip = 0 } }); }
public FpsLayer(D2D.RenderTarget renderTarget) : base(renderTarget) { _whiteBrush = new D2D.SolidColorBrush(RenderTarget, new Mathe.RawColor4(1, 1, 1, 1)); _blackBrush = new D2D.SolidColorBrush(RenderTarget, new Mathe.RawColor4(0, 0, 0, 1)); _textFormat = new DW.TextFormat(_factoryWrite, "Microsoft YaHei", 12); _bufferSw = new Stopwatch(); _bufferSw.Start(); }
//public static Brush TEXT_BRUSH; public static void Initialize(RenderTarget g) { SCBRUSH_RED = new SolidColorBrush(g, Color.Red); SCBRUSH_BLACK = new SolidColorBrush(g, Color.Black); WRITE_FACTORY = new SharpDX.DirectWrite.Factory(); TEXT_FORMAT = new TextFormat(WRITE_FACTORY, "Arial", 14); //TEXT_BRUSH = new SolidColorBrush(g, Color.Red); }
public ProgressBar(ProgressBarTheme theme, TextFormat font, float x, float y, float width, float height, float value, float maxValue, bool blinkingEnabled, float blinkingThreshold) : base(theme, font, x, y, width, height) { this.currValue = value; this.maxValue = maxValue; this.blinkingEnabled = blinkingEnabled; this.blinkingThreshold = blinkingThreshold; }
public KeyMenuItem(Theme theme, TextFormat font, float x, float y, float width, float height, Menu parentMenu, string text, string extraData, Keys key) : base(theme, font, x, y, width, height, parentMenu, text, extraData) { this.Key = key; this.acceptKey = false; if (Program.GameImplementation.HasKey(this.ExtraData)) this.Key = Program.GameImplementation.GetValue<Keys>(this.ExtraData); }
public TextButton(UIElement parent, string name, RawRectangleF bounds, string text, DWrite.TextFormat textFormat, D2D1.Brush brush1, D2D1.Brush brush2, Action action) : base(parent, name, bounds) { Text = text; TextFormat = textFormat; Brush1 = brush1; Brush2 = brush2; Click = action; }
/// <summary> /// Initializes the specified device local. /// </summary> /// <param name="resource">The resource.</param> protected virtual void Initialize(SharpDX.DirectWrite.TextFormat resource) { Resource = ToDispose(resource); if (resource != null) { resource.Tag = this; } IsInited = true; }
DW.TextLayout createTextLayout(string text, DW.TextFormat format, double width, double height) { var layout = new DW.TextLayout(requireWriteFactory(), text, format, width.import(), height.import()); layout.TextAlignment = _state.TextAlignment.import(); layout.ParagraphAlignment = _state.ParagraphAlignment.import(); layout.WordWrapping = _state.WordWrapping.import(); return(layout); }
protected override void InitializeDirectXResources() { base.InitializeDirectXResources(); _textFormat = new DW.TextFormat(DwFactory, "Arial", DW.FontWeight.Bold, DW.FontStyle.Normal, DW.FontStretch.Normal, 84 * (float)GraphicsUtils.Scale) { TextAlignment = DW.TextAlignment.Center, ParagraphAlignment = DW.ParagraphAlignment.Center }; }
public TrackbarMenuItem(Theme theme, TextFormat font, float x, float y, float width, float height, Menu parentMenu, string text, float min, float max, float step, float value, string extraData) : base(theme, font, x, y, width, height, parentMenu, text, extraData) { this.minimum = min; this.maximum = max; this.value = value; this.step = step; if (Program.GameImplementation.HasKey(this.ExtraData)) this.value = Program.GameImplementation.GetValue<float>(this.ExtraData); }
public EngineInfoDrawer(RenderTarget renderTarget) { var factory = new DW.Factory(DW.FactoryType.Shared); defaultBrush = new SolidColorBrush(renderTarget, Color.Black); defaultTextFormat = new TextFormat(factory, "Microsoft Yahei Mono", FONT_SIZE); defaultRectangleFList = new RectangleF[MAX_ROW_COUNT]; for (int i = 0; i < MAX_ROW_COUNT; i++) { defaultRectangleFList[i] = new RectangleF(0, i * FONT_SIZE, ROW_WEIGHT, FONT_SIZE); } }
protected override void Dispose(bool disposing) { if (textFormat != null) { textFormat.Dispose(); textFormat = null; } base.Dispose(disposing); }
private void InitFont() { var directWriteFactory = new SharpDX.DirectWrite.Factory(); _directWriteTextFormat = new SharpDX.DirectWrite.TextFormat(directWriteFactory, _fontName, _fontSize) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near }; _directWriteFontColor = new SharpDX.Direct2D1.SolidColorBrush(_direct2DRenderTarget, _fontColor); directWriteFactory.Dispose(); }
private void Create(string familyName, float sizeInPoints, FontStyle style) { // family name this.familyName = familyName; // font style this.style = style; sw.FontStyle s; sw.FontWeight w; Conversions.Convert(style, out s, out w); this.textFormat = new sw.TextFormat( Factory, familyName, null, // font collection w, s, sw.FontStretch.Normal, sizeInPoints, // TODO: should this be in pixels? The documentation says device-independent pixels. "en-us"); // Create a font collection var collection = FontCollection(); int index = 0; if (collection.FindFamilyName( familyName: familyName, index: out index)) { // font family var fontFamily = collection.GetFontFamily(index); Conversions.Convert( style, out fontStyle, out fontWeight); // font this.Control = fontFamily.GetFirstMatchingFont( fontWeight, sw.FontStretch.Normal, fontStyle); // finally, the font face this.fontFace = new sw.FontFace(Control); } }
public DWrite.TextFormat this[float fontSize, string fontFamilyName = "Consolas"] { get { var key = $"{fontFamilyName}:{fontSize}"; if (!formatMap.ContainsKey(key)) { formatMap[key] = new DWrite.TextFormat(_factory, fontFamilyName, fontSize); } return(formatMap[key]); } }
public Menu(Theme theme, Theme themeSelected, Theme themeUnselected, TextFormat font, TextFormat fontCaption, float x, float y, float width, float height, string caption, float paddingX, float paddingY, float spacingY, bool fixedPosition) : base(theme, font, x, y, width, height, paddingX, paddingY, spacingY) { //themeUnselected = new Theme(Theme.ForeColor * 0.9f, Theme.BackColor * 0.9f, Theme.ForeColor * 0.9f, Color.Transparent, 0f, 0f); //themeSelected = new Theme(Theme.ForeColor * 1.1f, Theme.BackColor * 1.1f, Theme.ForeColor * 1.1f, Color.Transparent, 0f, 0f); this.themeSelected = themeSelected; this.themeUnselected = themeUnselected; this.fontCaption = fontCaption; lblCaption = new Label(theme, fontCaption, 0, 0, width, 20f, caption); this.menuItemIndex = 1; this.AddChildControl(lblCaption); this.fixedPosition = fixedPosition; }
private void Update(bool updateForce = false) { if (isUpdated || updateForce) { isUpdated = false; tFormat?.Dispose(); tFormat = CreateTextFormat(this.Font); foregroundBrush?.Dispose(); foregroundBrush = new d2.SolidColorBrush(Renderer.Device, Foreground.ToColor4()); } }
protected override void Initialize(DemoConfiguration demoConfiguration) { base.Initialize(demoConfiguration); // Initialize a TextFormat TextFormat = new TextFormat(FactoryDWrite, "Gabriola", 96) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }; RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype; ClientRectangle = new RectangleF(0, 0, demoConfiguration.Width, demoConfiguration.Height); SceneColorBrush.Color = Color.Black; }
private void DrawText(string text, float locX, float locY, D2D1.Brush fg, D2D1.Brush bg, string font = "", float size = 0) { using (TextFormat = new DW.TextFormat(DWFactory, font == "" ? Config.CooldownBarTextFont : font, size == 0 ? Config.CooldownBarTextFontSize : size)) { TextFormat.WordWrapping = DW.WordWrapping.NoWrap; using (DW.TextLayout TextLayout = new DW.TextLayout(DWFactory, text, TextFormat, 500, 500)) { using (TextBrush = new TextBrush(fg, bg)) { using (TextRenderer = new TextRenderer(Render, TextBrush)) { TextLayout.SetDrawingEffect(TextBrush, new DW.TextRange(10, 20)); TextLayout.Draw(TextRenderer, locX, locY); } } } } }
public Control(Theme theme, TextFormat font, float x, float y, float width, float height, bool visible, bool enabled) { this.x = x; this.y = y; this.width = width; this.height = height; this.theme = theme; this.font = font; this.childControls = new List<Control>(); this.Parent = null; this.visible = visible; this.enabled = enabled; this.autoSize = true; }
public Clock(Size clientSize) { ClientSize = clientSize; g_center = new PointF(ClientSize.Width / 2f, ClientSize.Height / 2f); // Create brushes blueBrush1 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.3f, 0.4f, 0.9f, 1)); blueBrush2 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.45f, 0.6f, 0.95f, 1)); blueBrush3 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.6f, 0.8f, 1f, 1)); whiteBrush = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(1f, 1f, 1f, 0.5f)); redBrush = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.99f, 0.16f, 0.3f, 0.7f)); // Create ellipses ellipseCentre = new D2D.Ellipse(new Mathe.RawVector2(g_center.X, g_center.Y), 120, 120); // Create text formats textFormat = new DW.TextFormat(RenderForm.FactoryWrite, "Berlin Sans FB", 36); strokeProperties = new D2D.StrokeStyleProperties { StartCap = D2D.CapStyle.Round, EndCap = D2D.CapStyle.Triangle }; strokeStyle = new D2D.StrokeStyle(RenderForm.Factory, strokeProperties); strokeProperties2 = new D2D.StrokeStyleProperties { StartCap = D2D.CapStyle.Round, EndCap = D2D.CapStyle.Round, DashStyle = D2D.DashStyle.Dash }; strokeStyle2 = new D2D.StrokeStyle(RenderForm.Factory, strokeProperties2); int len = 110; for (int i = 0; i < 60; i++) { int r = i % 5 == 0 ? 10 : 5; float deg, rad; deg = (i / 60f * 360 - 90); rad = deg / 180 * (float)Math.PI; lim[i] = new PointF(g_center.X + (float)Math.Cos(rad) * (len - r), g_center.Y + (float)Math.Sin(rad) * (len - r)); lim2[i] = new PointF(g_center.X + (float)Math.Cos(rad) * (len), g_center.Y + (float)Math.Sin(rad) * (len)); } sw = new Stopwatch(); sw.Start(); }
public D2D.GeometryRealization CreateSymbol(ShowSymbol sym, DW.TextFormat format) { D2D.GeometryRealization cached_geo = null; bool result = symbol_cache.TryGetValue(sym, out cached_geo); if (!result) { const int margin = 2; D2D.Geometry geo = null; DW.TextLayout layout = null; D2D.PathGeometry path = null; DW.TextMetrics metrics; D2D.StrokeStyle stroke = null; switch (sym) { case ShowSymbol.FullSpace: layout = new DW.TextLayout(this._DWFactory, " ", format, float.MaxValue, float.MaxValue); metrics = layout.Metrics; Rectangle rect = new Rectangle(margin, margin, Math.Max(1, metrics.WidthIncludingTrailingWhitespace - margin * 2), Math.Max(1, metrics.Height - margin * 2)); geo = new D2D.RectangleGeometry(this.Factory, rect); stroke = this.GetStroke(HilightType.Dash); break; case ShowSymbol.HalfSpace: layout = new DW.TextLayout(this._DWFactory, " ", format, float.MaxValue, float.MaxValue); metrics = layout.Metrics; rect = new Rectangle(margin, margin, Math.Max(1, metrics.WidthIncludingTrailingWhitespace - margin * 2), Math.Max(1, metrics.Height - margin * 2)); geo = new D2D.RectangleGeometry(this.Factory, rect); stroke = this.GetStroke(HilightType.Sold); break; case ShowSymbol.Tab: layout = new DW.TextLayout(this._DWFactory, "0", format, float.MaxValue, float.MaxValue); metrics = layout.Metrics; path = new D2D.PathGeometry(this.Factory); var sink = path.Open(); sink.BeginFigure(new SharpDX.Mathematics.Interop.RawVector2(1, 1), D2D.FigureBegin.Filled); //少し隙間を開けないと描写されない sink.AddLine(new SharpDX.Mathematics.Interop.RawVector2((float)1, (float)metrics.Height)); sink.EndFigure(D2D.FigureEnd.Closed); sink.Close(); geo = path; stroke = this.GetStroke(HilightType.Sold); break; } cached_geo = new D2D.GeometryRealization(this.Device, geo, 1.0f, 1.0f, stroke); this.symbol_cache.Add(sym, cached_geo); } return(cached_geo); }
private void PlatformConstruct(GraphicsDevice2D graphicsDevice, string fontFamily, float fontSize, FontWeight fontWeight, TextAlignment alignment) { DeviceTextFormat = AddDisposable(new DW.TextFormat( graphicsDevice.DirectWriteFactory, fontFamily, ToDirectWriteFontWeight(fontWeight), DW.FontStyle.Normal, DW.FontStretch.Normal, fontSize)); DeviceTextFormat.TextAlignment = ToDirectWriteTextAlignment(alignment); // TODO: Make this configurable. DeviceTextFormat.ParagraphAlignment = DW.ParagraphAlignment.Center; }
protected override void InitializeDirectXResources() { base.InitializeDirectXResources(); _textFormat = new DW.TextFormat(DwFactory, "Arial", DW.FontWeight.Bold, DW.FontStyle.Normal, DW.FontStretch.Normal, 84 * (float)GraphicsUtils.Scale) { TextAlignment = DW.TextAlignment.Center, ParagraphAlignment = DW.ParagraphAlignment.Center }; var clientSize = ClientSize; var fixationSize = _experiment.Config.Gui.FixationPoint.Size; _fixationPoint = new D2D1.Ellipse(new RawVector2(clientSize.Width / 2F, clientSize.Height / 2F), fixationSize, fixationSize); }
public override void DrawText(string str, PBrush brush, RectangleF rect, float size) { float sizept = Util.MmToPoint(size); float px = Util.MmToPoint(rect.X); float py = Util.MmToPoint(rect.Y); float pw = Util.MmToPoint(rect.Width); float ph = Util.MmToPoint(rect.Height); RawRectangleF rectpt = new RawRectangleF(px, py, pw, ph); text.TextFormat format = new text.TextFormat(writeFactory, "Arial", sizept); using (Brush b = GetBrush(brush)) { renderTarget.DrawText(str, format, rectpt, b, DrawTextOptions.None, MeasuringMode.GdiNatural); } }
public ValueMenuItem(Theme theme, TextFormat font, float x, float y, float width, float height, Menu parentMenu, string text, string extraData, object[] options, int selectedOption) : base(theme, font, x, y, width, height, parentMenu, text, extraData) { this.options = options; if (Program.GameImplementation.HasKey(this.ExtraData)) { for (int i = 0; i < this.Options.Length; i++) if (this.options[i] == Program.GameImplementation.GetValue(this.ExtraData)) this.CurrentOptionIndex = i; } else { this.CurrentOptionIndex = selectedOption; } }
protected override void Dispose(bool disposing) { if (this.textFormat != null) { this.textFormat.Dispose(); this.textFormat = null; } if (this.fontFace != null) { this.fontFace.Dispose(); this.fontFace = null; } base.Dispose(disposing); }
public override void DrawText(string text, PointF pos, float size, gdi.Color c) { float sizept = Util.MmToPoint(size); float px = Util.MmToPoint(pos.X); float py = Util.MmToPoint(pos.Y); float pw = Util.MmToPoint(1000); float ph = Util.MmToPoint(1000); RawRectangleF rectpt = new RawRectangleF(px, py, pw, ph); using (SolidColorBrush brush = new SolidColorBrush(renderTarget, c.ToColor4())) { text.TextFormat format = new text.TextFormat(writeFactory, "Arial", sizept); renderTarget.DrawText(text, format, rectpt, brush); format.Dispose(); } }
protected override void Initialize(GameConfiguration gameConfiguration) { base.Initialize(gameConfiguration); // Initialize a TextFormat Components.Add(ScreenManager = new ScreenManager(this)); ScreenManager.ToggleScreen(new GameScreen(this)); // Initialize a TextFormat TextFormat = new TextFormat(FactoryDWrite, "微软雅黑", 128) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }; RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype; // Initialize a TextLayout TextLayout = new TextLayout(FactoryDWrite, "编程棋 Alpha 0", TextFormat, gameConfiguration.Width, gameConfiguration.Height); }
public Direct2D1FormattedText(string text, Typeface typeface, double fontSize) { Factory factory = ((Direct2D1PlatformInterface)PlatformInterface.Instance).DirectWriteFactory; TextFormat format = new TextFormat( factory, typeface.FontFamily.Source, (float)fontSize); this.DirectWriteTextLayout = new TextLayout( factory, text ?? string.Empty, format, float.MaxValue, float.MaxValue); }
public FormattedTextImpl( string text, Typeface typeface, double fontSize, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList <FormattedTextStyleSpan> spans) { Text = text; var font = ((GlyphTypefaceImpl)typeface.GlyphTypeface.PlatformImpl).DWFont; var familyName = font.FontFamily.FamilyNames.GetString(0); using (var textFormat = new DWrite.TextFormat( Direct2D1Platform.DirectWriteFactory, familyName, font.FontFamily.FontCollection, (DWrite.FontWeight)typeface.Weight, (DWrite.FontStyle)typeface.Style, DWrite.FontStretch.Normal, (float)fontSize)) { textFormat.WordWrapping = wrapping == TextWrapping.Wrap ? DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap; TextLayout = new DWrite.TextLayout( Direct2D1Platform.DirectWriteFactory, Text ?? string.Empty, textFormat, (float)constraint.Width, (float)constraint.Height) { TextAlignment = textAlignment.ToDirect2D() }; } if (spans != null) { foreach (var span in spans) { ApplySpan(span); } } Bounds = Measure(); }
private void InitializeDirectXResources() { var clientSize = ClientSize; var backBufferDesc = new DXGI.ModeDescription(clientSize.Width, clientSize.Height, new DXGI.Rational(60, 1), DXGI.Format.R8G8B8A8_UNorm); var swapChainDesc = new DXGI.SwapChainDescription() { ModeDescription = backBufferDesc, SampleDescription = new DXGI.SampleDescription(1, 0), Usage = DXGI.Usage.RenderTargetOutput, BufferCount = 1, OutputHandle = Handle, SwapEffect = DXGI.SwapEffect.Discard, IsWindowed = false }; D3D11.Device.CreateWithSwapChain(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport, new[] { D3D.FeatureLevel.Level_10_0 }, swapChainDesc, out _d3DDevice, out var swapChain); _d3DDeviceContext = _d3DDevice.ImmediateContext; _swapChain = new DXGI.SwapChain1(swapChain.NativePointer); _d2DFactory = new D2D1.Factory(); using (var backBuffer = _swapChain.GetBackBuffer <D3D11.Texture2D>(0)) { _renderTargetView = new D3D11.RenderTargetView(_d3DDevice, backBuffer); _renderTarget = new D2D1.RenderTarget(_d2DFactory, backBuffer.QueryInterface <DXGI.Surface>(), new D2D1.RenderTargetProperties(new D2D1.PixelFormat(DXGI.Format.Unknown, D2D1.AlphaMode.Premultiplied))) { TextAntialiasMode = D2D1.TextAntialiasMode.Cleartype }; } _solidColorBrush = new D2D1.SolidColorBrush(_renderTarget, Color.White); _dwFactory = new DW.Factory(DW.FactoryType.Shared); _textFormat = new DW.TextFormat(_dwFactory, "Arial", DW.FontWeight.Bold, DW.FontStyle.Normal, DW.FontStretch.Normal, 84 * (float)GraphicsUtils.Scale) { TextAlignment = DW.TextAlignment.Center, ParagraphAlignment = DW.ParagraphAlignment.Center }; _bitmap = _paradigm.Config.Gui.UseBitmap ? Properties.Resources.Einstein.ToD2D1Bitmap(_renderTarget) : null; }
public virtual void Initialize(DeviceManager deviceManager) { TouchCapabilities = new Windows.Devices.Input.TouchCapabilities(); // Initialize a TextFormat textFormat = new TextFormat(deviceManager.FactoryDirectWrite, "Calibri", 20) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }; textFormat2 = new TextFormat(deviceManager.FactoryDirectWrite, "Calibri", 20) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Center }; sceneColorBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Color.Tomato); strokeProperties = new StrokeStyleProperties(); strokeProperties.StartCap = CapStyle.Round; strokeProperties.EndCap = CapStyle.Round; strokeProperties.LineJoin = LineJoin.Round; strokeStyle = new StrokeStyle(deviceManager.FactoryDirect2D, strokeProperties); }
/// <summary> /// Initializes a new instance of the <see cref="TitleControl"/> class. /// </summary> /// <param name="parent">The parent control.</param> public TitleControl(IElement parent) : base(parent) { this.textFormat = new DWrite.TextFormat(this.dwriteFactory, "Segoe UI", Helpers.GetFontSize(10)); this.textFormat.ParagraphAlignment = DWrite.ParagraphAlignment.Center; this.textFormat.TextAlignment = DWrite.TextAlignment.Trailing; this.textFormat.WordWrapping = DWrite.WordWrapping.NoWrap; var sign = new DWrite.EllipsisTrimming(this.dwriteFactory, this.textFormat); this.textFormat.SetTrimming(new DWrite.Trimming() { Granularity = DWrite.TrimmingGranularity.Character, Delimiter = 0, DelimiterCount = 0 }, sign); sign.Dispose(); this.Color = new RawColor4(1, 1, 1, 1); }
static void Main() { using (var window = new LayeredRenderWindow() { Text = "Hello World", DragMoveEnabled = true }) { var bottomRightFont = new DWrite.TextFormat(window.XResource.DWriteFactory, "Consolas", 16.0f) { FlowDirection = DWrite.FlowDirection.BottomToTop, TextAlignment = DWrite.TextAlignment.Trailing, }; var bottomLeftFont = new DWrite.TextFormat(window.XResource.DWriteFactory, "Consolas", DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, 24.0f) { FlowDirection = DWrite.FlowDirection.BottomToTop, TextAlignment = DWrite.TextAlignment.Leading, }; window.Draw += Draw; RenderLoop.Run(window, () => window.Render(1, 0)); void Draw(RenderWindow _, Direct2D.DeviceContext target) { XResource res = window.XResource; target.Clear(Color.Transparent); RectangleF rectangle = new RectangleF(0, 0, target.Size.Width, target.Size.Height); target.DrawRectangle( rectangle, res.GetColor(Color.Blue)); target.DrawText("😀😁😂🤣😃😄😅😆😉😊😋😎", res.TextFormats[36], rectangle, res.GetColor(Color.Blue), Direct2D.DrawTextOptions.EnableColorFont); target.DrawText($"{window.XResource.DurationSinceStart:mm':'ss'.'ff}\nFPS: {window.RenderTimer.FramesPerSecond:F1}", bottomRightFont, rectangle, res.GetColor(Color.Red)); target.DrawText("Hello World", bottomLeftFont, rectangle, res.GetColor(Color.Purple)); } } }
internal static async Task Render(CompositionEngine compositionEngine, RenderTarget renderTarget, FrameworkElement rootElement, TextBlock textBlock) { using (var textFormat = new TextFormat( compositionEngine.DWriteFactory, textBlock.FontFamily.Source, (float)textBlock.FontSize) { TextAlignment = textBlock.TextAlignment.ToSharpDX(), ParagraphAlignment = ParagraphAlignment.Near }) { var rect = textBlock.GetBoundingRect(rootElement).ToSharpDX(); // For some reason we need a bigger rect for the TextBlock rendering to fit in the same boundaries rect.Right++; rect.Bottom++; using ( var textBrush = await textBlock.Foreground.ToSharpDX(renderTarget, rect)) { if (textBrush == null) { return; } var layer = textBlock.CreateAndPushLayerIfNecessary(renderTarget, rootElement); // You can render the bounding rectangle to debug composition //renderTarget.DrawRectangle( // rect, // textBrush); renderTarget.DrawText( textBlock.Text, textFormat, rect, textBrush); if (layer != null) { renderTarget.PopLayer(); layer.Dispose(); } //} } } }
protected override void InitializeDirectXResources() { base.InitializeDirectXResources(); var guiScale = (float)GraphicsUtils.Scale; _blockTextFormat = new DW.TextFormat(DwFactory, "Arial", _paradigm.Config.Gui.BlockFontSize * guiScale) { TextAlignment = DW.TextAlignment.Center, ParagraphAlignment = DW.ParagraphAlignment.Center }; _cueTextFormat = new DW.TextFormat(DwFactory, "Arial", DW.FontWeight.Bold, DW.FontStyle.Normal, DW.FontStretch.Normal, 84 * guiScale) { TextAlignment = DW.TextAlignment.Center, ParagraphAlignment = DW.ParagraphAlignment.Center }; UpdateResources(); }
internal static async Task Render(CompositionEngine compositionEngine, RenderTarget renderTarget, FrameworkElement rootElement, TextBlock textBlock) { using (var textFormat = new TextFormat( compositionEngine.DWriteFactory, textBlock.FontFamily.Source, (float)textBlock.FontSize) { TextAlignment = textBlock.TextAlignment.ToSharpDX(), ParagraphAlignment = ParagraphAlignment.Near }) { var rect = textBlock.GetBoundingRect(rootElement).ToSharpDX(); // For some reason we need a bigger rect for the TextBlock rendering to fit in the same boundaries rect.Right++; rect.Bottom++; using ( var textBrush = await textBlock.Foreground.ToSharpDX(renderTarget, rect)) { //using(var layer = new Layer(renderTarget)) //{ //var layerParameters = new LayerParameters(); //layerParameters.ContentBounds = rect; //renderTarget.PushLayer(ref layerParameters, layer); // You can render the bounding rectangle to debug composition //renderTarget.DrawRectangle( // rect, // textBrush); renderTarget.DrawText( textBlock.Text, textFormat, rect, textBrush); //renderTarget.PopLayer(); //} } } }
public MainGame() { FactoryDWrite = new SharpDX.DirectWrite.Factory(); TextFormat = new TextFormat(FactoryDWrite, "Arial", 32) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Center }; _scoreApi = new ScoreClient(); }
internal D2dTextFormat(TextFormat textFormat) { if (textFormat == null) throw new ArgumentNullException("textFormat"); m_nativeTextFormat = textFormat; m_ellipsisTrimming = new EllipsisTrimming(D2dFactory.NativeDwFactory, m_nativeTextFormat); m_fontHeight = D2dFactory.FontSizeToPixel(m_nativeTextFormat.FontSize); }
public virtual void Render(TargetBase target) { if (!Show) return; var context2D = target.DeviceManager.ContextDirect2D; context2D.BeginDraw(); if (EnableClear) context2D.Clear(Colors.Black); var sizeX = (float)target.RenderTargetBounds.Width; var sizeY = (float)target.RenderTargetBounds.Height; var globalScaling = Matrix.Scaling(Math.Min(sizeX, sizeY)); var centerX = (float)(target.RenderTargetBounds.X + sizeX / 2.0f); var centerY = (float)(target.RenderTargetBounds.Y + sizeY / 2.0f); if (textFormat == null) { // Initialize a TextFormat textFormat = new TextFormat(target.DeviceManager.FactoryDirectWrite, "Calibri", 96 * sizeX / 1920) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }; } if (pathGeometry1 == null) { var sizeShape = sizeX / 4.0f; // Creates a random geometry inside a circle pathGeometry1 = new PathGeometry1(target.DeviceManager.FactoryDirect2D); var pathSink = pathGeometry1.Open(); var startingPoint = new DrawingPointF(sizeShape * 0.5f, 0.0f); pathSink.BeginFigure(startingPoint, FigureBegin.Hollow); for (int i = 0; i < 128; i++) { float angle = (float)i / 128.0f * (float)Math.PI * 2.0f; float R = (float)(Math.Cos(angle) * 0.1f + 0.4f); R *= sizeShape; DrawingPointF point1 = new DrawingPointF(R * (float)Math.Cos(angle), R * (float)Math.Sin(angle)); if ((i & 1) > 0) { R = (float)(Math.Sin(angle * 6.0f) * 0.1f + 0.9f); R *= sizeShape; point1 = new DrawingPointF(R * (float)Math.Cos(angle + Math.PI / 12), R * (float)Math.Sin(angle + Math.PI / 12)); } pathSink.AddLine(point1); } pathSink.EndFigure(FigureEnd.Open); pathSink.Close(); } context2D.TextAntialiasMode = TextAntialiasMode.Grayscale; float t = clock.ElapsedMilliseconds / 1000.0f; context2D.Transform = Matrix.RotationZ((float)(Math.Cos(t * 2.0f * Math.PI * 0.5f))) * Matrix.Translation(centerX, centerY, 0); context2D.DrawText("SharpDX\nDirect2D1\nDirectWrite", textFormat, new RectangleF(-sizeX / 2.0f, -sizeY / 2.0f, +sizeX/2.0f, sizeY/2.0f), sceneColorBrush); float scaling = (float)(Math.Cos(t * 2.0 * Math.PI * 0.25) * 0.5f + 0.5f) * 0.5f + 0.5f; context2D.Transform = Matrix.Scaling(scaling) * Matrix.RotationZ(t * 1.5f) * Matrix.Translation(centerX, centerY, 0); context2D.DrawGeometry(pathGeometry1, sceneColorBrush, 2.0f); context2D.EndDraw(); }
/// <summary> /// Initializes the renderer. /// </summary> /// <param name="deviceManager">The DirectX device manager.</param> public virtual void Initialize(DeviceManager deviceManager) { this.physicalFontMetrics = this.screenDisplay.FontMetrics * (DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f); //deviceManager.ContextDirect2D.TextAntialiasMode = TextAntialiasMode.Grayscale; deviceManager.ContextDirect2D.AntialiasMode = AntialiasMode.Aliased; this.textFormatNormal = new TextFormat(deviceManager.FactoryDirectWrite, this.screenDisplay.ColorTheme.FontFamily, FontWeight.Normal, FontStyle.Normal, this.physicalFontMetrics.FontSize) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Near, WordWrapping = WordWrapping.NoWrap }; this.textFormatBold = new TextFormat(deviceManager.FactoryDirectWrite, this.screenDisplay.ColorTheme.FontFamily, FontWeight.Bold, FontStyle.Normal, this.physicalFontMetrics.FontSize) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Near, WordWrapping = WordWrapping.NoWrap }; }
/// <summary> /// Create a GDI Compatible TextLayout. Takes a string, format, and associated constraints, and produces an object representing the result, formatted for a particular display resolution and measuring mode. /// </summary> /// <remarks> /// The resulting text layout should only be used for the intended resolution, and for cases where text scalability is desired {{CreateTextLayout}} should be used instead. /// </remarks> /// <param name="factory">an instance of <see cref = "SharpDX.DirectWrite.Factory" /></param> /// <param name="text">An array of characters that contains the string to create a new <see cref="T:SharpDX.DirectWrite.TextLayout" /> object from. This array must be of length stringLength and can contain embedded NULL characters. </param> /// <param name="textFormat">The text formatting object to apply to the string. </param> /// <param name="layoutWidth">The width of the layout box. </param> /// <param name="layoutHeight">The height of the layout box. </param> /// <param name="pixelsPerDip">The number of physical pixels per DIP (device independent pixel). For example, if rendering onto a 96 DPI device pixelsPerDip is 1. If rendering onto a 120 DPI device pixelsPerDip is 1.25 (120/96). </param> /// <param name="transform">An optional transform applied to the glyphs and their positions. This transform is applied after the scaling specifies the font size and pixels per DIP. </param> /// <param name="useGdiNatural">Instructs the text layout to use the same metrics as GDI bi-level text when set to FALSE. When set to TRUE, instructs the text layout to use the same metrics as text measured by GDI using a font created with CLEARTYPE_NATURAL_QUALITY. </param> /// <unmanaged>HRESULT IDWriteFactory::CreateGdiCompatibleTextLayout([In, Buffer] const wchar_t* string,[None] int stringLength,[None] IDWriteTextFormat* textFormat,[None] float layoutWidth,[None] float layoutHeight,[None] float pixelsPerDip,[In, Optional] const DWRITE_MATRIX* transform,[None] BOOL useGdiNatural,[Out] IDWriteTextLayout** textLayout)</unmanaged> public TextLayout(Factory factory, string text, TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, RawMatrix3x2? transform, bool useGdiNatural) : base(IntPtr.Zero) { factory.CreateGdiCompatibleTextLayout(text, text.Length, textFormat, layoutWidth, layoutHeight, pixelsPerDip, transform, useGdiNatural, this); }
/// <summary> /// Create a Gdi Compatible TextLayout. Takes a string, format, and associated constraints, and produces an object representing the result, formatted for a particular display resolution and measuring mode. /// </summary> /// <remarks> /// The resulting text layout should only be used for the intended resolution, and for cases where text scalability is desired {{CreateTextLayout}} should be used instead. /// </remarks> /// <param name="factory">an instance of <see cref = "SharpDX.DirectWrite.Factory" /></param> /// <param name="text">An array of characters that contains the string to create a new <see cref="T:SharpDX.DirectWrite.TextLayout" /> object from. This array must be of length stringLength and can contain embedded NULL characters. </param> /// <param name="textFormat">The text formatting object to apply to the string. </param> /// <param name="layoutWidth">The width of the layout box. </param> /// <param name="layoutHeight">The height of the layout box. </param> /// <param name="pixelsPerDip">The number of physical pixels per DIP (device independent pixel). For example, if rendering onto a 96 DPI device pixelsPerDip is 1. If rendering onto a 120 DPI device pixelsPerDip is 1.25 (120/96). </param> /// <param name="useGdiNatural">Instructs the text layout to use the same metrics as GDI bi-level text when set to FALSE. When set to TRUE, instructs the text layout to use the same metrics as text measured by GDI using a font created with CLEARTYPE_NATURAL_QUALITY. </param> /// <unmanaged>HRESULT IDWriteFactory::CreateGdiCompatibleTextLayout([In, Buffer] const wchar_t* string,[None] int stringLength,[None] IDWriteTextFormat* textFormat,[None] float layoutWidth,[None] float layoutHeight,[None] float pixelsPerDip,[In, Optional] const DWRITE_MATRIX* transform,[None] BOOL useGdiNatural,[Out] IDWriteTextLayout** textLayout)</unmanaged> public TextLayout(Factory factory, string text, TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, bool useGdiNatural) : this(factory, text, textFormat, layoutWidth, layoutHeight, pixelsPerDip, null , useGdiNatural) { }