summaryrefslogtreecommitdiff
path: root/src/gtkext/graph/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gtkext/graph/node.c')
-rw-r--r--src/gtkext/graph/node.c165
1 files changed, 122 insertions, 43 deletions
diff --git a/src/gtkext/graph/node.c b/src/gtkext/graph/node.c
index 47531e2..c79b8fc 100644
--- a/src/gtkext/graph/node.c
+++ b/src/gtkext/graph/node.c
@@ -144,6 +144,8 @@ static void g_graph_node_class_init(GGraphNodeClass *klass)
static void g_graph_node_init(GGraphNode *node)
{
+ node->alloc.x = UNINITIALIZED_NODE_POS;
+ node->alloc.y = UNINITIALIZED_NODE_POS;
}
@@ -253,7 +255,31 @@ unsigned int g_graph_node_get_rank(const GGraphNode *node)
void g_graph_node_reset_position(GGraphNode *node)
{
- node->reset_pos(node);
+ node->alloc.x = UNINITIALIZED_NODE_POS;
+ node->alloc.y = UNINITIALIZED_NODE_POS;
+
+ if (node->reset_pos != NULL)
+ node->reset_pos(node);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'encapsulation à traiter. *
+* nodes = ensemble des noeuds en place. *
+* *
+* Description : Définit les abscisses relatives du contenu d'un noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_node_prepare_x_line(GGraphNode *node, GGraphNode *nodes)
+{
+ node->prepare_x(node, nodes);
}
@@ -261,10 +287,8 @@ void g_graph_node_reset_position(GGraphNode *node)
/******************************************************************************
* *
* Paramètres : node = noeud graphique à manipuler. *
-* x = éventuelle abscisse à intégrer ou NULL. *
-* y = éventuelle ordonnée à intégrer ou NULL. *
* *
-* Description : Altère la position du noeud d'encapsulation. *
+* Description : Applique une position finale au noeud. *
* *
* Retour : - *
* *
@@ -272,22 +296,50 @@ void g_graph_node_reset_position(GGraphNode *node)
* *
******************************************************************************/
-void g_graph_node_set_position(GGraphNode *node, gint *x, gint *y)
+void g_graph_node_apply_position(GGraphNode *node)
{
-#if 1
- if (x != NULL && node->pending_x != 0)
- {
- *x += node->pending_x;
- printf(" ((%p)) adding %d => %d\n", node, node->pending_x, *x);
- node->pending_x = 0;
- }
- if (y != NULL && node->pending_y != 0)
+ gint x_pos; /* Position de référence */
+ GGraphNode *ref; /* Accès rapide */
+
+ if (node->apply_pos != NULL)
+ node->apply_pos(node);
+
+ switch (node->pending_flag)
{
- *y += node->pending_y;
- node->pending_y = 0;
+ case PPF_DIRECT_X:
+ g_graph_node_get_position(node->pending_rel, &x_pos, NULL);
+ x_pos += node->pending_pos.direct_x;
+ g_graph_node_set_x_position(node, x_pos);
+ break;
+
+ case PPF_LEFT_MARGIN:
+ g_graph_node_get_position(node->pending_rel, &x_pos, NULL);
+ x_pos += EDGE_SLOT_HORIZ_MARGIN + node->pending_pos.left_margin;
+ g_graph_node_set_x_position(node, x_pos);
+ break;
+
+ case PPF_RIGHT_MARGIN:
+ g_graph_node_get_position(node->pending_rel, &x_pos, NULL);
+ x_pos += node->pending_pos.right_margin;
+ x_pos -= (EDGE_SLOT_HORIZ_MARGIN + node->alloc.width);
+ g_graph_node_set_x_position(node, x_pos);
+ break;
+
+ case PPF_LEFT_NODE:
+ ref = node->pending_pos.left_node;
+ node->alloc.x = ref->alloc.x - NODE_HORIZONTAL_MARGIN - node->alloc.width;
+ break;
+
+ case PPF_RIGHT_NODE:
+ ref = node->pending_pos.right_node;
+ node->alloc.x = ref->alloc.x + ref->alloc.width - NODE_HORIZONTAL_MARGIN;
+ break;
+
+ default:
+ /* Position traitée par l'appelant */
+ break;
+
}
-#endif
- node->set_pos(node, x, y);
}
@@ -295,8 +347,34 @@ void g_graph_node_set_position(GGraphNode *node, gint *x, gint *y)
/******************************************************************************
* *
* Paramètres : node = noeud graphique à manipuler. *
-* x = éventuelle abscisse à intégrer ou NULL. *
-* y = éventuelle ordonnée à intégrer ou NULL. *
+* Paramètres : node = noeud graphique à manipuler. *
+* x = abscisse à intégrer. *
+* direct = indique un tracé direct éventuel. *
+* *
+* Description : Altère la position du noeud d'encapsulation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_node_set_x_position(GGraphNode *node, gint x)
+{
+ if (node->set_pos != NULL && x != GRAPH_HORIZONTAL_MARGIN)
+ node->set_pos(node, x);
+
+ node->alloc.x = x;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à manipuler. *
+* flag = nature de l'indication à intégrer. *
+* pos = argument supplémentaire à venir chercher. *
+* rel = éventuelle référence pour une relation relative. *
* *
* Description : Prépare la position du noeud pour l'alignement des liens. *
* *
@@ -306,33 +384,33 @@ void g_graph_node_set_position(GGraphNode *node, gint *x, gint *y)
* *
******************************************************************************/
-void g_graph_node_set_pending_position(GGraphNode *node, gint *x, gint *y)
+void g_graph_node_set_pending_position(GGraphNode *node, PendingPositionFlags flag, pending_position pos, GGraphNode *rel)
{
- gint cur_x; /* Abscisse courante */
- gint cur_y; /* Ordonnée courante */
- bool update_x; /* Mise à jour des abscisses */
- bool update_y; /* Mise à jour des ordonnées */
+ node->pending_pos = pos;
+ node->pending_flag = flag;
+ node->pending_rel = rel;
- g_graph_node_get_position(node, &cur_x, &cur_y);
+}
- if (x != NULL)
- {
- update_x = (cur_x != UNINITIALIZED_NODE_POS);
- if (!update_x) node->pending_x += *x;
- }
- else update_x = false;
- if (y != NULL)
- {
- update_y = (cur_y != UNINITIALIZED_NODE_POS);
- if (!update_y) node->pending_y += *y;
- }
- else update_y = false;
+/******************************************************************************
+* *
+* Paramètres : node = noeud graphique à manipuler. *
+* flag = nature de l'indication à intégrer. [OUT] *
+* pos = argument supplémentaire à venir chercher. [OUT] *
+* *
+* Description : Indique la position du noeud pour l'alignement des liens. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- if (update_x || update_y)
- g_graph_node_set_position(node,
- update_x ? cur_x + *x : NULL,
- update_y ? cur_x + *y : NULL);
+void g_graph_node_get_pending_position(GGraphNode *node, PendingPositionFlags *flag, pending_position *pos)
+{
+ *pos = node->pending_pos;
+ *flag = node->pending_flag;
}
@@ -353,7 +431,8 @@ void g_graph_node_set_pending_position(GGraphNode *node, gint *x, gint *y)
void g_graph_node_get_position(const GGraphNode *node, gint *x, gint *y)
{
- node->get_pos(node, x, y);
+ if (x != NULL) *x = node->alloc.x;
+ if (y != NULL) *y = node->alloc.y;
}
@@ -372,7 +451,7 @@ void g_graph_node_get_position(const GGraphNode *node, gint *x, gint *y)
GtkAllocation g_graph_node_get_allocation(const GGraphNode *node)
{
- return node->get_alloc(node);
+ return node->alloc;
}