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

Passive & Active tracing #638

Merged
merged 44 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b4a9347
Plumebd with data transfer
DavidShoe Jul 12, 2019
7e01206
Getting mainpage to talk to getbitmap. moving share callbacks from m…
DavidShoe Jul 15, 2019
74695d1
Trying to get bitmap from renderer.
DavidShoe Jul 16, 2019
68f6bdd
work
DavidShoe Jul 18, 2019
39ddc13
Share worked
DavidShoe Jul 18, 2019
c37d937
cleanups
DavidShoe Jul 18, 2019
427beb1
Cleanups progressing
DavidShoe Jul 19, 2019
46a0ae0
Share working, need loc for title string and user notification incase…
DavidShoe Jul 19, 2019
ee28b7a
More cleanup, now using share icon image and resources for strings. …
DavidShoe Jul 19, 2019
bc490ec
Change share to html based start.
DavidShoe Jul 24, 2019
95871e1
Key working, with UL but going to try changing to table.
DavidShoe Jul 24, 2019
3eb0552
Fix a html formating error, generating a new UL for each equation.
DavidShoe Jul 24, 2019
c80375e
Switched over to a table for equation key and have color block formating
DavidShoe Jul 24, 2019
82bc868
Merge pull request #1 from microsoft/feature/GraphingCalculator
DavidShoe Jul 25, 2019
b14f487
Merge branch 'feature/GraphingCalculator' into working
DavidShoe Jul 26, 2019
0a059df
Merge pull request #2 from DavidShoe/working
DavidShoe Jul 26, 2019
5e53af5
Updates from PR feedback, using Graphing::IBitmap abstraction.
DavidShoe Jul 30, 2019
1dc2608
Merge branch 'working' into feature/GraphingCalculator
DavidShoe Jul 30, 2019
8037671
Update src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h
DavidShoe Jul 30, 2019
59bef86
PR Updates.
DavidShoe Jul 30, 2019
fc1c0e1
Merge commit
DavidShoe Jul 30, 2019
1aadd66
Add variables to the graph key.
DavidShoe Jul 30, 2019
c0ba6b7
Merge branch 'AddVariables' into feature/GraphingCalculator
DavidShoe Jul 30, 2019
6b3b08f
eod
DavidShoe Jul 30, 2019
b30396f
Passive graph value tracing working.
DavidShoe Aug 2, 2019
7a99613
Basic active tracing cursor working.
DavidShoe Aug 2, 2019
2b8bd15
Move active tracing from graphingcalculator to grapher to save some h…
DavidShoe Aug 5, 2019
29e5ce2
Active tracing working, need to put button on screen for activation.
DavidShoe Aug 5, 2019
96a7e20
Added active tracing control button (placeholder image)
DavidShoe Aug 5, 2019
ce123ff
Merge of passive (popup display) and active tracing.
DavidShoe Aug 5, 2019
980155e
Eod
DavidShoe Aug 6, 2019
523c5e2
Popup trace value now tracks the highlighted point.
DavidShoe Aug 6, 2019
76d2d1d
Popup skined
DavidShoe Aug 7, 2019
c27afd4
PR Updates.
DavidShoe Aug 8, 2019
be45fce
Merge pull request #3 from DavidShoe/PRUpdates
DavidShoe Aug 8, 2019
50b5267
Merge remote-tracking branch 'myfork/feature/GraphingCalculator' into…
DavidShoe Aug 27, 2019
24d0de7
merge with mainline so we can get the pull request in.
DavidShoe Aug 27, 2019
4b9d668
Update certificate thumbnail so VS2019 doesn't have a build error.
DavidShoe Aug 27, 2019
ddaaa0f
PR comments in process.
DavidShoe Sep 23, 2019
6eeb447
PR Updates
DavidShoe Sep 25, 2019
691c62f
Merge with upstream
DavidShoe Sep 27, 2019
da9565e
PR Updates, change tracing value to use tooltip static resource so we…
DavidShoe Sep 30, 2019
acff033
PR updates, changed how we detect who has focus so we don't eat keys …
DavidShoe Oct 1, 2019
6c775ce
Additional filtering for the Key Up/Down in the grapher.
DavidShoe Oct 4, 2019
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Calculator/Calculator.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@
<PRIResource Include="Resources\zh-tw\Resources.resw" />
</ItemGroup>
<ItemGroup>
<Image Include="Assets\ActiveTracking-32_contrast-white.png" />
joseartrivera marked this conversation as resolved.
Show resolved Hide resolved
<Image Include="Assets\CalculatorAppList.contrast-black_scale-100.png" />
<Image Include="Assets\CalculatorAppList.contrast-black_scale-125.png" />
<Image Include="Assets\CalculatorAppList.contrast-black_scale-150.png" />
Expand Down
7 changes: 7 additions & 0 deletions src/Calculator/Calculator.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,9 @@
<Image Include="Assets\CalculatorAppList.targetsize-256_altform-lightunplated.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\ActiveTracking-32_contrast-white.png">
<Filter>Assets</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<Font Include="Assets\CalcMDL2.ttf">
Expand All @@ -1569,5 +1572,9 @@
<ItemGroup>
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
<CopyFileToFolders Include="$(GraphingImplDll)" />
<CopyFileToFolders Include="$(GraphingEngineDll)" />
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions src/Calculator/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3439,6 +3439,22 @@
<value>Add Equation</value>
<comment>Placeholder text for the equation input button</comment>
</data>
<data name="ShareActionErrorMessage" xml:space="preserve">
<value>Unable to share at this time.</value>
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved
<comment>If there is an error in the sharing action will display a dialog with this text.</comment>
</data>
<data name="ShareActionErrorOk" xml:space="preserve">
<value>OK</value>
<comment>Used on the dismiss button of the share action error dialog.</comment>
</data>
<data name="ShareActionTitle" xml:space="preserve">
<value>Look what I graphed.</value>
<comment>Sent as part of the shared content. The title for the share.</comment>
</data>
<data name="EmptyEquationString" xml:space="preserve">
<value>Empty graph equation</value>
<comment>When sharing and one of the equations has no content this will be shown in the graph key for that equation.</comment>
</data>
<data name="VaiablesHeader.Text" xml:space="preserve">
<value>Variables</value>
<comment>Header text for variables area</comment>
Expand Down
53 changes: 38 additions & 15 deletions src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:CalculatorApp.ViewModel"
DataContextChanged="GraphingCalculator_DataContextChanged"
mc:Ignorable="d">
mc:Ignorable="d"
>

<UserControl.Resources>
<converters:BooleanToVisibilityConverter x:Name="BooleanToVisibilityConverter"/>
<converters:BooleanToVisibilityNegationConverter x:Name="BooleanToVisibilityNegationConverter"/>
</UserControl.Resources>

<Grid x:Name="RootGrid">
<Grid x:Name="RootGrid" >
<Grid.RowDefinitions>
<RowDefinition x:Name="RowHamburger" Height="{StaticResource HamburgerHeightGridLength}"/>
<RowDefinition/>
Expand All @@ -30,22 +31,34 @@
<Grid x:Name="LeftGrid"
Grid.Row="1"
Grid.Column="0">

<graphControl:Grapher Name="GraphingControl"
Margin="4,7,4,4"
<Grid Grid.Row="0" Margin="4,7,4,4">
<graphControl:Grapher Name="GraphingControl"
EquationsSource="{x:Bind ViewModel.Equations, Mode=OneWay}"
ForceProportionalAxes="True"
UseSystemFocusVisuals="True"
VariablesUpdated="GraphVariablesUpdated">
<graphControl:Grapher.Background>
<SolidColorBrush Color="White"/>
</graphControl:Grapher.Background>
<graphControl:Grapher.EquationTemplate>
<DataTemplate x:DataType="vm:EquationViewModel">
<graphControl:Equation Expression="{x:Bind Expression, Mode=OneWay}" LineColor="{x:Bind LineColor, Mode=OneWay}"/>
</DataTemplate>
</graphControl:Grapher.EquationTemplate>
</graphControl:Grapher>
<graphControl:Grapher.Background>
<SolidColorBrush Color="White"/>
</graphControl:Grapher.Background>
<graphControl:Grapher.EquationTemplate>
<DataTemplate x:DataType="vm:EquationViewModel">
<graphControl:Equation Expression="{x:Bind Expression, Mode=OneWay}" LineColor="{x:Bind LineColor, Mode=OneWay}"/>
</DataTemplate>
</graphControl:Grapher.EquationTemplate>

</graphControl:Grapher>

<Popup x:Name="TraceValuePopup" Grid.Row="0" RenderTransformOrigin="0,1">
<Popup.RenderTransform>
<TranslateTransform x:Name="TraceValuePopupTransform" X="50" Y="150"/>
</Popup.RenderTransform>
<Grid Background="White" BorderBrush="SlateBlue" BorderThickness="3,3,3,3">
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved
<TextBlock x:Name="TraceValue" Text="x=0,y=0" Margin="5,5,5,5"/>
</Grid>
</Popup>

</Grid>


<!-- Temporary button until the final UI is created -->
<Button Margin="12,0,0,12"
Expand Down Expand Up @@ -229,7 +242,17 @@
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>

<local:EquationInputArea Grid.Row="0" Equations="{x:Bind ViewModel.Equations}"/>
<StackPanel>
<StackPanel Orientation="Horizontal">
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved
<Button x:Name="ActiveTracing" Click="OnActiveTracingClick" Width="40" Height="40" Margin="0,0,10,0">
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved
<Image Source="ms-appx:///Assets/ActiveTracking-32_contrast-white.png"/>
</Button>
<Button x:Name="Share" Click="OnShareClick" Width="40" Height="40">
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE72D;"/>
</Button>
</StackPanel>
<local:EquationInputArea Grid.Row="0" Equations="{x:Bind ViewModel.Equations}"/>
</StackPanel>

<Grid x:Name="ButtonContainerGrid"
Grid.Row="2"
Expand Down
176 changes: 162 additions & 14 deletions src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include "pch.h"
#include "CalcViewModel/Common/TraceLogger.h"
#include "GraphingCalculator.xaml.h"
#include "CalcViewModel/Common/KeyboardShortcutManager.h"
#include "Controls/CalculationResult.h"
Expand All @@ -11,19 +12,24 @@ using namespace CalculatorApp::ViewModel;
using namespace concurrency;
using namespace GraphControl;
using namespace Platform;
using namespace Platform::Collections;
using namespace std;
using namespace std::chrono;
using namespace Utils;
using namespace Windows::ApplicationModel::DataTransfer;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage::Streams;
using namespace Windows::System;
using namespace Windows::UI::Core;
using namespace Windows::UI::Input;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::UI::Popups;

constexpr auto sc_ViewModelPropertyName = L"ViewModel";

Expand All @@ -32,21 +38,47 @@ GraphingCalculator::GraphingCalculator()
Equation::RegisterDependencyProperties();
Grapher::RegisterDependencyProperties();
InitializeComponent();

DataTransferManager ^ dataTransferManager = DataTransferManager::GetForCurrentView();

// Register the current control as a share source.
m_dataRequestedToken = dataTransferManager->DataRequested += ref new TypedEventHandler<DataTransferManager ^, DataRequestedEventArgs ^>(this, &GraphingCalculator::OnDataRequested);

// Request notifications when we should be showing the trace values
m_showTracePopupChangedToken = GraphingControl->TracingChangedEvent += ref new TracingChangedEventHandler(this, &GraphingCalculator::OnShowTracePopupChanged);
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved

// And when the actual trace value changes
m_tracePointChangedToken = GraphingControl->TracingValueChangedEvent += ref new TracingValueChangedEventHandler(this, &GraphingCalculator::OnTracePointChanged);
}

void GraphingCalculator::OnShowTracePopupChanged(bool newValue)
{
TraceValuePopup->IsOpen = newValue;
}

void GraphingCalculator::GraphingCalculator_DataContextChanged(FrameworkElement^ sender, DataContextChangedEventArgs^ args)
void GraphingCalculator::GraphingCalculator_DataContextChanged(FrameworkElement ^ sender, DataContextChangedEventArgs ^ args)
{
ViewModel = dynamic_cast<GraphingCalculatorViewModel^>(args->NewValue);
ViewModel = dynamic_cast<GraphingCalculatorViewModel ^>(args->NewValue);

ViewModel->VariableUpdated += ref new EventHandler<VariableChangedEventArgs>(this, &CalculatorApp::GraphingCalculator::OnVariableChanged);
}

GraphingCalculatorViewModel^ GraphingCalculator::ViewModel::get()
void GraphingCalculator::OnTracePointChanged(Windows::Foundation::Point newPoint)
{
auto p = GraphingControl->TraceValue;
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved
auto l = GraphingControl->TraceLocation;
TraceValuePopupTransform->X = (int)l.X + 15;
TraceValuePopupTransform->Y = (int)l.Y - 30;

TraceValue->Text = "x=" + newPoint.X.ToString() + ", y=" + newPoint.Y.ToString();
DavidShoe marked this conversation as resolved.
Show resolved Hide resolved
}

GraphingCalculatorViewModel ^ GraphingCalculator::ViewModel::get()
{
return m_viewModel;
}

void GraphingCalculator::ViewModel::set(GraphingCalculatorViewModel^ vm)
void GraphingCalculator::ViewModel::set(GraphingCalculatorViewModel ^ vm)
{
if (m_viewModel != vm)
{
Expand All @@ -55,20 +87,132 @@ void GraphingCalculator::ViewModel::set(GraphingCalculatorViewModel^ vm)
}
}

void GraphingCalculator::GraphVariablesUpdated(Object^, Object^)
void CalculatorApp::GraphingCalculator::OnShareClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
{
// Ask the OS to start a share action.
DataTransferManager::ShowShareUI();
}

// When share is invoked (by the user or programmatically) the event handler we registered will be called to populate the data package with the
// data to be shared. We will request the current graph image from the grapher as a stream that will pass to the share request.
void GraphingCalculator::OnDataRequested(DataTransferManager ^ sender, DataRequestedEventArgs ^ args)
{
try
{
// Get our title from the localized resources
auto resourceLoader = Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();
auto EmptyEquationString = resourceLoader->GetString(L"EmptyEquationString");

std::wstring rawHtml = L"<p><img src='graph.png'></p>";

auto equations = ViewModel->Equations;
rawHtml += L"<p><table cellpadding=\"10\">";
rawHtml += L"<col width=\"20\">";
rawHtml += L"<row height=\"20\">";
for (unsigned i = 0; i < equations->Size; i++)
{
auto expression = equations->GetAt(i)->Expression->Data();
auto color = equations->GetAt(i)->LineColor;

if (equations->GetAt(i)->Expression->Length() == 0)
{
expression = EmptyEquationString->Data();
}

rawHtml += L"<tr>";

rawHtml += L"<td style=\"background-color:rgb(";
rawHtml += color.R.ToString()->Data();
rawHtml += L",";
rawHtml += color.G.ToString()->Data();
rawHtml += L",";
rawHtml += color.B.ToString()->Data();
rawHtml += L"); \">";
rawHtml += L"</td>";
rawHtml += L"<td>";
rawHtml += expression;
rawHtml += L"</td>";

rawHtml += L"</tr>";
}
rawHtml += L"</table></p>";

auto variables = ViewModel->Variables;
rawHtml += L"<p><table cellpadding=\"10\">";
rawHtml += L"<col width=\"20\">";
rawHtml += L"<row height=\"20\">";
for (unsigned i = 0; i < variables->Size; i++)
{
auto name = variables->GetAt(i)->Name;
auto value = variables->GetAt(i)->Value;

if (name->Length() >= 0)
{
rawHtml += L"<tr>";

rawHtml += L"<td>";
rawHtml += name->Data();
rawHtml += L"</td>";
rawHtml += L"<td>";
rawHtml += std::to_wstring(value);
rawHtml += L"</td>";

rawHtml += L"</tr>";
}
}
rawHtml += L"</table></p>";

// Shortcut to the request data
auto requestData = args->Request->Data;

DataPackage ^ dataPackage = ref new DataPackage();
auto html = HtmlFormatHelper::CreateHtmlFormat(ref new String(rawHtml.c_str()));

auto titleString = resourceLoader->GetString(L"ShareActionTitle");
requestData->Properties->Title = titleString;

requestData->SetHtmlFormat(html);

auto bitmapStream = GraphingControl->GetGraphBitmapStream();

requestData->ResourceMap->Insert(ref new String(L"graph.png"), bitmapStream);

// Set the thumbnail image (in case the share target can't handle HTML)
requestData->Properties->Thumbnail = bitmapStream;

// And the bitmap (in case the share target can't handle HTML)
requestData->SetBitmap(bitmapStream);
}
catch (Exception ^ ex)
{
TraceLogger::GetInstance().LogPlatformException(__FUNCTIONW__, ex);

// Something went wrong, notify the user.
auto resourceLoader = Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();

auto errorTitleString = resourceLoader->GetString(L"ShareActionErrorMessage");
auto errorOkString = resourceLoader->GetString(L"ShareActionErrorOk");
auto errDialog = ref new Windows::UI::Xaml::Controls::ContentDialog();

errDialog->Content = errorTitleString;
errDialog->CloseButtonText = errorOkString;
errDialog->ShowAsync();
}
}

void GraphingCalculator::GraphVariablesUpdated(Object ^, Object ^)
{
m_viewModel->UpdateVariables(GraphingControl->Variables);
}

void GraphingCalculator::OnVariableChanged(Platform::Object^ sender, VariableChangedEventArgs args)
void GraphingCalculator::OnVariableChanged(Platform::Object ^ sender, VariableChangedEventArgs args)
{
GraphingControl->SetVariable(args.variableName, args.newValue);
}


void GraphingCalculator::SubmitTextbox(TextBox^ sender)
void GraphingCalculator::SubmitTextbox(TextBox ^ sender)
{
auto variableViewModel = static_cast<VariableViewModel^>(sender->DataContext);
auto variableViewModel = static_cast<VariableViewModel ^>(sender->DataContext);

if (sender->Name == "ValueTextBox")
{
Expand All @@ -88,21 +232,20 @@ void GraphingCalculator::SubmitTextbox(TextBox^ sender)
}
}

void GraphingCalculator::TextBoxLosingFocus(TextBox^ sender, LosingFocusEventArgs^)
void GraphingCalculator::TextBoxLosingFocus(TextBox ^ sender, LosingFocusEventArgs ^)
{
SubmitTextbox(sender);
}


void GraphingCalculator::TextBoxKeyDown(TextBox^ sender, KeyRoutedEventArgs^ e)
void GraphingCalculator::TextBoxKeyDown(TextBox ^ sender, KeyRoutedEventArgs ^ e)
{
if (e->Key == ::VirtualKey::Enter)
{
SubmitTextbox(sender);
}
}

double GraphingCalculator::validateDouble(String^ value, double defaultValue)
double GraphingCalculator::validateDouble(String ^ value, double defaultValue)
{
try
{
Expand All @@ -114,7 +257,12 @@ double GraphingCalculator::validateDouble(String^ value, double defaultValue)
}
}

void GraphingCalculator::TextBoxGotFocus(TextBox^ sender, RoutedEventArgs^ e)
void GraphingCalculator::TextBoxGotFocus(TextBox ^ sender, RoutedEventArgs ^ e)
{
sender->SelectAll();
}

void GraphingCalculator::OnActiveTracingClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
{
GraphingControl->ActiveTracing = !GraphingControl->ActiveTracing;
}
Loading