blob: 5783d71d8ffcd39dc29d169a831f4e12074393e9 [file] [log] [blame]
adamdunkelsb27d85a2003-09-01 22:23:26 +00001/**
adamdunkelse937ded2003-10-01 07:53:57 +00002 * \addtogroup ctk
3 * @{
4 */
5
6/**
adamdunkelsb27d85a2003-09-01 22:23:26 +00007 * \file
8 * CTK screen drawing module interface, ctk-draw.
9 * \author Adam Dunkels <adam@dunkels.com>
10 *
11 * This file contains the interface for the ctk-draw module.The
12 * ctk-draw module takes care of the actual screen drawing for CTK by
13 * implementing a handful of functions that are called by CTK.
14 *
adamdunkelsb27d85a2003-09-01 22:23:26 +000015 */
16
adamdunkelsca9ddcb2003-03-19 14:13:31 +000017/*
adamdunkelsb27d85a2003-09-01 22:23:26 +000018 * Copyright (c) 2002-2003, Adam Dunkels.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000019 * All rights reserved.
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above
27 * copyright notice, this list of conditions and the following
28 * disclaimer in the documentation and/or other materials provided
29 * with the distribution.
adamdunkelsb27d85a2003-09-01 22:23:26 +000030 * 3. The name of the author may not be used to endorse or promote
adamdunkelsca9ddcb2003-03-19 14:13:31 +000031 * products derived from this software without specific prior
32 * written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
35 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
38 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
adamdunkelsb27d85a2003-09-01 22:23:26 +000046 * This file is part of the Contiki desktop OS.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000047 *
adamdunkels6c168982004-07-04 11:40:04 +000048 * $Id: ctk-draw.h,v 1.6 2004/07/04 11:40:04 adamdunkels Exp $
adamdunkelsca9ddcb2003-03-19 14:13:31 +000049 *
50 */
51
52#ifndef __CTK_DRAW_H__
53#define __CTK_DRAW_H__
54
55#include "ctk.h"
56
57#include "ctk-arch.h"
58
adamdunkelsb27d85a2003-09-01 22:23:26 +000059/**
adamdunkelse937ded2003-10-01 07:53:57 +000060 * \defgroup ctkdraw CTK device driver functions
61 * @{
62 *
63 * The CTK device driver functions are divided into two modules, the
64 * ctk-draw module and the ctk-arch module. The purpose of the
65 * ctk-arch and the ctk-draw modules is to act as an interface between
66 * the CTK and the actual hardware of the system on which Contiki is
67 * run. The ctk-arch takes care of the keyboard input from the user,
68 * and the ctk-draw is responsible for drawing the CTK desktop,
69 * windows and user interface widgets onto the actual screen.
70 *
71 * More information about the ctk-draw and the ctk-arch modules can be
72 * found in the sections \ref ctk-draw and \ref ctk-arch.
73 */
74
75/**
76 * \page ctk-draw The ctk-draw module
77 *
78 * In order to work efficiently even on limited systems, CTK uses a
79 * simple coordinate system, where the screen is addressed using
80 * character coordinates instead of pixel coordinates. This makes it
81 * trivial to implement the coordinate system on a text-based screen,
82 * and significantly reduces complexity for pixel based screen
83 * systems.
84 *
85 * The top left of the screen is (0,0) with x and y coordinates
86 * growing downwards and to the right.
87 *
88 * It is the responsibility of the ctk-draw module to keep track of
89 * the screen size and must implement the two functions
90 * ctk_draw_width() and ctk_draw_height(), which are used by the CTK
91 * for querying the screen size. The functions must return the width
92 * and the height of the ctk-draw screen in character coordinates.
93 *
94 * The ctk-draw module is responsible for drawing CTK windows onto the
95 * screen through the function ctk_draw_window().. A pseudo-code
96 * implementation of this function might look like this:
97 * \code
98 ctk_draw_window(window, focus, clipy1, clipy2) {
99 draw_window_borders(window, focus, clipy1, clipy2);
100 foreach(widget, window->inactive) {
101 ctk_draw_widget(widget, focus, clipy1, clipy2);
102 }
103 foreach(widget, window->active) {
104 if(widget == window->focused) {
105 ctk_draw_widget(widget, focus | CTK_FOCUS_WIDGET,
106 clipy1, clipy2);
107 } else {
108 ctk_draw_widget(widget, focus, clipy1, clipy2);
109 }
110 }
111 }
112
113 \endcode
114 *
115 * Where draw_window_borders() draws the window borders (also between
116 * clipy1 and clipy2). The ctk_draw_widget() function is explained
117 * below. Notice how the clipy1 and clipy2 parameters are passed to
118 * all other functions; every function needs to know the boundaries
119 * within which they are allowed to draw.
120 *
121 * In order to aid in implementing a ctk-draw module, a text-based
122 * ctk-draw called ctk-conio has already been implemented. It conforms
123 * to the Borland conio C library, and a skeleton implementation of
124 * said library exists in lib/libconio.c. If a more machine specific
125 * ctk-draw module is to be implemented, the instructions in this file
126 * should be followed.
127 *
128 */
129
130/**
adamdunkelsb27d85a2003-09-01 22:23:26 +0000131 * The initialization function.
132 *
133 * This function is supposed to get the screen ready for drawing, and
134 * may be called at more than one time during the operation of the
135 * system.
136 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000137void ctk_draw_init(void);
138
adamdunkelsb27d85a2003-09-01 22:23:26 +0000139/**
140 * Clear the screen between the clip bounds.
141 *
142 * This function should clear the screen between the y coordinates
143 * "clipy1" and "clipy2", including the line at y coordinate "clipy1",
144 * but not the line at y coordinate "clipy2".
145 *
146 * \note This function may be used to draw a background image
147 * (wallpaper) on the desktop; it does not necessarily "clear" the
148 * screen.
149 *
150 * \param clipy1 The lower y coordinate of the clip region.
151 * \param clipy2 The upper y coordinate of the clip region.
152 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000153void ctk_draw_clear(unsigned char clipy1, unsigned char clipy2);
adamdunkelsb27d85a2003-09-01 22:23:26 +0000154
155/**
156 * Draw the window background.
157 *
158 * This function will be called by the CTK before a window will be
159 * completely redrawn.The function is supposed to draw the window
160 * background, excluding window borders as these should be drawn by
161 * the function that actually draws the window, between "clipy1" and
162 * "clipy2".
163 *
164 * \note This function does not necessarily have to clear the window -
165 * it can be used for drawing a background pattern in the window as
166 * well.
167 *
168 * \param window The window for which the background should be drawn.
169 *
170 * \param focus The focus of the window, either CTK_FOCUS_NONE for a
171 * background window, or CTK_FOCUS_WINDOW for the foreground window.
172 *
173 * \param clipy1 The lower y coordinate of the clip region.
174 * \param clipy2 The upper y coordinate of the clip region.
175*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000176void ctk_draw_clear_window(struct ctk_window *window,
177 unsigned char focus,
adamdunkelsb27d85a2003-09-01 22:23:26 +0000178 unsigned char clipy1,
179 unsigned char clipy2);
180/**
181 * Draw a window onto the screen.
182 *
183 * This function is called by the CTK when a window should be drawn on
184 * the screen. The ctk-draw layer is free to choose how the window
185 * will appear on screen; with or without window borders and the style
186 * of the borders, with or without transparent window background and
187 * how the background shall look, etc.
188 *
189 * \param window The window which is to be drawn.
190 *
191 * \param focus Specifies if the window should be drawn in foreground
192 * or background colors and can be either CTK_FOCUS_NONE or
193 * CTK_FOCUS_WINDOW. Windows with a focus of CTK_FOCUS_WINDOW is
194 * usually drawn in a brighter color than those with CTK_FOCUS_NONE.
195 *
196 * \param clipy1 Specifies the first lines on screen that actually
197 * should be drawn, in screen coordinates (line 1 is the first line
198 * below the menus).
199 *
200 * \param clipy2 Specifies the last + 1 line on screen that should be
201 * drawn, in screen coordinates (line 1 is the first line below the
202 * menus)
203 *
204 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000205void ctk_draw_window(struct ctk_window *window,
206 unsigned char focus,
207 unsigned char clipy1,
208 unsigned char clipy2);
209
adamdunkelsb27d85a2003-09-01 22:23:26 +0000210
211/**
212 * Draw a dialog onto the screen.
213 *
214 * In CTK, a dialog is similar to a window, with the only exception
215 * being that they are drawn in a different style. Also, since dialogs
216 * always are drawn on top of everything else, they do not need to be
217 * drawn within any special boundaries.
218 *
219 * \note This function can usually be implemented so that it uses the
220 * same widget drawing code as the ctk_draw_window() function.
221 *
222 * \param dialog The dialog that is to be drawn.
223 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000224void ctk_draw_dialog(struct ctk_window *dialog);
225
adamdunkelsb27d85a2003-09-01 22:23:26 +0000226/**
227 * Draw a widget on a window.
228 *
229 * This function is used for drawing a CTK widgets onto the screem is
230 * likely to be the most complex function in the ctk-draw
231 * module. Still, it is straightforward to implement as it can be
232 * written in an incremental fashion, starting with a single widget
233 * type and adding more widget types, one at a time.
234
235 * The ctk-draw module may exploit how the CTK focus constants are
236 * defined in order to use a look-up table for the colors. The CTK
237 * focus constants are defined in the file ctk/ctk.h as follows:
238 \code
239 #define CTK_FOCUS_NONE 0
240 #define CTK_FOCUS_WIDGET 1
241 #define CTK_FOCUS_WINDOW 2
242 #define CTK_FOCUS_DIALOG 4
243 \endcode
244
245 * This gives the following table:
246 \code
247 0: CTK_FOCUS_NONE (Background window, non-focused widget)
248 1: CTK_FOCUS_WIDGET (Background window, focused widget)
249 2: CTK_FOCUS_WINDOW (Foreground window, non-focused widget)
250 3: CTK_FOCUS_WINDOW | CTK_FOCUS_WIDGET
251 (Foreground window, focused widget)
252 4: CTK_FOCUS_DIALOG (Dialog, non-focused widget)
253 5: CTK_FOCUS_DIALOG | CTK_FOCUS_WIDGET
254 (Dialog, focused widget)
255 \endcode
256
257
258 * \param w The widget to be drawn.
259 * \param focus The focus of the widget.
260 * \param clipy1 The lower y coordinate of the clip region.
261 * \param clipy2 The upper y coordinate of the clip region.
262 */
263
264void ctk_draw_widget(struct ctk_widget *w,
265 unsigned char focus,
266 unsigned char clipy1,
267 unsigned char clipy2);
268
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000269void ctk_draw_menus(struct ctk_menus *menus);
270
271
272
273/* Returns width and height of screen. */
274unsigned char ctk_draw_width(void);
275unsigned char ctk_draw_height(void);
276
277
adamdunkels6c168982004-07-04 11:40:04 +0000278extern unsigned char ctk_draw_windowborder_width,
279 ctk_draw_windowborder_height,
280 ctk_draw_windowtitle_height;
281
adamdunkelse937ded2003-10-01 07:53:57 +0000282
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000283#endif /* __CTK_DRAW_H__ */
adamdunkelse937ded2003-10-01 07:53:57 +0000284
285
286/**
287 * The keyboard character type of the system
288 *
289 * The ctk_arch_key_t is usually typedef'd to the char type, but some
290 * systems (such as VNC) have a 16-bit key type.
291 *
292 * \var typedef char ctk_arch_key_t;
293 */
294
295/**
296 * Get a keypress from the keyboard input queue.
297 *
298 * This function will remove the first keypress in the keyboard input
299 * queue and return it. If the keyboard queue is empty, the return
300 * value is undefined. This function is intended to be used only after
301 * the ctk_arch_keyavail() function has returned non-zero.
302 *
303 * \return The first keypress from the keyboard input queue.
304 *
305 * \fn ctk_arch_key_t ctk_arch_getkey(void);
306 */
307
308/**
309 * Check if there is a keypress in the keyboard input queue.
310 *
311 * \return Zero if the keyboard input queue is empty, non-zero
312 * otherwise.
313 *
314 * \fn unsigned char ctk_arch_keyavail(void);
315 */
316
317/**
318 * The character used for the Return/Enter key.
319 *
320 * \define #define CH_ENTER '\n'
321 */
322
323/**
324 * \page ctk-arch The ctk-arch module
325 *
326 * The ctk-arch module deals with keyboard input from the underlying
327 * target system on which Contiki is running. The ctk-arch manages a
328 * keyboard input queue that is queried using the two functions
329 * ctk_arch_keyavail() and ctk_arch_getkey().
330 */
adamdunkels6c168982004-07-04 11:40:04 +0000331
adamdunkelse937ded2003-10-01 07:53:57 +0000332/** @} */
333/** @} */