vindar / ILI9341_T4

Optimized ILI9341 screen driver library for Teensy 4/4.1, with vsync and diff. updates.
GNU Lesser General Public License v2.1
70 stars 12 forks source link

OverlayTextTFTDisplay #11

Closed ArminRehberger closed 1 year ago

ArminRehberger commented 1 year ago

Hello Arvind, I use your libary to display the X, Y and Z positions of my programmed CNC mill with the Teensy4.0. I implemented a new method to draw text on the TFT screen. It would be nice if you could implemend this method in your libary.

In this new method you can: Juse the line number Draw universal text Juse one of your fonts Juse the width of the rect for the background of the text (draw rect like textlength, draw rect over the entire width)

I found out an error in your method "FillRect" during testing the new method when drawing textz at the bottom. //if (ymax >= lx) ymax = ly - 1; // Error if (ymax >= ly) ymax = ly - 1;

Kind regards Armin Rehberger

// ##### Draw text // - fb : the framebuffer to draw onto // - position: position of the text: // 0= top right, 1=bottom right, 2=bottom left, 3=top left // - line: line no. // 0=line 0, 1=line 1, ... // - fg_color : foreground color.
// - bg_color : background color // - opacity: opacity of the FPS counter between 0.0f=transparent and 1.0f=opaque. // - text: Text to draw // - font: Font to be used: // 0=Bold_10, 1=Bold_12, 2=Bold_14, 3=Bold_16 // - Draw rect over the entire width // 0=draw rect like textlength, 1=draw rect over the entire width

// ##### Call the new method char outStr[100]; sprintf(outStr," ActPos X: %.4f mm",MotorRecive.ActPosMotor[0]); // Actual position X tft.OverlayTextTFTDisplay(fb, 3, 0, ILI9341_BLACK, ILI9341_RED, 0.8f, outStr, 3, 1); // Framebuffer, position, line, foreground color, background color, opacity, text, font, rect entire width

sprintf(outStr," ActPos Y: %.4f mm",MotorRecive.ActPosMotor[1]); // Actual position y tft.OverlayTextTFTDisplay(fb, 3, 1, ILI9341_BLACK, ILI9341_GREEN, 0.8f, outStr, 3, 1); // Framebuffer, position, line, foreground color, background color, opacity, text, font, rect entire width

sprintf(outStr," ActPos Z: %.4f mm",MotorRecive.ActPosMotor[2]); // Actual position z tft.OverlayTextTFTDisplay(fb, 3, 2, ILI9341_BLACK, ILI9341_BLUE, 0.8f, outStr, 3, 1); // Framebuffer, position, line, foreground color, background color, opacity, text, font, rect entire width

sprintf(outStr," RS485: %d",CounterReadGoodRS485); // Counter read good RS485 tft.OverlayTextTFTDisplay(fb, 3, 3, ILI9341_WHITE, ILI9341_BLACK, 0.5f, outStr, 3, 1); // Framebuffer, position, line, foreground color, background color, opacity, text, font, rect entire width

// ################################################################# // ##### Draw text, new method /*

vindar commented 1 year ago

Hello,

I agree with you that is useful to have a simple way to draw text onto the screen (for debugging, displaying infos...). So, as per your suggestion, I have created a new method called overlayText() adapted from your code above. I hope this suits you.

Since the library is just a screen driver (and not a full fledged graphics lib), I do not want to add more methods for drawing onto a framebuffer here. But, if you need more advanced text formatting, I suggest you look into my tgx library which will give you many more options to do that.

Thanks you for your help and for reporting the bug (fixed now) ! :-)

Arvind

ArminRehberger commented 1 year ago

Hello Arvind thank you for implementing the new method to draw text onto the screen. I use your screen driver to show graphic and text.

Kind regards Armin

vindar commented 1 year ago

Glad you find the library useful :-) I am closing the issue but you can reopen it if you find something wrong with the code. Thanks for your help !