public void ProcessUpdate(ElementIntentStates elementStates) { renderTimer.Reset(); renderTimer.Start(); if (!_paused) { //FastPixel fp = new FastPixel(_background.Width, _background.Height); FastPixel fp = new FastPixel(new Bitmap(_alphaBackground)); Bitmap floodBG = null; if (UseFloods) { floodBG = PreviewTools.Copy32BPPBitmapSafe(_blankAlphaBackground); //floodBG = new Bitmap(_blankAlphaBackground); //floodBG = new Bitmap(_blankAlphaBackground.Width, _blankAlphaBackground.Height); //Graphics g = Graphics.FromImage(floodBG); //g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; //SolidBrush brush = new SolidBrush(Color.FromArgb(50, 255, 0, 0)); //g.FillEllipse(brush, new Rectangle(200, 200, 300, 300)); //g.DrawImage(_blankAlphaBackground, 0, 0); //g.FillRectangle(_backgroundBrush, new Rectangle(0, 0, _blankAlphaBackground.Width, _blankAlphaBackground.Height)); } fp.Lock(); foreach (var channelIntentState in elementStates) { var elementId = channelIntentState.Key; Element element = VixenSystem.Elements.GetElement(elementId); if (element == null) { continue; } ElementNode node = VixenSystem.Elements.GetElementNodeForElement(element); if (node == null) { continue; } //foreach (IIntentState intentState in channelIntentState.Value) //{ // intentState.Dispatch(DisplayItems[0]); //} foreach (IIntentState <LightingValue> intentState in channelIntentState.Value) { if (_background != null) { List <PreviewPixel> pixels; if (NodeToPixel.TryGetValue(node, out pixels)) { foreach (PreviewPixel pixel in pixels) { //Color.FromArgb((int)(Intensity * byte.MaxValue), Color.R, Color.G, Color.B); //LightingValue v = intentState.GetValue(); //Color c = v.GetOpaqueIntensityAffectedColor(); //Color c = v.GetAlphaChannelIntensityAffectedColor(); Color c = intentState.GetValue().GetAlphaChannelIntensityAffectedColor(); //Color c = Color.White; pixel.Draw(fp, c); } } } } } //if (UseFloods) //{ // foreach (DisplayItem displayItem in DisplayItems) // { // if (displayItem.Shape.StringType == PreviewBaseShape.StringTypes.Flood) // { // Color c = displayItem.Shape._pixels[0].PixelColor; // int alpha = c.A; // //int maxAlpha = 255 - BackgroundAlpha; // //if (maxAlpha < 255) // //{ // //} // displayItem.Shape._pixels[0].PixelColor = Color.FromArgb(alpha, c.R, c.G, c.B); // displayItem.Shape.Draw(floodBG, false, null); // displayItem.Shape._pixels[0].PixelColor = Color.FromArgb(255 - BackgroundAlpha, 0, 0, 0); // } // } //} fp.Unlock(true); // First, draw our background image opaque bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; //if (UseFloods) //{ // bufferedGraphics.Graphics.DrawImage(_background, 0, 0, _background.Width, _background.Height); //} //else //{ // bufferedGraphics.Graphics.DrawImage(_alphaBackground, 0, 0, _alphaBackground.Width, _alphaBackground.Height); //} // Now, draw our "pixel" image using alpha blending ///bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; if (UseFloods) { bufferedGraphics.Graphics.DrawImage(floodBG, 0, 0, _blankAlphaBackground.Width, _blankAlphaBackground.Height); } bufferedGraphics.Graphics.DrawImage(fp.Bitmap, 0, 0, fp.Width, fp.Height); if (!this.Disposing && bufferedGraphics != null) { bufferedGraphics.Render(Graphics.FromHwnd(this.Handle)); } fp = null; } renderTimer.Stop(); lastRenderUpdateTime = renderTimer.ElapsedMilliseconds; }
/// <summary> /// This is used in edit mode only!! /// Need to make it go away so we only have one render engine /// </summary> public void RenderInForeground() { renderTimer.Reset(); renderTimer.Start(); if (_background != null) { //FastPixel fp = new FastPixel(_background.Width, _background.Height); FastPixel fp = new FastPixel(new Bitmap(_alphaBackground)); Bitmap floodBG = null; if (UseFloods) { floodBG = PreviewTools.Copy32BPPBitmapSafe(_blankAlphaBackground); //floodBG = new Bitmap(_blankAlphaBackground); //floodBG = new Bitmap(_blankAlphaBackground.Width, _blankAlphaBackground.Height); //Graphics g = Graphics.FromImage(floodBG); //g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; //SolidBrush brush = new SolidBrush(Color.FromArgb(50, 255, 0, 0)); //g.FillEllipse(brush, new Rectangle(200, 200, 300, 300)); //g.DrawImage(_blankAlphaBackground, 0, 0); //g.FillRectangle(_backgroundBrush, new Rectangle(0, 0, _blankAlphaBackground.Width, _blankAlphaBackground.Height)); } fp.Lock(); foreach (DisplayItem displayItem in DisplayItems) { //if (UseFloods && displayItem.Shape.StringType == PreviewBaseShape.StringTypes.Flood) //{ // displayItem.Shape.Draw(floodBG, _editMode, null); //} //else //{ if (_editMode) { displayItem.Draw(fp, true, HighlightedElements, SelectedDisplayItems.Contains(displayItem)); } else { displayItem.Draw(fp, false, null, false); } //} } fp.Unlock(true); // Finally, are we drawing a banded rectangle? if (_mouseCaptured && _selectedDisplayItem == null) { Graphics g = Graphics.FromImage(fp.Bitmap); g.DrawRectangle(Pens.White, _bandRect); } //lock (renderLock) //{ // First, draw our background image opaque bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; //bufferedGraphics.Graphics.DrawImage(_background, 0, 0, _background.Width, _background.Height); if (UseFloods) { bufferedGraphics.Graphics.DrawImage(_background, 0, 0, _background.Width, _background.Height); } else { //bufferedGraphics.Graphics.DrawImage(_alphaBackground, 0, 0, _alphaBackground.Width, _alphaBackground.Height); } //bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; if (UseFloods) { bufferedGraphics.Graphics.DrawImage(floodBG, 0, 0, _blankAlphaBackground.Width, _blankAlphaBackground.Height); } // Now, draw our "pixel" image using alpha blending bufferedGraphics.Graphics.DrawImage(fp.Bitmap, 0, 0, fp.Width, fp.Height); //} } bufferedGraphics.Render(Graphics.FromHwnd(this.Handle)); renderTimer.Stop(); lastRenderUpdateTime = renderTimer.ElapsedMilliseconds; }
public void DrawCircle(Rectangle rect, Color color) { //lock (Shapes.PreviewTools.renderLock) //{ if (rect.Width > 0 && rect.Height > 0) { // Default drawing tools don't draw circles that are either 1 or 2 pixels, // so we do it manually if (rect.Width == 1) { SetPixel(rect.Left, rect.Top, color); } else if (rect.Width == 2) { // Row 1 SetPixel(rect.Left, rect.Top, color); // Row 2 SetPixel(rect.Left, rect.Top + 1, color); } else if (rect.Width == 3) { // Row 1 SetPixel(rect.Left, rect.Top, color); // Row 1 SetPixel(rect.Left + 1, rect.Top, color); // Row 2 SetPixel(rect.Left, rect.Top + 1, color); } //else if (rect.Width == 4) //{ // // Row 1 // SetPixel(rect.Left, rect.Top, color); // // Row 1 // SetPixel(rect.Left + 1, rect.Top, color); // // Row 2 // SetPixel(rect.Left, rect.Top + 1, color); // // Row 2 // SetPixel(rect.Left + 1, rect.Top + 1, color); //} //else if (rect.Width == 5) //{ // // Row 1 // SetPixel(rect.Left, rect.Top, color); // // Row 1 // SetPixel(rect.Left + 1, rect.Top, color); // // Row 1 // SetPixel(rect.Left + 2, rect.Top, color); // // Row 2 // SetPixel(rect.Left, rect.Top + 1, color); // // Row 2 // SetPixel(rect.Left + 1, rect.Top + 1, color); //} //else if (rect.Width == 6) //{ // // Row 1 // SetPixel(rect.Left, rect.Top, color); // // Row 1 // SetPixel(rect.Left + 1, rect.Top, color); // // Row 1 // SetPixel(rect.Left + 2, rect.Top, color); // // Row 2 // SetPixel(rect.Left, rect.Top + 1, color); // // Row 2 // SetPixel(rect.Left + 1, rect.Top + 1, color); // // Row 3 // SetPixel(rect.Left + 2, rect.Top + 1, color); //} else { Bitmap b; FastPixel fp; if (!FastPixel.circleCache.TryGetValue(rect.Width, out fp)) { b = new Bitmap(rect.Width, rect.Height); Graphics g = Graphics.FromImage(b); //g.Clear(Color.Transparent); //SolidBrush brush = new SolidBrush(Color.White); g.FillEllipse(Brushes.White, new Rectangle(0, 0, rect.Width - 1, rect.Height - 1)); fp = new FastPixel(b); FastPixel.circleCache.Add(rect.Width, fp); } fp.Lock(); for (int x = 0; x < rect.Width; x++) { for (int y = 0; y < rect.Height; y++) { Color newColor = fp.GetPixel(x, y); if (newColor.A != 0) SetPixel(rect.Left + x, rect.Top + y, color); } } fp.Unlock(false); } } //} }