private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Get backing visual from shadow container and interop compositor _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer); _compositor = _shadowContainer.Compositor; // Get CompositionImage, its sprite visual _image = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(ShadowContainer); _imageVisual = _image.SpriteVisual; // Load mask asset onto surface using helpers in SamplesCommon _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _imageMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White); // Create surface brush for mask CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush(); mask.Surface = _imageMaskSurface.Surface; // Get surface brush from composition image CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush; // Create mask brush for toggle mask functionality _maskBrush = _compositor.CreateMaskBrush(); _maskBrush.Mask = mask; _maskBrush.Source = source; // Initialize toggle mask _isMaskEnabled = false; }
public BorderPlayground() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); this.InitializeComponent(); }
private void InitializeCompositionVariables() { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; var maxWindowWidth = bounds.Width.ToFloat(); var maxWindowHeight = bounds.Height.ToFloat(); var maxWindowRadius = Math.Max(maxWindowWidth, maxWindowHeight); // Setup sky visual's size, position, opacity, etc. _skyVisual = Sky.ContainerVisual(); _skyVisual.Size = new Vector2(maxWindowRadius * SkyVisualAreaRatio); _skyVisual.Offset = new Vector3(-SkyVisualRadius + maxWindowWidth / 2.0f, -SkyVisualRadius + maxWindowHeight / 2.0f, 0.0f); _skyVisual.CenterPoint = new Vector3(SkyVisualRadius, SkyVisualRadius, 0.0f); _skyVisual.Opacity = 0; _compositor = _skyVisual.Compositor; _reading = _compositor.CreatePropertySet(); _reading.InsertVector3("Offset", new Vector3(0.0f, 0.0f, 0.0f)); _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleBrush = _compositor.CreateSurfaceBrush(); _circleBrush.Surface = _imageLoader.LoadImageFromUri(new Uri(StarUriString)); if (_inclinometer != null) { SetupSkyVisualOffsetExpressionAnimation(); } }
private void Setup() { if (!_firstRun) { return; } _firstRun = false; var shadowContainer = ElementCompositionPreview.GetElementVisual(ImageContainer); var compositor = shadowContainer.Compositor; var image = ImageContainer.FindChildren <CompositionImage>().First(); var imageVisual = image.SpriteVisual; var imageLoader = ImageLoaderFactory.CreateImageLoader(compositor); var imageMaskSurface = imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Helpers/Composition/CircleMask.png")); var mask = compositor.CreateSurfaceBrush(); mask.Surface = imageMaskSurface.Surface; var source = image.SurfaceBrush as CompositionSurfaceBrush; var maskBrush = compositor.CreateMaskBrush(); maskBrush.Mask = mask; maskBrush.Source = source; image.Brush = maskBrush; Shadow.Mask = maskBrush.Mask; this.Fade(value: 1, delay: 1000).StartAsync(); }
/** * Creates a new Animation. By default, adds the given frame to the timeline, along with * two blank tranisitions. * * @param id * the id of the animation * @param frame * The frame to add to the timeline * @param factory * Object used to create the images for the frames * */ public Animation(string id, Frame frame, ImageLoaderFactory factory) { this.factory = factory; this.id = id; resources = new List <ResourcesUni>(); frames = new List <Frame>(); transitions = new List <Transition>(); frames.Add(frame); Transition t0 = new Transition(); t0.setType(Transition.TYPE_FADEIN); t0.setTime(1); transitions.Add(t0); Transition t1 = new Transition(); t1.setType(Transition.TYPE_FADEIN); t1.setTime(1); transitions.Add(t1); skippedFrames = 0; useTransitions = true; slides = false; }
private CompositionSurfaceBrush CreateBrushFromAsset(string name, out Size size) { IImageLoader imageLoader = ImageLoaderFactory.CreateImageLoader(m_compositor); CompositionDrawingSurface surface = imageLoader.LoadImageFromUri(new Uri("ms-appx:///Assets/" + name)); size = surface.Size; return(m_compositor.CreateSurfaceBrush(surface)); }
/// <summary> /// Initialize Composition /// </summary> private void InitializeComposition() { // Retrieve an instance of the Compositor from the backing Visual of the Page _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // Create a root visual from the Compositor _root = _compositor.CreateContainerVisual(); // Set the root ContainerVisual as the XAML Page Visual ElementCompositionPreview.SetElementChildVisual(this, _root); // Assign initial values to variables used to store updated offsets for the visuals float posXUpdated = _posX; float posYUpdated = _posY; // Create a list of image brushes that can be applied to a visual string[] imageNames = { "01.png", "02.png", "03.png", "04.png", "05.png", "06.png", "07.png", "08.png", "60Banana.png", "60Lemon.png", "60Vanilla.png", "60Mint.png", "60Orange.png", "110Strawberry.png", "60SprinklesRainbow.png" }; List <CompositionSurfaceBrush> imageBrushList = new List <CompositionSurfaceBrush>(); IImageLoader imageFactory = ImageLoaderFactory.CreateImageLoader(_compositor); for (int k = 0; k < imageNames.Length; k++) { var surface = imageFactory.LoadImageFromUri(new Uri("ms-appx:///Assets/Images/Composition/ImplicitAnimation/" + imageNames[k])); imageBrushList.Add(_compositor.CreateSurfaceBrush(surface)); } // Create nxn matrix of visuals where n=row/ColumnCount-1 and passes random image brush to the function // that creates a visual for (int i = 1; i < _rowCount; i++) { posXUpdated = i * _distance; for (int j = 1; j < _columnCount; j++) { CompositionSurfaceBrush brush = imageBrushList[randomBrush.Next(imageBrushList.Count)]; posYUpdated = j * _distance; _root.Children.InsertAtTop(CreateChildElement(brush, posXUpdated, posYUpdated)); } } EnableAnimationOnChildren(EnableAnimations.IsChecked.GetValueOrDefault()); }
/// <summary> /// Creates the circle used in the circle brush if not already created. /// </summary> private void EnsureCircleBrush() { if (_circleBrush == null) { _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleSurface = _imageLoader.CreateCircleSurface(200, Colors.White); _circleBrush = _compositor.CreateSurfaceBrush(_circleSurface.Surface); } }
/// <summary> /// Creates the circle used in the circle brush if not already created. /// </summary> private void EnsureCircleBrush() { if (_circleBrush == null) { _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri(CircleImagePath)); _circleBrush = _compositor.CreateSurfaceBrush(_circleSurface.Surface); } }
public CompCapabilities() { this.InitializeComponent(); _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); // Get hardware capabilities and register changed event listener _capabilities = CompositionCapabilities.GetForCurrentView(); }
/** * Creates a new frame with a image uri, a duration time and the selection for user click waiting * * @param uri * The uri for the image * @param time * The time (duration) of the frame */ public Frame(ImageLoaderFactory factory, string uri, long time, bool waitForClick) { this.uri = uri; this.factory = factory; type = TYPE_IMAGE; this.time = time; image = null; this.waitforclick = waitForClick; resources = new List <ResourcesUni>(); soundUri = ""; maxSoundTime = 1000; }
public ColorBloomTransitionHelper(UIElement hostForVisual) { this.hostForVisual = hostForVisual; var visual = ElementCompositionPreview.GetElementVisual(hostForVisual); _compositor = visual.Compositor; _containerForVisuals = _compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals); _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White); }
/** * Creates a new Animation. By default, adds the given frame to the timeline, along with * two blank tranisitions. * * @param id * the id of the animation * @param frame * The frame to add to the timeline * @param factory * Object used to create the images for the frames * */ public Animation(string id, Frame frame, ImageLoaderFactory factory) { this.factory = factory; this.id = id; resources = new List <ResourcesUni>(); frames = new List <Frame>(); transitions = new List <Transition>(); frames.Add(frame); transitions.Add(new Transition()); transitions.Add(new Transition()); skippedFrames = 0; useTransitions = true; slides = false; }
async private Task LoadImages() { _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); string[] imageNames = { "Photos/Pic06", "Photos/Pic30", "Photos/Pic39", "Landscapes/Landscape-7", "Landscapes/Landscape-8", "Landscapes/Landscape-9", "Landscapes/Landscape-12", "Photos/pic22", "Photos/Pic11" }; for (int i = 0; i < imageNames.Length; ++i) { var uri = new Uri($"ms-appx:///Assets/{imageNames[i]}.jpg"); var surface = await SurfaceLoader.LoadFromUri(uri); _imageSurfaces[i] = _compositor.CreateSurfaceBrush(surface); } }
public NineGridResizing() { this.InitializeComponent(); _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); // Add page loaded event listener this.Loaded += NineGridResizing_Loaded; // Set data context for data binding DataContext = this; // Sprite visual to be painted _ninegridVisual = _compositor.CreateSpriteVisual(); // Create ninegridbrush and paint on visual; _ninegridBrush = _compositor.CreateNineGridBrush(); _ninegridVisual.Brush = _ninegridBrush; // Clip compgrid var compGrid = ElementCompositionPreview.GetElementVisual(CompGrid); compGrid.Clip = _compositor.CreateInsetClip(); // Scene container to be scaled _backgroundContainer = ElementCompositionPreview.GetElementVisual(bkgHost); // Insert Composition island ElementCompositionPreview.SetElementChildVisual(ngHost, _ninegridVisual); // Instatiate brush scenario list and fill with created brush scenarios _nineGridBrushScenarios = new ObservableCollection <INineGridScenario>(CreateBrushes(_compositor, _imageLoader, _ninegridVisual.Size)); // Set default combo box selection to first item BrushScenarioSelected = _nineGridBrushScenarios.FirstOrDefault(); // Value timer initialization for sliders _valueTimerXSlider = new ValueTimer <float>(); _valueTimerXSlider.ValueChanged += OnXSliderValueChanged; _valueTimerYSlider = new ValueTimer <float>(); _valueTimerYSlider.ValueChanged += OnYSliderValueChanged; _valueTimerScaleSlider = new ValueTimer <float>(); _valueTimerScaleSlider.ValueChanged += OnScaleSliderValueChanged; }
/// <summary> /// Creates an instance of the ColorBloomTransitionHelper. /// Any visuals to be later created and animated will be hosted within the specified UIElement. /// </summary> public ColorBloomTransitionHelper(UIElement hostForVisual) { this.hostForVisual = hostForVisual; // we have an element in the XAML tree that will host our Visuals var visual = ElementCompositionPreview.GetElementVisual(hostForVisual); _compositor = visual.Compositor; // create a container // adding children to this container adds them to the live visual tree _containerForVisuals = _compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals); // initialize the ImageLoader and create the circle mask _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/TransitionAnimation-ColorBloom/CircleOpacityMask.png")); }
/// <summary> /// Creates an instance of the ColorBloomTransitionHelper. /// Any visuals to be later created and animated will be hosted within the specified UIElement. /// </summary> public ColorBloomTransitionHelper(UIElement hostForVisual) { this.hostForVisual = hostForVisual; // we have an element in the XAML tree that will host our Visuals var visual = ElementCompositionPreview.GetElementVisual(hostForVisual); _compositor = visual.Compositor; // create a container // adding children to this container adds them to the live visual tree _containerForVisuals = _compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals); // initialize the ImageLoader and create the circle mask _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White); }
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Get backing visual from shadow container and interop compositor _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer); _compositor = _shadowContainer.Compositor; // Get CompositionImage, its sprite visual _image = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(ShadowContainer); _imageVisual = _image.SpriteVisual; // Add drop shadow to image visual _shadow = _compositor.CreateDropShadow(); _imageVisual.Shadow = _shadow; // Initialize sliders to shadow defaults - with the exception of offset BlurRadiusSlider.Value = _shadow.BlurRadius; //defaults to 9.0f OffsetXSlider.Value = _shadow.Offset.X; //defaults to 0 OffsetYSlider.Value = _shadow.Offset.Y; //defaults to 0 RedSlider.Value = _shadow.Color.R; //defaults to 0 (black.R) GreenSlider.Value = _shadow.Color.G; //defaults to 0 (black.G) BlueSlider.Value = _shadow.Color.B; //defaults to 0 (black.B) // Load mask asset onto surface using helpers in SamplesCommon _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png")); // Create surface brush for mask CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush(); mask.Surface = _imageMaskSurface.Surface; // Get surface brush from composition image CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush; // Create mask brush for toggle mask functionality _maskBrush = _compositor.CreateMaskBrush(); _maskBrush.Mask = mask; _maskBrush.Source = source; // Initialize toggle mask and animation to false _isMaskEnabled = false; _isAnimationEnabled = false; }
public object DOMParse(XmlElement element, params object[] parameters) { ImageLoaderFactory ilf = parameters [0] as ImageLoaderFactory; Frame frame = new Frame(ilf); XmlNodeList assets = element.SelectNodes("next-scene"); switch (element.GetAttribute("type")) { case "image": frame.setType(Frame.TYPE_IMAGE); break; case "video": frame.setType(Frame.TYPE_VIDEO); break; } frame.setUri(element.GetAttribute("uri") ?? ""); frame.setWaitforclick("yes".Equals(element.GetAttribute("waitforclick"))); frame.setSoundUri(element.GetAttribute("soundUri") ?? ""); var time = element.GetAttribute("time"); if (!string.IsNullOrEmpty(time)) { frame.setTime(long.Parse(time)); } var maxsoundtime = element.GetAttribute("maxSoundTime"); if (!string.IsNullOrEmpty(maxsoundtime)) { frame.setMaxSoundTime(int.Parse(maxsoundtime)); } foreach (var resources in DOMParserUtility.DOMParse <ResourcesUni>(element.SelectNodes("resources"), parameters)) { frame.addResources(resources); } return(frame); }
/// <summary> /// MainPage_Loaded is used for all of our initialization to keep the UI thread mostly free. /// </summary> /// <param name="sender">not used</param> /// <param name="e">not used</param> private async void MainPage_Loaded(object sender, RoutedEventArgs e) { _compositor = ElementCompositionPreview.GetElementVisual(sender as UIElement).Compositor; _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(Scroller); var uri = new Uri("ms-appx:///Samples/SDK 10586/Z-Order Scrolling/RollingWaves.jpg"); ParallaxingImage.Source = uri; ParallaxingImage.Brush = await InitializeCrossFadeEffect(uri); var maskedBrush = InitializeCompositeEffect(); ParallaxingImage.SizeChanged += (s, ev) => { UpdateSizes(); }; InitializeBackgroundImageVisual(scrollProperties); InitializeFrontVisual(scrollProperties, maskedBrush); InitializeBehindVisual(scrollProperties, maskedBrush); UpdateSizes(); }
private void SetupCompositionImage(CompositionImage image, News.Helpers.Composition.CompositionShadow shadow) { var imageVisual = image.SpriteVisual; var compositor = imageVisual.Compositor; var imageLoader = ImageLoaderFactory.CreateImageLoader(compositor); var imageMaskSurface = imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Helpers/Composition/CircleMask.png")); var mask = compositor.CreateSurfaceBrush(); mask.Surface = imageMaskSurface.Surface; var source = image.SurfaceBrush as CompositionSurfaceBrush; var maskBrush = compositor.CreateMaskBrush(); maskBrush.Mask = mask; maskBrush.Source = source; image.Brush = maskBrush; shadow.Mask = maskBrush.Mask; }
private async void InitComposition() { // Obtain a Compositor and use it to initialize our ImageLoader. // Make sure you have the CompositionImageLoader nuget package: // https://www.nuget.org/packages/Robmikh.Util.CompositionImageLoader var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; var imageLoader = ImageLoaderFactory.CreateImageLoader(compositor); // Create a ManagedSurface, which is resilient to having our device lost suddenly. var managedSurface = await imageLoader.CreateManagedSurfaceFromUriAsync(new Uri("ms-appx:///Assets/tripphoto1.jpg")); // Create a brush using our new surface. var brush = compositor.CreateSurfaceBrush(managedSurface.Surface); // Create a visual and assign our brush to the visual's Brush property. var visual = compositor.CreateSpriteVisual(); visual.Size = managedSurface.Size.ToVector2(); // We use the image's real size so we avoid stretching. This isn't strictly necessary. visual.Offset = new Vector3(50, 50, 0); visual.Brush = brush; // Attach our visual into the tree. ElementCompositionPreview.SetElementChildVisual(this, visual); }
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { Compositor compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor; _imageLoader = ImageLoaderFactory.CreateImageLoader(compositor); ContainerVisual container = compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(MyGrid, container); // // Create a couple of SurfaceBrushes for the orbiters and center // CompositionSurfaceBrush redBrush = compositor.CreateSurfaceBrush(); _redBallSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/RedBall.png")); redBrush.Surface = _redBallSurface.Surface; CompositionSurfaceBrush blueBrush = compositor.CreateSurfaceBrush(); _blueBallSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/BlueBall.png")); blueBrush.Surface = _blueBallSurface.Surface; // // Create the center and orbiting sprites // SpriteVisual redSprite = compositor.CreateSpriteVisual(); redSprite.Brush = redBrush; redSprite.Size = new Vector2(100f, 100f); redSprite.Offset = new Vector3((float)Window.Current.Bounds.Width / 2 - redSprite.Size.X / 2, 150f, 0f); container.Children.InsertAtTop(redSprite); SpriteVisual blueSprite = compositor.CreateSpriteVisual(); blueSprite.Brush = blueBrush; blueSprite.Size = new Vector2(25f, 25f); blueSprite.Offset = new Vector3((float)Window.Current.Bounds.Width / 2 - redSprite.Size.X / 2, 50f, 0f); container.Children.InsertAtTop(blueSprite); // // Create the expression. This expression positions the orbiting sprite relative to the center of // of the red sprite's center. As we animate the red sprite's position, the expression will read // the current value of it's offset and keep the blue sprite locked in orbit. // ExpressionAnimation expressionAnimation = compositor.CreateExpressionAnimation("visual.Offset + " + "propertySet.CenterPointOffset + " + "Vector3(cos(ToRadians(propertySet.Rotation)) * 150," + "sin(ToRadians(propertySet.Rotation)) * 75, 0)"); // // Create the PropertySet. This property bag contains all the value referenced in the expression. We can // animation these property leading to the expression being re-evaluated per frame. // _propertySet = compositor.CreatePropertySet(); _propertySet.InsertScalar("Rotation", 0f); _propertySet.InsertVector3("CenterPointOffset", new Vector3(redSprite.Size.X / 2 - blueSprite.Size.X / 2, redSprite.Size.Y / 2 - blueSprite.Size.Y / 2, 0)); // Set the parameters of the expression animation expressionAnimation.SetReferenceParameter("propertySet", _propertySet); expressionAnimation.SetReferenceParameter("visual", redSprite); // Start the expression animation! blueSprite.StartAnimation("Offset", expressionAnimation); // Now animate the rotation property in the property bag, this generates the orbitting motion. var linear = compositor.CreateLinearEasingFunction(); var rotAnimation = compositor.CreateScalarKeyFrameAnimation(); rotAnimation.InsertKeyFrame(1.0f, 360f, linear); rotAnimation.Duration = TimeSpan.FromMilliseconds(4000); rotAnimation.IterationBehavior = AnimationIterationBehavior.Forever; _propertySet.StartAnimation("Rotation", rotAnimation); // Lastly, animation the Offset of the red sprite to see the expression track appropriately var offsetAnimation = compositor.CreateScalarKeyFrameAnimation(); offsetAnimation.InsertKeyFrame(0f, 50f); offsetAnimation.InsertKeyFrame(.5f, 150f); offsetAnimation.InsertKeyFrame(1f, 50f); offsetAnimation.Duration = TimeSpan.FromMilliseconds(4000); offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever; redSprite.StartAnimation("Offset.Y", offsetAnimation); }
/** * Creates a new empty frame */ public Frame(ImageLoaderFactory factory) : this(factory, "", DEFAULT_TIME, false) { }
/** * Creates a new Animation. By default, adds the given frame to the timeline, along with * two blank tranisitions. * * @param id * the id of the animation * @param frame * The frame to add to the timeline * @param factory * Object used to create the images for the frames * */ public Animation(string id, Frame frame, ImageLoaderFactory factory) { this.factory = factory; this.id = id; resources = new List<ResourcesUni>(); frames = new List<Frame>(); transitions = new List<Transition>(); frames.Add(frame); transitions.Add(new Transition()); transitions.Add(new Transition()); skippedFrames = 0; useTransitions = true; slides = false; }
/** * Creates a new frame with the given duration * * @param time * integer with the duration of the frame */ public Frame(ImageLoaderFactory factory, int time) : this(factory, "", time, false) { }
/** * Creates a new frame with a image uri * * @param uri * the uri for the image */ public Frame(ImageLoaderFactory factory, string uri) : this(factory, uri, DEFAULT_TIME, false) { }
public AnimationHandler_(InputStreamCreator isCreator, ImageLoaderFactory imageloader) { this.factory = imageloader; this.isCreator = isCreator; }
/** * Loads an animation from a filename * * @param filename * The xml descriptor for the animation * @return the loaded Animation */ public static Animation loadAnimation(InputStreamCreator isCreator, string filename, ImageLoaderFactory imageloader) { AnimationHandler_ animationHandler = new AnimationHandler_(isCreator, imageloader); // Create a new factory //factory.setValidating(false); //SAXParser saxParser; try { //saxParser = factory.newSAXParser(); // Read and close the input stream //File file = new File(filename); string descriptorIS = null; /*try { * System.out.println("FILENAME="+filename); * descriptorIS = ResourceHandler.getInstance( ).buildInputStream(filename); * System.out.println("descriptorIS==null?"+(descriptorIS==null)); * * //descriptorIS = new InputStream(ResourceHandler.getInstance().getResourceAsURLFromZip(filename)); * } catch (Exception e) { Debug.LogError(e); } { * e.printStackTrace(); * } * if (descriptorIS == null) { * descriptorIS = AssetsController.getInputStream(filename); * }*/ descriptorIS = isCreator.buildInputStream("Assets/Resources/CurrentGame/" + filename); if (!descriptorIS.EndsWith(".eaa")) { descriptorIS += ".eaa"; } animationHandler.Parse(descriptorIS); //saxParser.parse(descriptorIS, animationHandler); //descriptorIS.close(); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (SAXException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (FileNotFoundException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (IOException e) //{ // e.printStackTrace(); // System.err.println(filename); //} if (animationHandler.getAnimation() != null) { return(animationHandler.getAnimation()); } else { return(new Animation("anim" + (new System.Random()).Next(1000), imageloader)); } }
async private void LoadImages() { int loadedImageCount = 0; // Create the loader _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); // // Populate/load our unique list of image textures. // for (int i = 0; i < (int)NamedImage.Count; i++) { var name = (NamedImage)i; Uri uri = new Uri($"ms-appx:///Assets/Photos/{name.ToString()}.jpg"); _managedSurfaces[i] = _imageLoader.CreateManagedSurfaceFromUri(uri); var surface = await _imageLoader.LoadImageFromUriAsync(uri); _imageBrushes[i] = _compositor.CreateSurfaceBrush(surface); loadedImageCount++; } // // Populate/load our unique list of "text" image textures. // _textBrushes = new CompositionSurfaceBrush[_textNodes.Length]; for (int i = 0; i < _textNodes.Length; i++) { var textNode = _textNodes[i]; var textSurface = SurfaceLoader.LoadText(textNode.Text, new Size(textNode.TextureSize.X, textNode.TextureSize.Y), textNode.TextFormat, Colors.Black, Colors.Transparent); _textBrushes[i] = _compositor.CreateSurfaceBrush(textSurface); // // Remember the index of the brush so that we can refer to it later. // textNode.BrushIndex = i; loadedImageCount++; } // // Once we've loaded all of the images, we can continue populating the world. // if (loadedImageCount == _imageBrushes.Length + _textBrushes.Length) { PopulateWorld(); } }
/** * Creates a new Animation with a blank frame with a specific duration. * Equivalent to Animation (id, new Frame(factory, time), factory). * * @param id * the id of the animation * @param time * The duration of the frame to be created. * @param factory * Object used to create the images for the frames */ public Animation(string id, int time, ImageLoaderFactory factory) : this(id, new Frame(factory, time), factory) { }
public AnimationHandler_(InputStreamCreator isCreator, ImageLoaderFactory imageloader) { this.factory = imageloader; }
/** * Loads an animation from a filename * * @param filename * The xml descriptor for the animation * @return the loaded Animation */ public static Animation loadAnimation(InputStreamCreator isCreator, string filename, ImageLoaderFactory imageloader) { AnimationHandler_ animationHandler = new AnimationHandler_(isCreator, imageloader); // Create a new factory //factory.setValidating(false); //SAXParser saxParser; try { //saxParser = factory.newSAXParser(); // Read and close the input stream //File file = new File(filename); string descriptorIS = null; /*try { System.out.println("FILENAME="+filename); descriptorIS = ResourceHandler.getInstance( ).buildInputStream(filename); System.out.println("descriptorIS==null?"+(descriptorIS==null)); //descriptorIS = new InputStream(ResourceHandler.getInstance().getResourceAsURLFromZip(filename)); } catch (Exception e) { Debug.LogError(e); } { e.printStackTrace(); } if (descriptorIS == null) { descriptorIS = AssetsController.getInputStream(filename); }*/ descriptorIS = isCreator.buildInputStream("Assets/Resources/" + filename); if (!descriptorIS.EndsWith(".eaa")) descriptorIS += ".eaa"; animationHandler.Parse(descriptorIS); //saxParser.parse(descriptorIS, animationHandler); //descriptorIS.close(); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (SAXException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (FileNotFoundException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (IOException e) //{ // e.printStackTrace(); // System.err.println(filename); //} if (animationHandler.getAnimation() != null) return animationHandler.getAnimation(); else return new Animation("anim" + (new System.Random()).Next(1000), imageloader); }
/** * Creates a new frame with a image uri, a duration time and the selection for user click waiting * * @param uri * The uri for the image * @param time * The time (duration) of the frame */ public Frame(ImageLoaderFactory factory, string uri, long time, bool waitForClick) { this.uri = uri; this.factory = factory; type = TYPE_IMAGE; this.time = time; image = null; this.waitforclick = waitForClick; resources = new List<ResourcesUni>(); soundUri = ""; maxSoundTime = 1000; }