forked from NeoforceControls/Neoforce-Mono
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentReaders.cs
155 lines (122 loc) · 5.19 KB
/
ContentReaders.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
////////////////////////////////////////////////////////////////
// //
// Neoforce Controls //
// //
////////////////////////////////////////////////////////////////
// //
// File: ContentReaders.cs //
// //
// Version: 0.7 //
// //
// Date: 11/09/2010 //
// //
// Author: Tom Shane //
// //
////////////////////////////////////////////////////////////////
// //
// Copyright (c) by Tom Shane //
// //
////////////////////////////////////////////////////////////////
#region //// Using /////////////
//////////////////////////////////////////////////////////////////////////////
using System;
using System.IO;
using System.Xml;
using Microsoft.Xna.Framework.Content;
#if (!XBOX && !XBOX_FAKE)
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
#endif
//////////////////////////////////////////////////////////////////////////////
#endregion
namespace TomShane.Neoforce.Controls
{
////////////////////////////////////////////////////////////////////////////
public class LayoutXmlDocument : XmlDocument { }
public class SkinXmlDocument : XmlDocument { }
////////////////////////////////////////////////////////////////////////////
public class SkinReader : ContentTypeReader<SkinXmlDocument>
{
#region //// Methods ///////////
////////////////////////////////////////////////////////////////////////////
protected override SkinXmlDocument Read(ContentReader input, SkinXmlDocument existingInstance)
{
if (existingInstance == null)
{
SkinXmlDocument doc = new SkinXmlDocument();
doc.LoadXml(input.ReadString());
return doc;
}
else
{
existingInstance.LoadXml(input.ReadString());
}
return existingInstance;
}
////////////////////////////////////////////////////////////////////////////
#endregion
}
public class LayoutReader : ContentTypeReader<LayoutXmlDocument>
{
#region //// Methods ///////////
////////////////////////////////////////////////////////////////////////////
protected override LayoutXmlDocument Read(ContentReader input, LayoutXmlDocument existingInstance)
{
if (existingInstance == null)
{
LayoutXmlDocument doc = new LayoutXmlDocument();
doc.LoadXml(input.ReadString());
return doc;
}
else
{
existingInstance.LoadXml(input.ReadString());
}
return existingInstance;
}
////////////////////////////////////////////////////////////////////////////
#endregion
}
#if (!XBOX && !XBOX_FAKE)
public class CursorReader : ContentTypeReader<Cursor>
{
#region //// Methods ///////////
////////////////////////////////////////////////////////////////////////////
protected override Cursor Read(ContentReader input, Cursor existingInstance)
{
if (existingInstance == null)
{
int count = input.ReadInt32();
byte[] data = input.ReadBytes(count);
string path = Path.GetTempFileName();
File.WriteAllBytes(path, data);
string tPath = Path.GetTempFileName();
using(System.Drawing.Icon i = System.Drawing.Icon.ExtractAssociatedIcon(path))
{
using (System.Drawing.Bitmap b = i.ToBitmap())
{
b.Save(tPath, System.Drawing.Imaging.ImageFormat.Png);
b.Dispose();
}
i.Dispose();
}
//TODO: Replace with xml based solution for getting hotspot and size instead
IntPtr handle = NativeMethods.LoadCursor(path);
System.Windows.Forms.Cursor c = new System.Windows.Forms.Cursor(handle);
Vector2 hs = new Vector2(c.HotSpot.X, c.HotSpot.Y);
int w = c.Size.Width;
int h = c.Size.Height;
c.Dispose();
File.Delete(path);
return new Cursor(tPath, hs, w, h);
}
else
{
}
return existingInstance;
}
////////////////////////////////////////////////////////////////////////////
#endregion
}
#endif
}