1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/*
ChibiOS/GFX - Copyright (C) 2012, 2013
Joel Bodenmann aka Tectu <joel@unormal.org>
This file is part of ChibiOS/GFX.
ChibiOS/GFX is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/GFX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file include/gwin/graph.h
* @brief GWIN GRAPH module header file.
*
* @defgroup Graph Graph
* @ingroup GWIN
*
* @details GWIN allows it to easily draw graphs.
* @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h
* @pre GWIN_NEED_GRAPH must be set to TRUE in your gfxconf.h
*
* @{
*/
#ifndef _GWIN_GRAPH_H
#define _GWIN_GRAPH_H
#if GWIN_NEED_GRAPH || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
#define GW_GRAPH 0x0003
/*===========================================================================*/
/* Type definitions */
/*===========================================================================*/
// GDISP now has its own point structure
#define GGraphPoint point
typedef enum GGraphPointType_e {
GGRAPH_POINT_NONE, GGRAPH_POINT_DOT, GGRAPH_POINT_SQUARE, GGRAPH_POINT_CIRCLE
} GGraphPointType;
typedef struct GGraphPointStyle_t {
GGraphPointType type;
coord_t size;
color_t color;
} GGraphPointStyle;
typedef enum GGraphLineType_e {
GGRAPH_LINE_NONE, GGRAPH_LINE_SOLID, GGRAPH_LINE_DOT, GGRAPH_LINE_DASH
} GGraphLineType;
typedef struct GGraphLineStyle_t {
GGraphLineType type;
coord_t size;
color_t color;
} GGraphLineStyle;
typedef struct GGraphGridStyle_t {
GGraphLineType type;
coord_t size;
color_t color;
coord_t spacing;
} GGraphGridStyle;
typedef struct GGraphStyle_t {
GGraphPointStyle point;
GGraphLineStyle line;
GGraphLineStyle xaxis;
GGraphLineStyle yaxis;
GGraphGridStyle xgrid;
GGraphGridStyle ygrid;
uint16_t flags;
#define GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS 0x0001
#define GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS 0x0002
#define GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS 0x0004
#define GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS 0x0008
#define GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS)
#define GWIN_GRAPH_STYLE_NEGATIVE_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS)
#define GWIN_GRAPH_STYLE_XAXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS)
#define GWIN_GRAPH_STYLE_YAXIS_ARROWS (GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS)
#define GWIN_GRAPH_STYLE_ALL_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS)
} GGraphStyle;
// A graph window
typedef struct GGraphObject_t {
GWindowObject gwin;
GGraphStyle style;
coord_t xorigin, yorigin;
coord_t lastx, lasty;
} GGraphObject;
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Create a graph window.
* @return NULL if there is no resultant drawing area, otherwise a window handle.
*
* @param[in] gg The GGraphObject structure to initialise. If this is NULL the structure is dynamically allocated.
* @param[in] x,y The screen co-ordinates for the bottom left corner of the window
* @param[in] width The width of the window
* @param[in] height The height of the window
* @note The console is not automatically cleared on creation. You must do that by calling gwinClear() (possibly after changing your background color)
* @note The coordinate system within the window for graphing operations (but not for any other drawing
* operation) is relative to the bottom left corner and then shifted right and up by the specified
* graphing x and y origin. Note that this system is inverted in the y direction relative to the display.
* This gives the best graphing arrangement ie. increasing y values are closer to the top of the display.
*
* @api
*/
GHandle gwinCreateGraph(GGraphObject *gg, coord_t x, coord_t y, coord_t width, coord_t height);
/**
* @brief Set the style of the graphing operations.
*
* @param[in] gh The window handle (must be a graph window)
* @param[in] pstyle The graph style to set.
* @note The graph is not automatically redrawn. The new style will apply to any new drawing operations.
*
* @api
*/
void gwinGraphSetStyle(GHandle gh, const GGraphStyle *pstyle);
/**
* @brief Set the origin for graphing operations.
*
* @param[in] gh The window handle (must be a graph window)
* @param[in] x, y The new origin for the graph (in graph coordinates relative to the bottom left corner).
* @note The graph is not automatically redrawn. The new origin will apply to any new drawing operations.
*
* @api
*/
void gwinGraphSetOrigin(GHandle gh, coord_t x, coord_t y);
/**
* @brief Draw the axis and the background grid.
*
* @param[in] gh The window handle (must be a graph window)
* @note The graph is not automatically cleared. You must do that first by calling gwinClear().
*
* @api
*/
void gwinGraphDrawAxis(GHandle gh);
/**
* @brief Start a new set of graphing data.
* @details This prevents a line being drawn from the last data point to the next point to be drawn.
*
* @param[in] gh The window handle (must be a graph window)
*
* @api
*/
void gwinGraphStartSet(GHandle gh);
/**
* @brief Draw a graph point.
* @details A graph point and a line connecting to the previous point will be drawn.
*
* @param[in] gh The window handle (must be a graph window)
* @param[in] x, y The new point for the graph.
*
* @api
*/
void gwinGraphDrawPoint(GHandle gh, coord_t x, coord_t y);
/**
* @brief Draw multiple graph points.
* @details A graph point and a line connecting to each previous point will be drawn.
*
* @param[in] gh The window handle (must be a graph window)
* @param[in] points The array of points for the graph.
* @param[in] count The number of points in the array.
* @note This is slightly more efficient than calling gwinGraphDrawPoint() repeatedly.
*
* @api
*/
void gwinGraphDrawPoints(GHandle gh, const point *points, unsigned count);
#ifdef __cplusplus
}
#endif
#endif /* GWIN_NEED_GRAPH */
#endif /* _GWIN_GRAPH_H */
/** @} */
|