[apps/shared] CurveView: change drawArrow API to take arrow shape

arguments in float instead of coordinates
This commit is contained in:
Émilie Feral
2020-05-19 10:39:45 +02:00
parent 0f8f82b94b
commit c826c53659
2 changed files with 19 additions and 27 deletions

View File

@@ -449,7 +449,7 @@ void CurveView::drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor
}
void CurveView::drawArrow(KDContext * ctx, KDRect rect, float x, float y, float dx, float dy, KDColor color, KDCoordinate pixelArrowWith, float tanAngle) const {
void CurveView::drawArrow(KDContext * ctx, KDRect rect, float x, float y, float dx, float dy, KDColor color, float arrowWidth, float tanAngle) const {
/* Let's call the following variables L and l:
*
* / |
@@ -472,23 +472,16 @@ void CurveView::drawArrow(KDContext * ctx, KDRect rect, float x, float y, float
// We can't draw an arrow without any orientation
return;
}
/* We compute the arrow segments in pixels
* Warning: the computed values are relative so we need to add/subtract the
* pixel position of 0s. */
float x0Pixel = floatToPixel(Axis::Horizontal, 0.0f);
float y0Pixel = floatToPixel(Axis::Vertical, 0.0f);
float dxPixel = floatToPixel(Axis::Horizontal, dx) - x0Pixel;
float dyPixel = y0Pixel - floatToPixel(Axis::Vertical, dy);
float dx2dy2 = std::sqrt(dxPixel*dxPixel+dyPixel*dyPixel);
float l = pixelArrowWith;
float l = arrowWidth/2.0f;
float L = l/tanAngle;
float dx2dy2 = std::sqrt(dx*dx+dy*dy);
float arrow1dx = pixelToFloat(Axis::Horizontal, x0Pixel + L*dxPixel/dx2dy2 + l*dyPixel/dx2dy2);
float arrow1dy = pixelToFloat(Axis::Vertical, y0Pixel - (L*dyPixel/dx2dy2 - l*dxPixel/dx2dy2));
float arrow1dx = L*dx/dx2dy2 + l*dy/dx2dy2;
float arrow1dy = L*dy/dx2dy2 - l*dx/dx2dy2;
drawSegment(ctx, rect, x, y, x - arrow1dx, y - arrow1dy, color, false);
float arrow2dx = pixelToFloat(Axis::Horizontal, x0Pixel + L*dxPixel/dx2dy2 - l*dyPixel/dx2dy2);
float arrow2dy = pixelToFloat(Axis::Vertical, y0Pixel - (L*dyPixel/dx2dy2 + l*dxPixel/dx2dy2));
float arrow2dx = L*dx/dx2dy2 - l*dy/dx2dy2;
float arrow2dy = L*dy/dx2dy2 + l*dx/dx2dy2;
drawSegment(ctx, rect, x, y, x - arrow2dx, y - arrow2dy, color, false);
}

View File

@@ -77,29 +77,28 @@ protected:
void drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, Size size = Size::Small) const;
/* 'drawArrow' draws the edge of an arrow pointing to (x,y) with the
* orientation (dx,dy).
* The parameters defining the shape of the arrow are the length in pixel of
* half the base of the arrow triangle - 'pixelArrowWith' - and the tangent
* of the angle between the segment and each wing of the arrow called
* 'tanAngle'.
* The parameters defining the shape of the arrow are the length of the base
* of the arrow triangle - 'arrowWith' - and the tangent of the angle between
* the segment and each wing of the arrow called 'tanAngle'.
*
* / |
* / |
* / l
* / |
* / \ |
* / \ angle |
* <--------------------------------------------------
* \
* \
* \
* \
* \
* <----------------------------l---------------------
* \ |
* \ |
* \ |
* \ |
* \ |
*
* <--- L --->
*
* l = pixelArrowWith
* l = arrowWith
* tanAngle = tan(angle) = l/L
*/
void drawArrow(KDContext * ctx, KDRect rect, float x, float y, float dx, float dy, KDColor color, KDCoordinate pixelArrowWith = 4, float tanAngle = 0.4f) const;
void drawArrow(KDContext * ctx, KDRect rect, float x, float y, float dx, float dy, KDColor color, float arrowWith = 4, float tanAngle = 0.4f) const; // 0.3639 = tan(20°)
void drawGrid(KDContext * ctx, KDRect rect) const;
void drawAxes(KDContext * ctx, KDRect rect) const;
void drawAxis(KDContext * ctx, KDRect rect, Axis axis) const;