Example #1
0
        public void Unpack(FieldList source)
        {
            if (source == null)
            {
                return;
            }

            PairedList <ByteField, FieldList> searchResults =
                source.GetPairedItems <ByteField, FieldList>(DefAgentFieldID.ComponentState, DefAgentFieldID.DataPerComponentState);

            foreach (Pair <ByteField, FieldList> result in searchResults)
            {
                BlockState state = (BlockState)result.First.Data;

                if (!Data.ContainsKey(state))
                {
                    SlotStyleData newData = new SlotStyleData();
                    newData.Unpack(result.Second);

                    Data[state] = newData;
                }
            }

            // done
            IsUnpacked = true;
        }
Example #2
0
        public LinearGradientPaletteEntry(FieldList source)
            : base(PaletteEntryType.LinearGradient)
        {
            PairedList <ByteField, Int32Field> searchResults =
                source.GetPairedItems <ByteField, Int32Field>(DefAgentFieldID.GradientKeyPosition, DefAgentFieldID.GradientKeyColour);

            foreach (Pair <ByteField, Int32Field> res in searchResults)
            {
                Colours.Add(new Pair <byte, Color>(res.First.Data, DataHelper.IntToColour(res.Second.Data)));
            }

            IsHorizontal = ((UIFlowDirection)(source[DefAgentFieldID.FlowDirection].AsByte() ?? (byte)UIFlowDirection.Right) == UIFlowDirection.Right);
        }
Example #3
0
        public ColourSequencePaletteEntry(FieldList source)
            : base(PaletteEntryType.ColourSequence)
        {
            PairedList <ByteField, Int32Field> searchResults =
                source.GetPairedItems <ByteField, Int32Field>(DefAgentFieldID.GradientKeyPosition, DefAgentFieldID.GradientKeyColour);

            foreach (Pair <ByteField, Int32Field> res in searchResults)
            {
                Colours.Add(new Pair <byte, Color>(res.First.Data, DataHelper.IntToColour(res.Second.Data)));
            }

            Period = source[DefAgentFieldID.TimePeriod].AsShort() ?? 0;
            IsLoop = source[DefAgentFieldID.Loop].AsBoolean() ?? false;
        }
Example #4
0
        public PairedList <T, U> GetPairedItems <T, U>(short firstID, short secondID)
            where T : class, IFieldBase
            where U : class, IFieldBase
        {
            PairedList <T, U> res = new PairedList <T, U>();

            for (int i = 0; i < (fields.Count - 1); i++)
            {
                if ((fields[i].FieldID == firstID) && (fields[i + 1].FieldID == secondID) &&
                    (fields[i] is T) && (fields[i + 1] is U))
                {
                    res.Add(new Pair <T, U>((T)fields[i], (U)fields[i + 1]));
                    i++;
                }
            }

            return(res);
        }
Example #5
0
        public void Unpack(FieldList source)
        {
            if (source == null)
            {
                return;
            }

            UnpackDefinitionID(source);

            IsCheckable = false;

            // unpacking common attributes
            AcceptsFocus          = source[DefAgentFieldID.AcceptsFocus].AsBoolean() ?? false;
            SortIndex             = source[DefAgentFieldID.SortSlotIndex].AsShort() ?? -1;
            SizeToBackgroundImage = source[DefAgentFieldID.BlockSizeToBackground].AsBoolean() ?? false;

            // 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;

                SingleSlotBlockStateData data = GetOrCreateDataForState(state);

                // slot style data
                data.SlotStyle = new SlotStyleData();
                data.SlotStyle.Unpack(newData);

                // slot index
                data.SlotIndex = newData[DefAgentFieldID.SlotIndex].AsShort() ?? 0;

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

                // 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;

                data.MaximumChars = newData[DefAgentFieldID.MaximumChars].AsShort() ?? 0;
                data.MaximumLines = newData[DefAgentFieldID.MaximumLines].AsShort() ?? 0;
                data.MinimumLines = newData[DefAgentFieldID.MinimumLines].AsShort() ?? 0;

                // rendering hints
                FieldList firstSlotData = (FieldList)newData[DefAgentFieldID.SlotData];

                if (firstSlotData != null)
                {
                    string newSlotHint = firstSlotData[DefAgentFieldID.SlotHint].AsString();

                    if (newSlotHint != null)
                    {
                        SlotHint = newSlotHint;
                    }
                }

                stateData.Add(state, data);
            }

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

            // done
            IsUnpacked = true;
        }
        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;
        }