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

added thick lines and gradient fill support #528

Merged
merged 4 commits into from
Feb 18, 2024
Merged

added thick lines and gradient fill support #528

merged 4 commits into from
Feb 18, 2024

Conversation

tobozo
Copy link
Collaborator

@tobozo tobozo commented Feb 18, 2024

Features in this PR:

  • Antialiased thick lines, filled with plain color or gradient
  • Antialiased circles, filled with plain color or gradient
  • Rectangular fill with linear or radial gradient

LGFX Methods:

NOTE: COLOR can be any of uint8_t, uint16_t, uint32_t, RGBColor, rgb888_t, rgb565_t, rgb888_t, etc

  • Draw thick+smooth lines:
    void drawWideLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, float thick, COLOR color)

  • Draw thick+smooth lines (gradient fill):
    void drawWideLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, float thick, const colors_t gradient)

  • Draw wedge line:
    void drawWedgeLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, float thick0, float thick1, COLOR color)

  • Draw wedge line (gradient fill):
    void drawWedgeLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, float thick0, float thick1, const colors_t gradient)

  • Fill smooth circle with single color (redundant with fillSmoothCircle(), kept for benchmark):
    void drawSpot(int32_t x, int32_t y, float radius, COLOR fg_color)

  • Fill smooth circle, like fillSmoothCircle() but with gradient fill:
    void drawGradientSpot(int32_t x, int32_t y, float radius, const colors_t gradient)

  • Draw antialiased line:
    void drawSmoothLine( LovyanGFX* gfx, int32_t x0, int32_t y0, int32_t x1, int32_t y1, COLOR color )

  • Draw gradient line (not smoothed, used for filling):
    void drawGradientLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, const colors_t gradient )
    void drawGradientHLine(int32_t x, int32_t y, uint32_t w, const colors_t gradient )
    void drawGradientVLine(int32_t x, int32_t y, uint32_t h, const colors_t gradient )

  • Fill rect with radial/linear gradient (fill_style_t can be any of RADIAL, HLINEAR or VLINEAR):
    void fillGradientRect(int32_t x, int32_t y, uint32_t w, uint32_t h, COLOR start, COLOR end, fill_style_t style=RADIAL )
    void fillGradientRect(int32_t x, int32_t y, uint32_t w, uint32_t h, const colors_t gradient, fill_style_t style=RADIAL )

  • Create a gradient item from a sized array of colors or from a pointer to an array of colors:
    colors_t createGradient( rgb888_t[] colors )
    colors_t createGradient( rgb888_t* colors, uint32_t count )

  • Example:

    lgfx::rgb888_t colors[] = { {0x00,0xff,0x00}, {0xff,0xff,0x00}, {0xff,0x80,0x00}, {0xff,0x00,0x00} };
    auto gradient = tft.createGradient( colors ); // create a gradient item
    tft.fillGradientRect( 10, 10, 200, 200, gradient, HLINEAR );

@lovyan03
Copy link
Owner

thanks !
There are places where double type is used for coordinate calculation, but wouldn't float be sufficient?
I don't think such exact precision is required.

@tobozo
Copy link
Collaborator Author

tobozo commented Feb 18, 2024

fixed, apparently this is also provides a small performance improvement with radial gradients

@lovyan03 lovyan03 merged commit a7adcfa into develop Feb 18, 2024
168 checks passed
@tobozo
Copy link
Collaborator Author

tobozo commented Feb 19, 2024

btw @lovyan03 do you want me to submit that to M5GFX too ?

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

Successfully merging this pull request may close these issues.

2 participants