// TODO: To add this sample's url when it is available. //public override string SampleCodeUri { get { return ""; } } private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { double paramHeight; double paramWidth; GetParamSize(out paramWidth, out paramHeight); LeftWallGrid.Width = 0.02 * paramWidth; LeftWallGrid.Height = paramHeight; RightWallGrid.Width = paramWidth; RightWallGrid.Height = paramHeight; _roomVisual = ElementCompositionPreview.GetElementVisual(RoomGrid); _compositor = _roomVisual.Compositor; float scale = GetFullScale(); if (_roomVisual != null) { _roomVisual.Scale = new Vector3(scale, scale, 1.0f); } await LoadImages(); float flAngle = (float)(Math.PI / -64.0f); float perspectiveDistance = (float)RoomGrid.Width * 3; Vector3 centerPt = new Vector3( (float)(RoomGrid.Width * 0.5f), (float)(RoomGrid.Height * 0.5f), 0); Matrix4x4 transformMatrix = Matrix4x4.CreateTranslation(-centerPt) * Matrix4x4.CreateRotationY(flAngle) * new Matrix4x4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -1 / perspectiveDistance, 0, 0, 0, 1) * Matrix4x4.CreateTranslation(centerPt); Vector3 offset = new Vector3(transformMatrix.M41 - 8, transformMatrix.M42 - 8, 0); _roomVisual.TransformMatrix = transformMatrix * Matrix4x4.CreateTranslation(-offset); // Create three categories of panels, each panel has three contents. // Each category has a layer visual which contains three layer visual from its contents. // Effect on a category and all its sub tree contents works when hit-testing a category. // And effect on a content works when hit-testing a content. Visual rightWallVisual = ElementCompositionPreview.GetElementVisual(RightWallGrid); flAngle = (float)(Math.PI / 64.0f); rightWallVisual.TransformMatrix = Matrix4x4.CreateRotationY(flAngle); double sectionGridWidthRatio = 1 / 3.0; for (int i = 0; i < _fColumnCount; ++i) { _sectionContentParams[i] = new EffectParameters[_fColumnCount]; } EffectType[] sectionEffectTypes = { EffectType.Saturation, EffectType.HueRotation, EffectType.Sepia }; float[] sectionPropertyValues = { 1.0f, 0.0f, 0.0f }; Color[] sectionColors = { Colors.Linen, Colors.Linen, Colors.Linen }; double sectionWidthRatio = 0.9; double delatSectionWidth = RightWallGrid.Width * sectionGridWidthRatio * (1 - sectionWidthRatio) * 0.5; for (int j = 0; j < _fColumnCount; ++j) { Windows.UI.Xaml.Controls.Grid section = (Windows.UI.Xaml.Controls.Grid)RightWallGrid.Children[j]; section.Width = sectionGridWidthRatio * RightWallGrid.Width * sectionWidthRatio; section.Height = RightWallGrid.Height * 0.9; section.Margin = new Windows.UI.Xaml.Thickness( (1.5 - j * 0.5) * delatSectionWidth, 0.05 * paramHeight, (0.5 + j * 0.5) * delatSectionWidth, 0.05 * paramHeight); double contentGridHeightRatio = 1 / 3.0; double contentWidthRatio = 0.8; double contentHeightRatio = 0.8; double deltaWidth = (1 - contentWidthRatio) * 0.5 * section.Width; double deltaHeight = contentGridHeightRatio * section.Height * (1.0 - contentHeightRatio) * 0.5; _sectionParams[j] = new EffectParameters(this, sectionEffectTypes[j], sectionPropertyValues[j], 1.1f); _sectionParams[j].InitializeEffectBrush(); Vector2 sectionSize = new Vector2((float)section.Width, (float)section.Height); _sectionParams[j].VisualInstance = AddLayerVisual( _sectionParams[j].EffectInstance, sectionSize, RightWallGrid.Children[j]); _sectionParams[j].UpdatePropertyValue(); _sectionParams[j].VisualInstance.CenterPoint = new Vector3(sectionSize.X * 0.5f, sectionSize.Y * 0.5f, 0); AddColorSpriteVisual(sectionColors[j], _sectionParams[j].VisualInstance.Size, _sectionParams[j].VisualInstance); for (int i = 0; i < _fColumnCount; ++i) { Windows.UI.Xaml.Shapes.Rectangle content = (Windows.UI.Xaml.Shapes.Rectangle)section.Children[i]; content.Width = section.Width * contentWidthRatio; content.Height = contentGridHeightRatio * section.Height * contentHeightRatio; content.Margin = new Windows.UI.Xaml.Thickness(deltaWidth, (1.5 - i * 0.5) * deltaHeight, deltaWidth, (0.5 + i * 0.5) * deltaHeight); _sectionContentParams[i][j] = new EffectParameters(this, sectionEffectTypes[j], sectionPropertyValues[j]); _sectionContentParams[i][j].InitializeEffectBrush(); Vector2 contentASize = new Vector2((float)content.Width, (float)content.Height); _sectionContentParams[i][j].VisualInstance = AddLayerVisual( _sectionContentParams[i][j].EffectInstance, contentASize, new Vector3((float)section.Width * (0.5f - (float)contentWidthRatio * 0.5f), (float)content.Height * i + 1.5f * (float)deltaHeight * (i + 1), 0), _sectionParams[j].VisualInstance); _sectionContentParams[i][j].UpdatePropertyValue(); _sectionContentParams[i][j].VisualInstance.CenterPoint = new Vector3(contentASize.X * 0.5f, contentASize.Y * 0.5f, 0); AddImageSpriteVisual(_imageSurfaces[j * _fColumnCount + i], _sectionContentParams[i][j].VisualInstance.Size, _sectionContentParams[i][j].VisualInstance); } } for (int j = 0; j < RightWallGrid.Children.Count; ++j) { Windows.UI.Xaml.Controls.Grid section = (Windows.UI.Xaml.Controls.Grid)RightWallGrid.Children[j]; EffectParameters sectionPara = _sectionParams[j]; section.PointerEntered += (s, v) => { sectionPara.OnPointerEntered(); }; section.PointerExited += (s, v) => { sectionPara.OnPointerExited(); }; for (int i = 0; i < section.Children.Count; ++i) { Windows.UI.Xaml.Shapes.Rectangle content = (Windows.UI.Xaml.Shapes.Rectangle)section.Children[i]; EffectParameters contentPara = _sectionContentParams[i][j]; content.PointerEntered += (s, v) => { sectionPara.OnPointerExited(); contentPara.OnPointerEntered(); }; content.PointerExited += (s, v) => { sectionPara.OnPointerEntered(); contentPara.OnPointerExited(); }; content.PointerMoved += (s, V) => { sectionPara.OnPointerExited(); }; } } }
// TODO: To add this sample's url when it is available. //public override string SampleCodeUri { get { return ""; } } private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { double paramHeight; double paramWidth; GetParamSize(out paramWidth, out paramHeight); LeftWallGrid.Width = 0.02 * paramWidth; LeftWallGrid.Height = paramHeight; RightWallGrid.Width = paramWidth; RightWallGrid.Height = paramHeight; _roomVisual = ElementCompositionPreview.GetElementVisual(RoomGrid); _compositor = _roomVisual.Compositor; float scale = GetFullScale(); if (_roomVisual != null) { _roomVisual.Scale = new Vector3(scale, scale, 1.0f); } await LoadImages(); float flAngle = (float)(Math.PI / -64.0f); float perspectiveDistance = (float)RoomGrid.Width * 3; Vector3 centerPt = new Vector3( (float)(RoomGrid.Width * 0.5f), (float)(RoomGrid.Height * 0.5f), 0); Matrix4x4 transformMatrix = Matrix4x4.CreateTranslation(-centerPt) * Matrix4x4.CreateRotationY(flAngle) * new Matrix4x4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -1 / perspectiveDistance, 0, 0, 0, 1) * Matrix4x4.CreateTranslation(centerPt); Vector3 offset = new Vector3(transformMatrix.M41 - 8, transformMatrix.M42 - 8, 0); _roomVisual.TransformMatrix = transformMatrix * Matrix4x4.CreateTranslation(-offset); // Create three categories of panels, each panel has three contents. // Each category has a layer visual which contains three layer visual from its contents. // Effect on a category and all its sub tree contents works when hit-testing a category. // And effect on a content works when hit-testing a content. Visual rightWallVisual = ElementCompositionPreview.GetElementVisual(RightWallGrid); flAngle = (float)(Math.PI / 64.0f); rightWallVisual.TransformMatrix = Matrix4x4.CreateRotationY(flAngle); double sectionGridWidthRatio = 1 / 3.0; for (int i = 0; i < _fColumnCount; ++i) { _sectionContentParams[i] = new EffectParameters[_fColumnCount]; } EffectType[] sectionEffectTypes = { EffectType.Saturation, EffectType.HueRotation, EffectType.Sepia }; float[] sectionPropertyValues = { 1.0f, 0.0f, 0.0f }; Color[] sectionColors = { Colors.Linen, Colors.Linen, Colors.Linen }; double sectionWidthRatio = 0.9; double delatSectionWidth = RightWallGrid.Width * sectionGridWidthRatio * (1 - sectionWidthRatio) * 0.5; for (int j = 0; j < _fColumnCount; ++j) { Windows.UI.Xaml.Controls.Grid section = (Windows.UI.Xaml.Controls.Grid)RightWallGrid.Children[j]; section.Width = sectionGridWidthRatio * RightWallGrid.Width * sectionWidthRatio; section.Height = RightWallGrid.Height * 0.9; section.Margin = new Windows.UI.Xaml.Thickness( (1.5 - j * 0.5) * delatSectionWidth, 0.05 * paramHeight, (0.5 + j * 0.5) * delatSectionWidth, 0.05 * paramHeight); double contentGridHeightRatio = 1 / 3.0; double contentWidthRatio = 0.8; double contentHeightRatio = 0.8; double deltaWidth = (1 - contentWidthRatio) * 0.5 * section.Width; double deltaHeight = contentGridHeightRatio * section.Height * (1.0 - contentHeightRatio) * 0.5; _sectionParams[j] = new EffectParameters(this, sectionEffectTypes[j], sectionPropertyValues[j], 1.1f); _sectionParams[j].InitializeEffectBrush(); Vector2 sectionSize = new Vector2((float)section.Width, (float)section.Height); _sectionParams[j].VisualInstance = AddLayerVisual( _sectionParams[j].EffectInstance, sectionSize, RightWallGrid.Children[j]); _sectionParams[j].UpdatePropertyValue(); _sectionParams[j].VisualInstance.CenterPoint = new Vector3(sectionSize.X * 0.5f, sectionSize.Y * 0.5f, 0); AddColorSpriteVisual(sectionColors[j], _sectionParams[j].VisualInstance.Size, _sectionParams[j].VisualInstance); for (int i = 0; i < _fColumnCount; ++i) { Windows.UI.Xaml.Shapes.Rectangle content = (Windows.UI.Xaml.Shapes.Rectangle)section.Children[i]; content.Width = section.Width * contentWidthRatio; content.Height = contentGridHeightRatio * section.Height * contentHeightRatio; content.Margin = new Windows.UI.Xaml.Thickness(deltaWidth, (1.5 - i * 0.5) * deltaHeight, deltaWidth, (0.5 + i * 0.5) * deltaHeight); _sectionContentParams[i][j] = new EffectParameters(this, sectionEffectTypes[j], sectionPropertyValues[j]); _sectionContentParams[i][j].InitializeEffectBrush(); Vector2 contentASize = new Vector2((float)content.Width, (float)content.Height); _sectionContentParams[i][j].VisualInstance = AddLayerVisual( _sectionContentParams[i][j].EffectInstance, contentASize, new Vector3((float)section.Width * (0.5f - (float)contentWidthRatio * 0.5f), (float)content.Height * i + 1.5f * (float)deltaHeight * (i + 1), 0), _sectionParams[j].VisualInstance); _sectionContentParams[i][j].UpdatePropertyValue(); _sectionContentParams[i][j].VisualInstance.CenterPoint = new Vector3(contentASize.X * 0.5f, contentASize.Y * 0.5f, 0); AddImageSpriteVisual(_imageSurfaces[j * _fColumnCount + i].Brush, _sectionContentParams[i][j].VisualInstance.Size, _sectionContentParams[i][j].VisualInstance); } } for (int j = 0; j < RightWallGrid.Children.Count; ++j) { Windows.UI.Xaml.Controls.Grid section = (Windows.UI.Xaml.Controls.Grid)RightWallGrid.Children[j]; EffectParameters sectionPara = _sectionParams[j]; section.PointerEntered += (s, v) => { sectionPara.OnPointerEntered(); }; section.PointerExited += (s, v) => { sectionPara.OnPointerExited(); }; for (int i = 0; i < section.Children.Count; ++i) { Windows.UI.Xaml.Shapes.Rectangle content = (Windows.UI.Xaml.Shapes.Rectangle)section.Children[i]; EffectParameters contentPara = _sectionContentParams[i][j]; content.PointerEntered += (s, v) => { sectionPara.OnPointerExited(); contentPara.OnPointerEntered(); }; content.PointerExited += (s, v) => { sectionPara.OnPointerEntered(); contentPara.OnPointerExited(); }; content.PointerMoved += (s, V) => { sectionPara.OnPointerExited(); }; } } }