Use path instead of glyph for active tracing (#910)

* Use path instead of glyph
This commit is contained in:
Eric Wong 2020-01-10 16:42:55 -08:00 committed by GitHub
parent 240792a775
commit c7c9bf0513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 17 deletions

View File

@ -312,6 +312,11 @@
<Setter Property="Background" Value="{ThemeResource SystemControlAcrylicElementBrush}"/> <Setter Property="Background" Value="{ThemeResource SystemControlAcrylicElementBrush}"/>
</Style> </Style>
<SolidColorBrush x:Key="SwitchToggleBackground" Color="#40000000"/> <SolidColorBrush x:Key="SwitchToggleBackground" Color="#40000000"/>
<Style x:Key="TracePointerPathStyle" TargetType="Path">
<Setter Property="Fill" Value="White"/>
<Setter Property="Stroke" Value="Black"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
</ResourceDictionary> </ResourceDictionary>
<ResourceDictionary x:Key="Light"> <ResourceDictionary x:Key="Light">
<Style x:Key="ThemedSwitchModeToggleButtonStyle" <Style x:Key="ThemedSwitchModeToggleButtonStyle"
@ -338,6 +343,11 @@
<Setter Property="CornerRadius" Value="4"/> <Setter Property="CornerRadius" Value="4"/>
<Setter Property="Background" Value="{ThemeResource SystemControlAcrylicElementBrush}"/> <Setter Property="Background" Value="{ThemeResource SystemControlAcrylicElementBrush}"/>
</Style> </Style>
<Style x:Key="TracePointerPathStyle" TargetType="Path">
<Setter Property="Fill" Value="White"/>
<Setter Property="Stroke" Value="Black"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
<SolidColorBrush x:Key="SwitchToggleBackground" Color="#60ffffff"/> <SolidColorBrush x:Key="SwitchToggleBackground" Color="#60ffffff"/>
</ResourceDictionary> </ResourceDictionary>
<ResourceDictionary x:Key="HighContrast"> <ResourceDictionary x:Key="HighContrast">
@ -358,6 +368,11 @@
<Setter Property="Background" Value="{ThemeResource ToolTipBackground}"/> <Setter Property="Background" Value="{ThemeResource ToolTipBackground}"/>
</Style> </Style>
<SolidColorBrush x:Key="SwitchToggleBackground" Color="{ThemeResource SystemColorWindowColor}"/> <SolidColorBrush x:Key="SwitchToggleBackground" Color="{ThemeResource SystemColorWindowColor}"/>
<Style x:Key="TracePointerPathStyle" TargetType="Path">
<Setter Property="Fill" Value="{ThemeResource SystemColorHighlightTextColor}"/>
<Setter Property="Stroke" Value="{ThemeResource SystemColorWindowTextColor}"/>
<Setter Property="StrokeThickness" Value="2"/>
</Style>
</ResourceDictionary> </ResourceDictionary>
</ResourceDictionary.ThemeDictionaries> </ResourceDictionary.ThemeDictionaries>
</ResourceDictionary> </ResourceDictionary>
@ -413,6 +428,7 @@
<Grid x:Name="LeftGrid" <Grid x:Name="LeftGrid"
Grid.Row="1" Grid.Row="1"
Padding="0,4,0,0" Padding="0,4,0,0"
SizeChanged="LeftGrid_SizeChanged"
Visibility="{x:Bind ShouldDisplayPanel(IsSmallState, SwitchModeToggleButton.IsOn, x:True), Mode=OneWay}"> Visibility="{x:Bind ShouldDisplayPanel(IsSmallState, SwitchModeToggleButton.IsOn, x:True), Mode=OneWay}">
<Grid.Resources> <Grid.Resources>
<ResourceDictionary> <ResourceDictionary>
@ -507,18 +523,17 @@
</Button> </Button>
</StackPanel> </StackPanel>
</Border> </Border>
<Border x:Name="TracePointer" <Canvas>
Width="16" <Grid x:Name="TracePointer" Visibility="Collapsed">
Height="18" <Border x:Name="CursorShadow"/>
Margin="48,50,0,0" <Path x:Name="CursorPath"
HorizontalAlignment="Left" Width="18"
VerticalAlignment="Top" Height="18"
Visibility="Collapsed"> Style="{ThemeResource TracePointerPathStyle}"
<FontIcon Foreground="Red" Data="M0 0 l1371 1371 H538 l-538 538 Z"
FontFamily="{StaticResource CalculatorFontFamily}" Stretch="Uniform"/>
FontSize="18" </Grid>
Glyph="&#xE3B3;"/> </Canvas>
</Border>
<Border MinWidth="36" <Border MinWidth="36"
Margin="0,0,12,12" Margin="0,0,12,12"
HorizontalAlignment="Right" HorizontalAlignment="Right"

View File

@ -48,12 +48,14 @@ using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Media::Imaging; using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::UI::Popups; using namespace Windows::UI::Popups;
using namespace Windows::UI::ViewManagement;
constexpr auto sc_ViewModelPropertyName = L"ViewModel"; constexpr auto sc_ViewModelPropertyName = L"ViewModel";
DEPENDENCY_PROPERTY_INITIALIZATION(GraphingCalculator, IsSmallState); DEPENDENCY_PROPERTY_INITIALIZATION(GraphingCalculator, IsSmallState);
GraphingCalculator::GraphingCalculator() GraphingCalculator::GraphingCalculator()
: m_accessibilitySettings{ ref new AccessibilitySettings() }
{ {
InitializeComponent(); InitializeComponent();
@ -82,6 +84,13 @@ GraphingCalculator::GraphingCalculator()
virtualKey->Key = (VirtualKey)187; // OemAdd key virtualKey->Key = (VirtualKey)187; // OemAdd key
virtualKey->Modifiers = VirtualKeyModifiers::Control; virtualKey->Modifiers = VirtualKeyModifiers::Control;
ZoomInButton->KeyboardAccelerators->Append(virtualKey); ZoomInButton->KeyboardAccelerators->Append(virtualKey);
// add shadow to the trace pointer
AddTracePointerShadow();
// hide the shadow in high contrast mode
CursorShadow->Visibility = m_accessibilitySettings->HighContrast ? ::Visibility::Collapsed : ::Visibility::Visible;
m_accessibilitySettings->HighContrastChanged +=
ref new TypedEventHandler<AccessibilitySettings ^, Object ^>(this, &GraphingCalculator::OnHighContrastChanged);
} }
void GraphingCalculator::OnShowTracePopupChanged(bool newValue) void GraphingCalculator::OnShowTracePopupChanged(bool newValue)
@ -185,8 +194,8 @@ void GraphingCalculator::OnTracePointChanged(Point newPoint)
void CalculatorApp::GraphingCalculator::OnPointerPointChanged(Windows::Foundation::Point newPoint) void CalculatorApp::GraphingCalculator::OnPointerPointChanged(Windows::Foundation::Point newPoint)
{ {
// Move the pointer glyph to where it is supposed to be. // Move the pointer glyph to where it is supposed to be.
// because the glyph is centered and has some spacing, to get the point to properly line up with the glyph, move the x point over 2 px Canvas::SetLeft(TracePointer, newPoint.X);
TracePointer->Margin = Thickness(newPoint.X - 2, newPoint.Y, 0, 0); Canvas::SetTop(TracePointer, newPoint.Y);
} }
GraphingCalculatorViewModel ^ GraphingCalculator::ViewModel::get() GraphingCalculatorViewModel ^ GraphingCalculator::ViewModel::get()
@ -537,6 +546,21 @@ void GraphingCalculator::DisplayGraphSettings()
flyoutGraphSettings->ShowAt(GraphSettingsButton); flyoutGraphSettings->ShowAt(GraphSettingsButton);
} }
void CalculatorApp::GraphingCalculator::AddTracePointerShadow()
{
auto compositor = ::Hosting::ElementCompositionPreview::GetElementVisual(CursorPath)->Compositor;
auto dropShadow = compositor->CreateDropShadow();
dropShadow->BlurRadius = 6;
dropShadow->Opacity = 0.33f;
dropShadow->Offset = ::Numerics::float3(2, 2, 0);
dropShadow->Mask = CursorPath->GetAlphaMask();
auto shadowSpriteVisual = compositor->CreateSpriteVisual();
shadowSpriteVisual->Size = ::Numerics::float2(static_cast<float>(CursorPath->ActualWidth), static_cast<float>(CursorPath->ActualHeight));
shadowSpriteVisual->Shadow = dropShadow;
::Hosting::ElementCompositionPreview::SetElementChildVisual(CursorShadow, shadowSpriteVisual);
}
void GraphingCalculator::OnSettingsFlyout_Closing(FlyoutBase ^ sender, FlyoutBaseClosingEventArgs ^ args) void GraphingCalculator::OnSettingsFlyout_Closing(FlyoutBase ^ sender, FlyoutBaseClosingEventArgs ^ args)
{ {
auto flyout = static_cast<Flyout ^>(sender); auto flyout = static_cast<Flyout ^>(sender);
@ -544,6 +568,18 @@ void GraphingCalculator::OnSettingsFlyout_Closing(FlyoutBase ^ sender, FlyoutBas
args->Cancel = graphingSetting->CanBeClose(); args->Cancel = graphingSetting->CanBeClose();
} }
void GraphingCalculator::LeftGrid_SizeChanged(Object ^ /*sender*/, SizeChangedEventArgs ^ e)
{
// Initialize the pointer to the correct location to match initial value in GraphControl\DirectX\RenderMain.cpp
Canvas::SetLeft(TracePointer, e->NewSize.Width / 2 + 40);
Canvas::SetTop(TracePointer, e->NewSize.Height / 2 - 40);
}
void GraphingCalculator::OnHighContrastChanged(AccessibilitySettings ^ sender, Object ^ /*args*/)
{
CursorShadow->Visibility = sender->HighContrast ? ::Visibility::Collapsed : ::Visibility::Visible;
}
void GraphingCalculator::OnEquationFormatRequested(Object ^ sender, MathRichEditBoxFormatRequest ^ e) void GraphingCalculator::OnEquationFormatRequested(Object ^ sender, MathRichEditBoxFormatRequest ^ e)
{ {
if (!e->OriginalText->IsEmpty()) if (!e->OriginalText->IsEmpty())

View File

@ -74,6 +74,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
void GraphSettingsButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void GraphSettingsButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void SwitchModeToggleButton_Toggled(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void SwitchModeToggleButton_Toggled(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void DisplayGraphSettings(); void DisplayGraphSettings();
void AddTracePointerShadow();
private: private:
Windows::Foundation::EventRegistrationToken m_dataRequestedToken; Windows::Foundation::EventRegistrationToken m_dataRequestedToken;
@ -82,8 +83,11 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
Windows::Foundation::EventRegistrationToken m_activeTracingKeyUpToken; Windows::Foundation::EventRegistrationToken m_activeTracingKeyUpToken;
Windows::Foundation::EventRegistrationToken m_ActiveTracingPointerCaptureLost; Windows::Foundation::EventRegistrationToken m_ActiveTracingPointerCaptureLost;
CalculatorApp::ViewModel::GraphingCalculatorViewModel ^ m_viewModel; CalculatorApp::ViewModel::GraphingCalculatorViewModel ^ m_viewModel;
Windows::UI::ViewManagement::AccessibilitySettings ^ m_accessibilitySettings;
void void
OnSettingsFlyout_Closing(Windows::UI::Xaml::Controls::Primitives::FlyoutBase ^ sender, Windows::UI::Xaml::Controls::Primitives::FlyoutBaseClosingEventArgs ^ args); OnSettingsFlyout_Closing(Windows::UI::Xaml::Controls::Primitives::FlyoutBase ^ sender, Windows::UI::Xaml::Controls::Primitives::FlyoutBaseClosingEventArgs ^ args);
void LeftGrid_SizeChanged(Platform::Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e);
void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args);
void OnEquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e); void OnEquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e);
}; };

View File

@ -29,6 +29,7 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <iomanip> #include <iomanip>
#include <WindowsNumerics.h>
// C++\WinRT Headers // C++\WinRT Headers
#include "winrt/base.h" #include "winrt/base.h"

View File

@ -44,8 +44,6 @@ namespace GraphControl::DX
RegisterEventHandlers(); RegisterEventHandlers();
m_drawActiveTracing = false; m_drawActiveTracing = false;
m_activeTracingPointerLocation.X = 50;
m_activeTracingPointerLocation.Y = 50;
} }
RenderMain::~RenderMain() RenderMain::~RenderMain()
@ -65,6 +63,7 @@ namespace GraphControl::DX
renderer->SetDpi(dpi, dpi); renderer->SetDpi(dpi, dpi);
renderer->SetGraphSize(static_cast<unsigned int>(m_swapChainPanel->ActualWidth), static_cast<unsigned int>(m_swapChainPanel->ActualHeight)); renderer->SetGraphSize(static_cast<unsigned int>(m_swapChainPanel->ActualWidth), static_cast<unsigned int>(m_swapChainPanel->ActualHeight));
} }
} }
} }
@ -120,6 +119,13 @@ namespace GraphControl::DX
{ {
// TODO: Replace this with the sizedependent initialization of your app's content. // TODO: Replace this with the sizedependent initialization of your app's content.
RunRenderPass(); RunRenderPass();
if (m_swapChainPanel != nullptr)
{
// Initialize the active tracing location to just above and to the right of the center of the graph area
m_activeTracingPointerLocation.X = m_swapChainPanel->ActualWidth / 2 + 40;
m_activeTracingPointerLocation.Y = m_swapChainPanel->ActualHeight / 2 - 40;
}
} }
bool RenderMain::RunRenderPass() bool RenderMain::RunRenderPass()