Add line width option (#1098)
* add line thickness * clean up * Fix pr comments
This commit is contained in:
@@ -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,9 +558,15 @@ 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)
|
||||
{
|
||||
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);
|
||||
@@ -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()
|
||||
|
Reference in New Issue
Block a user