On 25 Sep 2001 16:55:34 -0700, Mark Wrenn wrote:
> I'm confused by Zoolib color support. I would expect the following to fill
> the rectangle with the color red:
>
> ZDCInk *ink = new ZDCInk( ZRGBColor( 255, 0, 0 ) );
> inDC.SetInk( *ink );
> inDC.Fill( theRect );
>
> Instead I get a black rectangle. I don't get it. Tracing through the code
> hasn't helped. Maybe this is a Mac issue?
ZRGBColor's components are 16 bit unsigned ints, although most pixmaps,
screens etc have at most a resolution of 8 bits per component -- 255
thus gets truncated to 0 (0x00FF --> 0x00), ie to black. On the other
hand, ZRGBColorSmall (better name anyone?) has 8 bit unsigned
components, and when it's converted to a ZRGBColor the 8 bits are
'smeared' across the full 16 bit range, so 0xFF --> 0xFFFF and 0x88 -->
0x8888.
Note that ZDCInk is geared towards use as a value-based type -- it's not
necessary nor generally desirable to allocate it from the heap. Under
the hood there is a reference counted representation, which will hold
either a single ZRGBColor, or a pair of colors and a bi-color pattern,
or a pixmap. It also has conversion constructors from ZRGBColorPOD (the
POD base for ZRGBColor) So to draw a red rectangle the following
suffices:
inDC.SetInk(ZRGBColor(0xFFFF, 0, 0));
inDC.Fill(theRect);
Or you could use the convenience static ZRGBColor::sRed thus:
inDC.SetInk(ZRGBColor::sRed);
ZRGBColor (and ZRGBColorSmall) also support basic arithmetic -- adding
two ZRGBColors does a clamped add of each colors' components.
A+
|