/* demo-09.c : demonstration de EZ-Draw * * Edouard.Thiel@lif.univ-mrs.fr - 21/06/2011 - version 1.2 * * Compilation sous Unix : * gcc -Wall demo-09.c ez-draw.c -o demo-09 -lX11 -lXext -L/usr/X11R6/lib * Compilation sous Windows : * gcc -Wall demo-09.c ez-draw.c -o demo-09.exe -lgdi32 * * This program is free software under the terms of the * GNU Lesser General Public License (LGPL) version 2.1. */ #include "ez-draw.h" #define MAX_CPT1 100 /* On peut eviter ces variables globales avec ez_set_data(), voir demo-10.c et suivantes. */ int cpt1 = 0, win1_w = 300, win1_h = 200, delay1 = 30; void win1_on_expose (Ez_event *ev) { /* On fait le dessin en fonction de cpt1 */ int xc = win1_w/2, rx = xc * cpt1 / MAX_CPT1, yc = win1_h/2, ry = yc * cpt1 / MAX_CPT1; ez_set_color (ez_magenta); ez_set_thick (3); ez_draw_circle (ev->win, xc-rx, yc-ry, xc+rx, yc+ry); ez_set_color (ez_black); ez_set_nfont (0); ez_draw_text (ev->win, EZ_BL, 8, win1_h-8, "q : quitter"); } void win1_on_key_press (Ez_event *ev) { switch (ev->key_sym) { case XK_q : ez_quit (); break; } } void win1_on_configure_notify (Ez_event *ev) { win1_w = ev->width; win1_h = ev->height; } void win1_on_timer_notify (Ez_event *ev) /* Le timer est arrive' a echance */ { /* On incremente le compteur cpt1 pour modifier la position de l'objet que l'on veut animer */ cpt1 = (cpt1 + 1) % MAX_CPT1; /* On envoie l'evenement Expose pour que la fenetre soit redessinee */ ez_send_expose (ev->win); /* On re'arme le timer, pour entretenir une "boucle" de TimerNotify qui est iteree tous les delay1 millisecondes */ ez_start_timer (ev->win, delay1); } void win1_event (Ez_event *ev) { switch (ev->type) { case Expose : win1_on_expose (ev); break; case KeyPress : win1_on_key_press (ev); break; case ConfigureNotify : win1_on_configure_notify (ev); break; case TimerNotify : win1_on_timer_notify (ev); break; } } int main () { Ez_window win1; if (ez_init() < 0) exit(1); win1 = ez_window_create (win1_w, win1_h, "Demo 09 : hypnose", win1_event); /* On associe un double-buffer d'affichage pour eviter tout clignotement */ ez_window_dbuf (win1, 1); /* Provoque l'envoie d'un evenement TimerNotify dans delay1 millisecondes : c'est le point de depart de la "boucle" de TimerNotify */ ez_start_timer (win1, delay1); ez_main_loop (); exit(0); }