Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DynamicRefreshRateSample #241

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Samples/Composition/DynamicRefreshRateTool/cpp-winui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.vs/

Debug/
Release/

x64/

packages/

Generated Files/

AppPackages/
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************

#include "pch.h"
#include "AnimationPage.h"
#if __has_include("AnimationPage.g.cpp")
#include "AnimationPage.g.cpp"
#endif

using namespace winrt;
using namespace Microsoft::UI::Xaml;
using namespace Microsoft::UI::Xaml::Controls::Primitives;

namespace winrt::DynamicRefreshRateTool::implementation
{
const float DEFAULT_ROTATION_SPEED = 3600;

AnimationPage::AnimationPage()
{
InitializeComponent();
myStoryBoard().Begin();
}

void AnimationPage::Button_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
auto buttonClicked = sender.try_as<ToggleButton>();

for (auto button : { Button1(), Button2(), Button3() }) {
if ((buttonClicked == button) != button.IsChecked().GetBoolean()) {
button.OnToggle();
}
}

if (Button1().IsChecked().GetBoolean()) {
RotationAnimation().To(DEFAULT_ROTATION_SPEED / 2);
}

if (Button2().IsChecked().GetBoolean()) {
RotationAnimation().To(DEFAULT_ROTATION_SPEED);
}

if (Button3().IsChecked().GetBoolean()) {
RotationAnimation().To(DEFAULT_ROTATION_SPEED * 2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************

#pragma once

#include "AnimationPage.g.h"

namespace winrt::DynamicRefreshRateTool::implementation
{
struct AnimationPage : AnimationPageT<AnimationPage>
{
AnimationPage();

void Button_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
};
}

namespace winrt::DynamicRefreshRateTool::factory_implementation
{
struct AnimationPage : AnimationPageT<AnimationPage, implementation::AnimationPage>
{
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************

namespace DynamicRefreshRateTool
{
[default_interface]
runtimeclass AnimationPage : Microsoft.UI.Xaml.Controls.Page
{
AnimationPage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<Page
x:Class="DynamicRefreshRateTool.AnimationPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DynamicRefreshRateTool"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">

<Grid Background="{ThemeResource ForegroundBrush}">
<Grid.Clip>
<RectangleGeometry Rect="0,0,9999,9999" />
</Grid.Clip>
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<Ellipse HorizontalAlignment="Center" Height="25" VerticalAlignment="Center" Width="25" Fill="{ThemeResource SystemAccentColorLight2}" Stroke="{ThemeResource SystemAccentColorDark2}">
<Ellipse.RenderTransform>
<CompositeTransform TranslateX="150"/>
</Ellipse.RenderTransform>
</Ellipse>

<Ellipse HorizontalAlignment="Center" Height="25" VerticalAlignment="Center" Width="25" Fill="{ThemeResource SystemAccentColorLight2}" Stroke="{ThemeResource SystemAccentColorDark2}">
<Ellipse.RenderTransform>
<CompositeTransform TranslateY="150"/>
</Ellipse.RenderTransform>
</Ellipse>

<Ellipse HorizontalAlignment="Center" Height="25" VerticalAlignment="Center" Width="25" Fill="{ThemeResource SystemAccentColorLight2}" Stroke="{ThemeResource SystemAccentColorDark2}">
<Ellipse.RenderTransform>
<CompositeTransform TranslateX="-150"/>
</Ellipse.RenderTransform>
</Ellipse>

<Ellipse HorizontalAlignment="Center" Height="25" VerticalAlignment="Center" Width="25" Fill="{ThemeResource SystemAccentColorLight2}" Stroke="{ThemeResource SystemAccentColorDark2}">
<Ellipse.RenderTransform>
<CompositeTransform TranslateY="-150"/>
</Ellipse.RenderTransform>
</Ellipse>

<Grid.RenderTransform>
<CompositeTransform x:Name="globalTrnsform"/>
</Grid.RenderTransform>
</Grid>

<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<ToggleButton Margin="10" Name="Button1" Click="Button_Click">x0.5 Speed</ToggleButton>
<ToggleButton Margin="10" Name="Button2" Click="Button_Click" IsChecked="True">x1 Speed</ToggleButton>
<ToggleButton Margin="10" Name="Button3" Click="Button_Click">x2 Speed</ToggleButton>
</StackPanel>


<Grid.Resources>
<Storyboard x:Name="myStoryBoard">
<DoubleAnimation Storyboard.TargetName="globalTrnsform"
Storyboard.TargetProperty="Rotation"
From="0.0"
To="3600.0"
Duration="0:0:6.66666"
RepeatBehavior="Forever"
x:Name="RotationAnimation"/>
</Storyboard>
</Grid.Resources>
</Grid>
</Page>
17 changes: 17 additions & 0 deletions Samples/Composition/DynamicRefreshRateTool/cpp-winui/App.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************

namespace DynamicRefreshRateTool
{
}
42 changes: 42 additions & 0 deletions Samples/Composition/DynamicRefreshRateTool/cpp-winui/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Application
x:Class="DynamicRefreshRateTool.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DynamicRefreshRateTool">
<Application.Resources>
<ResourceDictionary>

<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>

<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="BackgroundBrush" Color="#F0F0F0"/>
<SolidColorBrush x:Key="BackgroundBrush2" Color="#F6F6F6"/>
<SolidColorBrush x:Key="ForegroundBrush" Color="#FDFDFD"/>
<SolidColorBrush x:Key="BorderBrush" Color="#E5E5E5"/>
<SolidColorBrush x:Key="ChartMain" Color="{ThemeResource SystemAccentColor}"/>
<SolidColorBrush x:Key="ChartDash" Color="{ThemeResource SystemAccentColorLight1}"/>
<SolidColorBrush x:Key="ChartFill" Color="{ThemeResource SystemAccentColorLight3}"/>
<StaticResource x:Key="ControlExampleDisplayBrush" ResourceKey="SolidBackgroundFillColorBaseBrush" />

<SolidColorBrush x:Key="WindowCaptionBackground">#20A0A0A0</SolidColorBrush>
<SolidColorBrush x:Key="WindowCaptionBackgroundDisabled">#20A0A0A0</SolidColorBrush>
</ResourceDictionary>

<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="BackgroundBrush" Color="#202020"/>
<SolidColorBrush x:Key="BackgroundBrush2" Color="#262626"/>
<SolidColorBrush x:Key="ForegroundBrush" Color="#2B2B2B"/>
<SolidColorBrush x:Key="BorderBrush" Color="#1A1A1A"/>
<SolidColorBrush x:Key="ChartMain" Color="{ThemeResource SystemAccentColor}"/>
<SolidColorBrush x:Key="ChartDash" Color="{ThemeResource SystemAccentColorDark1}"/>
<SolidColorBrush x:Key="ChartFill" Color="{ThemeResource SystemAccentColorDark3}"/>
<StaticResource x:Key="ControlExampleDisplayBrush" ResourceKey="SolidBackgroundFillColorBaseBrush" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>

</Application.Resources>
</Application>
67 changes: 67 additions & 0 deletions Samples/Composition/DynamicRefreshRateTool/cpp-winui/App.xaml.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************

#include "pch.h"

#include "App.xaml.h"
#include "MainWindow.xaml.h"

using namespace winrt;
using namespace Windows::Foundation;
using namespace Microsoft::UI::Xaml;
using namespace Microsoft::UI::Xaml::Controls;
using namespace Microsoft::UI::Xaml::Navigation;
using namespace DynamicRefreshRateTool;
using namespace DynamicRefreshRateTool::implementation;
using namespace Windows::UI::ViewManagement;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
App::App()
{
InitializeComponent();

#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e)
{
if (IsDebuggerPresent())
{
auto errorMessage = e.Message();
__debugbreak();
}
});
#endif
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
void App::OnLaunched(LaunchActivatedEventArgs const&)
{
window = make<MainWindow>();

// Set default window size on startup
HWND hwnd{ nullptr };
window.try_as<IWindowNative>()->get_WindowHandle(&hwnd);
auto winid = winrt::Microsoft::UI::GetWindowIdFromWindow(hwnd);
auto appWindow = winrt::Microsoft::UI::Windowing::AppWindow::GetFromWindowId(winid);
double scale = GetDpiForWindow(hwnd) / 96.0;
appWindow.Resize({ static_cast<int>(800 * scale), static_cast<int>(600 * scale) });

window.Activate();
}
30 changes: 30 additions & 0 deletions Samples/Composition/DynamicRefreshRateTool/cpp-winui/App.xaml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED ?AS IS?, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************

#pragma once

#include "App.xaml.g.h"

namespace winrt::DynamicRefreshRateTool::implementation
{
struct App : AppT<App>
{
App();

void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);

private:
winrt::Microsoft::UI::Xaml::Window window{ nullptr };
};
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading