mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-21 14:50:44 +01:00
[apps/graph/graph] Add a banner view in the graph view
Change-Id: Iafa0dcfc730911264d5b045c14bde54f432f53a2
This commit is contained in:
@@ -19,17 +19,25 @@ GraphView::GraphView(FunctionStore * functionStore, GraphWindow * graphWindow) :
|
||||
{
|
||||
}
|
||||
|
||||
BannerView * GraphView::bannerView() {
|
||||
return &m_bannerView;
|
||||
}
|
||||
|
||||
int GraphView::numberOfSubviews() const {
|
||||
return 1;
|
||||
return 2;
|
||||
};
|
||||
|
||||
View * GraphView::subviewAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return &m_cursorView;
|
||||
assert(index >= 0 && index < 2);
|
||||
if (index == 0) {
|
||||
return &m_cursorView;
|
||||
}
|
||||
return &m_bannerView;
|
||||
}
|
||||
|
||||
void GraphView::setContext(Context * context) {
|
||||
m_context = context;
|
||||
m_bannerView.setContext(context);
|
||||
}
|
||||
|
||||
Context * GraphView::context() const {
|
||||
@@ -74,6 +82,7 @@ void GraphView::goToAbscissaOnFunction(float abscissa, Function * function) {
|
||||
float ordinate = function->evaluateAtAbscissa(abscissa, m_context);
|
||||
m_graphWindow->centerAxisAround(GraphWindow::Axis::Y, ordinate);
|
||||
m_yCursorPosition = floatToPixel(Axis::Vertical, ordinate);
|
||||
updateBannerView(function);
|
||||
reload();
|
||||
}
|
||||
|
||||
@@ -89,6 +98,7 @@ void GraphView::initCursorPosition() {
|
||||
float fCenter = firstFunction->evaluateAtAbscissa(center, m_context);
|
||||
m_xCursorPosition = (bounds().width()-1.0f)/2.0f;
|
||||
m_yCursorPosition = floatToPixel(Axis::Vertical, fCenter);
|
||||
updateBannerView(firstFunction);
|
||||
}
|
||||
|
||||
void GraphView::moveCursorHorizontally(KDCoordinate xOffset) {
|
||||
@@ -102,6 +112,7 @@ void GraphView::moveCursorHorizontally(KDCoordinate xOffset) {
|
||||
bool windowHasMoved = m_graphWindow->panToMakePointVisible(x, y, xMargin, yMargin);
|
||||
m_xCursorPosition = floatToPixel(Axis::Horizontal, x);
|
||||
m_yCursorPosition = floatToPixel(Axis::Vertical, y);
|
||||
updateBannerView(f);
|
||||
if (windowHasMoved) {
|
||||
reload();
|
||||
} else {
|
||||
@@ -134,6 +145,7 @@ Function * GraphView::moveCursorVertically(int direction) {
|
||||
markRectAsDirty(KDRect(KDPoint(roundf(m_xCursorPosition) - k_cursorSize/2, roundf(m_yCursorPosition)- k_cursorSize/2), k_cursorSize, k_cursorSize));
|
||||
m_xCursorPosition = floatToPixel(Axis::Horizontal, x);
|
||||
m_yCursorPosition = floatToPixel(Axis::Vertical, nextY);
|
||||
updateBannerView(nextFunction);
|
||||
if (windowHasMoved) {
|
||||
reload();
|
||||
} else {
|
||||
@@ -144,10 +156,13 @@ Function * GraphView::moveCursorVertically(int direction) {
|
||||
|
||||
void GraphView::layoutSubviews() {
|
||||
KDRect cursorFrame(roundf(m_xCursorPosition) - k_cursorSize/2, roundf(m_yCursorPosition) - k_cursorSize/2, k_cursorSize, k_cursorSize);
|
||||
KDRect bannerFrame(KDRect(0, bounds().height()- k_bannerHeight, bounds().width(), k_bannerHeight));
|
||||
if (!m_visibleCursor) {
|
||||
cursorFrame = KDRectZero;
|
||||
bannerFrame = KDRectZero;
|
||||
}
|
||||
m_cursorView.setFrame(cursorFrame);
|
||||
m_bannerView.setFrame(bannerFrame);
|
||||
}
|
||||
|
||||
void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
@@ -199,4 +214,9 @@ float GraphView::evaluateCurveAtAbscissa(void * curve, float abscissa) const {
|
||||
return f->evaluateAtAbscissa(abscissa, m_context);
|
||||
}
|
||||
|
||||
void GraphView::updateBannerView(Function * function) {
|
||||
m_bannerView.setAbscissa(xCursorPosition());
|
||||
m_bannerView.setFunction(function);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user