- Expose ScaleRange from the UI

This commit is contained in:
Daniel Belcher 2019-04-01 00:08:37 -07:00
commit 969936d04f
5 changed files with 68 additions and 2 deletions

View file

@ -25,7 +25,8 @@
Grid.Row="1" Grid.Row="1"
Grid.Column="0"> Grid.Column="0">
<graphControl:Grapher Grid.Row="0" <graphControl:Grapher x:Name="Graph"
Grid.Row="0"
Margin="4,7,4,4" Margin="4,7,4,4"
EquationsSource="{x:Bind ViewModel.Equations, Mode=OneWay}" EquationsSource="{x:Bind ViewModel.Equations, Mode=OneWay}"
ForceProportionalAxes="True" ForceProportionalAxes="True"
@ -49,13 +50,38 @@
Margin="4,0,4,0"> Margin="4,0,4,0">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="5*"/> <RowDefinition Height="5*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="3*"/> <RowDefinition Height="3*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<local:EquationInputArea Grid.Row="0" Equations="{x:Bind ViewModel.Equations}"/> <local:EquationInputArea Grid.Row="0" Equations="{x:Bind ViewModel.Equations}"/>
<StackPanel Grid.Row="1" Orientation="Vertical">
<TextBlock Text="Scale Range"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox x:Name="CenterXTextBox"
Grid.Column="0"
KeyDown="ScaleRangeTextBox_KeyDown"
PlaceholderText="CenterX"/>
<TextBox x:Name="CenterYTextBox"
Grid.Column="1"
KeyDown="ScaleRangeTextBox_KeyDown"
PlaceholderText="CenterY"/>
<TextBox x:Name="ScaleTextBox"
Grid.Column="2"
KeyDown="ScaleRangeTextBox_KeyDown"
PlaceholderText="Scale"/>
</Grid>
</StackPanel>
<Grid x:Name="ButtonContainerGrid" <Grid x:Name="ButtonContainerGrid"
Grid.Row="1" Grid.Row="2"
Margin="3,0,3,3" Margin="3,0,3,3"
UseLayoutRounding="False"> UseLayoutRounding="False">
<Grid.RowDefinitions> <Grid.RowDefinitions>

View file

@ -11,12 +11,14 @@ using namespace CalculatorApp::ViewModel;
using namespace concurrency; using namespace concurrency;
using namespace GraphControl; using namespace GraphControl;
using namespace Platform; using namespace Platform;
using namespace std;
using namespace std::chrono; using namespace std::chrono;
using namespace Utils; using namespace Utils;
using namespace Windows::Foundation::Collections; using namespace Windows::Foundation::Collections;
using namespace Windows::Storage::Streams; using namespace Windows::Storage::Streams;
using namespace Windows::System; using namespace Windows::System;
using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Data; using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Media;
@ -49,3 +51,23 @@ void GraphingCalculator::ViewModel::set(GraphingCalculatorViewModel^ vm)
RaisePropertyChanged(StringReference(sc_ViewModelPropertyName)); RaisePropertyChanged(StringReference(sc_ViewModelPropertyName));
} }
} }
void GraphingCalculator::ScaleRangeTextBox_KeyDown(Object^ sender, KeyRoutedEventArgs^ e)
{
if (e->Key == VirtualKey::Enter)
{
auto valFromTB = [](TextBox^ tb)
{
wstring text = tb->Text->Data();
return stod(text);
};
double centerX = valFromTB(CenterXTextBox);
double centerY = valFromTB(CenterYTextBox);
double scale = valFromTB(ScaleTextBox);
Graph->ScaleRange(centerX, centerY, scale);
e->Handled = true;
}
}

View file

@ -22,6 +22,8 @@ namespace CalculatorApp
private: private:
void GraphingCalculator_DataContextChanged(Windows::UI::Xaml::FrameworkElement^ sender, Windows::UI::Xaml::DataContextChangedEventArgs^ args); void GraphingCalculator_DataContextChanged(Windows::UI::Xaml::FrameworkElement^ sender, Windows::UI::Xaml::DataContextChangedEventArgs^ args);
void ScaleRangeTextBox_KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
private: private:
CalculatorApp::ViewModel::GraphingCalculatorViewModel^ m_viewModel; CalculatorApp::ViewModel::GraphingCalculatorViewModel^ m_viewModel;
}; };

View file

@ -66,6 +66,20 @@ namespace GraphControl
} }
} }
void Grapher::ScaleRange(double centerX, double centerY, double scale)
{
if (m_graph)
{
if (auto renderer = m_graph->GetRenderer())
{
if (SUCCEEDED(renderer->ScaleRange(centerX, centerY, scale)))
{
m_renderMain->RunRenderPass();
}
}
}
}
void Grapher::OnApplyTemplate() void Grapher::OnApplyTemplate()
{ {
auto swapChainPanel = dynamic_cast<SwapChainPanel^>(GetTemplateChild(StringReference(s_templateKey_SwapChainPanel))); auto swapChainPanel = dynamic_cast<SwapChainPanel^>(GetTemplateChild(StringReference(s_templateKey_SwapChainPanel)));

View file

@ -100,6 +100,8 @@ namespace GraphControl
} }
#pragma endregion #pragma endregion
void ScaleRange(double centerX, double centerY, double scale);
protected: protected:
#pragma region Control Overrides #pragma region Control Overrides
void OnApplyTemplate() override; void OnApplyTemplate() override;