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

push rotated to sprite does not work #3644

Open
JohannieK opened this issue Jan 30, 2025 · 1 comment
Open

push rotated to sprite does not work #3644

JohannieK opened this issue Jan 30, 2025 · 1 comment

Comments

@JohannieK
Copy link

I am trying to push a rotated text onto a sprite. I can push the text to the sprite un-rotated, but when I try to push it rotated, I only get a green square. I am trying to make a compass wheel with the E and W letters rotated so that they will be upright when the wheel is rotated

`#include "SPI.h"
#include "TFT_eSPI.h"
#include "Free_Fonts.h"

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite dirWheel = TFT_eSprite(&tft);
TFT_eSprite dirLetter = TFT_eSprite(&tft);

void calcPoints(int degrees, int & x1, int & y1, int & x2, int & y2 ) {
x1 = 50 + 50 * cos (degrees * pi / 180);
y1 = 50 + 50 * sin (degrees * pi / 180);
x2 = 50 + 50 * cos (degrees * pi / 180);
y2 = 50 + 50 * sin (degrees * pi / 180);
}

void createWheel() {
dirWheel.setColorDepth(1);
dirWheel.createSprite(100, 100);
dirLetter.setColorDepth(1);
dirLetter.createSprite(14, 14);
dirLetter.fillSprite(TFT_BLACK);
dirLetter.setFreeFont(FM9);
dirLetter.setTextColor(TFT_GREEN,TFT_BLACK);
dirLetter.setTextDatum(CC_DATUM);
dirLetter.drawString("E", 7 ,7, GFXFF);
dirLetter.setPivot(7, 7);
dirWheel.setBitmapColor(TFT_GREEN, TFT_BLACK);
dirWheel.setPivot(50, 50);
dirWheel.fillSprite(TFT_BLACK);
dirLetter.pushToSprite(&dirWheel,1,43); //When this is is used, I get the E at the correct location on the dirWheel sprite
//dirLetter.pushRotated(&dirWheel,90); //When this line is used I get a green square at the middle of the dirWheel sprite
dirWheel.setFreeFont(FM9);
dirWheel.setTextColor(TFT_GREEN,TFT_BLACK);
dirWheel.setTextDatum(TC_DATUM);
dirWheel.drawString("N", 50 ,1, GFXFF);
dirWheel.setTextDatum(BC_DATUM);
dirWheel.drawString("S", 50 ,99, GFXFF);
dirWheel.pushRotated(0);
dirWheel.setTextDatum(ML_DATUM);
//dirWheel.drawString("E", 1 ,50, GFXFF);
dirWheel.setTextDatum(MR_DATUM);
dirWheel.drawString("W", 99 ,50, GFXFF);
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
calcPoints(45,x1,y1,x2,y2);
dirWheel.drawLine(x1, y1, x2, y2, TFT_GREEN);
calcPoints(135,x1,y1,x2,y2);
dirWheel.drawLine(x1, y1, x2, y2, TFT_GREEN);
calcPoints(225,x1,y1,x2,y2);
dirWheel.drawLine(x1, y1, x2, y2, TFT_GREEN);
calcPoints(315,x1,y1,x2,y2);
dirWheel.drawLine(x1, y1, x2, y2, TFT_GREEN);
dirWheel.setBitmapColor(TFT_GREEN, TFT_BLACK);
dirWheel.pushRotated(0);
}

void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Starting up...");
// Start the tft display
tft.init();
// Set the TFT display rotation in landscape mode
tft.setRotation(1);

// Clear the screen before writing to it
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setPivot(265, 185);
createWheel();
}

`
Am I doing something wrong or is this a bug ?

@JohannieK
Copy link
Author

Changing the sprites to 8 bit per pixel makes the code work with pushRotated, so I suspect it is a bug

Below code works.

void createWheel() { dirWheel.setColorDepth(8); dirWheel.createSprite(100, 100); dirLetter.setColorDepth(8); dirLetter.createSprite(14, 14); dirLetter.fillSprite(TFT_BLACK); dirLetter.setFreeFont(FM9); dirLetter.setTextColor(TFT_GREEN,TFT_BLACK); dirLetter.setTextDatum(CC_DATUM); dirLetter.drawString("E", 7 ,7, GFXFF); dirLetter.setPivot(7, 7); //dirWheel.setBitmapColor(TFT_GREEN, TFT_BLACK); dirWheel.setPivot(50, 50); dirWheel.fillSprite(TFT_BLACK); //dirLetter.pushToSprite(&dirWheel,1,43); dirLetter.pushRotated(&dirWheel,90); dirWheel.setFreeFont(FM9); dirWheel.setTextColor(TFT_GREEN,TFT_BLACK); dirWheel.setTextDatum(TC_DATUM); dirWheel.drawString("N", 50 ,1, GFXFF); dirWheel.setTextDatum(BC_DATUM); dirWheel.drawString("S", 50 ,99, GFXFF); dirWheel.pushRotated(0); dirWheel.setTextDatum(ML_DATUM); //dirWheel.drawString("E", 1 ,50, GFXFF); dirWheel.setTextDatum(MR_DATUM); dirWheel.drawString("W", 99 ,50, GFXFF); int x1 = 0; int y1 = 0; int x2 = 0; int y2 = 0; calcPoints(45,x1,y1,x2,y2); dirWheel.drawLine(x1, y1, x2, y2, TFT_GREEN); calcPoints(135,x1,y1,x2,y2); dirWheel.drawLine(x1, y1, x2, y2, TFT_GREEN); calcPoints(225,x1,y1,x2,y2); dirWheel.drawLine(x1, y1, x2, y2, TFT_GREEN); calcPoints(315,x1,y1,x2,y2); dirWheel.drawLine(x1, y1, x2, y2, TFT_GREEN); //dirWheel.setBitmapColor(TFT_GREEN, TFT_BLACK); dirWheel.pushRotated(0); }

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