1 // -*- C++ -*- 2 3 /* 4 * Gnome Chemistry Utils 5 * gccv/bezier-arrow.h 6 * 7 * Copyright (C) 2009-2010 Jean Bréfort <jean.brefort@normalesup.org> 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License as 11 * published by the Free Software Foundation; either version 3 of the 12 * License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 22 * USA 23 */ 24 25 #ifndef GCCV_BEZIER_ARROW_H 26 #define GCCV_BEZIER_ARROW_H 27 28 #include "line-item.h" 29 #include "structs.h" 30 31 /*!\file*/ 32 33 namespace gccv { 34 35 /*! 36 @brief Curved arrows. 37 38 Arrow composed of a Bezier cubic curve and an arrow head. 39 */ 40 class BezierArrow: public LineItem { 41 public: 42 /*! 43 @param canvas a Canvas. 44 45 Creates a new BezierArrow with a full head and sets 46 it as a child of the root Group of \a canvas. 47 */ 48 BezierArrow (Canvas *canvas); 49 /*! 50 @param parent the Group to which the new BezierArrow will be added. 51 @param client the ItemClient for the new BezierArrow if any. 52 53 Creates a new BezierArrow with a full head inside 54 \a parent and sets \a client as its associated ItemClient. 55 */ 56 BezierArrow (Group *parent, ItemClient *client = NULL); 57 /*! 58 The destructor. 59 */ 60 virtual ~BezierArrow (); 61 62 // virtual methods 63 /*! 64 @param x horizontal position 65 @param y vertical position 66 @param item where to store the Item. 67 68 Implementation of Item::Distance() for the BezierArrow class. Sets \a item to \a this. 69 */ 70 double Distance (double x, double y, Item **item) const; 71 /*! 72 @param cr a cairo_t. 73 @param is_vector whether the cairo_t is a vectorial context. 74 75 Draws the BezierArrow to \a cr. 76 */ 77 void Draw (cairo_t *cr, bool is_vector) const; 78 /*! 79 @param x the horizontal deplacement 80 @param y the vertical deplacement 81 82 Moves the BezierArrow. 83 */ 84 void Move (double x, double y); 85 86 protected: 87 /*! 88 Evaluates the BezierArrow bounds. 89 */ 90 void UpdateBounds (); 91 92 public: 93 /*! 94 @param x0 where to store the horizontal coordinate of the first control point. 95 @param y0 where to store the horizontal coordinate of the first control point. 96 @param x1 where to store the horizontal coordinate of the second control point. 97 @param y1 where to store the horizontal coordinate of the second control point. 98 @param x2 where to store the horizontal coordinate of the third control point. 99 @param y2 where to store the horizontal coordinate of the third control point. 100 @param x3 where to store the horizontal coordinate of the fourth control point. 101 @param y3 where to store the horizontal coordinate of the fourth control point. 102 103 Retrieves the coordinates of the four control points used to build the Bezier 104 cubic curve. 105 */ 106 void GetControlPoints (double &x0, double &y0, double &x1, double &y1, double &x2, double &y2, double &x3, double &y3); 107 /*! 108 @param x0 the new horizontal coordinate of the first control point. 109 @param y0 the new horizontal coordinate of the first control point. 110 @param x1 the new horizontal coordinate of the second control point. 111 @param y1 the new horizontal coordinate of the second control point. 112 @param x2 the new horizontal coordinate of the third control point. 113 @param y2 the new horizontal coordinate of the third control point. 114 @param x3 the new horizontal coordinate of the fourth control point. 115 @param y3 the new horizontal coordinate of the fourth control point. 116 117 Sets the coordinates of the four control points used to build the Bezier 118 cubic curve. 119 */ 120 void SetControlPoints (double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3); 121 122 /*!\fn SetHead(ArrowHeads Head) 123 @param Head the ArrowHeads for the end position of the arrow. 124 125 Sets the arrow head type at the segment end position. 126 */ 127 /*!\fn GetHead() 128 @return the ArrowHeads for the end position of the arrow. 129 */ 130 GCCV_ITEM_POS_PROP (ArrowHeads, Head) 131 /*!\fn SetA(double A) 132 @param A new arrow head size parameter. 133 134 Sets the distance from tip of arrowhead to center. 135 */ 136 /*!\fn GetA() 137 @return the distance from tip of arrowhead to center. 138 */ 139 GCCV_ITEM_POS_PROP (double, A) 140 /*!\fn SetB(double B) 141 @param B new arrow head size parameter. 142 143 Sets the distance from tip of arrowhead to trailing point, measured along shaft. 144 */ 145 /*!\fn GetB() 146 @return the distance from tip of arrowhead to trailing point, measured along 147 shaft. 148 */ 149 GCCV_ITEM_POS_PROP (double, B) 150 /*!\fn SetC(double C) 151 @param C new arrow head size parameter. 152 153 Sets the distance of arrowhead trailing points from outside edge of shaft. 154 */ 155 /*!\fn GetC() 156 @return the distance of arrowhead trailing points from outside edge of shaft. 157 */ 158 GCCV_ITEM_POS_PROP (double, C) 159 /*!\fn SetShowControls(bool ShowControls) 160 @param ShowControls whether to show control points. 161 162 If set to true, the control points will be displayed as squares. Lhe size of 163 these squares is five times the line witdth. 164 */ 165 /*!\fn GetShowControls() 166 @return whether the controlpoints are currently displayed (if the arrow is 167 visible, see Item::SetVisible()). 168 */ 169 GCCV_ITEM_POS_PROP (bool, ShowControls) 170 171 private: 172 Point m_Controls[4]; 173 }; 174 175 } 176 177 178 #endif // GCCV_BEZIER_ARROW_H 179