public void LoadContent(ContentManager cm) { //Start by loading all textures //playerTexture = cm.Load<Texture2D>("player.png"); // fontTexture = cm.Load<Texture2D>("basicFont.png"); thirstTexture = cm.Load <Texture2D>("waterBottle.png"); hungerTexture = cm.Load <Texture2D>("apple.png"); string fontFilePath = Path.Combine(cm.RootDirectory, "Fonts/font.fnt"); fontFile = FontLoader.Load(fontFilePath); fontTexture = cm.Load <Texture2D>("Fonts/font_0.png"); fontRenderer = new FontRenderer(fontFile, fontTexture); sizingRectangle = new Rectangle(0, 0, 211, 40); displays = new List <Display>(); //addDisplay(0, 0, //testing //displays.Add(new Display(0, 0, "12S red")); //Then assign textures to NPCs depending on their tag // thePlayer.sprite = playerTexture; }
/// <summary> /// /// </summary> /// <param name="fntFilePath"></param> /// <param name="fontTexturePath"></param> /// <param name="name"></param> /// <returns></returns> public static BitmapFontRenderer AddBMFont(string fntFilePath, string fontTexturePath, string name) { if (!fontRenderers.ContainsKey(name)) { string _fntFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, fntFilePath); string _textureFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, fontTexturePath); #if WINDOWS if (File.Exists(_fntFilePath) && File.Exists(_textureFilePath)) #elif WINRT if (MetroHelper.AppDataFileExists(_fntFilePath) && MetroHelper.AppDataFileExists(_textureFilePath)) #endif { FontFile fontFile = FontLoader.Load(_fntFilePath); Texture2D fontTexture = TextureLoader.FromFile(_textureFilePath); BitmapFontRenderer fr = new BitmapFontRenderer(fontFile, fontTexture); fontRenderers[name] = fr; return(fr); } } return(null); }
public static Textbox CreateTextbox(string placeholder = "") { Texture2D textboxImage = TextureLoader.Load("Textbox"); SpriteFont textboxFont = FontLoader.Load("MenuFont"); return(new Textbox(textboxImage, textboxFont, placeholder)); }
public void preload(IContentProvider content) { fonts = new FontProvider(); fonts.Add("sans", FontLoader.Load(content, "AgateLib/AgateSans")); this.palogo = content.Load <Texture2D>("imgs/palogo"); this.vtlogo = content.Load <Texture2D>("imgs/vtlogo"); }
public static RadioButton CreateRadioButton(string text, bool initalValue) { Texture2D checkedImage = TextureLoader.Load("RadioButtonChecked"); Texture2D uncheckedImage = TextureLoader.Load("RadioButtonUnchecked"); SpriteFont radioButtonFont = FontLoader.Load("MenuFont"); return(new RadioButton(checkedImage, uncheckedImage, radioButtonFont, text, initalValue)); }
public static CheckBox CreateCheckBox(string text, bool initalValue) { Texture2D checkedImage = TextureLoader.Load("CheckBoxChecked"); Texture2D uncheckedImage = TextureLoader.Load("CheckBoxUnchecked"); SpriteFont checkboxFont = FontLoader.Load("MenuFont"); return(new CheckBox(checkedImage, uncheckedImage, checkboxFont, text, initalValue)); }
private void FontFaceReady(DataPackage font) { // Load and apply additional settings: if (font.Errored) { Wrench.Log.Add("@font-face error: " + font.Error); return; } // Load the face - it will by default add to it's "native" family: FontFace loaded = FontLoader.Load(font.Data); if (loaded == null || loaded.Family == null) { Wrench.Log.Add("@font-face error: invalid font file at " + font.Url); return; } Value family = this["font-family"]; // Grab the family name: string familyName; if (family == null || family.Text == null) { familyName = loaded.Family.Name; } else { familyName = family.Text.Trim().Replace("\"", ""); } // Add as an active font: Dictionary <string, DynamicFont> fonts = Document.ActiveFonts; DynamicFont dFont; if (!fonts.TryGetValue(familyName, out dFont)) { // Create the font object: dFont = new DynamicFont(familyName); dFont.Family = loaded.Family; fonts[familyName] = dFont; } else { // Hook up the "real" family: dFont.Family = loaded.Family; // Tell all instances using this dFont that the font is ready: Document.html.FontLoaded(dFont); } }
public static Button CreateButton(string text) { Texture2D inactiveImage = TextureLoader.Load("ButtonInactive"); Texture2D hoveredImage = TextureLoader.Load("ButtonHovered"); Texture2D clickedImage = TextureLoader.Load("ButtonClicked"); SpriteFont buttonFont = FontLoader.Load("MenuFont"); return(new Button(inactiveImage, hoveredImage, clickedImage, buttonFont, text)); }
/// <summary>Loads this font from the local project files. Should be a folder named after the font family and in it a series of font files.</summary> /// <returns>True if at least one font face was loaded.</returns> public bool LoadFaces() { if (string.IsNullOrEmpty(Name)) { // This case results in every text asset being checked otherwise! return(false); } // Load all .ttf/.otf files: object[] faces = Resources.LoadAll(Name, typeof(TextAsset)); // For each font face.. for (int i = 0; i < faces.Length; i++) { // Get the raw font face data: byte[] faceData = ((TextAsset)faces[i]).bytes; if (faceData == null || faceData.Length == 0) { // It's a folder. continue; } // Load the font face - adds itself to the family within it if it's a valid font: try{ FontFace loaded; if (Fonts.DeferLoad) { loaded = FontLoader.DeferredLoad(faceData); } else { loaded = FontLoader.Load(faceData); } if (loaded != null && Family == null) { // Grab the family: Family = loaded.Family; } }catch { // Unity probably gave us a copyright file or something like that. // Generally the loader will catch this internally and return null. } } if (Family == null) { return(false); } return(true); }
public static GameFont ArialLarge; // = new GameFont("Arial", 8); public static void LoadContent(ContentManager content) { // ParticleFlowerBurst = content.Load<Texture2D>(@"Particle\FlowerBurst.png"); var fontFilePath = Path.Combine(content.RootDirectory, "Fonts\\Arial16.fnt"); var fontFile = FontLoader.Load(TitleContainer.OpenStream(fontFilePath)); var fontTexture = content.Load <Texture2D>(@"Fonts\Arial16_0.png"); ArialSmall = new GameFont(fontFile, fontTexture); fontFilePath = Path.Combine(content.RootDirectory, "Fonts\\Arial32.fnt"); fontFile = FontLoader.Load(TitleContainer.OpenStream(fontFilePath)); fontTexture = content.Load <Texture2D>(@"Fonts\Arial32_0.png"); ArialLarge = new GameFont(fontFile, fontTexture); }
private BmFont loadFont(string path) { var fontFilePath = findFile(path); using (var stream = TitleContainer.OpenStream(fontFilePath)) { var fontFile = FontLoader.Load(stream); var fontPng = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), fontFile.Pages[0].File); // textRenderer initialization will go here stream.Close(); return(new BmFont(fontFile, fontPng)); } }
public Renderer() { IGraphicsContext context = Engine.GraphicsContext; int width = context.Device.BackBuffer.Width; int height = context.Device.BackBuffer.Height; sceneTarget = RenderTarget2D.New(context.Device, width, height, PixelFormat.R8G8B8A8.UNorm); texToTargetEffect = EffectLoader.Load(@"Graphics/Shaders/CopyTextureToTarget.fx"); gbuffer = context.GBuffer; font = FontLoader.Load(@"Graphics/Fonts/Arial16.xml"); fpsClock = new Stopwatch(); fpsText = string.Empty; }
/// <summary> /// /// </summary> /// <param name="contentManager"></param> private void LoadContent(ContentManager contentManager) { var definitionPath = string.Format("{0}_{1}.fnt", Name, Style); using (var contents = File.OpenRead(Path.Combine(contentManager.RootDirectory, definitionPath))) _definition = FontLoader.Load(contents); // We need to support multiple texture pages for more than plain ASCII text. _textures = new Texture2D[_definition.Pages.Count]; for (int i = 0; i < _definition.Pages.Count; i++) { var texturePath = string.Format("{0}_{1}_{2}.png", Name, Style, i); _textures[i] = contentManager.Load <Texture2D>(texturePath); } }
public WinningScreen() { Stage = SummerizedStage.Score; RestartButton = WindowFactory.CreateButton("Restart"); NextButton = WindowFactory.CreateButton("Next"); RestartButton.Position = new Vector2() { X = GetControlXPosition(NextButton, 1, 2), Y = Position.Y + Height * 0.75f, }; NextButton.Position = new Vector2() { X = GetControlXPosition(NextButton, 2, 2), Y = Position.Y + Height * 0.75f, }; WinningText = new Label(FontLoader.Load("HeaderFont"), "You Win!", GlobalData.Theme["Blue"]); ScoreText = new Label(FontLoader.Load("HeaderFont"), "", GlobalData.Theme["LightMagenta"]); Star1 = WindowFactory.CreateStar(); Star2 = WindowFactory.CreateStar(); Star3 = WindowFactory.CreateStar(); Star2.Position = new Vector2() { X = Position.X + Width / 2 - Star1.Width / 2, Y = Position.Y + Height * 0.30f, }; Star1.Position = new Vector2() { X = Position.X + Width / 2 - Star1.Width / 2 - Star1.Width * 1.25f, Y = Star2.Position.Y + 20, }; Star3.Position = new Vector2() { X = Position.X + Width / 2 - Star1.Width / 2 + Star1.Width * 1.25f, Y = Star2.Position.Y + 20, }; addStar1 = new DelayedAction(Star1.Shine, 0.5f); addStar2 = new DelayedAction(Star2.Shine, 1.0f); addStar3 = new DelayedAction(Star3.Shine, 1.5f); }
public override void LoadContent(GraphicsDevice gd, ContentManager cm) { //Initialization for basicEffect basicEffect = new BasicEffect(gd); basicEffect.VertexColorEnabled = true; basicEffect.LightingEnabled = false; spriteBatch = new SpriteBatch(gd); string fontFilePath = Path.Combine(cm.RootDirectory, "Fonts/font.fnt"); fontFile = FontLoader.Load(fontFilePath); fontTexture = cm.Load <Texture2D>("Fonts/font_0.png"); fontRenderer = new FontRenderer(fontFile, fontTexture); logo = cm.Load <Texture2D>("LOGO.png"); bgTexture = cm.Load <Texture2D>("bg.png"); }
public BmFont(string fontTexture, ContentManager content) { //_content = content; _fontTexture = content.Load <Texture2D>(fontTexture); string fontFilePath = $"Content\\{fontTexture}.fnt"; FontFile fontFile = FontLoader.Load(fontFilePath); _fontFile = fontFile; _characterMap = new Dictionary <char, FontChar>(); foreach (FontChar fontCharacter in fontFile.Chars) { var c = (char)fontCharacter.ID; _characterMap.Add(c, fontCharacter); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); /* 1 game 1 font */ var fontFilePath = Path.Combine(Content.RootDirectory, @"fonts\segoe32.fnt"); var fontFile = FontLoader.Load(fontFilePath); var fontTexture = Content.Load <Texture2D>(@"fonts\segoe32_0.png"); fontRenderer = new FontRenderer(fontFile, fontTexture); LoadingScreen loading = new LoadingScreen(Content); ScreenManager.Instance.SetLoadingScreen(loading); ScreenManager.Instance.SetScreen(new MenuScreen()); //ScreenManager.Instance.SetScreen(new LevelCreator(0)); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _SpriteBatch = new SpriteBatch(GraphicsDevice); // Load the textures of the main scene _Background = this.Content.Load <Texture2D>("background"); _ReadyCover = this.Content.Load <Texture2D>("ready"); _GameoverCover = this.Content.Load <Texture2D>("gameover"); // Load the score font _ScoreFontFile = FontLoader.Load(Path.Combine(this.Content.RootDirectory, "score_font.fnt")); _ScoreFontTexture = this.Content.Load <Texture2D>("score_font_0"); _ScoreFontRenderer = new FontRenderer(_ScoreFontFile, _ScoreFontTexture); // Load the tips font _TipsFontFile = FontLoader.Load(Path.Combine(this.Content.RootDirectory, "tips_font.fnt")); _TipsFontTexture = this.Content.Load <Texture2D>("tips_font_0"); _TipsFontRenderer = new FontRenderer(_TipsFontFile, _TipsFontTexture); }
public WinAllScreen() { Title.Text = "Congratulation!"; WinAllText = new Label(FontLoader.Load("HeaderFont"), "You have passed all levels!", GlobalData.Theme["Silver"]); HighScoreText = new Label(FontLoader.Load("HeaderFont"), "High Score: " + GlobalData.Session.CurrentScore.ToString("N0"), GlobalData.Theme["Yellow"]); TextBox = WindowFactory.CreateTextbox(); SaveButton = WindowFactory.CreateButton("Back to menu"); TextBox.Position = new Vector2() { X = GetControlXPosition(TextBox, 1, 1), Y = this.Position.Y + 210f, }; SaveButton.Position = new Vector2() { X = GetControlXPosition(SaveButton, 1, 1), Y = this.Position.Y + 300f, }; }
/// <summary> /// Character テーブルと BMFont のデータから Font エントリを生成します /// </summary> /// <param name="chtablefile">キャラクタテーブル</param> /// <param name="fntfile">BMFont ファイル</param> private void Run(string chtablefile, string fntfile) { // Character Table 読み込み var chtable = this.LoadCharacterTable(chtablefile); // Font 情報読み込み var fonttable = FontLoader.Load(fntfile); // Font 検索 Function Func <char, FontChar> SearchFont = (seachch) => { FontChar ret = NullFontChar; foreach (var fontch in fonttable.Chars) { if (seachch == (char)fontch.ID) { ret = fontch; break; } } return(ret); }; int idx = 0; foreach (var ch in chtable) { FontChar fch = null; /* * Font の検索 */ // NULL 文字 if (ch == 0x0000) { fch = NullFontChar; }// SPACE は改行区切りとして使う else if (ch == CHAR_SPACE) { fch = NullFontChar; } // ^ を空白の変わりに使う else if (ch == CHAR_CIRCUM) { fch = SearchFont(CHAR_SPACE); } else { // 通常の文字 fch = SearchFont(ch); } // Font Character を出力 if (fch == NullFontChar || fch == null) { this.WriteData(idx, 0, 0, 0, 0, 0, 0, 0); if (fch == null) { Console.Error.WriteLine("Unknown Font Character - {0}:{1}", idx, ch); } } else if (fch != NullFontChar) { this.WriteData(idx, fch); } idx++; } }
/// <summary> /// Constrcutor /// </summary> /// <param name="device"></param> /// <param name="fileName"></param> public SpriteFont(GraphicsDevice rs, Stream stream) { this.rs = rs; FontFile input = FontLoader.Load(stream); int numGlyphs = input.Chars.Max(ch => ch.ID); // create charInfo and kernings : fontInfo.kernings = new Dictionary <Tuple <char, char>, float>(); fontInfo.charInfo = new SpriteFontInfo.CharInfo[numGlyphs + 1]; // check UNICODE : /*if (input.Info.Unicode!=0) { * throw new SystemException("UNICODE characters are not supported (Remove UNICODE flag)"); * } */ // check one-page bitmap fonts : if (input.Pages.Count != 1) { throw new GraphicsException("Only one page of font image is supported"); } // create path for font-image : string fontImagePath = input.Pages[0].File; fontTexture = rs.Game.Content.Load <Texture2D>(fontImagePath); // Fill structure : fontInfo.fontFace = input.Info.Face; fontInfo.baseLine = input.Common.Base; fontInfo.lineHeight = input.Common.LineHeight; fontInfo.scaleWidth = input.Common.ScaleW; fontInfo.scaleHeight = input.Common.ScaleH; float scaleWidth = fontInfo.scaleWidth; float scaleHeight = fontInfo.scaleHeight; // process character info : for (int i = 0; i < input.Chars.Count; i++) { FontChar ch = input.Chars[i]; int id = ch.ID; int x = ch.X; int y = ch.Y; int xoffs = ch.XOffset; int yoffs = ch.YOffset; int w = ch.Width; int h = ch.Height; fontInfo.charInfo[ch.ID].validChar = true; fontInfo.charInfo[ch.ID].xAdvance = ch.XAdvance; fontInfo.charInfo[ch.ID].srcRect = new RectangleF(x, y, w, h); fontInfo.charInfo[ch.ID].dstRect = new RectangleF(xoffs, yoffs, w, h); } var letterHeights = input.Chars .Where(ch1 => char.IsUpper((char)(ch1.ID))) .Select(ch2 => ch2.Height) .OrderBy(h => h) .ToList(); CapHeight = letterHeights[letterHeights.Count / 2]; // process kerning info : for (int i = 0; i < input.Kernings.Count; i++) { var pair = new Tuple <char, char>((char)input.Kernings[i].First, (char)input.Kernings[i].Second); int kerning = input.Kernings[i].Amount; fontInfo.kernings.Add(pair, kerning); } SpaceWidth = MeasureString(" ").Width; LineHeight = MeasureString(" ").Height; }
public static Label CreateLabel(string text) { SpriteFont labelFont = FontLoader.Load("MenuFont"); return(new Label(labelFont, text)); }
private bool LoadFont(Value value) { Value path = value["url"]; string pathValue; if (path != null) { // Get the text value: pathValue = path.Text; } else { // Read the raw value: pathValue = value.Text; } DataPackage package = new DataPackage(pathValue, Document.basepath); package.onload = delegate(UIEvent e){ // Load the face - it will by default add to it's "native" family: FontFace loaded = FontLoader.Load(package.responseBytes); if (loaded == null || loaded.Family == null) { Dom.Log.Add("@font-face error: invalid font file at " + package.location.absolute); return; } // Got any weight, stretch or style overrides? Css.Value styleValue = style["font-style"]; Css.Value weightValue = style["font-weight"]; Css.Value stretchValue = style["font-stretch"]; if (styleValue != null || weightValue != null || stretchValue != null) { // Yep! // New style value: int styleV = (styleValue == null) ? loaded.Style : styleValue.GetInteger(null, Css.Properties.FontStyle.GlobalProperty); // New weight value: int weight = (weightValue == null) ? loaded.Weight : weightValue.GetInteger(null, Css.Properties.FontWeight.GlobalProperty); // New stretch value: int stretch = (stretchValue == null) ? loaded.Stretch : stretchValue.GetInteger(null, Css.Properties.FontStretch.GlobalProperty); // Update the flags: loaded.SetFlags(styleV, weight, stretch); } Value family = style["font-family"]; // Grab the family name: string familyName; if (family == null || family.Text == null) { familyName = loaded.Family.Name; } else { familyName = family.Text.Trim(); } // Add as an active font: Dictionary <string, DynamicFont> fonts = Document.ActiveFonts; DynamicFont dFont; if (!fonts.TryGetValue(familyName, out dFont)) { // Create the font object: dFont = new DynamicFont(familyName); dFont.Family = loaded.Family; fonts[familyName] = dFont; } else { // Hook up the "real" family: dFont.Family = loaded.Family; // Tell all instances using this dFont that the font is ready: Document.FontLoaded(dFont); } }; // Send now: package.send(); return(true); }
public WindowScreen() { this.defaultFont = FontLoader.Load("MenuFont"); this.Title = new Label(defaultFont, text: "Breakout"); }
/// <inheritdoc /> public override async Task <FontFile?> ImportAsync(Stream stream, ImporterContext context, CancellationToken cancellationToken) { return(await Task.Run( () => { FontDescription?description = Json.Deserialize <FontDescription>(stream); if (description == null) { context.AddMessage("Importing item failed! Expected type {0}!", typeof(FontDescription)); return null; } FontStyle fs = FontStyle.Regular; if (description.IsBold) { fs |= FontStyle.Bold; } if (description.IsItalic) { fs |= FontStyle.Italic; } using (Font fnt = new Font(description.Name, description.Size, fs)) { if (string.Compare( fnt.Name, description.Name, StringComparison.InvariantCultureIgnoreCase) != 0) { context.AddMessage( "Can't import the font '{0:OrangeRed}'! " + "The font doesn't exists on the current system!", description); return null; } } string tempFileNameLocation = Path.Combine(TEMP_FILE_DIR, $"{description.Size}_{Path.GetRandomFileName()}.fnt"); string configLocation = Path.Combine("tools", $"config{Thread.CurrentThread.ManagedThreadId}.bmfc"); int textureWidth = Math2.RoundUpToPowerOfTwo( (int)Math.Sqrt(GetCharCount(description.Chars) * description.Size)); while (textureWidth <= Resource.MaximumTexture2DSize) { if (cancellationToken.IsCancellationRequested) { return null; } File.WriteAllText( configLocation, CreateConfig(description, textureWidth, textureWidth)); using (Process p = Process.Start( new ProcessStartInfo( _bmFontExeLocation, $"-c {configLocation} -o {tempFileNameLocation}") { UseShellExecute = false, CreateNoWindow = false })) { if (!p.HasExited) { int i = 0; while (!p.WaitForExit(1_000) && !cancellationToken.IsCancellationRequested && i++ < 45) { } if (!p.HasExited) { try { p.Kill(); } catch { /* IGNORE*/ } } } if (p.ExitCode == 0) { FontFile fontFile = FontLoader.Load(tempFileNameLocation); if (fontFile.Common !.Pages == 1) { if (CheckFontImageFiles(fontFile, TEMP_FILE_DIR)) { fontFile.Pages ![0].File = Path.GetFullPath(Path.Combine(TEMP_FILE_DIR, fontFile.Pages[0].File)); return fontFile; }