Is there a technique for drawing text in white / off-pixels using the C-API ?
Originally I coded score-functions & what-not to just write the font, but then my pixel-artist supplied black backgrounds, and now the text is invisible.
And for a purely selfish request: I would like a getTextHeight() function please.
I know this is a little bit old, but for people who wants examples and got here in the future, check this, I think it can help
void drawTextColor(LCDBitmap* BitmapContext, LCDFont *font, const void* text, size_t len, PDStringEncoding encoding, int x, int y, LCDColor color, bool inverted)
{
//grab width & height of our to be rendered text
pd->graphics->pushContext(BitmapContext);
int h = pd->graphics->getFontHeight(font);
pd->graphics->setFont(font);
int w = pd->graphics->getTextWidth(font, text, len, encoding, 0);
//create new bitmap and fillrect with our color / pattern
LCDBitmap *bitmap = pd->graphics->newBitmap(w, h, kColorClear);
if (inverted)
pd->graphics->setDrawMode(kDrawModeInverted);
pd->graphics->pushContext(bitmap);
pd->graphics->fillRect(0, 0, w, h, color);
pd->graphics->popContext();
//create mask with black background and draw text in white on the mask
LCDBitmap *bitmapmask = pd->graphics->newBitmap(w, h, kColorBlack);
pd->graphics->pushContext(bitmapmask);
pd->graphics->setDrawMode(kDrawModeFillWhite);
pd->graphics->setFont(font);
pd->graphics->drawText(text, len, encoding, 0, 0);
pd->graphics->popContext();
//set the mask to the bitmap with our pattern, this will make sure only the text
//part (white in mask is drawn from the bitmap)
pd->graphics->setBitmapMask(bitmap, bitmapmask);
//now draw the bitmap containing our text to the x & y position
pd->graphics->drawBitmap(bitmap, x, y, kBitmapUnflipped);
pd->graphics->freeBitmap(bitmap);
pd->graphics->freeBitmap(bitmapmask);
pd->graphics->popContext();
}
source: https://gist.github.com/joyrider3774/67d6783bfc2fefafc40f3f911ec93205