Ejemplo n.º 1
0
        public SnoopWindow()
        {
            itemsView = new UIWindow();
            //itemsView.X = spacing;
            //itemsView.Y = spacing;
            for (int i = 0; i < 50; i++)
            {
                Slot slot = new Slot(0, true);
                slot.ItemChanged += itemSlot_ItemChanged;
                slot.X            = 8 + i % 10 * slot.Width;
                slot.Y            = 8 + i / 10 * slot.Height;

                itemsView.AddChild(slot);
            }
            Width = itemsView.GetLastChild().X + itemsView.GetLastChild().Width + 8;
            float yPos = itemsView.GetLastChild().Y + itemsView.GetLastChild().Height + 10;

            for (int i = 50; i < 58; i++)
            {
                int  index = i - 50;
                Slot slot  = new Slot(0, true);
                slot.Scale = .6f;
                slot.X     = 8 + index % 2 * slot.Width;
                slot.Y     = yPos + index / 2 * slot.Height;
                itemsView.AddChild(slot);
            }
            Slot mouseSlot = new Slot(0, true);

            mouseSlot.X = itemsView.GetLastChild().X + itemsView.GetLastChild().Width + 4;
            mouseSlot.Y = itemsView.GetLastChild().Y + itemsView.GetLastChild().Height - mouseSlot.Height;
            itemsView.AddChild(mouseSlot);
            float xPos = mouseSlot.X + mouseSlot.Width + 4;

            for (int i = 0; i < 16; i++)
            {
                Slot slot = new Slot(0, true);
                slot.Scale = .7f;
                slot.X     = xPos + i % 8 * slot.Width;
                slot.Y     = yPos + i / 8 * slot.Height;
                itemsView.AddChild(slot);
            }
            AddChild(itemsView);
            Height = mouseSlot.Y + mouseSlot.Height + 8;

            itemsView.Width  = Width;
            itemsView.Height = Height;

            UILabel label = new UILabel("Mouse Item");

            label.Scale  = .5f;
            label.Anchor = AnchorPosition.Left;
            label.Y      = mouseSlot.Y + mouseSlot.Height / 2 + 4;
            label.X      = mouseSlot.X + mouseSlot.Width + 4;
            itemsView.AddChild(label);
        }
Ejemplo n.º 2
0
        void InitWindow()
        {
            var layout = new UILayout();

            layout.Axis = UI_AXIS.UI_AXIS_Y;

            var checkBox = new UICheckBox();

            checkBox.Id = "Checkbox";

            layout.AddChild(checkBox);

            var button = new UIButton();

            button.Text = "Button";
            button.Id   = "Button";

            layout.AddChild(button);

            var edit = new UIEditField();

            layout.AddChild(edit);
            edit.Id = "EditField";

            window          = new UIWindow();
            window.Settings = UI_WINDOW_SETTINGS.UI_WINDOW_SETTINGS_TITLEBAR | UI_WINDOW_SETTINGS.UI_WINDOW_SETTINGS_CLOSE_BUTTON;

            window.Text = "Hello Atomic GUI!";

            window.AddChild(layout);

            window.ResizeToFitContent();

            UIView.AddChild(window);
            window.Center();

            SubscribeToEvent <WidgetEvent>(window, e =>
            {
                if (e.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
                {
                    var target = e.Target;
                    if (target != null)
                    {
                        window.Text = $"Hello: {target.Id}";
                    }
                }
            });

            SubscribeToEvent <WidgetDeletedEvent>(window, e =>
            {
                BackToSelector();
            });
        }
Ejemplo n.º 3
0
        void InitWindow()
        {
            var layout = new UILayout();
            layout.Axis = UI_AXIS.UI_AXIS_Y;

            var checkBox = new UICheckBox();
            checkBox.Id = "Checkbox";

            layout.AddChild(checkBox);

            var button = new UIButton();
            button.Text = "Button";
            button.Id = "Button";

            layout.AddChild(button);

            var edit = new UIEditField();
            layout.AddChild(edit);
            edit.Id = "EditField";

            window = new UIWindow();
            window.Settings = UI_WINDOW_SETTINGS.UI_WINDOW_SETTINGS_TITLEBAR | UI_WINDOW_SETTINGS.UI_WINDOW_SETTINGS_CLOSE_BUTTON;

            window.Text = "Hello Atomic GUI!";

            window.AddChild(layout);

            window.ResizeToFitContent();

            UIView.AddChild(window);
            window.Center();

            SubscribeToEvent<WidgetEvent>(window, e =>
            {
                if (e.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
                {
                    var target = e.Target;
                    if (target != null)
                    {
                        window.Text = $"Hello: {target.Id}";
                    }

                }

            });

            SubscribeToEvent<WidgetDeletedEvent>(window, e =>
            {
                BackToSelector();
            });
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }