-
Notifications
You must be signed in to change notification settings - Fork 2
/
dlg_node.cc
193 lines (166 loc) · 5.19 KB
/
dlg_node.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
$Id: dlg_node.cc,v 1.1 2004/07/25 15:52:23 ksterker Exp $
Copyright (C) 2002 Kai Sterker <kaisterker@linuxgames.com>
Part of the Adonthell Project http://adonthell.linuxgames.com
Dlgedit is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Dlgedit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dlgedit; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @file dlg_node.cc
*
* @author Kai Sterker
* @brief Base class for the dialogue objects.
*/
#include <math.h>
#include "dlg_node.h"
// Coonstructor
DlgNode::DlgNode (node_type t, DlgRect area)
{
type_ = t;
index_ = -1;
top_left = area.topLeft ();
bottom_right = area.bottomRight ();
}
// Get the next node
DlgNode* DlgNode::next (query_type pos, int offset)
{
if (next_.empty ()) return NULL;
else return getNode (n, next_, pos, offset);
}
// Get the previous node
DlgNode* DlgNode::prev (query_type pos, int offset)
{
if (prev_.empty ()) return NULL;
else return getNode (p, prev_, pos, offset);
}
// Get a node from the specified list
DlgNode* DlgNode::getNode (std::list<DlgNode*>::iterator &it,
std::list<DlgNode*> &lst, query_type &pos, int &offset)
{
switch (pos)
{
case FIRST:
// point to the next element
it = lst.begin ();
offset -= 1;
break;
case NEXT:
// nothing needs be done
break;
case LAST:
// point to the last element
it = lst.end ();
offset = -offset;
break;
case PREV:
// reverse searching
offset = -offset;
break;
case CURRENT:
if (it != lst.end ()) return *it;
else return *(lst.begin ());
break;
default:
return NULL;
}
// forward iteration
if (offset >= 0)
{
for (int i = 0; i < offset && it != lst.end (); i++, it++);
if (it != lst.end ()) return *it;
}
// backward iteration
else
{
int i;
for (i = offset; i < 0 && it != lst.begin (); i++, it--);
if (i == 0) return *it;
}
return NULL;
}
// add node to list of followers
void DlgNode::addNext (DlgNode *node)
{
std::list<DlgNode*>::iterator i = next_.begin ();
DlgRect *cmp1, *cmp2 = node->type () == LINK ? node->next (FIRST) : node;
// search the proper place for insertion
while (i != next_.end ())
{
cmp1 = (*i)->type () == LINK ? (*i)->next (FIRST) : *i;
if (*cmp2 < *cmp1) break;
i++;
}
// insert
next_.insert (i, node);
}
// add node to list of precedessors
void DlgNode::addPrev (DlgNode *node)
{
std::list<DlgNode*>::iterator i = prev_.begin ();
DlgRect *cmp1, *cmp2 = node->type () == LINK ? node->prev (FIRST) : node;
// search the proper place for insertion
while (i != prev_.end ())
{
cmp1 = (*i)->type () == LINK ? (*i)->prev (FIRST) : *i;
if (*cmp2 < *cmp1) break;
i++;
}
prev_.insert (i, node);
}
// remove a node from the list of followers
void DlgNode::removeNext (DlgNode *node)
{
next_.remove (node);
n = next_.begin ();
}
// remove a node from the list of precedessors
void DlgNode::removePrev (DlgNode *node)
{
prev_.remove (node);
p = prev_.begin ();
}
// draw the node (with a certain mode)
void DlgNode::draw (cairo_surface_t *surface, DlgPoint &offset, GtkWidget *widget, mode_type m)
{
// change the mode temporarily
mode_type oldMode = mode_;
mode_ = m;
// draw
draw (surface, offset, widget);
// restore old mode
mode_ = oldMode;
}
void DlgNode::drawPolygon (cairo_t *cr, const GdkColor *color, const bool & filled, const DlgPoint *points, const int &num_points)
{
gdk_cairo_set_source_color (cr, color);
cairo_set_line_width (cr, 0.6);
cairo_move_to (cr, points[0].x(), points[0].y());
for (int i = 1; i < num_points; i++)
{
cairo_line_to (cr, points[i].x(), points[i].y());
}
filled ? cairo_fill (cr) : cairo_stroke (cr);
}
void DlgNode::drawCircle (cairo_t *cr, const GdkColor *color, const bool & filled, const int & x, const int & y, const int & radius)
{
gdk_cairo_set_source_color (cr, color);
cairo_set_line_width (cr, 0.6);
cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
filled ? cairo_fill (cr) : cairo_stroke (cr);
}
void DlgNode::drawRectangle (cairo_t *cr, const GdkColor *color, const bool & filled, const int & x, const int & y, const int & width, const int & height)
{
gdk_cairo_set_source_color (cr, color);
cairo_set_line_width (cr, 0.6);
cairo_rectangle (cr, x, y, width, height);
filled ? cairo_fill (cr) : cairo_stroke (cr);
}