blob: c0ba064b0ee1f690712a5d2f9de1e0098f49ca05 [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 *
oliverschmidtadf27db2005-03-15 15:51:17 +000048 * $Id: ctk-draw.h,v 1.7 2005/03/15 15:51:17 oliverschmidt 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
oliverschmidtadf27db2005-03-15 15:51:17 +000098 ctk_draw_window(window, focus, clipy1, clipy2, draw_borders) {
99 if(draw_borders) {
100 draw_window_borders(window, focus, clipy1, clipy2);
101 }
adamdunkelse937ded2003-10-01 07:53:57 +0000102 foreach(widget, window->inactive) {
103 ctk_draw_widget(widget, focus, clipy1, clipy2);
104 }
105 foreach(widget, window->active) {
106 if(widget == window->focused) {
107 ctk_draw_widget(widget, focus | CTK_FOCUS_WIDGET,
108 clipy1, clipy2);
109 } else {
110 ctk_draw_widget(widget, focus, clipy1, clipy2);
111 }
112 }
113 }
114
115 \endcode
116 *
117 * Where draw_window_borders() draws the window borders (also between
118 * clipy1 and clipy2). The ctk_draw_widget() function is explained
119 * below. Notice how the clipy1 and clipy2 parameters are passed to
120 * all other functions; every function needs to know the boundaries
121 * within which they are allowed to draw.
122 *
123 * In order to aid in implementing a ctk-draw module, a text-based
124 * ctk-draw called ctk-conio has already been implemented. It conforms
125 * to the Borland conio C library, and a skeleton implementation of
126 * said library exists in lib/libconio.c. If a more machine specific
127 * ctk-draw module is to be implemented, the instructions in this file
128 * should be followed.
129 *
130 */
131
132/**
adamdunkelsb27d85a2003-09-01 22:23:26 +0000133 * The initialization function.
134 *
135 * This function is supposed to get the screen ready for drawing, and
136 * may be called at more than one time during the operation of the
137 * system.
138 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000139void ctk_draw_init(void);
140
adamdunkelsb27d85a2003-09-01 22:23:26 +0000141/**
142 * Clear the screen between the clip bounds.
143 *
144 * This function should clear the screen between the y coordinates
145 * "clipy1" and "clipy2", including the line at y coordinate "clipy1",
146 * but not the line at y coordinate "clipy2".
147 *
148 * \note This function may be used to draw a background image
149 * (wallpaper) on the desktop; it does not necessarily "clear" the
150 * screen.
151 *
152 * \param clipy1 The lower y coordinate of the clip region.
153 * \param clipy2 The upper y coordinate of the clip region.
154 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000155void ctk_draw_clear(unsigned char clipy1, unsigned char clipy2);
adamdunkelsb27d85a2003-09-01 22:23:26 +0000156
157/**
158 * Draw the window background.
159 *
160 * This function will be called by the CTK before a window will be
161 * completely redrawn.The function is supposed to draw the window
162 * background, excluding window borders as these should be drawn by
163 * the function that actually draws the window, between "clipy1" and
164 * "clipy2".
165 *
166 * \note This function does not necessarily have to clear the window -
167 * it can be used for drawing a background pattern in the window as
168 * well.
169 *
170 * \param window The window for which the background should be drawn.
171 *
172 * \param focus The focus of the window, either CTK_FOCUS_NONE for a
173 * background window, or CTK_FOCUS_WINDOW for the foreground window.
174 *
175 * \param clipy1 The lower y coordinate of the clip region.
176 * \param clipy2 The upper y coordinate of the clip region.
177*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000178void ctk_draw_clear_window(struct ctk_window *window,
179 unsigned char focus,
adamdunkelsb27d85a2003-09-01 22:23:26 +0000180 unsigned char clipy1,
181 unsigned char clipy2);
182/**
183 * Draw a window onto the screen.
184 *
185 * This function is called by the CTK when a window should be drawn on
186 * the screen. The ctk-draw layer is free to choose how the window
187 * will appear on screen; with or without window borders and the style
188 * of the borders, with or without transparent window background and
189 * how the background shall look, etc.
190 *
191 * \param window The window which is to be drawn.
192 *
193 * \param focus Specifies if the window should be drawn in foreground
194 * or background colors and can be either CTK_FOCUS_NONE or
195 * CTK_FOCUS_WINDOW. Windows with a focus of CTK_FOCUS_WINDOW is
196 * usually drawn in a brighter color than those with CTK_FOCUS_NONE.
197 *
198 * \param clipy1 Specifies the first lines on screen that actually
199 * should be drawn, in screen coordinates (line 1 is the first line
200 * below the menus).
201 *
202 * \param clipy2 Specifies the last + 1 line on screen that should be
203 * drawn, in screen coordinates (line 1 is the first line below the
204 * menus)
205 *
206 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000207void ctk_draw_window(struct ctk_window *window,
208 unsigned char focus,
209 unsigned char clipy1,
oliverschmidtadf27db2005-03-15 15:51:17 +0000210 unsigned char clipy2,
211 unsigned char draw_borders);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000212
adamdunkelsb27d85a2003-09-01 22:23:26 +0000213
214/**
215 * Draw a dialog onto the screen.
216 *
217 * In CTK, a dialog is similar to a window, with the only exception
218 * being that they are drawn in a different style. Also, since dialogs
219 * always are drawn on top of everything else, they do not need to be
220 * drawn within any special boundaries.
221 *
222 * \note This function can usually be implemented so that it uses the
223 * same widget drawing code as the ctk_draw_window() function.
224 *
225 * \param dialog The dialog that is to be drawn.
226 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000227void ctk_draw_dialog(struct ctk_window *dialog);
228
adamdunkelsb27d85a2003-09-01 22:23:26 +0000229/**
230 * Draw a widget on a window.
231 *
232 * This function is used for drawing a CTK widgets onto the screem is
233 * likely to be the most complex function in the ctk-draw
234 * module. Still, it is straightforward to implement as it can be
235 * written in an incremental fashion, starting with a single widget
236 * type and adding more widget types, one at a time.
237
238 * The ctk-draw module may exploit how the CTK focus constants are
239 * defined in order to use a look-up table for the colors. The CTK
240 * focus constants are defined in the file ctk/ctk.h as follows:
241 \code
242 #define CTK_FOCUS_NONE 0
243 #define CTK_FOCUS_WIDGET 1
244 #define CTK_FOCUS_WINDOW 2
245 #define CTK_FOCUS_DIALOG 4
246 \endcode
247
248 * This gives the following table:
249 \code
250 0: CTK_FOCUS_NONE (Background window, non-focused widget)
251 1: CTK_FOCUS_WIDGET (Background window, focused widget)
252 2: CTK_FOCUS_WINDOW (Foreground window, non-focused widget)
253 3: CTK_FOCUS_WINDOW | CTK_FOCUS_WIDGET
254 (Foreground window, focused widget)
255 4: CTK_FOCUS_DIALOG (Dialog, non-focused widget)
256 5: CTK_FOCUS_DIALOG | CTK_FOCUS_WIDGET
257 (Dialog, focused widget)
258 \endcode
259
260
261 * \param w The widget to be drawn.
262 * \param focus The focus of the widget.
263 * \param clipy1 The lower y coordinate of the clip region.
264 * \param clipy2 The upper y coordinate of the clip region.
265 */
266
267void ctk_draw_widget(struct ctk_widget *w,
268 unsigned char focus,
269 unsigned char clipy1,
270 unsigned char clipy2);
271
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000272void ctk_draw_menus(struct ctk_menus *menus);
273
274
275
276/* Returns width and height of screen. */
277unsigned char ctk_draw_width(void);
278unsigned char ctk_draw_height(void);
279
280
adamdunkels6c168982004-07-04 11:40:04 +0000281extern unsigned char ctk_draw_windowborder_width,
282 ctk_draw_windowborder_height,
283 ctk_draw_windowtitle_height;
284
adamdunkelse937ded2003-10-01 07:53:57 +0000285
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000286#endif /* __CTK_DRAW_H__ */
adamdunkelse937ded2003-10-01 07:53:57 +0000287
288
289/**
290 * The keyboard character type of the system
291 *
292 * The ctk_arch_key_t is usually typedef'd to the char type, but some
293 * systems (such as VNC) have a 16-bit key type.
294 *
295 * \var typedef char ctk_arch_key_t;
296 */
297
298/**
299 * Get a keypress from the keyboard input queue.
300 *
301 * This function will remove the first keypress in the keyboard input
302 * queue and return it. If the keyboard queue is empty, the return
303 * value is undefined. This function is intended to be used only after
304 * the ctk_arch_keyavail() function has returned non-zero.
305 *
306 * \return The first keypress from the keyboard input queue.
307 *
308 * \fn ctk_arch_key_t ctk_arch_getkey(void);
309 */
310
311/**
312 * Check if there is a keypress in the keyboard input queue.
313 *
314 * \return Zero if the keyboard input queue is empty, non-zero
315 * otherwise.
316 *
317 * \fn unsigned char ctk_arch_keyavail(void);
318 */
319
320/**
321 * The character used for the Return/Enter key.
322 *
323 * \define #define CH_ENTER '\n'
324 */
325
326/**
327 * \page ctk-arch The ctk-arch module
328 *
329 * The ctk-arch module deals with keyboard input from the underlying
330 * target system on which Contiki is running. The ctk-arch manages a
331 * keyboard input queue that is queried using the two functions
332 * ctk_arch_keyavail() and ctk_arch_getkey().
333 */
adamdunkels6c168982004-07-04 11:40:04 +0000334
adamdunkelse937ded2003-10-01 07:53:57 +0000335/** @} */
336/** @} */