CompositionObject 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
시각적 트리 구조의 노드를 나타내는 컴퍼지션 API의 기본 클래스입니다.
컴퍼지션 개체는 컴퍼지션 API의 다른 모든 기능이 사용하고 빌드하는 시각적 트리 구조입니다. API를 사용하면 개발자가 각각 시각적 트리의 단일 노드를 나타내는 하나 이상의 Visual 개체를 정의하고 만들 수 있습니다.
UWP에 해당하는 WinUI 2 API: Microsoft.UI.Composition.CompositionObject(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조).
[WebHostHidden]
public ref class CompositionObject : IClosable
public ref class CompositionObject : IClosable
public ref class CompositionObject : IClosable, IAnimationObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[WebHostHidden]
class CompositionObject : IClosable
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 131072)]
class CompositionObject : IClosable
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 131072)]
class CompositionObject : IClosable, IAnimationObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class CompositionObject : System.IDisposable
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 131072)]
public class CompositionObject : System.IDisposable
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 131072)]
public class CompositionObject : System.IDisposable, IAnimationObject
Public Class CompositionObject
Implements IDisposable
Public Class CompositionObject
Implements IAnimationObject, IDisposable
- 상속
- 파생
- 특성
- 구현
Windows 요구 사항
| 디바이스 패밀리 |
Windows 10 (10.0.10240.0에서 도입되었습니다.)
|
| API contract |
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)
|
예제
이 샘플에서는 XAML, WWA 또는 DirectX를 사용하지 않고 컴퍼지션 API를 사용하여 자체 포함 앱을 만드는 방법을 보여줍니다. 샘플은 새 Compositor개체를 초기화한 다음 두 SpriteVisual 개체가 있는 장면 그래프를 만듭니다.
using System;
using System.Numerics;
using Windows.ApplicationModel.Core;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Core;
namespace HelloCompositionCs
{
public sealed class HelloComposition : IFrameworkView
{
//------------------------------------------------------------------------------
//
// HelloComposition.Initialize
//
// This method is called during startup to associate the IFrameworkView with the
// CoreApplicationView.
//
//------------------------------------------------------------------------------
void IFrameworkView.Initialize(CoreApplicationView view)
{
_view = view;
}
//------------------------------------------------------------------------------
//
// HelloComposition.SetWindow
//
// This method is called when the CoreApplication has created a new CoreWindow,
// allowing the application to configure the window and start producing content
// to display.
//
//------------------------------------------------------------------------------
void IFrameworkView.SetWindow(CoreWindow window)
{
_window = window;
InitNewComposition();
}
//------------------------------------------------------------------------------
//
// HelloComposition.Load
//
// This method is called when a specific page is being loaded in the
// application. It is not used for this application.
//
//------------------------------------------------------------------------------
void IFrameworkView.Load(string unused)
{
}
//------------------------------------------------------------------------------
//
// HelloComposition.Run
//
// This method is called by CoreApplication.Run to actually run the
// dispatcher's message pump.
//
//------------------------------------------------------------------------------
void IFrameworkView.Run()
{
_window.Activate();
_window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);
}
//------------------------------------------------------------------------------
//
// HelloComposition.Uninitialize
//
// This method is called during shutdown to disconnect the CoreApplicationView,
// and CoreWindow from the IFrameworkView.
//
//------------------------------------------------------------------------------
void IFrameworkView.Uninitialize()
{
_window = null;
_view = null;
}
//------------------------------------------------------------------------------
//
// HelloComposition.InitNewComposition
//
// This method is called by SetWindow, where we initialize Composition after
// the CoreWindow has been created.
//
//------------------------------------------------------------------------------
void InitNewComposition()
{
//
// Set up Windows.UI.Composition Compositor, root ContainerVisual, and associate with
// the CoreWindow.
//
_compositor = new Compositor();
_root = _compositor.CreateContainerVisual();
_view.CompositionRootVisual = _root;
//
// Create a simple scene.
//
var child1 = _compositor.CreateSpriteVisual();
child1.Offset = new Vector2(50.0f, 50.0f);
child1.Size = new Vector2(200, 200);
child1.Brush = _compositor.CreateColorBrush(Color.FromArgb(0xFF, 0x00, 0xCC, 0x00));
_root.Children.InsertAtTop(child1);
var child2 = _compositor.CreateSpriteVisual();
child2.Offset = new Vector2(50.0f, 50.0f);
child2.Size = new Vector2(200, 200);
child2.Brush = _compositor.CreateColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0xCC));
child1.Children.InsertAtTop(child2);
}
// CoreWindow / CoreApplicationView
private CoreWindow _window;
private CoreApplicationView _view;
// Windows.UI.Composition
private Compositor _compositor;
private ContainerVisual _root;
}
public sealed class HelloCompositionFactory : IFrameworkViewSource
{
//------------------------------------------------------------------------------
//
// HelloCompositionFactory.CreateView
//
// This method is called by CoreApplication to provide a new IFrameworkView for
// a CoreWindow that is being created.
//
//------------------------------------------------------------------------------
IFrameworkView IFrameworkViewSource.CreateView()
{
return new HelloComposition();
}
//------------------------------------------------------------------------------
//
// main
//
//------------------------------------------------------------------------------
static int Main(string[] args)
{
CoreApplication.Run(new HelloCompositionFactory());
return 0;
}
}
} // namespace HelloCompositionCs
이 샘플에서는 XAML, WWA 또는 DirectX를 사용하지 않고 불투명도를 변경하기 위해 간단한 시각적 개체 트리를 생성하고 안내하는 방법을 보여 줍니다. 이 샘플은 이전 샘플을 기반으로 자식 시각적 개체를 만들고, 추가하고, 속성을 변경하는 방법을 보여 줍니다.
이 시나리오에서는 Visuals의 시각적 트리 계층 구조가 빌드됩니다. Compositor가 만들어지면 관리할 수 있는 개체를 만드는 데 사용됩니다.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Numerics;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Core;
namespace VisualTreeCs
{
public sealed class VisualTree : IFrameworkView
{
//------------------------------------------------------------------------------
//
// VisualTree.Initialize
//
// This method is called during startup to associate the IFrameworkView with the
// CoreApplicationView.
//
//------------------------------------------------------------------------------
void IFrameworkView.Initialize(CoreApplicationView view)
{
_view = view;
_random = new Random();
}
//------------------------------------------------------------------------------
//
// VisualTree.SetWindow
//
// This method is called when the CoreApplication has created a new CoreWindow,
// allowing the application to configure the window and start producing content
// to display.
//
//------------------------------------------------------------------------------
void IFrameworkView.SetWindow(CoreWindow window)
{
_window = window;
InitNewComposition();
_window.PointerPressed += OnPointerPressed;
_window.PointerMoved += OnPointerMoved;
_window.PointerReleased += OnPointerReleased;
}
//------------------------------------------------------------------------------
//
// VisualTree.OnPointerPressed
//
// This method is called when the user touches the screen, taps it with a stylus
// or clicks the mouse.
//
//------------------------------------------------------------------------------
void OnPointerPressed(CoreWindow window, PointerEventArgs args)
{
Point position = args.CurrentPoint.Position;
//
// Walk our list of visuals to determine who, if anybody, was selected
//
foreach (var child in _root.Children)
{
//
// Did we hit this child?
//
Vector2 offset = child.Offset;
Vector2 size = child.Size;
if ((position.X >= offset.X) &&
(position.X < offset.X + size.X) &&
(position.Y >= offset.Y) &&
(position.Y < offset.Y + size.Y))
{
//
// This child was hit. Since the children are stored back to front,
// the last one hit is the front-most one so it wins
//
_currentVisual = child;
_offsetBias = new Vector2((float)(offset.X - position.X),
(float)(offset.Y - position.Y));
}
}
//
// If a visual was hit, bring it to the front of the Z order
//
if (_currentVisual != null)
{
ContainerVisual parent = _currentVisual.Parent as ContainerVisual;
parent.Children.Remove(_currentVisual);
parent.Children.InsertAtTop(_currentVisual);
}
}
//------------------------------------------------------------------------------
//
// VisualTree.OnPointerMoved
//
// This method is called when the user moves their finger, stylus or mouse with
// a button pressed over the screen.
//
//------------------------------------------------------------------------------
void OnPointerMoved(CoreWindow window, PointerEventArgs args)
{
//
// If a visual is selected, drag it with the pointer position and
// make it opaque while we drag it
//
if (_currentVisual != null)
{
Point position = args.CurrentPoint.Position;
_currentVisual.Opacity = 1.0f;
_currentVisual.Offset = new Vector2((float)(position.X + _offsetBias.X),
(float)(position.Y + _offsetBias.Y));
}
}
//------------------------------------------------------------------------------
//
// VisualTree.OnPointerReleased
//
// This method is called when the user lifts their finger or stylus from the
// screen, or lifts the mouse button.
//
//------------------------------------------------------------------------------
void OnPointerReleased(CoreWindow window, PointerEventArgs args)
{
//
// If a visual was selected, make it transparent again when it is
// released
//
if (_currentVisual != null)
{
_currentVisual.Opacity = 0.8f;
_currentVisual = null;
}
}
//------------------------------------------------------------------------------
//
// VisualTree.Load
//
// This method is called when a specific page is being loaded in the
// application. It is not used for this application.
//
//------------------------------------------------------------------------------
void IFrameworkView.Load(string unused)
{
}
//------------------------------------------------------------------------------
//
// VisualTree.Run
//
// This method is called by CoreApplication.Run to actually run the
// dispatcher's message pump.
//
//------------------------------------------------------------------------------
void IFrameworkView.Run()
{
_window.Activate();
_window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);
}
//------------------------------------------------------------------------------
//
// VisualTree.Uninitialize
//
// This method is called during shutdown to disconnect the CoreApplicationView,
// and CoreWindow from the IFrameworkView.
//
//------------------------------------------------------------------------------
void IFrameworkView.Uninitialize()
{
_window = null;
_view = null;
}
//------------------------------------------------------------------------------
//
// VisualTree.InitNewComposition
//
// This method is called by SetWindow, where we initialize Composition after
// the CoreWindow has been created.
//
//------------------------------------------------------------------------------
void InitNewComposition()
{
//
// Set up Windows.UI.Composition Compositor, root ContainerVisual, and associate with
// the CoreWindow.
//
_compositor = new Compositor();
_root = _compositor.CreateContainerVisual();
_view.CompositionRootVisual = _root;
//
// Create a few visuals for our window
//
for (int index = 0; index < 20; index++)
{
_root.Children.InsertAtTop(CreateChildElement());
}
}
//------------------------------------------------------------------------------
//
// VisualTree.CreateChildElement
//
// Creates a small sub-tree to represent a visible element in our application.
//
//------------------------------------------------------------------------------
Visual CreateChildElement()
{
//
// Each element consists of two visuals, which produce the appearance
// of a framed rectangle
//
var visual = _compositor.CreateSpriteVisual();
//
// Position this visual randomly within our window
//
visual.Offset = new Vector2((float)(_random.NextDouble() * 400), (float)(_random.NextDouble() * 400));
//
// The outer rectangle is always white
//
visual.Brush = _compositor.CreateColorBrush( Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF) );
visual.Size = new Vector2(100.0f, 100.0f);
//
// The inner rectangle is inset from the outer by three pixels all around
//
var child = _compositor.CreateSpriteVisual();
visual.Children.InsertAtTop(child);
child.Offset = new Vector2(3.0f, 3.0f);
child.Size = new Vector2(94.0f, 94.0f);
//
// Pick a random color for every rectangle
//
byte red = (byte)(0xFF * (0.2f + (_random.NextDouble() / 0.8f)));
byte green = (byte)(0xFF * (0.2f + (_random.NextDouble() / 0.8f)));
byte blue = (byte)(0xFF * (0.2f + (_random.NextDouble() / 0.8f)));
child.Brush = _compositor.CreateColorBrush( Color.FromArgb(0xFF, red, green, blue) );
//
// Make the subtree root visual partially transparent. This will cause each visual in the subtree
// to render partially transparent, since a visual's opacity is multiplied with its parent's
// opacity
//
visual.Opacity = 0.8f;
return visual;
}
// CoreWindow / CoreApplicationView
private CoreWindow _window;
private CoreApplicationView _view;
// Windows.UI.Composition
private Compositor _compositor;
private ContainerVisual _root;
private Visual _currentVisual;
private Vector2 _offsetBias;
// Helpers
private Random _random;
}
public sealed class VisualTreeFactory : IFrameworkViewSource
{
//------------------------------------------------------------------------------
//
// VisualTreeFactory.CreateView
//
// This method is called by CoreApplication to provide a new IFrameworkView for
// a CoreWindow that is being created.
//
//------------------------------------------------------------------------------
IFrameworkView IFrameworkViewSource.CreateView()
{
return new VisualTree();
}
//------------------------------------------------------------------------------
//
// main
//
//------------------------------------------------------------------------------
static int Main(string[] args)
{
CoreApplication.Run(new VisualTreeFactory());
return 0;
}
}
} // namespace VisualTreeCs
설명
개체는 개체를 Compositor 사용하여 만들어집니다. 컴퍼지션 개체는 컨테이너일 수 있거나 콘텐츠를 보관할 수 있습니다. API를 사용하면 계층 구조에 있는 특정 작업에 대해 명확한 시각적 개체 집합을 제공하여 쉽게 사용할 수 있습니다.
Visual – 기본 개체, 대부분의 속성이 여기에 있으며 다른 Visual 개체에 의해 상속됩니다.
ContainerVisual – 파생 Visual되며 자식을 만드는 기능을 추가합니다.
SpriteVisual – 파생 ContainerVisual되며 이미지, 효과 및 스왑 체인 형식의 콘텐츠를 포함합니다.
Compositor – 애플리케이션과 시스템 작성기 프로세스 간의 관계를 관리합니다. 애니메이션은 애니메이션 효과를 주는 컴퍼지션 개체(예: Visual)의 속성을 업데이트합니다. 애니메이션에는 두 가지 유형이 있습니다.
KeyFrameAnimation: 두 개 이상의 키 프레임이 있는 시간 기반 애니메이션. 이러한 프레임은 마커이므로 개발자는 지정된 시간에 애니메이션 값이 무엇인지 정의할 수 있습니다. 애니메이션이 키 프레임 간에 값을 보간(혼합)하는 방법을 지정하여 애니메이션을 미세 조정할 수도 있습니다. KeyFrameAnimation 에는 서로 다른 유형의 키 프레임 값을 지원하는 여러 서브클래스가 있습니다.
ExpressionAnimation: 수학적 식을 사용하여 각 프레임에 애니메이션 값을 계산하는 방법을 지정하는 애니메이션입니다. 식은 컴퍼지션 개체의 속성을 참조할 수 있습니다. ExpressionAnimations는 시간 기반이 아니며 각 프레임(필요한 경우)으로 처리됩니다.
기본 시각적 개체
기본 시각적 개체(예: SpriteVisual)는 화면의 시각적 콘텐츠 및 해당 콘텐츠에 적용될 렌더링 옵션을 설명합니다.
효과
이미지 또는 시각적 개체 트리와 같은 원본 콘텐츠에 동적 픽셀 변경을 발생시키기 위해 효과를 시각적 트리에 연결할 수 있습니다.
효과는 소멸과 같은 간단한 작업, 흐림과 같은 더 복잡한 작업 또는 교차 페이드와 같은 매우 복잡한 A B 혼합 작업일 수 있습니다.
효과 만들기 및 사용에 대한 자세한 내용은 설명 섹션 CompositionEffectBrush 을 참조하세요.
버전 기록
| Windows 버전 | SDK 버전 | 추가된 값 |
|---|---|---|
| 1607 | 14393 | 의견 |
| 1607 | 14393 | ImplicitAnimations |
| 1607 | 14393 | StartAnimationGroup |
| 1607 | 14393 | StopAnimationGroup |
| 1709 | 16299 | DispatcherQueue |
| 1803 | 17134 | TryGetAnimationController |
| 1809 | 17763 | PopulatePropertyInfo |
| 1809 | 17763 | StartAnimationGroupWithIAnimationObject |
| 1809 | 17763 | StartAnimationWithIAnimationObject |
속성
| Comment |
CompositionObject와 연결할 문자열입니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Composition.CompositionObject.Comment(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
| Compositor |
Compositor 이 CompositionObject값을 만드는 데 사용됩니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Composition.CompositionObject.Compositor(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
| Dispatcher |
에 대한 디스패처입니다 CompositionObject. |
| DispatcherQueue |
DispatcherQueue CompostionObject에 대한 값을 가져옵니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Composition.CompositionObject.DispatcherQueue(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
| ImplicitAnimations |
이 개체에 연결된 암시적 애니메이션의 컬렉션입니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Composition.CompositionObject.ImplicitAnimations(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
| Properties |
에 연결된 CompositionObject속성의 컬렉션입니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Composition.CompositionObject.Properties(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
메서드
적용 대상
추가 정보
피드백
다음에 대한 사용자 의견 제출 및 보기