Пример #1
0
        public void Restore(Stream str)
        {
            if (str.ReadByte() == 0)
            {
                if (str.ReadByte() == 1)
                {
                    ComponentFont = str.ReadShort();
                }
                else
                {
                    ComponentFont = null;
                }

                if (str.ReadByte() == 1)
                {
                    PaintStyle fg = new PaintStyle();
                    fg.Restore(str);

                    ComponentForeground = fg;
                }
                else
                {
                    ComponentForeground = null;
                }

                if (str.ReadByte() == 1)
                {
                    PaintStyle bg = new PaintStyle();
                    bg.Restore(str);

                    ComponentBackground = bg;
                }
                else
                {
                    ComponentBackground = null;
                }

                MarginLeft   = str.ReadInteger();
                MarginTop    = str.ReadInteger();
                MarginRight  = str.ReadInteger();
                MarginBottom = str.ReadInteger();

                PaddingLeft   = str.ReadInteger();
                PaddingTop    = str.ReadInteger();
                PaddingRight  = str.ReadInteger();
                PaddingBottom = str.ReadInteger();

                int slotInfoCount = str.ReadInteger();

                if (slotInfoCount > 0)
                {
                    for (int i = 0; i < slotInfoCount; i++)
                    {
                        SlotData slot = new SlotData();
                        slot.Restore(str);

                        SlotInfo.Add(slot);
                    }
                }

                LayoutTemplate = CacheHelper.UnpackFromStream(str) as LayoutTemplateBase;
            }
        }
Пример #2
0
        public void Unpack(FieldList source)
        {
            if (source == null)
            {
                return;
            }

            UnpackDefinitionID(source);

            IsCheckable       = false;
            DeviceTextScaling = false;

            // unpacking common attributes
            SpecialTag            = source[DefAgentFieldID.DefinitionSpecialTag].AsInteger() ?? -1;
            BackgroundImageCrop   = (CropStrategy)(source[DefAgentFieldID.BackgroundCropStrategy].AsNumber() ?? 0);
            SizeToBackgroundImage = source[DefAgentFieldID.BlockSizeToBackground].AsBoolean() ?? false;
            AcceptsFocus          = source[DefAgentFieldID.AcceptsFocus].AsBoolean() ?? false;
            SortIndex             = source[DefAgentFieldID.SortSlotIndex].AsShort() ?? -1;

            // static display data
            int numberOfDisplayData = source.GetItemCount(MessageOutFieldID.SlotDisplayDataTypeID);

            if (numberOfDisplayData > 0)
            {
                StaticDisplayData = DisplayData.Parse(source);
            }

            // loop through states
            PairedList <ByteField, FieldList> states =
                source.GetPairedItems <ByteField, FieldList>(DefAgentFieldID.ComponentState, DefAgentFieldID.DataPerComponentState);

            foreach (Pair <ByteField, FieldList> item in states)
            {
                BlockState state   = (BlockState)item.First.Data;
                FieldList  newData = item.Second;

                AtomicBlockStateData data = GetOrCreateDataForState(state);

                // mark as checkable if applicable
                if ((state == BlockState.CheckedNormal) || (state == BlockState.CheckedFocused))
                {
                    IsCheckable = true;
                }

                // set paint styles
                data.ComponentForeground = new PaintStyle(newData, DefAgentFieldID.ForegroundPaintStyle);
                data.ComponentBackground = new PaintStyle(newData, DefAgentFieldID.BackgroundPaintStyle);

                // font reference
                data.ComponentFont = newData[DefAgentFieldID.FontReference].AsShort() ?? 0;

                // margins and paddings
                data.MarginLeft    = newData[DefAgentFieldID.LeftMargin2].AsShort() ?? 0;
                data.MarginTop     = newData[DefAgentFieldID.TopMargin2].AsShort() ?? 0;
                data.MarginRight   = newData[DefAgentFieldID.RightMargin].AsShort() ?? 0;
                data.MarginBottom  = newData[DefAgentFieldID.BottomMargin].AsShort() ?? 0;
                data.PaddingLeft   = newData[DefAgentFieldID.LeftPadding2].AsShort() ?? 0;
                data.PaddingTop    = newData[DefAgentFieldID.TopPadding2].AsShort() ?? 0;
                data.PaddingRight  = newData[DefAgentFieldID.RightPadding].AsShort() ?? 0;
                data.PaddingBottom = newData[DefAgentFieldID.BottomPadding].AsShort() ?? 0;

                // slot data
                List <FieldList> slotsData = newData.GetItems <FieldList>(DefAgentFieldID.SlotData);

                foreach (FieldList sd in slotsData)
                {
                    SlotData info = new SlotData();

                    info.Foreground = new PaintStyle(sd, DefAgentFieldID.ForegroundPaintStyle);
                    info.Background = new PaintStyle(sd, DefAgentFieldID.BackgroundPaintStyle);
                    info.Font       = sd[DefAgentFieldID.FontReference].AsShort() ?? 0;
                    info.SlotIndex  = sd[DefAgentFieldID.SlotIndex].AsShort() ?? 0;

                    // rendering hints
                    if ((SlotHints == null) || (SlotHints.Length <= info.SlotIndex) || (SlotHints[(int)info.SlotIndex] == null))
                    {
                        string newSlotHint = sd[DefAgentFieldID.SlotHint].AsString();

                        if (newSlotHint != null)
                        {
                            if (SlotHints == null)
                            {
                                SlotHints = new string[Math.Max(slotsData.Count, (int)(info.SlotIndex + 1))];
                            }
                            else if (SlotHints.Length <= info.SlotIndex)
                            {
                                Array.Resize <string>(ref SlotHints, Math.Max(slotsData.Count, (int)(info.SlotIndex + 1)));
                            }

                            SlotHints[(int)info.SlotIndex] = newSlotHint;
                        }
                    }

                    data.SlotInfo.Add(info);
                }

                // unpack layout
                LayoutType layoutType = (LayoutType)(newData[DefAgentFieldID.LayoutType].AsByte() ?? 0);

                if (layoutType == LayoutType.Table)
                {
                    // currently only table layout is supported for atomic blocks
                    data.LayoutTemplate = new TableLayoutTemplate(newData);
                }

                stateData.Add(state, data);
            }

            // rendering hints for the block
            UnpackBlockHints(source);

            // done
            IsUnpacked = true;
        }