Commit 03fb1678ae3f2985b7333b729090560090f2f1d5

Thomas de Grivel 2023-11-12T16:15:44

wip libc3 window cairo demo

diff --git a/.gitignore b/.gitignore
index f11de3e..8f9b16a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,9 @@ ic3/ic3_cov
 ic3/ic3_debug
 *.la
 libc3/window/cairo/xcb/demo/c3_window_cairo_xcb_demo
+libc3/window/cairo/xcb/demo/c3_window_cairo_xcb_demo_asan
+libc3/window/cairo/xcb/demo/c3_window_cairo_xcb_demo_cov
+libc3/window/cairo/xcb/demo/c3_window_cairo_xcb_demo_debug
 .libs/
 *.lo
 *.o
diff --git a/libc3/window/Makefile b/libc3/window/Makefile
index d4d8d38..66bdec4 100644
--- a/libc3/window/Makefile
+++ b/libc3/window/Makefile
@@ -10,6 +10,8 @@
 ## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
 ## THIS SOFTWARE.
 
+include config.mk
+
 build:
 	if ${HAVE_CAIRO} && ${HAVE_XCB}; then ${MAKE} -C cairo/xcb build; fi
 	if ${HAVE_CAIRO} && ${HAVE_XCB}; then ${MAKE} -C cairo/xcb/demo build; fi
@@ -78,5 +80,3 @@ update_sources:
 	install \
 	test \
 	update_sources
-
-include config.mk
diff --git a/libc3/window/cairo/c3_window_cairo_demo.c b/libc3/window/cairo/c3_window_cairo_demo.c
index dd1afab..537fe8f 100644
--- a/libc3/window/cairo/c3_window_cairo_demo.c
+++ b/libc3/window/cairo/c3_window_cairo_demo.c
@@ -32,11 +32,13 @@ bool c3_window_cairo_demo_render (s_window_cairo *window,
                                   cairo_t *cr)
 {
   s_sequence *seq;
+  cairo_text_extents_t te;
   assert(window);
   assert(cr);
   if (! window_animate((s_window *) window))
     return false;
   seq = window->sequence + window->sequence_pos;
+  /* background */
   switch (window->sequence_pos) {
   case 0:
     if (seq->t < 1.0)
@@ -61,6 +63,19 @@ bool c3_window_cairo_demo_render (s_window_cairo *window,
   }
   cairo_rectangle(cr, 0, 0, window->w, window->h);
   cairo_fill(cr);
+  /* text */
+  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+  cairo_select_font_face (cr, "CourierNew",
+                          CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+  cairo_set_font_size (cr, 20);
+  cairo_text_extents (cr, seq->title, &te);
+  cairo_move_to (cr, 20, window->h - te.height - te.y_bearing - 20);
+  cairo_show_text (cr, seq->title);
+  /* progress bar */
+  cairo_rectangle(cr, 20, window->h - 11,
+                  (window->w - 40.0) * seq->t / seq->duration,
+                  2);
+  cairo_fill(cr);
   return true;
 }
 
diff --git a/libc3/window/cairo/xcb/demo/c3_window_cairo_xcb_demo_debug b/libc3/window/cairo/xcb/demo/c3_window_cairo_xcb_demo_debug
old mode 100644
new mode 100755
diff --git a/libc3/window/cairo/xcb/window_cairo_xcb.c b/libc3/window/cairo/xcb/window_cairo_xcb.c
index 0bdf20f..80ea3bc 100644
--- a/libc3/window/cairo/xcb/window_cairo_xcb.c
+++ b/libc3/window/cairo/xcb/window_cairo_xcb.c
@@ -127,7 +127,7 @@ bool window_cairo_xcb_run (s_window_cairo *window)
     }
     else {
       sleep.tv_sec = 0;
-      sleep.tv_nsec = 1000000000 / 6;
+      sleep.tv_nsec = 1000000000 / 120;
       nanosleep(&sleep, NULL);
       if (! (r = window->render(window, cr)))
         goto clean;
diff --git a/libc3/window/configure b/libc3/window/configure
old mode 100644
new mode 100755
index d646c1d..35ef542
--- a/libc3/window/configure
+++ b/libc3/window/configure
@@ -17,6 +17,9 @@ export SRC_TOP="$(dirname "$PWD")"
 
 . ../../config.subr
 
+config_asan
+echo "HAVE_ASAN = $HAVE_ASAN" >> ${CONFIG_MK}
+
 if pkg-config cairo; then
     HAVE_CAIRO=true
     if pkg-config xcb; then
diff --git a/libc3/window/window.c b/libc3/window/window.c
index d71d0a3..b5714cf 100644
--- a/libc3/window/window.c
+++ b/libc3/window/window.c
@@ -34,7 +34,7 @@ bool window_animate (s_window *window)
   time_sub(&clock_monotonic, &seq->t0, &delta);
   time_to_f64(&delta, &t);
   seq->t = t;
-  printf("window_animate: %f\n", t);
+  /* printf("window_animate: %f\n", t); */
   if (t > seq->duration &&
       ! window_set_sequence_pos(window, (window->sequence_pos + 1) %
                                 window->sequence_count))