summaryrefslogtreecommitdiff
path: root/src/graph/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graph/node.c')
-rw-r--r--src/graph/node.c67
1 files changed, 64 insertions, 3 deletions
diff --git a/src/graph/node.c b/src/graph/node.c
index b220c4f..8432476 100644
--- a/src/graph/node.c
+++ b/src/graph/node.c
@@ -50,6 +50,9 @@ struct _GGraphNodeClass
{
GObjectClass parent; /* A laisser en premier */
+ double dpi_x; /* Résolution en abscisse */
+ double dpi_y; /* Résolution en ordonnée */
+
};
@@ -84,6 +87,44 @@ G_DEFINE_TYPE(GGraphNode, g_graph_node, G_TYPE_OBJECT);
static void g_graph_node_class_init(GGraphNodeClass *klass)
{
+ GdkScreen *screen; /* Ecran par défaut */
+ gint width; /* Largeur d'écran en pixels */
+ gint height; /* Hauteur d'écran en pixels */
+ gint width_mm; /* Largeur d'écran en mm. */
+ gint height_mm; /* Hauteur d'écran en mm. */
+
+ screen = gdk_screen_get_default();
+
+ width = gdk_screen_get_width(screen);
+ height = gdk_screen_get_height(screen);
+
+ width_mm = gdk_screen_get_width_mm(screen);
+ height_mm = gdk_screen_get_height_mm(screen);
+
+ /**
+ * Il y a 2.54 centimètres, soit 25.4 millimètres, dans un pouce.
+ * On a donc :
+ *
+ * dpi = N pixels / (M millimètres / (25.4 millimètres / 1 pouce))
+ * = N pixels / (M pouces / 25.4)
+ * = N * 25.4 pixels / M pouces
+ *
+ */
+
+ if (width_mm > 0 && height_mm > 0)
+ {
+ klass->dpi_x = (width * 25.4) / (double)width_mm;
+ klass->dpi_y = (height * 25.4) / (double)height_mm;
+ }
+ else
+ {
+ klass->dpi_x = 96;
+ klass->dpi_y = 96;
+ }
+
+
+ klass->dpi_x = 72;
+ klass->dpi_y = 72;
}
@@ -136,7 +177,7 @@ GGraphNode *g_graph_node_new(GtkBinView *view)
}
-
+#include <math.h>
/******************************************************************************
* *
* Paramètres : node = intermédiaire à consulter. *
@@ -153,14 +194,27 @@ GGraphNode *g_graph_node_new(GtkBinView *view)
char *g_graph_node_register_for_dot(const GGraphNode *node, char *cmds)
{
GtkRequisition requisition; /* Taille à l'écran requise */
+ char buffer[128];
+
+ gtk_widget_size_request(GTK_WIDGET(node->view), &requisition);
cmds = stradd(cmds, node->name);
+ cmds = stradd(cmds, " [shape=box, fixedsize ");
- gtk_widget_size_request(GTK_WIDGET(node->view), &requisition);
+ printf(" req=(%d ; %d) -->> (%g ; %g)\n",
+ requisition.width,
+ requisition.height,
+ requisition.width / G_GRAPH_NODE_GET_CLASS(node)->dpi_x,
+ requisition.height / G_GRAPH_NODE_GET_CLASS(node)->dpi_y);
+ snprintf(buffer, 128, ", width=\"%g\"", round(requisition.width / G_GRAPH_NODE_GET_CLASS(node)->dpi_x) + 1.0);
+ cmds = stradd(cmds, buffer);
- cmds = stradd(cmds, " [shape=box];\n");
+ snprintf(buffer, 128, ", height=\"%g\"", round(requisition.height / G_GRAPH_NODE_GET_CLASS(node)->dpi_y) + 1.0);
+ cmds = stradd(cmds, buffer);
+
+ cmds = stradd(cmds, "];\n");
return cmds;
@@ -184,6 +238,13 @@ char *g_graph_node_register_for_dot(const GGraphNode *node, char *cmds)
void g_graph_node_place(const GGraphNode *node, GtkFixed *fixed, gint x, gint y)
{
+ GtkRequisition requisition; /* Taille à l'écran actuelle */
+
+ gtk_widget_size_request(GTK_WIDGET(node->view), &requisition);
+
+ x -= requisition.width / 2;
+ y -= requisition.height / 2;
+
gtk_fixed_put(fixed, GTK_WIDGET(node->view), x, y);
}