| 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_mover.cc |
| 21 |
* |
| 22 |
* @author Kai Sterker |
| 23 |
* @brief A dummy node for drag'n dropping DlgArrows. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "dlg_mover.h" |
| 27 |
|
| 28 |
// create a new mover |
| 29 |
DlgMover::DlgMover (DlgPoint &p) |
| 30 |
{ |
| 31 |
// Let position be the center of the mover |
| 32 |
top_left = DlgPoint (p.x () - 15, p.y () - 15); |
| 33 |
bottom_right = DlgPoint (x () + 30, y () + 30); |
| 34 |
|
| 35 |
type_ = MOVER; |
| 36 |
moving = NONE; |
| 37 |
oldCircle = NULL; |
| 38 |
} |
| 39 |
|
| 40 |
// attach an arrow to the mover |
| 41 |
bool DlgMover::attach (DlgArrow *arrow) |
| 42 |
{ |
| 43 |
// Is arrow dragged by its tip? |
| 44 |
if (contains (arrow->getTip ())) |
| 45 |
{ |
| 46 |
// save old Circle, in case we have to abort dragging |
| 47 |
oldCircle = arrow->next (FIRST); |
| 48 |
|
| 49 |
// remember what we are moving |
| 50 |
moving = TIP; |
| 51 |
|
| 52 |
// connect mover and arrow |
| 53 |
arrow->removeNext (oldCircle); |
| 54 |
arrow->addNext (this); |
| 55 |
|
| 56 |
// finally attach the arrow |
| 57 |
prev_.push_back (arrow); |
| 58 |
|
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
// arrow dragged by its tail? |
| 63 |
if (contains (arrow->getTail ())) |
| 64 |
{ |
| 65 |
// save old Circle, in case we have to abort dragging |
| 66 |
oldCircle = arrow->prev (FIRST); |
| 67 |
|
| 68 |
// remember what we are moving |
| 69 |
moving = TAIL; |
| 70 |
|
| 71 |
// connect mover and arrow |
| 72 |
arrow->removePrev (oldCircle); |
| 73 |
arrow->addPrev (this); |
| 74 |
|
| 75 |
// finally attach the arrow |
| 76 |
next_.push_back (arrow); |
| 77 |
|
| 78 |
return true; |
| 79 |
} |
| 80 |
|
| 81 |
return false; |
| 82 |
} |
| 83 |
|
| 84 |
// drop the arrow onto the given node, if possible |
| 85 |
void DlgMover::drop (DlgNode *node) |
| 86 |
{ |
| 87 |
// get the arrow attached to this mover |
| 88 |
DlgNode *arrow = (moving == TIP ? prev_.front () : next_.front ()); |
| 89 |
DlgNode *circle; |
| 90 |
|
| 91 |
// test whether node is any good |
| 92 |
if (node == NULL || node->type () == LINK || |
| 93 |
node == arrow->next (FIRST) || node == arrow->prev (FIRST)) |
| 94 |
circle = oldCircle; |
| 95 |
else |
| 96 |
circle = node; |
| 97 |
|
| 98 |
// tail was moved |
| 99 |
if (moving == TAIL) |
| 100 |
{ |
| 101 |
// do not link two player nodes |
| 102 |
if (circle->type () == PLAYER && arrow->next (FIRST)->type () == PLAYER) |
| 103 |
circle = oldCircle; |
| 104 |
|
| 105 |
// remove arrow from old circle |
| 106 |
oldCircle->removeNext (arrow); |
| 107 |
arrow->removePrev (this); |
| 108 |
|
| 109 |
// connect circle and arrow |
| 110 |
circle->addNext (arrow); |
| 111 |
arrow->addPrev (circle); |
| 112 |
|
| 113 |
// reorder precedessor of arrow |
| 114 |
arrow->next (FIRST)->removePrev (arrow); |
| 115 |
arrow->next (FIRST)->addPrev (arrow); |
| 116 |
} |
| 117 |
|
| 118 |
// tip was moved |
| 119 |
else |
| 120 |
{ |
| 121 |
// do not link two player nodes |
| 122 |
if (circle->type () == PLAYER && arrow->prev (FIRST)->type () == PLAYER) |
| 123 |
circle = oldCircle; |
| 124 |
|
| 125 |
// remove arrow from old circle |
| 126 |
oldCircle->removePrev (arrow); |
| 127 |
arrow->removeNext (this); |
| 128 |
|
| 129 |
// connect circle and arrow |
| 130 |
circle->addPrev (arrow); |
| 131 |
arrow->addNext (circle); |
| 132 |
|
| 133 |
// reorder precedessor of arrow |
| 134 |
arrow->prev (FIRST)->removeNext (arrow); |
| 135 |
arrow->prev (FIRST)->addNext (arrow); |
| 136 |
} |
| 137 |
|
| 138 |
// redraw arrow |
| 139 |
((DlgArrow *) arrow)->initShape (); |
| 140 |
|
| 141 |
return; |
| 142 |
} |