[apps/shared][apps/calculation] Create a methods

Shared::CurveView::drawAxisLabel and use it in ComplexGraphView
This commit is contained in:
Émilie Feral
2019-10-14 10:40:22 +02:00
committed by Léa Saviot
parent 9c3dd84c42
commit f7942207f5
3 changed files with 13 additions and 2 deletions

View File

@@ -16,6 +16,8 @@ void ComplexGraphView::drawRect(KDContext * ctx, KDRect rect) const {
drawDot(ctx, rect, m_complex->x(), m_complex->y(), KDColorBlack);
drawLabel(ctx, rect, Axis::Horizontal, m_complex->x());
drawLabel(ctx, rect, Axis::Vertical, m_complex->y());
drawAxisLabel(ctx, rect, Axis::Horizontal, "Re", m_complex->x() > 0.0f);
drawAxisLabel(ctx, rect, Axis::Vertical, "Im", m_complex->y() > 0.0f);
}

View File

@@ -242,7 +242,7 @@ void CurveView::drawGraduation(KDContext * ctx, KDRect rect, Axis axis, float gr
ctx->fillRect(graduation, KDColorBlack);
}
void CurveView::privateDrawLabelOnly(KDContext * ctx, KDRect rect, Axis axis, float grad, char * label, float verticalCoordinate, float horizontalCoordinate, FloatingPosition floatingLabels, bool shiftOrigin, KDCoordinate viewHeight, KDColor backgroundColor) const {
void CurveView::privateDrawLabelOnly(KDContext * ctx, KDRect rect, Axis axis, float grad, const char * label, float verticalCoordinate, float horizontalCoordinate, FloatingPosition floatingLabels, bool shiftOrigin, KDCoordinate viewHeight, KDColor backgroundColor) const {
KDCoordinate labelPosition = std::round(floatToPixel(axis, grad));
KDSize textSize = k_font->stringSize(label);
float xPosition = 0.0f;
@@ -287,6 +287,14 @@ void CurveView::privateDrawLabelOnly(KDContext * ctx, KDRect rect, Axis axis, fl
}
}
void CurveView::drawAxisLabel(KDContext * ctx, KDRect rect, Axis axis, const char * label, bool minExtremityPosition) const {
float verticalCoordinate = std::round(floatToPixel(Axis::Vertical, 0.0f));
float horizontalCoordinate = std::round(floatToPixel(Axis::Horizontal, 0.0f));
float position = minExtremityPosition ? min(axis) : max(axis);
position *= 0.9f;
privateDrawLabelOnly(ctx, rect, axis, position, label, verticalCoordinate, horizontalCoordinate);
}
void CurveView::drawLabel(KDContext * ctx, KDRect rect, Axis axis, float grad) const {
drawGraduation(ctx, rect, axis, grad);

View File

@@ -72,6 +72,7 @@ protected:
bool fillBar, KDColor defaultColor, KDColor highlightColor, float highlightLowerBound = INFINITY, float highlightUpperBound = -INFINITY) const;
void computeLabels(Axis axis);
void simpleDrawBothAxesLabels(KDContext * ctx, KDRect rect) const;
void drawAxisLabel(KDContext * ctx, KDRect rect, Axis axis, const char * label, bool minExtremityPosition) const;
void drawLabel(KDContext * ctx, KDRect rect, Axis axis, float grad) const;
void drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin, bool graduationOnly = false, bool fixCoordinate = false, KDCoordinate fixedCoordinate = 0, KDColor backgroundColor = KDColorWhite) const;
View * m_bannerView;
@@ -84,7 +85,7 @@ private:
Min,
Max
};
void privateDrawLabelOnly(KDContext * ctx, KDRect rect, Axis axis, float grad, char * label, float verticalCoordinate, float horizontalCoordinate, FloatingPosition floatingLabels = FloatingPosition::None, bool shiftOrigin = false, KDCoordinate viewHeight = 0, KDColor backgroundColor = KDColorWhite) const;
void privateDrawLabelOnly(KDContext * ctx, KDRect rect, Axis axis, float grad, const char * label, float verticalCoordinate, float horizontalCoordinate, FloatingPosition floatingLabels = FloatingPosition::None, bool shiftOrigin = false, KDCoordinate viewHeight = 0, KDColor backgroundColor = KDColorWhite) const;
void drawGridLines(KDContext * ctx, KDRect rect, Axis axis, float step, KDColor boldColor, KDColor lightColor) const;
/* The window bounds are deduced from the model bounds but also take into
account a margin (computed with k_marginFactor) */