CompositionProToolkit v0.4.2 released


Well, the last week has been pretty busy – learning little more details about the Composition APIs, major refactoring of the CompositionProToolkit code, breaking changes and adding new features and controls. The hard work finally paid off. I am excited to announce the release of CompositionProToolkit v0.4.2. Let’s see, in detail, what this new version contains.

Breaking Changes

First and foremost, you would like to know what will not work if you move to version 0.4.2. After digging deeper into the various classes within the Windows.UI.Composition namespace, I realized that before introducing new features and controls, it was high time I refactored my code. Thus I began – optimizing various classes, removing lot of redundant Task.Run(…)* encapsulations. As a result, many APIs which were earlier asynchronous are now synchronous (you no longer need to await them!). The main advantages are improved execution speed and more robust code. 🙂

Here are some of the classes whose APIs have changed. If you are using them within their code you will have to update them to the new API calls.

CompositionGeneratorFactory

CompositionGeneratorFactory no longer requires a sharedLock parameter while obtaining the CompositionGenerator. The lock is now managed internally within each CompositionSurfaceImage. Since this was an optional argument in the GetCompositionGenerator API, if you were not providing this argument in your code the your code need not be changed.

v0.4.1

public static ICompositionGenerator GetCompositionGenerator(Compositor compositor, 
    CompositionGraphicsDevice graphicsDevice=null, object sharedLock=null);

v0.4.2

public static ICompositionGenerator GetCompositionGenerator(Compositor compositor, 
    CompositionGraphicsDevice graphicsDevice=null);

ICompositionMask

All the asynchronous APIs in ICompositionMask class have been refactored into synchronous APIs.

v0.4.1

Task RedrawAsync();
Task RedrawAsync(Geometry.CanvasGeometry geometry);
Task RedrawAsync(Size size, Geometry.CanvasGeometry geometry);
Task RedrawAsync(Size size, Geometry.CanvasGeometry geometry, ICanvasBrush brush);
Task RedrawAsync(Size size, Geometry.CanvasGeometry geometry, Color color);
Task ResizeAsync(Size size);

v0.4.2

void Redraw();
void Redraw(Geometry.CanvasGeometry geometry);
void Redraw(Size size, Geometry.CanvasGeometry geometry);
void Redraw(Size size, Geometry.CanvasGeometry geometry, ICanvasBrush brush);
void Redraw(Size size, Geometry.CanvasGeometry geometry, Color color);
void Resize(Size size);

ICompositionSurfaceImage

A few of the asynchronous APIs in ICompositionSurfaceImage class have been refactored into synchronous APIs.

v0.4.1

Task RedrawAsync(CompositionSurfaceImageOptions options);
Task ResizeAsync(Size size);
Task ResizeAsync(Size size, CompositionSurfaceImageOptions options);

v0.4.2

void Redraw(CompositionSurfaceImageOptions options);
void Resize(Size size);
void Resize(Size size, CompositionSurfaceImageOptions options);

ICompositionGenerator

All the asynchronous APIs in ICompositionGenerator related to creating of ICompositionMask and visual Reflection have been refactored into synchronous APIs.

v0.4.1

Task CreateMaskAsync(Size size, CanvasGeometry geometry);
Task CreateMaskAsync(Size size, CanvasGeometry geometry, ICanvasBrush brush);
Task CreateMaskAsync(Size size, CanvasGeometry geometry, Color color);
Task CreateReflectionAsync(ContainerVisual visual, float reflectionDistance, 
    float reflectionLength, ReflectionLocation location);

v0.4.2

ICompositionMask CreateMask(Size size, CanvasGeometry geometry);
ICompositionMask CreateMask(Size size, CanvasGeometry geometry, ICanvasBrush brush);
ICompositionMask CreateMask(Size size, CanvasGeometry geometry, Color color);
void CreateReflection(ContainerVisual visual, float reflectionDistance, 
    float reflectionLength, ReflectionLocation location));

So what’s new in v0.4.2?

Now that we are done with the breaking changes, let’s look what all new features and controls have been added to CompositionProToolkit v0.4.2.

CompositionSurfaceImageOptions

CompositionSurfaceImageOptions now has an additional property AutoResize which can be set to False when you are trying to render a large image onto the CompositionSurfaceImage as a thumbnail. This will optimize memory usage.

Property Type Description Default value
AutoResize Boolean Specifies whether the CompositionSurfaceImage should resize itself automatically to match the loaded image size. When set to True, the Stretch, HorizontalAlignment and VerticalAlignment options are ignored. False

CompositionImageFrame

CompositionImageFrame now provides a fade in animation while transitioning from one image to another. It also supports rounded corners and display of shadows which can be configured easily. It also allows an option to optimize the rendering of the image. This is useful for scenarios where you are trying to render a large image to a smaller size, for example thumbnails.

CPT6.gif

The following new properties have been added to CompositionImageFrame

Property Type Description Default value
CornerRadius CornerRadius Indicates the corner radius of the the ImageFrame. The image will be rendered with rounded corners. (0, 0, 0, 0)
DisplayShadow Boolean Indicates whether the shadow for this image should be displayed. False
RenderOptimized Boolean Indicates whether optimization must be used to render the image.Set this property to True if the CompositionImageFrame is very small compared to the actual image size. This will optimize memory usage. False
ShadowBlurRadius Double Specifies the Blur radius of the shadow. 0.0
ShadowColor Color Specifies the color of the shadow. Transparent
ShadowOffsetX Double Specifies the horizontal offset of the shadow. 0.0
ShadowOffsetY Double Specifies the vertical offset of the shadow. 0.0
ShadowOpacity Double Specifies the opacity of the shadow. 1
TransitionDuration Double Indicates the duration of the crossfade animation while transitioning from one image to another. 700ms

FluidBanner

FluidBanner is now a part of the CompositionProToolkit. It now internally uses CompositionSurfaceImage to host the images. It provides the following properties which can be used to customize the FluidBanner.

Dependency Property Type Description Default Value
AlignX AlignmentX Indicates how the image is positioned horizontally in the FluidBanner items. Center
AlignY AlignmentY Indicates how the image is positioned vertically in the FluidBanner items. Center
DecodeHeight int The height, in pixels, that the images are decoded to. (Optional) 0
DecodeWidth int The width, in pixels, that the images are decoded to. (Optional) 0
ItemBackground Color The background color of each item in the FluidBanner Black
ItemGap double The gap between adjacent items in the banner. 30
ItemsSource IEnumerable<Uri> The collection of Uris of images to be shown in the FluidBanner null
Padding Thickness The padding inside the FluidBanner Thickness(0)
Stretch Stretch Indicates how the image is resized to fill its allocated space within each FluidBanner item. Uniform

The latest source code is available in GitHub. The Nuget package is available here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s