Setting a pattern as shape-fill not working?

Hello all,

If I do

    static LCDPattern kColorChekerboard = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};

    pd->graphics->clear(kColorChekerboard);
    pd->graphics->fillRect(64, 64, 128, 128, kColorBlack);
    pd->graphics->fillEllipse(256, 64, 128, 128, 0.0f, 0.0f, kColorBlack);

Then it comes out as I expect

a

But what I really want is to fill shapes with a pattern

    static LCDPattern kColorChekerboard = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};

    pd->graphics->clear(kColorBlack);
    pd->graphics->fillRect(64, 64, 128, 128, kColorChekerboard);
    pd->graphics->fillEllipse(256, 64, 128, 128, 0.0f, 0.0f, kColorChekerboard);

and here it does not seem to work.

b

Any ideas what is wrong here?

Thanks - Tim

I guess the issue is that your pattern doesn’t include the mask (basically the alpha) and I would think the clear function is actually not using the mask so it work in that case.

1 Like

Yeah, that's a bug. If you don't provide another 8 bytes for the mask we should default to opaque, not transparent. I'll fix that now!

..ohhhh wait. This is C, so the function can't tell how big the data passed in is. :frowning: I'll make a proper constructor function for patterns, and finally make LCDColor a union like I should have in the first place.

2 Likes

Thanks both!

I mixed and matched documentation, I got the example pattern from Inside Playdate and the C API from Inside Playdate with C

Looking again, it does say "An additional 8 numbers can be specified for an alpha mask bitmap." and it is indeed a uint8_t LCDPattern[16]. But I didn't consider the possibility that it would default to transparent.

Adding the cast too for good measure to remove the warning

    static LCDPattern kColorChekerboard = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};

    pd->graphics->clear(kColorBlack);
    pd->graphics->fillRect(64, 64, 128, 128, (uintptr_t)kColorChekerboard);
    pd->graphics->fillEllipse(256, 64, 128, 128, 0.0f, 0.0f, (uintptr_t)kColorChekerboard);

and I get what I expected.

c

1 Like

I added a macro of marginal utility:

#define LCDOpaquePattern(r0,r1,r2,r3,r4,r5,r6,r7) (LCDPattern){(r0),(r1),(r2),(r3),(r4),(r5),(r6),(r7),0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}

If you don't know you need the extra mask bits, you probably don't know about the macro either.. :confused:

And the union idea was a bust--it makes LCDColor and LCDSolidColor very different things, which means there has to be a bunch of clumsy type coercion all over the place. Oh well.

1 Like

Perhaps you could consider adding an example pattern to the C docs, like in the Lua doc? If that was there, I don't think I would have made the mistake I did above.

1 Like