LPC1343 Graphics Sub-System: Drawing Primitives (drawing.c)
Overview of the main drawing primiives includes in drawing.c
In order to seperate the rendering and graphics code from the low-level HW access, all of the primitive drawing routings have been placed in a seperate file named drawing.c. The set of functions found in drawing.c forms the backbone of the graphics sub-system, and contains most of the primitives you would expect to find, such as setting pixels, and drawing simple shapes (squares, triangles, circles, rounded rectangles, solid and dotted lines, etc.), as well as a few convenience callbacks to other functions in the graphics sub-system. The main functions are detailed below:
Detailed Descriptions
void drawPixel(uint16_t x, uint16_t y, uint16_t color)
Sets a single pixel at the specified x,y location using the supplied RGB565 color.
#include "drivers/lcd/tft/drawing.h"
...
// Draw a white pixel at X:20, Y:50
drawPixel(20, 50, COLOR_WHITE);
void drawFill(uint16_t color)
Fills the entire LCD screen with the specified RGB565 Color
#include "drivers/lcd/tft/drawing.h"
...
drawFill(COLOR_WHITE);
void drawLine ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color )
Draws a line between two locations on the LCD screen. (Note: If the line is a straight horizontal or vertical line, this function will automatically use an optimised drawing method in the specific LCD driver.)
#include "drivers/lcd/tft/drawing.h"
...
// Draw a green line from 10, 1 to 96, 118
drawLine(10, 1, 96, 118, COLOR_GREEN);
void drawLineDotted ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t empty, uint16_t solid, uint16_t color )
Draws a line with a fixed pattern of empty and solid pixels.

#include "drivers/lcd/tft/drawing.h"
...
// Background
drawFill(COLOR_WHITE);
// Solid line
drawLine(10, 10, 230, 10, COLOR_BLACK);
// 1x1 pattern
drawLineDotted(10, 15, 230, 15, 1, 1, COLOR_BLACK);
// 2x2 pattern
drawLineDotted(10, 20, 230, 20, 2, 2, COLOR_BLACK);
// 3x3 pattern
drawLineDotted(10, 25, 230, 25, 3, 3, COLOR_BLACK);
// 3x5 pattern
drawLineDotted(10, 30, 230, 30, 3, 5, COLOR_BLACK);
// 5x10 pattern
drawLineDotted(10, 35, 230, 35, 5, 10, COLOR_BLACK);
Note: This function was added in v0.92 of the LPC1343 Code Base.
void drawCircle (uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint16_t color)
Draws a circle with the specified radius using the supplied x and y co-ordinates as the center point.
#include "drivers/lcd/tft/drawing.h"
...
// Draw a white circle with a 25 pixel radius centered on X:50, Y:50
drawCircle(50, 50, 25, COLOR_WHITE);
void drawCircleFilled (uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint16_t color)
Identical to drawCircle, but also fills the interior of the circle
#include "drivers/lcd/tft/drawing.h"
...
// Draw a solid white circle with a 25 pixel radius centered on X:50, Y:50
drawCircleFilled(50, 50, 25, COLOR_WHITE);
void drawCorner (uint16_t xCenter, uint16_t yCenter, uint16_t r, drawCorners_t corner, uint16_t color)
Draws a 1-pixel wide corner (or corners if multiple corners are combined in drawCorners_t), centered around the specified xCenter and yCenter position
// Draw a top-left corner with a 10 pixel radius, centered at 20, 20
drawCorner(20, 20, 10, DRAW_CORNERS_TOPLEFT, COLOR_GRAY_128);
void drawCornerFilled (uint16_t xCenter, uint16_t yCenter, uint16_t radius, drawCorners_t position, uint16_t color)
Same as drawCorner, but also fills the corner area with the specified color (from xCenter/yCenter out to the edge of the semi-circle).
// Draw a top-left corner with a 10 pixel radius, centered at 20, 20
drawCornerFilled(20, 20, 10, DRAW_CORNERS_TOPLEFT, COLOR_GRAY_128);
void drawArrow(uint16_t x, uint16_t y, uint16_t size, drawDirection_t direction, uint16_t color)
Draws a rectangular 'arrow' points in the specified direction (useful for scrollbars, selection menus, etc.). Note that the arrow will be drawn starting at the 1-pixel 'tip' and will expand outward from this point until the specified size is reached. You may need to adjust the starting 'y' position to place UP and DOWN arrows side by side.
The direction of the arrow is specified with one of the following values (enum located in drawing.h):
DRAW_DIRECTION_LEFTDRAW_DIRECTION_RIGHTDRAW_DIRECTION_UPDRAW_DIRECTION_DOWN
#include "drivers/lcd/tft/drawing.h"
...
// Draw left and right arrows
drawArrow(105, 65, 7, DRAW_DIRECTION_LEFT, TEXTCOLORACTIVE);
drawArrow(220, 65, 7, DRAW_DIRECTION_RIGHT, TEXTCOLORACTIVE);
NOTE: This function was added in v0.92 of the LPC1343 Code Base.
void drawRectangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
Draws a rectangle using the specified co-ordinates
#include "drivers/lcd/tft/drawing.h"
...
// Draw a white rectangle from 10, 10 to 100, 35
drawRectangle(10, 10, 100, 35, COLOR_WHITE);
void drawRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
Draws a filled rectangle using the specified co-ordinates
#include "drivers/lcd/tft/drawing.h"
...
// Draw a solid blue rectangle from 10, 10 to 100, 35
drawRectangleFilled(10, 10, 100, 25, COLOR_BLUE);
void drawRoundedRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color, uint16_t radius, drawCorners_t corners )
Draws a filled rectangle with rounded corners using the specified radius and location.
The following values can be used to indicate which corners should be 'rounded' (enum defined in drawing.h):
DRAW_CORNERS_NONE,
DRAW_CORNERS_ALL,
DRAW_CORNERS_TOP,
DRAW_CORNERS_BOTTOM,
DRAW_CORNERS_LEFT,
DRAW_CORNERS_RIGHT
#include "drivers/lcd/tft/drawing.h"
...
// Draw a rectangle with all four corners rounded using a
// 10-pixel radius, solid blue fill, from 10,10 to 200,80
drawRoundedRectangleFilled(10, 10, 200, 80, COLOR_BLUE, 10, DRAW_CORNERS_ALL);
NOTE: This function was added in v0.92 of the LPC1343 Code Base.
void drawGradient ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t startColor, uint16_t endColor)
Draws a linear top-to-bottom gradient between the two specified colors
#include "drivers/displays/tft/drawing.h"
// Draw a gradient-filled rectangle
uint16_t btnWidth, btnHeight, btnX, btnY;
btnWidth = 200;
btnHeight = 20;
btnX = 10;
btnY = 30;
drawFill(0xFFFF);
drawRectangle(btnX-1, btnY-1, btnX+btnWidth+1, btnY+btnHeight+1, COLOR_GRAY_80);
drawGradient(btnX, btnY, btnX+btnWidth, btnY+btnHeight, COLOR_WHITE, COLOR_GRAY_128);
void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draws the outline of a triangle using the three supplied vertices.
#include "drivers/lcd/tft/drawing.h"
...
drawTriangle ( 100, 10, 20, 120, 230, 290, COLOR_WHITE);
NOTE: This function was added in v0.93 of the LPC1343 Code Base.
void drawTriangleFilled(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draws a filled triangle using the three supplied vertices.
#include "drivers/lcd/tft/drawing.h"
...
drawTriangleFilled ( 100, 10, 20, 120, 230, 290, COLOR_WHITE);
// Draw black circles at each point of the triangle
drawCircleFilled(100, 10, 2, COLOR_BLACK);
drawCircleFilled(20, 120, 2, COLOR_BLACK);
drawCircleFilled(230, 290, 2, COLOR_BLACK);
NOTE: This function was added in v0.93 of the LPC1343 Code Base.