/// <summary>Initializes a new instance of the <see cref="ColorMapCanvas"/> class.</summary> /// <param name="colorMap">The color map.</param> public ColorMapCanvas(ColorMap colorMap) { #if DEBUG if (colorMap == null) { throw new ArgumentNullException("colorMap", "ColorMap can not be NULL"); } #endif this.colorMap = colorMap; this.totalwidth = colorMap.Width; this.totalheight = colorMap.Height; this.left = -(this.totalwidth * 0.5f); this.right = +(this.totalwidth * 0.5f); this.top = -(this.totalheight * 0.5f); this.bottom = +(this.totalheight * 0.5f); }
private static void SetSelectionRectangle(Rectangle rectangle, TextBoxSelectionBox textBoxSelectionBox, GUIColor color) { if (rectangle.Width >= 1 && rectangle.Height >= 1) { textBoxSelectionBox.CurrentTextureName = textBoxSelectionBox.Manager.ImageCompositor.CreateRectangleTexture(textBoxSelectionBox.Name, (int)rectangle.Width, (int)rectangle.Height, 0, GUIColor.White(), GUIColor.White()); var size = textBoxSelectionBox.Manager.ImageCompositor.ReadSizeTexture(textBoxSelectionBox.CurrentTextureName); var count = (int)size.X * (int)size.Y; var colorArray = new GUIColor[count]; for (var i = 0; i < count; i++) { colorArray[i] = color; } var map = new ColorMap(colorArray, (int)size.X, (int)size.Y); textBoxSelectionBox.Manager.ImageCompositor.UpdateTexture(textBoxSelectionBox.CurrentTextureName, map); textBoxSelectionBox.ConfigActive = true; } }
/// <summary>Fills in the content of the control showing all values of Blue (0 to 255) for the given /// Red and Green.</summary> /// <param name="map">The map to update.</param> private void DrawStyleBlue(ref ColorMap map) { // i represents the current line of pixels we want to draw horizontally for (var i = 0; i < map.Height; i++) { // red is based on the current vertical position var blue = 255 - Round(255 * (double)i / map.Height); // Get the Color for this line var rgb = GUIColor.FromARGB(this.rgba.R, this.rgba.G, blue); for (var l = 0; l < map.Width; l++) { map.Set(l, i, rgb); } } }
/// <summary> /// Fills in the content of the control showing all values of Hue (from 0 to 360) , a rainbow /// </summary> /// <param name="map">The map to update.</param> private static void DrawStyleHue(ref ColorMap map) { // S and L will both be at 100% for this DrawStyle var hsl = new HSL { S = 1.0, L = 1.0 }; // i represents the current line of pixels we want to draw horizontally for (var i = 0; i < map.Height; i++) { // H (hue) is based on the current vertical position hsl.H = 1.0 - ((double)i / map.Height); // Get the Color for this line var rgb = AdobeColors.HSLToRGB(hsl); for (var l = 0; l < map.Width; l++) { map.Set(l, i, rgb); } } }
/// <summary>Create a new color-map with a vertical flip of given color-map.</summary> /// <param name="source">The source.</param> /// <returns>A vertical flipped color-map.</returns> private static ColorMap FlipColorMapHVertical(ColorMap source) { var target = new ColorMap(source.Width, source.Height); for (int x = 0; x < source.Width; x++) { for (int y = 0; y < source.Height; y++) { var sourcePixel = source.Get(x, y); target.Set(x, (source.Height - 1) - y, sourcePixel); } } return target; }
/// <summary> /// Draws the vertical line on the given color-map. /// </summary> /// <param name="colorMap">The color map to draw into.</param> /// <param name="x">The x position to draw the line.</param> /// <param name="startY">The start y to draw the line.</param> /// <param name="endY">The end y to draw the line.</param> /// <param name="colorToUse">The color to use.</param> private static void DrawVerticalLineOnColorMap(ref ColorMap colorMap, int x, int startY, int endY, GUIColor colorToUse) { for (int y = startY; y < endY; y++) { colorMap.Set(x, y, colorToUse); } }
/// <summary>Places the source array into target array. /// Its like copy a bitmap into a bitmap at a specific location.</summary> /// <param name="sourceArray">The source array.</param> /// <param name="targetArray">The target array.</param> /// <param name="placeAtX">The place at x.</param> /// <param name="placeAtY">The place at y.</param> private static void PlaceSourceColorMapIntoTargetColorMap(ColorMap sourceArray, ref ColorMap targetArray, int placeAtX, int placeAtY) { // get the source pixel for (var x = 0; x < sourceArray.Width; x++) { for (var y = 0; y < sourceArray.Height; y++) { var sourcePixel = sourceArray.Get(x, y); targetArray.TrySet(placeAtX + x, placeAtY + y, sourcePixel); } } }
private static ColorMap CreateRoundedCornerColorMap(int innerRadius, int outerRadius, GUIColor innerColor, GUIColor outerColor) { int x; int y; int width = outerRadius; int height = outerRadius; var array = new ColorMap(width, height); for (x = 0; x < +width; x++) { for (y = 0; y < +height; y++) { // get the distance to x,y var r = Math.Sqrt((x * x) + (y * y)); if (r < innerRadius) { array.Set(x, y, innerColor); } else if (r >= innerRadius && r < outerRadius) { array.Set(x, y, outerColor); } } } return array; }
/// <summary> /// Called when graphics resources need to be loaded. /// /// Use this for the usage of : /// - creation of the internal embedded controls. /// - setting of the variables and resources in this control /// - to load any game-specific graphics resources /// - take over the config width and height and use it into State /// - overriding how this item looks like , by settings its texture or theme /// /// Call base.LoadContent before you do your override code, this will cause : /// - State.SourceRectangle to be reset to the Config.Size /// </summary> public override void LoadContent() { base.LoadContent(); this.UpdateDrawSizeByConfig(); Manager.ImageCompositor.CreateSpriteFont(Theme.FontName); // Calculate the width and height Config.Width = 1; // width should be really thin Config.Height = (int)Manager.ImageCompositor.ReadSizeString(Theme.FontName, "M").Y - 1; // height should be compared to the used font this.UpdateDrawSizeByConfig(); // create the texture this.CurrentTextureName = Manager.ImageCompositor.CreateRectangleTexture(this.Name, (int)Config.Width, (int)Config.Height, 0, GUIColor.MidnightBlue(), GUIColor.MidnightBlue()); // create a new color for the texture.. var count = (int)(Config.Width * Config.Height); var colorArray = new GUIColor[count]; for (var i = 0; i < count; i++) { colorArray[i] = GUIColor.MidnightBlue(); } var map = new ColorMap(colorArray, (int)this.Config.Width, (int)this.Config.Height); Manager.ImageCompositor.UpdateTexture(this.CurrentTextureName, map); }
/// <summary> /// Reverses this color-array in this instance. /// </summary> /// <returns>A reversed color-map.</returns> public ColorMap Reverse() { var reverseData = new GUIColor[this.Width * this.Height]; var r = reverseData.Length - 1; foreach (var guiColor in this.colors) { reverseData[r] = guiColor; r--; } var map = new ColorMap(reverseData, this.width, this.height); return map; }
/// <summary> /// Updates the texture color image with give color image. /// </summary> /// <param name="textureName">Name of the texture.</param> /// <param name="colorMap">The color array.</param> public override void UpdateTexture(string textureName, ColorMap colorMap) { #if DEBUG if (colorMap == null) { throw new ArgumentNullException("colorMap", "Given array can not be null , cause we use it to update the texture."); } #endif // first reverse the data var reverseData = colorMap.Reverse(); var texture = this.resourcesTexture.Read(textureName); if (texture == null) { System.Diagnostics.Debug.WriteLine("Could not update texture, could not find texture"); Debugger.Break(); return; } texture.SetData(reverseData.ToArray()); }
/// <summary>Resizes the color-map to the given target size.</summary> /// <param name="sourceArray">The source array.</param> /// <param name="targetWidth">Width of the target.</param> /// <param name="targetHeight">Height of the target.</param> /// <returns>A color-map with given target size.</returns> private static ColorMap ResizeImage(ColorMap sourceArray, int targetWidth, int targetHeight) { var targetArray = new ColorMap(targetWidth, targetHeight); // walk trough every pixel on the target // find out the area that the a pixel on target is covering on the source // average the source area into one pixel to be used on the target // // the way i am looking at it is that you have a target (emitting) rectangle standing on a table // and somewhere further in the distance you have a larger source (receiving) rectangle standing on a table // we are shooting beams trough the target (emitting) rectangle // those hit the source (receiving) rectangle at a given position // we use those hit-points to calculate what the color will be in the target rectangle for (int targetX = 0; targetX < targetWidth; targetX++) { for (int targetY = 0; targetY < targetHeight; targetY++) { // we walk trough every point in the target rectangle // find out, how big the source rectangle is var sourceAreaWidth = (float)sourceArray.Width / targetWidth; var sourceAreaHeight = (float)sourceArray.Height / targetHeight; // find the center of the source rectangle (receiver) on the table var percentageTargetX = (float)targetX / targetWidth; var percentageTargetY = (float)targetY / targetHeight; var sourceCentreX = Lerp(0, sourceArray.Width, percentageTargetX); var sourceCentreY = Lerp(0, sourceArray.Height, percentageTargetY); // get the array of pixels on the source rectangle , that we will use for averaging my location on the target rectangle var sourceLeft = Math.Floor(sourceCentreX - (sourceAreaWidth * 0.5f)); var sourceRight = Math.Ceiling(sourceCentreX + (sourceAreaWidth * 0.5f)); var sourceTop = Math.Floor(sourceCentreY - (sourceAreaHeight * 0.5f)); var sourceBottom = Math.Ceiling(sourceCentreY + (sourceAreaHeight * 0.5f)); // get all the colors in the source rectangle that are targeted var colorToAverage = new List <GUIColor>(); for (var parseX = (int)sourceLeft; parseX < sourceRight; parseX++) { for (var parseY = (int)sourceTop; parseY < sourceBottom; parseY++) { if (parseX < 0 || parseX > sourceArray.Width || parseY < 0 || parseY > sourceArray.Height) { continue; } var sourceColor = sourceArray.Get(parseX, parseY); colorToAverage.Add(sourceColor); } } // average those colors into the color that will be used in the target rectangle float r = 0; float g = 0; float b = 0; float a = 0; for (var index = 0; index < colorToAverage.Count; index++) { var clr = colorToAverage[index]; r = r + clr.R; g = g + clr.G; b = b + clr.B; a = a + clr.A; } r = r / colorToAverage.Count; g = g / colorToAverage.Count; b = b / colorToAverage.Count; a = a / colorToAverage.Count; targetArray.Set(targetX, targetY, new GUIColor((byte)r, (byte)g, (byte)b, (byte)a)); } } return(targetArray); }
/// <summary>Creates a rounded rectangle texture with given color and border.</summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="borderWidth">Width of the border.</param> /// <param name="cornerSize">Size of the corner.</param> /// <param name="fillColor">Color of the fill.</param> /// <param name="borderColor">Color of the border.</param> /// <returns>A color-map with a rounded rectangle inside.</returns> public static ColorMap CreateRoundedRectangleColorMap(int width, int height, int borderWidth, int cornerSize, GUIColor fillColor, GUIColor borderColor) { var colorMap = new ColorMap(width, height); if (cornerSize > width / 2) { cornerSize = width / 2; } if (cornerSize > height / 2) { cornerSize = height / 2; } // draw top horizontal lines for (var y = 0; y < cornerSize; y++) { if (y < borderWidth) { DrawHorizontalLineOnColorMap(ref colorMap, y, cornerSize, width - cornerSize, borderColor); } else { DrawHorizontalLineOnColorMap(ref colorMap, y, cornerSize, width - cornerSize, fillColor); } } // draw bottom horizontal lines for (var y = height - cornerSize; y < height; y++) { if (y < height - borderWidth) { DrawHorizontalLineOnColorMap(ref colorMap, y, cornerSize, width - cornerSize, fillColor); } else { DrawHorizontalLineOnColorMap(ref colorMap, y, cornerSize, width - cornerSize, borderColor); } } // draw left vertical lines for (var x = 0; x < cornerSize; x++) { if (x < borderWidth) { DrawVerticalLineOnColorMap(ref colorMap, x, cornerSize, height - cornerSize, borderColor); } else { DrawVerticalLineOnColorMap(ref colorMap, x, cornerSize, height - cornerSize, fillColor); } } // draw right vertical lines for (var x = width - cornerSize; x < width; x++) { if (x < width - borderWidth) { DrawVerticalLineOnColorMap(ref colorMap, x, cornerSize, height - cornerSize, fillColor); } else { DrawVerticalLineOnColorMap(ref colorMap, x, cornerSize, height - cornerSize, borderColor); } } // draw internal rectangle DrawRectangleOnColorMap(ref colorMap, cornerSize, cornerSize, width - cornerSize, height - cornerSize, fillColor); // create the bottom right corner var bottomRightCorner = CreateHighQualityRoundedCornerColorMap(cornerSize - borderWidth, cornerSize, fillColor, borderColor); PlaceSourceColorMapIntoTargetColorMap(bottomRightCorner, ref colorMap, width - cornerSize, height - cornerSize); // create the bottom left corner var bottomLeftCorner = FlipColorMapHorizontal(bottomRightCorner); PlaceSourceColorMapIntoTargetColorMap(bottomLeftCorner, ref colorMap, 0, height - cornerSize); // create the top right corner var topRightCorner = FlipColorMapHVertical(bottomRightCorner); PlaceSourceColorMapIntoTargetColorMap(topRightCorner, ref colorMap, width - cornerSize, 0); // create the bottom left corner var topLeftCorner = FlipColorMapHorizontal(topRightCorner); PlaceSourceColorMapIntoTargetColorMap(topLeftCorner, ref colorMap, 0, 0); return(colorMap); }
private static void SetPixel(ref ColorMap colorMap, int imageWidth, int imageHeight, float x, float y, GUIColor colorToUse) { // all is centered , so shift it back t bitmap coordinates // shift x to bitmap location var tempX = (imageWidth / 2) + (int)x; if (tempX >= imageWidth) { return; } if (tempX <= 0) { return; } // shift y to bitmap location var tempY = (imageHeight / 2) + (int)y; if (tempY >= imageHeight) { return; } if (tempY <= 0) { return; } // get the location into my array colorMap.Set(tempX, tempY, colorToUse); }
/// <summary>Resizes the color-map to the given target size.</summary> /// <param name="sourceArray">The source array.</param> /// <param name="targetWidth">Width of the target.</param> /// <param name="targetHeight">Height of the target.</param> /// <returns>A color-map with given target size.</returns> private static ColorMap ResizeImage(ColorMap sourceArray, int targetWidth, int targetHeight) { var targetArray = new ColorMap(targetWidth, targetHeight); // walk trough every pixel on the target // find out the area that the a pixel on target is covering on the source // average the source area into one pixel to be used on the target // // the way i am looking at it is that you have a target (emitting) rectangle standing on a table // and somewhere further in the distance you have a larger source (receiving) rectangle standing on a table // we are shooting beams trough the target (emitting) rectangle // those hit the source (receiving) rectangle at a given position // we use those hit-points to calculate what the color will be in the target rectangle for (int targetX = 0; targetX < targetWidth; targetX++) { for (int targetY = 0; targetY < targetHeight; targetY++) { // we walk trough every point in the target rectangle // find out, how big the source rectangle is var sourceAreaWidth = (float)sourceArray.Width / targetWidth; var sourceAreaHeight = (float)sourceArray.Height / targetHeight; // find the center of the source rectangle (receiver) on the table var percentageTargetX = (float)targetX / targetWidth; var percentageTargetY = (float)targetY / targetHeight; var sourceCentreX = Lerp(0, sourceArray.Width, percentageTargetX); var sourceCentreY = Lerp(0, sourceArray.Height, percentageTargetY); // get the array of pixels on the source rectangle , that we will use for averaging my location on the target rectangle var sourceLeft = Math.Floor(sourceCentreX - (sourceAreaWidth * 0.5f)); var sourceRight = Math.Ceiling(sourceCentreX + (sourceAreaWidth * 0.5f)); var sourceTop = Math.Floor(sourceCentreY - (sourceAreaHeight * 0.5f)); var sourceBottom = Math.Ceiling(sourceCentreY + (sourceAreaHeight * 0.5f)); // get all the colors in the source rectangle that are targeted var colorToAverage = new List<GUIColor>(); for (var parseX = (int)sourceLeft; parseX < sourceRight; parseX++) { for (var parseY = (int)sourceTop; parseY < sourceBottom; parseY++) { if (parseX < 0 || parseX > sourceArray.Width || parseY < 0 || parseY > sourceArray.Height) { continue; } var sourceColor = sourceArray.Get(parseX, parseY); colorToAverage.Add(sourceColor); } } // average those colors into the color that will be used in the target rectangle float r = 0; float g = 0; float b = 0; float a = 0; for (var index = 0; index < colorToAverage.Count; index++) { var clr = colorToAverage[index]; r = r + clr.R; g = g + clr.G; b = b + clr.B; a = a + clr.A; } r = r / colorToAverage.Count; g = g / colorToAverage.Count; b = b / colorToAverage.Count; a = a / colorToAverage.Count; targetArray.Set(targetX, targetY, new GUIColor((byte)r, (byte)g, (byte)b, (byte)a)); } } return targetArray; }
/// <summary> /// Draws this control in the style blue. /// </summary> /// <param name="map">The map to update.</param> private void DrawStyleBlue(ref ColorMap map) { var blue = this.rgba.B; for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { // red = x, green = y , blue is constant var red = Round((x / map.Width) * 255); var green = Round(255 - (255 * (double)y / (map.Height - 4))); map.Set(x, y, new GUIColor((byte)red, (byte)green, blue)); } } }
/// <summary>Creates a high quality rounded corner color-map.</summary> /// <param name="innerRadius">The inner radius.</param> /// <param name="outerRadius">The outer radius.</param> /// <param name="innerColor">Color of the inner.</param> /// <param name="outerColor">Color of the outer.</param> /// <returns>A color-map with a high quality rounded corner inside.</returns> private static ColorMap CreateHighQualityRoundedCornerColorMap(int innerRadius, int outerRadius, GUIColor innerColor, GUIColor outerColor) { int x; int y; const int GrowFactor = 4; int width = outerRadius * GrowFactor; int height = outerRadius * GrowFactor; // create a grown round corner var array = new ColorMap(width, height); for (x = 0; x < +width; x++) { for (y = 0; y < +height; y++) { // get the distance to x,y var r = Math.Sqrt((x * x) + (y * y)); if (r < innerRadius * GrowFactor) { array.Set(x, y, innerColor); } else if (r >= innerRadius * GrowFactor && r < outerRadius * GrowFactor) { array.Set(x, y, outerColor); } } } // and shrink it array = ResizeImage(array, outerRadius, outerRadius); return array; }
/// <summary> /// Draws this control in the style red. /// </summary> /// <param name="map">The map to update.</param> private void DrawStyleRed(ref ColorMap map) { var red = this.rgba.G; for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { // red = constant, green = x , blue = y var green = Round((x / map.Width) * 255); var blue = Round(255 - (255 * (double)y / (map.Height - 4))); map.Set(x, y, new GUIColor(red, (byte)green, (byte)blue)); } } }
/// <summary> /// Draws a horizontal line on the given color-map. /// </summary> /// <param name="colorMap">The color map to draw into.</param> /// <param name="y">The y position to draw the line.</param> /// <param name="startX">The start x to draw the line.</param> /// <param name="endX">The end x to draw the line.</param> /// <param name="colorToUse">The color to use.</param> private static void DrawHorizontalLineOnColorMap(ref ColorMap colorMap, int y, int startX, int endX, GUIColor colorToUse) { for (var x = startX; x < endX; x++) { colorMap.Set(x, y, colorToUse); } }
/// <summary> /// Draws this control in the style saturation. /// </summary> /// <param name="map">The map to update.</param> private void DrawStyleSaturation(ref ColorMap map) { var hslStart = new HSL(); var hslEnd = new HSL(); hslStart.S = this.hsl.S; hslEnd.S = this.hsl.S; hslStart.L = 1.0; hslEnd.L = 0.0; for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { // Calculate Hue at this line (Saturation and Luminance are constant) hslStart.H = (double)x / map.Width; hslEnd.H = hslStart.H; var rgbStart = AdobeColors.HSLToRGB(hslStart); var rgbEnd = AdobeColors.HSLToRGB(hslEnd); var lerpValue = y / map.Height; var rgbValue = AdobeColors.Lerp(rgbStart, rgbEnd, lerpValue); map.Set(x, y, rgbValue); } } }
/// <summary> /// Draws a color filled rectangle on given color-map. /// </summary> /// <param name="colorMap">The color map.</param> /// <param name="startX">The start x.</param> /// <param name="startY">The start y.</param> /// <param name="endX">The end x.</param> /// <param name="endY">The end y.</param> /// <param name="colorToUse">The color to use.</param> private static void DrawRectangleOnColorMap(ref ColorMap colorMap, int startX, int startY, int endX, int endY, GUIColor colorToUse) { for (var x = startX; x < endX; x++) { for (var y = startY; y < endY; y++) { colorMap.Set(x, y, colorToUse); } } }
/// <summary> /// Draws this control in the style hue. /// </summary> /// <param name="map">The map to update.</param> private void DrawStyleHue(ref ColorMap map) { var hslStart = new HSL(); var hslEnd = new HSL(); hslStart.H = this.hsl.H; hslEnd.H = this.hsl.H; hslStart.S = 0; hslEnd.S = 1; for (var y = 0; y < map.Height; y++) { hslStart.L = (float)y / map.Height; hslEnd.L = hslStart.L; var rgbStart = AdobeColors.HSLToRGB(hslStart); var rgbEnd = AdobeColors.HSLToRGB(hslEnd); for (var x = 0; x < map.Width; x++) { var lerpValue = 1 - (x / (float)map.Width); // System.Diagnostics.Debug.WriteLine(lerpValue); var rgbValue = AdobeColors.Lerp(rgbStart, rgbEnd, lerpValue); map.Set(x, y, rgbValue); } } }
/// <summary> /// Calls all the functions necessary to redraw the entire control. /// </summary> private void RedrawControl() { this.SetIndicatorPosition(this.sliderValue); var width = (int)Config.Width; var heigth = (int)Config.Height; if (Manager.ImageCompositor.Contains(this.CurrentTextureName) == false) { this.CurrentTextureName = Manager.ImageCompositor.CreateFlatTexture(this.Name + "-Background", width, heigth, GUIColor.Gainsboro()); } var colorMap = new ColorMap(width, heigth); switch (this.drawStyle) { case DrawStyle.Hue: DrawStyleHue(ref colorMap); break; case DrawStyle.Saturation: this.DrawStyleSaturation(ref colorMap); break; case DrawStyle.Brightness: this.DrawStyleLuminance(ref colorMap); break; case DrawStyle.Red: this.DrawStyleRed(ref colorMap); break; case DrawStyle.Green: this.DrawStyleGreen(ref colorMap); break; case DrawStyle.Blue: this.DrawStyleBlue(ref colorMap); break; } Manager.ImageCompositor.UpdateTexture(this.CurrentTextureName, colorMap); }
/// <summary>Creates the a texture with a rectangle with given color and border.</summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="borderWidth">Width of the border.</param> /// <param name="color">The color.</param> /// <param name="borderColor">Color of the border.</param> /// <returns>A color map with a rectangle image in the colorMap.</returns> public static ColorMap CreateRectangleColorMap(int width, int height, int borderWidth, GUIColor color, GUIColor borderColor) { var colorMap = new ColorMap(width, height); var left = borderWidth; var right = width - borderWidth; var top = borderWidth; var bottom = height - borderWidth; GUIColor colorToUse; for (var wY = 0; wY < height; wY++) { for (var wX = 0; wX < width; wX++) { colorToUse = color; if (wX < left || wX >= right) { colorToUse = borderColor; } if (wY < top || wY >= bottom) { colorToUse = borderColor; } colorMap.Set(wX, wY, colorToUse); } } return colorMap; }
/// <summary>Fills in the content of the control showing all values of Luminance (0 to 100%) for the given /// Hue and Saturation.</summary> /// <param name="map">The map to update.</param> private void DrawStyleLuminance(ref ColorMap map) { // Use the H and S values of the current color (m_hsl) var colorToConvert = new HSL { H = this.hsl.H, S = this.hsl.S }; // i represents the current line of pixels we want to draw horizontally for (var i = 0; i < map.Height; i++) { // L (Luminance) is based on the current vertical position colorToConvert.L = 1.0 - ((double)i / map.Height); // Get the Color for this line var rgb = AdobeColors.HSLToRGB(colorToConvert); for (var l = 0; l < map.Width; l++) { map.Set(l, i, rgb); } } }
/// <summary>Creates a rounded rectangle texture with given color and border.</summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="borderWidth">Width of the border.</param> /// <param name="cornerSize">Size of the corner.</param> /// <param name="fillColor">Color of the fill.</param> /// <param name="borderColor">Color of the border.</param> /// <returns>A color-map with a rounded rectangle inside.</returns> public static ColorMap CreateRoundedRectangleColorMap(int width, int height, int borderWidth, int cornerSize, GUIColor fillColor, GUIColor borderColor) { var colorMap = new ColorMap(width, height); if (cornerSize > width / 2) { cornerSize = width / 2; } if (cornerSize > height / 2) { cornerSize = height / 2; } // draw top horizontal lines for (var y = 0; y < cornerSize; y++) { if (y < borderWidth) { DrawHorizontalLineOnColorMap(ref colorMap, y, cornerSize, width - cornerSize, borderColor); } else { DrawHorizontalLineOnColorMap(ref colorMap, y, cornerSize, width - cornerSize, fillColor); } } // draw bottom horizontal lines for (var y = height - cornerSize; y < height; y++) { if (y < height - borderWidth) { DrawHorizontalLineOnColorMap(ref colorMap, y, cornerSize, width - cornerSize, fillColor); } else { DrawHorizontalLineOnColorMap(ref colorMap, y, cornerSize, width - cornerSize, borderColor); } } // draw left vertical lines for (var x = 0; x < cornerSize; x++) { if (x < borderWidth) { DrawVerticalLineOnColorMap(ref colorMap, x, cornerSize, height - cornerSize, borderColor); } else { DrawVerticalLineOnColorMap(ref colorMap, x, cornerSize, height - cornerSize, fillColor); } } // draw right vertical lines for (var x = width - cornerSize; x < width; x++) { if (x < width - borderWidth) { DrawVerticalLineOnColorMap(ref colorMap, x, cornerSize, height - cornerSize, fillColor); } else { DrawVerticalLineOnColorMap(ref colorMap, x, cornerSize, height - cornerSize, borderColor); } } // draw internal rectangle DrawRectangleOnColorMap(ref colorMap, cornerSize, cornerSize, width - cornerSize, height - cornerSize, fillColor); // create the bottom right corner var bottomRightCorner = CreateHighQualityRoundedCornerColorMap(cornerSize - borderWidth, cornerSize, fillColor, borderColor); PlaceSourceColorMapIntoTargetColorMap(bottomRightCorner, ref colorMap, width - cornerSize, height - cornerSize); // create the bottom left corner var bottomLeftCorner = FlipColorMapHorizontal(bottomRightCorner); PlaceSourceColorMapIntoTargetColorMap(bottomLeftCorner, ref colorMap, 0, height - cornerSize); // create the top right corner var topRightCorner = FlipColorMapHVertical(bottomRightCorner); PlaceSourceColorMapIntoTargetColorMap(topRightCorner, ref colorMap, width - cornerSize, 0); // create the bottom left corner var topLeftCorner = FlipColorMapHorizontal(topRightCorner); PlaceSourceColorMapIntoTargetColorMap(topLeftCorner, ref colorMap, 0, 0); return colorMap; }
/// <summary> /// Updates the texture. /// </summary> /// <param name="textureName">Name of the texture.</param> /// <param name="colorMap">The color map.</param> public abstract void UpdateTexture(string textureName, ColorMap colorMap);
private static void CreateEmptyRectangleColorMap(ref ColorMap colorMap, int imageWidth, int imageHeight, GUIColor colorToUse) { for (var wY = 0; wY < imageHeight; wY++) { for (var wX = 0; wX < imageWidth; wX++) { colorMap.Set(wX, wY, colorToUse); } } }