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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/*
ChibiOS/GFX - Copyright (C) 2012
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 gwin.h
* @brief GWIN Graphic window subsystem header file.
*
* @addtogroup GWIN
* @{
*/
#ifndef _GWIN_H
#define _GWIN_H
#ifndef GFX_USE_GWIN
#define GFX_USE_GWIN FALSE
#endif
#if GFX_USE_GWIN || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/**
* @name GWIN more complex functionality to be compiled
* @{
*/
/**
* @brief Should console functions be included.
* @details Defaults to FALSE
*/
#ifndef GWIN_NEED_CONSOLE
#define GWIN_NEED_CONSOLE FALSE
#endif
/**
* @brief Should button functions be included.
* @details Defaults to FALSE
*/
#ifndef GWIN_NEED_BUTTON
#define GWIN_NEED_BUTTON FALSE
#endif
/** @} */
/*===========================================================================*/
/* Low Level Driver details and error checks. */
/*===========================================================================*/
#if !defined(GFX_USE_GDISP) || !GFX_USE_GDISP
#error "GWIN: GFX_USE_GDISP must also be defined"
#endif
#include "gdisp.h"
#if !GDISP_NEED_CLIP
#warning "GWIN: Drawing can occur outside the defined window as GDISP_NEED_CLIP is FALSE"
#endif
#if GWIN_NEED_CONSOLE && !GDISP_NEED_TEXT
#error "GWIN: Text support (GDISP_NEED_TEXT) is required if GWIN_NEED_CONSOLE is defined."
#endif
#if GWIN_NEED_BUTTON && !GDISP_NEED_TEXT
#error "GWIN: Text support (GDISP_NEED_TEXT) is required if GWIN_NEED_BUTTON is defined."
#endif
#if GWIN_NEED_BUTTON
#warning "GWIN: Button support is not complete yet"
#endif
/*===========================================================================*/
/* Type definitions */
/*===========================================================================*/
typedef enum GWindowType_e {
GW_WINDOW, GW_CONSOLE, GW_BUTTON
} GWindowType;
// A basic window
typedef struct GWindowObject_t {
GWindowType type; // What type of window is this
uint16_t flags; // Internal flags
coord_t x, y; // Screen relative position
coord_t width, height; // Dimensions of this window
color_t color, bgcolor; // Current drawing colors
#if GDISP_NEED_TEXT
font_t font; // Current font
#endif
} GWindowObject, * GHandle;
#if GWIN_NEED_CONSOLE
// A console window. Supports wrapped text writing and a cursor.
typedef struct GConsoleObject_t {
GWindowObject gwin;
struct GConsoleWindowStream_t {
const struct GConsoleWindowVMT_t *vmt;
_base_asynchronous_channel_data
} stream;
coord_t cx,cy; // Cursor position
uint8_t fy; // Current font height
uint8_t fp; // Current font inter-character spacing
} GConsoleObject;
#endif
#if GWIN_NEED_BUTTON
typedef enum GButtonShape_e {
GBTN_3D, GBTN_SQUARE, GBTN_ROUNDED, GBTN_ELLIPSE
} GButtonShape;
typedef struct GButtonStyle_t {
GButtonShape shape;
color_t color_up_edge;
color_t color_up_fill;
color_t color_up_txt;
color_t color_dn_edge;
color_t color_dn_fill;
color_t color_dn_txt;
} GButtonStyle;
typedef enum GButtonType_e {
GBTN_NORMAL, GBTN_TOGGLE
} GButtonType;
typedef enum GButtonState_e {
GBTN_UP, GBTN_DOWN
} GButtonState;
// A button window
typedef struct GButtonObject_t {
GWindowObject gwin;
GButtonStyle style;
GButtonState state;
GButtonType type;
const char * txt;
void * callback; // To be fixed
void * inputsrc; // To be fixed
} GButtonObject;
#endif
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
/* Base Functions */
GHandle gwinCreateWindow(GWindowObject *gw, coord_t x, coord_t y, coord_t width, coord_t height);
void gwinDestroyWindow(GHandle gh);
/**
* @brief Get the X coordinate of the window
* @details Returns the X coordinate of the origin of the window.
* The coordinate is relative to the physical screen zero point.
*
* @param[in] gh The window
*/
#define gwinGetScreenX(gh) ((gh)->x)
/**
* @brief Get the Y coordinate of the window
* @details Returns the Y coordinate of the origin of the window.
* The coordinate is relative to the physical screen zero point.
*
* @param[in] gh The window
*/
#define gwinGetScreenY(gh) ((gh)->y)
/**
* @brief Get the width of the window
*
* @param[in] gh The window
*/
#define gwinGetWidth(gh) ((gh)->width)
/**
* @brief Get the height of the window
*
* @param[in] gh The window
*/
#define gwinGetHeight(gh) ((gh)->height)
/**
* @brief Set foreground color
* @details Set the color which will be used to draw
*
* @param[in] gh The window
* @param[in] clr The color to be set
*/
#define gwinSetColor(gh, clr) (gh)->color = (clr)
/**
* @brief Set background color
* @details Set the color which will be used as background
* @note gwinClear() must be called to set the background color
*
* @param[in] gh The window
* @param[in] bgclr The background color
*/
#define gwinSetBgColor(gh, bgclr) (gh)->bgcolor = (bgclr)
/* Set up for text */
#if GDISP_NEED_TEXT
void gwinSetFont(GHandle gh, font_t font);
#endif
/* Drawing Functions */
void gwinClear(GHandle gh);
void gwinDrawPixel(GHandle gh, coord_t x, coord_t y);
void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1);
void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy);
void gwinFillArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy);
void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer);
/* Circle Functions */
#if GDISP_NEED_CIRCLE
void gwinDrawCircle(GHandle gh, coord_t x, coord_t y, coord_t radius);
void gwinFillCircle(GHandle gh, coord_t x, coord_t y, coord_t radius);
#endif
/* Ellipse Functions */
#if GDISP_NEED_ELLIPSE
void gwinDrawEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b);
void gwinFillEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b);
#endif
/* Arc Functions */
#if GDISP_NEED_ARC
void gwinDrawArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle);
void gwinFillArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle);
#endif
/* Read a pixel Function */
#if GDISP_NEED_PIXELREAD
color_t gwinGetPixelColor(GHandle gh, coord_t x, coord_t y);
#endif
/* Extra Text Functions */
#if GDISP_NEED_TEXT
void gwinDrawChar(GHandle gh, coord_t x, coord_t y, char c);
void gwinFillChar(GHandle gh, coord_t x, coord_t y, char c);
void gwinDrawString(GHandle gh, coord_t x, coord_t y, const char *str);
void gwinFillString(GHandle gh, coord_t x, coord_t y, const char *str);
void gwinDrawStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, justify_t justify);
void gwinFillStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, justify_t justify);
#endif
#if GWIN_NEED_CONSOLE
GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height, font_t font);
BaseSequentialStream *gwinGetConsoleStream(GHandle gh);
void gwinPutChar(GHandle gh, char c);
void gwinPutString(GHandle gh, const char *str);
void gwinPutCharArray(GHandle gh, const char *str, size_t n);
#endif
#if GWIN_NEED_BUTTON
GHandle gwinCreateButton(GButtonObject *gb, coord_t x, coord_t y, coord_t width, coord_t height, font_t font, GButtonType type);
void gwinSetButtonStyle(GHandle gh, const GButtonStyle *style);
void gwinSetButtonText(GHandle gh, const char *txt, bool_t useAlloc);
void gwinButtonDraw(GHandle gh);
#define gwinGetButtonState(gh) (((GButtonObject *)(gh))->state)
//void gwinSetButtonCallback(GHandle gh, ????);
//void gwinSetButtonInput(GHandle gh, ????);
#endif
#ifdef __cplusplus
}
#endif
#endif /* GFX_USE_GWIN */
#endif /* _GWIN_H */
/** @} */
|