@@ -22,10 +22,10 @@ namespace winrt::DrawingIslandComponents::implementation
22
22
// - When the ContentIsland is destroyed, ContentIsland.AppData will call IClosable.Close
23
23
// on this instance to break cycles and clean up expensive resources.
24
24
25
- m_background. Visual = m_output.Compositor .CreateSpriteVisual ();
26
- m_background. Visual .RelativeSizeAdjustment (float2 ( 1 .0f , 1 .0f ) );
25
+ m_output. RootVisual = m_output.Compositor .CreateContainerVisual ();
26
+ m_output. RootVisual .RelativeSizeAdjustment ({ 1 .0f , 1 .0f } );
27
27
28
- m_island = winrt::ContentIsland::Create (m_background. Visual );
28
+ m_island = winrt::ContentIsland::Create (m_output. RootVisual );
29
29
m_island.AppData (get_strong ().as <winrt::IInspectable>());
30
30
31
31
Output_Initialize ();
@@ -61,6 +61,8 @@ namespace winrt::DrawingIslandComponents::implementation
61
61
void
62
62
DrawingIsland::Close ()
63
63
{
64
+ m_output.RootVisual = nullptr ;
65
+
64
66
m_input.KeyboardSource = nullptr ;
65
67
m_input.PretranslateSource = nullptr ;
66
68
m_input.PointerSource = nullptr ;
@@ -76,30 +78,18 @@ namespace winrt::DrawingIslandComponents::implementation
76
78
m_items.Items .clear ();
77
79
m_items.SelectedItem = nullptr ;
78
80
79
- // TODO: Enable Mica on Win 11
80
- #if FALSE
81
- // Destroy SystemBackdropController objects.
82
- if (m_backdropController != nullptr )
81
+ if (nullptr != m_background.BackdropController )
83
82
{
84
- if (m_backdropConfiguration != nullptr )
85
- {
86
- // m_backdropConfiguration is only initialized for the DrawingIsland that owns the
87
- // SystemBackdropController.
88
-
89
- m_backdropController.Close ();
90
- m_backdropController = nullptr ;
91
- m_backdropConfiguration = nullptr ;
92
- }
93
- else
94
- {
95
- // We're closing a DrawingIsland in a popup, not the owner DrawingIsland of the
96
- // SystemBackdropController. Therefore, remove the current target from the
97
- // Controller.
83
+ // Clean up our SystemBackdropController.
84
+ m_background.BackdropController .RemoveAllSystemBackdropTargets ();
85
+ m_background.BackdropController .Close ();
86
+ m_background.BackdropController = nullptr ;
87
+ }
98
88
99
- m_backdropController.RemoveSystemBackdropTarget (m_backdropTarget);
100
- }
89
+ if (nullptr != m_background.BackdropConfiguration )
90
+ {
91
+ m_background.BackdropConfiguration = nullptr ;
101
92
}
102
- #endif
103
93
104
94
// Make sure automation is destroyed.
105
95
for (auto & automationPeer : m_uia.AutomationPeers )
@@ -132,6 +122,17 @@ namespace winrt::DrawingIslandComponents::implementation
132
122
}
133
123
134
124
125
+ void DrawingIsland::EnableBackgroundTransparency (
126
+ bool value)
127
+ {
128
+ if (value != m_background.BackdropEnabled )
129
+ {
130
+ m_background.BackdropEnabled = value;
131
+ Output_UpdateSystemBackdrop ();
132
+ }
133
+ }
134
+
135
+
135
136
IFACEMETHODIMP
136
137
DrawingIsland::OnDirectMessage (
137
138
IInputPreTranslateKeyboardSourceInterop* /* source*/ ,
@@ -435,11 +436,19 @@ namespace winrt::DrawingIslandComponents::implementation
435
436
switch (activationListener.State ())
436
437
{
437
438
case winrt::InputActivationState::Activated:
438
- m_background.Visual .Opacity (1 .0f );
439
+ m_output.RootVisual .Opacity (1 .0f );
440
+ if (nullptr != m_background.BackdropConfiguration )
441
+ {
442
+ m_background.BackdropConfiguration .IsInputActive (true );
443
+ }
439
444
break ;
440
445
441
446
default :
442
- m_background.Visual .Opacity (m_background.Opacity );
447
+ m_output.RootVisual .Opacity (m_output.Opacity );
448
+ if (nullptr != m_background.BackdropConfiguration )
449
+ {
450
+ m_background.BackdropConfiguration .IsInputActive (false );
451
+ }
443
452
break ;
444
453
}
445
454
});
@@ -753,13 +762,13 @@ namespace winrt::DrawingIslandComponents::implementation
753
762
// also mirrored. The text will need another RelativeOffsetAdjustment and Scale to
754
763
// return to the normal space.
755
764
756
- m_background. Visual .RelativeOffsetAdjustment (winrt::float3 (1 , 0 , 0 ));
757
- m_background. Visual .Scale (winrt::float3 (-1 , 1 , 1 ));
765
+ m_output. RootVisual .RelativeOffsetAdjustment (winrt::float3 (1 , 0 , 0 ));
766
+ m_output. RootVisual .Scale (winrt::float3 (-1 , 1 , 1 ));
758
767
}
759
768
else
760
769
{
761
- m_background. Visual .RelativeOffsetAdjustment (winrt::float3 (0 , 0 , 0 ));
762
- m_background. Visual .Scale (winrt::float3 (1 , 1 , 1 ));
770
+ m_output. RootVisual .RelativeOffsetAdjustment (winrt::float3 (0 , 0 , 0 ));
771
+ m_output. RootVisual .Scale (winrt::float3 (1 , 1 , 1 ));
763
772
}
764
773
m_prevState.LayoutDirection = m_island.LayoutDirection ();
765
774
}
@@ -768,6 +777,25 @@ namespace winrt::DrawingIslandComponents::implementation
768
777
void
769
778
DrawingIsland::Output_Initialize ()
770
779
{
780
+ // Create the background visual.
781
+ m_background.Visual = m_output.Compositor .CreateSpriteVisual ();
782
+ m_background.Visual .RelativeSizeAdjustment ({ 1 .0f , 1 .0f });
783
+
784
+ m_background.BrushDefault = m_output.Compositor .CreateColorBrush (
785
+ winrt::Color{ 0xFF , 0x20 , 0x20 , 0x20 });
786
+
787
+ m_background.BrushA = m_output.Compositor .CreateColorBrush (
788
+ winrt::Color{ 0xFF , 0x99 , 0x20 , 0x20 });
789
+
790
+ m_background.BrushB = m_output.Compositor .CreateColorBrush (
791
+ winrt::Color{ 0xFF , 0x20 , 0x99 , 0x20 });
792
+
793
+ m_background.BrushC = m_output.Compositor .CreateColorBrush (
794
+ winrt::Color{ 0xFF , 0x20 , 0x20 , 0x99 });
795
+
796
+ m_background.Visual .Brush (m_background.BrushDefault );
797
+ m_output.RootVisual .Children ().InsertAtTop (m_background.Visual );
798
+
771
799
for (int i = 0 ; i < _countof (m_output.ColorBrushes ); i++)
772
800
{
773
801
m_output.ColorBrushes [i] = m_output.Compositor .CreateColorBrush (s_colors[i]);
@@ -780,13 +808,13 @@ namespace winrt::DrawingIslandComponents::implementation
780
808
781
809
winrt::ContainerVisual drawingVisualsRoot = m_output.Compositor .CreateContainerVisual ();
782
810
m_items.Visuals = drawingVisualsRoot.Children ();
783
- m_background. Visual .Children ().InsertAtTop (drawingVisualsRoot);
811
+ m_output. RootVisual .Children ().InsertAtTop (drawingVisualsRoot);
784
812
785
813
m_items.CurrentColorVisual = m_output.Compositor .CreateSpriteVisual ();
786
814
m_items.CurrentColorVisual .Offset ({0 .0f , 0 .0f , 0 .0f });
787
- m_background. Visual .Children ().InsertAtTop (m_items.CurrentColorVisual );
815
+ m_output. RootVisual .Children ().InsertAtTop (m_items.CurrentColorVisual );
788
816
789
- SystemBackdrop_EvaluateUsage ();
817
+ Output_UpdateSystemBackdrop ();
790
818
791
819
Output_UpdateCurrentColorVisual ();
792
820
}
@@ -844,99 +872,53 @@ namespace winrt::DrawingIslandComponents::implementation
844
872
}
845
873
846
874
847
- // TODO: Enable Mica on Win 11
848
- #if FALSE
849
875
void
850
- DrawingIsland::SystemBackdrop_Initialize ()
876
+ DrawingIsland::Output_UpdateSystemBackdrop ()
851
877
{
852
- // Don't initilize system backdrop if we haven't been configured for it.
853
- if (!m_useSystemBackdrop) return ;
854
-
855
- if (m_backdropController == nullptr )
878
+ if (m_background.BackdropEnabled && nullptr == m_background.BackdropController )
856
879
{
857
- m_backdropConfiguration = winrt::SystemBackdropConfiguration ();
858
- m_backdropController = winrt::DesktopAcrylicController ();
859
- m_backdropController. SetSystemBackdropConfiguration (m_backdropConfiguration );
880
+ // Reduce the opacity of the background color visual so that we can see
881
+ // the Mica/DesktopAcrylic behind it.
882
+ m_background. Visual . Opacity ( 0 . 1f );
860
883
861
- auto activationListener = winrt::InputActivationListener::GetForIsland (m_island);
862
- (void )activationListener.InputActivationChanged (
863
- [this , activationListener](
864
- winrt::InputActivationListener const &,
865
- winrt::InputActivationListenerActivationChangedEventArgs const &)
884
+ // Create a new SystemBackdropConfiguration if we do not already have one.
885
+ if (nullptr == m_background.BackdropConfiguration )
866
886
{
867
- switch (activationListener.State ())
868
- {
869
- case winrt::InputActivationState::Activated:
870
- m_backdropConfiguration.IsInputActive (true );
871
- break ;
872
-
873
- default :
874
- m_backdropConfiguration.IsInputActive (false );
875
- break ;
876
- }
877
- });
878
- }
879
-
880
-
881
- // If we are the main content, we don't want to add custom clips or offsets to our
882
- // backdrop, so we can pass the ContentIsland as the target to the BackdropController.
883
- // This will by default fill the entire ContentIsland backdrop surface.
884
-
885
- m_backdropTarget = m_island;
886
-
887
- m_backdropController.AddSystemBackdropTarget (m_backdropTarget);
888
- }
889
- #endif
887
+ m_background.BackdropConfiguration = winrt::SystemBackdropConfiguration ();
888
+ }
890
889
890
+ // Decide between Mica and DesktopAcrylic.
891
+ if (winrt::MicaController::IsSupported ())
892
+ {
893
+ m_background.BackdropController = winrt::MicaController ();
894
+
895
+ }
896
+ else
897
+ {
898
+ m_background.BackdropController = winrt::DesktopAcrylicController ();
899
+ }
891
900
892
- void
893
- DrawingIsland::SystemBackdrop_EvaluateUsage ()
894
- {
895
- BYTE backgroundBrushOpacity = 0xFF ;
901
+ // Link the SystemBackdropConfiguration to our SystemBackdropController.
902
+ m_background.BackdropController .SetSystemBackdropConfiguration (
903
+ m_background.BackdropConfiguration );
896
904
897
- // TODO: Enable Mica on Win 11
898
- #if FALSE
899
- // If we use system backdrops, it will be behind our background visual. Make sure we can
900
- // see through the background visual to reveal the system backdrop.
901
- // reveal the system backdrop underneath.
902
- if (m_useSystemBackdrop)
903
- {
904
- backgroundBrushOpacity = 0x30 ;
905
+ // Add our island as the target.
906
+ m_background.BackdropController .AddSystemBackdropTarget (m_island);
905
907
}
906
- #endif
907
-
908
- // Create the background parent Visual that the individual square will be added into.
909
- m_background.BrushDefault = m_output.Compositor .CreateColorBrush (
910
- winrt::Color{ backgroundBrushOpacity, 0x20 , 0x20 , 0x20 });
911
-
912
- m_background.BrushA = m_output.Compositor .CreateColorBrush (
913
- winrt::Color{ backgroundBrushOpacity, 0x99 , 0x20 , 0x20 });
914
-
915
- m_background.BrushB = m_output.Compositor .CreateColorBrush (
916
- winrt::Color{ backgroundBrushOpacity, 0x20 , 0x99 , 0x20 });
917
-
918
- m_background.BrushC = m_output.Compositor .CreateColorBrush (
919
- winrt::Color{ backgroundBrushOpacity, 0x20 , 0x20 , 0x99 });
920
-
921
- m_background.Visual .Brush (m_background.BrushDefault );
922
- }
923
-
924
-
925
- // TODO: Enable Mica on Win 11
926
- #if FALSE
927
- void
928
- DrawingIsland::UseSystemBackdrop (
929
- boolean value)
930
- {
931
- if (m_useSystemBackdrop != value)
908
+ else
932
909
{
933
- m_useSystemBackdrop = value;
910
+ // Reset the background opacity to 1.0
911
+ m_background.Visual .Opacity (1 .0f );
934
912
935
- SystemBackdrop_EvaluateUsage ();
913
+ if (nullptr != m_background.BackdropController )
914
+ {
915
+ // Clean up our SystemBackdropController.
916
+ m_background.BackdropController .RemoveAllSystemBackdropTargets ();
917
+ m_background.BackdropController .Close ();
918
+ m_background.BackdropController = nullptr ;
919
+ }
936
920
}
937
921
}
938
- #endif
939
-
940
922
941
923
void
942
924
DrawingIsland::Environment_Initialize ()
0 commit comments