[comp.sys.sun] need help with pw_copy

grover@argon.hac.com (Dean Grover (ird)) (03/09/89)

I have been trying to get the pixwin function pw_copy to work for some
time now.  I can't seem to get it to work.  Are there any known bugs with
it ?  I have included a sample program which shows what I am trying to do.
I want the pixwin from main_frame copied into the pixwin in main_frame2.
On all the machines I have tried, the main_frame2 pixwin remains blank.
(Sun 3 - OS 3.4,3.5,4.0.  Sun 4 - OS 4.0)

Thanks in advance.
Dean Grover
Hughes Aircraft Co.
adgrover@hac2arpa.hac.com

--- cut here

#include <stdio.h>
#include <suntool/sunview.h>
#include <suntool/panel.h>
#include <suntool/canvas.h>

main(argc,argv)
int argc;
char *argv[];
{
int status;
Frame main_frame,main_frame2;
Canvas canvas1,canvas2;
Pixwin *pw1,*pw2;

    main_frame = window_create (NULL,FRAME,
		WIN_Y, 0,
		WIN_X, 0,
		FRAME_LABEL, "Frame 1",
		0);

    main_frame2 = window_create (NULL,FRAME,
		WIN_Y, 0,
		WIN_X, 300,
		FRAME_LABEL, "Frame 2",
		0);

    canvas1 = window_create (main_frame, CANVAS,
		WIN_WIDTH, 100,
		WIN_HEIGHT, 100,
		CANVAS_RETAINED, FALSE,
		0);

    canvas2 = window_create (main_frame2, CANVAS,
		WIN_WIDTH, 100,
		WIN_HEIGHT, 100,
		CANVAS_RETAINED, FALSE,
		0);

    pw1 = canvas_pixwin(canvas1);
    pw2 = canvas_pixwin(canvas2);



    window_fit(main_frame);
    window_fit(main_frame2);

    window_set(main_frame, WIN_SHOW, TRUE, 0);
    window_set(main_frame2, WIN_SHOW, TRUE, 0);

    (void) notify_dispatch();
    pw_vector(pw1,0,0,100,100,PIX_SRC,1);
    pw_vector(pw1,0,100,100,0,PIX_SRC,1);
    pw_copy(pw2,0,0,100,100,PIX_SRC,pw1,0,0);
    while (1) {
	(void) notify_dispatch();
	status =pw_copy(pw2,0,0,100,100,PIX_SRC,pw1,0,0);
	printf("pw_copy status %d\n",status);
    }
}

de%COMP.LANCS.AC.UK@cunyvm.cuny.edu (David England) (03/14/89)

I don't think you can pw_copy into a canvas pixrect - isn't it just a
pointer with no memory allocated. Anyway, here's a program I gave to a
student who was having similar probelms. It draws a line, then copies the
canvas into a memory pirext and clears the canvas.  Finally it copies back
the saved pixrect.

Dave
de@comp.lancs.ac.uk

#include  <stdio.h>
#include  <suntool/sunview.h>
#include  <suntool/canvas.h>
#include  <suntool/panel.h>
#include  <pixrect/pixrect_hs.h

/* Compile with  cc -g test.c -lsuntool -lsunwindow -lpixrect */

Pixwin *pw;
static struct pixrect *pr;


drawline()
{
    pw_vector(pw, 0, 0, 50, 50, PIX_SRC, 1);
}

clear()
{

    pw_read(pr,0, 0, 100, 100, PIX_SRC, pw, 0, 0);
    pw_writebackground(pw, 0, 0, 100, 100, PIX_CLR );
}

redraw()
{
    pw_write(pw,0, 0 ,100, 100, PIX_SRC, pr, 0, 0);
}

main()
{

        Frame myframe;
    Panel mypan;
    Panel_item clearit, line, copyit;
        Canvas mycan;

    pr = mem_create(200,200,1);

        myframe = window_create(NULL, FRAME,
                                0);

    mypan = window_create(myframe,PANEL,
                WIN_ROWS, 2,
                WIN_COLUMNS, 20,
                0);

    line = panel_create_item(mypan, PANEL_BUTTON,
                                PANEL_LABEL_STRING, "line",
                                PANEL_NOTIFY_PROC, drawline,
                0);


    clearit = panel_create_item(mypan, PANEL_BUTTON,
                                PANEL_LABEL_STRING, "Clear",
                                PANEL_NOTIFY_PROC, clear,
                0);

    copyit = panel_create_item(mypan, PANEL_BUTTON,
                PANEL_LABEL_STRING, "Redraw",
                PANEL_NOTIFY_PROC, redraw,
                0);


        mycan = window_create(myframe, CANVAS,
                                WIN_HEIGHT, 100,
                                WIN_WIDTH ,100,
                CANVAS_RETAINED, TRUE,
                                0);


        pw = canvas_pixwin(mycan);


    window_fit_width(myframe);
    window_main_loop(myframe);

}

hsc@vuse.vanderbilt.edu (Hsuan Chang) (03/23/89)

>I have been trying to get the pixwin function pw_copy to work for some
>time now.  I can't seem to get it to work.  Are there any known bugs with
>it ?  I have included a sample program which shows what I am trying to do.
>I want the pixwin from main_frame copied into the pixwin in main_frame2.
>On all the machines I have tried, the main_frame2 pixwin remains blank

As I recall, the pw_copy works only when the two pixwin are created from
the same base frame.  You might find a work around by using the pw_rop()
function and use target_pw->pw_prretained pixrect as the target pixrect.

Hope this helps.

Hsuan Chang    hsc@vuse.vanderbilt.edu
Image Processing Lab, Computer Science Department
Vanderbilt University, Nashville, Tn 37235

chuck@trantor.harris-atd.com (Chuck Musciano) (03/31/89)

> As I recall, the pw_copy works only when the two pixwin are created from
> the same base frame.

In fact, pw_copy only works when the source and destination are the same
pixrect, according to the manual.  Which makes one wonder why they make
you pass in two pixrects to begin with.

Chuck Musciano			ARPA  : chuck@trantor.harris-atd.com
Harris Corporation 		Usenet: ...!uunet!x102a!trantor!chuck
PO Box 37, MS 3A/1912		AT&T  : (407) 727-6131
Melbourne, FL 32902		FAX   : (407) 727-5510