Пример #1
0
/*        private Bitmap OptimizeBitmap(Bitmap source, Point origin, Point biggestPng, Point SmallestEmptySpace, Point MaximumMapEndingPts, Brush color)
        {
            Point Size = new Point(biggestPng.X - SmallestEmptySpace.X, biggestPng.Y - SmallestEmptySpace.Y);
            Bitmap empty = new Bitmap(MaximumMapEndingPts.X - SmallestEmptySpace.X, MaximumMapEndingPts.Y - SmallestEmptySpace.Y);
            Graphics process = Graphics.FromImage((Image)empty);
            process.FillRectangle(color, 0, 0, empty.Width, empty.Height);
            process.DrawImage(source, Size.X - origin.X, Size.Y - origin.Y);
            return empty;
        }*/

        private static Bitmap OptimizeBitmapTransparent(Bitmap source, WzVectorProperty origin, Point biggestPng, Point SmallestEmptySpace, Point MaximumMapEndingPts)
        {
            Point Size = new Point(biggestPng.X - SmallestEmptySpace.X, biggestPng.Y - SmallestEmptySpace.Y);
            Bitmap empty = new Bitmap(MaximumMapEndingPts.X - SmallestEmptySpace.X, MaximumMapEndingPts.Y - SmallestEmptySpace.Y);
            Graphics process = Graphics.FromImage((Image)empty);
            process.DrawImage(source, Size.X - origin.X.Value, Size.Y - origin.Y.Value);
            return empty;
        }
Пример #2
0
        public override IWzImageProperty DeepClone()
        {
            WzVectorProperty clone = (WzVectorProperty)MemberwiseClone();

            clone.x = (WzCompressedIntProperty)x.DeepClone();
            clone.y = (WzCompressedIntProperty)y.DeepClone();
            return(clone);
        }
Пример #3
0
        /// <summary>
        /// Gets the 'origin' position of the Canvas
        /// If not available, it defaults to xy of 0, 0
        /// </summary>
        /// <returns></returns>
        public PointF GetCanvasOriginPosition()
        {
            WzVectorProperty originPos = (WzVectorProperty)this[OriginPropertyName];

            if (originPos != null)
            {
                return(new PointF(originPos.X.Value, originPos.Y.Value));
            }

            return(new PointF(0, 0));
        }
Пример #4
0
        /// <summary>
        /// Gets the 'head' position of the Canvas
        /// If not available, it defaults to xy of 0, 0
        /// </summary>
        /// <returns></returns>
        public PointF GetCanvasLtPosition()
        {
            WzVectorProperty headPos = (WzVectorProperty)this[LtPropertyName];

            if (headPos != null)
            {
                return(new PointF(headPos.X.Value, headPos.Y.Value));
            }

            return(new PointF(0, 0));
        }
Пример #5
0
 public override WzImageProperty DeepClone()
 {
     WzVectorProperty clone = new WzVectorProperty(name, x, y);
     return clone;
 }
 internal static IExtended ExtractMore(WzBinaryReader reader, uint offset, int eob, string name, string iname, IWzObject parent, WzImage imgParent)
 {
     if (iname == "")
         iname = reader.ReadString();
     switch (iname)
     {
         case "Property":
             WzSubProperty subProp = new WzSubProperty(name) { Parent = parent };
             reader.BaseStream.Position += 2;
             subProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, subProp, imgParent));
             return subProp;
         case "Canvas":
             WzCanvasProperty canvasProp = new WzCanvasProperty(name) { Parent = parent };
             reader.BaseStream.Position++;
             if (reader.ReadByte() == 1)
             {
                 reader.BaseStream.Position += 2;
                 canvasProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, canvasProp, imgParent));
             }
             canvasProp.PngProperty = new WzPngProperty(reader, imgParent.parseEverything) { Parent = canvasProp };
             return canvasProp;
         case "Shape2D#Vector2D":
             WzVectorProperty vecProp = new WzVectorProperty(name) { Parent = parent };
             vecProp.X = new WzCompressedIntProperty("X", reader.ReadCompressedInt()) { Parent = vecProp };
             vecProp.Y = new WzCompressedIntProperty("Y", reader.ReadCompressedInt()) { Parent = vecProp };
             return vecProp;
         case "Shape2D#Convex2D":
             WzConvexProperty convexProp = new WzConvexProperty(name) { Parent = parent };
             int convexEntryCount = reader.ReadCompressedInt();
             convexProp.WzProperties.Capacity = convexEntryCount; //performance thing
             for (int i = 0; i < convexEntryCount; i++)
             {
                 convexProp.AddProperty(ParseExtendedProp(reader, offset, 0, name, convexProp, imgParent));
             }
             return convexProp;
         case "Sound_DX8":
             WzSoundProperty soundProp = new WzSoundProperty(name, reader, imgParent.parseEverything) { Parent = parent };
             return soundProp;
         case "UOL":
             reader.BaseStream.Position++;
             switch (reader.ReadByte())
             {
                 case 0:
                     return new WzUOLProperty(name, reader.ReadString()) { Parent = parent };
                 case 1:
                     return new WzUOLProperty(name, reader.ReadStringAtOffset(offset + reader.ReadInt32())) { Parent = parent };
             }
             throw new Exception("Unsupported UOL type");
         default:
             throw new Exception("Unknown iname: " + iname);
     }
 }
Пример #7
0
 private void CreateWzProp(IPropertyContainer parent, WzPropertyType propType, string propName, object value)
 {
     IWzImageProperty addedProp;
     switch (propType)
     {
         case WzPropertyType.ByteFloat:
             addedProp = new WzByteFloatProperty(propName);
             break;
         case WzPropertyType.Canvas:
             addedProp = new WzCanvasProperty(propName);
             ((WzCanvasProperty)addedProp).PngProperty = new WzPngProperty();
             break;
         case WzPropertyType.CompressedInt:
             addedProp = new WzCompressedIntProperty(propName);
             break;
         case WzPropertyType.Double:
             addedProp = new WzDoubleProperty(propName);
             break;
         /*case WzPropertyType.Sound:
             addedProp = new WzSoundProperty(propName);
             break;*/
         case WzPropertyType.String:
             addedProp = new WzStringProperty(propName);
             break;
         case WzPropertyType.UnsignedShort:
             addedProp = new WzUnsignedShortProperty(propName);
             break;
         case WzPropertyType.Vector:
             addedProp = new WzVectorProperty(propName);
             ((WzVectorProperty)addedProp).X = new WzCompressedIntProperty("X");
             ((WzVectorProperty)addedProp).Y = new WzCompressedIntProperty("Y");
             break;
         default:
             throw new NotSupportedException("not supported type");
     }
     addedProp.SetValue(value);
     parent.AddProperty(addedProp);
 }
Пример #8
0
        protected void SaveVector(WzVectorProperty pOrigin, string pName)
        {
            if (pOrigin == null)
            {
                return;
            }
            pName = pName.Replace('.', '_');

            SQLData.Instance.AppendRow(currentID, pName, "{VEC}" + pOrigin.X.ToInt().ToString() + ";" + pOrigin.Y.ToInt().ToString());
        }
        internal IWzImageProperty ParsePropertyFromXMLElement(XmlElement element)
        {
            switch (element.Name)
            {
                case "imgdir":
                    WzSubProperty sub = new WzSubProperty(element.GetAttribute("name"));
                    foreach (XmlElement subelement in element)
                        sub.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return sub;

                case "canvas":
                    WzCanvasProperty canvas = new WzCanvasProperty(element.GetAttribute("name"));
                    if (!element.HasAttribute("basedata")) throw new NoBase64DataException("no base64 data in canvas element with name " + canvas.Name);
                    canvas.PngProperty = new WzPngProperty();
                    MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(element.GetAttribute("basedata")));
                    canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true));
                    foreach (XmlElement subelement in element)
                        canvas.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return canvas;

                case "int":
                    WzCompressedIntProperty compressedInt = new WzCompressedIntProperty(element.GetAttribute("name"), int.Parse(element.GetAttribute("value"), formattingInfo));
                    return compressedInt;

                case "double":
                    WzDoubleProperty doubleProp = new WzDoubleProperty(element.GetAttribute("name"), double.Parse(element.GetAttribute("value"), formattingInfo));
                    return doubleProp;

                case "null":
                    WzNullProperty nullProp = new WzNullProperty(element.GetAttribute("name"));
                    return nullProp;

                case "sound":
                    if (!element.HasAttribute("basedata") || !element.HasAttribute("basehead") || !element.HasAttribute("length")) throw new NoBase64DataException("no base64 data in sound element with name " + element.GetAttribute("name"));
                    WzSoundProperty sound = new WzSoundProperty(element.GetAttribute("name"),
                        int.Parse(element.GetAttribute("length")),
                        Convert.FromBase64String(element.GetAttribute("basehead")),
                        Convert.FromBase64String(element.GetAttribute("basedata")));
                    return sound;

                case "string":
                    WzStringProperty stringProp = new WzStringProperty(element.GetAttribute("name"), element.GetAttribute("value"));
                    return stringProp;

                case "short":
                    WzUnsignedShortProperty shortProp = new WzUnsignedShortProperty(element.GetAttribute("name"), ushort.Parse(element.GetAttribute("value"), formattingInfo));
                    return shortProp;

                case "uol":
                    WzUOLProperty uol = new WzUOLProperty(element.GetAttribute("name"), element.GetAttribute("value"));
                    return uol;

                case "vector":
                    WzVectorProperty vector = new WzVectorProperty(element.GetAttribute("name"), new WzCompressedIntProperty("x", Convert.ToInt32(element.GetAttribute("x"))), new WzCompressedIntProperty("y", Convert.ToInt32(element.GetAttribute("y"))));
                    return vector;

                case "float":
                    WzByteFloatProperty floatProp = new WzByteFloatProperty(element.GetAttribute("name"), float.Parse(element.GetAttribute("value"), formattingInfo));
                    return floatProp;

                case "extended":
                    WzConvexProperty convex = new WzConvexProperty(element.GetAttribute("name"));
                    foreach (XmlElement subelement in element)
                        convex.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return convex;
            }
            throw new InvalidDataException("unknown XML prop " + element.Name);
        }
Пример #10
0
        public ObjectInfo Add(Bitmap bmp, string name)
        {
            if (!IsNameValid(name))
                throw new NameAlreadyUsedException();

            Point origin = new Point(bmp.Width / 2, bmp.Height / 2);

            WzSubProperty prop = new WzSubProperty();
            WzCanvasProperty canvasProp = new WzCanvasProperty();
            canvasProp.PngProperty = new WzPngProperty();
            canvasProp.PngProperty.SetPNG(bmp);
            canvasProp["origin"] = new WzVectorProperty("", new WzIntProperty("X", origin.X), new WzIntProperty("Y", origin.Y));
            canvasProp["z"] = new WzIntProperty("", 0);
            prop["0"] = canvasProp;

            ObjectInfo oi = new ObjectInfo(bmp, origin, oS, l0, l1, name, prop);
            newObjects.Add(oi);
            newObjectsData.Add(name, SaveImageToBytes(bmp));
            SerializeObjects();
            l1prop[name] = prop;

            return oi;
        }
Пример #11
0
 private static void ParseXML(XmlElement element, IPropertyContainer wo)
 {
     foreach (XmlNode node in element)
     {
         if (!(node is XmlElement)) continue;
         XmlElement childElement = (XmlElement)node;
         if (childElement.Name == "imgdir")
         {
             WzSubProperty sub = new WzSubProperty(childElement.GetAttribute("name"));
             wo.AddProperty(sub);
             ParseXML(childElement, (IPropertyContainer)sub);
         }
         else if (childElement.Name == "canvas")
         {
             WzCanvasProperty canvas = new WzCanvasProperty(childElement.GetAttribute("name"));
             canvas.PngProperty = new WzPngProperty();
             MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(childElement.GetAttribute("basedata")));
             canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true));
             wo.AddProperty(canvas);
             ParseXML(childElement, (IPropertyContainer)canvas);
         }
         if (childElement.Name == "int")
         {
             WzCompressedIntProperty compressedInt = new WzCompressedIntProperty(childElement.GetAttribute("name"), int.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(compressedInt);
         }
         if (childElement.Name == "double")
         {
             WzDoubleProperty doubleProp = new WzDoubleProperty(childElement.GetAttribute("name"), double.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(doubleProp);
         }
         if (childElement.Name == "null")
         {
             WzNullProperty nullProp = new WzNullProperty(childElement.GetAttribute("name"));
             wo.AddProperty(nullProp);
         }
         if (childElement.Name == "sound")
         {
             WzSoundProperty sound = new WzSoundProperty(childElement.GetAttribute("name"));
             sound.SetDataUnsafe(Convert.FromBase64String(childElement.GetAttribute("basedata")));
             wo.AddProperty(sound);
         }
         if (childElement.Name == "string")
         {
             string str = childElement.GetAttribute("value").Replace("&lt;", "<").Replace("&amp;", "&").Replace("&gt;", ">").Replace("&apos;", "'").Replace("&quot;", "\"");
             WzStringProperty stringProp = new WzStringProperty(childElement.GetAttribute("name"), str);
             wo.AddProperty(stringProp);
         }
         if (childElement.Name == "short")
         {
             WzUnsignedShortProperty shortProp = new WzUnsignedShortProperty(childElement.GetAttribute("name"), ushort.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(shortProp);
         }
         if (childElement.Name == "uol")
         {
             WzUOLProperty uol = new WzUOLProperty(childElement.GetAttribute("name"), childElement.GetAttribute("value"));
             wo.AddProperty(uol);
         }
         if (childElement.Name == "vector")
         {
             WzVectorProperty vector = new WzVectorProperty(childElement.GetAttribute("name"), new WzCompressedIntProperty("x", Convert.ToInt32(childElement.GetAttribute("x"))), new WzCompressedIntProperty("y", Convert.ToInt32(childElement.GetAttribute("y"))));
             wo.AddProperty(vector);
         }
         if (childElement.Name == "float")
         {
             WzByteFloatProperty floatProp = new WzByteFloatProperty(childElement.GetAttribute("name"), float.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(floatProp);
         }
         if (childElement.Name == "extended")
         {
             WzConvexProperty convex = new WzConvexProperty(childElement.GetAttribute("name"));
             wo.AddProperty(convex);
             ParseXML(childElement, (IPropertyContainer)convex);
         }
     }
 }
Пример #12
0
 public void SaveChairs()
 {
     if (board.BoardItems.Chairs.Count == 0)
     {
         return;
     }
     WzSubProperty chairParent = new WzSubProperty();
     for (int i = 0; i < board.BoardItems.Chairs.Count; i++)
     {
         Chair chairInst = board.BoardItems.Chairs[i];
         WzVectorProperty chair = new WzVectorProperty();
         chair.X = new WzIntProperty("X", chairInst.X);
         chair.Y = new WzIntProperty("Y", chairInst.Y);
         chairParent[i.ToString()] = chair;
     }
     image["seat"] = chairParent;
 }
Пример #13
0
        internal void ExtractMore(int eob, string name, string iname)
        {
            if (iname == "")
            {
                iname = reader.ReadString();
            }
            switch (iname)
            {
            case "Property":
                WzSubProperty subProp = new WzSubProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                reader.BaseStream.Position += 2;
                subProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, subProp, imgParent));
                extendedProperty = subProp;
                break;

            case "Canvas":
                WzCanvasProperty canvasProp = new WzCanvasProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                reader.BaseStream.Position++;
                if (reader.ReadByte() == 1)
                {
                    reader.BaseStream.Position += 2;
                    canvasProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, canvasProp, imgParent));
                }
                canvasProp.PngProperty = new WzPngProperty(reader)
                {
                    Parent = canvasProp, ParentImage = imgParent
                };
                extendedProperty = canvasProp;
                break;

            case "Shape2D#Vector2D":
                WzVectorProperty vecProp = new WzVectorProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                vecProp.X = new WzCompressedIntProperty("X", reader.ReadCompressedInt())
                {
                    Parent = vecProp, ParentImage = imgParent
                };
                vecProp.Y = new WzCompressedIntProperty("Y", reader.ReadCompressedInt())
                {
                    Parent = vecProp, ParentImage = imgParent
                };
                extendedProperty = vecProp;
                break;

            case "Shape2D#Convex2D":
                WzConvexProperty convexProp = new WzConvexProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                int convexEntryCount = reader.ReadCompressedInt();
                for (int i = 0; i < convexEntryCount; i++)
                {
                    WzExtendedProperty exProp = new WzExtendedProperty(offset, name)
                    {
                        Parent = convexProp, ParentImage = imgParent
                    };
                    exProp.ParseExtendedProperty(reader);
                    convexProp.AddProperty(exProp);
                }
                extendedProperty = convexProp;
                break;

            case "Sound_DX8":
                WzSoundProperty soundProp = new WzSoundProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                soundProp.ParseSound(reader);
                extendedProperty = soundProp;
                break;

            case "UOL":
                reader.BaseStream.Position++;
                extendedProperty = new WzUOLProperty(name, ExtractString())
                {
                    Parent = parent, ParentImage = imgParent
                };

                /*
                 * switch (reader.ReadByte())
                 *                  {
                 *                          case 0:
                 *                                  extendedProperty = new WzUOLProperty(name, reader.ReadString()) { Parent = parent, ParentImage = imgParent };
                 *                                  break;
                 *                          case 1:
                 *                                  extendedProperty = new WzUOLProperty(name, reader.ReadStringAtOffset(offset + reader.ReadInt32())) { Parent = parent, ParentImage = imgParent };
                 *                                  break;
                 *                  }
                 */
                break;
            }
        }
Пример #14
0
 public static Microsoft.Xna.Framework.Point VectorToXNAPoint(WzVectorProperty source)
 {
     return new Microsoft.Xna.Framework.Point(source.X.Value, source.Y.Value);
 }
Пример #15
0
 public static System.Drawing.Point VectorToSystemPoint(WzVectorProperty source)
 {
     return new System.Drawing.Point(source.X.Value, source.Y.Value);
 }
Пример #16
0
        public override WzImageProperty DeepClone()
        {
            WzVectorProperty clone = new WzVectorProperty(name, x, y);

            return(clone);
        }
Пример #17
0
		internal void ExtractMore(int eob, string name, string iname)
		{
			if (iname == "")
				iname = reader.ReadString();
			switch (iname)
			{
				case "Property":
					WzSubProperty subProp = new WzSubProperty(name) { Parent = parent, ParentImage = imgParent };
					reader.BaseStream.Position += 2;
					subProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, subProp, imgParent));
					extendedProperty = subProp;
					break;
				case "Canvas":
					WzCanvasProperty canvasProp = new WzCanvasProperty(name) { Parent = parent, ParentImage = imgParent };
					reader.BaseStream.Position++;
					if (reader.ReadByte() == 1)
					{
						reader.BaseStream.Position += 2;
						canvasProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, canvasProp, imgParent));
					}
					canvasProp.PngProperty = new WzPngProperty(reader) { Parent = canvasProp, ParentImage = imgParent };
					extendedProperty = canvasProp;
					break;
				case "Shape2D#Vector2D":
					WzVectorProperty vecProp = new WzVectorProperty(name) { Parent = parent, ParentImage = imgParent };
					vecProp.X = new WzCompressedIntProperty("X", reader.ReadCompressedInt()) { Parent = vecProp, ParentImage = imgParent };
					vecProp.Y = new WzCompressedIntProperty("Y", reader.ReadCompressedInt()) { Parent = vecProp, ParentImage = imgParent };
					extendedProperty = vecProp;
					break;
				case "Shape2D#Convex2D":
					WzConvexProperty convexProp = new WzConvexProperty(name) { Parent = parent, ParentImage = imgParent };
					int convexEntryCount = reader.ReadCompressedInt();
					for (int i = 0; i < convexEntryCount; i++)
					{
						WzExtendedProperty exProp = new WzExtendedProperty(offset, name) { Parent = convexProp, ParentImage = imgParent };
						exProp.ParseExtendedProperty(reader);
						convexProp.AddProperty(exProp);
					}
					extendedProperty = convexProp;
					break;
				case "Sound_DX8":
					WzSoundProperty soundProp = new WzSoundProperty(name) { Parent = parent, ParentImage = imgParent };
					soundProp.ParseSound(reader);
					extendedProperty = soundProp;
					break;
				case "UOL":
					reader.BaseStream.Position++;
                    extendedProperty = new WzUOLProperty(name, ExtractString()) { Parent = parent, ParentImage = imgParent };
                    /*
                    switch (reader.ReadByte())
					{
						case 0:
							extendedProperty = new WzUOLProperty(name, reader.ReadString()) { Parent = parent, ParentImage = imgParent };
							break;
						case 1:
							extendedProperty = new WzUOLProperty(name, reader.ReadStringAtOffset(offset + reader.ReadInt32())) { Parent = parent, ParentImage = imgParent };
							break;
					}
                    */
					break;
			}
		}