Colors Everywhere #
First thing I worked on today was to improve the handling of the clicks within the fore/background color control. Since it is a custom control, I get to write it's HitTest routine. I get as the parameters the place where the user clicked, and I can do whatever I want with that. I used two PtInRect calls to determine which rectangle the user clicked in, and returned part code I had defined (part codes are just integers, so I just made two new constants, kForeColorPart and kBackColorPart to represent the two rectangles). Then in the HandleContentClick routine I look at which part code was returned (until now I was just looking to see if a part code was returned at all, now I'm looking at which one) and call the color picker for the appropriate color. In this way I can add other gadgets to the custom control (like Photoshop's switch colors widget, and the reset colors one too) by simply adding a new part code and the appropriate hit test checks.
Then I made the color swatches be actually drawn in the current icon's fore/background colors. Since the drawing function couldn't be part of the class, I had to go through a more roundabout way to get the colors. The control has a contrlOwner field, which stores a pointer to the window it belongs to. When I create the window for an editor I put in its WRefCon field a pointer to the instance of the class which represents this editor. Then when I need to find which class the window belongs to I just do a GetWRefCon, cast it as a icnsEditorPtr and I've got the class (this is used in many places, like in my event loop, to determine how to refresh a window, etc). So in the end I obtained the pointer to the parent class, and got its foreColor and backColor fields, and did a PaintRect with them. Then whenever the user changes the colors I just call a Draw1Control to refresh it.
Now that I added color picking I discovered that my pixel-setting function wasn't working. This was because in the RGBColor structure the component values were up to 65535, but in a 32 bit image they go to 255. In end I got the most significant byte of each color, and "added" all of them in a long, which corresponded to the address of the pixel in the pix map. Of course I could of used the system function SetCPixel, but it would have been rather slow (or so I was lead to believe, from what the Black Art of Macintosh Game Programming book says).
Post a Comment