4 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999, 2000, 2001, 2003 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See devlib/README for information.
9 * \brief Simple charts on top of mware/gfx routines (implementation).
14 * bm = chart_init(0, ymax, N_POINTS_CURVE, ymin);
16 * chart_drawCurve(bm, curve_y, curve_points + 1);
17 * gfx_setViewRect(bm, xmin, ymax, xmax, ymin);
18 * chart_drawDots(bm, samples_x, samples_y, samples_cnt);
24 * \author Bernardo Innocenti <bernie@develer.com>
29 *#* Revision 1.5 2004/09/14 20:56:39 bernie
30 *#* Make more generic and adapt to new gfx functions.
32 *#* Revision 1.3 2004/08/11 19:39:12 bernie
33 *#* Use chart_x_t and chart_y_t for the input dataset.
35 *#* Revision 1.1 2004/08/04 03:16:30 bernie
36 *#* Import simple chart drawing code.
41 #include <mware/gfx.h>
44 #ifndef CONFIG_CHART_ARROWS
45 #define CONFIG_CHART_ARROWS 0
49 void chart_init(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax)
53 gfx_SetClipRect(bm, xmin + CHART_BORDERLEFT, ymin + CHART_BORDERTOP,
54 xmax - CHART_BORDERRIGHT, ymax - CHART_BORDERBOTTOM);
60 void chart_setScale(Bitmap *bm, chart_x_t xmin, chart_y_t ymin, chart_x_t xmax, chart_y_t ymax)
62 gfx_SetViewRect(bm, xmin, ymin, xmax, ymax);
69 void chart_drawAxis(Bitmap *bm)
71 #if CONFIG_CHART_ARROWS
74 gfx_MoveTo(bm, bm->cr.xmin, bm->cr.ymin + 4);
75 gfx_LineTo(bm, bm->cr.xmin, bm->cr.ymax - 1);
76 gfx_LineTo(bm, bm->cr.xmax - 4 - 1, bm->cr.ymax - 1);
79 gfx_MoveTo(bm, bm->cr.xmin - 2, bm->cr.ymin + 3);
80 gfx_LineTo(bm, bm->cr.xmin + 2, bm->cr.ymin + 3);
81 gfx_LineTo(bm, bm->cr.xmin, bm->cr.ymin);
82 gfx_LineTo(bm, bm->cr.xmin - 2, bm->cr.ymin + 3);
84 /* Draw right arrow */
85 gfx_MoveTo(bm, bm->cr.xmax - 4, bm->cr.ymax - 3);
86 gfx_LineTo(bm, bm->cr.xmax - 4, bm->cr.ymax + 1);
87 gfx_LineTo(bm, bm->cr.xmax - 1, bm->cr.ymax - 1);
88 gfx_LineTo(bm, bm->cr.xmax - 4, bm->cr.ymax - 3);
90 #else /* CONFIG_CHART_ARROWS */
92 /* Draw a box around the chart */
93 gfx_RectDraw(bm, bm->cr.xmin, bm->cr.ymin, bm->cr.xmax, bm->cr.ymax);
95 #endif /* CONFIG_CHART_ARROWS */
97 //CHECK_WALL(wall_before_raster, WALL_SIZE);
98 //CHECK_WALL(wall_after_raster, WALL_SIZE);
103 * Draw a set of \a curve_cnt connected segments, whose Y coordinates
104 * are identified by the \a curve_y array and X-coordinates are
105 * are evenly spaced by one virtual unit.
107 void chart_drawCurve(Bitmap *bm, const chart_y_t *curve_y, int curve_cnt)
111 gfx_MoveTo(bm, gfx_TransformX(bm, 0), gfx_TransformY(bm, curve_y[0]));
113 for (i = 1; i < curve_cnt; i++)
114 gfx_LineTo(bm, gfx_TransformX(bm, i), gfx_TransformY(bm, curve_y[i]));
116 //CHECK_WALL(wall_before_raster, WALL_SIZE);
117 //CHECK_WALL(wall_after_raster, WALL_SIZE);
122 * Disegna dei dot in corrispondenza delle coppie (dotsx[i];dotsy[i])
123 * Se dotsx e' NULL, i punti vengono disegnati ad intervalli regolari.
125 void chart_drawDots(Bitmap *bm, const chart_x_t *dots_x, const chart_y_t *dots_y, int cnt)
130 for (i = 0; i < cnt; i++)
133 x = gfx_TransformX(bm, dots_x[i]);
135 x = gfx_TransformX(bm, i);
137 y = gfx_TransformY(bm, dots_y[i]);
139 /* Draw tick over the curve */
141 x - TICKS_WIDTH / 2, y - TICKS_HEIGHT / 2,
142 x + (TICKS_WIDTH + 1) / 2, y + (TICKS_HEIGHT + 1) / 2);
144 /* Draw vertical line from the curve to the X-axis */
145 //gfx_DrawLine(bm, x, y, x, bm->cr.ymax - 1);
148 //CHECK_WALL(wall_before_raster, WALL_SIZE);
149 //CHECK_WALL(wall_after_raster, WALL_SIZE);