Exemplo n.º 1
0
        /// <summary>Function to allow user defined setup of the graphics context with this control.</summary>
        /// <param name="context">The context being assigned.</param>
        /// <param name="swapChain">
        /// The swap chain assigned to the <span class="nolink">RenderControl<span class="languageSpecificText"><span class="cs">()</span><span class="cpp">()</span><span class="nu">()</span><span class="fs">()</span></span></span>.
        /// </param>
        protected override void OnSetupGraphics(IGraphicsContext context, GorgonSwapChain swapChain)
        {
            Debug.Assert(EditorCommonResources.CheckerBoardPatternImage != null, "Background texture was not loaded.");

            _ribbonForm.GraphicsContext = context;

            _background = GorgonTexture2DView.CreateTexture(context.Graphics, new GorgonTexture2DInfo("Editor_BG_Texture")
            {
                Format  = EditorCommonResources.CheckerBoardPatternImage.Format,
                Width   = EditorCommonResources.CheckerBoardPatternImage.Width,
                Height  = EditorCommonResources.CheckerBoardPatternImage.Height,
                Binding = TextureBinding.ShaderResource,
                Usage   = ResourceUsage.Immutable
            }, EditorCommonResources.CheckerBoardPatternImage);

            _viewers[ImageType.Image2D] = new Texture2DViewer(context, swapChain, ScrollHorizontal, ScrollVertical);
            _viewers[ImageType.Image2D].CreateResources(_background);
            _viewers[ImageType.ImageCube] = new TextureCubeViewer(context, swapChain, ScrollHorizontal, ScrollVertical);
            _viewers[ImageType.ImageCube].CreateResources(_background);
            _viewers[ImageType.Image3D] = new Texture3DViewer(context, swapChain, ScrollHorizontal, ScrollVertical);
            _viewers[ImageType.Image3D].CreateResources(_background);

            if (DataContext?.ImageType == null)
            {
                ValidateControls();
                return;
            }

            _textureViewer = _viewers[DataContext.ImageType];
            _textureViewer.UpdateTexture(DataContext);
            UpdateImageSizeDetails(DataContext);
            UpdateMipDetails(DataContext);
            UpdateArrayDetails(DataContext);
            UpdateDepthSliceDetails(DataContext);

            ValidateControls();
        }
Exemplo n.º 2
0
        /// <summary>Function called when a property is changed on the data context.</summary>
        /// <param name="e">The event parameters.</param>
        /// <remarks>Implementors should override this method in order to handle a property change notification from their data context.</remarks>
        protected override void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(IImageContent.CurrentPanel):
                if (DataContext.CurrentPanel == null)
                {
                    break;
                }

                Control panel = GetRegisteredPanel <Control>(DataContext.CurrentPanel.GetType().FullName);

                if (Controls.Contains(panel))
                {
                    Controls.Remove(panel);
                }

                panel.Visible = true;
                AddControlToPanelHost(panel);
                IsPanelHostActive = true;
                break;

            case nameof(IImageContent.ArrayCount):
                UpdateArrayDetails(DataContext);
                break;

            case nameof(IImageContent.DepthCount):
                UpdateDepthSliceDetails(DataContext);
                UpdateMipDetails(DataContext);
                break;

            case nameof(IImageContent.MipCount):
                UpdateMipDetails(DataContext);
                break;

            case nameof(IImageContent.CurrentArrayIndex):
                // Don't need to call update texture parameters here, we already use an index by default.
                UpdateArrayDetails(DataContext);
                break;

            case nameof(IImageContent.CurrentDepthSlice):
                UpdateDepthSliceDetails(DataContext);
                _textureViewer.UpdateTextureParameters(DataContext);
                break;

            case nameof(IImageContent.CurrentMipLevel):
                UpdateMipDetails(DataContext);
                _textureViewer.UpdateTextureParameters(DataContext);
                break;

            case nameof(IImageContent.Width):
            case nameof(IImageContent.Height):
                UpdateImageSizeDetails(DataContext);
                if (_textureViewer == null)
                {
                    _textureViewer = _viewers[DataContext.ImageType];
                }

                _textureViewer.UpdateTexture(DataContext);
                break;

            case nameof(IImageContent.ImageType):
                if (!_viewers.ContainsKey(DataContext.ImageType))
                {
                    break;
                }

                _textureViewer?.UpdateTexture(null);
                _textureViewer = _viewers[DataContext.ImageType];
                _textureViewer.UpdateTexture(DataContext);
                break;

            default:
                if (_textureViewer == null)
                {
                    _textureViewer = _viewers[DataContext.ImageType];
                }

                _textureViewer.UpdateTexture(DataContext);
                UpdateMipDetails(DataContext);
                break;
            }

            ValidateControls();
        }