Re: fl_deactivate_all_forms()

J. P. Mellor (jpmellor@ai.mit.edu)
Mon, 23 Dec 1996 18:29:19 -0500

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

From: "J. P. Mellor" <jpmellor@ai.mit.edu>
>I'm still having problems with V0.84. Below is a simple program which
>demonstrates the behavior. The left mouse button prints a message to

Apparently the sample program didn't make it. Try again.

jp

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

typedef struct {
FL_FORM *stereo_utility;
FL_OBJECT *image;
FL_OBJECT *button;
FL_OBJECT *exit;
void *vdata;
long ldata;
} FD_stereo_utility;

FD_stereo_utility *fd_stereo_utility;
int button1 = FALSE;
int last_x, last_y;

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_button_press_handler(FL_OBJECT *obj, Window win, int w, int h,
XEvent *xev, void *data)
{
Display *display;
GC gc;

if (xev->xbutton.button == Button1) {
printf("Button 1 pressed: (%d %d)\n", xev->xbutton.x, xev->xbutton.y);
button1 = TRUE;
last_x = xev->xbutton.x;
last_y = xev->xbutton.y;
}
else if (xev->xbutton.button == Button2) {
fl_activate_all_forms();
printf("Forms activated\n");
}
else if (xev->xbutton.button == Button3) {
printf("Done\n");
fl_trigger_object(fd_stereo_utility->exit);
}

return TRUE;
}

int
canvas_motion_notify_handler(FL_OBJECT *obj, Window win, int w, int h,
XEvent *xev, void *data)
{
int x, y, x0, y0;
Window root, child;
int buttons;

XQueryPointer(fl_get_display(), win, &root, &child, &x0, &y0,
&x, &y, &buttons);
if (button1 && ((x != last_x) || (y != last_y))) {
printf("Button 1 moved: (%d %d)\n", x, y);
last_x = xev->xbutton.x;
last_y = xev->xbutton.y;
}

return TRUE;
}

int
canvas_button_release_handler(FL_OBJECT *obj, Window win, int w, int h,
XEvent *xev, void *data)
{
if (button1 && (xev->xbutton.button == Button1)) {
printf("Button 1 released: (%d %d)\n", xev->xbutton.x, xev->xbutton.y);
last_x = xev->xbutton.x;
last_y = xev->xbutton.y;
button1 = FALSE;
}

return TRUE;
}

void
deactivate_callback(FL_OBJECT *obj, long argument)
{
fl_deactivate_all_forms();
}

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

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

fl_set_glcanvas_defaults(attributeList);

fdui->stereo_utility = fl_bgn_form(FL_UP_BOX, 272, 310);
fdui->image = obj = fl_add_glcanvas(FL_NORMAL_CANVAS,8,8,256,256,"");
fl_add_canvas_handler(obj, Expose, &canvas_expose_handler, (void *)0);
fl_add_canvas_handler(obj, ButtonPress, &canvas_button_press_handler,
(void *)0);
fl_add_canvas_handler(obj, MotionNotify, &canvas_motion_notify_handler,
(void *)0);
fl_add_canvas_handler(obj, ButtonRelease, &canvas_button_release_handler,
(void *)0);
fdui->button = obj = fl_add_button(FL_NORMAL_BUTTON, 8, 272, 256, 30, "Deactivate Form");
fl_set_object_callback(obj, &deactivate_callback, 0);
fdui->exit = obj = fl_add_button(FL_HIDDEN_BUTTON, 8, 272, 0, 0, "");
fl_end_form();

return fdui;
}

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

fl_initialize(&argc, argv, 0, 0, 0);
fd_stereo_utility = create_form_stereo_utility();

/* show the first form */
fl_show_form(fd_stereo_utility->stereo_utility, FL_PLACE_CENTER,
FL_FULLBORDER, "Stereo Utility");

obj = fl_do_forms();
return 0;
}