mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
- Expose ScaleRange from the UI
This commit is contained in:
parent
d6812e0880
commit
969936d04f
5 changed files with 68 additions and 2 deletions
|
@ -25,7 +25,8 @@
|
|||
Grid.Row="1"
|
||||
Grid.Column="0">
|
||||
|
||||
<graphControl:Grapher Grid.Row="0"
|
||||
<graphControl:Grapher x:Name="Graph"
|
||||
Grid.Row="0"
|
||||
Margin="4,7,4,4"
|
||||
EquationsSource="{x:Bind ViewModel.Equations, Mode=OneWay}"
|
||||
ForceProportionalAxes="True"
|
||||
|
@ -49,13 +50,38 @@
|
|||
Margin="4,0,4,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="5*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="3*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<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.Row="1"
|
||||
Grid.Row="2"
|
||||
Margin="3,0,3,3"
|
||||
UseLayoutRounding="False">
|
||||
<Grid.RowDefinitions>
|
||||
|
|
|
@ -11,12 +11,14 @@ using namespace CalculatorApp::ViewModel;
|
|||
using namespace concurrency;
|
||||
using namespace GraphControl;
|
||||
using namespace Platform;
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
using namespace Utils;
|
||||
using namespace Windows::Foundation::Collections;
|
||||
using namespace Windows::Storage::Streams;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Controls;
|
||||
using namespace Windows::UI::Xaml::Data;
|
||||
using namespace Windows::UI::Xaml::Input;
|
||||
using namespace Windows::UI::Xaml::Media;
|
||||
|
@ -49,3 +51,23 @@ void GraphingCalculator::ViewModel::set(GraphingCalculatorViewModel^ vm)
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ namespace CalculatorApp
|
|||
private:
|
||||
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:
|
||||
CalculatorApp::ViewModel::GraphingCalculatorViewModel^ m_viewModel;
|
||||
};
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
auto swapChainPanel = dynamic_cast<SwapChainPanel^>(GetTemplateChild(StringReference(s_templateKey_SwapChainPanel)));
|
||||
|
|
|
@ -100,6 +100,8 @@ namespace GraphControl
|
|||
}
|
||||
#pragma endregion
|
||||
|
||||
void ScaleRange(double centerX, double centerY, double scale);
|
||||
|
||||
protected:
|
||||
#pragma region Control Overrides
|
||||
void OnApplyTemplate() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue