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 | d9a9107 | 2004-07-29 11:49:45 +0000 | [diff] [blame^] | 32 | * $Id: ctk-conio.c,v 1.14 2004/07/29 11:49:45 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 | |
| 286 | |
| 287 | h = window->y + 2 + window->h; |
| 288 | /* Clear window contents. */ |
| 289 | for(i = window->y + 2; i < h; ++i) { |
| 290 | if(i >= clipy1 && i < clipy2) { |
| 291 | cclearxy(window->x + 1, i, window->w); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 296 | static void |
| 297 | draw_window_contents(struct ctk_window *window, unsigned char focus, |
| 298 | unsigned char clipy1, unsigned char clipy2, |
| 299 | unsigned char x1, unsigned char x2, |
| 300 | unsigned char y1, unsigned char y2) |
| 301 | { |
| 302 | struct ctk_widget *w; |
| 303 | unsigned char wfocus; |
| 304 | |
| 305 | /* Draw inactive widgets. */ |
| 306 | for(w = window->inactive; w != NULL; w = w->next) { |
| 307 | draw_widget(w, x1, y1, x2, y2, |
| 308 | clipy1, clipy2, |
| 309 | focus); |
| 310 | } |
| 311 | |
| 312 | /* Draw active widgets. */ |
| 313 | for(w = window->active; w != NULL; w = w->next) { |
| 314 | wfocus = focus; |
| 315 | if(w == window->focused) { |
| 316 | wfocus |= CTK_FOCUS_WIDGET; |
| 317 | } |
| 318 | |
| 319 | draw_widget(w, x1, y1, x2, y2, |
| 320 | clipy1, clipy2, |
| 321 | wfocus); |
| 322 | } |
| 323 | |
adamdunkels | fe32f8d | 2003-04-28 20:31:48 +0000 | [diff] [blame] | 324 | #ifdef CTK_CONIO_CONF_UPDATE |
| 325 | CTK_CONIO_CONF_UPDATE(); |
| 326 | #endif /* CTK_CONIO_CONF_UPDATE */ |
| 327 | |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 328 | } |
| 329 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 330 | void |
| 331 | ctk_draw_window(struct ctk_window *window, unsigned char focus, |
| 332 | unsigned char clipy1, unsigned char clipy2) |
| 333 | { |
| 334 | unsigned char x, y; |
| 335 | unsigned char h; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 336 | unsigned char x1, y1, x2, y2; |
| 337 | |
| 338 | if(window->y + 1 >= clipy2) { |
| 339 | return; |
| 340 | } |
| 341 | |
| 342 | x = window->x; |
| 343 | y = window->y + 1; |
| 344 | |
| 345 | if(focus & CTK_FOCUS_WINDOW) { |
| 346 | textcolor(WINDOWCOLOR_FOCUS); |
| 347 | } else { |
| 348 | textcolor(WINDOWCOLOR); |
| 349 | } |
| 350 | |
| 351 | x1 = x + 1; |
| 352 | y1 = y + 1; |
| 353 | x2 = x1 + window->w; |
| 354 | y2 = y1 + window->h; |
| 355 | |
| 356 | /* Draw window frame. */ |
| 357 | if(y >= clipy1) { |
| 358 | cputcxy(x, y, CH_ULCORNER); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 359 | gotoxy(wherex() + window->titlelen + 2, wherey()); |
| 360 | chline(window->w - (wherex() - x) - 2); |
| 361 | cputcxy(x2, y, CH_URCORNER); |
| 362 | } |
| 363 | |
| 364 | h = window->h; |
| 365 | |
| 366 | if(clipy1 > y1) { |
| 367 | if(clipy1 - y1 < h) { |
| 368 | h = clipy1 - y1; |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 369 | y1 = clipy1; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 370 | } else { |
| 371 | h = 0; |
| 372 | } |
| 373 | } |
| 374 | |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 375 | if(clipy2 < y1 + h) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 376 | if(y1 >= clipy2) { |
| 377 | h = 0; |
| 378 | } else { |
| 379 | h = clipy2 - y1; |
| 380 | } |
| 381 | } |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 382 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 383 | cvlinexy(x, y1, h); |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 384 | cvlinexy(x2, y1, h); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 385 | |
| 386 | if(y + window->h >= clipy1 && |
| 387 | y + window->h < clipy2) { |
| 388 | cputcxy(x, y2, CH_LLCORNER); |
| 389 | chlinexy(x1, y2, window->w); |
| 390 | cputcxy(x2, y2, CH_LRCORNER); |
| 391 | } |
| 392 | |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 393 | draw_window_contents(window, focus & CTK_FOCUS_WINDOW, clipy1, clipy2, |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 394 | x1, x2, y + 1, y2); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 395 | } |
| 396 | /*-----------------------------------------------------------------------------------*/ |
| 397 | void |
| 398 | ctk_draw_dialog(struct ctk_window *dialog) |
| 399 | { |
| 400 | unsigned char x, y; |
| 401 | unsigned char i; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 402 | unsigned char x1, y1, x2, y2; |
| 403 | |
| 404 | textcolor(DIALOGCOLOR); |
| 405 | |
| 406 | x = dialog->x; |
| 407 | y = dialog->y + 1; |
| 408 | |
| 409 | |
| 410 | x1 = x + 1; |
| 411 | y1 = y + 1; |
| 412 | x2 = x1 + dialog->w; |
| 413 | y2 = y1 + dialog->h; |
| 414 | |
| 415 | |
| 416 | /* Draw dialog frame. */ |
| 417 | |
| 418 | cvlinexy(x, y1, |
| 419 | dialog->h); |
| 420 | cvlinexy(x2, y1, |
| 421 | dialog->h); |
| 422 | |
| 423 | chlinexy(x1, y, |
| 424 | dialog->w); |
| 425 | chlinexy(x1, y2, |
| 426 | dialog->w); |
| 427 | |
| 428 | cputcxy(x, y, CH_ULCORNER); |
| 429 | cputcxy(x, y2, CH_LLCORNER); |
| 430 | cputcxy(x2, y, CH_URCORNER); |
| 431 | cputcxy(x2, y2, CH_LRCORNER); |
| 432 | |
| 433 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 434 | /* Clear dialog contents. */ |
| 435 | for(i = y1; i < y2; ++i) { |
| 436 | cclearxy(x1, i, dialog->w); |
| 437 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 438 | |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 439 | draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, |
| 440 | x1, x2, y1, y2); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 441 | } |
| 442 | /*-----------------------------------------------------------------------------------*/ |
| 443 | void |
| 444 | ctk_draw_clear(unsigned char y1, unsigned char y2) |
| 445 | { |
| 446 | unsigned char i; |
| 447 | |
| 448 | for(i = y1; i < y2; ++i) { |
| 449 | cclearxy(0, i, sizex); |
| 450 | } |
| 451 | } |
| 452 | /*-----------------------------------------------------------------------------------*/ |
| 453 | static void |
| 454 | draw_menu(struct ctk_menu *m) |
| 455 | { |
| 456 | unsigned char x, x2, y; |
| 457 | textcolor(OPENMENUCOLOR); |
oliverschmidt | d9a9107 | 2004-07-29 11:49:45 +0000 | [diff] [blame^] | 458 | revers(0); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 459 | x = wherex(); |
| 460 | cputs(m->title); |
| 461 | cputc(' '); |
| 462 | x2 = wherex(); |
| 463 | if(x + CTK_CONF_MENUWIDTH > sizex) { |
| 464 | x = sizex - CTK_CONF_MENUWIDTH; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | for(y = 0; y < m->nitems; ++y) { |
| 469 | if(y == m->active) { |
| 470 | textcolor(ACTIVEMENUITEMCOLOR); |
| 471 | revers(0); |
| 472 | } else { |
| 473 | textcolor(MENUCOLOR); |
oliverschmidt | d9a9107 | 2004-07-29 11:49:45 +0000 | [diff] [blame^] | 474 | revers(1); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 475 | } |
| 476 | gotoxy(x, y + 1); |
| 477 | if(m->items[y].title[0] == '-') { |
| 478 | chline(CTK_CONF_MENUWIDTH); |
| 479 | } else { |
| 480 | cputs(m->items[y].title); |
| 481 | } |
| 482 | if(x + CTK_CONF_MENUWIDTH > wherex()) { |
| 483 | cclear(x + CTK_CONF_MENUWIDTH - wherex()); |
| 484 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 485 | } |
| 486 | gotoxy(x2, 0); |
| 487 | textcolor(MENUCOLOR); |
oliverschmidt | d9a9107 | 2004-07-29 11:49:45 +0000 | [diff] [blame^] | 488 | revers(1); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 489 | } |
| 490 | /*-----------------------------------------------------------------------------------*/ |
| 491 | void |
| 492 | ctk_draw_menus(struct ctk_menus *menus) |
| 493 | { |
| 494 | struct ctk_menu *m; |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 495 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 496 | /* Draw menus */ |
| 497 | textcolor(MENUCOLOR); |
| 498 | gotoxy(0, 0); |
| 499 | revers(1); |
adamdunkels | e68091d | 2003-04-16 18:29:10 +0000 | [diff] [blame] | 500 | cputc(' '); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 501 | for(m = menus->menus->next; m != NULL; m = m->next) { |
| 502 | if(m != menus->open) { |
| 503 | cputs(m->title); |
| 504 | cputc(' '); |
| 505 | } else { |
| 506 | draw_menu(m); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | |
| 511 | if(wherex() + strlen(menus->desktopmenu->title) + 1>= sizex) { |
| 512 | gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); |
| 513 | } else { |
| 514 | cclear(sizex - wherex() - |
| 515 | strlen(menus->desktopmenu->title) - 1); |
| 516 | } |
| 517 | |
| 518 | /* Draw desktopmenu */ |
| 519 | if(menus->desktopmenu != menus->open) { |
| 520 | cputs(menus->desktopmenu->title); |
| 521 | cputc(' '); |
| 522 | } else { |
| 523 | draw_menu(menus->desktopmenu); |
| 524 | } |
| 525 | |
| 526 | revers(0); |
| 527 | } |
| 528 | /*-----------------------------------------------------------------------------------*/ |
| 529 | unsigned char |
| 530 | ctk_draw_height(void) |
| 531 | { |
| 532 | return sizey; |
| 533 | } |
| 534 | /*-----------------------------------------------------------------------------------*/ |
| 535 | unsigned char |
| 536 | ctk_draw_width(void) |
| 537 | { |
| 538 | return sizex; |
| 539 | } |
| 540 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca2cbe5 | 2004-07-04 11:38:43 +0000 | [diff] [blame] | 541 | int |
| 542 | ctk_arch_isprint(char c) |
| 543 | { |
| 544 | return isprint(c); |
| 545 | } |