private void MaskChanged() { bool anyOn = mask[0] || mask[1] || mask[2]; SetEnabledControls(anyOn); ColorBgra top = ColorBgra.Black; top.Bgra |= mask[0] ? (uint)0xFF : 0; top.Bgra |= mask[1] ? (uint)0xFF00 : 0; top.Bgra |= mask[2] ? (uint)0xFF0000 : 0; gradientInput.MaxColor = top.ToColor(); gradientOutput.MaxColor = top.ToColor(); for (int i = 0; i < 3; ++i) { histogramInput.SetSelected(i, mask[i]); histogramOutput.SetSelected(i, mask[i]); } ignore++; InitDialogFromToken(); ignore--; }
private void ListBoxDrawSwatches(DrawItemEventArgs e, ColorBgra primary, ColorBgra secondary) { int swatchareasidelength = e.Bounds.Height * 2 / 3; Point swatchareapoint = new Point( e.Bounds.Right - (e.Bounds.Height + swatchareasidelength) / 2, e.Bounds.Top + (e.Bounds.Height - swatchareasidelength) / 2); Size swatchareasize = new Size(swatchareasidelength, swatchareasidelength); Rectangle swatcharearect = new Rectangle(swatchareapoint, swatchareasize); // save the rectangle of the selected item's swatch rect so if the user double clicks we open the colors dialog instead of effect dialog if (lbScript.SelectedIndex == e.Index) { lbScript_SelectedItemSwatchRect = swatcharearect; } Point swatch1point = swatchareapoint; Point swatch2point = swatchareapoint; swatch2point = Point.Add(swatch2point, new Size((int)(swatchareasidelength / 3f), (int)(swatchareasidelength / 3f))); Size swatchsize = new Size((int)(swatchareasidelength * (2 / 3f)), (int)(swatchareasidelength * (2 / 3f))); Rectangle swatch1rect = new Rectangle(swatch1point, swatchsize); Rectangle swatch2rect = new Rectangle(swatch2point, swatchsize); using (Brush secondarybrush = new SolidBrush(secondary.ToColor())) using (Brush primarybrush = new SolidBrush(primary.ToColor())) { e.Graphics.FillRectangle(new SolidBrush(secondary.ToColor()), swatch2rect); e.Graphics.DrawRectangle(SystemPens.ButtonShadow, swatch2rect.X, swatch2rect.Y, swatch2rect.Width, swatch2rect.Height); e.Graphics.FillRectangle(new SolidBrush(primary.ToColor()), swatch1rect); e.Graphics.DrawRectangle(SystemPens.ButtonShadow, swatch1rect.X, swatch1rect.Y, swatch1rect.Width, swatch1rect.Height); } }
public static int HslDifferenceSquared(ColorBgra bgra1, ColorBgra bgra2) { ColorHSL hsl1 = bgra1.ToColor(); ColorHSL hsl2 = bgra2.ToColor(); int diffSq = 0, tmp; tmp = hsl1.H - hsl2.H; diffSq += tmp * tmp; tmp = hsl1.S - hsl2.S; diffSq += tmp * tmp; tmp = hsl1.L - hsl2.L; diffSq += tmp * tmp; return(diffSq / 3); }
private int inOnPropertyValueChanged = 0; // this field is necessary to avoid having Effect`1.OnSetRenderInfo() called 3-4+ times at effect startup protected override void OnPropertyValueChanged() { ++this.inOnPropertyValueChanged; try { int value = Property.Value; int red = (value >> 16) & 0xff; int green = (value >> 8) & 0xff; int blue = value & 0xff; SetPropertyValueFromRgb(red, green, blue); ColorBgra color = ColorBgra.FromBgr((byte)blue, (byte)green, (byte)red); this.colorRectangle.RectangleColor = color.ToColor(); } finally { --this.inOnPropertyValueChanged; } }
protected void RenderShape() { // create the Pen we will use to draw with Pen outlinePen = null; Brush interiorBrush = null; PenInfo pi = AppEnvironment.PenInfo; BrushInfo bi = AppEnvironment.BrushInfo; ColorBgra primary = AppEnvironment.PrimaryColor; ColorBgra secondary = AppEnvironment.SecondaryColor; if (!ForceShapeDrawType && AppEnvironment.ShapeDrawType == ShapeDrawType.Interior) { Utility.Swap(ref primary, ref secondary); } // Initialize pens and brushes to the correct colors if ((mouseButton & MouseButtons.Left) == MouseButtons.Left) { outlinePen = pi.CreatePen(AppEnvironment.BrushInfo, primary.ToColor(), secondary.ToColor()); interiorBrush = bi.CreateBrush(secondary.ToColor(), primary.ToColor()); } else if ((mouseButton & MouseButtons.Right) == MouseButtons.Right) { outlinePen = pi.CreatePen(AppEnvironment.BrushInfo, secondary.ToColor(), primary.ToColor()); interiorBrush = bi.CreateBrush(primary.ToColor(), secondary.ToColor()); } if (!this.UseDashStyle) { outlinePen.DashStyle = DashStyle.Solid; } outlinePen.LineJoin = LineJoin.MiterClipped; outlinePen.MiterLimit = 2; // redraw the old saveSurface if (interiorSaveRegion != null) { RestoreRegion(interiorSaveRegion); interiorSaveRegion.Dispose(); interiorSaveRegion = null; } if (outlineSaveRegion != null) { RestoreRegion(outlineSaveRegion); outlineSaveRegion.Dispose(); outlineSaveRegion = null; } // anti-aliasing? Don't mind if I do if (AppEnvironment.AntiAliasing) { renderArgs.Graphics.SmoothingMode = SmoothingMode.AntiAlias; } else { renderArgs.Graphics.SmoothingMode = SmoothingMode.None; } // also set the pixel offset mode renderArgs.Graphics.PixelOffsetMode = GetPixelOffsetMode(); // figure out how we're going to draw ShapeDrawType drawType; if (ForceShapeDrawType) { drawType = ForcedShapeDrawType; } else { drawType = AppEnvironment.ShapeDrawType; } // get the region we want to save points = this.TrimShapePath(points); PointF[] pointsArray = points.ToArray(); PdnGraphicsPath shapePath = CreateShapePath(pointsArray); if (shapePath != null) { // create non-optimized interior region PdnRegion interiorRegion = new PdnRegion(shapePath); // create non-optimized outline region PdnRegion outlineRegion; using (PdnGraphicsPath outlinePath = (PdnGraphicsPath)shapePath.Clone()) { try { outlinePath.Widen(outlinePen); outlineRegion = new PdnRegion(outlinePath); } // Sometimes GDI+ gets cranky if we have a very small shape (e.g. all points // are coincident). catch (OutOfMemoryException) { outlineRegion = new PdnRegion(shapePath); } } // create optimized outlineRegion for purposes of rendering, if it is possible to do so // shapes will often provide an "optimized" region that circumvents the fact that // we'd otherwise get a region that encompasses the outline *and* the interior, thus // slowing rendering significantly in many cases. RectangleF[] optimizedOutlineRegion = GetOptimizedShapeOutlineRegion(pointsArray, shapePath); PdnRegion invalidOutlineRegion; if (optimizedOutlineRegion != null) { Utility.InflateRectanglesInPlace(optimizedOutlineRegion, (int)(outlinePen.Width + 2)); invalidOutlineRegion = Utility.RectanglesToRegion(optimizedOutlineRegion); } else { invalidOutlineRegion = Utility.SimplifyAndInflateRegion(outlineRegion, Utility.DefaultSimplificationFactor, (int)(outlinePen.Width + 2)); } // create optimized interior region PdnRegion invalidInteriorRegion = Utility.SimplifyAndInflateRegion(interiorRegion, Utility.DefaultSimplificationFactor, 3); PdnRegion invalidRegion = new PdnRegion(); invalidRegion.MakeEmpty(); // set up alpha blending renderArgs.Graphics.CompositingMode = AppEnvironment.GetCompositingMode(); SaveRegion(invalidOutlineRegion, invalidOutlineRegion.GetBoundsInt()); this.outlineSaveRegion = invalidOutlineRegion; if ((drawType & ShapeDrawType.Outline) != 0) { shapePath.Draw(renderArgs.Graphics, outlinePen); } invalidRegion.Union(invalidOutlineRegion); // draw shape if ((drawType & ShapeDrawType.Interior) != 0) { SaveRegion(invalidInteriorRegion, invalidInteriorRegion.GetBoundsInt()); this.interiorSaveRegion = invalidInteriorRegion; renderArgs.Graphics.FillPath(interiorBrush, shapePath); invalidRegion.Union(invalidInteriorRegion); } else { invalidInteriorRegion.Dispose(); invalidInteriorRegion = null; } bitmapLayer.Invalidate(invalidRegion); invalidRegion.Dispose(); invalidRegion = null; outlineRegion.Dispose(); outlineRegion = null; interiorRegion.Dispose(); interiorRegion = null; } Update(); if (shapePath != null) { shapePath.Dispose(); shapePath = null; } outlinePen.Dispose(); interiorBrush.Dispose(); }
public static float GetSaturation(this ColorBgra colorBgra) { Color colorArgb = colorBgra.ToColor(); return(colorArgb.GetSaturation()); }
public static float GetBrightness(this ColorBgra colorBgra) { Color colorArgb = colorBgra.ToColor(); return(colorArgb.GetBrightness()); }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.CompositingMode = CompositingMode.SourceOver; int scaledSwatchSize = UI.ScaleWidth(this.unscaledSwatchSize); int swatchColumns = this.ClientSize.Width / scaledSwatchSize; Point mousePt = Control.MousePosition; mousePt = PointToClient(mousePt); int activeIndex = MouseXYToColorIndex(mousePt.X, mousePt.Y); for (int i = 0; i < this.colors.Count; ++i) { ColorBgra c = this.colors[i]; int swatchX = i % swatchColumns; int swatchY = i / swatchColumns; Rectangle swatchRect = new Rectangle( swatchX * scaledSwatchSize, swatchY * scaledSwatchSize, scaledSwatchSize, scaledSwatchSize); PushButtonState state; if (this.mouseDown) { if (i == this.mouseDownIndex) { state = PushButtonState.Pressed; } else { state = PushButtonState.Normal; } } else if (i == activeIndex) { state = PushButtonState.Hot; } else { state = PushButtonState.Normal; } bool drawOutline; switch (state) { case PushButtonState.Hot: drawOutline = true; break; case PushButtonState.Pressed: drawOutline = false; break; case PushButtonState.Default: case PushButtonState.Disabled: case PushButtonState.Normal: drawOutline = false; break; default: throw new InvalidEnumArgumentException(); } Utility.DrawColorRectangle(e.Graphics, swatchRect, c.ToColor(), drawOutline); } if (this.blinkHighlight) { int period = (Math.Abs(Environment.TickCount) / blinkInterval) % 2; Color color; switch (period) { case 0: color = SystemColors.Window; break; case 1: color = SystemColors.Highlight; break; default: throw new InvalidOperationException(); } using (Pen pen = new Pen(color)) { e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width - 1, Height - 1)); } } base.OnPaint(e); }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.CompositingMode = CompositingMode.SourceOver; int width = UIUtil.ScaleWidth(this.unscaledSwatchSize); int num2 = base.ClientSize.Width / width; Point mousePosition = Control.MousePosition; mousePosition = base.PointToClient(mousePosition); int num3 = this.MouseXYToColorIndex(mousePosition.X, mousePosition.Y); for (int i = 0; i < this.colors.Count; i++) { PushButtonState pressed; bool flag; ColorBgra bgra = this.colors[i]; int num5 = i % num2; int num6 = i / num2; Rectangle rect = new Rectangle(num5 * width, num6 * width, width, width); if (this.mouseDown) { if (i == this.mouseDownIndex) { pressed = PushButtonState.Pressed; } else { pressed = PushButtonState.Normal; } } else if (i == num3) { pressed = PushButtonState.Hot; } else { pressed = PushButtonState.Normal; } switch (pressed) { case PushButtonState.Normal: case PushButtonState.Disabled: case PushButtonState.Default: flag = false; break; case PushButtonState.Hot: flag = true; break; case PushButtonState.Pressed: flag = false; break; default: throw ExceptionUtil.InvalidEnumArgumentException <PushButtonState>(pressed, "state"); } ColorRectangle.Draw(e.Graphics, rect, bgra.ToColor(), base.Enabled, flag); } if (this.blinkHighlight) { Color window; switch (((Math.Abs(Environment.TickCount) / 500) % 2)) { case 0: window = SystemColors.Window; break; case 1: window = SystemColors.Highlight; break; default: throw new InvalidOperationException(); } using (Pen pen = new Pen(window)) { e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, base.Width - 1, base.Height - 1)); } } base.OnPaint(e); }