µGFX  2.9
version 2.9
gwin_graph.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 /**
9  * @file src/gwin/gwin_graph.h
10  * @brief GWIN GRAPH module header file
11  *
12  * @defgroup Graph Graph
13  * @ingroup Windows
14  *
15  * @brief Graph window. Used to display highly customizable graphs.
16  *
17  * @details GWIN allows it to easily draw graphs.
18  *
19  * @pre GFX_USE_GWIN must be set to GFXON in your gfxconf.h
20  * @pre GWIN_NEED_GRAPH must be set to GFXON in your gfxconf.h
21  *
22  * @{
23  */
24 
25 #ifndef _GWIN_GRAPH_H
26 #define _GWIN_GRAPH_H
27 
28 /* This file is included within "src/gwin/gwin.h" */
29 
30 typedef enum GGraphPointType_e {
31  GGRAPH_POINT_NONE, GGRAPH_POINT_DOT, GGRAPH_POINT_SQUARE, GGRAPH_POINT_CIRCLE
32  } GGraphPointType;
33 
34 typedef struct GGraphPointStyle_t {
35  GGraphPointType type;
36  gCoord size;
37  gColor color;
38  } GGraphPointStyle;
39 
40 typedef enum GGraphLineType_e {
41  GGRAPH_LINE_NONE, GGRAPH_LINE_SOLID, GGRAPH_LINE_DOT, GGRAPH_LINE_DASH
42  } GGraphLineType;
43 
44 typedef struct GGraphLineStyle_t {
45  GGraphLineType type;
46  gCoord size;
47  gColor color;
48  } GGraphLineStyle;
49 
50 typedef struct GGraphGridStyle_t {
51  GGraphLineType type;
52  gCoord size;
53  gColor color;
54  gCoord spacing;
55  } GGraphGridStyle;
56 
57 typedef struct GGraphStyle_t {
58  GGraphPointStyle point;
59  GGraphLineStyle line;
60  GGraphLineStyle xaxis;
61  GGraphLineStyle yaxis;
62  GGraphGridStyle xgrid;
63  GGraphGridStyle ygrid;
64  gU16 flags;
65  #define GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS 0x0001
66  #define GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS 0x0002
67  #define GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS 0x0004
68  #define GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS 0x0008
69  #define GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS)
70  #define GWIN_GRAPH_STYLE_NEGATIVE_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS)
71  #define GWIN_GRAPH_STYLE_XAXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS)
72  #define GWIN_GRAPH_STYLE_YAXIS_ARROWS (GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS)
73  #define GWIN_GRAPH_STYLE_ALL_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS)
74 } GGraphStyle;
75 
76 // A graph window
77 typedef struct GGraphObject {
78  GWindowObject g;
79  GGraphStyle style;
80  gCoord xorigin, yorigin;
81  gCoord lastx, lasty;
82  } GGraphObject;
83 
84 /*===========================================================================*/
85 /* External declarations. */
86 /*===========================================================================*/
87 
88 /**
89  * @brief Create a graph window.
90  * @return NULL if there is no resultant drawing area, otherwise a window handle.
91  *
92  * @param[in] g The GDisplay to display this window on
93  * @param[in] gg The GGraphObject structure to initialise. If this is NULL the structure is dynamically allocated.
94  * @param[in] pInit The initialization parameters to use
95  *
96  * @note The drawing color and the background color get set to the current defaults. If you haven't called
97  * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are GFX_WHITE and GFX_BLACK respectively.
98  * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there
99  * is no default font and text drawing operations will no nothing.
100  * @note The dimensions and position may be changed to fit on the real screen.
101  * @note A graph does not save the drawing state. It is not automatically redrawn if the window is moved or
102  * its visibility state is changed.
103  * @note The coordinate system within the window for graphing operations (but not for any other drawing
104  * operation) is relative to the bottom left corner and then shifted right and up by the specified
105  * graphing x and y origin. Note that this system is inverted in the y direction relative to the display.
106  * This gives the best graphing arrangement ie. increasing y values are closer to the top of the display.
107  *
108  * @api
109  */
110 GHandle gwinGGraphCreate(GDisplay *g, GGraphObject *gg, const GWindowInit *pInit);
111 #define gwinGraphCreate(gg, pInit) gwinGGraphCreate(GDISP, gg, pInit)
112 
113 /**
114  * @brief Set the style of the graphing operations.
115  *
116  * @param[in] gh The window handle (must be a graph window)
117  * @param[in] pstyle The graph style to set.
118  * @note The graph is not automatically redrawn. The new style will apply to any new drawing operations.
119  *
120  * @api
121  */
122 void gwinGraphSetStyle(GHandle gh, const GGraphStyle *pstyle);
123 
124 /**
125  * @brief Set the origin for graphing operations.
126  *
127  * @param[in] gh The window handle (must be a graph window)
128  * @param[in] x, y The new origin for the graph (in graph coordinates relative to the bottom left corner).
129  * @note The graph is not automatically redrawn. The new origin will apply to any new drawing operations.
130  *
131  * @api
132  */
134 
135 /**
136  * @brief Draw the axis and the background grid.
137  *
138  * @param[in] gh The window handle (must be a graph window)
139  * @note The graph is not automatically cleared. You must do that first by calling gwinClear().
140  *
141  * @api
142  */
144 
145 /**
146  * @brief Start a new set of graphing data.
147  * @details This prevents a line being drawn from the last data point to the next point to be drawn.
148  *
149  * @param[in] gh The window handle (must be a graph window)
150  *
151  * @api
152  */
154 
155 /**
156  * @brief Draw a graph point.
157  * @details A graph point and a line connecting to the previous point will be drawn.
158  *
159  * @param[in] gh The window handle (must be a graph window)
160  * @param[in] x, y The new point for the graph.
161  *
162  * @api
163  */
165 
166 /**
167  * @brief Draw multiple graph points.
168  * @details A graph point and a line connecting to each previous point will be drawn.
169  *
170  * @param[in] gh The window handle (must be a graph window)
171  * @param[in] points The array of points for the graph.
172  * @param[in] count The number of points in the array.
173  * @note This is slightly more efficient than calling gwinGraphDrawPoint() repeatedly.
174  *
175  * @api
176  */
177 void gwinGraphDrawPoints(GHandle gh, const gPoint *points, unsigned count);
178 
179 #endif /* _GWIN_GRAPH_H */
180 /** @} */
181 
COLOR_TYPE gColor
The color type definition.
Definition: gdisp_colors.h:437
gI16 gCoord
The type for a coordinate or length on the screen.
Definition: gdisp.h:39
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.
The structure to initialise a GWIN.
Definition: gwin.h:75
A window object structure.
Definition: gwin.h:40
Type for a 2D point on the screen.
Definition: gdisp.h:51