Google
www ResExcellence

Application Makeovers
Desktop Snapshots
iTunes Skins
Mighty Mouse Cursors
Uploads
Boot Images
Dock Poofs
Links List
Photoshop Goodies
Users Forum
Boot Panels
Download Stats
Log-In Panels
REALbasic
Clocks
GUI Software
Mac OS X Mods
Safari Stuff
Desktop Pictures
Icons
Mac OS X Themes
Splash Screens
Homepage
Download a free demo of REALbasic!
Download a free demo of REALbasic!

Recent Articles...
3D
3D Photo Gallery (Part 2)
3D Photo Gallery (Part 1)

Audio
iPod Tricks (Part 3)
iPod Tricks (Part 2)
iPod Tricks (Part 1)
Laugh Track Machine
Audio Player with Reverb
Shepard Melody
RB Phone Home
Build a Drum Machine

Custom Controls
Custom Buttons
Custom Buttons Part II
iTunes-style Listboxes
Custom Controls

General RB
Wiggle Window
JPEG in PDF
Hey! You got your Checkbox in my Listbox!
Background Applications
Listbox Auto-Find
Virtual Volumes
Time Tracker
Software Distribution (Part 4)
Software Distribution (Part 3)
Software Distribution (Part 2)
Software Distribution (Part 1)
Exceptions
Living on the Edge
Tips and Tricks
Review of REALbasic 3.0
Text Clippings Made Easy

Graphics
Image Spinner
Cropping Graphics (Part 4)
Cropping Graphics (Part 3)
Cropping Graphics (Part 2)
Cropping Graphics (Part 1)
Shimmer Graphics
Lissajous Figures
Simple Screen Capture
Vector Graphics
Kaleidoscope Images
Stegonography
Spirals!
Image Table
RB Magnifying Lens
Screen Capture
Color Picker Tutorial

Hacks
Ghost Grab
Speedy Mouse Extension
iTunes Plugins
iTunes Skinner

Internet
Display Web Image In Canvas
HTML IMG Tags
Version Tracking
Even Smarter Instant Messaging
Web Tiler
JavaScript and REALbasic
Stock Ticker (Part 2)
Stock Ticker (Part I)
AIM Mate

Mac OS X
Using Sheets in REALbasic
Build a Bundle (Part 2)
Build a Bundle (Part 1)
Dock Your Passwords
Mac OS X Debugging
REALbasic Mac OS X Icon Tutorial
Animate Your Dock
RB and the Command Line

Novelty
Guessing Game
Calendar Trivia
Tile Mixer
Zip Code Finder
Happy Valentine's Day
Merlin Simulator (Part 3)
Merlin Simulator (Part 2)
Merlin Simulator (Part 1)
Buzzword Machine
AppleSoft BASIC

Printing
Print to PDF

Registration
Registration Code Validation

Resources
Picture Extractor (Part 2)
Picture Extractor (Part 1)

Serial
Caller ID (Part 3)
Caller ID (Part 2)
Caller ID (Part 1)

Speech
Speech Recognition

Video
Big Brother Video Capture

Newest Dev Tools!

Book Alert !
REALbasic for Dummies
by Erick Tejkowski
$19.99 @ Amazon

Made with REALbasic!

Book Alert !
REALbasic the Definitive Guide
by Matt Neuburg

Problems?
Downloads are in StuffIt 5 format (free download).
Tell me about a bad link (Thanks!).
Submission Policy

6-07-01

REALbasic Color Picker Tutorial by Erick Tejkowsi

Have you ever noticed that computer people like to describe colors in a variety of ways? Web developers use one format, REALbasic programmers another, and Mac OS X resource hackers use yet a third.

This week's tutorial will show you how to build a color converter. Beginners should enjoy the project, because it is easy to complete. Pros can benefit too, because the tool is very useful. (I use mine daily.)

Programmers have several different schemes for describing color. The web folks like to talk in hex, REALbasic programmers in integers, and the 'plist' files of Mac OS X use decimals. Below is a chart showing the color schemes and their numeric ranges.

Web $00 - $FF
REALbasic 0 - 255
'plist' files 0 - 1

Build the Interface

This week's interface is very simple to build. Open Window1 and drag the following controls into your interface:

  • 1 PushButton, named PushButton1.
  • 3 EditFields, named HexField, RBField, and plistField respectively.
  • 1 Rectangle, named Rectangle1. Change its FillColor to whatever you wish.

You may arrange your interface in any fashion you desire. The idea of the application is that a user will push PushButton1 and choose a color from the color picker. Once a color has been selected, our project will convert the color into 3 color formats:

  • Hex - Useful for web pages
  • REALbasic format - Handy for coding REALbasic graphics
  • 'plist' format - Great for editing 'plist' files in Mac OS X

Pictured below is a sample interface. (Note how the extra StaticText and Line controls spruce up the interface.)

06-07_interface.jpg (20k)

Add the Code

Like the interface, the code portion of this week's tutorial is very easy to recreate. Open the Action event of PushButton1 and add the following code:

Dim r,g,b as String
Dim dr,dg,db as Double
Dim c as Color
Dim colorSelected as Boolean


//set the default color for the color picker dialog
c = Rectangle1.FillColor

//let the user select a new color
colorSelected = SelectColor(c,"Select a Color")


if colorSelected = TRUE then
//update the color in the interface
Rectangle1.FillColor=c

//*******************************
//
// Calculate Hex color values ($00-$FF)
//
//*******************************
r = hex(c.red)
//make sure the red hex string is two digits long
if len(r)=1 then
r = "0" + r
end if

g = hex(c.green)
//make sure the green hex string is two digits long
if len(g)=1 then
g = "0" + g
end if

b = hex(c.blue)
//make sure the blue hex string is two digits long
if len(b)=1 then
b = "0" + b
end if
//display color info
HexField.text = r + ", " + g + ", " + b

//*******************************
//
// Calculate REALbasic color values (0-255)
//
//*******************************
//convert integer color values to strings
r = str(c.red)
g = str(c.green)
b = str(c.blue)
//display color info
RBField.text = r + ", " + g + ", " + b

//*******************************
//
// Calculate plist color values (0.0 - 1.0)
//
//*******************************
//change values to decimal percentages
// and convert color values to doubles
dr = c.red/255
dg = c.green/255
db = c.blue/255

//convert doubles to formatted strings (i.e. with decimal points)
r = format(dr,"#.00##")
g = format(dg,"#.00##")
b = format(db,"#.00##")
//display color info
plistField.text = r + ", " + g + ", " + b
end if

First, we allow the user to select a color using the standard color picker. On Mac OS X, it looks like this:

06-07_picker.jpg (15k)

If the user selects a color, we convert the red, green, and blue values of the Color object into the three color formats: Hex, RB, and 'plist'. There is a bit more involved in the Hex conversion than the others. This is due to the fact that all numbers below 16 will return only one digit in hex. However, HTML requires double digits. The extra code tacks on a leading "0" (zero) if the string is only one character long.

The REALbasic color format has a range of 0 to 255. No conversion is necessary.

Finally, the 'plist' format is somewhat unique, because we must use Double type variables in this conversion. 'plist' colors fall in the range between 0 and 1. Since decimal points are involved, Double variables are required. The Format command cleans up the decimal points and puts them into a string which we then display.

Test and Build

That's it! To test, select Debug->Run. Once you have it down pat, select File->Build Application. This week's example is compatible with Mac OS Classic, Mac OS Carbon, and Microsoft Windows.

As usual, you may:

And, for the first time in this column... Microsoft Windows!


6-05-01

REALbasic News by Erick Tejkowsi

Can they ship by kangaroo? REAL Software announced the availability of REALbasic for the Australian market. Streetwise Software will be taking care of sales,distribution, and support for RB users down under. Welcome Streetwise Software!

MacTech extends deadline. If you are interested in competing in the June MacTech REALbasic Challenge, the deadline for submission has been extended to June 8. Get those entries in!

Cool Eye Candy!. Do your REALbasic interfaces need some improvement? Everyday Software has updated the popular MS Style Buttons 2.8 and Mac OS X Toolbar Buttons 1.0 (pictured below). They look great and they're a cinch to use!

Object Binding Tutorial. Quantum Meruit has a new and improved Object Binding tutorial available. This is one of the better explanations on the topic I have seen.

Who's got the fastest finger?. REALbasic University has a nifty REALbasic tutorial for creating a fast-action finger game, 'ala Who Wants to be a Millionaire. They also show you how to build an email utility app. If that weren't enough, they even answer reader's RB-related mail. Whew!

Super Duper!. Essence Software has updated the REALbasic must-have Super Socket 2.0.2. If you are working with networks in your RB apps, there's no better tool around.

Hurry, get the plunger.... VanHoek and crew have done it again. Plugin Plunger has reached version 2.3 and is available for download. If you are unfamiliar with this tool, it let's you peer inside plugins to learn what classes, methods, and other goodies are located within. Oh yes, it's free too!

More GUI Goodies. While you're busy downloading cool RB tools, be sure to pick up HierPop 1.6. It gives you the ability to create contextual menus with icons among other useful tricks.



Application Makeovers
Desktop Snapshots
iTunes Skins
Mighty Mouse Cursors
Uploads
Boot Images
Dock Poofs
Links List
Photoshop Goodies
Users Forum
Boot Panels
Download Stats
Log-In Panels
REALbasic
Clocks
GUI Software
Mac OS X Mods
Safari Stuff
Desktop Pictures
Icons
Mac OS X Themes
Splash Screens
Homepage

Maintained by the Staff of ResExcellence. This entire site ©1997-2003 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.

[an error occurred while processing this directive] on the ResEx LinuxPPC Server