Ejemplo n.º 1
0
        public override void Load(XPathNodeIterator iterator, MpeParser parser)
        {
            MpeLog.Debug("MpeGroup.Load()");
            base.Load(iterator, parser);
            this.parser = parser;
            //Animation = parser.GetAnimation(iterator, "animation", Animation);
            //tags.Remove("animation");

            // Mpe Specific Tags
            bool firstLoad = false;

            if (parser.GetString(iterator, "mpe/layout", null) == null)
            {
                MpeLog.Debug("This is a group that has never been opened with MPE!");
                firstLoad = true;
                Left      = 0;
                Top       = 0;
            }
            LayoutStyle = parser.GetLayout(iterator, "mpe/layout", LayoutStyle);
            Spring      = parser.GetBoolean(iterator, "mpe/spring", Spring);
            Spacing     = parser.GetInt(iterator, "mpe/spacing", Spacing);
            Padding     = parser.GetPadding(iterator, "mpe/padding", Padding);
            // Child Controls
            XPathNodeIterator i = iterator.Current.Select("control");
            bool firstControl   = true;
            int  x = int.MaxValue;
            int  y = int.MaxValue;
            int  r = 0;
            int  b = 0;

            while (i.MoveNext())
            {
                XPathNodeIterator typeIterator = i.Current.SelectChildren("type", "");
                if (typeIterator.MoveNext())
                {
                    MpeControlType ctype = MpeControlType.Create(typeIterator.Current.Value);
                    if (firstControl && ctype == MpeControlType.Image)
                    {
                        firstControl = false;
                        backImage.Load(i, parser);
                    }
                    else
                    {
                        MpeControl c = parser.CreateControl(ctype);
                        Controls.Add(c);
                        c.Load(i, parser);
                        c.BringToFront();
                        if (firstLoad)
                        {
                            if (c.Left < x)
                            {
                                x = c.Left;
                            }
                            if (c.Top < y)
                            {
                                y = c.Top;
                            }
                            if ((c.Left + c.Width) > r)
                            {
                                r = c.Left + c.Width;
                            }
                            if ((c.Top + c.Height) > b)
                            {
                                b = c.Top + c.Height;
                            }
                        }
                    }
                }
            }
            if (firstLoad)
            {
                MpeLog.Info("x=" + x + " y=" + y);
                Left = x - 4;
                Top  = y - 4;
                for (int a = 0; a < Controls.Count; a++)
                {
                    if (Controls[a] is MpeControl)
                    {
                        Controls[a].Left -= x - 4;
                        Controls[a].Top  -= y - 4;
                    }
                }
                Width  = r - x + 8;
                Height = b - y + 8;
            }

            if (Spring)
            {
                Width  = parser.GetInt(iterator, "width", Width);
                Height = parser.GetInt(iterator, "height", Height);
            }
            Modified = false;
        }
Ejemplo n.º 2
0
        public override void Load(XPathNodeIterator iterator, MpeParser parser)
        {
            MpeLog.Debug("MpeScreen.Load()");
            this.parser = parser;
            XPathNodeIterator i = null;

            if (iterator == null)
            {
                throw new MpeParserException("The given iterator is invalid.");
            }
            if (iterator.Current.Name == "controls")
            {
                Width      = parser.GetInt(iterator, "skin/width", Width);
                Height     = parser.GetInt(iterator, "skin/height", Height);
                ScreenSize = MpeScreenSize.FromResolution(Width, Height);
                i          = iterator.Current.Select("control[type='image']");
                if (i.MoveNext())
                {
                    backImage.Load(i, parser);
                }
                Id = 0;
            }
            else if (iterator.Current.Name == "window")
            {
                string stype = parser.GetString(iterator, "type", "");
                if (stype == MpeScreenType.Dialog.ToString().ToLower())
                {
                    screenType = MpeScreenType.Dialog;
                }
                else if (stype == MpeScreenType.OnScreenDisplay.ToString().ToLower())
                {
                    screenType = MpeScreenType.OnScreenDisplay;
                }
                else
                {
                    screenType = MpeScreenType.Window;
                }

                Id             = parser.GetInt(iterator, "id", Id);
                AllowOverlay   = parser.GetBoolean(iterator, "allowoverlay", AllowOverlay);
                AutohideTopbar = parser.GetBoolean(iterator, "autohidetopbar", AutohideTopbar);
                DefaultControl = parser.GetInt(iterator, "defaultcontrol", DefaultControl);

                if (screenType == MpeScreenType.Dialog)
                {
                    // Initialize the default screen
                    MpeScreen defaultScreen = (MpeScreen)parser.GetControl(MpeControlType.Screen);
                    if (defaultScreen == null)
                    {
                        throw new MpeParserException("Reference screen was never initialized and loaded");
                    }
                    TextureBack = defaultScreen.TextureBack;
                    Size        = defaultScreen.Size;
                    AllowDrop   = false;
                    // First create the dialog group

                    MpeGroup dialog = (MpeGroup)parser.CreateControl(MpeControlType.Group);
                    dialog.Id          = DialogGroupId;
                    dialog.LayoutStyle = MpeLayoutStyle.Grid;
                    dialog.Parser      = Parser;
                    Controls.Add(dialog);

                    // Add all the controls
                    i = iterator.Current.Select("controls/control");
                    bool first = true;
                    while (i.MoveNext())
                    {
                        string s = parser.GetString(i, "type", "");
                        if (first && s == MpeControlType.Image.ToString())
                        {
                            first = false;
                            dialog.TextureBackImage.Load(i, parser);
                            dialog.Size     = dialog.TextureBackImage.Size;
                            dialog.Location = dialog.TextureBackImage.Location;
                        }
                        else
                        {
                            XPathNodeIterator typeIterator = i.Current.SelectChildren("type", "");
                            if (typeIterator.MoveNext())
                            {
                                MpeControlType type = MpeControlType.Create(typeIterator.Current.Value);
                                MpeControl     c    = parser.CreateControl(type);
                                dialog.Controls.Add(c);
                                c.Load(i, parser);
                                c.BringToFront();
                            }
                        }
                    }
                }
                else
                {
                    AllowDrop = true;
                    i         = iterator.Current.Select("controls/control");
                    bool first = true;
                    while (i.MoveNext())
                    {
                        string s = parser.GetString(i, "type", "");
                        if (first && s == MpeControlType.Image.ToString())
                        {
                            backImage.Load(i, parser);
                        }
                        else
                        {
                            XPathNodeIterator typeIterator = i.Current.SelectChildren("type", "");
                            if (typeIterator.MoveNext())
                            {
                                MpeControlType type = MpeControlType.Create(typeIterator.Current.Value);
                                MpeControl     c    = parser.CreateControl(type);
                                Controls.Add(c);
                                c.Load(i, parser);
                                c.BringToFront();
                            }
                        }
                        first = false;
                    }
                }
            }
            Modified = false;
        }