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  * \param draw_borders The border style
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 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 /** @} */
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
Representation of the menu bar.
Definition: ctk.h:611
void ctk_draw_clear(unsigned char clipy1, unsigned char clipy2)
Clear the screen between the clip bounds.
Definition: ctk-conio.c:441
CTK header file.
Representation of a CTK window.
Definition: ctk.h:506
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.
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