13 #include "../../gfx.h"
15 #if GFX_USE_GWIN && GWIN_NEED_GRAPH
17 #include "gwin_class.h"
19 #define GGRAPH_FLG_CONNECTPOINTS (GWIN_FIRST_CONTROL_FLAG<<0)
20 #define GGRAPH_ARROW_SIZE 5
22 static const GGraphStyle GGraphDefaultStyle = {
23 { GGRAPH_POINT_DOT, 0, GFX_WHITE },
24 { GGRAPH_LINE_DOT, 2, GFX_GRAY },
25 { GGRAPH_LINE_SOLID, 0, GFX_WHITE },
26 { GGRAPH_LINE_SOLID, 0, GFX_WHITE },
27 { GGRAPH_LINE_NONE, 0, GFX_WHITE, 0 },
28 { GGRAPH_LINE_NONE, 0, GFX_WHITE, 0 },
29 GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS
32 static const gwinVMT graphVMT = {
40 static void pointto(GGraphObject *gg,
gCoord x,
gCoord y,
const GGraphPointStyle *style) {
41 if (style->type == GGRAPH_POINT_NONE)
45 x += gg->g.x + gg->xorigin;
46 y = gg->g.y + gg->g.height - 1 - gg->yorigin - y;
48 if (style->size <= 1) {
54 case GGRAPH_POINT_SQUARE:
55 gdispGDrawBox(gg->g.display, x-style->size, y-style->size, 2*style->size, 2*style->size, style->color);
58 case GGRAPH_POINT_CIRCLE:
62 case GGRAPH_POINT_DOT:
73 gCoord run_on, run_off, run;
75 if (style->type == GGRAPH_LINE_NONE)
79 x0 += gg->g.x + gg->xorigin;
80 y0 = gg->g.y + gg->g.height - 1 - gg->yorigin - y0;
81 x1 += gg->g.x + gg->xorigin;
82 y1 = gg->g.y + gg->g.height - 1 - gg->yorigin - y1;
84 if (style->size <= 0) {
90 switch (style->type) {
93 run_off = -style->size;
96 case GGRAPH_LINE_DASH:
98 run_off = -style->size;
101 case GGRAPH_LINE_SOLID:
130 for(i=0; i<=dx; ++i) {
150 for(i=0; i<=dy; ++i) {
169 if (!(gg = (GGraphObject *)_gwindowCreate(g, &gg->g, pInit, &graphVMT, 0)))
171 gg->xorigin = gg->yorigin = 0;
172 gg->lastx = gg->lasty = 0;
175 _gwinFlushRedraws(REDRAW_WAIT);
180 #define gg ((GGraphObject *)gh)
182 if (gh->
vmt != &graphVMT)
185 gg->style.point = pstyle->point;
186 gg->style.line = pstyle->line;
187 gg->style.xaxis = pstyle->xaxis;
188 gg->style.yaxis = pstyle->yaxis;
189 gg->style.xgrid = pstyle->xgrid;
190 gg->style.ygrid = pstyle->ygrid;
191 gg->style.flags = pstyle->flags;
197 #define gg ((GGraphObject *)gh)
199 if (gh->
vmt != &graphVMT)
209 #define gg ((GGraphObject *)gh)
210 gCoord i, xmin, ymin, xmax, ymax;
212 if (gh->
vmt != &graphVMT || !_gwinDrawStart(gh))
216 xmax = gh->
width-gg->xorigin-1;
218 ymax = gh->
height-gg->yorigin-1;
221 if (gg->style.xgrid.type != GGRAPH_LINE_NONE && gg->style.xgrid.spacing >= 2) {
222 for(i = gg->style.xgrid.spacing; i <= xmax; i += gg->style.xgrid.spacing)
223 lineto(gg, i, ymin, i, ymax, (GGraphLineStyle *)&gg->style.xgrid);
224 for(i = -gg->style.xgrid.spacing; i >= xmin; i -= gg->style.xgrid.spacing)
225 lineto(gg, i, ymin, i, ymax, (GGraphLineStyle *)&gg->style.xgrid);
229 if (gg->style.ygrid.type != GGRAPH_LINE_NONE && gg->style.ygrid.spacing >= 2) {
230 for(i = gg->style.ygrid.spacing; i <= ymax; i += gg->style.ygrid.spacing)
231 lineto(gg, xmin, i, xmax, i, (GGraphLineStyle *)&gg->style.ygrid);
232 for(i = -gg->style.ygrid.spacing; i >= ymin; i -= gg->style.ygrid.spacing)
233 lineto(gg, xmin, i, xmax, i, (GGraphLineStyle *)&gg->style.ygrid);
237 lineto(gg, xmin, 0, xmax, 0, &gg->style.xaxis);
238 if ((gg->style.flags & GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS)) {
239 if (xmin > 0 || xmin < -(GGRAPH_ARROW_SIZE+1)) {
240 lineto(gg, xmin, 0, xmin+GGRAPH_ARROW_SIZE, GGRAPH_ARROW_SIZE, &gg->style.xaxis);
241 lineto(gg, xmin, 0, xmin+GGRAPH_ARROW_SIZE, -GGRAPH_ARROW_SIZE, &gg->style.xaxis);
244 if ((gg->style.flags & GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS)) {
245 if (xmax < 0 || xmax > (GGRAPH_ARROW_SIZE+1)) {
246 lineto(gg, xmax, 0, xmax-GGRAPH_ARROW_SIZE, GGRAPH_ARROW_SIZE, &gg->style.xaxis);
247 lineto(gg, xmax, 0, xmax-GGRAPH_ARROW_SIZE, -GGRAPH_ARROW_SIZE, &gg->style.xaxis);
252 lineto(gg, 0, ymin, 0, ymax, &gg->style.yaxis);
253 if ((gg->style.flags & GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS)) {
254 if (ymin > 0 || ymin < -(GGRAPH_ARROW_SIZE+1)) {
255 lineto(gg, 0, ymin, GGRAPH_ARROW_SIZE, ymin+GGRAPH_ARROW_SIZE, &gg->style.yaxis);
256 lineto(gg, 0, ymin, -GGRAPH_ARROW_SIZE, ymin+GGRAPH_ARROW_SIZE, &gg->style.yaxis);
259 if ((gg->style.flags & GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS)) {
260 if (ymax < 0 || ymax > (GGRAPH_ARROW_SIZE+1)) {
261 lineto(gg, 0, ymax, GGRAPH_ARROW_SIZE, ymax-GGRAPH_ARROW_SIZE, &gg->style.yaxis);
262 lineto(gg, 0, ymax, -GGRAPH_ARROW_SIZE, ymax-GGRAPH_ARROW_SIZE, &gg->style.yaxis);
271 if (gh->
vmt != &graphVMT)
274 gh->
flags &= ~GGRAPH_FLG_CONNECTPOINTS;
278 #define gg ((GGraphObject *)gh)
280 if (gh->
vmt != &graphVMT || !_gwinDrawStart(gh))
283 if ((gh->
flags & GGRAPH_FLG_CONNECTPOINTS)) {
285 lineto(gg, gg->lastx, gg->lasty, x, y, &gg->style.line);
288 pointto(gg, gg->lastx, gg->lasty, &gg->style.point);
291 gh->
flags |= GGRAPH_FLG_CONNECTPOINTS;
298 pointto(gg, x, y, &gg->style.point);
305 #define gg ((GGraphObject *)gh)
309 if (gh->
vmt != &graphVMT || !_gwinDrawStart(gh))
313 for(p = points, i = 0; i < count; p++, i++) {
314 if ((gh->
flags & GGRAPH_FLG_CONNECTPOINTS)) {
316 lineto(gg, gg->lastx, gg->lasty, p->
x, p->
y, &gg->style.line);
320 pointto(gg, gg->lastx, gg->lasty, &gg->style.point);
323 gh->
flags |= GGRAPH_FLG_CONNECTPOINTS;
332 for(p = points, i = 0; i < count; p++, i++)
333 pointto(gg, p->
x, p->
y, &gg->style.point);
void gdispGDrawPixel(GDisplay *g, gCoord x, gCoord y, gColor color)
Set a pixel in the specified color.
void gdispGDrawCircle(GDisplay *g, gCoord x, gCoord y, gCoord radius, gColor color)
Draw a circle.
void gdispGDrawLine(GDisplay *g, gCoord x0, gCoord y0, gCoord x1, gCoord y1, gColor color)
Draw a line.
gI16 gCoord
The type for a coordinate or length on the screen.
void gdispGDrawBox(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy, gColor color)
Draw a rectangular box.
void gwinGraphDrawPoint(GHandle gh, gCoord x, gCoord y)
Draw a graph point.
void gwinGraphStartSet(GHandle gh)
Start a new set of graphing data.
void gwinGraphDrawPoints(GHandle gh, const gPoint *points, unsigned count)
Draw multiple graph points.
void gwinGraphDrawAxis(GHandle gh)
Draw the axis and the background grid.
GHandle gwinGGraphCreate(GDisplay *g, GGraphObject *gg, const GWindowInit *pInit)
Create a graph window.
void gwinGraphSetStyle(GHandle gh, const GGraphStyle *pstyle)
Set the style of the graphing operations.
void gwinGraphSetOrigin(GHandle gh, gCoord x, gCoord y)
Set the origin for graphing operations.
void gwinSetVisible(GHandle gh, gBool visible)
Sets whether a window is visible or not.
The structure to initialise a GWIN.
A window object structure.
const struct gwinVMT * vmt
Type for a 2D point on the screen.
The Virtual Method Table for a GWIN window.