TweetFollow Us on Twitter

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

Technical Questions Answered

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:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »

Price Scanner via MacPrices.net

Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&T’s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
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
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer 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 MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more

Jobs Board

*Apple* Systems Administrator - JAMF - Syste...
Title: Apple Systems Administrator - JAMF ALTA is supporting a direct hire opportunity. This position is 100% Onsite for initial 3-6 months and then remote 1-2 Read more
Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.