adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, 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. |
adamdunkels | 76a4c4a | 2004-06-06 05:52:21 +0000 | [diff] [blame] | 14 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 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 "ctk" console GUI toolkit for cc65 |
| 31 | * |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame^] | 32 | * $Id: ctk-conio.c,v 1.15 2004/08/12 21:52:03 oliverschmidt Exp $ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
adamdunkels | 09e2757 | 2004-03-25 09:50:13 +0000 | [diff] [blame] | 36 | #include <conio.h> |
| 37 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 38 | #include "ctk.h" |
| 39 | #include "ctk-draw.h" |
| 40 | |
| 41 | #include "ctk-conio-conf.h" |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 42 | #include <string.h> |
adamdunkels | ca2cbe5 | 2004-07-04 11:38:43 +0000 | [diff] [blame] | 43 | #include <ctype.h> |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 44 | |
| 45 | #ifndef NULL |
| 46 | #define NULL (void *)0 |
| 47 | #endif /* NULL */ |
| 48 | |
| 49 | static unsigned char sizex, sizey; |
| 50 | |
adamdunkels | ca2cbe5 | 2004-07-04 11:38:43 +0000 | [diff] [blame] | 51 | unsigned char ctk_draw_windowborder_height = 1; |
| 52 | unsigned char ctk_draw_windowborder_width = 1; |
| 53 | unsigned char ctk_draw_windowtitle_height = 1; |
| 54 | |
| 55 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 56 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 57 | static void |
| 58 | cputsn(char *str, unsigned char len) |
| 59 | { |
oliverschmidt | 4037b26 | 2004-06-27 20:59:05 +0000 | [diff] [blame] | 60 | char c; |
| 61 | |
| 62 | while(len > 0) { |
| 63 | --len; |
| 64 | c = *str; |
| 65 | if(c == 0) { |
| 66 | break; |
| 67 | } |
| 68 | cputc(c); |
| 69 | ++str; |
| 70 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 71 | } |
| 72 | /*-----------------------------------------------------------------------------------*/ |
| 73 | void |
| 74 | ctk_draw_init(void) |
| 75 | { |
| 76 | bgcolor(SCREENCOLOR); |
| 77 | bordercolor(BORDERCOLOR); |
| 78 | screensize(&sizex, &sizey); |
| 79 | ctk_draw_clear(0, sizey); |
| 80 | } |
| 81 | /*-----------------------------------------------------------------------------------*/ |
| 82 | static void |
| 83 | draw_widget(struct ctk_widget *w, |
| 84 | unsigned char x, unsigned char y, |
| 85 | unsigned char clipx, |
| 86 | unsigned char clipy, |
| 87 | unsigned char clipy1, unsigned char clipy2, |
| 88 | unsigned char focus) |
| 89 | { |
| 90 | unsigned char xpos, ypos, xscroll; |
| 91 | unsigned char i, j; |
| 92 | char c, *text; |
adamdunkels | 09e2757 | 2004-03-25 09:50:13 +0000 | [diff] [blame] | 93 | unsigned char len, wfocus; |
| 94 | |
| 95 | wfocus = 0; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 96 | if(focus & CTK_FOCUS_WINDOW) { |
| 97 | textcolor(WIDGETCOLOR_FWIN); |
| 98 | if(focus & CTK_FOCUS_WIDGET) { |
| 99 | textcolor(WIDGETCOLOR_FOCUS); |
adamdunkels | 09e2757 | 2004-03-25 09:50:13 +0000 | [diff] [blame] | 100 | wfocus = 1; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 101 | } |
| 102 | } else if(focus & CTK_FOCUS_DIALOG) { |
| 103 | textcolor(WIDGETCOLOR_DIALOG); |
| 104 | if(focus & CTK_FOCUS_WIDGET) { |
| 105 | textcolor(WIDGETCOLOR_FOCUS); |
adamdunkels | 09e2757 | 2004-03-25 09:50:13 +0000 | [diff] [blame] | 106 | wfocus = 1; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 107 | } |
| 108 | } else { |
| 109 | textcolor(WIDGETCOLOR); |
| 110 | } |
| 111 | |
| 112 | xpos = x + w->x; |
| 113 | ypos = y + w->y; |
| 114 | |
| 115 | switch(w->type) { |
| 116 | case CTK_WIDGET_SEPARATOR: |
| 117 | if(ypos >= clipy1 && ypos < clipy2) { |
| 118 | chlinexy(xpos, ypos, w->w); |
| 119 | } |
| 120 | break; |
| 121 | case CTK_WIDGET_LABEL: |
| 122 | text = w->widget.label.text; |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 123 | for(i = 0; i < w->h; ++i) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 124 | if(ypos >= clipy1 && ypos < clipy2) { |
| 125 | gotoxy(xpos, ypos); |
| 126 | cputsn(text, w->w); |
| 127 | if(w->w - (wherex() - xpos) > 0) { |
| 128 | cclear(w->w - (wherex() - xpos)); |
| 129 | } |
| 130 | } |
| 131 | ++ypos; |
| 132 | text += w->w; |
| 133 | } |
| 134 | break; |
| 135 | case CTK_WIDGET_BUTTON: |
| 136 | if(ypos >= clipy1 && ypos < clipy2) { |
adamdunkels | 09e2757 | 2004-03-25 09:50:13 +0000 | [diff] [blame] | 137 | if(wfocus != 0) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 138 | revers(1); |
| 139 | } else { |
| 140 | revers(0); |
| 141 | } |
| 142 | cputcxy(xpos, ypos, '['); |
| 143 | cputsn(w->widget.button.text, w->w); |
| 144 | cputc(']'); |
| 145 | revers(0); |
| 146 | } |
| 147 | break; |
| 148 | case CTK_WIDGET_HYPERLINK: |
| 149 | if(ypos >= clipy1 && ypos < clipy2) { |
adamdunkels | 09e2757 | 2004-03-25 09:50:13 +0000 | [diff] [blame] | 150 | if(wfocus != 0) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 151 | revers(0); |
| 152 | } else { |
| 153 | revers(1); |
| 154 | } |
| 155 | gotoxy(xpos, ypos); |
| 156 | textcolor(WIDGETCOLOR_HLINK); |
| 157 | cputsn(w->widget.button.text, w->w); |
| 158 | revers(0); |
| 159 | } |
| 160 | break; |
| 161 | case CTK_WIDGET_TEXTENTRY: |
| 162 | text = w->widget.textentry.text; |
adamdunkels | 09e2757 | 2004-03-25 09:50:13 +0000 | [diff] [blame] | 163 | if(wfocus != 0) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 164 | revers(1); |
| 165 | } else { |
| 166 | revers(0); |
| 167 | } |
| 168 | xscroll = 0; |
| 169 | if(w->widget.textentry.xpos >= w->w - 1) { |
| 170 | xscroll = w->widget.textentry.xpos - w->w + 1; |
| 171 | } |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 172 | for(j = 0; j < w->h; ++j) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 173 | if(ypos >= clipy1 && ypos < clipy2) { |
| 174 | if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && |
| 175 | w->widget.textentry.ypos == j) { |
| 176 | revers(0); |
| 177 | cputcxy(xpos, ypos, '>'); |
| 178 | for(i = 0; i < w->w; ++i) { |
| 179 | c = text[i + xscroll]; |
| 180 | if(i == w->widget.textentry.xpos - xscroll) { |
| 181 | revers(1); |
| 182 | } else { |
| 183 | revers(0); |
| 184 | } |
| 185 | if(c == 0) { |
| 186 | cputc(' '); |
| 187 | } else { |
| 188 | cputc(c); |
| 189 | } |
| 190 | revers(0); |
| 191 | } |
| 192 | cputc('<'); |
| 193 | } else { |
| 194 | cvlinexy(xpos, ypos, 1); |
| 195 | gotoxy(xpos + 1, ypos); |
| 196 | cputsn(text, w->w); |
| 197 | i = wherex(); |
| 198 | if(i - xpos - 1 < w->w) { |
| 199 | cclear(w->w - (i - xpos) + 1); |
| 200 | } |
| 201 | cvline(1); |
| 202 | } |
| 203 | } |
| 204 | ++ypos; |
| 205 | text += w->w; |
| 206 | } |
| 207 | revers(0); |
| 208 | break; |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 209 | #if CTK_CONF_ICONS |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 210 | case CTK_WIDGET_ICON: |
| 211 | if(ypos >= clipy1 && ypos < clipy2) { |
oliverschmidt | f42b7bc | 2004-06-27 15:04:01 +0000 | [diff] [blame] | 212 | if(wfocus != 0) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 213 | revers(1); |
| 214 | } else { |
| 215 | revers(0); |
| 216 | } |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 217 | #if CTK_CONF_ICON_TEXTMAPS |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 218 | if(w->widget.icon.textmap != NULL) { |
| 219 | for(i = 0; i < 3; ++i) { |
| 220 | gotoxy(xpos, ypos); |
| 221 | if(ypos >= clipy1 && ypos < clipy2) { |
| 222 | cputc(w->widget.icon.textmap[0 + 3 * i]); |
| 223 | cputc(w->widget.icon.textmap[1 + 3 * i]); |
| 224 | cputc(w->widget.icon.textmap[2 + 3 * i]); |
| 225 | } |
| 226 | ++ypos; |
| 227 | } |
| 228 | } |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 229 | #endif /* CTK_CONF_ICON_TEXTMAPS */ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 230 | |
| 231 | len = strlen(w->widget.icon.title); |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 232 | if(xpos + len >= sizex) { |
| 233 | xpos = sizex - len; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 234 | } |
| 235 | |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 236 | gotoxy(xpos, ypos); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 237 | if(ypos >= clipy1 && ypos < clipy2) { |
| 238 | cputs(w->widget.icon.title); |
| 239 | } |
| 240 | revers(0); |
| 241 | } |
| 242 | break; |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 243 | #endif /* CTK_CONF_ICONS */ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 244 | |
| 245 | default: |
| 246 | break; |
| 247 | } |
| 248 | } |
| 249 | /*-----------------------------------------------------------------------------------*/ |
| 250 | void |
| 251 | ctk_draw_widget(struct ctk_widget *w, |
| 252 | unsigned char focus, |
| 253 | unsigned char clipy1, |
| 254 | unsigned char clipy2) |
| 255 | { |
| 256 | struct ctk_window *win = w->window; |
| 257 | unsigned char posx, posy; |
| 258 | |
| 259 | posx = win->x + 1; |
| 260 | posy = win->y + 2; |
| 261 | |
| 262 | if(w == win->focused) { |
| 263 | focus |= CTK_FOCUS_WIDGET; |
| 264 | } |
| 265 | |
| 266 | draw_widget(w, posx, posy, |
| 267 | posx + win->w, |
| 268 | posy + win->h, |
| 269 | clipy1, clipy2, |
| 270 | focus); |
adamdunkels | fe32f8d | 2003-04-28 20:31:48 +0000 | [diff] [blame] | 271 | |
| 272 | #ifdef CTK_CONIO_CONF_UPDATE |
| 273 | CTK_CONIO_CONF_UPDATE(); |
| 274 | #endif /* CTK_CONIO_CONF_UPDATE */ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 275 | } |
| 276 | /*-----------------------------------------------------------------------------------*/ |
| 277 | void |
| 278 | ctk_draw_clear_window(struct ctk_window *window, |
| 279 | unsigned char focus, |
| 280 | unsigned char clipy1, |
| 281 | unsigned char clipy2) |
| 282 | { |
| 283 | unsigned char i; |
| 284 | unsigned char h; |
| 285 | |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame^] | 286 | if(focus & CTK_FOCUS_WINDOW) { |
| 287 | textcolor(WINDOWCOLOR_FOCUS); |
| 288 | } else { |
| 289 | textcolor(WINDOWCOLOR); |
| 290 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 291 | |
| 292 | h = window->y + 2 + window->h; |
| 293 | /* Clear window contents. */ |
| 294 | for(i = window->y + 2; i < h; ++i) { |
| 295 | if(i >= clipy1 && i < clipy2) { |
| 296 | cclearxy(window->x + 1, i, window->w); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 301 | static void |
| 302 | draw_window_contents(struct ctk_window *window, unsigned char focus, |
| 303 | unsigned char clipy1, unsigned char clipy2, |
| 304 | unsigned char x1, unsigned char x2, |
| 305 | unsigned char y1, unsigned char y2) |
| 306 | { |
| 307 | struct ctk_widget *w; |
| 308 | unsigned char wfocus; |
| 309 | |
| 310 | /* Draw inactive widgets. */ |
| 311 | for(w = window->inactive; w != NULL; w = w->next) { |
| 312 | draw_widget(w, x1, y1, x2, y2, |
| 313 | clipy1, clipy2, |
| 314 | focus); |
| 315 | } |
| 316 | |
| 317 | /* Draw active widgets. */ |
| 318 | for(w = window->active; w != NULL; w = w->next) { |
| 319 | wfocus = focus; |
| 320 | if(w == window->focused) { |
| 321 | wfocus |= CTK_FOCUS_WIDGET; |
| 322 | } |
| 323 | |
| 324 | draw_widget(w, x1, y1, x2, y2, |
| 325 | clipy1, clipy2, |
| 326 | wfocus); |
| 327 | } |
| 328 | |
adamdunkels | fe32f8d | 2003-04-28 20:31:48 +0000 | [diff] [blame] | 329 | #ifdef CTK_CONIO_CONF_UPDATE |
| 330 | CTK_CONIO_CONF_UPDATE(); |
| 331 | #endif /* CTK_CONIO_CONF_UPDATE */ |
| 332 | |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 333 | } |
| 334 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 335 | void |
| 336 | ctk_draw_window(struct ctk_window *window, unsigned char focus, |
| 337 | unsigned char clipy1, unsigned char clipy2) |
| 338 | { |
| 339 | unsigned char x, y; |
| 340 | unsigned char h; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 341 | unsigned char x1, y1, x2, y2; |
| 342 | |
| 343 | if(window->y + 1 >= clipy2) { |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | x = window->x; |
| 348 | y = window->y + 1; |
| 349 | |
| 350 | if(focus & CTK_FOCUS_WINDOW) { |
| 351 | textcolor(WINDOWCOLOR_FOCUS); |
| 352 | } else { |
| 353 | textcolor(WINDOWCOLOR); |
| 354 | } |
| 355 | |
| 356 | x1 = x + 1; |
| 357 | y1 = y + 1; |
| 358 | x2 = x1 + window->w; |
| 359 | y2 = y1 + window->h; |
| 360 | |
| 361 | /* Draw window frame. */ |
| 362 | if(y >= clipy1) { |
| 363 | cputcxy(x, y, CH_ULCORNER); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 364 | gotoxy(wherex() + window->titlelen + 2, wherey()); |
| 365 | chline(window->w - (wherex() - x) - 2); |
| 366 | cputcxy(x2, y, CH_URCORNER); |
| 367 | } |
| 368 | |
| 369 | h = window->h; |
| 370 | |
| 371 | if(clipy1 > y1) { |
| 372 | if(clipy1 - y1 < h) { |
| 373 | h = clipy1 - y1; |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 374 | y1 = clipy1; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 375 | } else { |
| 376 | h = 0; |
| 377 | } |
| 378 | } |
| 379 | |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 380 | if(clipy2 < y1 + h) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 381 | if(y1 >= clipy2) { |
| 382 | h = 0; |
| 383 | } else { |
| 384 | h = clipy2 - y1; |
| 385 | } |
| 386 | } |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 387 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 388 | cvlinexy(x, y1, h); |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 389 | cvlinexy(x2, y1, h); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 390 | |
| 391 | if(y + window->h >= clipy1 && |
| 392 | y + window->h < clipy2) { |
| 393 | cputcxy(x, y2, CH_LLCORNER); |
| 394 | chlinexy(x1, y2, window->w); |
| 395 | cputcxy(x2, y2, CH_LRCORNER); |
| 396 | } |
| 397 | |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 398 | draw_window_contents(window, focus & CTK_FOCUS_WINDOW, clipy1, clipy2, |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 399 | x1, x2, y + 1, y2); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 400 | } |
| 401 | /*-----------------------------------------------------------------------------------*/ |
| 402 | void |
| 403 | ctk_draw_dialog(struct ctk_window *dialog) |
| 404 | { |
| 405 | unsigned char x, y; |
| 406 | unsigned char i; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 407 | unsigned char x1, y1, x2, y2; |
| 408 | |
| 409 | textcolor(DIALOGCOLOR); |
| 410 | |
| 411 | x = dialog->x; |
| 412 | y = dialog->y + 1; |
| 413 | |
| 414 | |
| 415 | x1 = x + 1; |
| 416 | y1 = y + 1; |
| 417 | x2 = x1 + dialog->w; |
| 418 | y2 = y1 + dialog->h; |
| 419 | |
| 420 | |
| 421 | /* Draw dialog frame. */ |
| 422 | |
| 423 | cvlinexy(x, y1, |
| 424 | dialog->h); |
| 425 | cvlinexy(x2, y1, |
| 426 | dialog->h); |
| 427 | |
| 428 | chlinexy(x1, y, |
| 429 | dialog->w); |
| 430 | chlinexy(x1, y2, |
| 431 | dialog->w); |
| 432 | |
| 433 | cputcxy(x, y, CH_ULCORNER); |
| 434 | cputcxy(x, y2, CH_LLCORNER); |
| 435 | cputcxy(x2, y, CH_URCORNER); |
| 436 | cputcxy(x2, y2, CH_LRCORNER); |
| 437 | |
| 438 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 439 | /* Clear dialog contents. */ |
| 440 | for(i = y1; i < y2; ++i) { |
| 441 | cclearxy(x1, i, dialog->w); |
| 442 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 443 | |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 444 | draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, |
| 445 | x1, x2, y1, y2); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 446 | } |
| 447 | /*-----------------------------------------------------------------------------------*/ |
| 448 | void |
| 449 | ctk_draw_clear(unsigned char y1, unsigned char y2) |
| 450 | { |
| 451 | unsigned char i; |
| 452 | |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame^] | 453 | textcolor(BACKGROUNDCOLOR); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 454 | for(i = y1; i < y2; ++i) { |
| 455 | cclearxy(0, i, sizex); |
| 456 | } |
| 457 | } |
| 458 | /*-----------------------------------------------------------------------------------*/ |
| 459 | static void |
| 460 | draw_menu(struct ctk_menu *m) |
| 461 | { |
| 462 | unsigned char x, x2, y; |
| 463 | textcolor(OPENMENUCOLOR); |
oliverschmidt | d9a9107 | 2004-07-29 11:49:45 +0000 | [diff] [blame] | 464 | revers(0); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 465 | x = wherex(); |
| 466 | cputs(m->title); |
| 467 | cputc(' '); |
| 468 | x2 = wherex(); |
| 469 | if(x + CTK_CONF_MENUWIDTH > sizex) { |
| 470 | x = sizex - CTK_CONF_MENUWIDTH; |
| 471 | } |
| 472 | |
| 473 | |
| 474 | for(y = 0; y < m->nitems; ++y) { |
| 475 | if(y == m->active) { |
| 476 | textcolor(ACTIVEMENUITEMCOLOR); |
| 477 | revers(0); |
| 478 | } else { |
| 479 | textcolor(MENUCOLOR); |
oliverschmidt | d9a9107 | 2004-07-29 11:49:45 +0000 | [diff] [blame] | 480 | revers(1); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 481 | } |
| 482 | gotoxy(x, y + 1); |
| 483 | if(m->items[y].title[0] == '-') { |
| 484 | chline(CTK_CONF_MENUWIDTH); |
| 485 | } else { |
| 486 | cputs(m->items[y].title); |
| 487 | } |
| 488 | if(x + CTK_CONF_MENUWIDTH > wherex()) { |
| 489 | cclear(x + CTK_CONF_MENUWIDTH - wherex()); |
| 490 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 491 | } |
| 492 | gotoxy(x2, 0); |
| 493 | textcolor(MENUCOLOR); |
oliverschmidt | d9a9107 | 2004-07-29 11:49:45 +0000 | [diff] [blame] | 494 | revers(1); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 495 | } |
| 496 | /*-----------------------------------------------------------------------------------*/ |
| 497 | void |
| 498 | ctk_draw_menus(struct ctk_menus *menus) |
| 499 | { |
| 500 | struct ctk_menu *m; |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 501 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 502 | /* Draw menus */ |
| 503 | textcolor(MENUCOLOR); |
| 504 | gotoxy(0, 0); |
| 505 | revers(1); |
adamdunkels | e68091d | 2003-04-16 18:29:10 +0000 | [diff] [blame] | 506 | cputc(' '); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 507 | for(m = menus->menus->next; m != NULL; m = m->next) { |
| 508 | if(m != menus->open) { |
| 509 | cputs(m->title); |
| 510 | cputc(' '); |
| 511 | } else { |
| 512 | draw_menu(m); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | |
| 517 | if(wherex() + strlen(menus->desktopmenu->title) + 1>= sizex) { |
| 518 | gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); |
| 519 | } else { |
| 520 | cclear(sizex - wherex() - |
| 521 | strlen(menus->desktopmenu->title) - 1); |
| 522 | } |
| 523 | |
| 524 | /* Draw desktopmenu */ |
| 525 | if(menus->desktopmenu != menus->open) { |
| 526 | cputs(menus->desktopmenu->title); |
| 527 | cputc(' '); |
| 528 | } else { |
| 529 | draw_menu(menus->desktopmenu); |
| 530 | } |
| 531 | |
| 532 | revers(0); |
| 533 | } |
| 534 | /*-----------------------------------------------------------------------------------*/ |
| 535 | unsigned char |
| 536 | ctk_draw_height(void) |
| 537 | { |
| 538 | return sizey; |
| 539 | } |
| 540 | /*-----------------------------------------------------------------------------------*/ |
| 541 | unsigned char |
| 542 | ctk_draw_width(void) |
| 543 | { |
| 544 | return sizex; |
| 545 | } |
| 546 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca2cbe5 | 2004-07-04 11:38:43 +0000 | [diff] [blame] | 547 | int |
| 548 | ctk_arch_isprint(char c) |
| 549 | { |
| 550 | return isprint(c); |
| 551 | } |