public void Dispose() { if (sceneThumbInfo != null) { sceneThumbInfo.Dispose(); sceneThumbInfo = null; } }
private void saveSceneThumbInfo(Slide slide, SceneThumbInfo thumbInfo) { try { using (Stream stream = slideEditController.ResourceProvider.openWriteStream(slide.SceneThumbInfoName)) { SharedXmlSaver.Save(thumbInfo, stream); } saveThumbnail(slide.SceneThumbName, thumbInfo.SceneThumb); } catch (Exception ex) { Logging.Log.Error("{0} exception updating thumbnail info. Message: {1}", ex.GetType().Name, ex.Message); } }
/// <summary> /// Add a bitmap to act as a scene thumb for a slide. This class will take control of the /// bitmap and dispose it when it is done. /// </summary> /// <param name="slide"></param> /// <param name="thumb"></param> public void addUnsavedSceneThumb(Slide slide, SceneThumbInfo thumb) { SceneThumbInfo oldThumb; //Make sure we haven't loaded some other saved version of this thumb if (savedSceneThumbCache.TryGetValue(slide, out oldThumb)) { savedSceneThumbCache.Remove(slide); oldThumb.Dispose(); } //Make sure it wasn't already in unsavedSceneThumbs if (unsavedSceneThumbs.TryGetValue(slide, out oldThumb)) { oldThumb.Dispose(); unsavedSceneThumbs[slide] = thumb; } else { unsavedSceneThumbs.Add(slide, thumb); } }
private SceneThumbInfo renderSceneThumbnail() { SceneThumbInfo sceneThumbInfo = new SceneThumbInfo(); ImageRendererProperties imageProperties = new ImageRendererProperties(); imageProperties.Width = SlideImageManager.SceneThumbWidth; imageProperties.Height = SlideImageManager.SceneThumbHeight; imageProperties.AntiAliasingMode = 2; imageProperties.TransparentBackground = false; imageProperties.UseActiveViewportLocation = false; imageProperties.OverrideLayers = true; imageProperties.ShowBackground = false; imageProperties.ShowWatermark = false; imageProperties.ShowUIUpdates = false; slide.StartupAction.configureThumbnailProperties(imageProperties); imageProperties.CustomizeCameraPosition = (camera, viewport) => { SceneNode node = camera.getParentSceneNode(); Vector3 position = node.getDerivedPosition(); Vector3 lookAt = imageProperties.CameraLookAt; Vector3 topLeft = SceneViewWindow.Unproject(0, 0, camera.getViewMatrix(), camera.getProjectionMatrix()); Vector3 bottomRight = SceneViewWindow.Unproject(1, 1, camera.getViewMatrix(), camera.getProjectionMatrix()); Vector3 include = imageProperties.IncludePoint; //Move camera back more float distance = -60; Vector3 direction = (position - lookAt).normalized(); node.setPosition(position - (direction * distance)); camera.lookAt(lookAt); Vector2 includeLoc = SceneViewWindow.Project(include, camera.getViewMatrix(), camera.getProjectionMatrix(), imageProperties.Width, imageProperties.Height); sceneThumbInfo.IncludeX = (int)includeLoc.x; sceneThumbInfo.IncludeY = (int)includeLoc.y; sceneThumbInfo.Color = viewport.getBackgroundColor(); }; sceneThumbInfo.SceneThumb = imageRenderer.renderImage(imageProperties); return(sceneThumbInfo); }
public SlideSceneInfo(Slide slide, SceneThumbInfo sceneThumbInfo) { startupAction = CopySaver.Default.copy(slide.StartupAction); this.sceneThumbInfo = sceneThumbInfo; }
public void updateThumbnail(bool forceUpdateSceneThumb = false) { Dictionary <RmlEditorViewInfo, LayoutContainer> layoutPositions = new Dictionary <RmlEditorViewInfo, LayoutContainer>(); if (slideEditorController.ResourceProvider != null) { //Setup a LayoutChain to mimic the main one. LayoutChain layoutChain = new LayoutChain(); layoutChain.addLink(new PopupAreaChainLink(GUILocationNames.ContentAreaPopup), true); layoutChain.addLink(new BorderLayoutNoAnimationChainLink(GUILocationNames.ContentArea), true); IntSize2 thumbTotalSize = new IntSize2(SlideImageManager.ThumbWidth, SlideImageManager.ThumbHeight); FreeImageBitmap thumb = slideEditorController.SlideImageManager.createThumbBitmap(slide); layoutChain.SuppressLayout = true; LayoutContainer sceneContainer = new NullLayoutContainer(thumbTotalSize); layoutChain.addContainer(new BorderLayoutElementName(GUILocationNames.ContentArea, BorderLayoutLocations.Center), sceneContainer, null); foreach (var editor in rmlEditors.Values) { if (editor.Component != null) { float sizeRatio = (float)SlideImageManager.ThumbHeight / editor.Component.ViewHost.Container.RigidParentWorkingSize.Height; IntSize2 size = (IntSize2)(editor.Component.ViewHost.Container.DesiredSize * sizeRatio); NullLayoutContainer container = new NullLayoutContainer(size); layoutPositions.Add(editor, container); layoutChain.addContainer(editor.View.ElementName, container, null); } } layoutChain.SuppressLayout = false; layoutChain.WorkingSize = thumbTotalSize; layoutChain.Location = new IntVector2(0, 0); layoutChain.layout(); //Render thumbnail, Start with the scene IntVector2 sceneThumbPosition = sceneContainer.Location; String sceneThumbFile = slide.SceneThumbName; if (forceUpdateSceneThumb) { slideEditorController.SlideImageManager.addUnsavedSceneThumb(slide, renderSceneThumbnail()); } SceneThumbInfo sceneThumbInfo = slideEditorController.SlideImageManager.loadThumbSceneBitmap(slide, renderSceneThumbnail); IntSize2 centerSize = sceneContainer.WorkingSize; RectangleF destRect = new RectangleF(sceneThumbPosition.x, sceneThumbPosition.y, centerSize.Width, centerSize.Height); thumb.FillBackground(new RGBQUAD(FreeImageAPI.Color.FromArgb(sceneThumbInfo.Color.toARGB()))); int requiredWidth = (sceneThumbInfo.SceneThumb.Width - ((sceneThumbInfo.SceneThumb.Width - sceneThumbInfo.IncludeX) * 2)); int requiredHeight = (sceneThumbInfo.SceneThumb.Height - (sceneThumbInfo.IncludeY * 2)); int sceneThumbWidth = sceneThumbInfo.SceneThumb.Width; int sceneThumbHeight = sceneThumbInfo.SceneThumb.Height; int sceneThumbHalfWidth = sceneThumbWidth / 2; int sceneThumbHalfHeight = sceneThumbHeight / 2; float requiredHeightWidthRatio = (float)requiredHeight / requiredWidth; float centerHeightWidthRatio = (float)centerSize.Height / centerSize.Width; float srcWidth = requiredWidth; float srcHeight = requiredHeight; if (requiredHeightWidthRatio < centerHeightWidthRatio) //Compare ratios between our source required area and the destination { //Use the full required width, add height from source image //Convert the center size to the same size ratio as the required size float sizeRatio = (float)requiredWidth / centerSize.Width; srcHeight = centerSize.Height * sizeRatio; if (srcHeight > sceneThumbHeight) //Stretch out the image as much as possible, limiting by the size of the scene thumb if needed. { srcHeight = sceneThumbHeight; } float destHeight = srcHeight / sizeRatio; destRect = new RectangleF(destRect.Left, destRect.Height / 2 + destRect.Top - destHeight / 2, destRect.Width, destHeight); //Make a dest rect that takes as much image as it can } else { //Use the full required height, add width from source image float sizeRatio = (float)requiredHeight / centerSize.Height; srcWidth = centerSize.Width * sizeRatio; if (srcWidth > sceneThumbWidth) { srcWidth = sceneThumbWidth; } float destWidth = srcWidth / sizeRatio; destRect = new RectangleF(destRect.Width / 2 + destRect.Left - destWidth / 2, destRect.Top, destWidth, destRect.Height); } RectangleF srcRect = new RectangleF(sceneThumbHalfWidth - srcWidth / 2, sceneThumbHalfHeight - srcHeight / 2, srcWidth, srcHeight); using (FreeImageBitmap resizedSceneThumb = sceneThumbInfo.SceneThumb.Copy((int)srcRect.X, (int)srcRect.Y, (int)srcRect.Right, (int)srcRect.Bottom)) { resizedSceneThumb.Rescale((int)destRect.Width, (int)destRect.Height, FREE_IMAGE_FILTER.FILTER_BILINEAR); thumb.Paste(resizedSceneThumb, (int)destRect.X, (int)destRect.Y, int.MaxValue); } //Render all panels foreach (var editor in rmlEditors.Values) { if (editor.Component != null) { LayoutContainer container; if (layoutPositions.TryGetValue(editor, out container)) { Rectangle panelThumbPos = new Rectangle(container.Location.x, container.Location.y, container.WorkingSize.Width, container.WorkingSize.Height); editor.Component.writeToGraphics(thumb, panelThumbPos); } } } slideEditorController.SlideImageManager.thumbnailUpdated(slide); } }
public SlideSceneInfo getCurrentSceneInfo() { SceneThumbInfo sceneThumbInfo = slideEditorController.SlideImageManager.loadThumbSceneBitmap(slide, renderSceneThumbnail); return(new SlideSceneInfo(slide, sceneThumbInfo.copy())); }