mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] Shared: Factorize code: all FunctionGraphView have a member
indicating the selected function
This commit is contained in:
committed by
EmilieNumworks
parent
0dec52a708
commit
a6050fda55
@@ -12,8 +12,7 @@ GraphView::GraphView(SequenceStore * sequenceStore, InteractiveCurveViewRange *
|
||||
m_verticalCursor(false),
|
||||
m_highlightedDotStart(-1),
|
||||
m_highlightedDotEnd(-1),
|
||||
m_shouldColorHighlighted(false),
|
||||
m_selectedSequence(nullptr)
|
||||
m_shouldColorHighlighted(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -34,7 +33,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
continue;
|
||||
}
|
||||
drawDot(ctx, rect, x, y, s->color());
|
||||
if (x >= m_highlightedDotStart && x <= m_highlightedDotEnd && s == m_selectedSequence) {
|
||||
if (x >= m_highlightedDotStart && x <= m_highlightedDotEnd && s == m_selectedFunction) {
|
||||
KDColor color = m_shouldColorHighlighted ? s->color() : KDColorBlack;
|
||||
if (y >= 0.0f) {
|
||||
drawSegment(ctx, rect, Axis::Vertical, x, 0.0f, y, color, 1);
|
||||
@@ -63,14 +62,6 @@ void GraphView::reload() {
|
||||
}
|
||||
}
|
||||
|
||||
void GraphView::selectSequence(Sequence * sequence) {
|
||||
if (m_selectedSequence != sequence) {
|
||||
reload();
|
||||
m_selectedSequence = sequence;
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
void GraphView::setHighlight(int start, int end) {
|
||||
if (m_highlightedDotStart != start || m_highlightedDotEnd != end) {
|
||||
reload();
|
||||
|
||||
@@ -13,7 +13,6 @@ public:
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setVerticalCursor(bool verticalCursor);
|
||||
void reload() override;
|
||||
void selectSequence(Sequence * sequence);
|
||||
void setHighlight(int start, int end);
|
||||
void setHighlightColor(bool highlightColor);
|
||||
private:
|
||||
@@ -24,7 +23,6 @@ private:
|
||||
int m_highlightedDotStart;
|
||||
int m_highlightedDotEnd;
|
||||
bool m_shouldColorHighlighted;
|
||||
Sequence * m_selectedSequence;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ bool TermSumController::moveCursorHorizontallyToPosition(int position) {
|
||||
}
|
||||
|
||||
void TermSumController::setSequence(Sequence * sequence) {
|
||||
m_graphView->selectSequence(sequence);
|
||||
m_graphView->selectFunction(sequence);
|
||||
m_sequence = sequence;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Shared {
|
||||
FunctionGraphView::FunctionGraphView(InteractiveCurveViewRange * graphRange,
|
||||
CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
|
||||
CurveView(graphRange, cursor, bannerView, cursorView),
|
||||
m_selectedFunction(nullptr),
|
||||
m_xLabels{},
|
||||
m_yLabels{},
|
||||
m_context(nullptr)
|
||||
@@ -32,6 +33,14 @@ Context * FunctionGraphView::context() const {
|
||||
return m_context;
|
||||
}
|
||||
|
||||
void FunctionGraphView::selectFunction(Function * function) {
|
||||
if (m_selectedFunction != function) {
|
||||
reload();
|
||||
m_selectedFunction = function;
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
char * FunctionGraphView::label(Axis axis, int index) const {
|
||||
return (axis == Axis::Horizontal ? (char *)m_xLabels[index] : (char *)m_yLabels[index]);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "curve_view.h"
|
||||
#include "function.h"
|
||||
#include "../constant.h"
|
||||
#include "interactive_curve_view_range.h"
|
||||
|
||||
@@ -15,6 +16,9 @@ public:
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setContext(Poincare::Context * context);
|
||||
Poincare::Context * context() const;
|
||||
void selectFunction(Function * function);
|
||||
protected:
|
||||
Function * m_selectedFunction;
|
||||
private:
|
||||
char * label(Axis axis, int index) const override;
|
||||
char m_xLabels[k_maxNumberOfXLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)];
|
||||
|
||||
Reference in New Issue
Block a user