home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / next / programm / 7805 < prev    next >
Encoding:
Text File  |  1992-12-17  |  2.3 KB  |  48 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!psinntp!afs!greg
  3. From: greg@afs.com (Gregory H. Anderson)
  4. Subject: Re: Colored Button
  5. Message-ID: <1992Dec16.192424.6320@afs.com>
  6. Sender: greg@afs.com
  7. Reply-To: greg@afs.com
  8. References: <U3S9T0P@gwdu03.gwdg.de>
  9. Date: Wed, 16 Dec 1992 19:24:24 GMT
  10. Lines: 36
  11.  
  12. Mail to the referenced address bounced, so pardon my bandwidth for posting  
  13. the answer here. It's short and sweet, and maybe you'll learn something  
  14. you didn't know about Buttons and ButtonCells anyway.  8^)
  15.  
  16. In article <U3S9T0P@gwdu03.gwdg.de> mzeller@gwdg.de writes:
  17. > I'd like to have a colored button - I don't want to use a TIFF Icon for  
  18. it.
  19.  
  20. This is harder than you realize. You would have to subclass ButtonCell,  
  21. not Button, because that's where the actual drawing gets done. In fact,  
  22. the -setXxxColor methods in the View classes, like TextField, are actually  
  23. cover methods for the underlying Cells. To get what you want, you would  
  24. need to add an instance variable for the color(s) and subclass the -read:  
  25. and -:write methods to store it. You would need to add set/return methods  
  26. for the color(s) in the ButtonCell and Button classes. You'd probably want  
  27. a custom IB inspector with a color well, so you wouldn't be forced to set  
  28. the colors programatically.
  29.  
  30. Here's the really difficult part. You would need to completely replace the  
  31. -drawInside: method of ButtonCell, using your color(s) as the foreground  
  32. and/or background fill color(s). The ButtonCell draw code is complicated.  
  33. There are numerous combinations of text/icon placements, on/off states  
  34. (which may have different icons and/or text), highlighting, etc. You'd  
  35. have to get it all exactly right if you wanted the perfect substitute for  
  36. a ButtonCell. That would take some patience and iterative testing. Plus,  
  37. you'd have to be prepared to enhance its capabilities as new releases of  
  38. the AppKit appear.
  39.  
  40. I know a lot (not all) about how to do it, but I wouldn't want to replace  
  41. ButtonCell's draw code from scratch on a deadline. I think the best  
  42. solution is to lobby NeXT for this behavior in a future release.
  43. --
  44. Gregory H. Anderson          | Thus spake the master programmer: 
  45. Master Programmer / Manager  | "Let the programmers be many and  
  46. Anderson Financial Systems   | the managers few; then all will be 
  47. greg@afs.com  (Nextmail OK)  | productive." -- Tao of Programming
  48.