adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 1 | /** |
| 2 | * \file |
| 3 | * CTK screen drawing module interface, ctk-draw. |
| 4 | * \author Adam Dunkels <adam@dunkels.com> |
| 5 | * |
| 6 | * This file contains the interface for the ctk-draw module.The |
| 7 | * ctk-draw module takes care of the actual screen drawing for CTK by |
| 8 | * implementing a handful of functions that are called by CTK. |
| 9 | * |
| 10 | * The purpose of the ctk-arch and the ctk-draw is to act as an |
| 11 | * interface between the CTK and the actual hardware of the system on |
| 12 | * which Contiki is run. The ctk-arch takes care of the keyboard input |
| 13 | * from the user, and the ctk-draw is responsible for drawing the CTK |
| 14 | * desktop, windows and user interface widgets onto the actual screen. |
| 15 | * |
| 16 | * In order to aid in implementing a ctk-draw module, a text-based |
| 17 | * ctk-draw called ctk-conio has already been implemented. It conforms |
| 18 | * to the Borland conio C library, and a skeleton implementation of |
| 19 | * said library exists in lib/libconio.c. If a more machine specific |
| 20 | * ctk-draw module is to be implemented, the instructions in this file |
| 21 | * should be followed. |
| 22 | * |
| 23 | * In order to work efficiently even on limited systems, CTK uses a |
| 24 | * simple coordinate system, where the screen is addressed using |
| 25 | * character coordinates instead of pixel coordinates. This makes it |
| 26 | * trivial to implement the coordinate system on a text-based screen, |
| 27 | * and significantly reduces complexity for pixel based screen |
| 28 | * systems. |
| 29 | * |
| 30 | * The top left of the screen is (0,0) with x and y coordinates |
| 31 | * growing downwards and to the right. |
| 32 | * |
| 33 | * It is the responsibility of the ctk-draw module to keep track of |
| 34 | * the screen size and must implement the two functions |
| 35 | * ctk_draw_width() and ctk_draw_height(), which are used by the CTK |
| 36 | * for querying the screen size. The functions must return the width |
| 37 | * and the height of the ctk-draw screen in character coordinates. |
| 38 | * |
| 39 | * The ctk-draw module is responsible for drawing CTK windows onto the |
| 40 | * screen through the function ctk_draw_window().. A pseudo-code |
| 41 | * implementation of this function might look like this: |
| 42 | * \code |
| 43 | ctk_draw_window(window, focus, clipy1, clipy2) { |
| 44 | draw_window_borders(window, focus, clipy1, clipy2); |
| 45 | foreach(widget, window->inactive) { |
| 46 | draw_widget(widget, focus, clipy1, clipy2); |
| 47 | } |
| 48 | foreach(widget, window->active) { |
| 49 | if(widget == window->focused) { |
| 50 | draw_widget(widget, focus | CTK_FOCUS_WIDGET, |
| 51 | clipy1, clipy2); |
| 52 | } else { |
| 53 | draw_widget(widget, focus, clipy1, clipy2); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | \endcode |
| 59 | |
| 60 | * Where draw_window_borders() draws the window borders (also between |
| 61 | * clipy1 and clipy2). The draw_widget() function used may the same |
| 62 | * function as ctk_draw_widget() explained later. Notice how the |
| 63 | * clipy1 and clipy2 parameters are passed to all other functions; |
| 64 | * every function needs to know the boundaries within which they are |
| 65 | * allowed to draw. |
| 66 | */ |
| 67 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 68 | /* |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 69 | * Copyright (c) 2002-2003, Adam Dunkels. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 70 | * All rights reserved. |
| 71 | * |
| 72 | * Redistribution and use in source and binary forms, with or without |
| 73 | * modification, are permitted provided that the following conditions |
| 74 | * are met: |
| 75 | * 1. Redistributions of source code must retain the above copyright |
| 76 | * notice, this list of conditions and the following disclaimer. |
| 77 | * 2. Redistributions in binary form must reproduce the above |
| 78 | * copyright notice, this list of conditions and the following |
| 79 | * disclaimer in the documentation and/or other materials provided |
| 80 | * with the distribution. |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 81 | * 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] | 82 | * products derived from this software without specific prior |
| 83 | * written permission. |
| 84 | * |
| 85 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 86 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 87 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 88 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 89 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 90 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 91 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 92 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 93 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 94 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 95 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 96 | * |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 97 | * This file is part of the Contiki desktop OS. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 98 | * |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 99 | * $Id: ctk-draw.h,v 1.3 2003/09/01 22:23:26 adamdunkels Exp $ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 100 | * |
| 101 | */ |
| 102 | |
| 103 | #ifndef __CTK_DRAW_H__ |
| 104 | #define __CTK_DRAW_H__ |
| 105 | |
| 106 | #include "ctk.h" |
| 107 | |
| 108 | #include "ctk-arch.h" |
| 109 | |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 110 | /** |
| 111 | * The initialization function. |
| 112 | * |
| 113 | * This function is supposed to get the screen ready for drawing, and |
| 114 | * may be called at more than one time during the operation of the |
| 115 | * system. |
| 116 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 117 | void ctk_draw_init(void); |
| 118 | |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 119 | /** |
| 120 | * Clear the screen between the clip bounds. |
| 121 | * |
| 122 | * This function should clear the screen between the y coordinates |
| 123 | * "clipy1" and "clipy2", including the line at y coordinate "clipy1", |
| 124 | * but not the line at y coordinate "clipy2". |
| 125 | * |
| 126 | * \note This function may be used to draw a background image |
| 127 | * (wallpaper) on the desktop; it does not necessarily "clear" the |
| 128 | * screen. |
| 129 | * |
| 130 | * \param clipy1 The lower y coordinate of the clip region. |
| 131 | * \param clipy2 The upper y coordinate of the clip region. |
| 132 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 133 | void ctk_draw_clear(unsigned char clipy1, unsigned char clipy2); |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 134 | |
| 135 | /** |
| 136 | * Draw the window background. |
| 137 | * |
| 138 | * This function will be called by the CTK before a window will be |
| 139 | * completely redrawn.The function is supposed to draw the window |
| 140 | * background, excluding window borders as these should be drawn by |
| 141 | * the function that actually draws the window, between "clipy1" and |
| 142 | * "clipy2". |
| 143 | * |
| 144 | * \note This function does not necessarily have to clear the window - |
| 145 | * it can be used for drawing a background pattern in the window as |
| 146 | * well. |
| 147 | * |
| 148 | * \param window The window for which the background should be drawn. |
| 149 | * |
| 150 | * \param focus The focus of the window, either CTK_FOCUS_NONE for a |
| 151 | * background window, or CTK_FOCUS_WINDOW for the foreground window. |
| 152 | * |
| 153 | * \param clipy1 The lower y coordinate of the clip region. |
| 154 | * \param clipy2 The upper y coordinate of the clip region. |
| 155 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 156 | void ctk_draw_clear_window(struct ctk_window *window, |
| 157 | unsigned char focus, |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 158 | unsigned char clipy1, |
| 159 | unsigned char clipy2); |
| 160 | /** |
| 161 | * Draw a window onto the screen. |
| 162 | * |
| 163 | * This function is called by the CTK when a window should be drawn on |
| 164 | * the screen. The ctk-draw layer is free to choose how the window |
| 165 | * will appear on screen; with or without window borders and the style |
| 166 | * of the borders, with or without transparent window background and |
| 167 | * how the background shall look, etc. |
| 168 | * |
| 169 | * \param window The window which is to be drawn. |
| 170 | * |
| 171 | * \param focus Specifies if the window should be drawn in foreground |
| 172 | * or background colors and can be either CTK_FOCUS_NONE or |
| 173 | * CTK_FOCUS_WINDOW. Windows with a focus of CTK_FOCUS_WINDOW is |
| 174 | * usually drawn in a brighter color than those with CTK_FOCUS_NONE. |
| 175 | * |
| 176 | * \param clipy1 Specifies the first lines on screen that actually |
| 177 | * should be drawn, in screen coordinates (line 1 is the first line |
| 178 | * below the menus). |
| 179 | * |
| 180 | * \param clipy2 Specifies the last + 1 line on screen that should be |
| 181 | * drawn, in screen coordinates (line 1 is the first line below the |
| 182 | * menus) |
| 183 | * |
| 184 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 185 | void ctk_draw_window(struct ctk_window *window, |
| 186 | unsigned char focus, |
| 187 | unsigned char clipy1, |
| 188 | unsigned char clipy2); |
| 189 | |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 190 | |
| 191 | /** |
| 192 | * Draw a dialog onto the screen. |
| 193 | * |
| 194 | * In CTK, a dialog is similar to a window, with the only exception |
| 195 | * being that they are drawn in a different style. Also, since dialogs |
| 196 | * always are drawn on top of everything else, they do not need to be |
| 197 | * drawn within any special boundaries. |
| 198 | * |
| 199 | * \note This function can usually be implemented so that it uses the |
| 200 | * same widget drawing code as the ctk_draw_window() function. |
| 201 | * |
| 202 | * \param dialog The dialog that is to be drawn. |
| 203 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 204 | void ctk_draw_dialog(struct ctk_window *dialog); |
| 205 | |
adamdunkels | b27d85a | 2003-09-01 22:23:26 +0000 | [diff] [blame^] | 206 | /** |
| 207 | * Draw a widget on a window. |
| 208 | * |
| 209 | * This function is used for drawing a CTK widgets onto the screem is |
| 210 | * likely to be the most complex function in the ctk-draw |
| 211 | * module. Still, it is straightforward to implement as it can be |
| 212 | * written in an incremental fashion, starting with a single widget |
| 213 | * type and adding more widget types, one at a time. |
| 214 | |
| 215 | * The ctk-draw module may exploit how the CTK focus constants are |
| 216 | * defined in order to use a look-up table for the colors. The CTK |
| 217 | * focus constants are defined in the file ctk/ctk.h as follows: |
| 218 | \code |
| 219 | #define CTK_FOCUS_NONE 0 |
| 220 | #define CTK_FOCUS_WIDGET 1 |
| 221 | #define CTK_FOCUS_WINDOW 2 |
| 222 | #define CTK_FOCUS_DIALOG 4 |
| 223 | \endcode |
| 224 | |
| 225 | * This gives the following table: |
| 226 | \code |
| 227 | 0: CTK_FOCUS_NONE (Background window, non-focused widget) |
| 228 | 1: CTK_FOCUS_WIDGET (Background window, focused widget) |
| 229 | 2: CTK_FOCUS_WINDOW (Foreground window, non-focused widget) |
| 230 | 3: CTK_FOCUS_WINDOW | CTK_FOCUS_WIDGET |
| 231 | (Foreground window, focused widget) |
| 232 | 4: CTK_FOCUS_DIALOG (Dialog, non-focused widget) |
| 233 | 5: CTK_FOCUS_DIALOG | CTK_FOCUS_WIDGET |
| 234 | (Dialog, focused widget) |
| 235 | \endcode |
| 236 | |
| 237 | |
| 238 | * \param w The widget to be drawn. |
| 239 | * \param focus The focus of the widget. |
| 240 | * \param clipy1 The lower y coordinate of the clip region. |
| 241 | * \param clipy2 The upper y coordinate of the clip region. |
| 242 | */ |
| 243 | |
| 244 | void ctk_draw_widget(struct ctk_widget *w, |
| 245 | unsigned char focus, |
| 246 | unsigned char clipy1, |
| 247 | unsigned char clipy2); |
| 248 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 249 | void ctk_draw_menus(struct ctk_menus *menus); |
| 250 | |
| 251 | |
| 252 | |
| 253 | /* Returns width and height of screen. */ |
| 254 | unsigned char ctk_draw_width(void); |
| 255 | unsigned char ctk_draw_height(void); |
| 256 | |
| 257 | |
| 258 | #endif /* __CTK_DRAW_H__ */ |