Adding share functionality to Graphing Calculator (#601)

* Plumebd with data transfer

* Getting mainpage to talk to getbitmap.  moving share callbacks from mainpage to graphingcalculator

* Trying to get bitmap from renderer.

* work

* Share worked

* cleanups

* Cleanups progressing

* Share working, need loc for title string and user notification incase of a failure.  Then add the equations key.

* More cleanup, now using share icon image and resources for strings.  Still need to do the graph equation key.

* Change share to html based start.

* Key working, with UL but going to try changing to table.

* Fix a html formating error, generating a new UL for each equation.

* Switched over to a table for equation key and have color block formating

* Updates from PR feedback, using Graphing::IBitmap abstraction.

* Update src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h

Fixed

Co-Authored-By: Pepe Rivera <joseartrivera@gmail.com>

* PR Updates.

* Add variables to the graph key.

* PR Updates.
This commit is contained in:
David Shoemaker
2019-08-13 12:57:13 -07:00
committed by Stephanie Anderl
parent 46f11c7c72
commit c1efa3d3e3
8 changed files with 239 additions and 23 deletions

View File

@@ -10,6 +10,7 @@ using namespace std;
using namespace Windows::Devices::Input;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage::Streams;
using namespace Windows::System;
using namespace Windows::UI;
using namespace Windows::UI::Input;
@@ -49,7 +50,7 @@ namespace GraphControl
DependencyProperty^ Grapher::s_equationsSourceProperty;
DependencyProperty^ Grapher::s_variablesProperty;
DependencyProperty^ Grapher::s_forceProportionalAxesTemplateProperty;
Grapher::Grapher()
: m_solver{ IMathSolver::CreateMathSolver() }
, m_graph{ m_solver->CreateGrapher() }
@@ -122,7 +123,7 @@ namespace GraphControl
{
s_equationsProperty = DependencyProperty::Register(
StringReference(s_propertyName_Equations),
EquationCollection::typeid ,
EquationCollection::typeid,
Grapher::typeid,
ref new PropertyMetadata(
nullptr,
@@ -555,7 +556,7 @@ namespace GraphControl
// For scaling, the graphing engine interprets x,y position between the range [-1, 1].
// Translate the pointer position to the [-1, 1] bounds.
const auto& pos = currentPointer->Position;
const auto[centerX, centerY] = PointerPositionToGraphPosition(pos.X, pos.Y, ActualWidth, ActualHeight);
const auto [centerX, centerY] = PointerPositionToGraphPosition(pos.X, pos.Y, ActualWidth, ActualHeight);
ScaleRange(centerX, centerY, scale);
@@ -563,16 +564,16 @@ namespace GraphControl
}
void Grapher::OnPointerPressed(PointerRoutedEventArgs^ e)
{
{
// Set the pointer capture to the element being interacted with so that only it
// will fire pointer-related events
CapturePointer(e->Pointer);
}
}
void Grapher::OnPointerReleased(PointerRoutedEventArgs^ e)
{
{
ReleasePointerCapture(e->Pointer);
}
}
void Grapher::OnPointerCanceled(PointerRoutedEventArgs^ e)
{
@@ -618,7 +619,7 @@ namespace GraphControl
// Convert from PointerPosition to graph position.
const auto& pos = e->Position;
const auto[centerX, centerY] = PointerPositionToGraphPosition(pos.X, pos.Y, width, height);
const auto [centerX, centerY] = PointerPositionToGraphPosition(pos.X, pos.Y, width, height);
if (FAILED(renderer->ScaleRange(centerX, centerY, scale)))
{
@@ -635,4 +636,47 @@ namespace GraphControl
}
}
}
RandomAccessStreamReference^ Grapher::GetGraphBitmapStream()
{
RandomAccessStreamReference^ outputStream;
if (m_renderMain != nullptr && m_graph != nullptr)
{
if (auto renderer = m_graph->GetRenderer())
{
std::shared_ptr < Graphing::IBitmap> BitmapOut;
bool hasSomeMissingDataOut = false;
HRESULT hr = E_FAIL;
hr = renderer->GetBitmap(BitmapOut, hasSomeMissingDataOut);
if (SUCCEEDED(hr))
{
// Get the raw date
std::vector<BYTE> byteVector = BitmapOut->GetData();
auto arr = ref new Array<BYTE>(&byteVector[0], (unsigned int)byteVector.size());
// create a memory stream wrapper
InMemoryRandomAccessStream^ stream = ref new InMemoryRandomAccessStream();
// Get a writer to transfer the data
auto writer = ref new DataWriter(stream->GetOutputStreamAt(0));
// write the data
writer->WriteBytes(arr);
writer->StoreAsync()->GetResults();
// Get a reference stream to return;
outputStream = RandomAccessStreamReference::CreateFromStream(stream);
}
else
{
OutputDebugString(L"Grapher::GetGraphBitmapStream() unable to get graph image from renderer\r\n");
winrt::throw_hresult(hr);
}
}
}
return outputStream;
}
}

View File

@@ -194,5 +194,8 @@ namespace GraphControl
const std::unique_ptr<Graphing::IMathSolver> m_solver;
const std::shared_ptr<Graphing::IGraph> m_graph;
public:
Windows::Storage::Streams::RandomAccessStreamReference^ GetGraphBitmapStream();
};
}