diff options
author | Joel Bodenmann <joel@unormal.org> | 2012-10-24 02:39:21 +0200 |
---|---|---|
committer | Joel Bodenmann <joel@unormal.org> | 2012-10-24 02:39:21 +0200 |
commit | 5ac69126489aaa36182f79ea184fc771d0ac5d27 (patch) | |
tree | 76d1d63df5bffcab59fa00a9568aa9ad60f76fa6 /src | |
parent | d1f970217374c5f0363ebbfa6bd6551094a5735d (diff) | |
download | uGFX-5ac69126489aaa36182f79ea184fc771d0ac5d27.tar.gz uGFX-5ac69126489aaa36182f79ea184fc771d0ac5d27.tar.bz2 uGFX-5ac69126489aaa36182f79ea184fc771d0ac5d27.zip |
first graph implementation
Diffstat (limited to 'src')
-rw-r--r-- | src/gdisp.c | 18 | ||||
-rw-r--r-- | src/graph.c | 99 |
2 files changed, 112 insertions, 5 deletions
diff --git a/src/gdisp.c b/src/gdisp.c index a63b3db5..83ba8972 100644 --- a/src/gdisp.c +++ b/src/gdisp.c @@ -258,9 +258,9 @@ * @brief Draw a line.
* @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x0,y0 The start position
- * @param[in] x1,y1 The end position
- * @param[in] color The color to use
+ * @param[in] x0,y0 The start position
+ * @param[in] x1,y1 The end position
+ * @param[in] color The color to use
*
* @api
*/
@@ -280,6 +280,18 @@ chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
}
#endif
+
+ /**
+ * @brief Draw a dashed line.
+ * @pre The GDISP unit must be in powerOn or powerSleep mode.
+ *
+ * @param[in] x0,y0 The start position
+ * @param[in] x1,y1 The end position
+ * @param[in] length The length of the dash
+ * @param[in] color The color of the dashed line
+ *
+ * @api
+ */
#if GDISP_NEED_MULTITHREAD || defined(__DOXYGEN__)
/**
diff --git a/src/graph.c b/src/graph.c index 9fd3984f..c67fa252 100644 --- a/src/graph.c +++ b/src/graph.c @@ -25,8 +25,103 @@ #if GFX_USE_GRAPH -gfxGraphInit(struct graph_t *g) { - (void)g; +point_t origin; // origin of graph + +static void swapCoordinates(coord_t *a, coord_t *b) { + coord_t temp; + + temp = *b; + *b = *a; + *a = temp; +} + +static void _horizontalDotLine(coord_t x0, coord_t y0, coord_t x1, uint16_t space, color_t color) { + uint16_t offset = x0; + uint16_t count = ((x1 - x0) / space); + + do { + gdispDrawPixel(offset, y0, color); + offset += space; + } while(count--); +} + +static void _verticalDotLine(coord_t x0, coord_t y0, coord_t y1, uint16_t space, color_t color) { + uint16_t offset = y0; + uint16_t count = ((y1 - y0) / space); + + do { + gdispDrawPixel(x0, offset, color); + offset += space; + } while(count--); +} + +void graphDrawOneQuadrant(Graph *g) { + if(g->x0 > g->x1) + swapCoordinates(&g->x0, &g->x1); + if(g->y0 > g->y1) + swapCoordinates(&g->y0, &g->y1); + + uint16_t i; + uint16_t length_x = (g->x1 - g->x0); + uint16_t length_y = (g->y1 - g->y0); + uint16_t middle_x = (g->x1 - g->x0) / 2; + uint16_t middle_y = (g->y1 - g->y0) / 2; + + origin.x = g->x0; + origin.y = g->y1; + + /* X Axis */ + gdispDrawLine(g->x0, g->y1, g->x1, g->y1, g->color); + for(i = 0; i <= (length_y / g->grid_size); i++) + _horizontalDotLine(g->x0, g->y0 + g->grid_size * i, g->x1, g->dot_space, g->color); + + /* Y Axis */ + gdispDrawLine(g->x0, g->y0, g->x0, g->y1, g->color); + for(i = 0; i <= (length_x / g->grid_size); i++) + _verticalDotLine(g->x0 + g->grid_size * i, g->y0, g->y1, g->dot_space, g->color); +} + +void graphDrawFourQuadrants(Graph *g) { + if(g->x0 > g->x1) + swapCoordinates(&g->x0, &g->x1); + if(g->y0 > g->y1) + swapCoordinates(&g->y0, &g->y1); + + uint16_t i; + uint16_t length_x = (g->x1 - g->x0); + uint16_t length_y = (g->y1 - g->y0); + uint16_t middle_x = (g->x1 - g->x0) / 2; + uint16_t middle_y = (g->y1 - g->y0) / 2; + + origin.x = middle_x; + origin.y = middle_y; + + /* X Axis */ + gdispDrawLine(g->x0, middle_y, g->x1, middle_y, g->color); + for(i = 0; i <= (length_y / g->grid_size); i++) + _horizontalDotLine(g->x0, g->y0 + g->grid_size * i, g->x1, g->dot_space, g->color); + + /* Y Axis */ + gdispDrawLine(middle_x, g->y0, middle_x, g->y1, g->color); + for(i = 0; i <= (length_x / g->grid_size); i++) + _verticalDotLine(g->x0 + g->grid_size * i, g->y0, g->y1, g->dot_space, g->color); +} + +void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color) { + uint16_t i; + + for(i = 0; i < entries; i++) + gdispFillCircle(coord[i][0] + origin.x, origin.y - coord[i][1], radius, color); +} + +void graphDrawNet(int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor) { + uint16_t i; + + for(i = 0; i < entries; ++i) + gdispDrawLine(coord[i-1][0] + origin.x, origin.y - coord[i-1][1], coord[i][0] + origin.x, origin.y - coord[i][1], lineColor); + for(i = 0; i < entries; ++i) + if(radius != 0) + lcdFillCircle(coord[i][0] + origin.x, origin.y - coord[i][1], radius, dotColor); } #endif /* GFX_USE_GRAPH */ |