示例#1
0
文件: ModulePlugin.cs 项目: zparr/ATF
        private void DefineModuleType(
            XmlQualifiedName name,
            string displayName,
            string description,
            string imageName,
            ElementType.Pin[] inputs,
            ElementType.Pin[] outputs,
            SchemaLoader loader)
        {
            // turn input pins into attributes on the type
            var attributes = new List <AttributeInfo>();

            foreach (ElementType.Pin pin in inputs)
            {
                attributes.Add(
                    new AttributeInfo(
                        pin.Name,
                        (pin.TypeName == BooleanPinTypeName) ? BooleanPinType : FloatPinType));
            }

            // create the type
            var type = new DomNodeType(
                name.ToString(),
                Schema.moduleType.Type,
                attributes,
                EmptyArray <ChildInfo> .Instance,
                EmptyArray <ExtensionInfo> .Instance);

            // add it to the schema-defined types
            loader.AddNodeType(name.ToString(), type);

            // create an element type and add it to the type metadata
            // For now, let all circuit elements be used as 'connectors' which means
            //  that their pins will be used to create the pins on a master instance.
            bool isConnector = true; //(inputs.Length + outputs.Length) == 1;

            type.SetTag <ICircuitElementType>(
                new ElementType(
                    displayName,
                    isConnector,
                    new Size(),
                    ResourceUtil.GetImage32(imageName),
                    inputs,
                    outputs));

            // add the type to the palette
            m_paletteService.AddItem(
                new NodeTypePaletteItem(
                    type,
                    displayName,
                    description,
                    imageName),
                PaletteCategory,
                this);
        }
        /// <summary>
        /// Constructor for simply tracking a pre-registered image.
        /// Because it was not created here, Image will not be disposed of in IDispose.Dispose().</summary>
        /// <param name="id">Image identifier</param>
        /// <param name="size">Image size</param>
        public EmbeddedImage(string id, ImageSizes size)
        {
            m_isOwner = false;
            m_id      = id;
            switch (size)
            {
            case ImageSizes.e16x16: Image = ResourceUtil.GetImage16(id); break;

            case ImageSizes.e24x24: Image = ResourceUtil.GetImage24(id); break;

            case ImageSizes.e32x32: Image = ResourceUtil.GetImage32(id); break;

            default:
                throw new ArgumentException("Invalid size specified");
            }

            if (Image == null)
            {
                throw new ArgumentException("No image registered with this id and size");
            }
        }
示例#3
0
        private void DefineCircuitType(
            DomNodeType type,
            string elementTypeName,
            string imageName,
            ICircuitPin[] inputs,
            ICircuitPin[] outputs)
        {
            // create an element type and add it to the type metadata
            // For now, let all circuit elements be used as 'connectors' which means
            //  that their pins will be used to create the pins on a master instance.
            bool isConnector = true; //(inputs.Length + outputs.Length) == 1;
            var  image       = string.IsNullOrEmpty(imageName) ? null : ResourceUtil.GetImage32(imageName);

            type.SetTag <ICircuitElementType>(
                new ElementType(
                    elementTypeName,
                    isConnector,
                    new Size(),
                    image,
                    inputs,
                    outputs));
        }
示例#4
0
        /// <summary>
        /// Helper function to return properly sized images based on user preferences</summary>
        /// <param name="imageName">Image name</param>
        /// <returns>Image of given name</returns>
        public Image GetProperlySizedImage(string imageName)
        {
            Image image = null;

            if (!string.IsNullOrEmpty(imageName))
            {
                if (m_imageSize == ImageSizes.Size16x16)
                {
                    image = ResourceUtil.GetImage16(imageName);
                }
                else if (m_imageSize == ImageSizes.Size24x24)
                {
                    image = ResourceUtil.GetImage24(imageName);
                }
                else if (m_imageSize == ImageSizes.Size32x32)
                {
                    image = ResourceUtil.GetImage32(imageName);
                }
            }

            return(image);
        }
示例#5
0
        protected override void OnNodeSet()
        {
            base.OnNodeSet();

            if (string.IsNullOrEmpty(GetAttribute <string>(moduleType.labelAttribute)))
            {
                SetAttribute(moduleType.labelAttribute, GetAttribute <string>(moduleType.nameAttribute));
            }

            // Pull image icon image from node definition
            var nodeDef = DomNode.Type.GetTag <SF.Tong.Schema.NodeTypeInfo>();

            m_Image = string.IsNullOrEmpty(nodeDef.Icon) ? null : ResourceUtil.GetImage32(nodeDef.Icon);

            // Create non-string child classes
            if (DomNode.Children != null)
            {
                foreach (var childInfo in DomNode.Type.Children)
                {
                    if (childInfo.IsList)
                    {
                        continue;
                    }
                    if (DomNode.GetChild(childInfo) != null)
                    {
                        continue;
                    }

                    var newChild = new DomNode(childInfo.Type);
                    DomNode.SetChild(childInfo, newChild);
                }
            }

            // Add sockets for attributes
            if (DomNode.Type.Attributes != null)
            {
                foreach (var attrInfo in DomNode.Type.Attributes)
                {
                    var attrRule = attrInfo.GetRule <GameDataAttributeRule>();
                    if (attrRule == null || attrRule.SchemaProperty == null)
                    {
                        continue;
                    }

                    switch (attrRule.SchemaProperty.Socket)
                    {
                    case SF.Tong.Schema.SocketType.Input:
                        m_Inputs.Add(new ElementType.Pin(attrInfo.Name, attrInfo.Type, m_Inputs.Count, allowFanIn: attrRule.SchemaProperty.AllowMultipleInput));
                        break;

                    case SF.Tong.Schema.SocketType.Output:
                        m_Outputs.Add(new ElementType.Pin(attrInfo.Name, attrInfo.Type, m_Outputs.Count, allowFanOut: attrRule.SchemaProperty.AllowMultipleOutput));
                        break;

                    case SF.Tong.Schema.SocketType.InOut:
                        m_Inputs.Add(new ElementType.Pin(attrInfo.Name, attrInfo.Type, m_Inputs.Count, allowFanIn: attrRule.SchemaProperty.AllowMultipleInput));
                        m_Outputs.Add(new ElementType.Pin(attrInfo.Name, attrInfo.Type, m_Outputs.Count, allowFanOut: attrRule.SchemaProperty.AllowMultipleOutput));
                        break;

                    default:
                        break;
                    }
                }
            }


            // Create child sockets
            if (DomNode.Children != null)
            {
                foreach (var child in DomNode.Children)
                {
                    if (child.ChildInfo.Type != socketType.Type)
                    {
                        continue;
                    }

                    string socketName = GetBaseNameFor(child.ChildInfo, child);

                    // Only output can vary
                    var newPin = new ElementType.Pin(socketName, AttributeType.BooleanType, m_Outputs.Count);
                    m_Outputs.Add(newPin);
                }
            }


            // Update socket as new a child node is added
            DomNode.ChildInserted += (sender, args) =>
            {
                if (DomNode != args.Parent)
                {
                    return;
                }

                if (args.ChildInfo.Type == socketType.Type)
                {
                    string socketName = GetBaseNameFor(args.ChildInfo, args.Child);

                    // Only output can vary
                    var newPin = new ElementType.Pin(socketName, AttributeType.BooleanType, m_Outputs.Count);
                    m_Outputs.Add(newPin);
                }
            };

            // Update socket as new a child node is removed
            DomNode.ChildRemoved += (sender, args) =>
            {
                if (DomNode != args.Parent)
                {
                    return;
                }

                if (args.ChildInfo.Type == socketType.Type)
                {
                    string socketName = GetBaseNameFor(args.ChildInfo, args.Child);

                    // Only output can vary
                    int iSocket = 0;
                    for (; iSocket < m_Outputs.Count; iSocket++)
                    {
                        var output = m_Outputs[iSocket];
                        if (output.Name == socketName)
                        {
                            m_Outputs.RemoveAt(iSocket);
                            break;
                        }
                    }

                    // fix up index
                    for (; iSocket < m_Outputs.Count; iSocket++)
                    {
                        var output = m_Outputs[iSocket];
                        output.Index = iSocket;
                    }
                }
            };

            // For title text
            UpdateTitleText();

            DomNode.AttributeChanged += OnAttributeChanged;
        }
示例#6
0
        /// <summary>
        /// Constructor</summary>
        public FilteredFileDialogBase()
        {
            InitializeComponent();

            // Initialize ListView
            listView1.View        = View.Details;
            listView1.VirtualMode = true; // virtual mode is necessary for processing large number of files in a reasonable time

            // Suspending automatic refreshes as items are added/removed.
            listView1.BeginUpdate();
            listView1.Columns.Add("Name", 250, HorizontalAlignment.Left);
            listView1.Columns.Add("Date Modified", 130, HorizontalAlignment.Left);
            listView1.Columns.Add("Size", listView1.Width - 250 - 130 - 20, HorizontalAlignment.Right);
            listView1.ColumnClick += listView1_ColumnClick;
            m_listViewItemComparer = new ListViewItemComparer();

            listView1.SmallImageList = new ImageList();
            listView1.SmallImageList.Images.Add(ResourceUtil.GetImage16(Resources.FolderIcon));
            listView1.SmallImageList.Images.Add(ResourceUtil.GetImage16(Resources.DocumentImage));
            listView1.SmallImageList.Images.Add(ResourceUtil.GetImage16(Resources.DiskDriveImage));
            listView1.SmallImageList.Images.Add(ResourceUtil.GetImage16(Resources.ComputerImage));
            listView1.LargeImageList = new ImageList();
            listView1.LargeImageList.Images.Add(ResourceUtil.GetImage32(Resources.FolderImage));
            listView1.LargeImageList.Images.Add(ResourceUtil.GetImage32(Resources.DocumentImage));
            listView1.LargeImageList.Images.Add(ResourceUtil.GetImage32(Resources.DiskDriveImage));


            listView1.DoubleClick += listView1_DoubleClick;
            listView1.VirtualItemsSelectionRangeChanged += listView1_VirtualItemsSelectionRangeChanged;
            listView1.SelectedIndexChanged += listView1_SelectedIndexChanged;
            listView1.AfterLabelEdit       += listView1_AfterLabelEdit;

            listView1.RetrieveVirtualItem += listView1_RetrieveVirtualItem;
            listView1.CacheVirtualItems   += listView1_CacheVirtualItems;


            // Re-enable the display.
            listView1.EndUpdate();

            toolStripButton1.Click                += backButton_Click;
            toolStripButton2.Click                += upButton_Click;
            toolStripButton3.Click                += newFolder_Click;
            fileTypeComboBox.DropDownStyle         = ComboBoxStyle.DropDownList;
            fileTypeComboBox.SelectedIndexChanged += fileTypeComboBox_SelectedIndexChanged;

            fileNameComboBox.SelectedIndexChanged += fileNameComboBox_SelectedIndexChanged;
            fileNameComboBox.PreviewKeyDown       += fileNameComboBox_PreviewKeyDown;
            fileNameComboBox.TextChanged          += fileNameComboBox_TextChanged;

            lookInComboBox.SelectedIndexChanged += path_SelectedIndexChanged;
            lookInComboBox.DrawMode              = DrawMode.OwnerDrawFixed;
            lookInComboBox.DrawItem             += lookInComboBox_DrawItem;

            m_timer = new Timer {
                Interval = SELECTION_DELAY
            };                                                  // timer is needed to avoid excessive delay of fileNameComboBox update when large number of files are selected
            m_timer.Tick += timer_Tick;

            this.Load += fileDialogBase_Load;

            m_backgroundWorker = new BackgroundWorker();
            m_backgroundWorker.WorkerSupportsCancellation = true;
            m_backgroundWorker.DoWork += backgroundWorker_DoWork; // cache time-consuming ListView file information items asynchronously
        }