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.4 2004/08/25 14:12:09 rasky
30 *#* Aggiornato il comment block dei log RCS
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 void chart_init(Bitmap *bm, vcoord_t xmin, vcoord_t ymin, vcoord_t xmax, vcoord_t ymax)
49 gfx_SetClipRect(bm, CHART_BORDERLEFT, CHART_BORDERTOP,
50 bm->width - CHART_BORDERRIGHT - 1, bm->height - CHART_BORDERBOTTOM - 1);
52 gfx_SetViewRect(bm, xmin, ymin, xmax, ymax);
54 //CHECK_WALL(wall_before_raster, WALL_SIZE);
55 //CHECK_WALL(wall_after_raster, WALL_SIZE);
62 void chart_drawAxis(Bitmap *bm)
65 gfx_MoveTo(bm, CHART_BORDERLEFT, 4);
66 gfx_LineTo(bm, CHART_BORDERLEFT, CHART_BORDERTOP + CHART_HEIGHT - 1);
67 gfx_LineTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 5, CHART_BORDERTOP + CHART_HEIGHT - 1);
70 gfx_MoveTo(bm, CHART_BORDERLEFT - 2, 3);
71 gfx_LineTo(bm, CHART_BORDERLEFT + 2, 3);
72 gfx_LineTo(bm, CHART_BORDERLEFT, 0);
73 gfx_LineTo(bm, CHART_BORDERLEFT - 2, 3);
75 /* Draw right arrow */
76 gfx_MoveTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 4, CHART_BORDERTOP + CHART_HEIGHT - 3);
77 gfx_LineTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 4, CHART_BORDERTOP + CHART_HEIGHT + 1);
78 gfx_LineTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 1, CHART_BORDERTOP + CHART_HEIGHT - 1);
79 gfx_LineTo(bm, CHART_BORDERLEFT + CHART_WIDTH - 4, CHART_BORDERTOP + CHART_HEIGHT - 3);
81 //CHECK_WALL(wall_before_raster, WALL_SIZE);
82 //CHECK_WALL(wall_after_raster, WALL_SIZE);
87 * Draw a set of \a curve_cnt connected segments, whose Y coordinates
88 * are identified by the \a curve_y array and X-coordinates are
89 * are evenly spaced by one virtual unit.
91 void chart_drawCurve(Bitmap *bm, const chart_y_t *curve_y, int curve_cnt)
95 gfx_MoveTo(bm, gfx_TransformX(bm, 0), gfx_TransformY(bm, curve_y[0]));
97 for (i = 1; i < curve_cnt; i++)
98 gfx_LineTo(bm, gfx_TransformX(bm, i), gfx_TransformY(bm, curve_y[i]));
100 //CHECK_WALL(wall_before_raster, WALL_SIZE);
101 //CHECK_WALL(wall_after_raster, WALL_SIZE);
106 * Disegna dei dot in corrispondenza delle coppie (dotsx[i];dotsy[i])
107 * Se dotsx e' NULL, i punti vengono disegnati ad intervalli regolari.
109 void chart_drawDots(Bitmap *bm, const chart_x_t *dots_x, const chart_y_t *dots_y, int cnt)
114 for (i = 0; i < cnt; i++)
117 x = gfx_TransformX(bm, dots_x[i]);
119 x = gfx_TransformX(bm, i);
121 y = gfx_TransformY(bm, dots_y[i]);
123 gfx_DrawRect(bm, x - 1, y - 1, x + 1, y + 1);
125 /* Disegna ticks sull'asse X */
126 gfx_DrawLine(bm, x, bm->height - 1, x, CHART_HEIGHT - 1);
129 //CHECK_WALL(wall_before_raster, WALL_SIZE);
130 //CHECK_WALL(wall_after_raster, WALL_SIZE);