X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/3a4d8a99f885909119362e3b9b9b587315d74ad7..b2d84a4b240edc1e4e15793180529eacce45cec8:/drivers/displays/tft/drawing.c diff --git a/drivers/displays/tft/drawing.c b/drivers/displays/tft/drawing.c index 924c115..b8ad086 100644 --- a/drivers/displays/tft/drawing.c +++ b/drivers/displays/tft/drawing.c @@ -95,7 +95,7 @@ void drawCharSmall(uint16_t x, uint16_t y, uint16_t color, uint8_t c, struct FON { uint8_t bit = 0x00; bit = (column[xoffset] << (8 - (yoffset + 1))); // Shift current row bit left - bit = (bit >> 7); // Shift current row but right (results in 0x01 for black, and 0x00 for white) + bit = (bit >> 7); // Shift current row bit right (results in 0x01 for black, and 0x00 for white) if (bit) { drawPixel(x + xoffset, y + yoffset, color); @@ -238,6 +238,11 @@ void drawLine ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t col /**************************************************************************/ void drawLineDotted ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t empty, uint16_t solid, uint16_t color ) { + lcdProperties_t properties; + + // Get the LCD properties (to check for HW acceleration in the driver) + properties = lcdGetProperties(); + if (solid == 0) { return; @@ -250,7 +255,7 @@ void drawLineDotted ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16 y1 = y1 > 65000 ? 0 : y1; // Check if we can use the optimised horizontal line method - if ((y0 == y1) && (empty == 0)) + if ((y0 == y1) && (empty == 0) && properties.fastHLine) { lcdDrawHLine(x0, x1, y0, color); return; @@ -259,7 +264,7 @@ void drawLineDotted ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16 // Check if we can use the optimised vertical line method. // This can make a huge difference in performance, but may // not work properly on every LCD controller: - if ((x0 == x1) && (empty == 0)) + if ((x0 == x1) && (empty == 0) && properties.fastVLine) { // Warning: This may actually be slower than drawing individual pixels on // short lines ... Set a minimum line size to use the 'optimised' method @@ -732,6 +737,119 @@ void drawRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, u } } +/**************************************************************************/ +/*! + @brief Draws a rectangle with rounded corners + + @param[in] x0 + Starting x co-ordinate + @param[in] y0 + Starting y co-ordinate + @param[in] x1 + Ending x co-ordinate + @param[in] y1 + Ending y co-ordinate + @param[in] color + Color used when drawing + @param[in] radius + Corner radius in pixels + @param[in] corners + Which corners to round + + @section EXAMPLE + @code + + drawRoundedRectangle ( 10, 10, 200, 200, COLOR_BLACK, 10, DRAW_CORNERS_ALL ); + + @endcode + +*/ +/**************************************************************************/ +void drawRoundedRectangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color, uint16_t radius, drawCorners_t corners ) +{ + int height; + uint16_t y; + + if (corners == DRAW_CORNERS_NONE) + { + drawRectangle(x0, y0, x1, y1, color); + return; + } + + // Calculate height + if (y1 < y0) + { + y = y1; + y1 = y0; + y0 = y; + } + height = y1 - y0; + + // Check radius + if (radius > height / 2) + { + radius = height / 2; + } + radius -= 1; + + switch (corners) + { + case DRAW_CORNERS_ALL: + drawCorner(x0 + radius, y0 + radius, radius, DRAW_CORNERS_TOPLEFT, color); + drawCorner(x1 - radius, y0 + radius, radius, DRAW_CORNERS_TOPRIGHT, color); + drawCorner(x0 + radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMLEFT, color); + drawCorner(x1 - radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMRIGHT, color); + if (radius*2+1 < height) + { + drawLine(x0, y0+radius, x0, y1-radius, color); + drawLine(x1, y0+radius, x1, y1-radius, color); + } + drawLine(x0+radius, y0, x1-radius, y0, color); + drawLine(x0+radius, y1, x1-radius, y1, color); + break; + case DRAW_CORNERS_TOP: + drawCorner(x0 + radius, y0 + radius, radius, DRAW_CORNERS_TOPLEFT, color); + drawCorner(x1 - radius, y0 + radius, radius, DRAW_CORNERS_TOPRIGHT, color); + drawLine(x0, y0+radius, x0, y1, color); + drawLine(x0, y1, x1, y1, color); + drawLine(x1, y1, x1, y0+radius, color); + drawLine(x0+radius, y0, x1-radius, y0, color); + break; + case DRAW_CORNERS_BOTTOM: + drawCorner(x0 + radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMLEFT, color); + drawCorner(x1 - radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMRIGHT, color); + drawLine(x0, y0, x1, y0, color); + drawLine(x1, y0, x1, y1-radius, color ); + drawLine(x1-radius, y1, x0+radius, y1, color); + drawLine(x0, y1-radius, x0, y0, color); + break; + case DRAW_CORNERS_LEFT: + drawCorner(x0 + radius, y0 + radius, radius, DRAW_CORNERS_TOPLEFT, color); + drawCorner(x0 + radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMLEFT, color); + if (radius*2+1 < height) + { + drawLine(x0, y0+radius, x0, y1-radius, color); + } + drawLine(x1, y0, x1, y1, color); + drawLine(x0+radius, y0, x1, y0, color); + drawLine(x0+radius, y1, x1, y1, color); + break; + case DRAW_CORNERS_RIGHT: + drawCorner(x1 - radius, y0 + radius, radius, DRAW_CORNERS_TOPRIGHT, color); + drawCorner(x1 - radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMRIGHT, color); + if (radius*2+1 < height) + { + drawLine(x1, y0+radius, x1, y1-radius, color); + } + drawLine(x0, y0, x0, y1, color); + drawLine(x0, y0, x1-radius, y0, color); + drawLine(x0, y1, x1-radius, y1, color); + break; + default: + break; + } +} + /**************************************************************************/ /*! @brief Draws a filled rectangle with rounded corners