Exemple #1
0
 private static void Write(AssetStreamWriter writer, UIEditText o, List <object> objectDictionary)
 {
     Write(writer, (UILabel)o, objectDictionary);
     writer.Write((byte)o.Format);
     writer.WriteBibimString(o.Placeholder);
     writer.Write(o.MaxLength);
     writer.Write(o.Frozen);
     writer.WriteBibimString(o.EditorTitle);
     writer.WriteBibimString(o.EditorDescription);
 }
Exemple #2
0
 private void Process(UIEditText label, PhotoshopDocument.Layer layer)
 {
     Process((UILabel)label, layer);
 }
Exemple #3
0
        private UIVisual AddChildTo(UIWindow window, PhotoshopDocument.Layer layer)
        {
            if (string.IsNullOrEmpty(layer.Name) ||
                layer.Name.StartsWith("#") == false)
            {
                return(null);
            }

            string name;
            string type;
            Dictionary <string, string> args;

            ParseLayerName(layer.Name, out name, out type, out args);

            if (layer.IsGroup == false)
            {
                if (string.Compare(type, "UIMarkupLabel", true) == 0 ||
                    string.Compare(type, "MarkupLabel", true) == 0 ||
                    string.Compare(type, "Label", true) == 0)
                {
                    UILabel label = new UILabel();
                    label.Name = name;
                    if (args.ContainsKey("0"))
                    {
                        label.Text = args["0"];
                    }
                    window.AddChild(label);
                    Process(label, layer);
                    return(label);
                }
                else if (string.Compare(type, "Document", true) == 0 ||
                         string.Compare(type, "Doc", true) == 0)
                {
                    UIDocument document = new UIDocument();
                    document.Name = name;
                    if (args.ContainsKey("0"))
                    {
                        document.Text = args["0"];
                    }
                    window.AddChild(document);
                    Process(document, layer);
                    return(document);
                }
                else if (string.Compare(type, "Edit", true) == 0 ||
                         string.Compare(type, "EditText", true) == 0 ||
                         string.Compare(type, "EditBox", true) == 0)
                {
                    UIEditText editText = new UIEditText();
                    editText.Name = name;
                    if (args.ContainsKey("0"))
                    {
                        editText.Text = args["0"];
                    }
                    window.AddChild(editText);
                    Process(editText, layer);
                    return(editText);
                }
                else if (string.Compare(type, "9Patch", true) == 0 ||
                         string.Compare(type, "NinePatch", true) == 0 ||
                         string.Compare(type, "9P", true) == 0 ||
                         string.Compare(type, "9P*", true) == 0)
                {
                    UIWindow childWindow = new UIWindow();
                    childWindow.Name = name;
                    window.AddChild(childWindow);
                    Process((UIPanel)childWindow, layer);

                    int bw = layer.Bitmap.Width;
                    int bh = layer.Bitmap.Height;

                    int leftBorder   = 0;
                    int topBorder    = 0;
                    int rightBorder  = 0;
                    int bottomBorder = 0;
                    switch (args.Count)
                    {
                    case 0:
                        leftBorder   = bw / 10;
                        topBorder    = bh / 10;
                        rightBorder  = leftBorder;
                        bottomBorder = topBorder;
                        break;

                    case 1:
                        leftBorder   = int.Parse(args["0"] ?? "0");
                        topBorder    = leftBorder;
                        rightBorder  = leftBorder;
                        bottomBorder = leftBorder;
                        break;

                    default:
                        leftBorder   = int.Parse(args["0"] ?? "0");
                        topBorder    = int.Parse(args["1"] ?? "0");
                        rightBorder  = int.Parse(args["2"] ?? "0");
                        bottomBorder = int.Parse(args["3"] ?? "0");
                        break;
                    }

                    int horizontalBorder = leftBorder + rightBorder;
                    int verticalBorder   = topBorder + bottomBorder;

                    Bitmap leftTopImage     = layer.Bitmap.Clip(new Rectangle(0, 0, leftBorder, topBorder));
                    Bitmap rightTopImage    = layer.Bitmap.Clip(new Rectangle(bw - rightBorder, 0, rightBorder, topBorder));
                    Bitmap leftBottomImage  = layer.Bitmap.Clip(new Rectangle(0, bh - bottomBorder, leftBorder, bottomBorder));
                    Bitmap rightBottomImage = layer.Bitmap.Clip(new Rectangle(bw - rightBorder, bh - bottomBorder, rightBorder, bottomBorder));
                    Bitmap leftImage        = layer.Bitmap.Clip(new Rectangle(0, topBorder, leftBorder, bh - verticalBorder));
                    Bitmap topImage         = layer.Bitmap.Clip(new Rectangle(leftBorder, 0, bw - horizontalBorder, topBorder));
                    Bitmap rightImage       = layer.Bitmap.Clip(new Rectangle(bw - rightBorder, topBorder, rightBorder, bh - verticalBorder));
                    Bitmap bottomImage      = layer.Bitmap.Clip(new Rectangle(leftBorder, bh - bottomBorder, bw - horizontalBorder, bottomBorder));
                    Bitmap centerImage      = layer.Bitmap.Clip(new Rectangle(leftBorder, topBorder, Math.Max(bw - horizontalBorder, 1), Math.Max(bh - verticalBorder, 1)));

                    var images = new List <UIImage>(9);
                    images.Add(CreateNinePatchPart(leftTopImage, UIAnchorPoint.LeftTop, new Vector2(0.0f, 0.0f), 0, 0, leftBorder, topBorder, UISizeMode.Absolute, UISizeMode.Absolute));
                    images.Add(CreateNinePatchPart(rightTopImage, UIAnchorPoint.RightTop, new Vector2(1.0f, 0.0f), 0, 0, rightBorder, topBorder, UISizeMode.Absolute, UISizeMode.Absolute));
                    images.Add(CreateNinePatchPart(leftBottomImage, UIAnchorPoint.LeftBottom, new Vector2(0.0f, 1.0f), 0, 0, leftBorder, bottomBorder, UISizeMode.Absolute, UISizeMode.Absolute));
                    images.Add(CreateNinePatchPart(rightBottomImage, UIAnchorPoint.RightBottom, new Vector2(1.0f, 1.0f), 0, 0, rightBorder, bottomBorder, UISizeMode.Absolute, UISizeMode.Absolute));

                    images.Add(CreateNinePatchPart(leftImage, UIAnchorPoint.LeftTop, new Vector2(0.0f, 0.0f), 0, topBorder, leftBorder, -verticalBorder, UISizeMode.Absolute, UISizeMode.Adjustive));           // left
                    images.Add(CreateNinePatchPart(topImage, UIAnchorPoint.LeftTop, new Vector2(0.0f, 0.0f), leftBorder, 0, -horizontalBorder, topBorder, UISizeMode.Adjustive, UISizeMode.Absolute));          // top
                    images.Add(CreateNinePatchPart(rightImage, UIAnchorPoint.RightTop, new Vector2(1.0f, 0.0f), 0, topBorder, rightBorder, -verticalBorder, UISizeMode.Absolute, UISizeMode.Adjustive));        // right
                    images.Add(CreateNinePatchPart(bottomImage, UIAnchorPoint.LeftBottom, new Vector2(0.0f, 1.0f), leftBorder, 0, -horizontalBorder, bottomBorder, UISizeMode.Adjustive, UISizeMode.Absolute)); // bototm

                    bool forceSingleColor = false;
                    if (string.Compare(type, "9P*", true) == 0)
                    {
                        forceSingleColor = true;
                    }

                    images.Add(CreateNinePatchPart(
                                   centerImage,
                                   UIAnchorPoint.LeftTop,
                                   new Vector2(0.0f, 0.0f),
                                   leftBorder,
                                   topBorder,
                                   -horizontalBorder,
                                   -verticalBorder,
                                   UISizeMode.Adjustive,
                                   UISizeMode.Adjustive,
                                   forceSingleColor: forceSingleColor));

                    foreach (var item in images)
                    {
                        if (item != null)
                        {
                            childWindow.AddChild(item);
                        }
                    }
                    return(childWindow);
                }
                else
                {
                    UIImage image = new UIImage();
                    image.Name = name;
                    window.AddChild(image);
                    Process(image, layer, string.Compare(type, "MaskImage", true) == 0 || string.Compare(type, "MaskSprite", true) == 0);
                    return(image);
                }
            }
            else
            {
                if (string.Compare(type, "Button", true) == 0)
                {
                    UIButton button = new UIButton();
                    button.Name = name;
                    window.AddChild(button);
                    Process(button, layer);
                    return(button);
                }
                else if (string.Compare(type, "CheckBox", true) == 0)
                {
                    UICheckBox button = new UICheckBox();
                    button.Name = name;
                    window.AddChild(button);
                    Process(button, layer);
                    return(button);
                }
                else if (string.Compare(type, "Radio", true) == 0)
                {
                    UIRadioButton button = new UIRadioButton();
                    button.Name = name;
                    window.AddChild(button);
                    Process(button, layer);
                    return(button);
                }
                else if (string.Compare(type, "Scrollable", true) == 0)
                {
                    UIScrollablePanel panel = new UIScrollablePanel();
                    panel.Name = name;
                    window.AddChild(panel);
                    Process(panel, layer);
                    return(panel);
                }
                else
                {
                    bool hasNormal          = layer.FindSubLayer("#Normal", false) != null;
                    bool hasPushed          = layer.FindSubLayer("#Pushed", false) != null;
                    bool hasHovering        = layer.FindSubLayer("#Hovering", false) != null;
                    bool hasCheckedNormal   = layer.FindSubLayer("#CheckedNormal", false) != null;
                    bool hasCheckedPushed   = layer.FindSubLayer("#CheckedPushed", false) != null;
                    bool hasCheckedHovering = layer.FindSubLayer("#CheckedHovering", false) != null;
                    if (hasNormal && hasPushed && !hasCheckedNormal && !hasCheckedPushed)
                    {
                        UIButton button = new UIButton();
                        button.Name = name;
                        window.AddChild(button);
                        Process(button, layer);
                        return(button);
                    }
                    else if (hasNormal && hasCheckedNormal)
                    {
                        UICheckBox button = new UICheckBox();
                        button.Name = name;
                        window.AddChild(button);
                        Process(button, layer);
                        return(button);
                    }
                    else
                    {
                        UIWindow childWindow = new UIWindow();
                        childWindow.Name = name;
                        window.AddChild(childWindow);
                        Process(childWindow, layer);
                        return(childWindow);
                    }
                }
            }
        }