public MaterialComputeColorKeys(ObjectParameterKey<Texture> textureBaseKey, ParameterKey valueBaseKey, Color? defaultTextureValue = null, bool isColor = true) { //if (textureBaseKey == null) throw new ArgumentNullException("textureBaseKey"); //if (valueBaseKey == null) throw new ArgumentNullException("valueBaseKey"); TextureBaseKey = textureBaseKey; ValueBaseKey = valueBaseKey; DefaultTextureValue = defaultTextureValue; IsColor = isColor; }
public void TestBasicInvalidations() { // - test the properties that are supposed to invalidate the object measurement UIElementLayeringTests.TestMeasureInvalidation(this, () => Font = null); UIElementLayeringTests.TestMeasureInvalidation(this, () => Text = "New Text"); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => TextColor = new Color(1, 2, 3, 4)); }
/// <summary> /// Create an atlas texture element that contains all the information from the source texture. /// </summary> /// <param name="name">The reference name of the element</param> /// <param name="texture"></param> /// <param name="sourceRegion">The region of the element in the source texture</param> /// <param name="borderSize">The size of the border around the element in the output atlas</param> /// <param name="borderModeU">The border mode along the U axis</param> /// <param name="borderModeV">The border mode along the V axis</param> /// <param name="borderColor">The color of the border</param> public AtlasTextureElement(string name, Image texture, RotableRectangle sourceRegion, int borderSize, TextureAddressMode borderModeU, TextureAddressMode borderModeV, Color? borderColor = null) { Name = name; Texture = texture; SourceRegion = sourceRegion; BorderSize = borderSize; BorderModeU = borderModeU; BorderModeV = borderModeV; BorderColor = borderColor ?? Color.Transparent; }
public InternalDrawCommand(SpriteBatch spriteBatch, ref Vector2 fontSize, ref Vector2 position, ref Color color, float rotation, ref Vector2 origin, ref Vector2 scale, SpriteEffects spriteEffects, float depth) { SpriteBatch = spriteBatch; Position = position; Color = color; Rotation = rotation; Origin = origin; Scale = scale; SpriteEffects = spriteEffects; Depth = depth; FontSize = fontSize; }
public static Material Create(GraphicsDevice device, Color color, float intensity) { var material = Material.New(device, new MaterialDescriptor { Attributes = { Diffuse = new MaterialDiffuseMapFeature(new ComputeColor()), DiffuseModel = new MaterialDiffuseLambertModelFeature(), Emissive = new MaterialEmissiveMapFeature(new ComputeColor()) } }); // set the color to the material material.Parameters.Set(MaterialKeys.DiffuseValue, new Color4(color).ToColorSpace(device.ColorSpace)); material.Parameters.Set(MaterialKeys.EmissiveIntensity, intensity); material.Parameters.Set(MaterialKeys.EmissiveValue, new Color4(color).ToColorSpace(device.ColorSpace)); return material; }
/// <summary> /// Raised when the <see cref="Color"/> property is modified. /// </summary> private void OnColorChanged() { bool isInitializing = !templateApplied && initializingProperty == null; if (isInitializing) { initializingProperty = ColorProperty; } if (!interlock) { InternalColor = ColorHSV.FromColor(Color); var colorRGBA = InternalColor.ToColor(); interlock = true; SetCurrentValue(RedProperty, (byte)(Math.Round(colorRGBA.R * 255.0f))); SetCurrentValue(GreenProperty, (byte)(Math.Round(colorRGBA.G * 255.0f))); SetCurrentValue(BlueProperty, (byte)(Math.Round(colorRGBA.B * 255.0f))); SetCurrentValue(AlphaProperty, (byte)(Math.Round(colorRGBA.A * 255.0f))); SetCurrentValue(HueProperty, InternalColor.H); SetCurrentValue(SaturationProperty, InternalColor.S * 100.0f); SetCurrentValue(BrightnessProperty, InternalColor.V * 100.0f); interlock = false; } if (!suspendBindingUpdates) { RenderColorPickerSurface(); } else if (colorPreviewRenderSurface != null) { colorPreviewRenderSurface.Fill = new SolidColorBrush(Color.ToSystemColor()); } UpdateBinding(ColorProperty); if (isInitializing) { initializingProperty = null; } }
/// <summary> /// Update the color surface brush according to the current <see cref="Hue"/> value. /// </summary> private void RenderColorPickerSurface() { if (colorPreviewRenderSurface != null) { colorPreviewRenderSurface.Fill = new SolidColorBrush(Color.ToSystemColor()); } if (colorPickerRenderSurface != null) { // Ensure the color picker is loaded if (!double.IsNaN(colorPickerRenderSurface.Width) && !double.IsNaN(colorPickerRenderSurface.Height)) { var width = (int)colorPickerRenderSurface.Width; var height = (int)colorPickerRenderSurface.Height; PixelFormat pf = PixelFormats.Bgr32; int rawStride = (width * pf.BitsPerPixel + 7) / 8; var rawImage = new byte[rawStride * height]; for (int j = 0; j < height; ++j) { float y = j / (float)(height - 1); for (int i = 0; i < width; ++i) { float x = i / (float)(width - 1); var color4 = new ColorHSV(Hue, x, y, 1.0f).ToColor(); var color = new Color(color4); rawImage[(i + j * width) * 4 + 0] = color.B; rawImage[(i + j * width) * 4 + 1] = color.G; rawImage[(i + j * width) * 4 + 2] = color.R; } } colorPickerRenderSurface.Fill = new DrawingBrush(new ImageDrawing(BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, rawStride), new Rect(0.0f, 0.0f, width, height))); } } }
private Image CreateMockTexture(int width, int height, Color color) { var texture = Image.New2D(width, height, 1, PixelFormat.R8G8B8A8_UNorm); unsafe { var ptr = (Color*)texture.DataPointer; // Fill in mock data for (var y = 0; y < height; ++y) for (var x = 0; x < width; ++x) { ptr[y * width + x] = y < height / 2 ? color : Color.White; } } return texture; }
public AlphaLevelTest(Rectangle region, Color? transparencyColor, AlphaLevels expectedResult) { Region = region; TransparencyColor = transparencyColor; ExpectedResult = expectedResult; }
private AtlasTextureElement CreateElement(string name, int width, int height, int borderSize = 0, Color? color = null) { return CreateElement(name, width, height, borderSize, TextureAddressMode.Clamp, color); }
private AtlasTextureElement CreateElement(string name, int width, int height, int borderSize, TextureAddressMode borderMode, Color? color = null, Color? borderColor = null) { Image image = null; if (color != null) image = CreateMockTexture(width, height, color.Value); return new AtlasTextureElement(name, image, new RotableRectangle(0, 0, width, height), borderSize, borderMode, borderMode, borderColor); }
public ScrollBar() { BarColorInternal = new Color(0, 0, 0, 0); }
/// <inheritdoc/> public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // TODO: string conversion is not correctly supported if (value is Color) { var color = (Color)value; if (targetType == typeof(System.Windows.Media.Color)) { return(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B)); } if (targetType == typeof(Color)) { return(color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B))); } if (targetType == typeof(string)) { return('#' + color.ToRgba().ToString("X8")); } } if (value is Color3) { var color = (Color3)value; if (targetType == typeof(System.Windows.Media.Color)) { return(System.Windows.Media.Color.FromScRgb(1.0f, color.R, color.G, color.B)); } if (targetType == typeof(Color)) { return(new Color(color.R, color.G, color.B)); } if (targetType == typeof(Color3)) { return(color); } if (targetType == typeof(Color4)) { return(new Color4(color.R, color.G, color.B, 1.0f)); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(System.Windows.Media.Color.FromScRgb(1.0f, color.R, color.G, color.B))); } if (targetType == typeof(string)) { return('#' + color.ToRgb().ToString("X6")); } } if (value is Color4) { var color = (Color4)value; if (targetType == typeof(System.Windows.Media.Color)) { return(System.Windows.Media.Color.FromScRgb(color.A, color.R, color.G, color.B)); } if (targetType == typeof(Color)) { return(new Color(color.R, color.G, color.B, color.A)); } if (targetType == typeof(Color3)) { return(new Color3(color.R, color.G, color.B)); } if (targetType == typeof(Color4)) { return(color); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(System.Windows.Media.Color.FromScRgb(color.A, color.R, color.G, color.B))); } if (targetType == typeof(string)) { return('#' + color.ToRgba().ToString("X8")); } } if (value is string) { var stringColor = value as string; int intValue; if (!stringColor.StartsWith("#") || !Int32.TryParse(stringColor.Substring(1), NumberStyles.HexNumber, null, out intValue)) { intValue = unchecked ((int)0xFF000000); } if (targetType == typeof(Color)) { return(Color.FromRgba(intValue)); } if (targetType == typeof(Color3)) { return(new Color3(intValue)); } if (targetType == typeof(Color4)) { return(new Color4(intValue)); } if (targetType == typeof(System.Windows.Media.Color)) { return(System.Windows.Media.Color.FromArgb( (byte)((intValue >> 24) & 255), (byte)(intValue & 255), (byte)((intValue >> 8) & 255), (byte)((intValue >> 16) & 255))); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(System.Windows.Media.Color.FromArgb( (byte)((intValue >> 24) & 255), (byte)(intValue & 255), (byte)((intValue >> 8) & 255), (byte)((intValue >> 16) & 255)))); } if (targetType == typeof(string)) { return(stringColor); } } throw new NotSupportedException("Requested conversion is not supported."); }
public void PickColorTest() { var pixelCoordinate1 = new Int2(4, 4); var theoreticalColor1 = new Color(0, 255, 46, 255); var pixelCoordinate2 = new Int2(3, 4); var theoreticalColor2 = new Color(222, 76, 255, 255); var images = new[] { "BgraSheet.dds", "RgbaSheet.dds" }; foreach (var image in images) { using (var texTool = new TextureTool()) using (var texImage = texTool.Load(Module.PathToInputImages + image)) { var foundColor = texTool.PickColor(texImage, pixelCoordinate1); Assert.AreEqual(theoreticalColor1, foundColor); foundColor = texTool.PickColor(texImage, pixelCoordinate2); Assert.AreEqual(theoreticalColor2, foundColor); } } }
/// <summary> /// Initializes a new instance of the <see cref="LightColorRgb"/> class. /// </summary> /// <param name="color">The color.</param> public LightColorRgb(Color color) { Color = (Color3)color; }
public void TestBasicInvalidations() { // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => OverlayColor = new Color(1, 2, 3, 4)); UIElementLayeringTests.TestNoInvalidation(this, () => IsModal = !IsModal); }
/// <inheritdoc/> public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var brush = value as SolidColorBrush; if (brush != null) { value = brush.Color; } if (value is Color) { var color = (Color)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return(color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } if (value is Color3) { var color = (Color3)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return((Color)color); } if (targetType == typeof(Color3)) { return(color); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbToString(color.ToRgb())); } } if (value is Color4) { var color = (Color4)value; if (targetType == typeof(System.Windows.Media.Color)) { return(color.ToSystemColor()); } if (targetType == typeof(Color)) { return((Color)color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(color.ToSystemColor())); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } if (value is System.Windows.Media.Color) { var wpfColor = (System.Windows.Media.Color)value; if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(wpfColor)); } var color = new Color(wpfColor.R, wpfColor.G, wpfColor.B, wpfColor.A); if (targetType == typeof(System.Windows.Media.Color)) { return(color); } if (targetType == typeof(Color)) { return(color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } if (targetType == typeof(string)) { return(ColorExtensions.RgbaToString(color.ToRgba())); } } var stringColor = value as string; if (stringColor != null) { var intValue = 0xFF000000; if (stringColor.StartsWith("#")) { if (stringColor.Length == "#000".Length && uint.TryParse(stringColor.Substring(1, 3), NumberStyles.HexNumber, null, out intValue)) { intValue = ((intValue & 0x00F) << 16) | ((intValue & 0x00F) << 20) | ((intValue & 0x0F0) << 4) | ((intValue & 0x0F0) << 8) | ((intValue & 0xF00) >> 4) | ((intValue & 0xF00) >> 8) | (0xFF000000); } if (stringColor.Length == "#000000".Length && uint.TryParse(stringColor.Substring(1, 6), NumberStyles.HexNumber, null, out intValue)) { intValue = ((intValue & 0x000000FF) << 16) | (intValue & 0x0000FF00) | ((intValue & 0x00FF0000) >> 16) | (0xFF000000); } if (stringColor.Length == "#00000000".Length && uint.TryParse(stringColor.Substring(1, 8), NumberStyles.HexNumber, null, out intValue)) { intValue = ((intValue & 0x000000FF) << 16) | (intValue & 0x0000FF00) | ((intValue & 0x00FF0000) >> 16) | (intValue & 0xFF000000); } } if (targetType == typeof(Color)) { return(Color.FromRgba(intValue)); } if (targetType == typeof(Color3)) { return(new Color3(intValue)); } if (targetType == typeof(Color4)) { return(new Color4(intValue)); } if (targetType == typeof(System.Windows.Media.Color)) { return(System.Windows.Media.Color.FromArgb( (byte)((intValue >> 24) & 255), (byte)(intValue & 255), (byte)((intValue >> 8) & 255), (byte)((intValue >> 16) & 255))); } if (targetType.IsAssignableFrom(typeof(SolidColorBrush))) { return(new SolidColorBrush(System.Windows.Media.Color.FromArgb( (byte)((intValue >> 24) & 255), (byte)(intValue & 255), (byte)((intValue >> 8) & 255), (byte)((intValue >> 16) & 255)))); } if (targetType == typeof(string)) { return(stringColor); } } #if DEBUG if (value == null || value == DependencyProperty.UnsetValue) { return(DependencyProperty.UnsetValue); } throw new NotSupportedException("Requested conversion is not supported."); #else return(DependencyProperty.UnsetValue); #endif }
public override void SetDefaults() { Width = 100.0f; Height = 100.0f; Format = TextureFormat.Compressed; Hint = TextureHint.Color; Alpha = AlphaFormat.Auto; ColorKeyColor = new Color(255, 0, 255); ColorKeyEnabled = false; IsSizeInPercentage = true; GenerateMipmaps = true; PremultiplyAlpha = true; }
public override void SetDefaults() { Format = TextureFormat.Compressed; Alpha = AlphaFormat.Interpolated; ColorKeyColor = new Color(255, 0, 255); ColorKeyEnabled = false; GenerateMipmaps = false; PremultiplyAlpha = true; }
/// <summary> /// Initializes a new instance of the <see cref="ColorRgbProvider"/> class. /// </summary> /// <param name="color">The color.</param> public ColorRgbProvider(Color color) { Value = (Color3)color; }
private void DrawBorder(Border border, ref Vector3 offsets, ref Vector3 borderSize, ref Color borderColor, UIRenderingContext context) { var worldMatrix = border.WorldMatrixInternal; worldMatrix.M41 += worldMatrix.M11 * offsets.X + worldMatrix.M21 * offsets.Y + worldMatrix.M31 * offsets.Z; worldMatrix.M42 += worldMatrix.M12 * offsets.X + worldMatrix.M22 * offsets.Y + worldMatrix.M32 * offsets.Z; worldMatrix.M43 += worldMatrix.M13 * offsets.X + worldMatrix.M23 * offsets.Y + worldMatrix.M33 * offsets.Z; Batch.DrawCube(ref worldMatrix, ref borderSize, ref borderColor, context.DepthBias); }
/// <inheritdoc/> public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (targetType == typeof(object)) { return(value); } var stringColor = value as string; if (stringColor != null) { int intValue; if (!stringColor.StartsWith("#") || !Int32.TryParse(stringColor.Substring(1), NumberStyles.HexNumber, null, out intValue)) { intValue = unchecked ((int)0xFF000000); } if (targetType == typeof(Color)) { return(Color.FromRgba(intValue)); } if (targetType == typeof(Color3)) { return(new Color3(intValue)); } if (targetType == typeof(Color4)) { return(new Color4(intValue)); } } if (value is SolidColorBrush) { var brush = (SolidColorBrush)value; value = brush.Color; } if (value is System.Windows.Media.Color) { var wpfColor = (System.Windows.Media.Color)value; if (targetType == typeof(Color)) { return(new Color(wpfColor.R, wpfColor.G, wpfColor.B, wpfColor.A)); } if (targetType == typeof(Color3)) { return(new Color3(wpfColor.ScR, wpfColor.ScG, wpfColor.ScB)); } if (targetType == typeof(Color4)) { return(new Color4(wpfColor.ScR, wpfColor.ScG, wpfColor.ScB, wpfColor.ScA)); } } if (value is Color) { var color = (Color)value; if (targetType == typeof(Color)) { return(color); } if (targetType == typeof(Color3)) { return(color.ToColor3()); } if (targetType == typeof(Color4)) { return(color.ToColor4()); } } if (value is Color3) { var color = (Color3)value; if (targetType == typeof(Color)) { return(new Color(color.R, color.G, color.B)); } if (targetType == typeof(Color3)) { return(color); } if (targetType == typeof(Color4)) { return(new Color4(1.0f, color.R, color.G, color.B)); } } if (value is Color4) { var color = (Color4)value; if (targetType == typeof(Color)) { return(new Color(color.R, color.G, color.B, color.A)); } if (targetType == typeof(Color3)) { return(new Color3(color.R, color.G, color.B)); } if (targetType == typeof(Color4)) { return(color); } } throw new NotSupportedException("Requested conversion is not supported."); }
private void ChangeImageColor(Color color) { imageElement.Color = color; }
/// <summary> /// Initializes a new instance of the <see cref="ColorKeyRequest"/> class. /// </summary> public ColorKeyRequest(Color colorKey) { ColorKey = colorKey; }
/// <summary> /// Creates an empty instance of SpriteInfo /// </summary> public SpriteInfo() { PixelsPerUnit = 100; CenterFromMiddle = true; BorderModeU = TextureAddressMode.Clamp; BorderModeV = TextureAddressMode.Clamp; BorderColor = Color.Transparent; }