| 1 |
/* |
| 2 |
Copyright (C) 2002 Kai Sterker <[email protected]> |
| 3 |
Part of the Adonthell Project <http://adonthell.nongnu.org> |
| 4 |
|
| 5 |
Dlgedit is free software; you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU General Public License as published by |
| 7 |
the Free Software Foundation; either version 2 of the License, or |
| 8 |
(at your option) any later version. |
| 9 |
|
| 10 |
Dlgedit is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with Dlgedit. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
/** |
| 20 |
* @file dlg_arrow.h |
| 21 |
* |
| 22 |
* @author Kai Sterker |
| 23 |
* @brief The node linking two DlgCircle's. |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef DLG_ARROW_H |
| 27 |
#define DLG_ARROW_H |
| 28 |
|
| 29 |
#include "dlg_node.h" |
| 30 |
|
| 31 |
/** |
| 32 |
* This node type's sole purpose is to link any two DlgCircles. |
| 33 |
* It's graphical representation is an arrow, hence the name. |
| 34 |
*/ |
| 35 |
class DlgArrow : public DlgNode |
| 36 |
{ |
| 37 |
public: |
| 38 |
/** |
| 39 |
* Create a new arrow. |
| 40 |
*/ |
| 41 |
DlgArrow () { mode_ = IDLE; type_ = LINK; nid_ = 0; } |
| 42 |
/** |
| 43 |
* Create a new link between two nodes. |
| 44 |
* @param s The node where the link starts. |
| 45 |
* @param e The node the link points to. |
| 46 |
*/ |
| 47 |
DlgArrow (DlgNode *s, DlgNode *e); |
| 48 |
/** |
| 49 |
* Detach the arrow from it's start and end circle. |
| 50 |
*/ |
| 51 |
~DlgArrow (); |
| 52 |
|
| 53 |
/** |
| 54 |
* Calculate the arrow's shape. Call this function every time either |
| 55 |
* it's start- or end-circle has moved. |
| 56 |
*/ |
| 57 |
void initShape (); |
| 58 |
|
| 59 |
/** |
| 60 |
* Draw this node to the given surface with the specified offset. |
| 61 |
* The node's current mode determines the color thw node is drawn with. |
| 62 |
* @param surface the cairo_surface_t to draw to |
| 63 |
* @param offset the DlgPoint to use as offset |
| 64 |
* @param widget the GtkWidget to update after drawing |
| 65 |
*/ |
| 66 |
void draw (cairo_surface_t *surface, DlgPoint &offset, GtkWidget *widget); |
| 67 |
|
| 68 |
/** |
| 69 |
* Init the Arrow from a file. The file to load from is a global |
| 70 |
* variable, as loading is handled by a scanner generated with flex. |
| 71 |
* @param module The dialogue this arrow belongs to. |
| 72 |
* @return <b>true</b> if loading was successful, <b>false</b> |
| 73 |
* otherwise. |
| 74 |
*/ |
| 75 |
bool load (DlgNode *module); |
| 76 |
|
| 77 |
/** |
| 78 |
* save an Arrow to a file |
| 79 |
* @param file Stream to an open file |
| 80 |
*/ |
| 81 |
void save (std::ofstream &file); |
| 82 |
|
| 83 |
/** |
| 84 |
* Check whether the arrow is located at the given point. |
| 85 |
* @return <b>true</b> if this is the case, <b>false</b> otherwise. |
| 86 |
*/ |
| 87 |
bool operator== (DlgPoint &point); |
| 88 |
|
| 89 |
/** |
| 90 |
* Get the arrow's head. |
| 91 |
* @return position of the arrow's head. |
| 92 |
*/ |
| 93 |
DlgPoint getTip () { return DlgPoint (line[1]); } |
| 94 |
|
| 95 |
/** |
| 96 |
* Get the arrow's tail. |
| 97 |
* @return position of the arrow's tail. |
| 98 |
*/ |
| 99 |
DlgPoint getTail () { return DlgPoint (line[0]); } |
| 100 |
|
| 101 |
private: |
| 102 |
/** |
| 103 |
* Calculate intersection of arrow line and node shape. This works |
| 104 |
* as follows: |
| 105 |
* |
| 106 |
* We have a rectangle that represents the shape of the start node. |
| 107 |
* The start of the arrow's line lies in the center of this rectangle, |
| 108 |
* and it will obviously pass through exactly one of its four sides. |
| 109 |
* |
| 110 |
* To find out which side, we split the rectangle into four quadrants, |
| 111 |
* with the start point as origin. Then we check through which of the |
| 112 |
* four quadrants above line runs. |
| 113 |
* |
| 114 |
* That way, only two sides will remain for the intersection. To figure |
| 115 |
* out the right one, we compare the line with the angle bisection of |
| 116 |
* its quadrant. |
| 117 |
* |
| 118 |
* Now that we know the side, we also know one coordinate of the |
| 119 |
* intersection. We can simply insert this into the equation of the |
| 120 |
* line and calculate the second coordinate. Voila: we have the point |
| 121 |
* where the arrow intersects with the node. |
| 122 |
* |
| 123 |
* @param start Point where the arrow starts |
| 124 |
* @param end Point where the arrow ends |
| 125 |
* @param shape Shape of the start node |
| 126 |
* |
| 127 |
* @return The intersection of arrow and start node. |
| 128 |
*/ |
| 129 |
DlgPoint getIntersection (DlgPoint &start, DlgPoint &end, DlgRect &shape); |
| 130 |
|
| 131 |
GdkPoint line[2]; // the arrow's line |
| 132 |
GdkPoint tip[3]; // the arrow's tip |
| 133 |
}; |
| 134 |
|
| 135 |
#endif // DLG_ARROW_H |