public void AddFallback(FieldFont font, string name, float scale) { var msdf = new MSDFFont(font); msdf.VectorScale = scale; Fallbacks.Add(msdf); }
public void Begin(Matrix worldViewProjection, bool optimizeForSmallText = false) { if (_currentlyDrawing) { throw new Exception("Currently drawing."); } _currentFont = null; _currentTexture = null; _vertices.Clear(); _optimizeForSmallText = optimizeForSmallText; _currentlyDrawing = true; Effect.Parameters["WorldViewProjection"].SetValue(worldViewProjection); if (optimizeForSmallText) { Effect.CurrentTechnique = Effect.Techniques[SmallTextTechnique]; } else { Effect.CurrentTechnique = Effect.Techniques[LargeTextTechnique]; } }
public Label(FieldFont font, string content, HorizontalAlignment hAlign, AbstractValue horizontal, VerticalAlignment vAlign, AbstractValue vertical, AbstractValue width, AbstractValue height) : base(hAlign, horizontal, vAlign, vertical, width, height) { _font = font; Content = content; }
public TextRenderer(Effect effect, FieldFont font, GraphicsDevice device) { this.Effect = effect; this.Font = font; this.Device = device; this.Quad = new Quad(); this.Cache = new Dictionary <char, GlyphRenderInfo>(); this.ForegroundColor = Color.White; this.EnableKerning = true; this.OptimizeForTinyText = false; }
public void End() { if (!_currentlyDrawing) { throw new Exception("Not currently drawing."); } Flush(); _currentlyDrawing = false; _currentFont = null; _currentTexture = null; }
protected override void LoadContent() { // Global Content GlobalContent = new LockingContentManager(Services); GlobalContent.Locked = false; GlobalContent.RootDirectory = "Content"; ProcessManager.Attach(new AudioManager(GlobalContent)); LoadGameContent(GlobalContent); GlobalContent.Locked = true; FieldFont font = GlobalContent.Load <FieldFont>("font_msdf_hyperspace"); // Attach first game state last SharedGameState sharedState = (SharedGameState)ProcessManager.Attach(new SharedGameState(this)); ProcessManager.Attach(new UIMenuGameState(this, sharedState)); }
public MSDFInfo(FieldFont Font) { itemW = 1f / Font.Atlas.Width; itemH = 1f / Font.Atlas.Height; textureWidth = Font.Atlas.GlyphSize; textureHeight = Font.Atlas.GlyphSize; cutUX = itemW / textureWidth; cutUY = itemH / textureHeight; cut2UX = cutUX * 2; cut2UY = cutUY * 2; uW = itemW - 2 * cutUX; uH = itemH - 2 * cutUY; cutX = 1f / textureWidth; cutY = 1f / textureHeight; atlasWidth = Font.Atlas.Width; pairs = Font.StringToPair; }
public MSDFFont(FieldFont font) { Font = font; GlyphSize = font.Atlas.GlyphSize; }
public void LinkEveryController() { //obvious question - "why": //this is for mono ahead of time compilation. By referencing everything here, //we make sure these classes and generic variants are AOT compiled var load = new LoadingScreen(); var loadc = new LoadingScreenController(null, null, null); var screen = new PersonSelectionEdit(); var t = new TerrainController(null, null, null, null, null); var n = new Network.Network(null, null, null, null); var v = new Credits(); var cd = new Common.DataService.ClientDataService(null, null, null); var c = new CoreGameScreen(); var cc = new CoreGameScreenController(null, null, null, null, null); var s = new SandboxGameScreen(); var ps = new PersonSelection(null, null); var psc = new PersonSelectionController(null, null, null, null); var cl1 = new Server.Clients.AuthClient(""); var cl2 = new Server.Clients.CityClient(""); var cl3 = new Server.Clients.ApiClient(""); var ls = new LoginScreen(null); var lc = new LoginController(null, null); var lr = new Regulators.LoginRegulator(null, null, null); var seled = new PersonSelectionEditController(null, null); var casr = new Regulators.CreateASimRegulator(null); var purch = new Regulators.PurchaseLotRegulator(null); var conn = new Regulators.LotConnectionRegulator(null, null, null); var t2 = new Regulators.CityConnectionRegulator(null, null, null, null, Kernel, null); var neigh = new Regulators.GenericActionRegulator <NhoodRequest, NhoodResponse>(null); var bulletin = new Regulators.GenericActionRegulator <BulletinRequest, BulletinResponse>(null); var regu = new Regulators.RegulatorsModule(); var prov = new CacheProvider(); var clip = new AuthClientProvider(null); var citp = new CityClientProvider(null); var ar = new Server.Clients.AriesClient(null); var tso = new cTSOSerializerProvider(null); var ser = new Server.Protocol.Voltron.DataService.cTSOSerializer(null); var mods = new ModelSerializerProvider(null); var dbs = new Common.DatabaseService.DatabaseService(null); var cds = new Common.DataService.ClientDataService(null, null, null); var arp = new Server.Protocol.Aries.AriesProtocolDecoder(null); var are = new Server.Protocol.Aries.AriesProtocolEncoder(null); var serc = new Common.Serialization.SerializationContext(null, null); var ff = new FieldFont(); var fa = new FieldAtlas(); var fg = new FieldGlyph(); var kp = new KerningPair(); var met = new Metrics(); var dict = new Dictionary <char, FieldGlyph>(); var packets = new object[] { new ClientOnlinePDU(), new HostOnlinePDU(), new SetIgnoreListPDU(), new SetIgnoreListResponsePDU(), new SetInvinciblePDU(), new RSGZWrapperPDU(), new TransmitCreateAvatarNotificationPDU(), new DataServiceWrapperPDU(), new DBRequestWrapperPDU(), new OccupantArrivedPDU(), new ClientByePDU(), new ServerByePDU(), new FindPlayerPDU(), new FindPlayerResponsePDU(), new ChatMsgPDU(), new AnnouncementMsgPDU(), new MessagingWindowController(null, null, null), new Controllers.Panels.SecureTradeController(null, null), new GizmoSearchController(null, null, null), new GizmoTop100Controller(null, null, null, null, null), new LotAdmitController(null, null, null), new GizmoController(null, null, null), new PersonPageController(null, null, null), new LotPageController(null, null), new BookmarksController(null, null, null), new RelationshipDialogController(null, null, null, null), new InboxController(null, null, null, null), new JoinLotProgressController(null, null), new DisconnectController(null, null, null, null, null), new GenericSearchController(null, null), new NeighPageController(null, null), new RatingListController(null, null, null), new RatingSummaryController(null, null, null), new NeighborhoodActionController(null), ImmutableList.Create <uint>(), ImmutableList.Create <JobLevel>(), ImmutableList.Create <Relationship>(), ImmutableList.Create <Bookmark>(), ImmutableList.Create <bool>(), new cTSOGenericData(), }; }
public static Widget CreateFromPrototype(ContentManager content, WidgetPrototype prototype, ref Dictionary <string, WeakReference <Widget> > widgetIdDict) { Widget widget = null; AbstractValue width = ValueFromString(prototype.Width); AbstractValue height = ValueFromString(prototype.Height); AbstractValue horizontal = ValueFromString(prototype.Horizontal); AbstractValue vertical = ValueFromString(prototype.Vertical); HorizontalAlignment halign; switch (prototype.Halign.ToLower()[0]) { case 'r': halign = HorizontalAlignment.Right; break; case 'l': halign = HorizontalAlignment.Left; break; case 'c': default: halign = HorizontalAlignment.Center; break; } VerticalAlignment valign; switch (prototype.Valign.ToLower()[0]) { case 't': valign = VerticalAlignment.Top; break; case 'b': valign = VerticalAlignment.Bottom; break; case 'c': default: valign = VerticalAlignment.Center; break; } /** WIDGET SPECIALIZATIONS **/ if (prototype is LabelWidgetPrototype) { FieldFont font = content.Load <FieldFont>(((LabelWidgetPrototype)prototype).Font); string labelContent = ((LabelWidgetPrototype)prototype).Content; widget = new Label(font, labelContent, halign, horizontal, valign, vertical, width, height); } if (prototype is ImageWidgetPrototype) { TextureRegion2D texture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((ImageWidgetPrototype)prototype).Image)); widget = new Image(texture, halign, horizontal, valign, vertical, width, height); } if (prototype is NinePatchImageWidgetPrototype) { TextureRegion2D texture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((NinePatchImageWidgetPrototype)prototype).Image)); string[] rawThickness = ((NinePatchImageWidgetPrototype)prototype).Thickness.Trim().Split(','); if (rawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } widget = new NinePatchImage(new NinePatchRegion2D(texture, int.Parse(rawThickness[0]), int.Parse(rawThickness[1]), int.Parse(rawThickness[2]), int.Parse(rawThickness[3])), halign, horizontal, valign, vertical, width, height); } if (prototype is PanelWidgetPrototype || prototype is ExternalWidgetPrototype) { widget = new Panel(halign, horizontal, valign, vertical, width, height); } if (prototype is ButtonWidgetPrototype) { TextureRegion2D releasedTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((ButtonWidgetPrototype)prototype).ReleasedImage)); string[] releasedRawThickness = ((ButtonWidgetPrototype)prototype).ReleasedThickness.Trim().Split(','); if (releasedRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } TextureRegion2D hoverTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((ButtonWidgetPrototype)prototype).HoverImage)); string[] hoverRawThickness = ((ButtonWidgetPrototype)prototype).HoverThickness.Trim().Split(','); if (hoverRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } TextureRegion2D pressedTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((ButtonWidgetPrototype)prototype).PressedImage)); string[] pressedRawThickness = ((ButtonWidgetPrototype)prototype).PressedThickness.Trim().Split(','); if (pressedRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } widget = new Button(new NinePatchRegion2D(releasedTexture, int.Parse(releasedRawThickness[0]), int.Parse(releasedRawThickness[1]), int.Parse(releasedRawThickness[2]), int.Parse(releasedRawThickness[3])), new NinePatchRegion2D(hoverTexture, int.Parse(hoverRawThickness[0]), int.Parse(hoverRawThickness[1]), int.Parse(hoverRawThickness[2]), int.Parse(hoverRawThickness[3])), new NinePatchRegion2D(pressedTexture, int.Parse(pressedRawThickness[0]), int.Parse(pressedRawThickness[1]), int.Parse(pressedRawThickness[2]), int.Parse(pressedRawThickness[3])), halign, horizontal, valign, vertical, width, height); if (((ButtonWidgetPrototype)prototype).OnClick.Length > 0) { string[] onclickParts = ((ButtonWidgetPrototype)prototype).OnClick.Trim().Split(':'); switch (onclickParts[0].ToLower()) { case "queue": ((Button)widget).Action = () => { string assemblyQualifiedName = string.Format("GameJam.Events.{0}, GameJam", onclickParts[1]); IEvent evt = (IEvent)Activator.CreateInstance(Type.GetType(assemblyQualifiedName)); EventManager.Instance.QueueEvent(evt); }; break; default: throw new Exception(string.Format("Unkown action type: `{0}`", onclickParts[0])); } } ((Button)widget).rightID = ((ButtonWidgetPrototype)prototype).RightID; ((Button)widget).leftID = ((ButtonWidgetPrototype)prototype).LeftID; ((Button)widget).aboveID = ((ButtonWidgetPrototype)prototype).AboveID; ((Button)widget).belowID = ((ButtonWidgetPrototype)prototype).BelowID; ((Button)widget).isSelected = ((ButtonWidgetPrototype)prototype).IsSelected; } if (prototype is SliderWidgetPrototype) { TextureRegion2D releasedTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((SliderWidgetPrototype)prototype).ReleasedImage)); string[] releasedRawThickness = ((SliderWidgetPrototype)prototype).ReleasedThickness.Trim().Split(','); if (releasedRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } TextureRegion2D hoverTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((SliderWidgetPrototype)prototype).HoverImage)); string[] hoverRawThickness = ((SliderWidgetPrototype)prototype).HoverThickness.Trim().Split(','); if (hoverRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } TextureRegion2D pressedTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((SliderWidgetPrototype)prototype).PressedImage)); string[] pressedRawThickness = ((SliderWidgetPrototype)prototype).PressedThickness.Trim().Split(','); if (pressedRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } widget = new Slider(new NinePatchRegion2D(releasedTexture, int.Parse(releasedRawThickness[0]), int.Parse(releasedRawThickness[1]), int.Parse(releasedRawThickness[2]), int.Parse(releasedRawThickness[3])), new NinePatchRegion2D(hoverTexture, int.Parse(hoverRawThickness[0]), int.Parse(hoverRawThickness[1]), int.Parse(hoverRawThickness[2]), int.Parse(hoverRawThickness[3])), new NinePatchRegion2D(pressedTexture, int.Parse(pressedRawThickness[0]), int.Parse(pressedRawThickness[1]), int.Parse(pressedRawThickness[2]), int.Parse(pressedRawThickness[3])), halign, horizontal, valign, vertical, width, height, ((SliderWidgetPrototype)prototype).isVertical, ((SliderWidgetPrototype)prototype).isHorizontal, ((SliderWidgetPrototype)prototype).divisions, ((SliderWidgetPrototype)prototype).cvar); ((Slider)widget).rightID = ((SliderWidgetPrototype)prototype).RightID; ((Slider)widget).leftID = ((SliderWidgetPrototype)prototype).LeftID; ((Slider)widget).aboveID = ((SliderWidgetPrototype)prototype).AboveID; ((Slider)widget).belowID = ((SliderWidgetPrototype)prototype).BelowID; ((Slider)widget).isSelected = ((SliderWidgetPrototype)prototype).IsSelected; } if (prototype is DropDownPanelWidgetPrototype) { TextureRegion2D releasedTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((DropDownPanelWidgetPrototype)prototype).ReleasedImage)); string[] releasedRawThickness = ((DropDownPanelWidgetPrototype)prototype).ReleasedThickness.Trim().Split(','); if (releasedRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } TextureRegion2D hoverTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((DropDownPanelWidgetPrototype)prototype).HoverImage)); string[] hoverRawThickness = ((DropDownPanelWidgetPrototype)prototype).HoverThickness.Trim().Split(','); if (hoverRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } TextureRegion2D pressedTexture = content.Load <TextureAtlas>("complete_texture_atlas") .GetRegion((((DropDownPanelWidgetPrototype)prototype).PressedImage)); string[] pressedRawThickness = ((DropDownPanelWidgetPrototype)prototype).PressedThickness.Trim().Split(','); if (pressedRawThickness.Length != 4) { throw new Exception("NinePatchImage thickness must be integers in the for `left,top,right,bottom`."); } AbstractValue contentsWidth = ValueFromString(((DropDownPanelWidgetPrototype)prototype).ContentsInfo.Width); AbstractValue contentsHeight = ValueFromString(((DropDownPanelWidgetPrototype)prototype).ContentsInfo.Height); string[] rawEventTypes = ((DropDownPanelWidgetPrototype)prototype).CloseOn.Split(','); Type[] eventTypes = new Type[rawEventTypes.Length]; for (int i = 0; i < rawEventTypes.Length; i++) { string rawEventType = rawEventTypes[i]; string assemblyQualifiedName = string.Format("GameJam.Events.{0}, GameJam", rawEventType); eventTypes[i] = Type.GetType(assemblyQualifiedName); } widget = new DropDownPanel(new NinePatchRegion2D(releasedTexture, int.Parse(releasedRawThickness[0]), int.Parse(releasedRawThickness[1]), int.Parse(releasedRawThickness[2]), int.Parse(releasedRawThickness[3])), new NinePatchRegion2D(hoverTexture, int.Parse(hoverRawThickness[0]), int.Parse(hoverRawThickness[1]), int.Parse(hoverRawThickness[2]), int.Parse(hoverRawThickness[3])), new NinePatchRegion2D(pressedTexture, int.Parse(pressedRawThickness[0]), int.Parse(pressedRawThickness[1]), int.Parse(pressedRawThickness[2]), int.Parse(pressedRawThickness[3])), halign, horizontal, valign, vertical, width, height, contentsWidth, contentsHeight, eventTypes); ((DropDownPanel)widget).rightID = ((DropDownPanelWidgetPrototype)prototype).RightID; ((DropDownPanel)widget).leftID = ((DropDownPanelWidgetPrototype)prototype).LeftID; ((DropDownPanel)widget).aboveID = ((DropDownPanelWidgetPrototype)prototype).AboveID; ((DropDownPanel)widget).belowID = ((DropDownPanelWidgetPrototype)prototype).BelowID; ((DropDownPanel)widget).isSelected = ((DropDownPanelWidgetPrototype)prototype).IsSelected; foreach (WidgetPrototype childPrototype in ((DropDownPanelWidgetPrototype)prototype).ContentsInfo.Children) { ((DropDownPanel)widget).AddContent(CreateFromPrototype(content, childPrototype, ref widgetIdDict)); } } if (widget is IParentWidget) { List <WidgetPrototype> children = prototype.Children; if (prototype is ExternalWidgetPrototype) { string src = ((ExternalWidgetPrototype)prototype).Source; children = content.Load <List <WidgetPrototype> >(src); } foreach (WidgetPrototype childPrototype in children) { ((IParentWidget)widget).Add(CreateFromPrototype(content, childPrototype, ref widgetIdDict)); } } widget.Hidden = prototype.Hidden; widget.Alpha = prototype.Alpha; if (prototype.AspectRatio.Length > 0) { string[] aspectRatioParts = prototype.AspectRatio.Split(new[] { ':', '/' }); float aspectRatio = 0; if (aspectRatioParts.Length == 1) { aspectRatio = float.Parse(aspectRatioParts[0]); } if (aspectRatioParts.Length == 2) { aspectRatio = float.Parse(aspectRatioParts[0]) / float.Parse(aspectRatioParts[1]); } widget.AspectRatio = aspectRatio; widget.MaintainAspectRatio = true; } if (prototype.ID.Trim().Length > 0) { if (widgetIdDict.ContainsKey(prototype.ID)) { throw new Exception(string.Format("Duplicate Widget ID: '{0}'", prototype.ID)); } widgetIdDict.Add(prototype.ID, new WeakReference <Widget>(widget)); } if (prototype.Class.Trim().Length > 0) { string[] classes = prototype.Class.Trim().ToLower().Split(','); widget.Classes.AddRange(classes); } return(widget); }
public MSDFFont(FieldFont font) { Font = font; GlyphSize = font.Atlas.GlyphSize; Info = new MSDFInfo(font); }
public FieldFontComponent(FieldFont font, string content) { Font = font; Content = content; }
public void Draw(FieldFont font, string content, Vector2 position, float rotation, Color color, float scale = 1, bool enableKerning = true, float depth = 0) { if (!_currentlyDrawing) { throw new Exception("Not currently drawing. Call `Begin` first."); } if (string.IsNullOrEmpty(content)) { return; } if (_currentFont != null) { if (_currentFont.PxRange != font.PxRange || _currentFont.TxSize != font.TxSize) { // Incompatible Flush(); } } _currentFont = font; Effect.Parameters["PxRange"].SetValue(font.PxRange); GlyphRenderInfo[] sequence = content.Select((char c) => { return(font.GetRenderInfo(Device, Content, c)); }).ToArray(); float cos = (float)Math.Cos(rotation); float sin = (float)Math.Sin(rotation); Vector2 pen = -font.MeasureString(content, enableKerning) / 2; for (int i = 0; i < sequence.Length; i++) { GlyphRenderInfo current = sequence[i]; if (current == null) { continue; } if (_currentTexture != null) { if (_currentTexture != current.TextureRegion.Texture) { Flush(); } } _currentTexture = current.TextureRegion.Texture; Effect.Parameters["GlyphTexture"].SetValue(current.TextureRegion.Texture); Effect.Parameters["TextureSize"].SetValue(new Vector2(current.TextureRegion.Texture.Width, current.TextureRegion.Texture.Height)); float glyphHeight = font.TxSize * (1.0f / current.Metrics.Scale); float glyphWidth = font.TxSize * (1.0f / current.Metrics.Scale); float left = pen.X - current.Metrics.Translation.X; float bottom = pen.Y - current.Metrics.Translation.Y; float right = left + glyphWidth; float top = bottom + glyphHeight; if (!char.IsWhiteSpace(current.Character)) { Vector2 bottomLeft = new Vector2(left, bottom) * scale; Vector2 topRight = new Vector2(right, top) * scale; bottomLeft += position; topRight += position; Rectangle glyphSourceBounds = current.TextureRegion.Bounds; float umin = glyphSourceBounds.X / (float)current.TextureRegion.Texture.Width, vmin = glyphSourceBounds.Y / (float)current.TextureRegion.Texture.Height, umax = (glyphSourceBounds.X + glyphSourceBounds.Width) / (float)current.TextureRegion.Texture.Width, vmax = (glyphSourceBounds.Y + glyphSourceBounds.Height) / (float)current.TextureRegion.Texture.Height; int verticesCount = _vertices.Count; _vertices.Add(new VertexPositionColorTexture { Position = new Vector3(RotateVector(new Vector2(topRight.X, bottomLeft.Y), cos, sin), depth), Color = color, TextureCoordinate = new Vector2(umax, vmax) }); _vertices.Add(new VertexPositionColorTexture { Position = new Vector3(RotateVector(new Vector2(bottomLeft.X, bottomLeft.Y), cos, sin), depth), Color = color, TextureCoordinate = new Vector2(umin, vmax) }); _vertices.Add(new VertexPositionColorTexture { Position = new Vector3(RotateVector(new Vector2(bottomLeft.X, topRight.Y), cos, sin), depth), Color = color, TextureCoordinate = new Vector2(umin, vmin) }); _vertices.Add(new VertexPositionColorTexture { Position = new Vector3(RotateVector(new Vector2(topRight.X, topRight.Y), cos, sin), depth), Color = color, TextureCoordinate = new Vector2(umax, vmin) }); // ccw rotation _indices.Add(verticesCount); // 0 _indices.Add(verticesCount + 1); // 1 _indices.Add(verticesCount + 2); // 2 _indices.Add(verticesCount + 2); // 2 _indices.Add(verticesCount + 3); // 3 _indices.Add(verticesCount); // 0 } pen.X += current.Metrics.Advance; if (enableKerning && i < sequence.Length - 1) { var next = sequence[i + 1]; if (next != null) { var pair = font.KerningPairs.FirstOrDefault( x => x.Left == current.Character && x.Right == next.Character); if (pair != null) { pen.X += pair.Advance; } } } } }
public void Draw(FieldFont font, string content, Vector2 position, float rotation) { Draw(font, content, position, rotation, Color.White); }