/// <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 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; }