Contiki 2.5
ctk-draw.h
Go to the documentation of this file.
1 /**
2  * \addtogroup ctk
3  * @{
4  */
5 
6 /**
7  * \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  *
15  */
16 
17 /*
18  * Copyright (c) 2002-2003, Adam Dunkels.
19  * 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.
30  * 3. The name of the author may not be used to endorse or promote
31  * 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  *
46  * This file is part of the Contiki desktop OS.
47  *
48  * $Id: ctk-draw.h,v 1.2 2006/08/26 23:56:18 oliverschmidt Exp $
49  *
50  */
51 
52 #ifndef __CTK_DRAW_H__
53 #define __CTK_DRAW_H__
54 
55 #include "ctk/ctk.h"
56 #include "contiki-conf.h"
57 
58 /**
59  * \defgroup ctkdraw CTK device driver functions
60  * @{
61  *
62  * The CTK device driver functions are divided into two modules, the
63  * ctk-draw module and the ctk-arch module. The purpose of the
64  * ctk-arch and the ctk-draw modules is to act as an interface between
65  * the CTK and the actual hardware of the system on which Contiki is
66  * run. The ctk-arch takes care of the keyboard input from the user,
67  * and the ctk-draw is responsible for drawing the CTK desktop,
68  * windows and user interface widgets onto the actual screen.
69  *
70  * More information about the ctk-draw and the ctk-arch modules can be
71  * found in the sections \ref ctk-draw and \ref ctk-arch.
72  */
73 
74 /**
75  * \page ctk-draw The ctk-draw module
76  *
77  * In order to work efficiently even on limited systems, CTK uses a
78  * simple coordinate system, where the screen is addressed using
79  * character coordinates instead of pixel coordinates. This makes it
80  * trivial to implement the coordinate system on a text-based screen,
81  * and significantly reduces complexity for pixel based screen
82  * systems.
83  *
84  * The top left of the screen is (0,0) with x and y coordinates
85  * growing downwards and to the right.
86  *
87  * It is the responsibility of the ctk-draw module to keep track of
88  * the screen size and must implement the two functions
89  * ctk_draw_width() and ctk_draw_height(), which are used by the CTK
90  * for querying the screen size. The functions must return the width
91  * and the height of the ctk-draw screen in character coordinates.
92  *
93  * The ctk-draw module is responsible for drawing CTK windows onto the
94  * screen through the function ctk_draw_window().. A pseudo-code
95  * implementation of this function might look like this:
96  * \code
97  ctk_draw_window(window, focus, clipy1, clipy2, draw_borders) {
98  if(draw_borders) {
99  draw_window_borders(window, focus, clipy1, clipy2);
100  }
101  foreach(widget, window->inactive) {
102  ctk_draw_widget(widget, focus, clipy1, clipy2);
103  }
104  foreach(widget, window->active) {
105  if(widget == window->focused) {
106  ctk_draw_widget(widget, focus | CTK_FOCUS_WIDGET,
107  clipy1, clipy2);
108  } else {
109  ctk_draw_widget(widget, focus, clipy1, clipy2);
110  }
111  }
112  }
113 
114  \endcode
115  *
116  * Where draw_window_borders() draws the window borders (also between
117  * clipy1 and clipy2). The ctk_draw_widget() function is explained
118  * below. Notice how the clipy1 and clipy2 parameters are passed to
119  * all other functions; every function needs to know the boundaries
120  * within which they are allowed to draw.
121  *
122  * In order to aid in implementing a ctk-draw module, a text-based
123  * ctk-draw called ctk-conio has already been implemented. It conforms
124  * to the Borland conio C library, and a skeleton implementation of
125  * said library exists in lib/libconio.c. If a more machine specific
126  * ctk-draw module is to be implemented, the instructions in this file
127  * should be followed.
128  *
129  */
130 
131 /**
132  * The initialization function.
133  *
134  * This function is supposed to get the screen ready for drawing, and
135  * may be called at more than one time during the operation of the
136  * system.
137  */
138 void ctk_draw_init(void);
139 
140 /**
141  * Clear the screen between the clip bounds.
142  *
143  * This function should clear the screen between the y coordinates
144  * "clipy1" and "clipy2", including the line at y coordinate "clipy1",
145  * but not the line at y coordinate "clipy2".
146  *
147  * \note This function may be used to draw a background image
148  * (wallpaper) on the desktop; it does not necessarily "clear" the
149  * screen.
150  *
151  * \param clipy1 The lower y coordinate of the clip region.
152  * \param clipy2 The upper y coordinate of the clip region.
153  */
154 void ctk_draw_clear(unsigned char clipy1, unsigned char clipy2);
155 
156 /**
157  * Draw the window background.
158  *
159  * This function will be called by the CTK before a window will be
160  * completely redrawn.The function is supposed to draw the window
161  * background, excluding window borders as these should be drawn by
162  * the function that actually draws the window, between "clipy1" and
163  * "clipy2".
164  *
165  * \note This function does not necessarily have to clear the window -
166  * it can be used for drawing a background pattern in the window as
167  * well.
168  *
169  * \param window The window for which the background should be drawn.
170  *
171  * \param focus The focus of the window, either CTK_FOCUS_NONE for a
172  * background window, or CTK_FOCUS_WINDOW for the foreground window.
173  *
174  * \param clipy1 The lower y coordinate of the clip region.
175  * \param clipy2 The upper y coordinate of the clip region.
176 */
177 void ctk_draw_clear_window(struct ctk_window *window,
178  unsigned char focus,
179  unsigned char clipy1,
180  unsigned char clipy2);
181 /**
182  * Draw a window onto the screen.
183  *
184  * This function is called by the CTK when a window should be drawn on
185  * the screen. The ctk-draw layer is free to choose how the window
186  * will appear on screen; with or without window borders and the style
187  * of the borders, with or without transparent window background and
188  * how the background shall look, etc.
189  *
190  * \param window The window which is to be drawn.
191  *
192  * \param focus Specifies if the window should be drawn in foreground
193  * or background colors and can be either CTK_FOCUS_NONE or
194  * CTK_FOCUS_WINDOW. Windows with a focus of CTK_FOCUS_WINDOW is
195  * usually drawn in a brighter color than those with CTK_FOCUS_NONE.
196  *
197  * \param clipy1 Specifies the first lines on screen that actually
198  * should be drawn, in screen coordinates (line 1 is the first line
199  * below the menus).
200  *
201  * \param clipy2 Specifies the last + 1 line on screen that should be
202  * drawn, in screen coordinates (line 1 is the first line below the
203  * menus)
204  *
205  */
206 void ctk_draw_window(struct ctk_window *window,
207  unsigned char focus,
208  unsigned char clipy1,
209  unsigned char clipy2,
210  unsigned char draw_borders);
211 
212 
213 /**
214  * Draw a dialog onto the screen.
215  *
216  * In CTK, a dialog is similar to a window, with the only exception
217  * being that they are drawn in a different style. Also, since dialogs
218  * always are drawn on top of everything else, they do not need to be
219  * drawn within any special boundaries.
220  *
221  * \note This function can usually be implemented so that it uses the
222  * same widget drawing code as the ctk_draw_window() function.
223  *
224  * \param dialog The dialog that is to be drawn.
225  */
226 void ctk_draw_dialog(struct ctk_window *dialog);
227 
228 /**
229  * Draw a widget on a window.
230  *
231  * This function is used for drawing a CTK widgets onto the screem is
232  * likely to be the most complex function in the ctk-draw
233  * module. Still, it is straightforward to implement as it can be
234  * written in an incremental fashion, starting with a single widget
235  * type and adding more widget types, one at a time.
236 
237  * The ctk-draw module may exploit how the CTK focus constants are
238  * defined in order to use a look-up table for the colors. The CTK
239  * focus constants are defined in the file ctk/ctk.h as follows:
240  \code
241  #define CTK_FOCUS_NONE 0
242  #define CTK_FOCUS_WIDGET 1
243  #define CTK_FOCUS_WINDOW 2
244  #define CTK_FOCUS_DIALOG 4
245  \endcode
246 
247  * This gives the following table:
248  \code
249  0: CTK_FOCUS_NONE (Background window, non-focused widget)
250  1: CTK_FOCUS_WIDGET (Background window, focused widget)
251  2: CTK_FOCUS_WINDOW (Foreground window, non-focused widget)
252  3: CTK_FOCUS_WINDOW | CTK_FOCUS_WIDGET
253  (Foreground window, focused widget)
254  4: CTK_FOCUS_DIALOG (Dialog, non-focused widget)
255  5: CTK_FOCUS_DIALOG | CTK_FOCUS_WIDGET
256  (Dialog, focused widget)
257  \endcode
258 
259 
260  * \param w The widget to be drawn.
261  * \param focus The focus of the widget.
262  * \param clipy1 The lower y coordinate of the clip region.
263  * \param clipy2 The upper y coordinate of the clip region.
264  */
265 
266 void ctk_draw_widget(struct ctk_widget *w,
267  unsigned char focus,
268  unsigned char clipy1,
269  unsigned char clipy2);
270 
271 void ctk_draw_menus(struct ctk_menus *menus);
272 
273 
274 
275 /* Returns width and height of screen. */
276 CCIF unsigned char ctk_draw_width(void);
277 CCIF unsigned char ctk_draw_height(void);
278 
279 
280 extern unsigned char ctk_draw_windowborder_width,
281  ctk_draw_windowborder_height,
282  ctk_draw_windowtitle_height;
283 
284 
285 #endif /* __CTK_DRAW_H__ */
286 
287 
288 /**
289  * The keyboard character type of the system
290  *
291  * The ctk_arch_key_t is usually typedef'd to the char type, but some
292  * systems (such as VNC) have a 16-bit key type.
293  *
294  * \var typedef char ctk_arch_key_t;
295  */
296 
297 /**
298  * Get a keypress from the keyboard input queue.
299  *
300  * This function will remove the first keypress in the keyboard input
301  * queue and return it. If the keyboard queue is empty, the return
302  * value is undefined. This function is intended to be used only after
303  * the ctk_arch_keyavail() function has returned non-zero.
304  *
305  * \return The first keypress from the keyboard input queue.
306  *
307  * \fn ctk_arch_key_t ctk_arch_getkey(void);
308  */
309 
310 /**
311  * Check if there is a keypress in the keyboard input queue.
312  *
313  * \return Zero if the keyboard input queue is empty, non-zero
314  * otherwise.
315  *
316  * \fn unsigned char ctk_arch_keyavail(void);
317  */
318 
319 /**
320  * The character used for the Return/Enter key.
321  *
322  * \define #define CH_ENTER '\n'
323  */
324 
325 /**
326  * \page ctk-arch The ctk-arch module
327  *
328  * The ctk-arch module deals with keyboard input from the underlying
329  * target system on which Contiki is running. The ctk-arch manages a
330  * keyboard input queue that is queried using the two functions
331  * ctk_arch_keyavail() and ctk_arch_getkey().
332  */
333 
334 /** @} */
335 /** @} */