BeRTOS
|
00001 00040 #include "charts.h" 00041 #include <gfx/gfx.h> 00042 00043 00044 #ifndef CONFIG_CHART_ARROWS 00045 #define CONFIG_CHART_ARROWS 0 00046 #endif 00047 00048 00049 void chart_init(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax) 00050 { 00051 /* Clear the chart area */ 00052 gfx_rectClear(bm, xmin, ymin, xmax, ymax); 00053 00054 gfx_setClipRect(bm, xmin + CHART_BORDERLEFT, ymin + CHART_BORDERTOP, 00055 xmax - CHART_BORDERRIGHT, ymax - CHART_BORDERBOTTOM); 00056 00057 chart_drawAxis(bm); 00058 } 00059 00060 00061 void chart_setScale(Bitmap *bm, chart_x_t xmin, chart_y_t ymin, chart_x_t xmax, chart_y_t ymax) 00062 { 00063 gfx_setViewRect(bm, xmin, ymin, xmax, ymax); 00064 } 00065 00066 00070 void chart_drawAxis(Bitmap *bm) 00071 { 00072 #if CONFIG_CHART_ARROWS 00073 00074 /* Draw axis */ 00075 gfx_moveTo(bm, bm->cr.xmin, bm->cr.ymin + 4); 00076 gfx_lineTo(bm, bm->cr.xmin, bm->cr.ymax - 1); 00077 gfx_lineTo(bm, bm->cr.xmax - 4 - 1, bm->cr.ymax - 1); 00078 00079 /* Draw up arrow */ 00080 gfx_moveTo(bm, bm->cr.xmin - 2, bm->cr.ymin + 3); 00081 gfx_lineTo(bm, bm->cr.xmin + 2, bm->cr.ymin + 3); 00082 gfx_lineTo(bm, bm->cr.xmin, bm->cr.ymin); 00083 gfx_lineTo(bm, bm->cr.xmin - 2, bm->cr.ymin + 3); 00084 00085 /* Draw right arrow */ 00086 gfx_moveTo(bm, bm->cr.xmax - 4, bm->cr.ymax - 3); 00087 gfx_lineTo(bm, bm->cr.xmax - 4, bm->cr.ymax + 1); 00088 gfx_lineTo(bm, bm->cr.xmax - 1, bm->cr.ymax - 1); 00089 gfx_lineTo(bm, bm->cr.xmax - 4, bm->cr.ymax - 3); 00090 00091 #else /* CONFIG_CHART_ARROWS */ 00092 00093 /* Draw a box around the chart */ 00094 gfx_rectDraw(bm, bm->cr.xmin, bm->cr.ymin, bm->cr.xmax, bm->cr.ymax); 00095 00096 #endif /* CONFIG_CHART_ARROWS */ 00097 00098 //CHECK_WALL(wall_before_raster, WALL_SIZE); 00099 //CHECK_WALL(wall_after_raster, WALL_SIZE); 00100 } 00101 00102 00108 void chart_drawCurve(Bitmap *bm, const chart_y_t *curve_y, int curve_cnt) 00109 { 00110 int i; 00111 00112 gfx_moveTo(bm, gfx_transformX(bm, 0), gfx_transformY(bm, curve_y[0])); 00113 00114 for (i = 1; i < curve_cnt; i++) 00115 gfx_lineTo(bm, gfx_transformX(bm, i), gfx_transformY(bm, curve_y[i])); 00116 00117 //CHECK_WALL(wall_before_raster, WALL_SIZE); 00118 //CHECK_WALL(wall_after_raster, WALL_SIZE); 00119 } 00120 00121 00126 void chart_drawDots(Bitmap *bm, const chart_x_t *dots_x, const chart_y_t *dots_y, int cnt) 00127 { 00128 int i; 00129 coord_t x, y; 00130 00131 for (i = 0; i < cnt; i++) 00132 { 00133 if (dots_x) 00134 x = gfx_transformX(bm, dots_x[i]); 00135 else 00136 x = gfx_transformX(bm, i); 00137 00138 y = gfx_transformY(bm, dots_y[i]); 00139 00140 /* Draw tick over the curve */ 00141 gfx_rectFill(bm, 00142 x - TICKS_WIDTH / 2, y - TICKS_HEIGHT / 2, 00143 x + (TICKS_WIDTH + 1) / 2, y + (TICKS_HEIGHT + 1) / 2); 00144 00145 /* Draw vertical line from the curve to the X-axis */ 00146 //gfx_drawLine(bm, x, y, x, bm->cr.ymax - 1); 00147 } 00148 00149 //CHECK_WALL(wall_before_raster, WALL_SIZE); 00150 //CHECK_WALL(wall_after_raster, WALL_SIZE); 00151 } 00152