23 #include <cairo/cairo.h>
45 void findArrowHeadPoints(
float xBase,
float yBase,
float xPoint,
float yPoint,
float headToLengthRatio,
float width){
46 vecX=xPoint-xBase,
vecY=yPoint-yBase;
47 float shaftLength=sqrt(powf(
vecX,2.)+powf(vecY,2.));
48 float theta=2*M_PI*.25;
49 float cosTheta=cos(theta), sinTheta=sin(theta);
50 float unitX=
vecX/shaftLength, unitY=vecY/shaftLength;
51 float rotX=unitX*cosTheta-unitY*sinTheta, rotY=unitX*sinTheta+unitY*cosTheta;
52 float orthX=rotX*width, orthY=rotY*width;
55 ySide1=yPoint-vecY*headToLengthRatio+orthY;
56 ySide2=yPoint-vecY*headToLengthRatio-orthY;
87 CairoArrow(cairo_t *cr,
float xBase,
float yBase,
float xPoint,
float yPoint,
float headToLengthRatio,
float width,
bool closed,
bool filled) {
88 draw(cr, xBase, yBase, xPoint, yPoint, headToLengthRatio, width, closed, filled);
103 void draw(cairo_t *cr,
float xBase,
float yBase,
float xPoint,
float yPoint,
float headToLengthRatio,
float width,
bool closed,
bool filled) {
105 cairo_move_to (cr, xBase, yBase);
108 scale=headToLengthRatio;
109 cairo_line_to (cr, xBase+
vecX*(1-scale), yBase+
vecY*(1-scale));
112 if (filled || closed)
113 cairo_new_sub_path (cr);
115 cairo_line_to (cr, xPoint, yPoint);
117 if (filled || closed)
118 cairo_close_path(cr);
129 #endif // CAIROARROW_H_