public Curve GetAsCurve() { if (this is Curve) { return((Curve)this); } EPoint pt = ((Line)this).Offset; EPoint ptNew = pt / 2; return(new Curve(ptNew.Copy(), ptNew)); }
public static void Assemble(string definition, string savePathWithPrefix, EPoint firstTryTextureSize) { Hashtable passNumberToTexture = GenerateFileLists(definition, null); bool usingPasses = passNumberToTexture.Count > 1 ? true : false; //usingPasses = generate several bitmaps, based on different sequences foreach (DictionaryEntry dePass in passNumberToTexture) { int passNum = (int)dePass.Key; Hashtable textureNamesToFramesets = (Hashtable)dePass.Value; foreach (DictionaryEntry deTexture in textureNamesToFramesets) { string textureName = (string)deTexture.Key; Hashtable framesets = (Hashtable)deTexture.Value; XmlDocument doc = new XmlDocument(); XmlNode xmlNode = doc.CreateElement("Animations"); doc.AppendChild(xmlNode); XmlNode xmlFramesetNode; XmlAttribute xmlAttr; ArrayList allFiles = new ArrayList(); foreach (DictionaryEntry deAnim in framesets) { string framesetName = (string)deAnim.Key; string[] filenames = (string[])deAnim.Value; if (filenames.Length > 0) { //frameset can have same name as others (other characters etc) //so it must be uniquely identifiable - add xmlFramesetNode = xmlNode.OwnerDocument.CreateElement(framesetName); xmlNode.AppendChild(xmlFramesetNode); string sAnimFrames = "0"; // Create animation frame list: <Animations> tag //if (usingPasses) //{ int startFrame = allFiles.Count; sAnimFrames = startFrame.ToString(); //} sAnimFrames += " 0-" + (filenames.Length - 1).ToString(); //for (int i=0; i<filenames.Length;i++) // sAnimFrames+=i.ToString()+","; //sAnimFrames = sAnimFrames.Remove(sAnimFrames.Length-1,1); xmlAttr = xmlNode.OwnerDocument.CreateAttribute("value"); xmlFramesetNode.Attributes.Append(xmlAttr); xmlAttr.InnerText = sAnimFrames; } foreach (string filename in filenames) { allFiles.Add(filename); } } string[] all = new string[allFiles.Count]; for (int i = 0; i < allFiles.Count; i++) { all[i] = (string)allFiles[i]; } string saveFilename = textureName; if (usingPasses) { saveFilename += "_" + passNum.ToString().PadLeft(2, '0'); } saveFilename = savePathWithPrefix + saveFilename; //TODO: find texture size to start trying with. //TODO: doesn't really matter in which texture the individual frames are... (in some cases at least) EPoint trySize = firstTryTextureSize.Copy(); for (int tryNum = 0; tryNum < 3; tryNum++) { try { Endogine.BitmapHelpers.TexturePacking.TreePack( new System.Drawing.Size(trySize.X, trySize.Y), all, saveFilename); } catch { if (trySize.X <= trySize.Y) { trySize.X *= 2; } else { trySize.Y *= 2; } } } //load the auto-created resource fork and add the animations to it: string xmlFilename = saveFilename + ".xml"; XmlDocument resDoc = new XmlDocument(); resDoc.Load(xmlFilename); if (resDoc["root"]["Animations"] == null) { Endogine.Serialization.XmlHelper.CreateAndAddElement(resDoc["root"], "Animations"); } resDoc["root"]["Animations"].InnerXml = doc["Animations"].InnerXml; //Endogine.Serialization.XmlHelper.Merge(resDoc["root"]["Animations"], doc["Animations"]); resDoc.Save(xmlFilename); } } }
public ArrayList CreateMorphedShape(float ratio) { ArrayList morphedCommands = new ArrayList(); int targetIndex = -1; EPoint ptCurrent = new EPoint(); foreach (ShapeCommand.Base cmd in this.CommandList) { if (!(cmd is ShapeCommand.Style)) { targetIndex++; } ShapeCommand.Base cmdTo = (ShapeCommand.Base) this._morphCommandList[targetIndex]; if (cmd is ShapeCommand.Move) { EPoint pt1 = ((ShapeCommand.Move)cmd).Target; EPoint pt2 = ((ShapeCommand.Move)cmdTo).Target; ptCurrent = this.GetPointBetween(pt1, pt2, ratio); morphedCommands.Add(new ShapeCommand.Move(ptCurrent)); } else if ((cmd is ShapeCommand.Line) || (cmd is ShapeCommand.Curve)) { ShapeCommand.Draw draw = (ShapeCommand.Draw)cmd; ShapeCommand.Curve curve = draw.GetAsCurve(); if ((cmdTo is ShapeCommand.Line) || (cmdTo is ShapeCommand.Curve)) { draw = (ShapeCommand.Draw)cmdTo; ShapeCommand.Curve curveTo = draw.GetAsCurve(); EPoint ptControl = this.GetPointBetween(curve.Control, curveTo.Control, ratio); EPoint ptAnchor = this.GetPointBetween(curve.Anchor, curveTo.Anchor, ratio); morphedCommands.Add(new ShapeCommand.Curve(ptControl, ptAnchor)); ptCurrent += ptControl + ptAnchor; } else { ShapeCommand.Move move = (ShapeCommand.Move)cmdTo; EPoint ptFrom = ptCurrent + curve.Control + curve.Anchor; EPoint ptTo = move.Target; ptCurrent = this.GetPointBetween(ptFrom, ptTo, ratio); morphedCommands.Add(new ShapeCommand.Move(ptCurrent.Copy())); } } else if (cmd is ShapeCommand.LineStyle) { ShapeCommand.LineStyle ls = (ShapeCommand.LineStyle)cmd; if (ls.StyleId > 0) { Style.LineStyle style = (Style.LineStyle) this.LineStyles[ls.StyleId - 1]; style.MorphPosition = ratio; morphedCommands.Add(ls); //.GetMorphed(ratio)); } } else if (cmd is ShapeCommand.FillStyle) { ShapeCommand.FillStyle fs = (ShapeCommand.FillStyle)cmd; if (fs.StyleId > 0) { Style.FillStyle style = (Style.FillStyle) this.FillStyles[fs.StyleId - 1]; style.MorphPosition = ratio; morphedCommands.Add(fs); //.GetMorphed(ratio)); } } } return(morphedCommands); }
public static void Assemble(string definition, string savePathWithPrefix, EPoint firstTryTextureSize) { Hashtable passNumberToTexture = GenerateFileLists(definition, null); bool usingPasses = passNumberToTexture.Count > 1 ? true : false; //usingPasses = generate several bitmaps, based on different sequences foreach (DictionaryEntry dePass in passNumberToTexture) { int passNum = (int)dePass.Key; Hashtable textureNamesToFramesets = (Hashtable)dePass.Value; foreach (DictionaryEntry deTexture in textureNamesToFramesets) { string textureName = (string)deTexture.Key; Hashtable framesets = (Hashtable)deTexture.Value; XmlDocument doc = new XmlDocument(); XmlNode xmlNode = doc.CreateElement("Animations"); doc.AppendChild(xmlNode); XmlNode xmlFramesetNode; XmlAttribute xmlAttr; ArrayList allFiles = new ArrayList(); foreach (DictionaryEntry deAnim in framesets) { string framesetName = (string)deAnim.Key; string[] filenames = (string[])deAnim.Value; if (filenames.Length > 0) { //frameset can have same name as others (other characters etc) //so it must be uniquely identifiable - add xmlFramesetNode = xmlNode.OwnerDocument.CreateElement(framesetName); xmlNode.AppendChild(xmlFramesetNode); string sAnimFrames = "0"; // Create animation frame list: <Animations> tag //if (usingPasses) //{ int startFrame = allFiles.Count; sAnimFrames = startFrame.ToString(); //} sAnimFrames += " 0-" + (filenames.Length - 1).ToString(); //for (int i=0; i<filenames.Length;i++) // sAnimFrames+=i.ToString()+","; //sAnimFrames = sAnimFrames.Remove(sAnimFrames.Length-1,1); xmlAttr = xmlNode.OwnerDocument.CreateAttribute("value"); xmlFramesetNode.Attributes.Append(xmlAttr); xmlAttr.InnerText = sAnimFrames; } foreach (string filename in filenames) allFiles.Add(filename); } string[] all = new string[allFiles.Count]; for (int i = 0; i < allFiles.Count; i++) all[i] = (string)allFiles[i]; string saveFilename = textureName; if (usingPasses) saveFilename += "_" + passNum.ToString().PadLeft(2, '0'); saveFilename = savePathWithPrefix + saveFilename; //TODO: find texture size to start trying with. //TODO: doesn't really matter in which texture the individual frames are... (in some cases at least) EPoint trySize = firstTryTextureSize.Copy(); for (int tryNum = 0; tryNum < 3; tryNum++) { try { Endogine.BitmapHelpers.TexturePacking.TreePack( new System.Drawing.Size(trySize.X, trySize.Y), all, saveFilename); } catch { if (trySize.X <= trySize.Y) trySize.X *= 2; else trySize.Y *= 2; } } //load the auto-created resource fork and add the animations to it: string xmlFilename = saveFilename + ".xml"; XmlDocument resDoc = new XmlDocument(); resDoc.Load(xmlFilename); if (resDoc["root"]["Animations"] == null) Endogine.Serialization.XmlHelper.CreateAndAddElement(resDoc["root"], "Animations"); resDoc["root"]["Animations"].InnerXml = doc["Animations"].InnerXml; //Endogine.Serialization.XmlHelper.Merge(resDoc["root"]["Animations"], doc["Animations"]); resDoc.Save(xmlFilename); } } }
public ArrayList CreateMorphedShape(float ratio) { ArrayList morphedCommands = new ArrayList(); int targetIndex=-1; EPoint ptCurrent = new EPoint(); foreach (ShapeCommand.Base cmd in this.CommandList) { if (!(cmd is ShapeCommand.Style)) targetIndex++; ShapeCommand.Base cmdTo = (ShapeCommand.Base)this._morphCommandList[targetIndex]; if (cmd is ShapeCommand.Move) { EPoint pt1 = ((ShapeCommand.Move)cmd).Target; EPoint pt2 = ((ShapeCommand.Move)cmdTo).Target; ptCurrent = this.GetPointBetween(pt1,pt2,ratio); morphedCommands.Add(new ShapeCommand.Move(ptCurrent)); } else if ((cmd is ShapeCommand.Line) || (cmd is ShapeCommand.Curve)) { ShapeCommand.Draw draw = (ShapeCommand.Draw)cmd; ShapeCommand.Curve curve = draw.GetAsCurve(); if ((cmdTo is ShapeCommand.Line) || (cmdTo is ShapeCommand.Curve)) { draw = (ShapeCommand.Draw)cmdTo; ShapeCommand.Curve curveTo = draw.GetAsCurve(); EPoint ptControl = this.GetPointBetween(curve.Control,curveTo.Control,ratio); EPoint ptAnchor = this.GetPointBetween(curve.Anchor,curveTo.Anchor,ratio); morphedCommands.Add(new ShapeCommand.Curve(ptControl, ptAnchor)); ptCurrent+= ptControl + ptAnchor; } else { ShapeCommand.Move move = (ShapeCommand.Move)cmdTo; EPoint ptFrom = ptCurrent+curve.Control+curve.Anchor; EPoint ptTo = move.Target; ptCurrent = this.GetPointBetween(ptFrom, ptTo, ratio); morphedCommands.Add(new ShapeCommand.Move(ptCurrent.Copy())); } } else if (cmd is ShapeCommand.LineStyle) { ShapeCommand.LineStyle ls = (ShapeCommand.LineStyle)cmd; if (ls.StyleId > 0) { Style.LineStyle style = (Style.LineStyle)this.LineStyles[ls.StyleId-1]; style.MorphPosition = ratio; morphedCommands.Add(ls); //.GetMorphed(ratio)); } } else if (cmd is ShapeCommand.FillStyle) { ShapeCommand.FillStyle fs = (ShapeCommand.FillStyle)cmd; if (fs.StyleId > 0) { Style.FillStyle style = (Style.FillStyle)this.FillStyles[fs.StyleId-1]; style.MorphPosition = ratio; morphedCommands.Add(fs); //.GetMorphed(ratio)); } } } return morphedCommands; }