Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
StaticSpriteFontDataConverter.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.Collections;
4 using System.Collections.Generic;
5 
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Serialization;
8 using SiliconStudio.Core.Serialization.Converters;
10 
11 namespace SiliconStudio.Paradox.Graphics
12 {
13  internal class StaticSpriteFontDataConverter : DataConverter<StaticSpriteFontData, SpriteFont>
14  {
15  public override void ConvertFromData(ConverterContext converterContext, StaticSpriteFontData data, ref SpriteFont obj)
16  {
17  var services = converterContext.Tags.Get(ServiceRegistry.ServiceRegistryKey);
18  var fontSystem = services.GetSafeServiceAs<GameFontSystem>().FontSystem;
19 
20  var staticSpriteFont = new StaticSpriteFont(fontSystem, data);
21 
22  for (int index = 0; index < data.Bitmaps.Length; index++)
23  {
24  var bitmap = data.Bitmaps[index];
25 
26  // Convert to texture ref so that Converter system doesn't get lost
27  // TODO: Support that directly in converter?
28  var textureRef = new ContentReference<Texture2D> { Location = bitmap.Location };
29  Texture2D texture = null;
30  converterContext.ConvertFromData(textureRef, ref texture);
31  staticSpriteFont.StaticTextures[index] = texture;
32  }
33 
34  obj = staticSpriteFont;
35  }
36 
37  public override void ConvertToData(ConverterContext converterContext, ref StaticSpriteFontData data, SpriteFont obj)
38  {
39  throw new System.NotImplementedException();
40  }
41 
42  [ModuleInitializer]
43  public static void Initialize()
44  {
45  ConverterContext.RegisterConverter(new StaticSpriteFontDataConverter());
46  }
47  }
48 }
The system managing the fonts.
Definition: FontSystem.cs:13
Base class for converters to/from a data type.
SharpDX.DirectWrite.Font Font
The texture dimension is 2D.