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

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



Michael Ziege <ziege@ito.umnw.ethz.ch> writes:
>Philippe Rochambeau writes:
>
>>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)?

$win->portRect

>>2) How can I make my own colors using 3 RGB values, instead of using constant
s
>>such as blueColor, whiteColor, etc?

While Michael's solution appears to work superficially, it does so for
an utterly bizarre reason: His RGB color (hex 33333333FF) is passed to a
routine (ForeColor) which wants an integer argument, so it converts that
string to the number 3333, which is close enough to the old QD color blue
to be drawn as blue. Needless to say, this technique does *not* work for
RGB colors in general.

MacPerl 5.1.5 supports a RGBColor class (and RGBForeColor works for non-Color
windows, too), but I forgot to define a constructor for that class, so
to get blue, create it as:

$color = bless \pack("S3", 13107, 13107, 65535), "RGBColor";

>>3) How can I make my circle last (it currently disappears almost immediately)
?

Michael's code for this question is correct, but it is worth spelling out:
You should *not* draw permanent elements into Macintosh windows *except*
in response to update events. Your oval was erased because after drawing,
the window contents were still considered "invalid" and thus were wiped
out by the next update event.

>>4) How do you manage window events in MacPerl when not using MacWindow?

This is possible with Mac::Events. However, the deeper question is why you want
to avoid MacWindow. I'm not saying that your reason for it is bad; it might
very well be that my code is bad. Either way, though, it would be interesting
to discuss this further.

So with the changes I discussed above (and one further change: I left out the
SetPort call in the update routine, as the port is guaranteed to be set
already), Michael's code looks like this:

#!perl

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

$color = bless \pack("S3", 13107, 13107, 65535), "RGBColor";
  # A different kind of blue

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

$bounds = new Rect 40, 50, 150, 150;
$win = new MacWindow $bounds, "Hello World!", 1, documentProc, 1;
$win->sethook("redraw", \&DrawOval); #drawing routine


WaitNextEvent while $win->window; #event handler, until click in close box

dispose $win;

sub DrawOval {
        RGBForeColor($color);
        PenPat($love);
        PaintOval($win->window->portRect);
}

------

Matthias

-----
Matthias Neeracher   <neeri@iis.ee.ethz.ch>   http://www.iis.ee.ethz.ch/~neeri
   "I'm set free to find a new illusion" -- Velvet Underground

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