TweetFollow Us on Twitter

3D Controls in Sys 7 Apps

Volume Number: 13 (1997)
Issue Number: 6
Column Tag: Look And Feel

Adding 3D Controls to your System 7 App

by Jeff Beeghly

Custom controls can be used to provide Apple's Grayscale Appearance for System 7 applications

Introduction

Applications containing 3D controls are becoming the standard in the computer industry. Users and developers prefer applications which contain a "3D object" look and feel. For some time now, developers have been implementing their own version of 3D controls. The intent of this article is to demonstrate how to effortlessly transform an application from the standard 2D appearance into a 3D appearance.

Transforming Dialogs into the 3D World

By following these simple steps, you can transform your dialog boxes and give them a new "3D look and feel":

  1. Add 3D Buttons CDEF.rsrc to your project. This file is in the source code package which accompanies this article.
  2. Change the content color of every dialog box (and alert box) within your projects' resource from white to gray. If you're using ResEdit, this is accomplished by opening a DLOG resource, changing the color from Default to Custom and changing the content color to light gray (Figure 1).

    Figure 1. Setting the Content Color to Gray Within ResEdit.

    If you're using Resorcerer, this is accomplished by opening a DLOG resource, selecting the Set Dialog Info... menu item, selecting the Window Color Content item, then setting each of the RGB values to 56797 (0xDDDD Hex).

    Figure 2. Setting the Content Color to Gray Within Resorcerer.

  3. Every edit text item within the dialog box must have its background color set to white. This is accomplished by creating a dialog item list color table ('ictb') resource for each dialog. If you're using ResEdit you will have to create an 'ictb' resource that has the same ID as the 'DITL' resource you are working with. ResEdit does not have an 'ictb' editor, so you will have to assemble one by hand using ResEdit's Hex editor. For more information on the 'ictb' resource and its' format, please consult "The Item Color Table Resource" within Inside Macintosh: Toolbox Essentials, or consult the "NewCDialog" topic within THINK Reference.

    If you're using Resorcerer, you will need to select the edit text item, then select the Color and Text Styles... menu item (which will bring up the Color and Text Styles dialog box). Since the default background color is white, the only thing you need to do here is select the Backcolor checkbox.

    Figure 3. Setting the background color of an edit text item within Resorcerer.

  4. Add Update3DDialog.c to your project.
  5. In each dialog of your application, there should be a modal dialog filter. Within each filter, add the function Update3DDialog() to the update switch (Listing 1) and include Update3DDialog.h within the source code.

    Listing 1: ExampleDialogProc

    // Add this include
    #include "Update3DDialog.h"
    
    pascal Boolean ExampleDialogProc(DialogPtr pTheDialog,
    EventRecord *pTheEvent, short *pnItem)
    {
        WindowPtr   pWindow;
        GrafPtr     pOldPort;
        short       nType;
        Handle      hItem;
        Rect        rItem;
    
       switch( pTheEvent->what )
       {
          case updateEvt:
            pWindow = (WindowPtr )pTheEvent->message;
            if(pWindow == (WindowPtr )pTheDialog)
            {
              GetPort(&pOldPort);
              SetPort(pTheDialog);
    
              BeginUpdate(pTheDialog);
              UpdateDialog(pTheDialog, pTheDialog->visRgn);
              DrawDefaultButtonOutline(pTheDialog, OK_ITEM);
              hPic = GetPicture(USER_PIC_ID);
              GetDItem(pTheDialog, USER_ITEM, &nType,
                 &hItem, &rItem);
              DrawPicture(hPic, &rItem);
       
              // Add this function
              Update3DDialog(pTheDialog);
              EndUpdate(pTheDialog);
    
              SetPort(pOldPort);
            }
            break;
             .
             .
             .
    
  6. Recompile and run your application.

What could be simpler?

What's Going on in There?

The CDEF that was added to the project is a modified version of the 3D Buttons CDEF v1.08 written by Zig Zichterman (located at http://www.best.com/~ziggr/ as well as many InfoMac and UMICH ftp mirrors). By adding the 3D Buttons CDEF and giving it a resource ID of 0, the standard system controls (which are contained within the System's CDEF 0) are replaced with the 3D Buttons CDEF when the application is launched. The standard push button, radio button, and check box now contain the new 3D appearance (Figure 4). Please note that the standard controls will only be modified for your application, not system-wide. If you switch to other applications while your application is running, you will notice that the other applications still contain the standard system controls they had before.

Figure 4. 3D Push Button, 3D Radio Button, and 3D Check Box.

Our CDEF is also very intelligent; it knows when it should be drawn in 3D and when it should be drawn in 2D. When the control is drawn, it checks for the following three conditions:

  • Does the machine have color Quickdraw?
  • Is the GDevice in which the control will be drawn set to at least 256 colors?
  • Does the dialog box have a colored background?

If all three conditions are met, the control is drawn in 3D, otherwise the standard 2D control is drawn. Using this convention, dialog boxes only appear in 3D when specifically intended to be that way.

When wouldn't you want dialogs to look 3D? While working on a recent project I noticed a discrepancy within the StandardPutFile dialog box. Every control contained the 3D appearance except the New Folder button. This control is not a standard control and is not overwritten by the added CDEF. In this situation, consistency is more important than having a 3D appearance, so the dialog was left with it's original 2D appearance.

Why Not Use the Original 3D Buttons CDEF?

The original 3D Buttons CDEF is modeled after the suggested 3D style guide described in the article, "Working in the Third Dimension" which appeared in the September 1993 issue of develop (issue 15). Since the publication of this article, Apple has released a document titled "Apple Grayscale Appearance For System 7.5," located at ftp://ftpdev.info.apple.com/Developer_Services/Technical_Documentation/Human_Interface/Apple_Grayscale_Appearance.sit.hqx. The new version of the CDEF incorporates the new Apple Grayscale Appearance guidelines, separates the push button CDEF from the standard controls CDEF, fixes two bugs that were in the original 1.08 code, and includes several project-wide #ifdefs.

The project was also converted from C++ to C. By converting the source from C++ to C, I was able to take out redundant code, redundant code paths, and eliminate a lot of overhead that's inherent with C++. I analyzed the performance of the drawing of the CDEFs and found that the C version of the push button was 30% faster then the C++ version, and the C version of the icon button was 67% faster then the C++ version. An added benefit is that the size of the C CDEFs are smaller than the size of the C++ versions. The downside is that the C version isn't as readable as the C++ version. For more detailed information on the changes that were made, please consult the Read Me file within the 3D Plug&Play:3D CDEFs f folder.

Example 1

Example 1 is a simple dialog demonstrating a little bit of everything. Each of the three button styles are represented and the example also displays the buttons in their disabled state. If you observe the edit text item and the list box item, you will notice that both items contain a 3D rim (Figure 5). The rim has been added to give the appearance of depth to each object. The rim is drawn with the Update3DDialog routine, which parses the DILT of a dialog. The current incarnation of Update3DDialog looks at each item within the DITL list, and draws the rim if the item is an editText, picItem, or userItem.

Figure 5. 3D Rim Around a List Box.

Example 2

One of the purposes of this article is to provide developers an effortless (or near effortless) way to give their dialog boxes a 3D look and feel. To ensure that the routines would be widely usable and not dependent on my methodology or style, I added the routines to several different building blocks. I used TransSkel's DialogSkel example, Metrowerk's CDialogsApp PowerPlant example, a Resorcerer-generated dialog, and a code snippet called Dim Text.

The easiest example to convert was the TransSkel example which required only the added files and modifications listed before. The PowerPlant example was very simple as well, however it is not complete. The PowerPlant example creates windows instead of dialog boxes and 'DITL' resources, so my Update3DDialog routine was useless in this case. Rather than write a class that overrides any of the PowerPlant classes (which has a high chance of conflicting with the other classes), this has been left as an exercise for the reader.

The Resorcerer example was also easy to convert, except I had to create an unique version of Update3DDialog (Update3DDialog-Resorcerer.c). Resorcerer uses user items to display group boxes, and the original update routine draws a 3D rim around user items. Dim Text was also easy to convert, however, some minor modifications were required. For more information on the changes made to each of these projects, please consult the notes file located within each project's folder.

Example 3

Example 3 is an expansion of Example 1. Within Example 3 you may open a 3D or 2D dialog box. Some users may not prefer to have 3D buttons (or may choose their own interface with Mac OS 8). Within the Example 3 application is a preferences dialog. The sole purpose of this dialog box is to change the appearance of the controls from 3D to 2D and back. This is accomplished by using Get1Resource and SetResInfo to move the 3D CDEF resource out (and back into) the CDEF 0 location, and changing the background color of DITL and WIND resources. When the CDEF is not in the 0 location, the standard controls that are built into the System are used instead of our custom CDEF. This technique allows the user to decide upon the appearance of the application.

This technique also allows the application to be compatible with MacOS 8. As stated earlier, the application achieves its 3D look by overriding the standard CDEF 0 that is built into the system. By this same convention, it will probably override any appearance setting the user has set with the Appearance Manager in MacOS 8. By providing this mechanism, the user has the ability to use the advance controls with the current system, and use MacOS 8's customizable controls when it is released.

Example 4

Example 4 demonstrates what you can achieve when you use 3D controls. The example not only incorporates the 3D controls demonstrated earlier, it also contains an Icon button, Group Box, and a Plus/Minus (Spindial) CDEF, all of which can be displayed in 3D (Figure 6) or 2D.

Figure 6. 3D Buttons CDEF along with Icon button, Group Box, and Plus/Minus CDEFs.

In addition to this dialog box, Example 4 also contains dialog boxes which focus on the different kinds of Group Box, Plus/Minus, and Icon Button variations that are available. Of special importance is the Icon Button CDEF. Developers are increasingly incorporating tool pallets within their applications. Within these tool palettes are usually a large number of icon buttons. The behavior of icon buttons typically act as push buttons, yet some icon buttons may act as checkboxes (like Microsoft Word's text alignment buttons) or radio buttons (like Photoshop's Tool palette).

While working on the code for Example 4's Icon Button dialog, I noticed that the icon buttons that were intended to act as checkboxes or radio buttons produced a flickering effect. The problem is when the control is selected and the mouse button is released, the control is sent a redraw message from the system, and the control is drawn in the off position. The code within the application then changed the value of the control and displayed the control in a selected position (Figure 7).

Figure 7. Flicker Producing Drawing Process.

To overcome the unwanted flicker, I added code within the CDEF to handle this special case and I added a new variation number to the Icon Button CDEF. Use variation 3 for a push button style icon button, and variation 4 for a checkbox or radio button style icon button. For example, if the ID of the Icon Button CDEF is 1101, the ProcID of a push button style icon button is 17619 (1101 * 16 + 3 = 17619) and 17620 for a checkbox or radio button style icon button (1101 * 16 + 4 = 17620).

Conclusion

What has been demonstrated here is just the tip of the iceberg. There is plenty of room for development of more 3D controls. There is also room for implementing user interface elements that are controlled by the user. For example, the Preferences dialog could not only relocate the 3D Buttons CDEF, it could change the background color of each dialog and alert back and forth between white and gray.

For More Information

If you are interested in developing CDEFs, I'd suggest the following materials:

  1. 3D Buttons CDEF, by Zig Zichterman, located on http://www.best.com/~ziggr/.
  2. CDEF Template, by Chris Larson, located on ftp://mirrors.apple.com/mirrors/info-mac/dev/src/cdef-template-10.hqx.
  3. Jim's CDEFs, by Jim Stout, located on ftp://mirrors.apple.com/mirrors/info-mac/dev/lib/jims-cdefs-15.hqx.
  4. A Fragment of Your Imagination, by Joe Zobkiw, Adison-Wesley
  5. More Mac Programming Techniques, by Dan Sydow, M&T Books
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
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 »

Price Scanner via MacPrices.net

Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more
Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more
Every version of Apple Pencil is on sale toda...
Best Buy has all Apple Pencils on sale today for $79, ranging up to 39% off MSRP for some models. Sale prices for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more

Jobs Board

Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Regular Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular 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
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.