/// <summary> /// Changes the entity back to it's default configuration /// </summary> public void MakeDefault() { _bodyImage.Color = Color.White.ToRGBColor(); FocusLost += c => RGBColor = Color.White.ToRGBColor(); FocusGain += c => RGBColor = Color.Red.ToRGBColor(); OnDown += c => RGBColor = Color.Green.ToRGBColor(); }
public Button(Node parent, string name, Vector2 position, Vector2 bounds, RGBColor color) : base(parent, name) { Body.Position = position; Body.Bounds = bounds; //Make our rectangles _bodyImage = new ShapeTypes.Rectangle(this, "BodyImage", true); _bodyImage.LinkDependency(ShapeTypes.Rectangle.DEPENDENCY_BODY, Body); _bodyImage.Color = color; }
public static XYZColor RGBtoXYZ(RGBColor rgb) { XYZColor xyz = new XYZColor(); float r, g, b; r = rgb.R; g = rgb.G; b = rgb.B; if (r > 0.04045f) { r = (float)Math.Pow((r + 0.055) / 1.055, 2.4); } else { r = r / 12.92f; } if (g > 0.04045) { g = (float)Math.Pow((g + 0.055f) / 1.055f, 2.4f); } else { g = g / 12.92f; } if (b > 0.04045f) { b = (float)Math.Pow((b + 0.055f) / 1.055f, 2.4f); } else { b = b / 12.92f; } r *= 100; g *= 100; b *= 100; xyz.X = r * 0.4124f + g * 0.3576f + b * 0.1805f; xyz.Y = r * 0.2126f + g * 0.7152f + b * 0.0722f; xyz.Z = r * 0.0193f + g * 0.1192f + b * 0.9505f; xyz.Alpha = rgb.Alpha; return(xyz); }
public TextButton(Node parent, string name, Vector2 position, RGBColor color) : base(parent, name) { Body.Position = position; _textBody = new Body(this, "TextBody"); TextRender = new TextRender(this, "Render", Assets.Font, ""); TextRender.LinkDependency(TextRender.DEPENDENCY_BODY, _textBody); TextRender.Layer = .9f; //Start setting up Render's body _textBody.Bounds = TextRender.Bounds; Body.Bounds = TextRender.Bounds + Spacing; _textBody.Position = new Vector2(Body.Position.X + Body.Bounds.X / 2 - _textBody.Bounds.X / 2, Body.Position.Y + Body.Bounds.Y / 2 - _textBody.Bounds.Y / 2); //Make our rectangles _bodyImage = new ShapeTypes.Rectangle(this, "BodyImage", true); _bodyImage.LinkDependency(ShapeTypes.Rectangle.DEPENDENCY_BODY, Body); _bodyImage.Color = color; }
public void MakeNextColorButton(RGBColor color) { //Change the color to the base hue value HSVColor hsv = ColorMath.RGBtoHSV(color); //make the color the purest possible hsv.S = 1; hsv.V = 1; RGBColor rgb = hsv.ToRGBColor(); Button button = new Button(_page, "ColorButton" + _lastX.ToString(), _lastTab, new Vector2(_lastX, 539), new Vector2(20, 20), rgb); button.OnReleased += control => _currentColor = rgb; button.OnDown += c => button.RGBColor = Color.White.ToRGBColor(); button.FocusLost += c => button.RGBColor = rgb; button.FocusGain += c => button.RGBColor = rgb; _lastX += 25; _lastTab.X++; }
//Extensions public static RGBColor ToRGBColor(this Color c) { RGBColor rgbcolor = new RGBColor(); rgbcolor.R = ((float)c.R / Byte.MaxValue); rgbcolor.G = ((float)c.G / Byte.MaxValue); rgbcolor.B = ((float)c.B / Byte.MaxValue); rgbcolor.Alpha = ((float)c.A / Byte.MaxValue); return rgbcolor; }
public static XYZColor RGBtoXYZ(RGBColor rgb) { XYZColor xyz = new XYZColor(); float r, g, b; r = rgb.R; g = rgb.G; b = rgb.B; if (r > 0.04045f) r = (float)Math.Pow((r + 0.055)/1.055, 2.4); else r = r / 12.92f; if (g > 0.04045) g =(float)Math.Pow((g + 0.055f)/1.055f , 2.4f); else g = g/12.92f; if (b > 0.04045f) b = (float)Math.Pow((b + 0.055f)/1.055f , 2.4f); else b = b/12.92f; r *= 100; g *= 100; b *= 100; xyz.X = r*0.4124f + g*0.3576f + b*0.1805f; xyz.Y = r*0.2126f + g*0.7152f + b*0.0722f; xyz.Z = r*0.0193f + g*0.1192f + b*0.9505f; xyz.Alpha = rgb.Alpha; return xyz; }
public static HSVColor RGBtoHSV(RGBColor rgb) { float max, min; HSVColor hsv = new HSVColor(); min = Math.Min(Math.Min(rgb.R, rgb.G), rgb.B); max = Math.Max(Math.Max(rgb.R, rgb.G), rgb.B); hsv.V = max; if (hsv.V < .0001f) { hsv.H = hsv.S = 0; return hsv; } rgb.R /= hsv.V; rgb.G /= hsv.V; rgb.B /= hsv.V; min = Math.Min(Math.Min(rgb.R, rgb.G), rgb.B); max = Math.Max(Math.Max(rgb.R, rgb.G), rgb.B); hsv.S = max - min; if (hsv.S < .0001f) { hsv.H = 0; return hsv; } rgb.R = (rgb.R - min) / (max - min); rgb.G = (rgb.G - min) / (max - min); rgb.B = (rgb.B - min) / (max - min); min = Math.Min(Math.Min(rgb.R, rgb.G), rgb.B); max = Math.Max(Math.Max(rgb.R, rgb.G), rgb.B); if (Math.Abs(max - rgb.R) < .0001f) { hsv.H = 1f/6f * (rgb.G - rgb.B); if (hsv.H < 0) { hsv.H += 1f; } } else if (Math.Abs(max - rgb.G) < .0001f) { hsv.H = 2f/6f + 1f/6f * (rgb.B - rgb.R); } else /* rgb_max == rgb.b */ { hsv.H = 4f/6f + 1f/6f * (rgb.R - rgb.G); } hsv.Alpha = rgb.Alpha; return hsv; }