v0.86 and graphics expose

J. P. Mellor (jpmellor@ai.mit.edu)
Fri, 11 Apr 1997 09:38:29 -0400

To subscribers of the xforms list from "J. P. Mellor" <jpmellor@ai.mit.edu> :

There still seems to be a problem with canvases and graphics exposes.
These events cause fl_do_forms() to return. Also setting a canvas
handler for GraphicsExpose doesn't help. Below is a program which
demonstrates the behavior. Two forms pop up; one mostly covering the
other. The left button copies a region from the window to a pixmap.
On the fully expose window this works properly. On the partially
expose window (the cursor will change to a cross) the left button will
cause fl_do_forms() to return.

jp

=======================================================================
/* This program tests the graphics expose event - it should not cause fl_do_forms() to return */

#include <GL/gl.h>
#include <GL/glx.h>
#include <forms.h>
#include <stdlib.h>

#define mark_width 15
#define mark_height 15
#define mark_x_hot 7
#define mark_y_hot 7
static unsigned char mark_bits[] = {
0x9f, 0xfc, 0x9f, 0xfc, 0x9f, 0xfc, 0x9f, 0xfc, 0x9f, 0xfc, 0x80, 0x80,
0x80, 0x80, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80, 0x9f, 0xfc, 0x9f, 0xfc,
0x9f, 0xfc, 0x9f, 0xfc, 0x9f, 0xfc};

typedef struct {
FL_FORM *form;
FL_OBJECT *image;
} FD_form;

FD_form *fd_form1, *fd_form2;
Pixmap mark, save;

int
canvas_expose_handler(FL_OBJECT *obj, Window win, int w, int h,
XEvent *xev, void *data)
{
glXMakeCurrent(fl_get_display(), win, fl_get_glcanvas_context(obj));
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();

return TRUE;
}

int
canvas_graphics_expose_handler(FL_OBJECT *obj, Window win, int w, int h,
XEvent *xev, void *data)
{
return TRUE;
}

int
canvas_button_press_handler(FL_OBJECT *obj, Window win, int w, int h,
XEvent *xev, void *data)
{
Display *display;

if (xev->xbutton.button == Button1) {
display = fl_get_display();
printf("Button 1\n");
XCopyArea(display, win, save, DefaultGC(display, DefaultScreen(display)),
0, 0, mark_width, mark_height, 0, 0);
}
else if (xev->xbutton.button == Button2) {
display = fl_get_display();
printf("Button 2\n");
XCopyArea(display, save, win, DefaultGC(display, DefaultScreen(display)),
0, 0, mark_width, mark_height, 0, 0);
}
else if (xev->xbutton.button == Button3) {
printf("Button 3\n");
return FALSE;

}

return TRUE;
}

FD_form *create_form()
{
FL_OBJECT *obj;
FD_form *fdui;
const int attributeList[] = { GLX_RGBA, None };

if ((fdui=fl_calloc(1, sizeof(*fdui))) == NULL) {
fprintf(stderr, "Could not allocate FD_form\n");
}

fl_set_glcanvas_defaults(attributeList);

fdui->form = fl_bgn_form(FL_UP_BOX, 272, 272);

fdui->image = obj = fl_add_glcanvas(FL_NORMAL_CANVAS, 8, 8, 256, 256, "");
fl_add_canvas_handler(obj, Expose, &canvas_expose_handler, NULL);
fl_add_canvas_handler(obj, GraphicsExpose, &canvas_graphics_expose_handler, NULL);
fl_add_canvas_handler(obj, ButtonPress, &canvas_button_press_handler, NULL);

fl_end_form();

return fdui;
}

void
init_xstuff(void)
{
Cursor cursor;
XColor color1, color2;
Window window;
Display *display;

color1.red = color1.green = color1.blue = 0;
color2.red = color2.green = color2.blue = ~0;
window = fl_get_canvas_id(fd_form1->image);
display = fl_get_display();
mark = XCreatePixmapFromBitmapData(display, window, mark_bits,
mark_width, mark_height, 0, 1, 1);
cursor = XCreatePixmapCursor(display, mark, mark, &color2, &color1,
mark_x_hot, mark_y_hot);
XDefineCursor(display, fl_get_canvas_id(fd_form1->image), cursor);

/* this depends on the depth of the xserver */
save = XCreatePixmap(display, window, mark_width, mark_height,
DefaultDepth(display, DefaultScreen(display)));
}

int
main(int argc, char **argv)
{
FL_OBJECT *obj;

fl_initialize(&argc, argv, 0, 0, 0);
fd_form1 = create_form();
fd_form2 = create_form();

/* show the form */
fl_show_form(fd_form1->form, FL_PLACE_CENTER, FL_FULLBORDER, "Form1");
fl_show_form(fd_form2->form, FL_PLACE_CENTER, FL_FULLBORDER, "Form2");

init_xstuff();

obj = fl_do_forms();
return 0;
}
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/xforms-archive/