/* examples/canvas/reaffi.c */ #include He_node *princ, *panel, *canvas; void dessin_point (Window win, int x, int y, int coul) { XSetForeground (he_display, he_gc, coul); XDrawPoint (he_display, win, he_gc, x, y); } void canvas_repaint_proc (He_node *hn, Window win) { int x, y, w = HeGetWidth(hn), h = HeGetHeight(hn); printf ("Début RepaintProc\n"); /* Dessin du fond */ HeDrawBg (hn, he_white); /* Dessin volontairement lent */ for (y = 0; y < h; y++) for (x = 0; x < w; x++) if ((w/2-x)*(w/2-x)+(h/2-y)*(h/2-y) < w*h/4) dessin_point (win, x, y, he_black); printf ("Fin RepaintProc\n"); } void canvas_event_proc (He_node *hn, He_event *hev) { switch (hev->type) { case ButtonPress : if (hev->sb == 1) { printf ("Debut appel direct\n"); canvas_repaint_proc (canvas, hev->win); printf ("Fin appel direct\n"); } else if (hev->sb == 2) { printf ("Debut appel différé\n"); HePostRepaint (canvas); printf ("Fin appel différé\n"); } break; } } void butt1_proc (He_node *hn) { printf ("Debut appel direct\n"); canvas_repaint_proc (canvas, HeGetWindow(canvas)); printf ("Fin appel direct\n"); } void butt2_proc (He_node *hn) { printf ("Debut appel différé\n"); HePostRepaint (canvas); printf ("Fin appel différé\n"); } void princ_resize_proc (He_node *hn, int width, int height) { HeExpand (canvas, NULL, HE_BOTTOM_RIGHT); } int main (int argc, char *argv[]) { HeInit (&argc, &argv); princ = HeCreateFrame(); HeSetFrameLabel (princ, "Provoquer un réaffichage"); HeSetFrameResizeProc (princ, princ_resize_proc); panel = HeCreatePanel (princ); HeSetPanelLayout (panel, HE_VERTICAL); HeCreateButtonP (panel, "Appel direct", butt1_proc, NULL); HeCreateButtonP (panel, "Appel différé", butt2_proc, NULL); HeCreateMessageP (panel, "Bouton souris 1 : appel direct", FALSE); HeCreateMessageP (panel, "Bouton souris 2 : appel différé", FALSE); HeFit(panel); canvas = HeCreateCanvas (princ); HeSetY (canvas, HeGetHeight(panel) + 2); HeSetWidth (canvas, 500); HeSetHeight (canvas, 500); HeSetCanvasRepaintProc (canvas, canvas_repaint_proc); HeSetCanvasEventProc (canvas, canvas_event_proc); HeFit (princ); return HeMainLoop (princ); }