[comp.sys.mac.programmer] Emergeny help on picture drawing wanted!!!

delann@cs.umu.se (Anders Nyman) (01/30/91)

I have a quickdraw picture wich I wan't to draw in different size. I wan't to
shrink or expand it. But I fail to get it to work when I expand the picture.
Nothing occurs on my screen. If I try to draw the picture with an windowrect.
of the same size as in the recording, but in a different place, nothing occurs.
I hope that someone out there can help me out with this. The following code
is an testprogram in Think C 4.0.2 to try this out. My machine is an SE.

Any answer could be sent either to comp.sys.mac.programmer or by e-mail to:
delann@cs.umu.se or
nyman@kicki.stacken.kth.se

/Thanks for your attention!!!

The testprogram:

inittoolbox()
{
	InitGraf(&thePort);
	InitFonts();
	FlushEvents(everyEvent,0);
	InitWindows();
	InitMenus();
	TEInit();
	InitDialogs(0L);
	InitCursor();
	MaxApplZone();
}
 
WindowPtr thewind;
 
setupwindow()
{
	Rect therect;
	
	SetRect(&therect,0,0,180,180);
	thewind=NewWindow(0L,&therect,"\pTheWindow",1,2,-1L,0,0);
	ShowWindow(thewind);
}
 
main()
{
	PicHandle pic;
	Rect therect,therect1;
	
	inittoolbox();
	setupwindow();
 
	SetPort(thewind);
	SetRect(&therect,0,0,180,180);
	SetRect(&therect1,50,50,70,70);
	pic=OpenPicture(&therect);
	FillRect(&therect1,white);
	FrameRect(&therect1);
	ClosePicture();
	DrawPicture(pic,&therect);
	SetRect(&therect,0,0,230,230);
	DrawPicture(pic,&therect);
	KillPicture(pic);
}

CXT105@psuvm.psu.edu (Christopher Tate) (01/30/91)

You need to call SetClip() before you construct the picture, otherwise
the problem you mention might happen:  you won't get any drawing at all
when you try to use DrawPicture() later on.

Initially, the clip region for the picture is set to the default,
arbitrarily large (or at least *very* large) rectangle.  Following
the call to OpenPicture(), you need to call SetClip() (or ClipRect()
or whatever is most appropriate) to reduce the clipping region to
something more managable.  Using the bounding rectangle of the PICT
is a good way to go.

I don't know why DrawPicture() behaves this way, but unless you set
the clipping region to be small, the picture won't produce output.
This is documented in Inside Macintosh Volume I, in the QuickDraw
chapter, in the section on OpenPicture() and DrawPicture().

-------
Christopher Tate                  |  I hate writing, and I hate statistics,
                                  |  but most of all I hate writing about
cxt105@psuvm.psu.edu              |  statistics.  I'd rather go to the
 ...!psuvax1!psuvm.bitnet!cxt105  |  dentist; at least there you get to spit.
cxt105@psuvm.bitnet               |                      - Ed Sewell

d88-jwa@dront.nada.kth.se (Jon W{tte) (01/31/91)

In article <91029.212938CXT105@psuvm.psu.edu> CXT105@psuvm.psu.edu (Christopher Tate) writes:

>I don't know why DrawPicture() behaves this way, but unless you set
>the clipping region to be small, the picture won't produce output.
>This is documented in Inside Macintosh Volume I, in the QuickDraw
>chapter, in the section on OpenPicture() and DrawPicture().

Think about it:

	Rect clipRect = { -32768 , -32768 , 32767 , 32767 } ;

if you now offset the picture, you offset the clip rect as well.

	OffsetRect ( & clipRect , 100 , 100 ) ;

now clipRect == { -32668 , -32668 , -32667 , -32667 } That's
an empty rect (top, left > bottom, right)

Presumably scaling the pict works in an analogous way.

This is my guess. Anyone care to comment ? Am I right ?

							h+
::::::::       Jon W{tte, Stockholm, Sweden, h+@nada.kth.se       ::::::::
"The IM-IV file manager chapter documents zillions of calls, all of which
seem to do almost the same thing and none of which seem to do what I want
them to do."  --  Juri Munkki (jmunkki@hut.fi) in comp.sys.mac.programmer

lsr@Apple.com (Larry Rosenstein) (02/07/91)

In article <1991Jan30.183547.3571@nada.kth.se>, d88-jwa@dront.nada.kth.se (Jon W{tte) writes:
> 
> 	Rect clipRect = { -32768 , -32768 , 32767 , 32767 } ;
> 
> if you now offset the picture, you offset the clip rect as well.
> 
> 	OffsetRect ( & clipRect , 100 , 100 ) ;
> 
> now clipRect == { -32668 , -32668 , -32667 , -32667 } That's
> an empty rect (top, left > bottom, right)

Absolutely right.  This is why you always should set a minimum clipping
region when recording a picture.