Add line width option (#1098)
* add line thickness * clean up * Fix pr comments
This commit is contained in:
parent
fc19ddcbcb
commit
7dcfe0439c
@ -4414,6 +4414,26 @@
|
||||
<value>Graph Options</value>
|
||||
<comment>Heading for the Graph Options flyout in Graphing mode.</comment>
|
||||
</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">
|
||||
<value>Enter an expression</value>
|
||||
<comment>this is the placeholder text used by the textbox to enter an equation</comment>
|
||||
|
@ -183,6 +183,35 @@
|
||||
Style="{StaticResource TrigUnitsRadioButtonStyle}"
|
||||
IsChecked="{x:Bind ViewModel.TrigModeGradians, Mode=TwoWay}"/>
|
||||
</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>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
@ -66,3 +66,25 @@ void GraphingSettings::ResetViewButton_Clicked(Object ^ sender, RoutedEventArgs
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ namespace CalculatorApp
|
||||
Windows::UI::Xaml::Style ^ SelectTextBoxStyle(bool incorrectRange, bool error);
|
||||
void SetGrapher(GraphControl::Grapher ^ grapher);
|
||||
void RefreshRanges();
|
||||
|
||||
static Platform::String ^ GetLineWidthAutomationName(double width);
|
||||
private:
|
||||
void GridSettingsTextBox_PreviewKeyDown(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e);
|
||||
void ResetViewButton_Clicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
|
@ -34,6 +34,7 @@ DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Variables);
|
||||
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Equations);
|
||||
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, AxesColor);
|
||||
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, GraphBackground);
|
||||
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, LineWidth);
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -405,7 +406,7 @@ namespace GraphControl
|
||||
initResult = m_graph->TryInitialize();
|
||||
if (initResult != nullopt)
|
||||
{
|
||||
UpdateGraphOptions(m_graph->GetOptions(), vector<Equation^>());
|
||||
UpdateGraphOptions(m_graph->GetOptions(), vector<Equation ^>());
|
||||
SetGraphArgs(m_graph);
|
||||
|
||||
m_renderMain->Graph = m_graph;
|
||||
@ -525,7 +526,6 @@ namespace GraphControl
|
||||
Variables->Insert(variableName, ref new Variable(newValue));
|
||||
}
|
||||
|
||||
|
||||
if (m_graph != nullptr && m_renderMain != nullptr)
|
||||
{
|
||||
auto workItemHandler = ref new WorkItemHandler([this, variableName, newValue](IAsyncAction ^ action) {
|
||||
@ -558,10 +558,16 @@ namespace GraphControl
|
||||
auto lineColor = eq->LineColor;
|
||||
graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A);
|
||||
|
||||
if (eq->GraphedEquation != nullptr && !eq->HasGraphError && eq->IsSelected)
|
||||
if (eq->GraphedEquation)
|
||||
{
|
||||
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);
|
||||
}
|
||||
@ -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)
|
||||
{
|
||||
if (keepCurrentView)
|
||||
|
@ -50,7 +50,7 @@ public
|
||||
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, 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
|
||||
property bool ActiveTracing
|
||||
{
|
||||
@ -276,6 +276,7 @@ public
|
||||
void OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue);
|
||||
void OnAxesColorPropertyChanged(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 OnEquationStyleChanged(Equation ^ equation);
|
||||
void OnEquationLineEnabledChanged(Equation ^ equation);
|
||||
|
@ -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)
|
||||
{
|
||||
m_color = color;
|
||||
@ -63,7 +69,5 @@ void NearestPointRenderer::SetColor(const ColorF& color)
|
||||
void NearestPointRenderer::CreateBrush()
|
||||
{
|
||||
m_brush.Reset();
|
||||
ThrowIfFailed(
|
||||
m_deviceResources->GetD2DDeviceContext()->CreateSolidColorBrush(m_color, &m_brush)
|
||||
);
|
||||
ThrowIfFailed(m_deviceResources->GetD2DDeviceContext()->CreateSolidColorBrush(m_color, &m_brush));
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ namespace GraphControl::DX
|
||||
void Render(const Windows::Foundation::Point& location);
|
||||
|
||||
void SetColor(const D2D1::ColorF& color);
|
||||
void SetRadius(float radius);
|
||||
|
||||
private:
|
||||
void CreateBrush();
|
||||
|
@ -187,6 +187,11 @@ namespace GraphControl::DX
|
||||
return m_Tracing;
|
||||
}
|
||||
|
||||
void RenderMain::SetPointRadius(float radius)
|
||||
{
|
||||
m_nearestPointRenderer.SetRadius(radius);
|
||||
}
|
||||
|
||||
bool RenderMain::RunRenderPass()
|
||||
{
|
||||
// Non async render passes cancel if they can't obtain the lock immediatly
|
||||
|
@ -47,6 +47,8 @@ namespace GraphControl::DX
|
||||
|
||||
bool RenderMain::CanRenderPoint();
|
||||
|
||||
void SetPointRadius(float radius);
|
||||
|
||||
bool RunRenderPass();
|
||||
|
||||
Windows::Foundation::IAsyncAction ^ RunRenderPassAsync(bool allowCancel = true);
|
||||
|
@ -23,6 +23,7 @@ namespace GraphControl
|
||||
constexpr auto EVENT_NAME_EQUATION_COUNT_CHANGED = L"EquationCountChanged";
|
||||
constexpr auto EVENT_NAME_FUNCTION_ANALYSIS_PERFORMED = L"FunctionAnalysisPerformed";
|
||||
constexpr auto EVENT_NAME_VARIABLES_COUNT_CHANGED = L"VariablesCountChanged";
|
||||
constexpr auto EVENT_NAME_LINE_WIDTH_CHANGED = L"LineWidthChanged";
|
||||
|
||||
TraceLogger ^ TraceLogger::GetInstance()
|
||||
{
|
||||
@ -86,4 +87,11 @@ namespace GraphControl
|
||||
fields->AddInt64(StringReference(L"VariableCount"), variablesCount);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace GraphControl
|
||||
void LogEquationCountChanged(int currentValidEquations, int currentInvalidEquations);
|
||||
void LogFunctionAnalysisPerformed(int analysisErrorType, uint32 tooComplexFlag);
|
||||
void LogVariableCountChanged(int variablesCount);
|
||||
void LogLineWidthChanged();
|
||||
|
||||
private:
|
||||
TraceLogger()
|
||||
|
Loading…
Reference in New Issue
Block a user