Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ImageFragment.cs
Go to the documentation of this file.
1 using SiliconStudio.Core.Mathematics;
2 using SiliconStudio.Core.Serialization.Converters;
3 
4 namespace SiliconStudio.Paradox.Graphics
5 {
6  /// <summary>
7  /// A region of an image.
8  /// </summary>
9  [DataConverter(AutoGenerate = true, ContentReference = false)]
10  public class ImageFragment
11  {
12  internal RectangleF RegionInternal;
13 
14  internal ImageFragment()
15  : this(null)
16  {
17  }
18 
19  /// <summary>
20  /// Creates an empty image fragment having the provided name.
21  /// </summary>
22  /// <param name="fragmentName">Name of the fragment</param>
23  public ImageFragment(string fragmentName)
24  :this(fragmentName, null, null)
25  {
26  }
27 
28  /// <summary>
29  /// Creates a image fragment having the provided color/alpha textures and name.
30  /// The region size is initialized with the whole size of the texture.
31  /// </summary>
32  /// <param name="fragmentName">Name of the fragment</param>
33  /// <param name="color">The texture to use as color</param>
34  /// <param name="alpha">the texture to use as alpha</param>
35  public ImageFragment(string fragmentName, Texture2D color, Texture2D alpha)
36  {
37  Name = fragmentName;
38  IsTransparent = true;
39 
40  Texture = color;
41  TextureAlpha = alpha;
42 
43  var referenceTexture = color ?? alpha;
44  if(referenceTexture != null)
45  RegionInternal = new Rectangle(0, 0, referenceTexture.Width, referenceTexture.Height);
46  }
47 
48  /// <summary>
49  /// Gets or sets the name of the image fragment.
50  /// </summary>
51  [DataMemberConvert]
52  public string Name { get; internal set; }
53 
54  /// <summary>
55  /// The texture in which the image is contained
56  /// </summary>
57  [DataMemberConvert]
58  public Texture2D Texture { get; set; }
59 
60  /// <summary>
61  /// The texture in which the image alpha is contained
62  /// </summary>
63  [DataMemberConvert]
64  public Texture2D TextureAlpha { get; set; }
65 
66  /// <summary>
67  /// Gets a value indicating if the alpha component of the <see cref="ImageFragment"/> should be taken from the color of the <see cref="TextureAlpha"/> texture or not.
68  /// </summary>
69  public virtual bool SubstituteAlpha
70  {
71  get { return TextureAlpha != null; }
72  }
73 
74  /// <summary>
75  /// The rectangle specifying the region of the texture to use as fragment.
76  /// </summary>
77  [DataMemberConvert]
78  public virtual RectangleF Region
79  {
80  get { return RegionInternal; }
81  set { RegionInternal = value; }
82  }
83 
84  /// <summary>
85  /// Gets or sets the value indicating if the fragment contains transparent regions.
86  /// </summary>
87  [DataMemberConvert]
88  public bool IsTransparent { get; set; }
89 
90  /// <summary>
91  /// Gets or sets the rotation to apply to the texture region when rendering the <see cref="ImageFragment"/>
92  /// </summary>
93  [DataMemberConvert]
94  public virtual ImageOrientation Orientation { get; set; }
95 
96  public override string ToString()
97  {
98  var textureName = Texture != null ? Texture.Name : "''";
99  return Name + ", Texture: " + textureName + ", Region: " + Region;
100  }
101  }
102 }
ImageFragment(string fragmentName)
Creates an empty image fragment having the provided name.
Base class for converters to/from a data type.
Define a RectangleF. This structure is slightly different from System.Drawing.RectangleF as it is int...
Definition: RectangleF.cs:36
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
Definition: Texture2D.cs:37
System.Windows.Shapes.Rectangle Rectangle
Definition: ColorPicker.cs:16
Android.Widget.Orientation Orientation
Definition: Section.cs:9
ImageFragment(string fragmentName, Texture2D color, Texture2D alpha)
Creates a image fragment having the provided color/alpha textures and name. The region size is initia...
ImageOrientation
Defines the possible rotations to apply on image regions.
Base class for texture resources.
Definition: Texture.cs:38