/// <summary> /// Redraws only the content over the marker /// </summary> private void ClearMarker() { Graphics g = CreateGraphics(); // Determine the area that needs to be redrawn int start_x, start_y, end_x, end_y; int red = 0; int green = 0; int blue = 0; var hsl_start = new ColorManager.HSL(); var hsl_end = new ColorManager.HSL(); // Find the markers corners start_x = m_iMarker_X - 5; start_y = m_iMarker_Y - 5; end_x = m_iMarker_X + 5; end_y = m_iMarker_Y + 5; // Adjust the area if part of it hangs outside the content area if (start_x < 0) { start_x = 0; } if (start_y < 0) { start_y = 0; } if (end_x > Width - 4) { end_x = Width - 4; } if (end_y > Height - 4) { end_y = Height - 4; } // Redraw the content based on the current draw style: // The code get's a little messy from here switch (m_eDrawStyle) { // S=0,S=1,S=2,S=3.....S=100 // L=100 // L=99 // L=98 Drawstyle // L=97 Hue // ... // L=0 case eDrawStyle.Hue: hsl_start.H = m_hsl.H; hsl_end.H = m_hsl.H; // Hue is constant hsl_start.S = (double)start_x / (Width - 4); // Because we're drawing horizontal lines, s will not change hsl_end.S = (double)end_x / (Width - 4); // from line to line for (int i = start_y; i <= end_y; i++) // For each horizontal line: { hsl_start.L = 1.0 - (double)i / (Height - 4); // Brightness (L) WILL change for each horizontal hsl_end.L = hsl_start.L; // line drawn var br = new LinearGradientBrush(new Rectangle(start_x + 1, i + 2, end_x - start_x + 1, 1), ColorManager.HSL_to_RGB(hsl_start), ColorManager.HSL_to_RGB(hsl_end), 0, false); g.FillRectangle(br, new Rectangle(start_x + 2, i + 2, end_x - start_x + 1, 1)); } break; // H=0,H=1,H=2,H=3.....H=360 // L=100 // L=99 // L=98 Drawstyle // L=97 Saturation // ... // L=0 case eDrawStyle.Saturation: hsl_start.S = m_hsl.S; hsl_end.S = m_hsl.S; // Saturation is constant hsl_start.L = 1.0 - (double)start_y / (Height - 4); // Because we're drawing vertical lines, L will hsl_end.L = 1.0 - (double)end_y / (Height - 4); // not change from line to line for (int i = start_x; i <= end_x; i++) // For each vertical line: { hsl_start.H = (double)i / (Width - 4); // Hue (H) WILL change for each vertical hsl_end.H = hsl_start.H; // line drawn var br = new LinearGradientBrush(new Rectangle(i + 2, start_y + 1, 1, end_y - start_y + 2), ColorManager.HSL_to_RGB(hsl_start), ColorManager.HSL_to_RGB(hsl_end), 90, false); g.FillRectangle(br, new Rectangle(i + 2, start_y + 2, 1, end_y - start_y + 1)); } break; // H=0,H=1,H=2,H=3.....H=360 // S=100 // S=99 // S=98 Drawstyle // S=97 Brightness // ... // S=0 case eDrawStyle.Brightness: hsl_start.L = m_hsl.L; hsl_end.L = m_hsl.L; // Luminance is constant hsl_start.S = 1.0 - (double)start_y / (Height - 4); // Because we're drawing vertical lines, S will hsl_end.S = 1.0 - (double)end_y / (Height - 4); // not change from line to line for (int i = start_x; i <= end_x; i++) // For each vertical line: { hsl_start.H = (double)i / (Width - 4); // Hue (H) WILL change for each vertical hsl_end.H = hsl_start.H; // line drawn var br = new LinearGradientBrush(new Rectangle(i + 2, start_y + 1, 1, end_y - start_y + 2), ColorManager.HSL_to_RGB(hsl_start), ColorManager.HSL_to_RGB(hsl_end), 90, false); g.FillRectangle(br, new Rectangle(i + 2, start_y + 2, 1, end_y - start_y + 1)); } break; // B=0,B=1,B=2,B=3.....B=100 // G=100 // G=99 // G=98 Drawstyle // G=97 Red // ... // G=0 case eDrawStyle.Red: red = m_rgb.R; // Red is constant int start_b = Round(255 * (double)start_x / (Width - 4)); // Because we're drawing horizontal lines, B int end_b = Round(255 * (double)end_x / (Width - 4)); // will not change from line to line for (int i = start_y; i <= end_y; i++) // For each horizontal line: { green = Round(255 - (255 * (double)i / (Height - 4))); // green WILL change for each horizontal line drawn var br = new LinearGradientBrush(new Rectangle(start_x + 1, i + 2, end_x - start_x + 1, 1), Color.FromArgb(red, green, start_b), Color.FromArgb(red, green, end_b), 0, false); g.FillRectangle(br, new Rectangle(start_x + 2, i + 2, end_x - start_x + 1, 1)); } break; // B=0,B=1,B=2,B=3.....B=100 // R=100 // R=99 // R=98 Drawstyle // R=97 Green // ... // R=0 case eDrawStyle.Green: green = m_rgb.G; ; // Green is constant int start_b2 = Round(255 * (double)start_x / (Width - 4)); // Because we're drawing horizontal lines, B int end_b2 = Round(255 * (double)end_x / (Width - 4)); // will not change from line to line for (int i = start_y; i <= end_y; i++) // For each horizontal line: { red = Round(255 - (255 * (double)i / (Height - 4))); // red WILL change for each horizontal line drawn var br = new LinearGradientBrush(new Rectangle(start_x + 1, i + 2, end_x - start_x + 1, 1), Color.FromArgb(red, green, start_b2), Color.FromArgb(red, green, end_b2), 0, false); g.FillRectangle(br, new Rectangle(start_x + 2, i + 2, end_x - start_x + 1, 1)); } break; // R=0,R=1,R=2,R=3.....R=100 // G=100 // G=99 // G=98 Drawstyle // G=97 Blue // ... // G=0 case eDrawStyle.Blue: blue = m_rgb.B; ; // Blue is constant int start_r = Round(255 * (double)start_x / (Width - 4)); // Because we're drawing horizontal lines, R int end_r = Round(255 * (double)end_x / (Width - 4)); // will not change from line to line for (int i = start_y; i <= end_y; i++) // For each horizontal line: { green = Round(255 - (255 * (double)i / (Height - 4))); // green WILL change for each horizontal line drawn var br = new LinearGradientBrush(new Rectangle(start_x + 1, i + 2, end_x - start_x + 1, 1), Color.FromArgb(start_r, green, blue), Color.FromArgb(end_r, green, blue), 0, false); g.FillRectangle(br, new Rectangle(start_x + 2, i + 2, end_x - start_x + 1, 1)); } break; } }