-/**************************************************************************/
-/*!
- @brief Converts a 24-bit RGB color to an equivalent 16-bit RGB565 value
-
- @param[in] r
- 8-bit red
- @param[in] g
- 8-bit green
- @param[in] b
- 8-bit blue
-
- @section Example
-
- @code
-
- // Get 16-bit equivalent of 24-bit color
- uint16_t gray = drawRGB24toRGB565(0x33, 0x33, 0x33);
-
- @endcode
-*/
-/**************************************************************************/
-uint16_t drawRGB24toRGB565(uint8_t r, uint8_t g, uint8_t b)
-{
- return ((r / 8) << 11) | ((g / 4) << 5) | (b / 8);
-}
-
-/**************************************************************************/
-/*!
- @brief Converts a 16-bit RGB565 color to a standard 32-bit BGRA32
- color (with alpha set to 0xFF)
-
- @param[in] color
- 16-bit rgb565 color
-
- @section Example
-
- @code
-
- // First convert 24-bit color to RGB565
- uint16_t rgb565 = drawRGB24toRGB565(0xFF, 0x00, 0x00);
-
- // Convert RGB565 color back to BGRA32
- uint32_t bgra32 = drawRGB565toBGRA32(rgb565);
-
- // Display results
- printf("BGRA32: 0x%08X R: %u G: %u B: %u A: %u \r\n",
- bgra32,
- (bgra32 & 0x000000FF), // Blue
- (bgra32 & 0x0000FF00) >> 8, // Green
- (bgra32 & 0x00FF0000) >> 16, // Red
- (bgra32 & 0xFF000000) >> 24); // Alpha
-
- @endcode
-*/
-/**************************************************************************/
-uint32_t drawRGB565toBGRA32(uint16_t color)
-{
- uint32_t bits = (uint32_t)color;
- uint32_t blue = bits & 0x001F; // 5 bits blue
- uint32_t green = bits & 0x07E0; // 6 bits green
- uint32_t red = bits & 0xF800; // 5 bits red
-
- // Return shifted bits with alpha set to 0xFF
- return (red << 8) | (green << 5) | (blue << 3) | 0xFF000000;
-}
-
-/**************************************************************************/
-/*!
- @brief Reverses a 16-bit color from BGR to RGB
-*/
-/**************************************************************************/
-uint16_t drawBGR2RGB(uint16_t color)
-{
- uint16_t r, g, b;
-
- b = (color>>0) & 0x1f;
- g = (color>>5) & 0x3f;
- r = (color>>11) & 0x1f;
-
- return( (b<<11) + (g<<5) + (r<<0) );
-}
-
-/**************************************************************************/
-/*!
- @brief Draws a progress bar with rounded corners
-
- @param[in] x
- Starting x location
- @param[in] y
- Starting y location
- @param[in] width
- Total width of the progress bar in pixels
- @param[in] height
- Total height of the progress bar in pixels
- @param[in] borderCorners
- The type of rounded corners to render with the progress bar border
- @param[in] progressCorners
- The type of rounded corners to render with the inner progress bar
- @param[in] borderColor
- 16-bit color for the outer border
- @param[in] borderFillColor
- 16-bit color for the interior of the outer border
- @param[in] progressBorderColor
- 16-bit color for the progress bar's border
- @param[in] progressFillColor
- 16-bit color for the inner bar's fill
- @param[in] progress
- Progress percentage (between 0 and 100)
-
- @section Example
-
- @code
- #include "drivers/displays/tft/drawing.h"
-
- // Draw a the progress bar (150x15 pixels large, starting at X:10, Y:195
- // with rounded corners on the top and showing 72% progress)
- drawProgressBar(10, 195, 150, 15, DRAW_ROUNDEDCORNERS_TOP, DRAW_ROUNDEDCORNERS_TOP, COLOR_DARKERGRAY, COLOR_DARKGRAY, COLOR_LIMEGREENDIM, COLOR_LIMEGREEN, 72 );
-
- @endcode
-*/
-/**************************************************************************/
-void drawProgressBar ( uint16_t x, uint16_t y, uint16_t width, uint16_t height, drawRoundedCorners_t borderCorners, drawRoundedCorners_t progressCorners, uint16_t borderColor, uint16_t borderFillColor, uint16_t progressBorderColor, uint16_t progressFillColor, uint8_t progress )
-{
- // Draw border with rounded corners
- drawRectangleRounded(x, y, x + width, y + height, borderColor, 5, borderCorners);
- drawRectangleRounded(x+1, y+1, x + width - 1, y + height - 1, borderFillColor, 5, borderCorners);
-
- // Progress bar
- if (progress > 0 && progress <= 100)
- {
- // Calculate bar size
- uint16_t bw;
- bw = (width - 6); // bar at 100%
- if (progress != 100)
- {
- bw = (bw * progress) / 100;
- }
- drawRectangleRounded(x + 3, y + 3, bw + x + 3, y + height - 3, progressBorderColor, 5, progressCorners);
- drawRectangleRounded(x + 4, y + 4, bw + x + 3 - 1, y + height - 4, progressFillColor, 5, progressCorners);
- }
-}
-
-/**************************************************************************/
-/*!
- @brief Draws a simple button
-
- @param[in] x
- Starting x location
- @param[in] y
- Starting y location
- @param[in] width
- Total width of the button in pixels
- @param[in] height
- Total height of the button in pixels
- @param[in] fontInfo
- Pointer to the FONT_INFO used to render the button text
- @param[in] fontHeight
- The height in pixels of the font (used for centering)
- @param[in] borderclr
- The rgb565 border color
- @param[in] fillclr
- The rgb565 background color
- @param[in] fontclr
- The rgb565 font color
- @param[in] text
- The text to render on the button
-
- @section Example
-
- @code
-
- #include "drivers/displays/tft/drawing.h"
- #include "drivers/displays/tft/fonts/dejavusans9.h"
-
- // Draw two buttons using Vera Sans Bold 9
- drawButton(20, 195, 200, 35, &dejaVuSans9ptFontInfo, 7, COLOR_GRAY_80, COLOR_GRAY_80, COLOR_WHITE, "System Settings");
- drawButton(20, 235, 200, 35, &dejaVuSans9ptFontInfo, 7, COLOR_THEME_LIMEGREEN_DARKER, COLOR_THEME_LIMEGREEN_BASE, COLOR_BLACK, "System Settings");
-
- @endcode
-*/
-/**************************************************************************/
-void drawButton(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const FONT_INFO *fontInfo, uint16_t fontHeight, uint16_t borderclr, uint16_t fillclr, uint16_t fontclr, char* text)
-{
- // Border
- drawRectangleRounded(x, y, x + width, y + height, borderclr, 5, DRAW_ROUNDEDCORNERS_ALL);
- // Fill
- drawRectangleRounded(x+2, y+2, x+width-2, y+height-2, fillclr, 5, DRAW_ROUNDEDCORNERS_ALL);
-
- // Render text
- if (text != NULL)
- {
- uint16_t textWidth = drawGetStringWidth(&*fontInfo, text);
- uint16_t xStart = x + (width / 2) - (textWidth / 2);
- uint16_t yStart = y + (height / 2) - (fontHeight / 2) + 1;
- drawString(xStart, yStart, fontclr, &*fontInfo, text);
- }
-}
-