Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
FontSystem.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 
6 using System.Linq;
7 
8 namespace SiliconStudio.Paradox.Graphics.Font
9 {
10  /// <summary>
11  /// The system managing the fonts.
12  /// </summary>
13  public class FontSystem : IFontSystem
14  {
15  internal int FrameCount { get; private set; }
16  internal FontManager FontManager { get; private set; }
17  internal GraphicsDevice GraphicsDevice { get; private set; }
18  internal FontCacheManager FontCacheManager { get; private set; }
19  internal readonly HashSet<SpriteFont> AllocatedSpriteFonts = new HashSet<SpriteFont>();
20 
21  /// <summary>
22  /// Create a new instance of <see cref="FontSystem"/> base on the provided <see cref="GraphicsDevice"/>.
23  /// </summary>
24  /// <param name="graphicsDevice">A valid instance of <see cref="GraphicsDevice"/></param>
25  /// <exception cref="ArgumentNullException"><paramref name="graphicsDevice"/> is null</exception>
26  public FontSystem(GraphicsDevice graphicsDevice)
27  {
28  if (graphicsDevice == null)
29  throw new ArgumentNullException("graphicsDevice");
30 
31  GraphicsDevice = graphicsDevice;
32  FontManager = new FontManager();
33  FontCacheManager = new FontCacheManager(this);
34  }
35 
36  /// <summary>
37  /// Load the fonts.
38  /// </summary>
39  public void Load()
40  {
41  // TODO possibly load cached character bitmaps from the disk
42  }
43 
44  public void Draw()
45  {
46  ++FrameCount;
47  }
48 
49  public void Unload()
50  {
51  // TODO possibly save generated characters bitmaps on the disk
52 
53  // Dispose create sprite fonts
54  foreach (var allocatedSpriteFont in AllocatedSpriteFonts.ToArray())
55  allocatedSpriteFont.Dispose();
56  }
57 
59  {
60  return new StaticSpriteFont(this, data);
61  }
62 
64  {
65  return new DynamicSpriteFont(this, data);
66  }
67  }
68 }
FontSystem(GraphicsDevice graphicsDevice)
Create a new instance of FontSystem base on the provided GraphicsDevice.
Definition: FontSystem.cs:26
The interface to create and manage fonts.
Definition: IFontSystem.cs:8
The system managing the fonts.
Definition: FontSystem.cs:13
SharpDX.DirectWrite.Font Font
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
SpriteFont NewDynamic(DynamicSpriteFontData data)
Create a new instance of a dynamic font.
Definition: FontSystem.cs:63
SpriteFont to use with SpriteBatch. See SpriteFont to learn how to use it.
Definition: SpriteFont.cs:26
SpriteFont NewStatic(StaticSpriteFontData data)
Create a new instance of a static font.
Definition: FontSystem.cs:58
Data for a static SpriteFont object that supports kerning.