Forums > Dev

porting QuickDraw code

February 16, 2008 | 11:12 am

Hi,
I have re-written several Max externals for Mac OS X which I had originally writting for Mac OS 9. In these objects I used several windows and did a lot of drawing in these, using the QuickDraw routines.

Having ported my code, the objects still work, but there are warning messages when compiling the code to indicate that the QuickDraw routines are now deprecated (though they still do their job).

I want to replace the QuickDraw routines, and so I started to study Quartz 2D and did some examples based on the Carbon Application framework. Is it possible to use Quartz 2D routines in Max externals in a similar way? And if so, how can I do this?

Rainer


February 20, 2008 | 4:45 pm

I don’t think you can mix QD & Quartz. Certainly not easily.

Max 4 is a QD world. XCode gives you ‘deprecated’ warnings. I think you simply have to live with it.

You also get a warning because main() doesn’t return an int. Something else you have to live with: a Max external doesn’t return anything, e basta. I’m not quite sure why XCode is so petulant about main() returning int, other than it’s common in Unix apps to do so.

– P.


February 21, 2008 | 6:59 am

QD and Quartz are easy to mix.
The only caveat is that you have to surround the Quartz code with two specific functions:

QDBeginCGContext
QDEndCGContext

between these two functions you cannot use QD functions, only Quartz.

Other than that, the only annoying thing is the different coordinate system but that’s trivial to resolve.

Also, to prevent Xcode complaining, I usually declare main as

int main
{
return 0
}

That’s enough, and my externals still work…

Comments?

- Luigi

————————————————————
THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE SENDER BY E-MAIL AT SUPERBIGIO@YAHOO.COM AND DESTROY ALL COPIES OF THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC 1-207.
————————————————————

—– Original Message —-
From: Peter Castine

Sent: Wednesday, February 20, 2008 8:45:46 AM
Subject: [dev] Re: porting QuickDraw code

I don’t think you can mix QD & Quartz. Certainly not easily.

Max 4 is a QD world. XCode gives you ‘deprecated’ warnings. I think you simply have to live with it.

You also get a warning because main() doesn’t return an int. Something else you have to live with: a Max external doesn’t return anything, e basta. I’m not quite sure why XCode is so petulant about main() returning int, other than it’s common in Unix apps to do so.

– P.


—-
Peter Castine
Litter Power: < http://www.bek.no/~pcastine/Litter/>
iCE Tools: <
http://www.dspaudio.com/software/ice/ice_overview.html>

Never miss a thing. Make Yahoo your home page.

http://www.yahoo.com/r/hs


February 21, 2008 | 8:55 am

Thanks for the tip to use QDBeginCGContext and QDEndCGContext. I just found an example in the Quartz 2D Programming Guide ("Window Graphics Context: QuickDraw"). It looks like this:

void MyDrawInWindow (WindowRef window)
{
CGContextRef myContext;

SetPortWindowPort (window);// 1
QDBeginCGContext (GetWindowPort (window), &myContext);// 2

// ********** Your drawing code here ********** // 3
CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);
CGContextFillRect (myContext, CGRectMake (0, 0, 200, 100));
CGContextSetRGBFillColor (myContext, 0, 0, 1, .5);
CGContextFillRect (myContext, CGRectMake (0, 0, 100, 200));
CGContextFlush(myContext);// 4
QDEndCGContext (GetWindowPort(window), &myContext);// 5

}

The problem I still have to fix: how can I get the WindowRef?

In order to create a window for a Max external, I declare a window pointer _t_wind myWindow in the object class and create the window by calling the wind_new function. But this window pointer is not a WindowRef. So I am afraid I won’t be able to use this pointer to call the functions SetPortWindowPort etc.

How can I get a WindowRef from the t_wind pointer?

As for main, I have also used

int main ()
{
return (0)
}


February 21, 2008 | 1:33 pm

Quote: Luigi Castelli wrote on Thu, 21 February 2008 07:59
—————————————————-
> Also, to prevent Xcode complaining, I usually declare main as
>
> int main
> {
> return 0
> }
>
> That’s enough, and my externals still work…
—————————————————-

I may be overly paranoid, but there is the possibility that the return 0 might overwrite a register that the host application is expecting not to have overwritten.

Max may be sufficiently defensively programmed to not make assumptions about what happens to D0 (or whatever register a particular architecture might happen to use for returning int) while calling your main(). And you say it works for you. Still, my inclination is to do what the API says and ignore whatever Unix-style assumptions my compiler is making.

Interesting to know the technique for mixing QD and Quartz. Still, QD *does* work on Max 4 and QD remains supported (if deprecated). My plan is to migrate before OS 10.5, on the assumption that QD has got a little life left in it yet. I’m not the only one still using it.

I used to track down every single compiler warning. In CW and THINK days this was doable (if a bit anal). With XCode I’ve not found it practicable. But good luck to you.

– P.


February 21, 2008 | 2:33 pm

Peter Castine wrote:
> Still, my inclination is to do what the API says and ignore whatever Unix-style assumptions my compiler is making.

I remember a while ago somebody from C’74 (I think it was Joshua) said
on this list it would be safe to return 0 in main().

Olaf


February 21, 2008 | 8:53 pm

It also appears to be safe to return -1 in main(), or at least nothing bad happened when I did while testing.


February 22, 2008 | 12:15 am

On Feb 21, 2008, at 12:55 AM, Rainer.Buerck wrote:

> How can I get a WindowRef from the t_wind pointer?

t_syswind wind_syswind(t_wind *x);

This actually returns a WindowRef on OS X. This is all changing in
Max 5, FWIW.

-Joshua


February 22, 2008 | 11:02 pm

On Thu, 21 Feb 2008 16:15:04 -0800, Joshua Kit Clayton wrote:
> This actually returns a WindowRef on OS X. This is all changing in
> Max 5, FWIW.

Hi Joshua-

Is there any general info about where this is all going? I’m interested
in whether 5 will support the direct use of Quartz, or some sort of
compatibility layer (btw OSX, Win, Linux) that we’ll be encouraged to
use?

Best, Charles


February 22, 2008 | 11:23 pm

On Feb 22, 2008, at 3:02 PM, Charles Turner wrote:

> Is there any general info about where this is all going? I’m
> interested
> in whether 5 will support the direct use of Quartz, or some sort of
> compatibility layer (btw OSX, Win, Linux) that we’ll be encouraged to
> use?

We’re using a cross platform graphics API which form the outside
looks like Cairo (http://www.cairographics.org), but inside it uses
JUCE. The same code will work on all platforms. Use of platform
specific APIs may or may not be supported (though I’m sure you can
find workarounds, we just won’t guarantee to support them). If you
want to learn something now, I’d suggest checking out Cairo.

-Joshua


February 23, 2008 | 12:06 am

On Fri, 22 Feb 2008 15:23:17 -0800, Joshua Kit Clayton wrote:
> If you want to learn something now, I’d suggest checking out Cairo.

Just what I wanted to know. Thanks Joshua!

Best, Charles


Viewing 11 posts - 1 through 11 (of 11 total)