| 1 |
/* |
| 2 |
Copyright (C) 2002/2003 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_node.h |
| 21 |
* |
| 22 |
* @author Kai Sterker |
| 23 |
* @brief Base class for the dialogue objects. |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef DLG_NODE_H |
| 27 |
#define DLG_NODE_H |
| 28 |
|
| 29 |
#include <list> |
| 30 |
#include <string> |
| 31 |
#include <stdio.h> |
| 32 |
#include <fstream> |
| 33 |
#include "dlg_node_gfx.h" |
| 34 |
|
| 35 |
/* |
| 36 |
* Function to read the next token from dialogue source file |
| 37 |
* @param str used to return string values |
| 38 |
* @param i used to return numeric values |
| 39 |
* @return Type of token read as defined in dlg_types.h |
| 40 |
*/ |
| 41 |
extern int parse_dlgfile (std::string &str, int &i); |
| 42 |
|
| 43 |
/** |
| 44 |
* File pointer for dialogue source files being parsed. |
| 45 |
*/ |
| 46 |
extern FILE *loadlgin; |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* This is the base class for all dialogue objects. As this, it has three |
| 51 |
* major purposes: |
| 52 |
* |
| 53 |
* - provide means for a graphical representation of the node in the Graph |
| 54 |
* window. This functionality is inherited from the DlgNodeGfx class. |
| 55 |
* |
| 56 |
* - provide the glue between different Nodes, thus forming the actual graph. |
| 57 |
* |
| 58 |
* - provide a unique interface to the different flavours of Nodes in the |
| 59 |
* graph. |
| 60 |
*/ |
| 61 |
class DlgNode : public DlgNodeGfx |
| 62 |
{ |
| 63 |
public: |
| 64 |
DlgNode () { index_ = -1; } |
| 65 |
DlgNode (node_type t, DlgRect area); |
| 66 |
|
| 67 |
/** |
| 68 |
* @name Methods for graph traversal |
| 69 |
*/ |
| 70 |
//@{ |
| 71 |
/** |
| 72 |
* Get a node from this node's list of direct followers. |
| 73 |
* @param pos Defines what to do with the iterator of that list. |
| 74 |
* @param offset Move the iterator by that offset. |
| 75 |
* @return The node found at the specified offset from the given |
| 76 |
* iterator position. |
| 77 |
* @see query_type |
| 78 |
*/ |
| 79 |
DlgNode* next (query_type pos, int offset = 1); |
| 80 |
/** |
| 81 |
* Get a node from this node's list of direct predecessors. |
| 82 |
* @param pos Defines what to do with the iterator of that list. |
| 83 |
* @param offset Move the iterator by that offset. |
| 84 |
* @return The node found at the specified offset from the given |
| 85 |
* iterator position. |
| 86 |
* @see query_type |
| 87 |
*/ |
| 88 |
DlgNode* prev (query_type pos, int offset = 1); |
| 89 |
//@} |
| 90 |
|
| 91 |
/** |
| 92 |
* @name Node insertion |
| 93 |
*/ |
| 94 |
//@{ |
| 95 |
/** |
| 96 |
* Add a node to the list of predecessors. The nodes are sorted by their |
| 97 |
* position. The ones with the smallest y value come first; if nodes have |
| 98 |
* the same y value, then those with the smallest x value come first. |
| 99 |
* @param node the DlgNode to add. |
| 100 |
*/ |
| 101 |
void addPrev (DlgNode *node); |
| 102 |
/** |
| 103 |
* Add a node to the list of followers. |
| 104 |
* @param node the DlgNode to add. |
| 105 |
*/ |
| 106 |
void addNext (DlgNode *node); |
| 107 |
//@} |
| 108 |
|
| 109 |
/** |
| 110 |
* @name Node removal |
| 111 |
*/ |
| 112 |
//@{ |
| 113 |
/** |
| 114 |
* Remove a node from the list of precedessors. |
| 115 |
* @param node the DlgNode to remove. |
| 116 |
*/ |
| 117 |
void removePrev (DlgNode *node); |
| 118 |
/** |
| 119 |
* Remove a node from the list of followers. |
| 120 |
* @param node the DlgNode to remove. |
| 121 |
*/ |
| 122 |
void removeNext (DlgNode *node); |
| 123 |
//@} |
| 124 |
|
| 125 |
/** |
| 126 |
* Draw this node to the given surface. During drawing, the mode is |
| 127 |
* temporarily changed to the given mode. |
| 128 |
* @param surface the cairo_surface_t to draw to |
| 129 |
* @param offset the DlgPoint to use as offset |
| 130 |
* @param widget the GtkWidget to update after drawing |
| 131 |
* @param mode the new mode of the node |
| 132 |
*/ |
| 133 |
void draw (cairo_surface_t *surface, DlgPoint &offset, GtkWidget *widget, mode_type mode); |
| 134 |
|
| 135 |
/** |
| 136 |
* Draw this node to the given surface. |
| 137 |
* @param surface the cairo_surface_t to draw to |
| 138 |
* @param offset the DlgPoint to use as offset |
| 139 |
* @param widget the GtkWidget to update after drawing |
| 140 |
*/ |
| 141 |
virtual void draw (cairo_surface_t *surface, DlgPoint &offset, GtkWidget *widget) |
| 142 |
{ |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Save a node to file |
| 147 |
* @param out Stream to the file to save to |
| 148 |
*/ |
| 149 |
virtual void save (std::ofstream &out) { } |
| 150 |
|
| 151 |
/** |
| 152 |
* Get the type of the node. |
| 153 |
* @return the type of the node. |
| 154 |
*/ |
| 155 |
node_type &type () { return type_; } |
| 156 |
|
| 157 |
/** |
| 158 |
* Return the node's unique id. This is given when the node is |
| 159 |
* created and will never change from then on. It can be used |
| 160 |
* to correctly identify nodes of subdialogues and the like. |
| 161 |
* @return unique id of the node. |
| 162 |
*/ |
| 163 |
int node_id () { return nid_; } |
| 164 |
|
| 165 |
/** |
| 166 |
* Returns id of the module this node belongs to. It allows us |
| 167 |
* to tell nodes of different modules apart. Together with the |
| 168 |
* node id, this gives each node a unique id. |
| 169 |
* @return module id. |
| 170 |
*/ |
| 171 |
int module_id () { return mid_; } |
| 172 |
|
| 173 |
/** |
| 174 |
* Get the index of this node. Used by DlgCompile. |
| 175 |
* @return the node's index. |
| 176 |
*/ |
| 177 |
int index () { return index_; } |
| 178 |
|
| 179 |
/** |
| 180 |
* Set the index of this node. Used by DlgCompile. |
| 181 |
* @param i the index to use for this node. |
| 182 |
*/ |
| 183 |
void setIndex (int i) { index_ = i; } |
| 184 |
|
| 185 |
protected: |
| 186 |
node_type type_; // type of the node |
| 187 |
int index_; // used by DlgCompiler |
| 188 |
int nid_; // unique id of the node |
| 189 |
int mid_; // unique id of module node belongs to |
| 190 |
|
| 191 |
std::list<DlgNode*> prev_; // list of node's parents |
| 192 |
std::list<DlgNode*> next_; // list of node's children |
| 193 |
|
| 194 |
std::list<DlgNode*>::iterator p; // iterator over parents |
| 195 |
std::list<DlgNode*>::iterator n; // iterator over children |
| 196 |
|
| 197 |
DlgNode* getNode (std::list<DlgNode*>::iterator &it, |
| 198 |
std::list<DlgNode*> &lst, query_type &pos, int &offset); |
| 199 |
|
| 200 |
void drawPolygon (cairo_t *cr, const GdkColor *color, const bool & filled, const DlgPoint *points, const int &num_points); |
| 201 |
void drawCircle (cairo_t *cr, const GdkColor *color, const bool & filled, const int & x, const int & y, const int & radius); |
| 202 |
void drawRectangle (cairo_t *cr, const GdkColor *color, const bool & filled, const int & x, const int & y, const int & width, const int & height); |
| 203 |
}; |
| 204 |
|
| 205 |
#endif // DLG_NODE_H |