| 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 gui_graph.h |
| 21 |
* |
| 22 |
* @author Kai Sterker |
| 23 |
* @brief View for the dialogue graph |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef GUI_GRAPH_H |
| 27 |
#define GUI_GRAPH_H |
| 28 |
|
| 29 |
#include "gui_scrollable.h" |
| 30 |
#include "gui_tooltip.h" |
| 31 |
#include "dlg_module.h" |
| 32 |
|
| 33 |
/** |
| 34 |
* The widget handling the graphical representation of the dialogue graph. |
| 35 |
* Displays a dialogue module and offers an interface for authors to edit |
| 36 |
* the dialogue. Only one instance of this class exists throughout the whole |
| 37 |
* dlgedit session. |
| 38 |
*/ |
| 39 |
class GuiGraph : public Scrollable |
| 40 |
{ |
| 41 |
public: |
| 42 |
/** |
| 43 |
* Constructor. Main purpose is to create the drawing area for the |
| 44 |
* graph and to register the GTK+ event callbacks used to catch |
| 45 |
* user input for this widget. |
| 46 |
* @param paned The GtkPaned that will hold the graph view widget. |
| 47 |
*/ |
| 48 |
GuiGraph (GtkWidget* paned); |
| 49 |
/** |
| 50 |
* Standard desctructor. |
| 51 |
*/ |
| 52 |
virtual ~GuiGraph (); |
| 53 |
|
| 54 |
/** |
| 55 |
* @name Changing the view |
| 56 |
*/ |
| 57 |
//@{ |
| 58 |
/** |
| 59 |
* Attach a dialogue module to the view for drawing. |
| 60 |
* @param m the DlgModule to display and edit. |
| 61 |
* @param cntr whether the module should be centered in the view |
| 62 |
*/ |
| 63 |
void attachModule (DlgModule *m, bool cntr = false); |
| 64 |
/** |
| 65 |
* Detach the dialogue module attached to the view. |
| 66 |
*/ |
| 67 |
void detachModule (); |
| 68 |
/** |
| 69 |
* Switch view to the given module. Just a convenience method. Calling |
| 70 |
* detachModule () followed by attachModule (m) will do the same. |
| 71 |
* @param m The module to display. |
| 72 |
*/ |
| 73 |
void switchModule (DlgModule *m); |
| 74 |
//@} |
| 75 |
|
| 76 |
/** |
| 77 |
* @name Drawing area handling methods. |
| 78 |
*/ |
| 79 |
//@{ |
| 80 |
/** |
| 81 |
* Highlight nodes when hit by the cursor. |
| 82 |
* @param point Current position of the cursor. |
| 83 |
*/ |
| 84 |
void mouseMoved (DlgPoint &point); |
| 85 |
/** |
| 86 |
* Draw everything to the backing pixmap. |
| 87 |
*/ |
| 88 |
void draw (); |
| 89 |
/** |
| 90 |
* Resize the drawing area (after the user resized the window). |
| 91 |
* @param widget The widget containing the drawing area. |
| 92 |
*/ |
| 93 |
void resizeSurface (GtkWidget *widget); |
| 94 |
/** |
| 95 |
* Clear the drawing area. |
| 96 |
*/ |
| 97 |
void clear (); |
| 98 |
/** |
| 99 |
* Center the displayed dialogue on the drawing area. |
| 100 |
*/ |
| 101 |
void center (); |
| 102 |
//@} |
| 103 |
|
| 104 |
/** |
| 105 |
* @name Node manipulation methods. |
| 106 |
*/ |
| 107 |
//@{ |
| 108 |
/** |
| 109 |
* Create a new DlgCircle at the given position. |
| 110 |
* @param pos Current cursor position |
| 111 |
* @param type Type of the new circle. |
| 112 |
* @return <b>true</b> if the circle could be created, |
| 113 |
* <b>false</b> otherwise. |
| 114 |
*/ |
| 115 |
bool newCircle (DlgPoint &pos, node_type type = NPC); |
| 116 |
/** |
| 117 |
* Create a new DlgArrow between the selected node and the given position. |
| 118 |
* @param pos Current cursor position |
| 119 |
* @return <b>true</b> if the link could be created, <b>false</b> otherwise. |
| 120 |
*/ |
| 121 |
bool newArrow (DlgPoint &pos); |
| 122 |
/** |
| 123 |
* Insert a subdialogue at the given position. Note that the position is |
| 124 |
* already relative to the graph's origin. |
| 125 |
* @param pos Current cursor position. |
| 126 |
* @return \b true if a subdialogue could be added, \b false otherwise. |
| 127 |
*/ |
| 128 |
bool newModule (DlgPoint &pos); |
| 129 |
/** |
| 130 |
* Edit currently selected node. |
| 131 |
* @return <b>true</b> if editing was successful, <b>false</b> otherwise. |
| 132 |
*/ |
| 133 |
bool editNode (); |
| 134 |
/** |
| 135 |
* Delete currently selected node. |
| 136 |
* @return <b>true</b> if deleting was successful, <b>false</b> otherwise. |
| 137 |
*/ |
| 138 |
bool deleteNode (); |
| 139 |
/** |
| 140 |
* Select the given node and update the instant preview and node editor |
| 141 |
* accordingly. |
| 142 |
* @param node the DlgNode to be selected |
| 143 |
* @return <b>true</b> if the node exists and was selected successfully, |
| 144 |
* <b>false</b> otherwise. |
| 145 |
*/ |
| 146 |
bool selectNode (DlgNode *node); |
| 147 |
/** |
| 148 |
* Select the node at the given position. |
| 149 |
* @param point the coordinates of the DlgNode to be selected |
| 150 |
* @return <b>true</b> if the node exists and was selected successfully, |
| 151 |
* <b>false</b> otherwise. |
| 152 |
*/ |
| 153 |
bool selectNode (DlgPoint &point); |
| 154 |
/** |
| 155 |
* Select the parent of the currently selected node (or the first node |
| 156 |
* in case no node is selected so far. |
| 157 |
* @return <b>true</b> if the node exists and was selected successfully, |
| 158 |
* <b>false</b> otherwise. |
| 159 |
*/ |
| 160 |
bool selectParent (); |
| 161 |
/** |
| 162 |
* Select the first child of the currently selected node (or the first |
| 163 |
* node in case no node is selected so far. |
| 164 |
* @return <b>true</b> if the node exists and was selected successfully, |
| 165 |
* <b>false</b> otherwise. |
| 166 |
*/ |
| 167 |
bool selectChild (); |
| 168 |
/** |
| 169 |
* Select a sibling of the currently selected node (or the first |
| 170 |
* node in case no node is selected so far. |
| 171 |
* @param pos Specifies whether to select the previous or the next sibling. |
| 172 |
* @return <b>true</b> if the sibling exists and was selected successfully, |
| 173 |
* <b>false</b> otherwise. |
| 174 |
*/ |
| 175 |
bool selectSibling (query_type pos); |
| 176 |
/** |
| 177 |
* Select the first node in the dialogue. |
| 178 |
* @return <b>true</b> on success, <b>false</b> otherwise. |
| 179 |
*/ |
| 180 |
bool selectRoot (); |
| 181 |
/** |
| 182 |
* Deselect the node currently selected. |
| 183 |
*/ |
| 184 |
void deselectNode (); |
| 185 |
/** |
| 186 |
* Center the view on the given node, as long as it does not lie in the |
| 187 |
* inner 60\% of the visible area. |
| 188 |
* @param node DlgNode to center the view on. |
| 189 |
* @return <b>true</b> if the node exists and was centered on, |
| 190 |
* <b>false</b> otherwise. |
| 191 |
*/ |
| 192 |
bool centerNode (DlgNode *node = NULL); |
| 193 |
//@} |
| 194 |
|
| 195 |
/** |
| 196 |
* @name Drag'n dropping of DlgNodes |
| 197 |
*/ |
| 198 |
//@{ |
| 199 |
/** |
| 200 |
* Prepare a DlgNode for dragging. Circles can be moved directly. |
| 201 |
* Arrows need to be attached to a temporary, invisible node. This |
| 202 |
* method takes care of that. |
| 203 |
* @param point position where the user started to drag the mouse. |
| 204 |
* @return <b>true</b> if a node is being dragged, <b>false</b> otherwise. |
| 205 |
*/ |
| 206 |
bool prepareDragging (DlgPoint &point); |
| 207 |
/** |
| 208 |
* As long as in dragging mode, this method will update the position |
| 209 |
* of the node being dragged. |
| 210 |
* @param point current cursor position. |
| 211 |
*/ |
| 212 |
void drag (DlgPoint &point); |
| 213 |
/** |
| 214 |
* Once the user releases the left mouse button, this method calculates |
| 215 |
* the final position. In case of an Arrow being dragged, it will be |
| 216 |
* attached to a node if possible. Otherwise, the former state will be |
| 217 |
* restored. |
| 218 |
* @param point current cursor position. |
| 219 |
*/ |
| 220 |
void stopDragging (DlgPoint &point); |
| 221 |
//@} |
| 222 |
|
| 223 |
/** |
| 224 |
* @name Auto-Scrolling (TM) ;) functionality. |
| 225 |
*/ |
| 226 |
//@{ |
| 227 |
/** |
| 228 |
* Moves the view in the desired direction. |
| 229 |
*/ |
| 230 |
virtual void scroll (); |
| 231 |
/** |
| 232 |
* Check whether it is allowed to initiate |
| 233 |
* scrolling. |
| 234 |
* @return false if scrolling is forbidden, true otherwise. |
| 235 |
*/ |
| 236 |
virtual bool scrollingAllowed () const; |
| 237 |
/** |
| 238 |
* Return a pointer to the drawing area |
| 239 |
* @return the GtkDrawingArea widget |
| 240 |
*/ |
| 241 |
virtual GtkWidget *drawingArea () const { return graph; } |
| 242 |
//@} |
| 243 |
|
| 244 |
/** |
| 245 |
* @name Member access methods. |
| 246 |
*/ |
| 247 |
//@{ |
| 248 |
/** |
| 249 |
* Returns the current offset of the attached DlgModule. |
| 250 |
* @return the absolute position of the view |
| 251 |
*/ |
| 252 |
DlgPoint *position () { return offset; } |
| 253 |
/** |
| 254 |
* Return a pointer to the drawing surface. |
| 255 |
* @return the drawing surface |
| 256 |
*/ |
| 257 |
cairo_surface_t *pixmap () { return surface; } |
| 258 |
/** |
| 259 |
* Return the attached dialogue module. |
| 260 |
* @return the DlgModule currently attached to the view |
| 261 |
*/ |
| 262 |
DlgModule *getAttached () { return module; } |
| 263 |
/** |
| 264 |
* Get the (toplevel) dialogue the attached module |
| 265 |
* belongs to. |
| 266 |
* @return The toplevel dialogue. |
| 267 |
*/ |
| 268 |
DlgModule *dialogue (); |
| 269 |
/** |
| 270 |
* Get the state of the attached module. |
| 271 |
* @return the attached DlgModule's state. |
| 272 |
*/ |
| 273 |
mode_type mode () { return module ? module->state () : IDLE; } |
| 274 |
//@} |
| 275 |
|
| 276 |
private: |
| 277 |
DlgNode *mover; // The node currently dragged |
| 278 |
DlgModule *module; // Module assigned to the graph view |
| 279 |
DlgPoint *offset; // Module's relative position to the origin |
| 280 |
GtkWidget *graph; // Drawing Area |
| 281 |
cairo_surface_t *surface; // Drawing surface |
| 282 |
DlgRect drawing_area; // Size of the Drawing Area |
| 283 |
GuiTooltip *tooltip; // Tooltip for displaying node-text |
| 284 |
}; |
| 285 |
|
| 286 |
#endif // GUI_GRAPH_H |