protected override void OnGotContext(RenderContext context) { base.OnGotContext(context); var fontPath = Path.GetFullPath(GetFontFilePath()); var familyName = DirectWriteHelper.GetFontFamilyName(fontPath); _font = new D2DFont(context.DirectWriteFactory, familyName, FontSize, FontStyle.Regular, 10); _textFill = new D2DSolidBrush(context, FillColor); _textStroke = new D2DPen(context, StrokeColor, StrokeWidth); _fontFile = new FontFile(context.DirectWriteFactory, fontPath); _fontFace = new FontFace(context.DirectWriteFactory, FontFaceType.OpenTypeCollection, new[] { _fontFile }, 0, FontSimulations.None); _glyphRun = new GlyphRun { FontFace = _fontFace, FontSize = FontSize }; RegenerateFontPath(context); }
protected override void OnGotContext(RenderContext context) { base.OnGotContext(context); var settings = Program.Settings; var avatarCount = settings.Images.Avatars.Length; var avatarImages = new D2DBitmap[avatarCount]; for (var i = 0; i < avatarCount; ++i) { try { var image = Direct2DHelper.LoadBitmap(context, settings.Images.Avatars[i].FileName); avatarImages[i] = image; } catch (Exception ex) { Debug.Print(ex.Message); } } var clientSize = context.ClientSize; var layout = settings.UI.Avatars.Layout; var x = layout.X.IsPercentage ? layout.X.Value * clientSize.Width : layout.X.Value; var y = layout.Y.IsPercentage ? layout.Y.Value * clientSize.Height : layout.Y.Value; var w = layout.Width.IsPercentage ? layout.Width.Value * clientSize.Width : layout.Width.Value; var h = layout.Height.IsPercentage ? layout.Height.Value * clientSize.Height : layout.Height.Value; var rects = new RectangleF[avatarCount]; float radius; if (w >= h) { radius = h / 2; for (var i = 0; i < avatarCount; ++i) { var cx = (w - radius * 2) / (avatarCount - 1) * i; var rect = new RectangleF(x + cx, y, radius * 2, radius * 2); rects[i] = rect; } } else { radius = w / 2; for (var i = 0; i < avatarCount; ++i) { var cy = (h - radius * 2) / (avatarCount - 1) * i; var rect = new RectangleF(x, y + cy, radius * 2, radius * 2); rects[i] = rect; } } _avatarImages = avatarImages; _avatarRectangles = rects; var gamingArea = Game.AsTheaterDays().FindSingleElement <GamingArea>(); if (gamingArea == null) { throw new InvalidOperationException(); } var scalingResults = gamingArea.ScaleResults; _borderPen = new D2DPen(context, Color.White, scalingResults.AvatarBorder.Width); }