[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Drawing in a Color Window with MacPerl



Philippe Rochambeau writes on 13 November 1997:

>In order to learn how to use the Mac Toolbox with MacPerl, I am currently
>trying to open a color window and draw a patterned circle in it. Here is my
>code:
>
>#!perl -w
>
>use Mac::Events;
>use Mac::Windows;
>use Mac::QuickDraw;
>use Mac::Fonts;
>
>$color = blueColor;
>
>$love = new Pattern q{
>                                .XX.XX..
>                                X..X..X.
>                                X.....X.
>                                .X...X..
>                                ..X.X...
>                                ...X....
>                                ........
>                                ........
>};
>
>$portR = new Rect 0, 0, 100, 100;
>
>$win = NewCWindow $bounds, "Hello World!", 1, documentProc, 1;
>
>if ($win) {
>
># Routine QuickDraw
>SetPort($win);
>ForeColor($color);
>PenPat($love);
>PaintOval($portR);
>
>sleep(3);
>
>DisposeWindow($win);
>
>}
>
>Questions:
>
>1) What is the equivalent of PaintOval(myWindow^.portRect) in MacPerl (i.e.,
>How do you get a pointer to the portRect in MacPerl)?
>
>2) How can I make my own colors using 3 RGB values, instead of using constants
>such as blueColor, whiteColor, etc?
>
>3) How can I make my circle last (it currently disappears almost immediately)?
>
>4) How do you manage window events in MacPerl when not using MacWindow?

I am even more in the dark on this subject than you, but here are a few
thoughts.

I think one gets on better using a new MacWindow(), since it behaves more
or less as a normal Mac window -- the close and grow boxes work and you can
move it about in the usual way. A lot of work would be needed to breath
this life into a NewCWindow. I wouldn't know how to begin. Does anyone
know?

Here is a version of your script using a MacWindow:

#!perl -w

use Mac::Events;
use Mac::Windows;
use Mac::QuickDraw;
use Mac::Fonts;

$color = blueColor;

$love = new Pattern q{
                                .XX.XX..
                                X..X..X.
                                X.....X.
                                .X...X..
                                ..X.X...
                                ...X....
                                ........
                                ........
                     };


$portR = new Rect 10, 10, 100, 200;

$bounds = new Rect 50, 50, 400, 400;
$win = new MacWindow $bounds, "Hello World!", 1, documentProc, 1;

$ptr = $win->window;
sleep(2);             # pause for grow box

SetPort($ptr);
ForeColor($color);
PenPat($love);
PaintOval($portR);

WaitNextEvent while $win->window; # see example in 'ext'

dispose $win;

As you say the picture disappears shortly after it has been drawn. I am not
sure if this a bug exactly, but what seems to happen is this. The window
draws, and the picture within it. Then after about one second the grow box
appears, and (I suspect), in the process, redraws the window area white,
thus blotting out the picture.

If you put a 2 second pause (or a getc()) after the call to new MacWindow()
it allows time for the grow box to be drawn before the picture is drawn.
You can see the sequence as you run the script.

There must surely be a better way of doing this, but I have no idea what.

I do not know the answers to questions 1, 2 and 4 and I hope someone else
can tell us.

Congratulations on sussing out the way to do the pen-pattern and how to
fill a circle with it. That is very useful to know.

Also how very nice indeed to see a genuine MacPerl thread on this list for once.

Alan Fry



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch