public void LoadImage(Bitmap picBoxImg, ImageEditorBase editor)
        {
            imageEditor = editor;

            //Resize texture to hopefully prevent slow loading
            var image = BitmapExtension.Resize(picBoxImg, 65, 65);

            imgList.Images.Clear();
            imgList.ImageSize  = new Size(65, 65);
            imgList.ColorDepth = ColorDepth.Depth32Bit;

            Thread Thread = new Thread((ThreadStart)(() =>
            {
                LoadImage(image);
                Bitmap red = BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Red);
                LoadImage(red);
                Bitmap green = BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Green);
                LoadImage(green);
                Bitmap blue = BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Blue);
                LoadImage(blue);
                Bitmap alpha = BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Alpha);
                LoadImage(alpha);

                red.Dispose();
                green.Dispose();
                blue.Dispose();
                alpha.Dispose();
            }));

            Thread.Start();

            channelListView.FullRowSelect  = true;
            channelListView.SmallImageList = imgList;
        }
        public void SetEditorForm(IFileFormat fileFormat)
        {
            if (fileFormat == null)
            {
                GetActiveEditor <STUserControl>();
                return;
            }
            //Todo find a way to handle file editors
            if (fileFormat is IModelFormat)
            {
                if (ParentObjectView.WorkspacePanel == null)
                {
                    ParentObjectView.WorkspacePanel = new WorkspacePanel()
                    {
                        Dock = DockStyle.Fill
                    }
                }
                ;

                WorkspacePanel workspace = GetActiveEditor <WorkspacePanel>(ParentObjectView.WorkspacePanel);
                workspace.LoadFileFormat((IModelFormat)fileFormat);
                workspace.UpdateViewport();
            }
            //Todo find a way to handle file editors
            if (fileFormat is STGenericTexture)
            {
                ImageEditorBase editor = GetActiveEditor <ImageEditorBase>();
                editor.LoadProperties(((STGenericTexture)fileFormat).DisplayProperties);
                editor.LoadImage((STGenericTexture)fileFormat);
            }
        }
Пример #3
0
        private void SelectionChanged(ObjectTreeNode obj)
        {
            obj.OnClick();

            bool tryUpdateViewport = false;

            if (Runtime.SelectedBoneIndex != -1)
            {
                tryUpdateViewport         = true;
                Runtime.SelectedBoneIndex = -1;
            }

            if (obj.Tag is ArchiveFileInfo)
            {
                var fileInfo = (ArchiveFileInfo)obj.Tag;

                if (fileInfo.OpenFileFormatOnLoad)
                {
                    fileInfo.FileFormat = fileInfo.OpenFile();
                }
                if (fileInfo.FileFormat != null)
                {
                    var fileNode = ObjectListWrapperLoader.OpenFormat(imgList, fileInfo.FileFormat);
                    obj.Tag = fileInfo.FileFormat;
                    foreach (var child in fileNode.Children)
                    {
                        obj.AddChild(child);
                    }
                    SelectionChanged(obj);
                    return;
                }

                ArchiveFilePanel hexEditor = GetActiveEditor <ArchiveFilePanel>();
                hexEditor.LoadFile(this, fileInfo);
            }
            else if (obj.Tag is STGenericTexture)
            {
                var tex = (STGenericTexture)obj.Tag;

                ImageEditorBase editor = GetActiveEditor <ImageEditorBase>();
                editor.LoadProperties(tex.DisplayProperties);
                editor.LoadImage(tex);
            }
            else if (obj.Tag is IPropertyDisplay)
            {
                var property = (IPropertyDisplay)obj.Tag;

                STPropertyGrid editor = GetActiveEditor <STPropertyGrid>();
                editor.LoadProperty(property.PropertyDisplay);
            }
            else if (obj.Tag is IEditorDisplay)
            {
                var property = (IEditorDisplay)obj.Tag;
                Console.WriteLine($"IEditorDisplay {property}");

                var gui = GUIGenerator.Generate(property);
                gui.Dock = DockStyle.Fill;

                STPanel editor = GetActiveEditor <STPanel>();
                editor.Controls.Clear();
                editor.Controls.Add(gui);
            }
            else if (obj.Tag is System.IO.Stream)
            {
                var stream = (System.IO.Stream)obj.Tag;

                HexEditor hexEditor = GetActiveEditor <HexEditor>();
                hexEditor.LoadData(stream);
            }
            else if (obj.Tag is IVideoFormat)
            {
                VideoPlayer editor = GetActiveEditor <VideoPlayer>();
                editor.LoadVideoFile((IVideoFormat)obj.Tag);
            }
            else if (obj.Tag is STGenericMesh)
            {
                var mesh = (STGenericMesh)obj.Tag;
                mesh.SelectMesh?.Invoke(mesh, EventArgs.Empty);

                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace  = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                var            meshEditor = workspace.GetActiveEditor <MeshEditor>();
                meshEditor.LoadMesh(mesh);
                workspace.UpdateViewport();
                ObjectHiearchy.Focus();
            }
            else if (obj.Tag is STGenericMaterial)
            {
                var mat = (STGenericMaterial)obj.Tag;

                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace      = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                var            materialEditor = workspace.GetActiveEditor <MaterialEditor>();
                materialEditor.LoadMaterial(mat);
                workspace.UpdateViewport();
            }
            else if (obj.Tag is IModelFormat)
            {
                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                workspace.LoadFileFormat((IModelFormat)(obj.Tag));
                workspace.UpdateViewport();
            }
            else if (obj.Tag is IModelSceneFormat)
            {
                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                workspace.LoadFileFormat((IModelSceneFormat)(obj.Tag));
                workspace.UpdateViewport();
            }
            else if (obj.Tag is STAnimation)
            {
                if (WorkspacePanel == null)
                {
                    WorkspacePanel = CreateWorkspacePanel();
                }

                WorkspacePanel workspace = GetActiveEditor <WorkspacePanel>(WorkspacePanel);
                workspace.LoadFileFormat((STAnimation)(obj.Tag));
                workspace.UpdateViewport();
            }
            else if (obj.Tag is STBone)
            {
                var bone = (STBone)obj.Tag;
                Runtime.SelectedBoneIndex = bone.Index;
                WorkspacePanel.UpdateViewport();
            }

            if (tryUpdateViewport && WorkspacePanel != null)
            {
                WorkspacePanel.UpdateViewport();
            }
            // else
            //    GetActiveEditor<STPanel>();
        }