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

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
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
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more
New promo at Visible: Buy a new iPhone, get $...
Switch to Visible, and buy a new iPhone, and Visible will take $10 off their monthly Visible+ service for 24 months. Visible+ is normally $45 per month. With this promotion, the cost of Visible+ is... Read more
B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for $100 off Apple’s new MSRP, only $899. Free 1-2 day delivery is available to most US addresses. Their... Read more
Take advantage of Apple’s steep discounts on...
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

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel 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
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
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.