// NOTE: Eventually this code should be converted to use SlideRenderer instead of each SheetRenderer. There were some issues with doing // this initially so for the time being we will keep it like this. public static Bitmap DrawSlide(TableOfContentsModel.Entry currentEntry, BackgroundTemplate template, System.Drawing.Color background, SheetDisposition dispositions, int width, int height, float scale ) { // Save the old state System.Drawing.Drawing2D.GraphicsState oldState; using (Synchronizer.Lock(currentEntry.Slide.SyncRoot)) { Rectangle rect; int boundsWidth = currentEntry.Slide.Bounds.Width; int boundsHeight = currentEntry.Slide.Bounds.Height; int exportWidth = width; int exportHeight = height; if (width > 0 && height > 0) { // Do Nothing } else if (width > 0) { exportHeight = (int)Math.Round( ( (float)width / (float)boundsWidth ) * (float)boundsHeight ); } else if (height > 0) { exportWidth = (int)Math.Round( ( (float)height / (float)boundsHeight ) * (float)boundsWidth ); } else { exportWidth = boundsWidth; exportHeight = boundsHeight; } // Scale the size exportWidth = (int)Math.Round( exportWidth * scale ); exportHeight = (int)Math.Round( exportHeight * scale ); rect = new Rectangle(0, 0, exportWidth, exportHeight); //Note: Uses DibGraphicsBuffer from TPC SDK to do antialiasing //See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tbconprintingink.asp /// create the bitmap we're exporting to Bitmap toExport = new Bitmap(rect.Width, rect.Height); /// create what we will be drawing on to the export Graphics toSave = Graphics.FromImage(toExport); /// draw the slide data on a temporary graphics object in a temporary form System.Windows.Forms.Form tempForm = new System.Windows.Forms.Form(); Graphics screenGraphics = tempForm.CreateGraphics(); DibGraphicsBuffer dib = new DibGraphicsBuffer(); Graphics tempGraphics = dib.RequestBuffer(screenGraphics, rect.Width, rect.Height); //Add the background color //First see if there is a Slide BG, if not, try the Deck. Otherwise, use transparent. tempGraphics.Clear(background); //Add the background template if (template != null) { using (BackgroundTemplateRenderer bkgRender = new BackgroundTemplateRenderer(template)) { bkgRender.DrawAll(tempGraphics, rect); } } //Get the Slide content and draw it oldState = tempGraphics.Save(); Model.Presentation.SlideModel.SheetCollection sheets = currentEntry.Slide.ContentSheets; for (int i = 0; i < sheets.Count; i++) { Model.Viewer.SlideDisplayModel display = new Model.Viewer.SlideDisplayModel(tempGraphics, null); Rectangle slide = rect; float zoom = 1f; if (currentEntry.Slide != null) { slide = currentEntry.Slide.Bounds; zoom = currentEntry.Slide.Zoom; } System.Drawing.Drawing2D.Matrix pixel, ink; display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink); using (Synchronizer.Lock(display.SyncRoot)) { display.SheetDisposition = dispositions; display.Bounds = slide; display.PixelTransform = pixel; display.InkTransform = ink; } Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]); if ((r.Sheet.Disposition & dispositions) != 0) r.Paint(new System.Windows.Forms.PaintEventArgs(tempGraphics, rect)); r.Dispose(); } //Restore the Old State tempGraphics.Restore(oldState); oldState = tempGraphics.Save(); //Get the Annotation content and draw it sheets = currentEntry.Slide.AnnotationSheets; for (int i = 0; i < sheets.Count; i++) { Model.Viewer.SlideDisplayModel display = new Model.Viewer.SlideDisplayModel(tempGraphics, null); Rectangle slide = rect; float zoom = 1f; if (currentEntry.Slide != null) { slide = currentEntry.Slide.Bounds; zoom = currentEntry.Slide.Zoom; } System.Drawing.Drawing2D.Matrix pixel, ink; display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink); using (Synchronizer.Lock(display.SyncRoot)) { display.SheetDisposition = dispositions; display.Bounds = slide; display.PixelTransform = pixel; display.InkTransform = ink; } Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]); if ((r.Sheet.Disposition & dispositions) != 0) r.Paint(new System.Windows.Forms.PaintEventArgs(tempGraphics, rect)); r.Dispose(); } //Restore the Old State tempGraphics.Restore(oldState); //Export the image //Merge the graphics dib.PaintBuffer(toSave, 0, 0); //Dispose all the graphics toSave.Dispose(); screenGraphics.Dispose(); tempGraphics.Dispose(); return toExport; } }
protected override void OnPaintBackground(PaintEventArgs args) { Graphics g = args.Graphics; RoleModel role = null; LinkedDeckTraversalModel.NavigationSelector studentNavigationType = LinkedDeckTraversalModel.NavigationSelector.Full; if (PresenterModel.TheInstance != null) { using (Synchronizer.Lock(PresenterModel.TheInstance.Participant.SyncRoot)) { role = PresenterModel.TheInstance.Participant.Role; } using (Synchronizer.Lock(PresenterModel.TheInstance.ViewerState.SyncRoot)) { studentNavigationType = PresenterModel.TheInstance.ViewerState.StudentNavigationType; } } using(Synchronizer.Lock(this.SlideDisplay.SyncRoot)) { Rectangle slide = this.SlideDisplay.Bounds; // Draw the 3D border just outside the slide bounds. Rectangle border = slide; border.Inflate(BORDER_WIDTH, BORDER_WIDTH); ControlPaint.DrawBorder3D(g, border, Border3DStyle.Sunken, Border3DSide.All); if(this.Slide == null) { using(Font font = new Font(this.Font.FontFamily, this.Font.Size * 6)) { using(Brush brush = new SolidBrush(Color.FromArgb(this.BackColor.A / 6, SystemColors.WindowText))) { SizeF size = g.MeasureString(NO_SLIDE_MESSAGE, font, slide.Width); PointF location = new PointF( Math.Max(0, slide.X + ((slide.Width - size.Width) / 2)), Math.Max(0, slide.Y + ((slide.Height - size.Height) / 2))); g.DrawString(NO_SLIDE_MESSAGE, font, brush, new RectangleF(location, size)); } } } else { using(Synchronizer.Lock(this.Slide.SyncRoot)) { // Paint the unvisited slides. if ( role!=null && role is StudentModel && (!this.Slide.Visited) && studentNavigationType == LinkedDeckTraversalModel.NavigationSelector.Visited) using(Font font = new Font(this.Font.FontFamily, this.Font.Size * 6)) { using(Brush brush = new SolidBrush(Color.FromArgb(this.BackColor.A / 6, SystemColors.WindowText))) { SizeF size = g.MeasureString(UNVISITED_SLIDE_MESSAGE, font, slide.Width); PointF location = new PointF( Math.Max(0, slide.X + ((slide.Width - size.Width) / 2)), Math.Max(0, slide.Y + ((slide.Height - size.Height) / 2))); g.DrawString(UNVISITED_SLIDE_MESSAGE, font, brush, new RectangleF(location, size)); } } // Paint the slide's background to be something prettier than the default control color. //Retrieve the slide's background color else { Color c; using(Synchronizer.Lock(this.Slide.SyncRoot)) { c = this.Slide.BackgroundColor; } if(c.IsEmpty) { //Slide color undefined, use deck's default color c = this.DefaultDeckBGColor; } SolidBrush sb = new SolidBrush(c); //Some really cool brushes that we might consider offering... //HatchBrush hb = new HatchBrush(HatchStyle.DiagonalCross, Color.Gold, Color.Purple); //LinearGradientBrush lgb = new LinearGradientBrush(slide, Color.Purple, Color.Gold, 0f, true); g.FillRectangle(sb, slide); //g.FillRectangle(SystemBrushes.Window, slide); BackgroundTemplate backgroundTemplate; float slidezoom = 1f; using (Synchronizer.Lock(this.Slide.SyncRoot)) { backgroundTemplate = this.Slide.BackgroundTemplate; slidezoom = this.Slide.Zoom; } if (backgroundTemplate == null) { backgroundTemplate = this.DefaultDeckBGTemplate; } if (backgroundTemplate != null) { using (BackgroundTemplateRenderer render = new BackgroundTemplateRenderer(backgroundTemplate)) { render.Zoom = slidezoom; render.DrawAll(g, slide); } } } } // Paint the default background in the region outside the slide. Region inverse = g.Clip; inverse.Exclude(border); g.Clip = inverse; base.OnPaintBackground(args); } } }
/// <summary> /// Override the OnPaint to render the template /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (BackgroundTemplateRenderer render = new BackgroundTemplateRenderer(this.m_Form.m_Template)) { render.DrawAll(e.Graphics, this.ClientRectangle); } }
// TODO: Correctly Draw the Slide Annotation private void DrawSlide( DeckTraversalModel traversal, int index, System.Drawing.Rectangle rect, System.Drawing.Graphics buffer ) { // Save the old state System.Drawing.Drawing2D.GraphicsState oldState; using( Synchronizer.Lock( traversal.SyncRoot ) ) { using( Synchronizer.Lock( traversal.Deck.SyncRoot ) ) { using( Synchronizer.Lock( traversal.Deck.TableOfContents.SyncRoot ) ) { TableOfContentsModel.Entry entry = traversal.Deck.TableOfContents.Entries[index]; using( Synchronizer.Lock( entry.Slide.SyncRoot ) ) { //Draw the background color //First see if there is a Slide BG, if not, try the Deck. Otherwise, use transparent. if( entry.Slide.BackgroundColor != Color.Empty ) { buffer.FillRectangle( new System.Drawing.SolidBrush( entry.Slide.BackgroundColor ), rect ); } else if( traversal.Deck.DeckBackgroundColor != Color.Empty ) { buffer.FillRectangle( new System.Drawing.SolidBrush( traversal.Deck.DeckBackgroundColor ), rect ); } else { buffer.FillRectangle( new System.Drawing.SolidBrush( Color.Transparent ), rect ); } //Draw the background Template if (entry.Slide.BackgroundTemplate != null) { using (BackgroundTemplateRenderer render = new BackgroundTemplateRenderer(entry.Slide.BackgroundTemplate)) { render.Zoom = entry.Slide.Zoom; render.DrawAll(buffer, rect); } } //Get the Slide content and draw it oldState = buffer.Save(); Model.Presentation.SlideModel.SheetCollection sheets = entry.Slide.ContentSheets; for( int i = 0; i < sheets.Count; i++ ) { SlideDisplayModel display = new SlideDisplayModel( buffer, null ); Rectangle slide = rect; float zoom = 1f; if( entry.Slide != null ) { slide = entry.Slide.Bounds; zoom = entry.Slide.Zoom; } System.Drawing.Drawing2D.Matrix pixel, ink; display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink); using(Synchronizer.Lock(display.SyncRoot)) { display.Bounds = slide; display.PixelTransform = pixel; display.InkTransform = ink; } Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet( display, sheets[i] ); r.Paint( new System.Windows.Forms.PaintEventArgs(buffer, rect) ); r.Dispose(); } //Restore the Old State buffer.Restore( oldState ); oldState = buffer.Save(); //Get the Annotation content and draw it sheets = entry.Slide.AnnotationSheets; for( int i = 0; i < sheets.Count; i++ ) { SlideDisplayModel display = new SlideDisplayModel( buffer, null ); Rectangle slide = rect; float zoom = 1f; if( entry.Slide != null ) { slide = entry.Slide.Bounds; zoom = entry.Slide.Zoom; } System.Drawing.Drawing2D.Matrix pixel, ink; display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink); using(Synchronizer.Lock(display.SyncRoot)) { display.Bounds = slide; display.PixelTransform = pixel; display.InkTransform = ink; } Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet( display, sheets[i] ); if( r is Viewer.Slides.InkSheetRenderer ) { ((Viewer.Slides.InkSheetRenderer)r).Paint( buffer, rect ); } else r.Paint( new System.Windows.Forms.PaintEventArgs(buffer, rect) ); r.Dispose(); } //Restore the Old State buffer.Restore( oldState ); /* Microsoft.Ink.Renderer renderer = new Microsoft.Ink.Renderer(); for( int i = 0; i < sheets.Count; i++ ) { SheetModel sm = sheets[i]; if( sm is InkSheetModel ) { InkSheetModel ism = sm as InkSheetModel; using( Synchronizer.Lock( ism.SyncRoot ) ) { foreach( Microsoft.Ink.Stroke stroke in ism.Ink.Strokes ) { renderer.Draw( buffer, stroke ); } } } else if( sm is TextSheetModel ) { TextSheetModel tsm = sm as TextSheetModel; using( Synchronizer.Lock( tsm.SyncRoot ) ) { buffer.DrawString( tsm.Text, tsm.Font, new SolidBrush( tsm.Color ), tsm.Bounds ); } } else if( sm is ImageSheetModel ) { //add any images in the AnnotationSheets ImageSheetModel image_sheet_model = (ImageSheetModel)sm; using( Synchronizer.Lock( image_sheet_model.SyncRoot ) ) { buffer.DrawImage( image_sheet_model.Image, image_sheet_model.Bounds ); } } else { //Unknown, skip it continue; } } */ } } } } }
protected override void OnPaint( PaintEventArgs args ) { if (this.Slide == null) //Don't paint before the slide is set return; Color bkgColor; // Set the filmstrip background color BackgroundTemplate bkgTemplate; float slideZoom = 1f; RoleModel role; using (Synchronizer.Lock(PresenterModel.TheInstance.Participant.SyncRoot)) { role = PresenterModel.TheInstance.Participant.Role; } LinkedDeckTraversalModel.NavigationSelector studentNavigationType; using (Synchronizer.Lock(PresenterModel.TheInstance.ViewerState.SyncRoot)) { studentNavigationType = PresenterModel.TheInstance.ViewerState.StudentNavigationType; } using (Synchronizer.Lock(this.Slide.SyncRoot)) { bkgColor = (!this.Slide.BackgroundColor.IsEmpty) ? this.Slide.BackgroundColor : this.DefaultDeckBGColor; // For student role, paint unvisited slides gray. if (role is StudentModel && (!this.Slide.Visited) && studentNavigationType == LinkedDeckTraversalModel.NavigationSelector.Visited) bkgColor = SystemColors.Control; bkgTemplate = (this.Slide.BackgroundTemplate != null) ? this.Slide.BackgroundTemplate : this.DefaultDeckBGTemplate; slideZoom = this.Slide.Zoom; } args.Graphics.Clear(bkgColor); if (bkgTemplate != null) { BackgroundTemplateRenderer render = new BackgroundTemplateRenderer(bkgTemplate); render.Zoom = slideZoom; render.DrawAll(args.Graphics, this.ClientRectangle); } base.OnPaint( args ); // If the entry is selected, draw a thick border just inside of the 3D border. if( this.m_IsCurrentEntry ) { Rectangle highlight = this.ClientRectangle; if( this.m_IsCurrentDeckTraversal ) { using( Pen pen = new Pen( HIGHLIGHT_COLOR, HIGHLIGHT_BORDER_WIDTH ) ) { args.Graphics.DrawRectangle( pen, highlight ); } } else { using( Pen pen = new Pen( HIGHLIGHT_COLOR, HIGHLIGHT_BORDER_WIDTH ) ) { pen.DashStyle = DashStyle.Dot; args.Graphics.DrawRectangle( pen, highlight ); } } } }