/// <summary> /// Creates the configuration controls of this asset. /// </summary> public static void AddControls(HorizonBasedAmbientOcclusion asset, Window owner, ComboBox comboBoxResource) { GroupBox groupGeneral = CommonControls.Group("General", owner); #region Quality var quality = CommonControls.ComboBox("Quality", groupGeneral); // Add textures name quality.Items.Add("Low"); quality.Items.Add("Middle"); quality.Items.Add("High"); // Events quality.ItemIndexChanged += delegate { switch (quality.ItemIndex) { case 0: asset.Quality = HorizonBasedAmbientOcclusion.QualityType.LowQuality; break; case 1: asset.Quality = HorizonBasedAmbientOcclusion.QualityType.MiddleQuality; break; case 2: asset.Quality = HorizonBasedAmbientOcclusion.QualityType.HighQuality; break; } }; quality.Draw += delegate { if (quality.ListBoxVisible) return; switch (asset.Quality) { case HorizonBasedAmbientOcclusion.QualityType.LowQuality : quality.ItemIndex = 0; break; case HorizonBasedAmbientOcclusion.QualityType.MiddleQuality : quality.ItemIndex = 1; break; case HorizonBasedAmbientOcclusion.QualityType.HighQuality : quality.ItemIndex = 2; break; } }; #endregion var numberSteps = CommonControls.SliderNumericInt("Number Steps", groupGeneral, asset.NumberSteps, false, true, 0, 36, asset, "NumberSteps"); var numberDirections = CommonControls.SliderNumericInt("Number Directions", groupGeneral, asset.NumberDirections, false, true, 0, 36, asset, "NumberDirections"); var contrast = CommonControls.SliderNumericFloat("Contrast", groupGeneral, asset.Contrast, true, true, 0, 2, asset, "Contrast"); var lineAttenuation = CommonControls.SliderNumericFloat("LineAttenuation", groupGeneral, asset.LineAttenuation, false, false, 0, 2, asset, "LineAttenuation"); var radius = CommonControls.SliderNumericFloat("Radius", groupGeneral, asset.Radius, false, false, 0, 0.5f, asset, "Radius"); var angleBias = CommonControls.SliderNumericFloat("AngleBias", groupGeneral, asset.AngleBias, false, false, 0, 90, asset, "AngleBias"); groupGeneral.AdjustHeightFromChildren(); } // AddControls
/// <summary> /// Creates and shows the configuration window of this asset. /// </summary> public static Window Show<TAssetType>(Asset asset) where TAssetType : Asset { AssetContentManager temporalContentManager = null; AssetContentManager userContentManager = null; bool assetCreation = asset == null; PropertyInfo filenamesProperty = typeof(TAssetType).GetProperty("Filenames"); // Search for the Filenames property, not all assets have it. bool resourcedAsset = filenamesProperty != null; // Indicates if the asset has a resource (textures, models, etc.) or if it is a property asset (shadows, ambient light, etc.) string[] filenames = null; if (assetCreation) { // If the asset has an internal XNA Resource (textures, models, sounds) if (resourcedAsset) { filenames = (string[])filenamesProperty.GetValue(asset, null); // If there is no asset to create then return if (filenames.Length == 0) { CurrentCreatedAsset = null; // To avoid unwanted event references. return null; } userContentManager = AssetContentManager.CurrentContentManager; temporalContentManager = new AssetContentManager { Name = "Temporal Content Manager", Hidden = true }; AssetContentManager.CurrentContentManager = temporalContentManager; // Create a temporal asset with the first resource in the list. asset = (Asset)typeof(TAssetType).GetConstructor(new[] { typeof(string) }).Invoke(new object[] { filenames[0] }); } // If not... (ambient light, post process, shadows, etc.) else asset = (Asset)typeof(TAssetType).GetConstructor(new Type[] { }).Invoke(null); CurrentCreatedAsset = asset; } #region Window var window = new UserInterface.AssetWindow { AssetName = asset.Name, AssetType = (typeof(TAssetType)).Name, }; window.AssetNameChanged += delegate { string oldName = asset.Name; asset.SetUniqueName(window.AssetName); if (asset.Name != oldName) { window.AssetName = asset.Name; // The window name could be change if the name was not unique. asset.Name = oldName; // This is done for the undo. using (Transaction.Create()) { // Apply the command and store for the undo feature. ActionManager.SetProperty(asset, "Name", window.AssetName); ActionManager.CallMethod(// Redo UserInterfaceManager.Invalidate, // Undo UserInterfaceManager.Invalidate); } } }; window.Draw += delegate { window.AssetName = asset.Name; }; // In creation I don't want that the user mess with other things.) if (assetCreation) window.ShowModal(); #endregion #region Group Resource GroupBox groupResource; ComboBox comboBoxResource = null; ComboBox comboBoxContentManager = null; if (resourcedAsset) { groupResource = CommonControls.Group("Resource", window); comboBoxResource = CommonControls.ComboBox("Resource", groupResource); comboBoxContentManager = CommonControls.ComboBox("Content Manager", groupResource); groupResource.AdjustHeightFromChildren(); } #endregion #region Creation Mode if (assetCreation) { #region Combo Box Resource if (resourcedAsset) { comboBoxResource.Items.AddRange(filenames); comboBoxResource.ItemIndex = 0; // Events comboBoxResource.ItemIndexChanged += delegate { if (filenames[comboBoxResource.ItemIndex] != asset.Filename) { // This is a disposable asset so... temporalContentManager.Unload(); // To contemplate some assets like Lookup Tables and some textures. if (!asset.IsDisposed) asset.Dispose(); asset = (Asset)typeof(TAssetType).GetConstructor(new[] { typeof(string) }).Invoke(new object[] { filenames[comboBoxResource.ItemIndex] }); CurrentCreatedAsset = asset; window.AssetName = asset.Name; } }; comboBoxResource.Draw += delegate { if (comboBoxResource.ListBoxVisible) return; for (int i = 0; i < comboBoxResource.Items.Count; i++) { if ((string)comboBoxResource.Items[i] == asset.Filename) { if (comboBoxResource.ItemIndex != i) { comboBoxResource.ItemIndex = i; break; } } } }; } #endregion #region Combo Box Content Manager if (resourcedAsset) { // The names of the content manager are added here because we want to place the item index in the current content manager. comboBoxContentManager.Items.Clear(); // Add content names. foreach (AssetContentManager contentManager in AssetContentManager.SortedContentManagers) { if (!contentManager.Hidden) comboBoxContentManager.Items.Add(contentManager.Name); } // Find the current content manager. comboBoxContentManager.ItemIndex = 0; for (int i = 0; i < comboBoxContentManager.Items.Count; i++) { if (AssetContentManager.SortedContentManagers[i] == userContentManager) { comboBoxContentManager.ItemIndex = i; break; } } comboBoxResource.Draw += delegate { // The names of the content manager are added here because someone could dispose or add a new one. comboBoxContentManager.Items.Clear(); // Add names foreach (AssetContentManager contentManager in AssetContentManager.SortedContentManagers) { if (!contentManager.Hidden) comboBoxContentManager.Items.Add(contentManager.Name); } }; } #endregion #region Window Closed window.Closed += delegate { if (resourcedAsset) temporalContentManager.Dispose(); if (window.ModalResult == ModalResult.Cancel) { // Returns null. CurrentCreatedAsset = null; if (!asset.IsDisposed) asset.Dispose(); } else { if (resourcedAsset) { if (!asset.IsDisposed) // To contemplate some assets like Lookup Tables and some textures. asset.Dispose(); // Search the content manager reference using its name. foreach (AssetContentManager contenManager in AssetContentManager.SortedContentManagers) { if (contenManager.Name == (string)(comboBoxContentManager.Items[comboBoxContentManager.ItemIndex])) { AssetContentManager.CurrentContentManager = contenManager; break; } } // And create the asset with this content manager. CurrentCreatedAsset = (Asset)typeof(TAssetType).GetConstructor(new[] { typeof(string) }).Invoke(new object[] { filenames[comboBoxResource.ItemIndex] }); } CurrentCreatedAsset.Name = window.AssetName; } // Restore user content manager. if (resourcedAsset) AssetContentManager.CurrentContentManager = userContentManager; // Remove references to the event. CurrentCreatedAssetChanged = null; }; #endregion } #endregion #region Edit Mode else // If it is in edit mode... { // Fill Resource Combo Box. if (resourcedAsset) { comboBoxResource.Items.Add(asset.Filename); comboBoxResource.ItemIndex = 0; comboBoxResource.Enabled = false; // Fill Content Manager Combo Box. if (asset.ContentManager != null) comboBoxContentManager.Items.Add(asset.ContentManager.Name); else comboBoxContentManager.Items.Add("Does not have a Content Manager"); comboBoxContentManager.ItemIndex = 0; comboBoxContentManager.Enabled = false; } } #endregion #region Specific Controls for Specific Assets if (typeof(TAssetType) == typeof(Texture)) TextureControls.AddControls((Texture)asset, window, comboBoxResource); else if (typeof(TAssetType) == typeof(PostProcess)) PostProcessControls.AddControls((PostProcess) asset, window, comboBoxResource); else if (typeof(TAssetType) == typeof(LookupTable)) LookupTableControls.AddControls((LookupTable)asset, window, comboBoxResource); else if (typeof(TAssetType) == typeof(AmbientLight)) AmbientLightControls.AddControls((AmbientLight)asset, window, comboBoxResource); else if (typeof(TAssetType) == typeof(HorizonBasedAmbientOcclusion)) HorizonBasedAmbientOcclusionControls.AddControls((HorizonBasedAmbientOcclusion)asset, window, comboBoxResource); else if (typeof(TAssetType) == typeof(BasicShadow)) ShadowControls.AddControls((BasicShadow)asset, window, comboBoxResource); else if (typeof(TAssetType) == typeof(Sphere)) PrimitiveControls.AddControls((Sphere)asset, window, assetCreation); else if (typeof(TAssetType) == typeof(Box)) PrimitiveControls.AddControls((Box)asset, window, assetCreation); else if (typeof(TAssetType) == typeof(Plane)) PrimitiveControls.AddControls((Plane)asset, window, assetCreation); else if (typeof(TAssetType) == typeof(Cylinder)) PrimitiveControls.AddControls((Cylinder)asset, window, assetCreation); else if (typeof(TAssetType) == typeof(Cone)) PrimitiveControls.AddControls((Cone)asset, window, assetCreation); else if (typeof(TAssetType) == typeof(BlinnPhong)) BlinnPhongControls.AddControls((BlinnPhong)asset, window); else if (typeof(TAssetType) == typeof(Constant)) ConstantControls.AddControls((Constant)asset, window); else if (typeof(TAssetType) == typeof(CarPaint)) CarPaintControls.AddControls((CarPaint)asset, window); #endregion); if (assetCreation) { #region Buttons window.StatusBar = new StatusBar(); var buttonApply = new Button { Anchor = Anchors.Top | Anchors.Right, //Top = window.AvailablePositionInsideControl + CommonControls.ControlSeparation, Top = 5, Left = window.ClientWidth - 4 - 70 * 2 - 8, Text = "Create", Parent = window.StatusBar, }; buttonApply.Click += delegate { window.Close(); }; var buttonClose = new Button { Anchor = Anchors.Top | Anchors.Right, Text = "Cancel", ModalResult = ModalResult.Cancel, Top = buttonApply.Top, Left = window.ClientWidth - 70 - 8, Parent = window.StatusBar }; window.StatusBar.Height = buttonApply.Top + buttonApply.Height + 5; #endregion } window.AdjustHeightFromChildren(); window.Height += 5; if (window.Height > 600) window.Height = 600; return window; } // Show
/// <summary> /// Creates the configuration controls of this asset. /// </summary> public static void AddControls(Texture asset, Window owner, ComboBox comboBoxResource) { // In asset creation I need to look on the CurrentCreatedAsset property to have the last asset. // I can't use CurrentCreatedAsset in edit mode. // However I can use asset for creation (maybe in a disposed state but don't worry) and edit mode, // and only update the values when I know that CurrentCreatedAsset changes. #region Group Image var groupImage = CommonControls.Group("Image", owner); var imageBoxImage = CommonControls.ImageBox(asset, groupImage); groupImage.AdjustHeightFromChildren(); #endregion #region Group Properties GroupBox groupProperties = CommonControls.Group("Properties", owner); var widthTextBox = CommonControls.TextBox("Width", groupProperties, asset.Width.ToString()); widthTextBox.Enabled = false; var heightTextBox = CommonControls.TextBox("Height", groupProperties, asset.Height.ToString()); heightTextBox.Enabled = false; #region Prefered Sampler State var comboBoxPreferredSamplerState = CommonControls.ComboBox("Prefered Sampler State", groupProperties); comboBoxPreferredSamplerState.Items.Add("AnisotropicClamp"); comboBoxPreferredSamplerState.Items.Add("AnisotropicWrap"); comboBoxPreferredSamplerState.Items.Add("LinearClamp"); comboBoxPreferredSamplerState.Items.Add("LinearWrap"); comboBoxPreferredSamplerState.Items.Add("PointClamp"); comboBoxPreferredSamplerState.Items.Add("PointWrap"); comboBoxPreferredSamplerState.ItemIndexChanged += delegate { asset.PreferredSamplerState = GetSamplerState(comboBoxPreferredSamplerState.ItemIndex); }; comboBoxPreferredSamplerState.Draw += delegate { if (comboBoxPreferredSamplerState.ListBoxVisible) return; // Identify current index if (asset.PreferredSamplerState == SamplerState.AnisotropicClamp) comboBoxPreferredSamplerState.ItemIndex = 0; else if (asset.PreferredSamplerState == SamplerState.AnisotropicWrap) comboBoxPreferredSamplerState.ItemIndex = 1; else if (asset.PreferredSamplerState == SamplerState.LinearClamp) comboBoxPreferredSamplerState.ItemIndex = 2; else if (asset.PreferredSamplerState == SamplerState.LinearWrap) comboBoxPreferredSamplerState.ItemIndex = 3; else if (asset.PreferredSamplerState == SamplerState.PointClamp) comboBoxPreferredSamplerState.ItemIndex = 4; else if (asset.PreferredSamplerState == SamplerState.PointWrap) comboBoxPreferredSamplerState.ItemIndex = 5; else { if (customSamplerState == null) { comboBoxPreferredSamplerState.Items.Add("Custom"); customSamplerState = asset.PreferredSamplerState; } comboBoxPreferredSamplerState.ItemIndex = 6; } }; #endregion groupProperties.AdjustHeightFromChildren(); #endregion // If it is asset creation time. if (comboBoxResource != null) { comboBoxResource.ItemIndexChanged += delegate { // Update properties if the resource changes. imageBoxImage.Texture = ((Texture)AssetWindow.CurrentCreatedAsset); widthTextBox.Text = ((Texture)AssetWindow.CurrentCreatedAsset).Width.ToString(); heightTextBox.Text = ((Texture)AssetWindow.CurrentCreatedAsset).Height.ToString(); }; // If the user creates the asset (pressed the create button) then update the changeable properties. owner.Closed += delegate { if (owner.ModalResult != ModalResult.Cancel) ((Texture)AssetWindow.CurrentCreatedAsset).PreferredSamplerState = GetSamplerState(comboBoxPreferredSamplerState.ItemIndex); }; } } // AddControls
/// <summary> /// Creates the configuration controls of this asset. /// </summary> public static void AddControls(PostProcess asset, Window owner, ComboBox comboBoxResource) { #region Group Lens Exposure GroupBox groupToneMapping = CommonControls.Group("Tone Mapping", owner); // Lens Exposure var sliderLensExposure = CommonControls.SliderNumericFloat("Lens Exposure", groupToneMapping, asset.ToneMapping.LensExposure, true, true, -10, 10, asset.ToneMapping, "LensExposure"); // Auto Exposure Enabled CheckBox checkBoxAutoExposureEnabled = CommonControls.CheckBox("Auto Exposure Enabled", groupToneMapping, asset.ToneMapping.AutoExposureEnabled, asset.ToneMapping, "AutoExposureEnabled"); // Auto Exposure Adaptation Time Multiplier var sliderAutoExposureAdaptationTimeMultiplier = CommonControls.SliderNumericFloat("Adaptation Time Multiplier", groupToneMapping, asset.ToneMapping.AutoExposureAdaptationTimeMultiplier, false, true, 0, 10, asset.ToneMapping, "AutoExposureAdaptationTimeMultiplier"); // Auto Exposure Luminance Low Threshold var sliderAutoExposureLuminanceLowThreshold = CommonControls.SliderNumericFloat("Luminance Low Threshold", groupToneMapping, asset.ToneMapping.AutoExposureLuminanceLowThreshold, false, true, 0, 0.5f, asset.ToneMapping, "AutoExposureLuminanceLowThreshold"); // Auto Exposure Luminance High Threshold var sliderAutoExposureLuminanceHighThreshold = CommonControls.SliderNumericFloat("Luminance High Threshold", groupToneMapping, asset.ToneMapping.AutoExposureLuminanceHighThreshold, false, true, 0.5f, 20f, asset.ToneMapping, "AutoExposureLuminanceHighThreshold"); // Auto Exposure Enabled checkBoxAutoExposureEnabled.CheckedChanged += delegate { sliderLensExposure.Enabled = !asset.ToneMapping.AutoExposureEnabled; sliderAutoExposureAdaptationTimeMultiplier.Enabled = asset.ToneMapping.AutoExposureEnabled; sliderAutoExposureLuminanceLowThreshold.Enabled = asset.ToneMapping.AutoExposureEnabled; sliderAutoExposureLuminanceHighThreshold.Enabled = asset.ToneMapping.AutoExposureEnabled; }; #region Tone Mapping Curve ComboBox comboBoxToneMappingCurve = CommonControls.ComboBox("Tone Mapping Curve", groupToneMapping); comboBoxToneMappingCurve.Items.AddRange(new[] { "Filmic ALU", "Filmic Uncharted 2", "Duiker", "Reinhard", "Reinhard Modified", "Exponential", "Logarithmic", "Drago Logarithmic" }); comboBoxToneMappingCurve.ItemIndex = (int)asset.ToneMapping.ToneMappingFunction; comboBoxToneMappingCurve.ItemIndexChanged += delegate { asset.ToneMapping.ToneMappingFunction = (ToneMapping.ToneMappingFunctionEnumerate)comboBoxToneMappingCurve.ItemIndex; }; comboBoxToneMappingCurve.Draw += delegate { if (comboBoxToneMappingCurve.ListBoxVisible) return; comboBoxToneMappingCurve.ItemIndex = (int)asset.ToneMapping.ToneMappingFunction; }; #endregion // White Level var sliderWhiteLevel = CommonControls.SliderNumericFloat("White Level", groupToneMapping, asset.ToneMapping.ToneMappingWhiteLevel, false, true, 0f, 50f, asset.ToneMapping, "ToneMappingWhiteLevel"); // Luminance Saturation var sliderLuminanceSaturation = CommonControls.SliderNumericFloat("Luminance Saturation", groupToneMapping, asset.ToneMapping.ToneMappingLuminanceSaturation, false, true, 0f, 2f, asset.ToneMapping, "ToneMappingLuminanceSaturation"); // Drago Bias var sliderDragoBias = CommonControls.SliderNumericFloat("Drago Bias", groupToneMapping, asset.ToneMapping.DragoBias, false, true, 0f, 1f, asset.ToneMapping, "DragoBias"); // Shoulder Strength var sliderShoulderStrength = CommonControls.SliderNumericFloat("Shoulder Strength", groupToneMapping, asset.ToneMapping.Uncharted2ShoulderStrength, false, true, 0f, 1f, asset.ToneMapping, "Uncharted2ShoulderStrength"); // Linear Strength var sliderLinearStrength = CommonControls.SliderNumericFloat("Linear Strength", groupToneMapping, asset.ToneMapping.Uncharted2LinearStrength, false, true, 0f, 1f, asset.ToneMapping, "Uncharted2LinearStrength"); // Linear Angle var sliderLinearAngle = CommonControls.SliderNumericFloat("Linear Angle", groupToneMapping, asset.ToneMapping.Uncharted2LinearAngle, false, true, 0f, 3f, asset.ToneMapping, "Uncharted2LinearAngle"); // Toe Strength var sliderToeStrength = CommonControls.SliderNumericFloat("Toe Strength", groupToneMapping, asset.ToneMapping.Uncharted2ToeStrength, false, true, 0f, 1f, asset.ToneMapping, "Uncharted2ToeStrength"); // Toe Numerator var sliderToeNumerator = CommonControls.SliderNumericFloat("Toe Numerator", groupToneMapping, asset.ToneMapping.Uncharted2ToeNumerator, false, true, 0f, 0.1f, asset.ToneMapping, "Uncharted2ToeNumerator"); // Toe Denominator var sliderToeDenominator = CommonControls.SliderNumericFloat("Toe Denominator", groupToneMapping, asset.ToneMapping.Uncharted2ToeDenominator, false, true, 0f, 1f, asset.ToneMapping, "Uncharted2ToeDenominator"); // Linear White var sliderLinearWhite = CommonControls.SliderNumericFloat("Linear White", groupToneMapping, asset.ToneMapping.Uncharted2LinearWhite, false, true, 0f, 40f, asset.ToneMapping, "Uncharted2LinearWhite"); #region Sliders enabled? comboBoxToneMappingCurve.ItemIndexChanged += delegate { sliderWhiteLevel.Enabled = false; sliderLuminanceSaturation.Enabled = false; sliderDragoBias.Enabled = false; sliderShoulderStrength.Enabled = false; sliderLinearStrength.Enabled = false; sliderLinearAngle.Enabled = false; sliderToeStrength.Enabled = false; sliderToeNumerator.Enabled = false; sliderToeDenominator.Enabled = false; sliderLinearWhite.Enabled = false; if (asset.ToneMapping.ToneMappingFunction == ToneMapping.ToneMappingFunctionEnumerate.DragoLogarithmic) { sliderWhiteLevel.Enabled = true; sliderLuminanceSaturation.Enabled = true; sliderDragoBias.Enabled = true; } else if (asset.ToneMapping.ToneMappingFunction == ToneMapping.ToneMappingFunctionEnumerate.Exponential) { sliderWhiteLevel.Enabled = true; sliderLuminanceSaturation.Enabled = true; } else if (asset.ToneMapping.ToneMappingFunction == ToneMapping.ToneMappingFunctionEnumerate.FilmicUncharted2) { sliderShoulderStrength.Enabled = true; sliderLinearStrength.Enabled = true; sliderLinearAngle.Enabled = true; sliderToeStrength.Enabled = true; sliderToeNumerator.Enabled = true; sliderToeDenominator.Enabled = true; sliderLinearWhite.Enabled = true; } else if (asset.ToneMapping.ToneMappingFunction == ToneMapping.ToneMappingFunctionEnumerate.Logarithmic) { sliderWhiteLevel.Enabled = true; sliderLuminanceSaturation.Enabled = true; } else if (asset.ToneMapping.ToneMappingFunction == ToneMapping.ToneMappingFunctionEnumerate.Reinhard) { sliderLuminanceSaturation.Enabled = true; } else if (asset.ToneMapping.ToneMappingFunction == ToneMapping.ToneMappingFunctionEnumerate.ReinhardModified) { sliderWhiteLevel.Enabled = true; sliderLuminanceSaturation.Enabled = true; } }; #endregion groupToneMapping.AdjustHeightFromChildren(); #endregion #region Group Bloom GroupBox groupBloom = CommonControls.Group("Bloom", owner); // Enabled CheckBox checkBoxBloomEnabled = CommonControls.CheckBox("Enabled", groupBloom, asset.Bloom.Enabled, asset.Bloom, "Enabled", "The effect produces fringes (or feathers) of light around very bright objects in an image."); // Scale var sliderBloomScale = CommonControls.SliderNumericFloat("Scale", groupBloom, asset.Bloom.Scale, false, true, 0, 2, asset.Bloom, "Scale"); // Threshold var sliderBloomThreshold = CommonControls.SliderNumericFloat("Threshold", groupBloom, asset.Bloom.Threshold, false, true, 0, 10, asset.Bloom, "Threshold"); // Enabled checkBoxBloomEnabled.CheckedChanged += delegate { sliderBloomScale.Enabled = asset.Bloom.Enabled; sliderBloomThreshold.Enabled = asset.Bloom.Enabled; }; groupBloom.AdjustHeightFromChildren(); #endregion #region Group MLAA GroupBox groupMlaa = CommonControls.Group("MLAA", owner); // Enabled CheckBox checkBoxMlaaEnabled = CommonControls.CheckBox("Enabled", groupMlaa, asset.MLAA.Enabled, asset.MLAA, "Enabled", "Enables Morphological Antialiasing."); #region Edge Detection var comboBoxEdgeDetection = CommonControls.ComboBox("Edge Detection Type", groupMlaa, "Color: uses the color information. Good for texture and geometry aliasing. Depth: uses the depth buffer. Great for geometry aliasing. Both: the two at the same time. A little more costly with slightly better results."); // Add textures name comboBoxEdgeDetection.Items.Add("Both"); comboBoxEdgeDetection.Items.Add("Color"); comboBoxEdgeDetection.Items.Add("Depth"); // Events comboBoxEdgeDetection.ItemIndexChanged += delegate { switch (comboBoxEdgeDetection.ItemIndex) { case 0: asset.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Both; break; case 1: asset.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color; break; case 2: asset.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Depth; break; } }; comboBoxEdgeDetection.Draw += delegate { if (comboBoxEdgeDetection.ListBoxVisible) return; switch (asset.MLAA.EdgeDetection) { case MLAA.EdgeDetectionType.Both: comboBoxEdgeDetection.ItemIndex = 0; break; case MLAA.EdgeDetectionType.Color: comboBoxEdgeDetection.ItemIndex = 1; break; case MLAA.EdgeDetectionType.Depth: comboBoxEdgeDetection.ItemIndex = 2; break; } }; #endregion // Threshold Color var sliderMlaaColorThreshold = CommonControls.SliderNumericFloat("Color Threshold", groupMlaa, asset.MLAA.ThresholdColor, false, false, 0, 0.5f, asset.MLAA, "ThresholdColor"); // Threshold Depth var sliderMlaaDepthThreshold = CommonControls.SliderNumericFloat("Depth Threshold", groupMlaa, asset.MLAA.ThresholdDepth, false, false, 0, 0.5f, asset.MLAA, "ThresholdDepth"); checkBoxMlaaEnabled.CheckedChanged += delegate { comboBoxEdgeDetection.Enabled = asset.MLAA.Enabled; sliderMlaaColorThreshold.Enabled = asset.MLAA.Enabled; sliderMlaaDepthThreshold.Enabled = asset.MLAA.Enabled; }; groupMlaa.AdjustHeightFromChildren(); #endregion #region Group Film Grain GroupBox groupFilmGrain = CommonControls.Group("Film Grain", owner); // Enabled CheckBox checkBoxFilmGrainEnabled = CommonControls.CheckBox("Enabled", groupFilmGrain, asset.FilmGrain.Enabled, asset.FilmGrain, "Enabled", "Is the random optical texture of processed photographic film."); // Strength var sliderFilmgrainStrength = CommonControls.SliderNumericFloat("Strength", groupFilmGrain, asset.FilmGrain.Strength, false, true, 0, 0.5f, asset.FilmGrain, "Strength"); // Random Noise Strength var sliderFilmGrainRandomNoiseStrength = CommonControls.SliderNumericFloat("Random Noise Strength", groupFilmGrain, asset.FilmGrain.RandomNoiseStrength, false, false, 0, 5, asset.FilmGrain, "RandomNoiseStrength"); // Accentuate Dark Noise Power var sliderFilmGrainAccentuateDarkNoisePower = CommonControls.SliderNumericFloat("Accentuate Dark Noise Power", groupFilmGrain, asset.FilmGrain.AccentuateDarkNoisePower, false, false, 0, 10, asset.FilmGrain, "AccentuateDarkNoisePower"); checkBoxFilmGrainEnabled.CheckedChanged += delegate { sliderFilmgrainStrength.Enabled = asset.FilmGrain.Enabled; sliderFilmGrainRandomNoiseStrength.Enabled = asset.FilmGrain.Enabled; sliderFilmGrainAccentuateDarkNoisePower.Enabled = asset.FilmGrain.Enabled; }; groupFilmGrain.AdjustHeightFromChildren(); #endregion #region Group Adjust Levels GroupBox groupAdjustLevels = CommonControls.Group("Adjust Levels", owner); // Enabled CheckBox checkBoxAdjustLevelsEnabled = CommonControls.CheckBox("Enabled", groupAdjustLevels, asset.AdjustLevels.Enabled, asset.AdjustLevels, "Enabled", "Adjust color levels just like Photoshop."); // Input Black var sliderAdjustLevelsInputBlack = CommonControls.SliderNumericFloat("Input Black", groupAdjustLevels, asset.AdjustLevels.InputBlack, false, false, 0, 0.9f, asset.AdjustLevels, "InputBlack"); // Input White var sliderAdjustLevelsInputWhite = CommonControls.SliderNumericFloat("Input White", groupAdjustLevels, asset.AdjustLevels.InputWhite, false, false, 0.1f, 1f, asset.AdjustLevels, "InputWhite"); // Input Gamma var sliderAdjustLevelsInputGamma = CommonControls.SliderNumericFloat("Input Gamma", groupAdjustLevels, asset.AdjustLevels.InputGamma, false, false, 0.01f, 9.99f, asset.AdjustLevels, "InputGamma"); // Output Black var sliderAdjustLevelsOutputBlack = CommonControls.SliderNumericFloat("Output Black", groupAdjustLevels, asset.AdjustLevels.OutputBlack, false, false, 0, 1, asset.AdjustLevels, "OutputBlack"); // Output White var sliderAdjustLevelsOutputWhite = CommonControls.SliderNumericFloat("Output White", groupAdjustLevels, asset.AdjustLevels.OutputWhite, false, false, 0, 1, asset.AdjustLevels, "OutputWhite"); checkBoxAdjustLevelsEnabled.CheckedChanged += delegate { sliderAdjustLevelsInputBlack.Enabled = asset.AdjustLevels.Enabled; sliderAdjustLevelsInputWhite.Enabled = asset.AdjustLevels.Enabled; sliderAdjustLevelsInputGamma.Enabled = asset.AdjustLevels.Enabled; sliderAdjustLevelsOutputBlack.Enabled = asset.AdjustLevels.Enabled; sliderAdjustLevelsOutputWhite.Enabled = asset.AdjustLevels.Enabled; }; groupAdjustLevels.AdjustHeightFromChildren(); #endregion #region Group Color Correction GroupBox groupColorCorrection = CommonControls.Group("Color Correction", owner); // Enabled CheckBox checkBoxColorCorrectionEnabled = CommonControls.CheckBox("Enabled", groupColorCorrection, asset.ColorCorrection.Enabled, asset.ColorCorrection, "Enabled"); // First Lookup Table var assetCreatorFirstLookupTable = CommonControls.AssetSelector<LookupTable>("First Lookup Table", groupColorCorrection, asset.ColorCorrection, "FirstLookupTable"); // Second Lookup Table var assetCreatorSecondLookupTable = CommonControls.AssetSelector<LookupTable>("Second Lookup Table", groupColorCorrection, asset.ColorCorrection, "SecondLookupTable"); assetCreatorSecondLookupTable.Draw += delegate { assetCreatorSecondLookupTable.Enabled = asset.ColorCorrection.FirstLookupTable != null && checkBoxColorCorrectionEnabled.Checked; }; // Lerp Original Color Amount var sliderLerpOriginalColorAmount = CommonControls.SliderNumericFloat("Lerp Original Color", groupColorCorrection, asset.ColorCorrection.LerpOriginalColorAmount, false, false, 0, 1, asset.ColorCorrection, "LerpOriginalColorAmount"); sliderLerpOriginalColorAmount.Draw += delegate { sliderLerpOriginalColorAmount.Enabled = asset.ColorCorrection.FirstLookupTable != null && checkBoxColorCorrectionEnabled.Checked; }; // Lerp Lookup Tables Amount var sliderLerpLookupTablesAmount = CommonControls.SliderNumericFloat("Lerp Lookup Tables", groupColorCorrection, asset.ColorCorrection.LerpLookupTablesAmount, false, false, 0, 1, asset.ColorCorrection, "LerpLookupTablesAmount"); sliderLerpLookupTablesAmount.Draw += delegate { sliderLerpLookupTablesAmount.Enabled = asset.ColorCorrection.SecondLookupTable != null && asset.ColorCorrection.FirstLookupTable != null && checkBoxColorCorrectionEnabled.Checked; }; checkBoxColorCorrectionEnabled.CheckedChanged += delegate { assetCreatorFirstLookupTable.Enabled = asset.ColorCorrection.Enabled; }; groupColorCorrection.AdjustHeightFromChildren(); #endregion } // AddControls
} // AddGameObjectControlsToInspector /// <summary> /// Add game object component controls to the specified control. /// </summary> public static void AddGameObjectControls(GameObject gameObject, ClipControl control) { if (gameObject == null) { throw new ArgumentNullException("gameObject"); } if (control == null) { throw new ArgumentNullException("control"); } #region Name var nameLabel = new Label { Parent = control, Text = "Name", Left = 10, Top = 10, Height = 25, Alignment = Alignment.BottomCenter, }; var nameTextBox = new TextBox { Parent = control, Width = control.ClientWidth - nameLabel.Width - 12, Text = gameObject.Name, Left = 60, Top = 10, Anchor = Anchors.Left | Anchors.Top | Anchors.Right }; var lastSetName = gameObject.Name; nameTextBox.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.Key == Keys.Enter) { string oldName = gameObject.Name; gameObject.Name = nameTextBox.Text; //asset.SetUniqueName(window.AssetName); if (oldName != gameObject.Name) { nameTextBox.Text = gameObject.Name; // The name could be change if the name entered was not unique. gameObject.Name = oldName; // This is done for the undo. using (Transaction.Create()) { // Apply the command and store for the undo feature. ActionManager.SetProperty(gameObject, "Name", nameTextBox.Text); ActionManager.CallMethod(// Redo UserInterfaceManager.Invalidate, // Undo UserInterfaceManager.Invalidate); } } lastSetName = gameObject.Name; } }; nameTextBox.FocusLost += delegate { string oldName = gameObject.Name; gameObject.Name = nameTextBox.Text; //asset.SetUniqueName(window.AssetName); if (oldName != gameObject.Name) { nameTextBox.Text = gameObject.Name; // The name could be change if the name entered was not unique. gameObject.Name = oldName; // This is done for the undo. using (Transaction.Create()) { // Apply the command and store for the undo feature. ActionManager.SetProperty(gameObject, "Name", nameTextBox.Text); ActionManager.CallMethod(// Redo UserInterfaceManager.Invalidate, // Undo UserInterfaceManager.Invalidate); } lastSetName = gameObject.Name; } }; nameTextBox.Draw += delegate { if (lastSetName != gameObject.Name) { lastSetName = gameObject.Name; nameTextBox.Text = gameObject.Name; } }; #endregion #region Layer var comboBoxLayer = CommonControls.ComboBox("", control); comboBoxLayer.MaxItemsShow = 30; comboBoxLayer.ItemIndexChanged += delegate { // Store new asset. if (gameObject.Layer.Number != comboBoxLayer.ItemIndex) // If it change { using (Transaction.Create()) { // Apply the command and store for the undo feature. ActionManager.SetProperty(gameObject, "Layer", Layer.GetLayerByNumber(comboBoxLayer.ItemIndex)); ActionManager.CallMethod(// Redo UserInterfaceManager.Invalidate, // Undo UserInterfaceManager.Invalidate); } } }; comboBoxLayer.Draw += delegate { // Add layer names here because someone could change them. comboBoxLayer.Items.Clear(); for (int i = 0; i < 30; i++) { comboBoxLayer.Items.Add(Layer.GetLayerByNumber(i).Name); } if (comboBoxLayer.ListBoxVisible) { return; } // Identify current index comboBoxLayer.ItemIndex = gameObject.Layer.Number; }; #endregion ) #region Active CheckBox active = CommonControls.CheckBox("Active", control, gameObject.Active, gameObject, "Active"); active.Top = comboBoxLayer.Top + 5; #endregion if (gameObject is GameObject3D) { GameObject3D gameObject3D = (GameObject3D)gameObject; #region Transform Component var panel = CommonControls.PanelCollapsible("Transform", control, 0); // Position var vector3BoxPosition = CommonControls.Vector3Box("Position", panel, gameObject3D.Transform.LocalPosition, gameObject3D.Transform, "LocalPosition"); // Orientation. // This control has too many special cases, I need to do it manually. Vector3 initialValue = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI, gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI, gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI); initialValue.X = (float)Math.Round(initialValue.X, 4); initialValue.Y = (float)Math.Round(initialValue.Y, 4); initialValue.Z = (float)Math.Round(initialValue.Z, 4); var vector3BoxRotation = CommonControls.Vector3Box("Rotation", panel, initialValue); vector3BoxRotation.ValueChanged += delegate { Vector3 propertyValue = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI, gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI, gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI); // Round to avoid precision problems. propertyValue.X = (float)Math.Round(propertyValue.X, 4); propertyValue.Y = (float)Math.Round(propertyValue.Y, 4); propertyValue.Z = (float)Math.Round(propertyValue.Z, 4); // I compare the value of the transform property rounded to avoid a precision mismatch. if (propertyValue != vector3BoxRotation.Value) { using (Transaction.Create()) { Quaternion newValue = Quaternion.CreateFromYawPitchRoll(vector3BoxRotation.Value.Y * (float)Math.PI / 180, vector3BoxRotation.Value.X * (float)Math.PI / 180, vector3BoxRotation.Value.Z * (float)Math.PI / 180); ActionManager.SetProperty(gameObject3D.Transform, "LocalRotation", newValue); ActionManager.CallMethod(// Redo UserInterfaceManager.Invalidate, // Undo UserInterfaceManager.Invalidate); } } }; vector3BoxRotation.Draw += delegate { Vector3 localRotationDegrees = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI, gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI, gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI); // Round to avoid precision problems. localRotationDegrees.X = (float)Math.Round(localRotationDegrees.X, 4); localRotationDegrees.Y = (float)Math.Round(localRotationDegrees.Y, 4); localRotationDegrees.Z = (float)Math.Round(localRotationDegrees.Z, 4); if (vector3BoxRotation.Value != localRotationDegrees) { vector3BoxRotation.Value = localRotationDegrees; } }; // Scale var vector3BoxScale = CommonControls.Vector3Box("Scale", panel, gameObject3D.Transform.LocalScale, gameObject3D.Transform, "LocalScale"); #endregion #region Camera if (gameObject3D.Camera != null) { var panelCamera = CommonControls.PanelCollapsible("Camera", control, 0); CameraControls.AddControls(gameObject3D.Camera, panelCamera); } #endregion #region Model Filter if (gameObject3D.ModelFilter != null) { var panelModelFilter = CommonControls.PanelCollapsible("Model Filter", control, 0); ModelFilterControls.AddControls(gameObject3D.ModelFilter, panelModelFilter); } #endregion #region Model Renderer if (gameObject3D.ModelRenderer != null) { var panelModelRenderer = CommonControls.PanelCollapsible("Model Renderer", control, 0); ModelRendererControls.AddControls(gameObject3D.ModelRenderer, panelModelRenderer); } #endregion #region Light if (gameObject3D.Light != null) { if (gameObject3D.SpotLight != null) { var panelSpotLight = CommonControls.PanelCollapsible("Spot Light", control, 0); SpotLightControls.AddControls(gameObject3D.SpotLight, panelSpotLight); } if (gameObject3D.PointLight != null) { var panelPointLight = CommonControls.PanelCollapsible("Point Light", control, 0); PointLightControls.AddControls(gameObject3D.PointLight, panelPointLight); } if (gameObject3D.DirectionalLight != null) { var panelDirectionalLight = CommonControls.PanelCollapsible("Directional Light", control, 0); DirectionalLightControls.AddControls(gameObject3D.DirectionalLight, panelDirectionalLight); } } #endregion } else { GameObject2D gameObject2D = (GameObject2D)gameObject; } } // AddGameObjectControls