Esempio n. 1
0
        public AtomicBlockStateData this[BlockState state]
        {
            get
            {
                AtomicBlockStateData res = null;
                stateData.TryGetValue(state, out res);

                return(res);
            }
        }
Esempio n. 2
0
        public override void Restore(Stream str)
        {
            base.Restore(str);

            if (str.ReadByte() == 0)
            {
                SpecialTag        = str.ReadInteger();
                AcceptsFocus      = str.ReadBool();
                SortIndex         = str.ReadInteger();
                IsCheckable       = str.ReadBool();
                DeviceTextScaling = str.ReadBool();

                // static display data
                if (str.ReadByte() == 1)
                {
                    StaticDisplayData = new DisplayDataCollection();
                    StaticDisplayData.Restore(str);
                }
                else
                {
                    StaticDisplayData = null;
                }

                // slot hints
                int slotHintsCount = str.ReadInteger();

                if (slotHintsCount > 0)
                {
                    SlotHints = new string[slotHintsCount];

                    for (int i = 0; i < slotHintsCount; i++)
                    {
                        SlotHints[i] = BinaryHelper.ReadString(str);
                    }
                }
                else
                {
                    SlotHints = null;
                }

                // state data
                short statesCount = str.ReadShort();

                for (int i = 0; i < statesCount; i++)
                {
                    BlockState st = (BlockState)str.ReadShort();

                    AtomicBlockStateData stData = new AtomicBlockStateData();
                    stData.Restore(str);

                    stateData[st] = stData;
                }
            }
        }
Esempio n. 3
0
        private AtomicBlockStateData GetOrCreateDataForState(BlockState state)
        {
            AtomicBlockStateData res = null;

            stateData.TryGetValue(state, out res);

            if (res == null)
            {
                res = new AtomicBlockStateData();
            }

            return(res);
        }
Esempio n. 4
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;
        }