adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 1 | /** |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 2 | * \addtogroup ctk |
| 3 | * @{ |
| 4 | */ |
| 5 | |
| 6 | /** |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 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 | * |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 17 | /* |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 18 | * Copyright (c) 2002-2003, Adam Dunkels. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 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. |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 30 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 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 | * |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 46 | * This file is part of the Contiki desktop OS. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 47 | * |
adamdunkels | 6c16898 | 2004-07-04 11:40:04 +0000 | [diff] [blame^] | 48 | * $Id: ctk-draw.h,v 1.6 2004/07/04 11:40:04 adamdunkels Exp $ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 49 | * |
| 50 | */ |
| 51 | |
| 52 | #ifndef __CTK_DRAW_H__ |
| 53 | #define __CTK_DRAW_H__ |
| 54 | |
| 55 | #include "ctk.h" |
| 56 | |
| 57 | #include "ctk-arch.h" |
| 58 | |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 59 | /** |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 60 | * \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 | /** |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 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 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 137 | void ctk_draw_init(void); |
| 138 | |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 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 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 153 | void ctk_draw_clear(unsigned char clipy1, unsigned char clipy2); |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 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 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 176 | void ctk_draw_clear_window(struct ctk_window *window, |
| 177 | unsigned char focus, |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 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 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 205 | void ctk_draw_window(struct ctk_window *window, |
| 206 | unsigned char focus, |
| 207 | unsigned char clipy1, |
| 208 | unsigned char clipy2); |
| 209 | |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 210 | |
| 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 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 224 | void ctk_draw_dialog(struct ctk_window *dialog); |
| 225 | |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame] | 226 | /** |
| 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 | |
| 264 | void ctk_draw_widget(struct ctk_widget *w, |
| 265 | unsigned char focus, |
| 266 | unsigned char clipy1, |
| 267 | unsigned char clipy2); |
| 268 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 269 | void ctk_draw_menus(struct ctk_menus *menus); |
| 270 | |
| 271 | |
| 272 | |
| 273 | /* Returns width and height of screen. */ |
| 274 | unsigned char ctk_draw_width(void); |
| 275 | unsigned char ctk_draw_height(void); |
| 276 | |
| 277 | |
adamdunkels | 6c16898 | 2004-07-04 11:40:04 +0000 | [diff] [blame^] | 278 | extern unsigned char ctk_draw_windowborder_width, |
| 279 | ctk_draw_windowborder_height, |
| 280 | ctk_draw_windowtitle_height; |
| 281 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 282 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 283 | #endif /* __CTK_DRAW_H__ */ |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 284 | |
| 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 | */ |
adamdunkels | 6c16898 | 2004-07-04 11:40:04 +0000 | [diff] [blame^] | 331 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 332 | /** @} */ |
| 333 | /** @} */ |