Contiki 3.x
ctk-draw.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2003, Adam Dunkels.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following
12  * disclaimer in the documentation and/or other materials provided
13  * with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  * products derived from this software without specific prior
16  * written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * This file is part of the Contiki desktop OS.
31  *
32  *
33  */
34 
35 /**
36  * \addtogroup ctk
37  * @{
38  */
39 
40 /**
41  * \file
42  * CTK screen drawing module interface, ctk-draw.
43  * \author Adam Dunkels <adam@dunkels.com>
44  *
45  * This file contains the interface for the ctk-draw module.The
46  * ctk-draw module takes care of the actual screen drawing for CTK by
47  * implementing a handful of functions that are called by CTK.
48  *
49  */
50 
51 #ifndef CTK_DRAW_H_
52 #define CTK_DRAW_H_
53 
54 #include "ctk/ctk.h"
55 #include "contiki-conf.h"
56 
57 /**
58  * \defgroup ctkdraw CTK device driver functions
59  * @{
60  *
61  * The CTK device driver functions are divided into two modules, the
62  * ctk-draw module and the ctk-arch module. The purpose of the
63  * ctk-arch and the ctk-draw modules is to act as an interface between
64  * the CTK and the actual hardware of the system on which Contiki is
65  * run. The ctk-arch takes care of the keyboard input from the user,
66  * and the ctk-draw is responsible for drawing the CTK desktop,
67  * windows and user interface widgets onto the actual screen.
68  *
69  * More information about the ctk-draw and the ctk-arch modules can be
70  * found in the sections \ref ctk-draw and \ref ctk-arch.
71  */
72 
73 /**
74  * \page ctk-draw The ctk-draw module
75  *
76  * In order to work efficiently even on limited systems, CTK uses a
77  * simple coordinate system, where the screen is addressed using
78  * character coordinates instead of pixel coordinates. This makes it
79  * trivial to implement the coordinate system on a text-based screen,
80  * and significantly reduces complexity for pixel based screen
81  * systems.
82  *
83  * The top left of the screen is (0,0) with x and y coordinates
84  * growing downwards and to the right.
85  *
86  * It is the responsibility of the ctk-draw module to keep track of
87  * the screen size and must implement the two functions
88  * ctk_draw_width() and ctk_draw_height(), which are used by the CTK
89  * for querying the screen size. The functions must return the width
90  * and the height of the ctk-draw screen in character coordinates.
91  *
92  * The ctk-draw module is responsible for drawing CTK windows onto the
93  * screen through the function ctk_draw_window().. A pseudo-code
94  * implementation of this function might look like this:
95  * \code
96  ctk_draw_window(window, focus, clipy1, clipy2, draw_borders) {
97  if(draw_borders) {
98  draw_window_borders(window, focus, clipy1, clipy2);
99  }
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 /**
131  * 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  */
137 void ctk_draw_init(void);
138 
139 /**
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  */
153 void ctk_draw_clear(unsigned char clipy1, unsigned char clipy2);
154 
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 */
176 void ctk_draw_clear_window(struct ctk_window *window,
177  unsigned char focus,
178  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  */
205 void ctk_draw_window(struct ctk_window *window,
206  unsigned char focus,
207  unsigned char clipy1,
208  unsigned char clipy2,
209  unsigned char draw_borders);
210 
211 
212 /**
213  * Draw a dialog onto the screen.
214  *
215  * In CTK, a dialog is similar to a window, with the only exception
216  * being that they are drawn in a different style. Also, since dialogs
217  * always are drawn on top of everything else, they do not need to be
218  * drawn within any special boundaries.
219  *
220  * \note This function can usually be implemented so that it uses the
221  * same widget drawing code as the ctk_draw_window() function.
222  *
223  * \param dialog The dialog that is to be drawn.
224  */
225 void ctk_draw_dialog(struct ctk_window *dialog);
226 
227 /**
228  * Draw a widget on a window.
229  *
230  * This function is used for drawing a CTK widgets onto the screem is
231  * likely to be the most complex function in the ctk-draw
232  * module. Still, it is straightforward to implement as it can be
233  * written in an incremental fashion, starting with a single widget
234  * type and adding more widget types, one at a time.
235 
236  * The ctk-draw module may exploit how the CTK focus constants are
237  * defined in order to use a look-up table for the colors. The CTK
238  * focus constants are defined in the file ctk/ctk.h as follows:
239  \code
240  #define CTK_FOCUS_NONE 0
241  #define CTK_FOCUS_WIDGET 1
242  #define CTK_FOCUS_WINDOW 2
243  #define CTK_FOCUS_DIALOG 4
244  \endcode
245 
246  * This gives the following table:
247  \code
248  0: CTK_FOCUS_NONE (Background window, non-focused widget)
249  1: CTK_FOCUS_WIDGET (Background window, focused widget)
250  2: CTK_FOCUS_WINDOW (Foreground window, non-focused widget)
251  3: CTK_FOCUS_WINDOW | CTK_FOCUS_WIDGET
252  (Foreground window, focused widget)
253  4: CTK_FOCUS_DIALOG (Dialog, non-focused widget)
254  5: CTK_FOCUS_DIALOG | CTK_FOCUS_WIDGET
255  (Dialog, focused widget)
256  \endcode
257 
258 
259  * \param w The widget to be drawn.
260  * \param focus The focus of the widget.
261  * \param clipy1 The lower y coordinate of the clip region.
262  * \param clipy2 The upper y coordinate of the clip region.
263  */
264 
265 void ctk_draw_widget(struct ctk_widget *w,
266  unsigned char focus,
267  unsigned char clipy1,
268  unsigned char clipy2);
269 
270 void ctk_draw_menus(struct ctk_menus *menus);
271 
272 
273 
274 /* Returns width and height of screen. */
275 CCIF unsigned char ctk_draw_width(void);
276 CCIF unsigned char ctk_draw_height(void);
277 
278 
279 extern unsigned char ctk_draw_windowborder_width,
280  ctk_draw_windowborder_height,
281  ctk_draw_windowtitle_height;
282 
283 
284 #endif /* CTK_DRAW_H_ */
285 
286 
287 /**
288  * The keyboard character type of the system
289  *
290  * The ctk_arch_key_t is usually typedef'd to the char type, but some
291  * systems (such as VNC) have a 16-bit key type.
292  *
293  * \var typedef char ctk_arch_key_t;
294  */
295 
296 /**
297  * Get a keypress from the keyboard input queue.
298  *
299  * This function will remove the first keypress in the keyboard input
300  * queue and return it. If the keyboard queue is empty, the return
301  * value is undefined. This function is intended to be used only after
302  * the ctk_arch_keyavail() function has returned non-zero.
303  *
304  * \return The first keypress from the keyboard input queue.
305  *
306  * \fn ctk_arch_key_t ctk_arch_getkey(void);
307  */
308 
309 /**
310  * Check if there is a keypress in the keyboard input queue.
311  *
312  * \return Zero if the keyboard input queue is empty, non-zero
313  * otherwise.
314  *
315  * \fn unsigned char ctk_arch_keyavail(void);
316  */
317 
318 /**
319  * The character used for the Return/Enter key.
320  *
321  * \define #define CH_ENTER '\n'
322  */
323 
324 /**
325  * \page ctk-arch The ctk-arch module
326  *
327  * The ctk-arch module deals with keyboard input from the underlying
328  * target system on which Contiki is running. The ctk-arch manages a
329  * keyboard input queue that is queried using the two functions
330  * ctk_arch_keyavail() and ctk_arch_getkey().
331  */
332 
333 /** @} */
334 /** @} */
Representation of the menu bar.
Definition: ctk.h:611
void ctk_draw_clear(unsigned char y1, unsigned char y2)
Clear the screen between the clip bounds.
Definition: ctk-conio.c:441
void ctk_draw_widget(struct ctk_widget *w, unsigned char focus, unsigned char clipy1, unsigned char clipy2)
Draw a widget on a window.
Definition: ctk-conio.c:239
void ctk_draw_window(struct ctk_window *window, unsigned char focus, unsigned char clipy1, unsigned char clipy2, unsigned char draw_borders)
Draw a window onto the screen.
Definition: ctk-conio.c:327
void ctk_draw_init(void)
The initialization function.
Definition: ctk-conio.c:74
void ctk_draw_dialog(struct ctk_window *dialog)
Draw a dialog onto the screen.
Representation of a CTK window.
Definition: ctk.h:506
void ctk_draw_clear_window(struct ctk_window *window, unsigned char focus, unsigned char clipy1, unsigned char clipy2)
Draw the window background.
Definition: ctk-conio.c:265
The generic CTK widget structure that contains all other widget structures.
Definition: ctk.h:444
CTK header file.