示例#1
0
 public void Load(StreamInfo input, BaseReadOnlyDirectoryNode fileSystem)
 {
     using (var br = new BinaryReaderX(input.FileData, Encoding.ASCII, LeaveOpen))
     {
         var header = br.ReadType <Header>();
         Layout = (RootLayoutElement)ReadLayout(br, null);
     }
 }
示例#2
0
        private LayoutElement ReadLayout(BinaryReaderX br, LayoutElement parent)
        {
            var type = br.ReadInt32();

            switch (type)
            {
            // Root pane
            case 1:
                var element = br.ReadType <RootElement>();
                var root    = new RootLayoutElement(new Size(element.width, element.height), new Point(element.x, element.y));

                for (int i = 0; i < element.childrenCount; i++)
                {
                    br.BaseStream.Position = element.childrenOffsets[i];
                    root.Children.Add(ReadLayout(br, root));
                }

                return(root);

            // window
            case 2:
                var element2 = br.ReadType <WindowElement>();

                if (element2.childrenCount <= 0)
                {
                    var window = new LeafLayoutElement(new Size(element2.width, element2.height), new Point(element2.x, element2.y), parent);
                    switch (element2.anchor)
                    {
                    case 1:
                        window.ParentAnchor = LocationAnchor.Center;
                        break;

                    case 2:
                        window.ParentAnchor = LocationAnchor.Bottom;
                        break;
                    }

                    return(window);
                }
                else
                {
                    var window = new ParentLayoutElement(new Size(element2.width, element2.height), new Point(element2.x, element2.y), parent);
                    switch (element2.anchor)
                    {
                    case 1:
                        window.ParentAnchor = LocationAnchor.Center;
                        break;

                    case 2:
                        window.ParentAnchor = LocationAnchor.Bottom;
                        break;
                    }

                    for (int i = 0; i < element2.childrenCount; i++)
                    {
                        br.BaseStream.Position = element2.childrenOffsets[i];
                        window.Children.Add(ReadLayout(br, window));
                    }

                    return(window);
                }

            default:
                throw new InvalidOperationException($"Element type {type} not supported.");
            }
        }