Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tumbler Numbers - Used to work now doesn't #3588

Open
DrJaymz opened this issue Dec 19, 2024 · 1 comment
Open

Tumbler Numbers - Used to work now doesn't #3588

DrJaymz opened this issue Dec 19, 2024 · 1 comment

Comments

@DrJaymz
Copy link

DrJaymz commented Dec 19, 2024

I created a tumbler routine like the old tumblers you'd see on a Gas pump or car dashboard.
It works by working out where the digit we want is in the "window" then adding the digit before and after. Its all drawn on a sprite which is then pushed to the display.

This used to look cool but now no longer works. I think the problem is that the way in which text that is printed out of bounds is handled. The previous and next digits may be partially or completely obscured. This didn't used to matter.

I found the function setTextWrap and disabled it for x and y - doesn't make any difference.
For the following the sprite is 55x55 and I think digits are 0 to 99. What it should do is show 10,20,30,40 passing by.

If you can think of a better way with clipping or scrolling rectangles I'm happy to change it.

(ignore the colours and casting to floats etc I was trying to work out what was happening, the GREEN text works as exected, the other two appear over the top in the centre)

void printTens(float digit, int x)
{
  digits.fillSprite(TFT_BLACK);
  digits.setTextDatum(ML_DATUM);
  digits.setFreeFont(&FreeSansBold12pt7b);
  digits.setTextWrap(false,false);

  digit += 0.5;

  float pixel_fraction = (float)digits.height() / 10;
  float vLocation;
  int figure = (int)digit;

  if (figure == 10)
    figure = 0;

  sprintf(strBuff, "%01d0", figure);
  vLocation = (10.0 * (digit - int(digit))) * pixel_fraction;
  Serial.printf("GVLOC: %0.1f %i\n",vLocation, digits.height());
  digits.setTextColor(TFT_GREEN);
  digits.drawString(strBuff, 0, vLocation, 1);

  figure++;
  if (figure == 10)
    figure = 0;

  sprintf(strBuff, "%01d0", figure);
  vLocation = ((10.0 * (digit - int(digit))) * pixel_fraction) - (float)digits.height();
  Serial.printf("YVLOC: %0.1f %i\n",vLocation, digits.height());
  digits.setTextColor(TFT_YELLOW);
  digits.drawString(strBuff, 0, vLocation, 1);

  figure = (int)digit;
  figure--;

  sprintf(strBuff, "%01d0", figure);
  vLocation = ((10.0 * (digit - int(digit))) * pixel_fraction) + (float)digits.height();
    Serial.printf("CVLOC: %0.1f %i\n",vLocation, digits.height());
  digits.setTextColor(TFT_CYAN);
  digits.drawString(strBuff, 0, vLocation, 1);

  digits.pushSprite(x, PANEL_MIDY);
}
@DrJaymz
Copy link
Author

DrJaymz commented Dec 20, 2024

image

I see these lines have appeared. I commented out the checks on the Y coordinate but there must be more than that.
I would have thought partially obscured text was fairly commonly used. (but willing to conceed there is a better way).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant