From 98d2cf8b0621cadab1a3a62eb5c6be5c85d11a15 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Mon, 11 Apr 2016 18:34:26 +0200
Subject: [PATCH] add X functions to plot points

---
 common/utils/T/tracer/gui/x.c      | 28 ++++++++++++++++++++++++++++
 common/utils/T/tracer/gui/x.h      |  6 ++++++
 common/utils/T/tracer/gui/x_defs.h |  3 +++
 3 files changed, 37 insertions(+)

diff --git a/common/utils/T/tracer/gui/x.c b/common/utils/T/tracer/gui/x.c
index 04b110a435..e68e3bcb92 100644
--- a/common/utils/T/tracer/gui/x.c
+++ b/common/utils/T/tracer/gui/x.c
@@ -286,3 +286,31 @@ void x_draw(x_connection *_c, x_window *_w)
 printf("x_draw XCopyArea w h %d %d display %p window %d pixmap %d\n", w->width, w->height, c->d, (int)w->w, (int)w->p);
   XCopyArea(c->d, w->p, w->w, c->colors[1], 0, 0, w->width, w->height, 0, 0);
 }
+
+/* those two special functions are to plot many points
+ * first call x_add_point many times then x_plot_points once
+ */
+void x_add_point(x_connection *_c, int x, int y)
+{
+  struct x_connection *c = _c;
+
+  if (c->pts_size == c->pts_maxsize) {
+    c->pts_maxsize += 65536;
+    c->pts = realloc(c->pts, c->pts_maxsize * sizeof(XPoint));
+    if (c->pts == NULL) OOM;
+  }
+
+  c->pts[c->pts_size].x = x;
+  c->pts[c->pts_size].y = y;
+  c->pts_size++;
+}
+
+void x_plot_points(x_connection *_c, x_window *_w, int color)
+{
+  struct x_connection *c = _c;
+fprintf(stderr, "x_plot_points %d points\n", c->pts_size);
+  struct x_window *w = _w;
+  XDrawPoints(c->d, w->p, c->colors[color], c->pts, c->pts_size,
+      CoordModeOrigin);
+  c->pts_size = 0;
+}
diff --git a/common/utils/T/tracer/gui/x.h b/common/utils/T/tracer/gui/x.h
index 41cf65393b..e8f1d42d13 100644
--- a/common/utils/T/tracer/gui/x.h
+++ b/common/utils/T/tracer/gui/x.h
@@ -41,6 +41,12 @@ void x_fill_rectangle(x_connection *c, x_window *w, int color,
 void x_draw_string(x_connection *_c, x_window *_w, int color,
     int x, int y, const char *t);
 
+/* specials functions to plot many points
+ * you call several times x_add_point() then x_plot_points()
+ */
+void x_add_point(x_connection *c, int x, int y);
+void x_plot_points(x_connection *c, x_window *w, int color);
+
 /* this function copies the pixmap to the window */
 void x_draw(x_connection *c, x_window *w);
 
diff --git a/common/utils/T/tracer/gui/x_defs.h b/common/utils/T/tracer/gui/x_defs.h
index 43b99f7cf7..41817d06ce 100644
--- a/common/utils/T/tracer/gui/x_defs.h
+++ b/common/utils/T/tracer/gui/x_defs.h
@@ -7,6 +7,9 @@ struct x_connection {
   Display *d;
   GC *colors;
   int ncolors;
+  XPoint *pts;
+  int pts_size;
+  int pts_maxsize;
 };
 
 struct x_window {
-- 
GitLab