Add line width option (#1098)

* add line thickness

* clean up

* Fix pr comments
This commit is contained in:
Pepe Rivera 2020-03-26 14:15:44 -07:00 committed by GitHub
parent fc19ddcbcb
commit 7dcfe0439c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 124 additions and 8 deletions

View File

@ -4414,6 +4414,26 @@
<value>Graph Options</value> <value>Graph Options</value>
<comment>Heading for the Graph Options flyout in Graphing mode.</comment> <comment>Heading for the Graph Options flyout in Graphing mode.</comment>
</data> </data>
<data name="LineThicknessBox.Header" xml:space="preserve">
<value>Line Thickness</value>
<comment>Heading for the Graph Options flyout in Graphing mode.</comment>
</data>
<data name="SmallLineWidthAutomationName" xml:space="preserve">
<value>Small Line Width</value>
<comment>Automation name for line width setting</comment>
</data>
<data name="MediumLineWidthAutomationName" xml:space="preserve">
<value>Medium Line Width</value>
<comment>Automation name for line width setting</comment>
</data>
<data name="LargeLineWidthAutomationName" xml:space="preserve">
<value>Large Line Width</value>
<comment>Automation name for line width setting</comment>
</data>
<data name="ExtraLargeLineWidthAutomationName" xml:space="preserve">
<value>Extra Large Line Width</value>
<comment>Automation name for line width setting</comment>
</data>
<data name="mathRichEditBox.PlaceholderText" xml:space="preserve"> <data name="mathRichEditBox.PlaceholderText" xml:space="preserve">
<value>Enter an expression</value> <value>Enter an expression</value>
<comment>this is the placeholder text used by the textbox to enter an equation</comment> <comment>this is the placeholder text used by the textbox to enter an equation</comment>

View File

@ -183,6 +183,35 @@
Style="{StaticResource TrigUnitsRadioButtonStyle}" Style="{StaticResource TrigUnitsRadioButtonStyle}"
IsChecked="{x:Bind ViewModel.TrigModeGradians, Mode=TwoWay}"/> IsChecked="{x:Bind ViewModel.TrigModeGradians, Mode=TwoWay}"/>
</StackPanel> </StackPanel>
<ComboBox x:Name="LineThicknessBox"
x:Uid="LineThicknessBox"
MinWidth="200"
Margin="0,12,0,0"
SelectedItem="{x:Bind ViewModel.Graph.LineWidth, Mode=TwoWay}">
<ComboBox.Items>
<x:Double>1.0</x:Double>
<x:Double>2.0</x:Double>
<x:Double>3.0</x:Double>
<x:Double>4.0</x:Double>
</ComboBox.Items>
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="x:Double">
<Grid x:Name="LineGrid"
Height="20"
MaxWidth="200"
AutomationProperties.Name="{x:Bind local:GraphingSettings.GetLineWidthAutomationName((x:Double))}">
<Line VerticalAlignment="Center"
Stroke="{ThemeResource AppControlPageTextBaseHighColorBrush}"
StrokeThickness="{x:Bind}"
X1="0"
X2="200"
Y1="4"
Y2="4"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -66,3 +66,25 @@ void GraphingSettings::ResetViewButton_Clicked(Object ^ sender, RoutedEventArgs
{ {
ViewModel->ResetView(); ViewModel->ResetView();
} }
String ^ GraphingSettings::GetLineWidthAutomationName(double width)
{
auto resourceLoader = AppResourceProvider::GetInstance();
if (width == 1.0)
{
return resourceLoader->GetResourceString("SmallLineWidthAutomationName");
}
else if(width == 2.0)
{
return resourceLoader->GetResourceString("MediumLineWidthAutomationName");
}
else if (width == 3.0)
{
return resourceLoader->GetResourceString("LargeLineWidthAutomationName");
}
else
{
return resourceLoader->GetResourceString("ExtraLargeLineWidthAutomationName");
}
}

View File

@ -21,6 +21,8 @@ namespace CalculatorApp
Windows::UI::Xaml::Style ^ SelectTextBoxStyle(bool incorrectRange, bool error); Windows::UI::Xaml::Style ^ SelectTextBoxStyle(bool incorrectRange, bool error);
void SetGrapher(GraphControl::Grapher ^ grapher); void SetGrapher(GraphControl::Grapher ^ grapher);
void RefreshRanges(); void RefreshRanges();
static Platform::String ^ GetLineWidthAutomationName(double width);
private: private:
void GridSettingsTextBox_PreviewKeyDown(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e); void GridSettingsTextBox_PreviewKeyDown(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e);
void ResetViewButton_Clicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void ResetViewButton_Clicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);

View File

@ -34,6 +34,7 @@ DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Variables);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Equations); DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Equations);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, AxesColor); DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, AxesColor);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, GraphBackground); DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, GraphBackground);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, LineWidth);
namespace namespace
{ {
@ -405,7 +406,7 @@ namespace GraphControl
initResult = m_graph->TryInitialize(); initResult = m_graph->TryInitialize();
if (initResult != nullopt) if (initResult != nullopt)
{ {
UpdateGraphOptions(m_graph->GetOptions(), vector<Equation^>()); UpdateGraphOptions(m_graph->GetOptions(), vector<Equation ^>());
SetGraphArgs(m_graph); SetGraphArgs(m_graph);
m_renderMain->Graph = m_graph; m_renderMain->Graph = m_graph;
@ -525,7 +526,6 @@ namespace GraphControl
Variables->Insert(variableName, ref new Variable(newValue)); Variables->Insert(variableName, ref new Variable(newValue));
} }
if (m_graph != nullptr && m_renderMain != nullptr) if (m_graph != nullptr && m_renderMain != nullptr)
{ {
auto workItemHandler = ref new WorkItemHandler([this, variableName, newValue](IAsyncAction ^ action) { auto workItemHandler = ref new WorkItemHandler([this, variableName, newValue](IAsyncAction ^ action) {
@ -558,9 +558,15 @@ namespace GraphControl
auto lineColor = eq->LineColor; auto lineColor = eq->LineColor;
graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A); graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A);
if (eq->GraphedEquation != nullptr && !eq->HasGraphError && eq->IsSelected) if (eq->GraphedEquation)
{ {
eq->GraphedEquation->TrySelectEquation(); if (!eq->HasGraphError && eq->IsSelected)
{
eq->GraphedEquation->TrySelectEquation();
}
eq->GraphedEquation->GetGraphEquationOptions()->SetLineWidth(LineWidth);
eq->GraphedEquation->GetGraphEquationOptions()->SetSelectedEquationLineWidth(LineWidth + ((LineWidth <= 2) ? 1 : 2));
} }
} }
options.SetGraphColors(graphColors); options.SetGraphColors(graphColors);
@ -1049,6 +1055,21 @@ void Grapher::OnGraphBackgroundPropertyChanged(Windows::UI::Color /*oldValue*/,
} }
} }
void Grapher::OnLineWidthPropertyChanged(double oldValue, double newValue)
{
if (m_graph)
{
UpdateGraphOptions(m_graph->GetOptions(), GetGraphableEquations());
if (m_renderMain)
{
m_renderMain->SetPointRadius(LineWidth + 1);
m_renderMain->RunRenderPass();
TraceLogger::GetInstance()->LogLineWidthChanged();
}
}
}
optional<vector<shared_ptr<Graphing::IEquation>>> Grapher::TryInitializeGraph(bool keepCurrentView, const IExpression* graphingExp) optional<vector<shared_ptr<Graphing::IEquation>>> Grapher::TryInitializeGraph(bool keepCurrentView, const IExpression* graphingExp)
{ {
if (keepCurrentView) if (keepCurrentView)

View File

@ -50,7 +50,7 @@ public
DEPENDENCY_PROPERTY_R_WITH_DEFAULT_AND_CALLBACK(GraphControl::EquationCollection ^, Equations, nullptr); DEPENDENCY_PROPERTY_R_WITH_DEFAULT_AND_CALLBACK(GraphControl::EquationCollection ^, Equations, nullptr);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, AxesColor, Windows::UI::Colors::Transparent); DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, AxesColor, Windows::UI::Colors::Transparent);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, GraphBackground, Windows::UI::Colors::Transparent); DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, GraphBackground, Windows::UI::Colors::Transparent);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(double, LineWidth, 2.0);
// Pass active tracing turned on or off down to the renderer // Pass active tracing turned on or off down to the renderer
property bool ActiveTracing property bool ActiveTracing
{ {
@ -276,6 +276,7 @@ public
void OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue); void OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue);
void OnAxesColorPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue); void OnAxesColorPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue);
void OnGraphBackgroundPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue); void OnGraphBackgroundPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue);
void OnLineWidthPropertyChanged(double oldValue, double newValue);
void OnEquationChanged(Equation ^ equation); void OnEquationChanged(Equation ^ equation);
void OnEquationStyleChanged(Equation ^ equation); void OnEquationStyleChanged(Equation ^ equation);
void OnEquationLineEnabledChanged(Equation ^ equation); void OnEquationLineEnabledChanged(Equation ^ equation);

View File

@ -54,6 +54,12 @@ void NearestPointRenderer::Render(const Point& location)
} }
} }
void NearestPointRenderer::SetRadius(float radius)
{
m_ellipse.radiusX = radius;
m_ellipse.radiusY = radius;
}
void NearestPointRenderer::SetColor(const ColorF& color) void NearestPointRenderer::SetColor(const ColorF& color)
{ {
m_color = color; m_color = color;
@ -63,7 +69,5 @@ void NearestPointRenderer::SetColor(const ColorF& color)
void NearestPointRenderer::CreateBrush() void NearestPointRenderer::CreateBrush()
{ {
m_brush.Reset(); m_brush.Reset();
ThrowIfFailed( ThrowIfFailed(m_deviceResources->GetD2DDeviceContext()->CreateSolidColorBrush(m_color, &m_brush));
m_deviceResources->GetD2DDeviceContext()->CreateSolidColorBrush(m_color, &m_brush)
);
} }

View File

@ -17,6 +17,7 @@ namespace GraphControl::DX
void Render(const Windows::Foundation::Point& location); void Render(const Windows::Foundation::Point& location);
void SetColor(const D2D1::ColorF& color); void SetColor(const D2D1::ColorF& color);
void SetRadius(float radius);
private: private:
void CreateBrush(); void CreateBrush();

View File

@ -187,6 +187,11 @@ namespace GraphControl::DX
return m_Tracing; return m_Tracing;
} }
void RenderMain::SetPointRadius(float radius)
{
m_nearestPointRenderer.SetRadius(radius);
}
bool RenderMain::RunRenderPass() bool RenderMain::RunRenderPass()
{ {
// Non async render passes cancel if they can't obtain the lock immediatly // Non async render passes cancel if they can't obtain the lock immediatly

View File

@ -47,6 +47,8 @@ namespace GraphControl::DX
bool RenderMain::CanRenderPoint(); bool RenderMain::CanRenderPoint();
void SetPointRadius(float radius);
bool RunRenderPass(); bool RunRenderPass();
Windows::Foundation::IAsyncAction ^ RunRenderPassAsync(bool allowCancel = true); Windows::Foundation::IAsyncAction ^ RunRenderPassAsync(bool allowCancel = true);

View File

@ -23,6 +23,7 @@ namespace GraphControl
constexpr auto EVENT_NAME_EQUATION_COUNT_CHANGED = L"EquationCountChanged"; constexpr auto EVENT_NAME_EQUATION_COUNT_CHANGED = L"EquationCountChanged";
constexpr auto EVENT_NAME_FUNCTION_ANALYSIS_PERFORMED = L"FunctionAnalysisPerformed"; constexpr auto EVENT_NAME_FUNCTION_ANALYSIS_PERFORMED = L"FunctionAnalysisPerformed";
constexpr auto EVENT_NAME_VARIABLES_COUNT_CHANGED = L"VariablesCountChanged"; constexpr auto EVENT_NAME_VARIABLES_COUNT_CHANGED = L"VariablesCountChanged";
constexpr auto EVENT_NAME_LINE_WIDTH_CHANGED = L"LineWidthChanged";
TraceLogger ^ TraceLogger::GetInstance() TraceLogger ^ TraceLogger::GetInstance()
{ {
@ -86,4 +87,11 @@ namespace GraphControl
fields->AddInt64(StringReference(L"VariableCount"), variablesCount); fields->AddInt64(StringReference(L"VariableCount"), variablesCount);
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_VARIABLES_COUNT_CHANGED), fields); TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_VARIABLES_COUNT_CHANGED), fields);
} }
void TraceLogger::LogLineWidthChanged()
{
auto fields = ref new LoggingFields();
fields->AddString(StringReference(CALC_MODE), StringReference(GRAPHING_MODE));
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_LINE_WIDTH_CHANGED), fields);
}
} }

View File

@ -18,6 +18,7 @@ namespace GraphControl
void LogEquationCountChanged(int currentValidEquations, int currentInvalidEquations); void LogEquationCountChanged(int currentValidEquations, int currentInvalidEquations);
void LogFunctionAnalysisPerformed(int analysisErrorType, uint32 tooComplexFlag); void LogFunctionAnalysisPerformed(int analysisErrorType, uint32 tooComplexFlag);
void LogVariableCountChanged(int variablesCount); void LogVariableCountChanged(int variablesCount);
void LogLineWidthChanged();
private: private:
TraceLogger() TraceLogger()