From b682e2f3d7c09caf709a787f5242811796496672 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Tue, 10 Apr 2012 15:43:40 +0200 Subject: [PATCH] v1.1.1 --- ChangeLog.txt | 11 +- build/crossworks/LPC1343_CodeBase.hzs | 14 +-- drivers/displays/tft/controls/button.c | 16 +-- drivers/displays/tft/controls/progressbar.c | 9 +- drivers/displays/tft/drawing.c | 113 ++++++++++++++++++++ drivers/displays/tft/drawing.h | 1 + main.c | 5 + project/cmd_tbl.h | 2 +- project/commands/drawing/cmd_rectangle.c | 28 +++-- 9 files changed, 170 insertions(+), 29 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9f7f7da..5470fc1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,12 @@ +v1.1.1 - Ongoing +============================================================================== +NEW FEATURES +------------------------------------------------------------------------------ +- Added drawRoundedRectangle to drawing.c +- Added ability to select filled or empty rounded rectangles to the 'R' CLI + command + + v1.1.0 - 9 April 2012 ============================================================================== BREAKING CHANGES @@ -21,7 +30,7 @@ BREAKING CHANGES NEW FEATURES ------------------------------------------------------------------------------ -- Added drawCorner to graphics.c +- Added drawCorner to drawing.c - Added new 'controls/' folder to the GFX library, and added a number of controls that will render correctly with the theme settings, as well as using bitmap or anti-aliased fonts, depending on projectconfig.h diff --git a/build/crossworks/LPC1343_CodeBase.hzs b/build/crossworks/LPC1343_CodeBase.hzs index 430ec20..8af0be3 100644 --- a/build/crossworks/LPC1343_CodeBase.hzs +++ b/build/crossworks/LPC1343_CodeBase.hzs @@ -24,10 +24,6 @@ - - - - @@ -47,10 +43,10 @@ - - - + + + @@ -63,7 +59,7 @@ - + - + diff --git a/drivers/displays/tft/controls/button.c b/drivers/displays/tft/controls/button.c index a3de42c..db29382 100644 --- a/drivers/displays/tft/controls/button.c +++ b/drivers/displays/tft/controls/button.c @@ -59,6 +59,14 @@ /**************************************************************************/ void buttonRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t fontColor, char *text, theme_t theme) { + uint16_t brighter, darker; + uint16_t buttonEnd; + + // Draw background gradient then outline + drawGradient(x+2, y+2, x+width-2, y+height-2, theme.colorFill, theme.colorBorder); + drawRoundedRectangle(x+1, y+1, x+width-1, y+height-1, theme.colorFill, 5, DRAW_CORNERS_ALL); + drawRoundedRectangle(x, y, x+width, y+height, theme.colorBorderDarker, 5, DRAW_CORNERS_ALL); + #if CFG_TFTLCD_USEAAFONTS uint16_t ctable[4]; @@ -66,19 +74,11 @@ void buttonRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint1 // This should really be optimized out into theme.h! aafontsCalculateColorTable(theme.colorFill, fontColor, &ctable[0], 4); - // Draw the primitive shapes for the button - drawRoundedRectangleFilled(x, y, x+width, y+height, theme.colorBorder, 5, DRAW_CORNERS_ALL); - drawRoundedRectangleFilled(x+1, y+1, x+width-1, y+height-1, theme.colorFill, 5, DRAW_CORNERS_ALL); - if (text != NULL) { aafontsCenterString(x + width / 2, y + 1 + (height / 2) - (THEME_FONT.fontHeight / 2), ctable, &THEME_FONT, text); } #else - // Draw the primitive shapes for the button - drawRoundedRectangleFilled(x, y, x+width, y+height, theme.colorBorder, 5, DRAW_CORNERS_ALL); - drawRoundedRectangleFilled(x+1, y+1, x+width-1, y+height-1, theme.colorFill, 5, DRAW_CORNERS_ALL); - // Render text if (text != NULL) { diff --git a/drivers/displays/tft/controls/progressbar.c b/drivers/displays/tft/controls/progressbar.c index 8a46d21..3c0c061 100644 --- a/drivers/displays/tft/controls/progressbar.c +++ b/drivers/displays/tft/controls/progressbar.c @@ -79,11 +79,8 @@ void progressbarRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, // Make sure we don't end up in negative territory with really small values if (progressEnd < x + 2) progressEnd = x+2; - // Calculate slightly brighter and darker colors for the border and gradient - brighter = colorsAlphaBlend(COLOR_WHITE, color, 50); - darker = colorsAlphaBlend(COLOR_BLACK, color, 35); - // Draw the outline and background gradient + // This needs to be square to avoid flickering with rapid updates :/ drawRectangle(x, y, x+width, y+height, theme.colorBorderDarker); drawRectangle(x+1, y+1, x+width-1, y+height-1, theme.colorFill); drawGradient(progressEnd+1, y+2, x+width-2, y+height-2, theme.colorFill, theme.colorBorder); @@ -91,6 +88,10 @@ void progressbarRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, // Draw the progress gradient if required if (progress) { + // Calculate slightly brighter and darker colors for the border and gradient + brighter = colorsAlphaBlend(COLOR_WHITE, color, 50); + darker = colorsAlphaBlend(COLOR_BLACK, color, 35); + // Draw border rectangle and gradient fill drawRectangle(x+2, y+2, progressEnd, y+height-2, darker); drawGradient(x+3, y+3, progressEnd-1, y+height-3, brighter, color); } diff --git a/drivers/displays/tft/drawing.c b/drivers/displays/tft/drawing.c index 924c115..52cf1b7 100644 --- a/drivers/displays/tft/drawing.c +++ b/drivers/displays/tft/drawing.c @@ -732,6 +732,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 diff --git a/drivers/displays/tft/drawing.h b/drivers/displays/tft/drawing.h index 3b3257b..432c7d3 100644 --- a/drivers/displays/tft/drawing.h +++ b/drivers/displays/tft/drawing.h @@ -85,6 +85,7 @@ void drawCornerFilled ( uint16_t xCenter, uint16_t yCenter, uint16_t ra void drawArrow ( uint16_t x, uint16_t y, uint16_t size, drawDirection_t, uint16_t color ); void drawRectangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color ); void drawRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color ); +void drawRoundedRectangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color, uint16_t radius, drawCorners_t corners ); void drawRoundedRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color, uint16_t radius, drawCorners_t corners ); void drawGradient ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t startColor, uint16_t endColor ); void drawTriangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color ); diff --git a/main.c b/main.c index bb2c280..3d91f4d 100644 --- a/main.c +++ b/main.c @@ -43,6 +43,11 @@ #include "core/cmd/cmd.h" #endif +#include "drivers/displays/tft/lcd.h" +#include "drivers/displays/tft/drawing.h" +#include "drivers/displays/tft/touchscreen.h" +#include "drivers/displays/tft/controls/button.h" + /**************************************************************************/ /*! Main program entry point. After reset, normal code execution will diff --git a/project/cmd_tbl.h b/project/cmd_tbl.h index c305d07..b240cbe 100644 --- a/project/cmd_tbl.h +++ b/project/cmd_tbl.h @@ -133,7 +133,7 @@ cmd_t cmd_tbl[] = { "p", 3, 3, 0, cmd_pixel , "Draw Pixel" , "'p '" }, { "P", 6, 6, 0, cmd_progress , "Progress Bar" , "'P <%> '" }, { "r", 5, 7, 0, cmd_rectangle , "Rectangle" , "'r [ ]'" }, - { "R", 7, 7, 0, cmd_rectangleround , "Rounded Rectangle" , "'R '" }, + { "R", 7, 9, 0, cmd_rectangleround , "Rounded Rectangle" , "'R [ ]'" }, { "s", 2, 99, 0, cmd_textw , "Text Width" , "'s '" }, { "t", 6, 99, 0, cmd_text , "Text" , "'t '" }, { "v", 7, 8, 0, cmd_triangle , "Triangle" , "'v []'" }, diff --git a/project/commands/drawing/cmd_rectangle.c b/project/commands/drawing/cmd_rectangle.c index 05f039d..d35eafa 100644 --- a/project/commands/drawing/cmd_rectangle.c +++ b/project/commands/drawing/cmd_rectangle.c @@ -101,7 +101,8 @@ void cmd_rectangle(uint8_t argc, char **argv) /**************************************************************************/ void cmd_rectangleround(uint8_t argc, char **argv) { - int32_t x1, y1, x2, y2, c, radius, corners; + int32_t x1, y1, x2, y2, c, radius, corners, filled, border; + filled = 0; // Convert supplied parameters getNumber (argv[0], &x1); @@ -111,6 +112,19 @@ void cmd_rectangleround(uint8_t argc, char **argv) getNumber (argv[4], &c); getNumber (argv[5], &radius); getNumber (argv[6], &corners); + if (argc >= 8) + { + getNumber (argv[7], &filled); + } + if (argc == 9) + { + getNumber (argv[8], &border); + if (border < 0 || border > 0xFFFF) + { + printf("Invalid Border Color%s", CFG_PRINTF_NEWLINE); + return; + } + } // ToDo: Validate data! if (c < 0 || c > 0xFFFF) @@ -119,13 +133,15 @@ void cmd_rectangleround(uint8_t argc, char **argv) return; } - if ((radius == 0) || (corners == 0) || (corners > 5)) - { - drawRectangleFilled(x1, y1, x2, y2, (uint16_t)c); - } + if (filled) + drawRoundedRectangleFilled(x1, y1, x2, y2, (uint16_t)c, radius, corners); else + drawRoundedRectangle(x1, y1, x2, y2, (uint16_t)c, radius, corners); + + // Draw border if it's not the same color + if (argc == 9) { - drawRoundedRectangleFilled(x1, y1, x2, y2, (uint16_t)c, radius, corners); + drawRoundedRectangle(x1, y1, x2, y2, (uint16_t)border, radius, corners); } } -- 2.20.1