takkaO / OpenFontRender

TTF font render support library for microcomputer.
Other
112 stars 17 forks source link

tft_eSPI printf not using bg colour #21

Open beng2k opened 1 year ago

beng2k commented 1 year ago

Hello there,

I am trying to update text in a sprite. The numbers are displayed in the right position and using the same setCursor position. The numbers are not clearing despite setting the background colour to match the background. Here is a code snippet of the updating of the text. I cant see what I could be doing wrong?

    ofr.setDrawer(DATA3gauge);
    ofr.setFontColor(TFT_ORANGE, TFT_BLACK);
    ofr.setFontSize(35);
    ofr.setCursor(79,55);
    ofr.cprintf("ERR");
    DATA3gauge.pushSprite(320,0);
takkaO commented 1 year ago

Thank you for using this library 😊

Unfortunately, I have never used the sprite feature. Please tell me the smallest code that can reproduce the issue in my environment. And what microcontroller you are using.

Thank you.

MikeyMoMo commented 1 year ago

Note: The full demo program for OpenFontRender library I wrote is here: https://github.com/MikeyMoMo/OpenFontRender-Example-program

I have noticed the same thing. Just throw something on screen with foreground and background colors set. The background color is ignored. If you want it, that is a very good thing -- an invisible background color not changing the background of the characters. However, if you want the background color to happen, it is not good the way it is. I am writing to two different sprites and to the base tft screen.

Here is a code snippet I wrote to check out every non-trivial call in your API listing. I posted elsewhere with other errors that came up while writing and testing this program such as text height is wrong and the bounding box is wrong.

Here, the background color setting (done 2 ways) is ignored anyway. The letters come out white on black, not red.

  tft.fillScreen(TFT_BLACK);
  // Alignment Left
  // If the second font color is missing, it will be written invisible and the background color
  //  already on the screen will not be changed.  To change it, use a second color like this:
  render.setFontColor(TFT_WHITE, TFT_RED);  // Foreground, Background (optional)
  // Note, it can also be set by 8 bit hex values.  Foreground only or foreground and background, as above.
  //  render.setFontColor(0x50, 0x70, 0x150); // Mostly blue, a little green and less red. FG only set.
  //  ...or...
  //  render.setFontColor(0x50, 0x70, 0x150, 0x150, 0x70, 0x50);  // Set FG and BG to custom colors.
  //
  // You can also set the background color, only, thus:
  render.setBackgroundColor(TFT_RED);  // Change BG color only, leave font color as already set.

  // So far, the background color setting does nothing.  Maybe this is by design.

  // Alignment left
  render.setCursor(0, 0);
  render.printf("Hello\nWorld size ");  // Only foreground color honored.
beng2k commented 1 year ago

As above. Sorry for the delay. I can pull some code but this above looks very similar to what I have done as well.

As above it seems as though the background colour is ignored

MikeyMoMo commented 1 year ago

I just uploaded my full demo code that shows this (not) happening. It also shows how to use all but the most trivial calls to this library and even shows some of the trivial ones. It is my first Github repository. Please be kind... ;-))
It is here:

https://github.com/MikeyMoMo/OpenFontRender-Demo-program

There is a notation that the font BG color is not being used. I am not sure if that is in a sprite but it fails. I could do it to a sprite if necessary. I use OFR for both sprites and background (tft) screen writes and it operates the same both ways. Also under MikeyMoMo is a very full featured clock/calendar program that uses OFR for almost everything, sprites and tft writes. All works pretty well. Just a few little bugs to work out. SO glad to have this library!!!

takkaO commented 1 year ago

From v1.1, you can select background fill method. Try using the setBackgroundFillMethod() function. See GitHub Pages for details.

I am really sorry for the late updateπŸ™‡β€β™‚οΈπŸ™‡β€β™‚οΈπŸ™‡β€β™‚οΈ

MikeyMoMo commented 1 year ago

This works. The lines I used are:

      scrollSprite.fillRect(trackTimeDate, 0, scrollSpriteW, scrollSpriteH, DarkBlue);
      ofr.setDrawer(scrollSprite);
      ofr.setFontColor(TFT_WHITE, DarkBlue);
      ofr.setBackgroundFillMethod(BgFillMethod::Block);