Technical Questions
 Volume Number: 1 Issue Number: 11 Column Tag: Ask Prof. Mac

By Steve Brecher, Software Supply, MacTutor Contributing Editor

[Prof. Mac is dedicated to helping you solve your Macintosh Programming problems. Each month Prof. Mac will research out your problem and print the best possible solution in MacTutor. Don't waste time in frustration! Send your technical questions to Prof. Mac and let him research your problem for you. Write to Prof. Mac, care of this Journal. -Ed.]

## Coordinate Systems

Q. Moving a window by using MoveWindow(..., <portRect.left+offset>, <portRect.top+offset>, ...) doesn't work. What do I need to do?

A. The coordinates you pass to MoveWindow must be global coordinates, so transform them with calls to LocalToGlobal first. The distinction between local and global coordinates can be confusing (it was to me, anyway), so let's discuss coordinate systems.

A coordinate system is an abstraction. I visualize it as an infinitely large sheet of graph paper with one intersection of grid lines designated 0,0. By assigning one grid intersection (0,0 or any other ) to a specific bit in memory, we thereby are able to refer to pixels (memory bits) in terms of coordinates rather than in terms of RAM addresses. This is very convenient when thinking about graphics.

The QuickDraw bitmap is what associates a particlar coordinate system (graph paper) with a particular set of memory locations.

Think of the sheet of graph paper thumbtacked to a bit in memory. The thumbtack goes through the graph paper at the intersection designated by the top, left coordinates of the bitmap's bounds rectangle; this can be any intersection at all -- it needn't be 0,0. The tack's point sticks into memory at the location designated by the bitmap's baseAddr.

A point expressed in local coordinates is merely one that has been thus assigned to a pixel as specified by the relevant grafPort's bitmap. Each and every coordinate found in a grafPort (in the sense of a field in a Pascal record) is, by definition, local to that grafPort.

When we wish to compare the locations with respect to memory (screen) of points in two different grafPorts, we must adjust their coordinate systems so that the same intersection on each port's graph paper is assigned ("thumbtacked") to the same pixel. The convention for doing this is to "move" each graph paper so that its 0,0 coordinate is at the lowest-addressed pixel. Note that this method of inter-port comparison works only if both lowest-addressed pixels (baseAddr's) are the same! This implied requirement -- satisfied, of course, if both baseAddr's are equal to screenBase -- is usually taken for granted in IM discussions.

A local coordinate is an expression of vertical and horizontal distance from the 0,0 intersection on the particular piece of graph paper associated with a grafPort. A global coordinate is an expression of vertical and horizontal distance from the baseAddr pixel. If (and only if) two ports have the same baseAddr, then global coordinates from each may be compared and yield a valid graphics relationship.

While the QuickDraw chapter of Inside Macintosh says (of two ports being compared) "using the same bit image (such as the screen)", the rest of IM when using the term "global" takes for granted that the screen is in fact the common bit image for both ports.

When IM says a document being drawn "sticks to the coordinate system," I mentally translate that to "sticks to the graph paper"; similarly, I mentally translate "sticks to the screen" to "sticks to memory."

Of course, the memory locations designated by a bitmap do not have to coincide with the memory from which the screen is displayed. Drawing merely affects the memory designated by the bitmap; if that memory is (all or partially) in the screen buffer, then the screen display will be affected.

## QuickDraw Regions Limitation

Q. L. Tannenbaum of Long Beach, CA, submitted some MacFORTH code that illustrates a problem with QuickDraw's handling of complex regions. His program created 17 vertically-oriented rectangles while defining a region. Subsequently FrameRgn didn't seem to work correctly. He wants to know if the problem is in his code or in QuickDraw.

A. By doing some experiments ,and with the help of MacsBug, I analyzed the problem as follows.

There is a problem in QuickDraw's handling of regions containing more than 12 vertical (higher than wide) rectangles. FrameRgn of a region containing more than 12 vertical rectangles will paint them instead of frame them, and rectangles after the 12th (from left to right) will be enlarged horizonally.

If there are more than 24 such Rectangles, FrameRgn will crash with an address error.

The problem seems to be due to the way region information is stored, in conjunction with the fact that some routines (e.g., FrameRgn, possibly as a part of code common to other routines) allocate a fixed amount of space on the stack which is not large enough to accommodate a chunk of information recorded for the region.

For (at least) multiple rectangles, region information is stored in chunks consisting of pairs of arrays of coordinates in the form

```  top[i]         left[1] right[1] left[2] right[2] ... left[n] right[n]
bottom[i]    left[1] right[1] left[2] right[2] ... left[n] right[n]

```

where i ranges over 1 to the number of horizontal lines on which the rectangle corners lie, from top to bottom of the grafPort's portrect. Each array is terminated with a \$7FFF marker.

For horizontally-oriented rectangles, n=1, and each array contains exactly 3 coordinates. For vertically-oriented rectangles, n is equal to the number of rectangles, and each array is therefore potentially large. QuickDraw appears to do a Link A6,#-562, and part of the stack frame thus allocated appears to be filled with a chunk of coordinates via autoincremented A2 as the destination address of a move loop. If the chunk is too large, stack frame underflow will result.

I submitted the above to Apple's Tech Support team, and Ginger Jernigan replied:

"It isn't a bug, it is a limitation in QuickDraw, which will be documented in the final version of Inside Macintosh. Your analysis of the situation was correct. We're working to fix it or at least alleviate the nasty problems that occur (like getting real syserrors from Quickdraw calls)."

## Boldly Outlining Buttons

Q. Mike Scanlin asks: how do you get the thick border to outline a button in a dialog box for the button representing the default if the user hits Return (usually either "OK" or "Cancel")?

A. Usually such button highlighting appears in alert boxes. The Dialog Manager automatically highlights either item 1 or item 2 in an alert box. Whether item 1 or item 2 is highlighted depends on the value of a bit in the "stages" word for the current stage of the alert. (See Inside Macintosh, Dialog Manager, pp. 34-36.)

The stages word is located in the ALRT resource, and is divided into four 4-bit parts, each part governing one stage, or consecutive occurrence, of the alert. One bit in each part governs item highlighting; if the bit is clear, item 1 is highlighted, and if it's set, item 2 is highlighted.

Often item 1 is an "OK" button and item 2 is a "Cancel" button, and IM assumes this in its illustration. But in fact the Dialog Manager will highlight item 1 or item 2 regardless of what kind of item it is. This can somethimes be a problem. For example, if you have an alert with only a message (a statText item) and an "OK" button, you don't want any highlighting. But the Dialog Manager will relentlessly highlight either item 1 or item 2; if the statText is item 2 and the appropriate bit in the stages word is set, the text will have an ugly bold round-corner rectangle drawn around it. If the bit is clear, the "OK" button will be highlighted, which would be silly since it's the only enabled item.

The only way to handle such a situation is to add a dummy item to the alert's item list (such as a one-character statText item located outside of the alert's rectangle) and let that dummy item "take" the highlighting. In our example, the dummy item could be item 1, and the bits in the stages word would be clear so that item 1 is highlighted. To see an example of this technique, use ResEdit to examine the Finder's DITL 129 resource.

To highlight a button in a dialog that is not an alert, you can use a userItem. Usually a userItem just draws a non-standard item, such as a picture. In this case, we can employ a userItem to change the appearance of another item -- namely, of our button.

A userItem consists of a procedure, as documented in IM, Dialog Manager, p. 11. We will ignore the itemNo parameter, since the item that the userItem will be operating on is not the userItem itself, but the button we want to outline. The QuickDraw techniques for boldly outlining a button are shown on p. 13 of the Dialog Manager section:

```PenSize(3,3);
InsetRect(displayRect,-4,-4);
FrameRoundRect(displayRect,16,16)
```

--where displayRect is the button's display rectangle; GetDItem can be used to obtain it.

## Print Dialogs

Q. Paul Cozza of Long Beach, CA, asks: two undocumented Printing Manager routines -- PRSTLINIT and PRJOBINIT -- were mentioned on p. 32 of the First Draft (6/11/84) of Printing Manager section of Inside Macintosh. Apple promised documentation in a later release of the manual, but the routines have mysteriously disappeared altogether from the latest version (Second Draft, 3/27/85, distributed with the May 1985 Software Supplement). If these routines are now unavailable, what is the way to modify the print style and job dialogs?

A. My guess is that the routines succumbed to the generalization of printing procedures that was necessitated by the advent of the Laserwriter.

In the Imagewriter file (I'll let you know about the Laserwriter as soon as I can afford one!), the style dialog is the DLOG -8192 resource, and the job dialog is DLOG -8191. If you examine DITL (dialog item list) -8192, you'll see only placeholders where the paper sizes appear in the style dialog.

At least with respect to Imagewriter paper sizes, it is possible to make some changes. The PREC 3 resource in the Imagewriter file specifies the names of the papers as they will appear in the style dialog, and the sizes of the paper. The format of the PREC 3 resource is as follows:

n [1-word count] -- number of paper sizes;

n pairs of words -- vertical,horizontal paper size in 120ths of an inch;

n Pascal-format strings -- names of paper sizes;

1 word -- ? (probably flags for Orientation, Pagination, Reduction).

Up to six paper sizes can be accommodated by the style dialog box. The distributed Imagewriter file PREC 3 resource contains the specifications of five sizes (US Letter, A4 letter, US Legal, International Fanfold, Computer Paper).

As to other aspects of the dialogs I'm afraid you're on your own; I note the following warning in IM : "Your application should not change the data in the print record -- be sure to use only the standard dialogs for setting this information."

Community Search:
MacTech Search:

## Latest Forum Discussions

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

## Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for \$500-\$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for \$699, \$300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to \$600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at \$2969 and ranging up to \$600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to \$480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at \$1699 and ranging up to \$480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for \$80-\$100 off MSRP, starting only \$249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a \$50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for \$249, Certified Refurbished. That’s \$50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to \$400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for \$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for \$150-\$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering \$170-\$200 discounts on new...
Amazon is offering a \$170-\$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at \$1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

## Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more