charts.c

Go to the documentation of this file.
00001 
00052 /*#*
00053  *#* $Log$
00054  *#* Revision 1.4  2006/07/19 12:56:26  bernie
00055  *#* Convert to new Doxygen style.
00056  *#*
00057  *#* Revision 1.3  2005/11/27 23:33:29  bernie
00058  *#* Reorder includes.
00059  *#*
00060  *#* Revision 1.2  2005/11/04 18:17:45  bernie
00061  *#* Fix header guards and includes for new location of gfx module.
00062  *#*
00063  *#* Revision 1.1  2005/11/04 18:11:35  bernie
00064  *#* Move graphics stuff from mware/ to gfx/.
00065  *#*
00066  *#* Revision 1.7  2005/11/04 16:20:02  bernie
00067  *#* Fix reference to README.devlib in header.
00068  *#*
00069  *#* Revision 1.6  2004/11/16 21:04:23  bernie
00070  *#* Update to new naming scheme in mware/gfx.c.
00071  *#*
00072  *#* Revision 1.5  2004/09/14 20:56:39  bernie
00073  *#* Make more generic and adapt to new gfx functions.
00074  *#*
00075  *#* Revision 1.3  2004/08/11 19:39:12  bernie
00076  *#* Use chart_x_t and chart_y_t for the input dataset.
00077  *#*
00078  *#* Revision 1.1  2004/08/04 03:16:30  bernie
00079  *#* Import simple chart drawing code.
00080  *#*
00081  *#*/
00082 
00083 #include "charts.h"
00084 #include <gfx/gfx.h>
00085 
00086 
00087 #ifndef CONFIG_CHART_ARROWS
00088 #define CONFIG_CHART_ARROWS 0
00089 #endif
00090 
00091 
00092 void chart_init(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax)
00093 {
00094     /* Clear the chart area */
00095     gfx_rectClear(bm, xmin, ymin, xmax, ymax);
00096 
00097     gfx_setClipRect(bm, xmin + CHART_BORDERLEFT, ymin + CHART_BORDERTOP,
00098         xmax - CHART_BORDERRIGHT, ymax - CHART_BORDERBOTTOM);
00099 
00100     chart_drawAxis(bm);
00101 }
00102 
00103 
00104 void chart_setScale(Bitmap *bm, chart_x_t xmin, chart_y_t ymin, chart_x_t xmax, chart_y_t ymax)
00105 {
00106     gfx_setViewRect(bm, xmin, ymin, xmax, ymax);
00107 }
00108 
00109 
00113 void chart_drawAxis(Bitmap *bm)
00114 {
00115 #if CONFIG_CHART_ARROWS
00116 
00117     /* Draw axis */
00118     gfx_moveTo(bm, bm->cr.xmin, bm->cr.ymin + 4);
00119     gfx_lineTo(bm, bm->cr.xmin, bm->cr.ymax - 1);
00120     gfx_lineTo(bm, bm->cr.xmax - 4 - 1, bm->cr.ymax - 1);
00121 
00122     /* Draw up arrow */
00123     gfx_moveTo(bm, bm->cr.xmin - 2, bm->cr.ymin + 3);
00124     gfx_lineTo(bm, bm->cr.xmin + 2, bm->cr.ymin + 3);
00125     gfx_lineTo(bm, bm->cr.xmin, bm->cr.ymin);
00126     gfx_lineTo(bm, bm->cr.xmin - 2, bm->cr.ymin + 3);
00127 
00128     /* Draw right arrow */
00129     gfx_moveTo(bm, bm->cr.xmax - 4, bm->cr.ymax - 3);
00130     gfx_lineTo(bm, bm->cr.xmax - 4, bm->cr.ymax + 1);
00131     gfx_lineTo(bm, bm->cr.xmax - 1, bm->cr.ymax - 1);
00132     gfx_lineTo(bm, bm->cr.xmax - 4, bm->cr.ymax - 3);
00133 
00134 #else /* CONFIG_CHART_ARROWS */
00135 
00136     /* Draw a box around the chart */
00137     gfx_rectDraw(bm, bm->cr.xmin, bm->cr.ymin, bm->cr.xmax, bm->cr.ymax);
00138 
00139 #endif /* CONFIG_CHART_ARROWS */
00140 
00141     //CHECK_WALL(wall_before_raster, WALL_SIZE);
00142     //CHECK_WALL(wall_after_raster, WALL_SIZE);
00143 }
00144 
00145 
00151 void chart_drawCurve(Bitmap *bm, const chart_y_t *curve_y, int curve_cnt)
00152 {
00153     int i;
00154 
00155     gfx_moveTo(bm, gfx_transformX(bm, 0), gfx_transformY(bm, curve_y[0]));
00156 
00157     for (i = 1; i < curve_cnt; i++)
00158         gfx_lineTo(bm, gfx_transformX(bm, i), gfx_transformY(bm, curve_y[i]));
00159 
00160     //CHECK_WALL(wall_before_raster, WALL_SIZE);
00161     //CHECK_WALL(wall_after_raster, WALL_SIZE);
00162 }
00163 
00164 
00169 void chart_drawDots(Bitmap *bm, const chart_x_t *dots_x, const chart_y_t *dots_y, int cnt)
00170 {
00171     int i;
00172     coord_t x, y;
00173 
00174     for (i = 0; i < cnt; i++)
00175     {
00176         if (dots_x)
00177             x = gfx_transformX(bm, dots_x[i]);
00178         else
00179             x = gfx_transformX(bm, i);
00180 
00181         y = gfx_transformY(bm, dots_y[i]);
00182 
00183         /* Draw tick over the curve */
00184         gfx_rectFill(bm,
00185             x - TICKS_WIDTH / 2, y - TICKS_HEIGHT / 2,
00186             x + (TICKS_WIDTH + 1) / 2, y + (TICKS_HEIGHT + 1) / 2);
00187 
00188         /* Draw vertical line from the curve to the X-axis */
00189         //gfx_drawLine(bm, x, y, x, bm->cr.ymax - 1);
00190     }
00191 
00192     //CHECK_WALL(wall_before_raster, WALL_SIZE);
00193     //CHECK_WALL(wall_after_raster, WALL_SIZE);
00194 }
00195