halam2@umn-d-ub.d.umn.edu (Haseen I. Alam) (07/13/90)
Hi there,
I am relatively new in SunView environment. I wrote a program to do
edge linking on Unix systems in C. Next I added three procedures called
open_display, put_pixel, and close_display. open_display is passed in
the x and y dimensions and it opens up a window of that size. put_pixel
is passed in the x,y coordinates and a gray level value. I use this
same procedure to turn pixels on and off. Then at the end I call
close_display to close the display window. At some point or other I would
like to port this program to X-windows as well.
These procedures are defined in a file (included below) that I link via
makefile with my actual program. Everything works fine, almost! One
problem is if I open up aother window that overlaps the display window,
then it does not refresh anymore. The other problem is serious: at the
end of the program it pops up a little dialog box saying "Use left button
to quit" (something similar to that). If by mistake I use any of the other
two buttons then I get a DEVICE BUSY error. then I either have to use
CTRL-C or pull down a menu from the title bar and exit. Also I saw a call
that I can add to bring the display window in front of all the other
windows, but I forgot its name.
I would appreciate if any kind soul will help me with the above three
problems of (1) window refresh, (2) Device busy error, (3) making it the
top most window at the end, and (4) some code/pointer to implement the
above mentioned operations in X-windows.
Thanks in advance.
Haseen.
/* This is intdisp.c note this is not a main program */
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#define BUFSIZ 1024
Frame base_frame ;
Canvas canvas ;
Cursor cursor ;
Pixwin *pw, *fpw ;
Pixrect *mem_create() ;
char cmsname[BUFSIZ] ;
u_char red[256], green[256], blue[256] ;
colormap_t colormap ;
int X_size, Y_size;
static void canvas_event_proc() ;
void open_display () ;
void put_pixel () ;
void close_display () ;
void open_display (x,y)
int x,y ;
{
base_frame = window_create (NULL, FRAME,
FRAME_LABEL, "Display",
WIN_HEIGHT, y+20,
WIN_WIDTH, x+20,
0 ) ;
create_show_popup () ;
window_set (base_frame,WIN_SHOW,TRUE,0) ;
notify_dispatch () ;
X_size = x ;
Y_size = y ;
}
void close_display()
{
window_destroy(base_frame);
window_main_loop(base_frame);
}
create_show_popup()
{
setup_colourmap();
cursor = cursor_create(
CURSOR_OP, PIX_SRC ^ PIX_DST,
CURSOR_CROSSHAIR_LENGTH, 20,
CURSOR_SHOW_CROSSHAIRS, TRUE,0);
canvas = window_create(base_frame, CANVAS,
WIN_CURSOR, cursor,
CANVAS_HEIGHT, 768,
CANVAS_WIDTH, 768,
CANVAS_AUTO_SHRINK, FALSE,
WIN_EVENT_PROC, canvas_event_proc,
WIN_CONSUME_PICK_EVENT, WIN_IN_TRANSIT_EVENTS,
0);
pw = canvas_pixwin(canvas);
}
setup_colourmap()
{
register int i;
for (i = 0; i < 256; i++) {
red[i] = green[i] = blue[i] = -1;
}
fpw = (Pixwin *) window_get(base_frame, WIN_PIXWIN);
if (colormap.type == RMT_NONE || colormap.length == 0) {
sprintf(cmsname, "greyscale%d", 8);
pw_setcmsname(fpw, cmsname);
for (i = 1; i < 255; i++) {
red[i] = i;
green[i] = i;
blue[i] = i;
}
pw_putcolormap(fpw, 0, 256, red, green, blue);
}
window_set(base_frame, FRAME_INHERIT_COLORS, TRUE, 0);
}
static void canvas_event_proc (canvas, event, arg)
Canvas canvas;
Event *event;
caddr_t arg;
{
;
}
void put_pixel(x,y,value)
int x,y,value;
{
pw_put(pw,x,y,value);
notify_dispatch();
}
--
.--------------------------------------------------------------------.
| Haseen Ibne Alam | email : halam2@ub.d.umn.edu |
| "LET THE FORCE BE WITH YOU." | or halam@cola.d.umn.edu |
`--------------------------------------------------------------------'