Moves XNA 4 files for Github migration.

This commit is contained in:
2017-11-11 15:20:02 -08:00
parent d607b86cc0
commit a99816b6ad
32 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlBrNode: HtmlNode
{
public override string ToString()
{
return Environment.NewLine;
}
public HtmlBrNode()
{
Type = HtmlNodeType.Br;
}
public override string TagName
{
get { return StaticTagName; }
}
public static string StaticTagName
{
get { return "br"; }
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlDivNode: HtmlNode
{
public static string StaticTagName { get { return "div"; } }
public override string TagName { get { return StaticTagName; } }
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlDocumentNode: HtmlNode
{
public HtmlDocumentNode()
{
Type = HtmlNodeType.Document_;
}
public override string InnerHtml
{
get
{
StringBuilder sb = new StringBuilder();
foreach (HtmlNode child in Children)
{
sb.Append(child.OuterHtml);
}
return sb.ToString();
}
}
public override string OuterHtml
{
get
{
return InnerHtml;
}
}
public override string TagName
{
get { return "_Document"; }
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlImgNode: HtmlNode
{
public static string StaticTagName { get { return "img"; } }
public override string TagName { get { return StaticTagName; } }
public HtmlImgNode()
{
Type = HtmlNodeType.Img;
}
}
}

View File

@@ -0,0 +1,210 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using PlanB.Html.Utility;
namespace PlanB.Html.Nodes
{
public abstract class HtmlNode
{
public List<HtmlNode> Children { get; set; }
public HtmlNodeType Type { get; protected set; }
public List<KeyValuePair<string, string>> Attributes { get; set; }
public List<KeyValuePair<string, string>> Styles { get; set; }
public HtmlNode()
{
Attributes = new List<KeyValuePair<string, string>>();
Children = new List<HtmlNode>();
Styles = new List<KeyValuePair<string, string>>();
}
public virtual String InnerHtml
{
get
{
StringBuilder sb = new StringBuilder();
foreach (HtmlNode childNode in Children)
{
sb.Append(childNode.OuterHtml);
}
return sb.ToString();
}
}
public virtual String OuterHtml
{
get
{
string styles = GetStylesString();
string attributes = GetAttributesString();
StringBuilder sb = new StringBuilder();
sb.Append("<");
sb.Append(TagName);
if (!String.IsNullOrEmpty(styles))
{
sb.Append(" ");
sb.Append(styles);
}
if (!String.IsNullOrEmpty(attributes))
{
sb.Append(" ");
sb.Append(attributes);
}
if (Children.Count > 0)
{
sb.Append(">");
sb.Append(InnerHtml);
sb.Append("</");
sb.Append(TagName);
sb.Append(">");
}
else
{
sb.Append(" />");
}
return sb.ToString();
}
}
public abstract String TagName{get;}
protected virtual String GetAttributesString()
{
int numAttributes = Attributes.Count;
if (numAttributes == 0)
{
return String.Empty;
}
else if (numAttributes == 1)
{
return Attributes[0].Key + "=\"" + Attributes[0].Value + "\"";
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append(Attributes[0].Key + "=\"" + Attributes[0].Value + "\"");
foreach (KeyValuePair<string, string> attribute in Attributes.Skip(1))
{
sb.Append(" " + attribute.Key + "=\"" + attribute.Value + "\"");
}
return sb.ToString();
}
}
protected virtual String GetStylesString()
{
int numStyles = Styles.Count;
if (numStyles == 0)
{
return String.Empty;
}
else if (numStyles == 1)
{
return "style=\"" + Styles[0].Key + ":" + Styles[0].Value + ";\"";
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append("style=\"" + Styles[0].Key + ":" + Styles[0].Value + ";\"");
foreach (KeyValuePair<string, string> style in Styles.Skip(1))
{
sb.Append(";" + style.Key + ":" + style.Value);
}
sb.Append("\"");
return sb.ToString();
}
}
public void AddAttribute(KeyValuePair<string, string> attribute)
{
KeyValuePair<string, string> newAttribute = new KeyValuePair<string, string>(attribute.Key.ToLower(), attribute.Value);
if (newAttribute.Key == "style")
{
ClearStyles();
String styleString = newAttribute.Value;
string[] stylePairStrings = styleString.Split(new char[] { ';' });
KeyValuePair<string, string> style;
foreach (string stylePairString in stylePairStrings)
{
string[] temp = stylePairString.Split(new char[] { ':' });
if (temp.Length == 1)
{
style = new KeyValuePair<string, string>(temp[0], String.Empty);
}
else if (temp.Length >= 2)
{
style = new KeyValuePair<string, string>(temp[0], temp[1]);
}
else
{
style = new KeyValuePair<string, string>();
}
if (!String.IsNullOrEmpty(style.Key))
{
AddStyle(style);
}
}
}
else
{
Attributes.RemoveAll(i => i.Key == newAttribute.Key);
Attributes.Add(newAttribute);
}
}
private void ClearStyles()
{
Styles.Clear();
}
public void AddStyle(KeyValuePair<string, string> style)
{
string key = style.Key.ToLower();
string value = style.Value;
if (key == "color")
{
Color color = ColorHelper.FromCss(value);
if (color.A == 0xff)
{
value = String.Format("rgb({0}, {1}, {2})", color.R, color.G, color.B);
}
else
{
value = String.Format("rgba({0}, {1}, {2}, {3})", color.R, color.G, color.B, color.A);
}
}
KeyValuePair<string, string> newStyle = new KeyValuePair<string,string>(key, value);
Styles.RemoveAll(i => i.Key == newStyle.Key);
Styles.Add(newStyle);
}
}
public enum HtmlNodeType { Document_, Text_, Br, Span, Img, Paragraph, Div }
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlSpanNode: HtmlNode
{
public HtmlSpanNode()
{
Type = HtmlNodeType.Span;
}
public HtmlSpanNode(String text)
:this()
{
Children.Add(new HtmlTextNode(text));
}
public HtmlSpanNode(IEnumerable<HtmlNode> children)
:this()
{
foreach (HtmlNode child in children)
{
Children.Add(child);
}
}
public override string TagName
{
get { return StaticTagName; }
}
public static string StaticTagName { get { return "span"; } }
}
}

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace PlanB.Html.Nodes
{
public class HtmlTextNode: HtmlNode
{
public String Text { get; set; }
public override string ToString()
{
return Text;
}
public HtmlTextNode()
{
Text = String.Empty;
Type = HtmlNodeType.Text_;
}
public HtmlTextNode(String text)
{
Text = text;
Type = HtmlNodeType.Text_;
}
public override string InnerHtml
{
get
{
return String.Empty;
}
}
public override string OuterHtml
{
get
{
return Entitize(Text);
}
}
public override string TagName
{
get { return "_Text"; }
}
private string Entitize(string Text)
{
string temp = Text;
temp = temp.Replace("&", "&amp;");
temp = temp.Replace("<", "&lt;");
temp = temp.Replace(">", "&gt;");
temp = temp.Replace("\"", "&quot;");
return temp;
}
}
}