mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[apps/shared][apps/calculation] Create CurveView::drawLabel and use it
in complex_graph_view
This commit is contained in:
@@ -14,6 +14,10 @@ void ComplexGraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawAxes(ctx, rect);
|
||||
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());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -230,6 +230,49 @@ void CurveView::simpleDrawBothAxesLabels(KDContext * ctx, KDRect rect) const {
|
||||
drawLabels(ctx, rect, Axis::Horizontal, true);
|
||||
}
|
||||
|
||||
//TODO: factorize
|
||||
void CurveView::drawLabel(KDContext * ctx, KDRect rect, Axis axis, float grad) const {
|
||||
Axis otherAxis = (axis == Axis::Horizontal) ? Axis::Vertical : Axis::Horizontal;
|
||||
float axisCoordinate = std::round(floatToPixel(otherAxis, 0.0f));
|
||||
KDCoordinate labelPosition = std::round(floatToPixel(axis, grad));
|
||||
KDRect graduation = axis == Axis::Horizontal ?
|
||||
KDRect(
|
||||
labelPosition,
|
||||
axisCoordinate -(k_labelGraduationLength-2)/2,
|
||||
1,
|
||||
k_labelGraduationLength) :
|
||||
KDRect(
|
||||
axisCoordinate-(k_labelGraduationLength-2)/2,
|
||||
labelPosition,
|
||||
k_labelGraduationLength,
|
||||
1);
|
||||
ctx->fillRect(graduation, KDColorBlack);
|
||||
|
||||
char labelBuffer[k_labelBufferMaxSize];
|
||||
PrintFloat::ConvertFloatToText<float>(
|
||||
grad,
|
||||
labelBuffer,
|
||||
k_labelBufferMaxSize,
|
||||
k_labelBufferMaxGlyphLength,
|
||||
k_numberSignificantDigits,
|
||||
Preferences::PrintFloatMode::Decimal);
|
||||
|
||||
float xPosition = 0.0f;
|
||||
float yPosition = 0.0f;
|
||||
KDSize textSize = k_font->stringSize(labelBuffer);
|
||||
if (axis == Axis::Horizontal) {
|
||||
xPosition = labelPosition - textSize.width()/2;
|
||||
yPosition = axisCoordinate + k_labelMargin;
|
||||
} else {
|
||||
yPosition = labelPosition - textSize.height()/2;
|
||||
xPosition = axisCoordinate - k_labelMargin - textSize.width();
|
||||
}
|
||||
KDPoint origin = KDPoint(xPosition, yPosition);
|
||||
if (rect.intersects(KDRect(origin, textSize))) {
|
||||
ctx->drawString(labelBuffer, origin, k_font, KDColorBlack, KDColorWhite);
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin, bool graduationOnly, bool fixCoordinate, KDCoordinate fixedCoordinate, KDColor backgroundColor) const {
|
||||
int numberLabels = numberOfLabels(axis);
|
||||
if (numberLabels <= 1) {
|
||||
|
||||
@@ -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 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;
|
||||
CurveViewCursor * m_curveViewCursor;
|
||||
|
||||
Reference in New Issue
Block a user