Ejemplo n.º 1
0
        public static ElementWindow CreateWindowFromDescriptor(WindowDescriptor windowDescriptor)
        {
            ElementDescriptorMain mainDescriptor = windowDescriptor.MainElementDescriptor;
            ElementWindow         elementWindow  = new ElementWindow();
            List <IElement>       elements       = new List <IElement>();

            elementWindow.ElementDescriptor = mainDescriptor;
            foreach (ElementDescriptor elementDescriptor in windowDescriptor.ElementDescriptors)
            {
                if (elementDescriptor != mainDescriptor)
                {
                    try {
                        IElement element = CreateElementFromDescriptor(elementDescriptor);

                        elements.Add(element);
                        elementWindow.Children.Add((UIElement)element);
                    } catch (Exception e) {
                        Console.WriteLine("Error while creating an interface element: " + e.Message);
                    }
                }
            }

            elementWindow.ChildElements       = elements.ToArray();
            elementWindow.Margin              = new Thickness(0, 0, 0, 0);
            elementWindow.HorizontalAlignment = HorizontalAlignment.Stretch;
            elementWindow.VerticalAlignment   = VerticalAlignment.Stretch;
            elementWindow.SizeChanged        += (object sender, SizeChangedEventArgs e) => UpdateAnchors(elementWindow, elements);

            return(elementWindow);
        }
Ejemplo n.º 2
0
        public ElementDescriptorMain ElementMain(string elementName)
        {
            ElementDescriptorMain element = new ElementDescriptorMain(elementName);

            TokenType[] attributeTypes = new TokenType[] {
                TokenType.DMF_IsPane,
                TokenType.DMF_Macro,
                TokenType.DMF_Menu,
                TokenType.DMF_StatusBar
            };

            Token attributeToken = Current();

            while (Check(_sharedElementAttributeTypes) || Check(attributeTypes))
            {
                Consume(TokenType.DMF_Equals, "Expected '='");

                switch (attributeToken.Type)
                {
                case TokenType.DMF_IsPane: element.IsPane = Boolean(); break;

                case TokenType.DMF_Macro: String(); break;

                case TokenType.DMF_Menu: String(); break;

                case TokenType.DMF_StatusBar: Boolean(); break;

                default: SetSharedAttribute(element, attributeToken); break;
                }

                Newline();
                attributeToken = Current();
            }

            return(element);
        }
Ejemplo n.º 3
0
        public void ReadFromStream(PacketStream stream)
        {
            List <WindowDescriptor> windowDescriptors = new List <WindowDescriptor>();

            int windowCount = stream.ReadByte();

            for (int i = 0; i < windowCount; i++)
            {
                string windowName = stream.ReadString();
                List <ElementDescriptor> elementDescriptors = new List <ElementDescriptor>();

                int elementCount = stream.ReadByte();
                for (int j = 0; j < elementCount; j++)
                {
                    string            elementName = stream.ReadString();
                    DescriptorType    elementType = (DescriptorType)stream.ReadByte();
                    ElementDescriptor elementDescriptor;

                    switch (elementType)
                    {
                    case DescriptorType.Main: elementDescriptor = new ElementDescriptorMain(elementName); break;

                    case DescriptorType.Input: elementDescriptor = new ElementDescriptorInput(elementName); break;

                    case DescriptorType.Button: elementDescriptor = new ElementDescriptorButton(elementName); break;

                    case DescriptorType.Child: elementDescriptor = new ElementDescriptorChild(elementName); break;

                    case DescriptorType.Output: elementDescriptor = new ElementDescriptorOutput(elementName); break;

                    case DescriptorType.Info: elementDescriptor = new ElementDescriptorInfo(elementName); break;

                    case DescriptorType.Map: elementDescriptor = new ElementDescriptorMap(elementName); break;

                    case DescriptorType.Browser: elementDescriptor = new ElementDescriptorBrowser(elementName); break;

                    default: throw new Exception("Invalid descriptor type '" + elementType + "'");
                    }

                    elementDescriptors.Add(elementDescriptor);

                    AttributeType valueType;
                    do
                    {
                        valueType = (AttributeType)stream.ReadByte();
                        switch (valueType)
                        {
                        case AttributeType.Pos: elementDescriptor.Pos = new Point(stream.ReadUInt16(), stream.ReadUInt16()); break;

                        case AttributeType.Size: elementDescriptor.Size = new Size(stream.ReadUInt16(), stream.ReadUInt16()); break;

                        case AttributeType.Anchor1: elementDescriptor.Anchor1 = new Point(stream.ReadUInt16(), stream.ReadUInt16()); break;

                        case AttributeType.Anchor2: elementDescriptor.Anchor2 = new Point(stream.ReadUInt16(), stream.ReadUInt16()); break;

                        case AttributeType.BackgroundColor: elementDescriptor.BackgroundColor = Color.FromArgb(stream.ReadByte(), stream.ReadByte(), stream.ReadByte()); break;

                        case AttributeType.IsVisible: elementDescriptor.IsVisible = stream.ReadBool(); break;

                        case AttributeType.IsDefault: elementDescriptor.IsDefault = stream.ReadBool(); break;

                        case AttributeType.IsPane: ((ElementDescriptorMain)elementDescriptor).IsPane = stream.ReadBool(); break;

                        case AttributeType.Left: ((ElementDescriptorChild)elementDescriptor).Left = stream.ReadString(); break;

                        case AttributeType.Right: ((ElementDescriptorChild)elementDescriptor).Right = stream.ReadString(); break;

                        case AttributeType.IsVert: ((ElementDescriptorChild)elementDescriptor).IsVert = stream.ReadBool(); break;

                        case AttributeType.Text:
                            if (elementDescriptor is ElementDescriptorButton)
                            {
                                ((ElementDescriptorButton)elementDescriptor).Text = stream.ReadString();
                            }
                            break;


                        case AttributeType.End: break;

                        default: throw new Exception("Invalid attribute type '" + valueType + "'");
                        }
                    } while (valueType != AttributeType.End);
                }

                WindowDescriptor windowDescriptor = new WindowDescriptor(windowName, elementDescriptors);
                windowDescriptors.Add(windowDescriptor);
            }

            InterfaceDescriptor = new InterfaceDescriptor(windowDescriptors);
        }
Ejemplo n.º 4
0
        public void WriteToStream(PacketStream stream)
        {
            stream.WriteByte((byte)InterfaceDescriptor.WindowDescriptors.Count);

            foreach (WindowDescriptor windowDescriptor in InterfaceDescriptor.WindowDescriptors)
            {
                stream.WriteString(windowDescriptor.Name);

                stream.WriteByte((byte)windowDescriptor.ElementDescriptors.Count);
                foreach (ElementDescriptor elementDescriptor in windowDescriptor.ElementDescriptors)
                {
                    stream.WriteString(elementDescriptor.Name);

                    if (elementDescriptor is ElementDescriptorMain)
                    {
                        stream.WriteByte((byte)DescriptorType.Main);
                    }
                    else if (elementDescriptor is ElementDescriptorChild)
                    {
                        stream.WriteByte((byte)DescriptorType.Child);
                    }
                    else if (elementDescriptor is ElementDescriptorInput)
                    {
                        stream.WriteByte((byte)DescriptorType.Input);
                    }
                    else if (elementDescriptor is ElementDescriptorButton)
                    {
                        stream.WriteByte((byte)DescriptorType.Button);
                    }
                    else if (elementDescriptor is ElementDescriptorOutput)
                    {
                        stream.WriteByte((byte)DescriptorType.Output);
                    }
                    else if (elementDescriptor is ElementDescriptorInfo)
                    {
                        stream.WriteByte((byte)DescriptorType.Info);
                    }
                    else if (elementDescriptor is ElementDescriptorMap)
                    {
                        stream.WriteByte((byte)DescriptorType.Map);
                    }
                    else if (elementDescriptor is ElementDescriptorBrowser)
                    {
                        stream.WriteByte((byte)DescriptorType.Browser);
                    }
                    else
                    {
                        throw new Exception("Invalid descriptor");
                    }

                    if (elementDescriptor.Pos.HasValue)
                    {
                        stream.WriteByte((byte)AttributeType.Pos);
                        stream.WriteUInt16((UInt16)elementDescriptor.Pos.Value.X);
                        stream.WriteUInt16((UInt16)elementDescriptor.Pos.Value.Y);
                    }

                    if (elementDescriptor.Size.HasValue)
                    {
                        stream.WriteByte((byte)AttributeType.Size);
                        stream.WriteUInt16((UInt16)elementDescriptor.Size.Value.Width);
                        stream.WriteUInt16((UInt16)elementDescriptor.Size.Value.Height);
                    }

                    if (elementDescriptor.Anchor1.HasValue)
                    {
                        stream.WriteByte((byte)AttributeType.Anchor1);
                        stream.WriteUInt16((UInt16)elementDescriptor.Anchor1.Value.X);
                        stream.WriteUInt16((UInt16)elementDescriptor.Anchor1.Value.Y);
                    }

                    if (elementDescriptor.Anchor2.HasValue)
                    {
                        stream.WriteByte((byte)AttributeType.Anchor2);
                        stream.WriteUInt16((UInt16)elementDescriptor.Anchor2.Value.X);
                        stream.WriteUInt16((UInt16)elementDescriptor.Anchor2.Value.Y);
                    }

                    if (elementDescriptor.BackgroundColor.HasValue)
                    {
                        stream.WriteByte((byte)AttributeType.BackgroundColor);
                        stream.WriteByte(elementDescriptor.BackgroundColor.Value.R);
                        stream.WriteByte(elementDescriptor.BackgroundColor.Value.G);
                        stream.WriteByte(elementDescriptor.BackgroundColor.Value.B);
                    }

                    if (elementDescriptor.IsVisible != default)
                    {
                        stream.WriteByte((byte)AttributeType.IsVisible);
                        stream.WriteBool(elementDescriptor.IsVisible.Value);
                    }

                    if (elementDescriptor.IsDefault != default)
                    {
                        stream.WriteByte((byte)AttributeType.IsDefault);
                        stream.WriteBool(elementDescriptor.IsDefault);
                    }

                    ElementDescriptorMain elementMainDescriptor = elementDescriptor as ElementDescriptorMain;
                    if (elementMainDescriptor != null)
                    {
                        if (elementMainDescriptor.IsPane != default)
                        {
                            stream.WriteByte((byte)AttributeType.IsPane);
                            stream.WriteBool(elementMainDescriptor.IsPane);
                        }
                    }

                    ElementDescriptorChild elementChildDescriptor = elementDescriptor as ElementDescriptorChild;
                    if (elementChildDescriptor != null)
                    {
                        if (elementChildDescriptor.Left != null)
                        {
                            stream.WriteByte((byte)AttributeType.Left);
                            stream.WriteString(elementChildDescriptor.Left);
                        }

                        if (elementChildDescriptor.Right != null)
                        {
                            stream.WriteByte((byte)AttributeType.Right);
                            stream.WriteString(elementChildDescriptor.Right);
                        }

                        if (elementChildDescriptor.IsVert != default)
                        {
                            stream.WriteByte((byte)AttributeType.IsVert);
                            stream.WriteBool(elementChildDescriptor.IsVert);
                        }
                    }

                    ElementDescriptorButton elementButtonDescriptor = elementDescriptor as ElementDescriptorButton;
                    if (elementButtonDescriptor != null)
                    {
                        if (elementButtonDescriptor.Text != null)
                        {
                            stream.WriteByte((byte)AttributeType.Text);
                            stream.WriteString(elementButtonDescriptor.Text);
                        }
                    }

                    stream.WriteByte((byte)AttributeType.End);
                }
            }
        }