adamdunkels | 60612e7 | 2004-08-09 20:21:30 +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. |
| 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 "ctk" console GUI toolkit for cc65 |
| 31 | * |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 32 | * $Id: ctk-conio-service.c,v 1.8 2005/03/29 20:30:32 oliverschmidt Exp $ |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
| 36 | #include <conio.h> |
| 37 | |
| 38 | #include "ctk.h" |
| 39 | #include "ctk-draw.h" |
| 40 | |
| 41 | #include "ctk-draw-service.h" |
| 42 | |
| 43 | #include "ctk-conio-conf.h" |
| 44 | #include <string.h> |
| 45 | |
| 46 | #ifndef NULL |
| 47 | #define NULL (void *)0 |
| 48 | #endif /* NULL */ |
| 49 | |
| 50 | static unsigned char sizex, sizey; |
| 51 | |
| 52 | /*unsigned char ctk_draw_windowborder_height = 1; |
| 53 | unsigned char ctk_draw_windowborder_width = 1; |
| 54 | unsigned char ctk_draw_windowtitle_height = 1;*/ |
| 55 | |
| 56 | |
| 57 | /*-----------------------------------------------------------------------------------*/ |
| 58 | static void |
| 59 | cputsn(char *str, unsigned char len) |
| 60 | { |
| 61 | char c; |
| 62 | |
| 63 | while(len > 0) { |
| 64 | --len; |
| 65 | c = *str; |
| 66 | if(c == 0) { |
| 67 | break; |
| 68 | } |
| 69 | cputc(c); |
| 70 | ++str; |
| 71 | } |
| 72 | } |
| 73 | /*-----------------------------------------------------------------------------------*/ |
| 74 | static void |
| 75 | s_ctk_draw_init(void) |
| 76 | { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 77 | (void)bgcolor(SCREENCOLOR); |
| 78 | (void)bordercolor(BORDERCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 79 | screensize(&sizex, &sizey); |
| 80 | ctk_draw_clear(0, sizey); |
| 81 | } |
| 82 | /*-----------------------------------------------------------------------------------*/ |
| 83 | static void |
| 84 | draw_widget(struct ctk_widget *w, |
| 85 | unsigned char x, unsigned char y, |
| 86 | unsigned char clipx, |
| 87 | unsigned char clipy, |
| 88 | unsigned char clipy1, unsigned char clipy2, |
| 89 | unsigned char focus) |
| 90 | { |
| 91 | unsigned char xpos, ypos, xscroll; |
| 92 | unsigned char i, j; |
| 93 | char c, *text; |
| 94 | unsigned char len, wfocus; |
| 95 | |
| 96 | wfocus = 0; |
| 97 | if(focus & CTK_FOCUS_WINDOW) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 98 | (void)textcolor(WIDGETCOLOR_FWIN); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 99 | if(focus & CTK_FOCUS_WIDGET) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 100 | (void)textcolor(WIDGETCOLOR_FOCUS); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 101 | wfocus = 1; |
| 102 | } |
| 103 | } else if(focus & CTK_FOCUS_DIALOG) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 104 | (void)textcolor(WIDGETCOLOR_DIALOG); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 105 | if(focus & CTK_FOCUS_WIDGET) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 106 | (void)textcolor(WIDGETCOLOR_FOCUS); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 107 | wfocus = 1; |
| 108 | } |
| 109 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 110 | (void)textcolor(WIDGETCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | xpos = x + w->x; |
| 114 | ypos = y + w->y; |
| 115 | |
| 116 | switch(w->type) { |
| 117 | case CTK_WIDGET_SEPARATOR: |
| 118 | if(ypos >= clipy1 && ypos < clipy2) { |
| 119 | chlinexy(xpos, ypos, w->w); |
| 120 | } |
| 121 | break; |
| 122 | case CTK_WIDGET_LABEL: |
| 123 | text = w->widget.label.text; |
| 124 | for(i = 0; i < w->h; ++i) { |
| 125 | if(ypos >= clipy1 && ypos < clipy2) { |
| 126 | gotoxy(xpos, ypos); |
| 127 | cputsn(text, w->w); |
| 128 | if(w->w - (wherex() - xpos) > 0) { |
| 129 | cclear(w->w - (wherex() - xpos)); |
| 130 | } |
| 131 | } |
| 132 | ++ypos; |
| 133 | text += w->w; |
| 134 | } |
| 135 | break; |
| 136 | case CTK_WIDGET_BUTTON: |
| 137 | if(ypos >= clipy1 && ypos < clipy2) { |
| 138 | if(wfocus != 0) { |
| 139 | revers(1); |
| 140 | } else { |
| 141 | revers(0); |
| 142 | } |
| 143 | cputcxy(xpos, ypos, '['); |
| 144 | cputsn(w->widget.button.text, w->w); |
| 145 | cputc(']'); |
| 146 | revers(0); |
| 147 | } |
| 148 | break; |
| 149 | case CTK_WIDGET_HYPERLINK: |
| 150 | if(ypos >= clipy1 && ypos < clipy2) { |
| 151 | if(wfocus != 0) { |
| 152 | revers(0); |
| 153 | } else { |
| 154 | revers(1); |
| 155 | } |
| 156 | gotoxy(xpos, ypos); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 157 | (void)textcolor(WIDGETCOLOR_HLINK); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 158 | cputsn(w->widget.button.text, w->w); |
| 159 | revers(0); |
| 160 | } |
| 161 | break; |
| 162 | case CTK_WIDGET_TEXTENTRY: |
| 163 | text = w->widget.textentry.text; |
| 164 | if(wfocus != 0) { |
| 165 | revers(1); |
| 166 | } else { |
| 167 | revers(0); |
| 168 | } |
| 169 | xscroll = 0; |
| 170 | if(w->widget.textentry.xpos >= w->w - 1) { |
| 171 | xscroll = w->widget.textentry.xpos - w->w + 1; |
| 172 | } |
| 173 | for(j = 0; j < w->h; ++j) { |
| 174 | if(ypos >= clipy1 && ypos < clipy2) { |
| 175 | if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && |
| 176 | w->widget.textentry.ypos == j) { |
| 177 | revers(0); |
| 178 | cputcxy(xpos, ypos, '>'); |
| 179 | for(i = 0; i < w->w; ++i) { |
| 180 | c = text[i + xscroll]; |
| 181 | if(i == w->widget.textentry.xpos - xscroll) { |
| 182 | revers(1); |
| 183 | } else { |
| 184 | revers(0); |
| 185 | } |
| 186 | if(c == 0) { |
| 187 | cputc(' '); |
| 188 | } else { |
| 189 | cputc(c); |
| 190 | } |
| 191 | revers(0); |
| 192 | } |
| 193 | cputc('<'); |
| 194 | } else { |
| 195 | cvlinexy(xpos, ypos, 1); |
| 196 | gotoxy(xpos + 1, ypos); |
| 197 | cputsn(text, w->w); |
| 198 | i = wherex(); |
| 199 | if(i - xpos - 1 < w->w) { |
| 200 | cclear(w->w - (i - xpos) + 1); |
| 201 | } |
| 202 | cvline(1); |
| 203 | } |
| 204 | } |
| 205 | ++ypos; |
| 206 | text += w->w; |
| 207 | } |
| 208 | revers(0); |
| 209 | break; |
| 210 | case CTK_WIDGET_ICON: |
| 211 | if(ypos >= clipy1 && ypos < clipy2) { |
| 212 | if(focus & 1) { |
| 213 | revers(1); |
| 214 | } else { |
| 215 | revers(0); |
| 216 | } |
| 217 | gotoxy(xpos, ypos); |
| 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 | } |
| 229 | x = xpos; |
| 230 | |
| 231 | len = strlen(w->widget.icon.title); |
| 232 | if(x + len >= sizex) { |
| 233 | x = sizex - len; |
| 234 | } |
| 235 | |
| 236 | gotoxy(x, ypos); |
| 237 | if(ypos >= clipy1 && ypos < clipy2) { |
| 238 | cputs(w->widget.icon.title); |
| 239 | } |
| 240 | revers(0); |
| 241 | } |
| 242 | break; |
| 243 | |
| 244 | default: |
| 245 | break; |
| 246 | } |
| 247 | } |
| 248 | /*-----------------------------------------------------------------------------------*/ |
| 249 | static void |
| 250 | s_ctk_draw_widget(struct ctk_widget *w, |
| 251 | unsigned char focus, |
| 252 | unsigned char clipy1, |
| 253 | unsigned char clipy2) |
| 254 | { |
| 255 | struct ctk_window *win = w->window; |
| 256 | unsigned char posx, posy; |
| 257 | |
| 258 | posx = win->x + 1; |
| 259 | posy = win->y + 2; |
| 260 | |
| 261 | if(w == win->focused) { |
| 262 | focus |= CTK_FOCUS_WIDGET; |
| 263 | } |
| 264 | |
| 265 | draw_widget(w, posx, posy, |
| 266 | posx + win->w, |
| 267 | posy + win->h, |
| 268 | clipy1, clipy2, |
| 269 | focus); |
| 270 | |
| 271 | #ifdef CTK_CONIO_CONF_UPDATE |
| 272 | CTK_CONIO_CONF_UPDATE(); |
| 273 | #endif /* CTK_CONIO_CONF_UPDATE */ |
| 274 | } |
| 275 | /*-----------------------------------------------------------------------------------*/ |
| 276 | static void |
| 277 | s_ctk_draw_clear_window(struct ctk_window *window, |
| 278 | unsigned char focus, |
| 279 | unsigned char clipy1, |
| 280 | unsigned char clipy2) |
| 281 | { |
| 282 | unsigned char i; |
| 283 | unsigned char h; |
| 284 | |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 285 | if(focus & CTK_FOCUS_WINDOW) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 286 | (void)textcolor(WINDOWCOLOR_FOCUS); |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 287 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 288 | (void)textcolor(WINDOWCOLOR); |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 289 | } |
| 290 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 291 | h = window->y + 2 + window->h; |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 292 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 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 | /*-----------------------------------------------------------------------------------*/ |
| 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 | |
| 329 | #ifdef CTK_CONIO_CONF_UPDATE |
| 330 | CTK_CONIO_CONF_UPDATE(); |
| 331 | #endif /* CTK_CONIO_CONF_UPDATE */ |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 332 | } |
| 333 | /*-----------------------------------------------------------------------------------*/ |
| 334 | static void |
| 335 | s_ctk_draw_window(struct ctk_window *window, unsigned char focus, |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 336 | unsigned char clipy1, unsigned char clipy2, |
| 337 | unsigned char draw_borders) |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 338 | { |
| 339 | unsigned char x, y; |
| 340 | unsigned char h; |
| 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; |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 349 | x1 = x + 1; |
| 350 | y1 = y + 1; |
| 351 | x2 = x1 + window->w; |
| 352 | y2 = y1 + window->h; |
| 353 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 354 | if(draw_borders) { |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 355 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 356 | /* Draw window frame. */ |
| 357 | if(focus & CTK_FOCUS_WINDOW) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 358 | (void)textcolor(WINDOWCOLOR_FOCUS); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 359 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 360 | (void)textcolor(WINDOWCOLOR); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | if(y >= clipy1) { |
| 364 | cputcxy(x, y, CH_ULCORNER); |
oliverschmidt | 7b9025d | 2005-03-18 01:08:35 +0000 | [diff] [blame] | 365 | gotoxy(wherex() + window->titlelen + CTK_CONF_WINDOWMOVE * 2, wherey()); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 366 | chline(window->w - (wherex() - x) - 2); |
| 367 | cputcxy(x2, y, CH_URCORNER); |
| 368 | } |
| 369 | |
| 370 | h = window->h; |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 371 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 372 | if(clipy1 > y1) { |
| 373 | if(clipy1 - y1 < h) { |
| 374 | h = clipy1 - y1; |
| 375 | y1 = clipy1; |
| 376 | } else { |
| 377 | h = 0; |
| 378 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 379 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 380 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 381 | if(clipy2 < y1 + h) { |
| 382 | if(y1 >= clipy2) { |
| 383 | h = 0; |
| 384 | } else { |
| 385 | h = clipy2 - y1; |
| 386 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 387 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 388 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 389 | cvlinexy(x, y1, h); |
| 390 | cvlinexy(x2, y1, h); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 391 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 392 | if(y + window->h >= clipy1 && |
| 393 | y + window->h < clipy2) { |
| 394 | cputcxy(x, y2, CH_LLCORNER); |
| 395 | chlinexy(x1, y2, window->w); |
| 396 | cputcxy(x2, y2, CH_LRCORNER); |
| 397 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 398 | } |
| 399 | |
oliverschmidt | e99386b | 2004-12-27 22:03:04 +0000 | [diff] [blame] | 400 | draw_window_contents(window, focus, clipy1, clipy2, |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 401 | x1, x2, y + 1, y2); |
| 402 | } |
| 403 | /*-----------------------------------------------------------------------------------*/ |
| 404 | static void |
| 405 | s_ctk_draw_dialog(struct ctk_window *dialog) |
| 406 | { |
| 407 | unsigned char x, y; |
| 408 | unsigned char i; |
| 409 | unsigned char x1, y1, x2, y2; |
| 410 | |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 411 | (void)textcolor(DIALOGCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 412 | |
| 413 | x = dialog->x; |
| 414 | y = dialog->y + 1; |
| 415 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 416 | x1 = x + 1; |
| 417 | y1 = y + 1; |
| 418 | x2 = x1 + dialog->w; |
| 419 | y2 = y1 + dialog->h; |
| 420 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 421 | /* Draw dialog frame. */ |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 422 | cvlinexy(x, y1, |
| 423 | dialog->h); |
| 424 | cvlinexy(x2, y1, |
| 425 | dialog->h); |
| 426 | |
| 427 | chlinexy(x1, y, |
| 428 | dialog->w); |
| 429 | chlinexy(x1, y2, |
| 430 | dialog->w); |
| 431 | |
| 432 | cputcxy(x, y, CH_ULCORNER); |
| 433 | cputcxy(x, y2, CH_LLCORNER); |
| 434 | cputcxy(x2, y, CH_URCORNER); |
| 435 | cputcxy(x2, y2, CH_LRCORNER); |
| 436 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 437 | /* Clear dialog contents. */ |
| 438 | for(i = y1; i < y2; ++i) { |
| 439 | cclearxy(x1, i, dialog->w); |
| 440 | } |
| 441 | |
| 442 | draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, |
| 443 | x1, x2, y1, y2); |
| 444 | } |
| 445 | /*-----------------------------------------------------------------------------------*/ |
| 446 | static void |
| 447 | s_ctk_draw_clear(unsigned char y1, unsigned char y2) |
| 448 | { |
| 449 | unsigned char i; |
| 450 | |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 451 | (void)textcolor(BACKGROUNDCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 452 | for(i = y1; i < y2; ++i) { |
| 453 | cclearxy(0, i, sizex); |
| 454 | } |
| 455 | } |
| 456 | /*-----------------------------------------------------------------------------------*/ |
| 457 | static void |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 458 | draw_menu(struct ctk_menu *m, unsigned char open) |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 459 | { |
| 460 | unsigned char x, x2, y; |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 461 | |
| 462 | if(open) { |
| 463 | x = x2 = wherex(); |
| 464 | if(x2 + CTK_CONF_MENUWIDTH > sizex) { |
| 465 | x2 = sizex - CTK_CONF_MENUWIDTH; |
| 466 | } |
| 467 | |
| 468 | for(y = 0; y < m->nitems; ++y) { |
| 469 | if(y == m->active) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 470 | (void)textcolor(ACTIVEMENUITEMCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 471 | revers(0); |
| 472 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 473 | (void)textcolor(MENUCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 474 | revers(1); |
| 475 | } |
| 476 | gotoxy(x2, 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(x2 + CTK_CONF_MENUWIDTH > wherex()) { |
| 483 | cclear(x2 + CTK_CONF_MENUWIDTH - wherex()); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | gotoxy(x, 0); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 488 | (void)textcolor(OPENMENUCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 489 | revers(0); |
| 490 | } |
| 491 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 492 | cputs(m->title); |
| 493 | cputc(' '); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 494 | (void)textcolor(MENUCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 495 | revers(1); |
| 496 | } |
| 497 | /*-----------------------------------------------------------------------------------*/ |
| 498 | static void |
| 499 | s_ctk_draw_menus(struct ctk_menus *menus) |
| 500 | { |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 501 | struct ctk_menu *m; |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 502 | |
| 503 | /* Draw menus */ |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame^] | 504 | (void)textcolor(MENUCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 505 | gotoxy(0, 0); |
| 506 | revers(1); |
| 507 | cputc(' '); |
| 508 | for(m = menus->menus->next; m != NULL; m = m->next) { |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 509 | draw_menu(m, m == menus->open); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 510 | } |
| 511 | |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 512 | /* Draw desktopmenu */ |
| 513 | if(wherex() + strlen(menus->desktopmenu->title) + 1 >= sizex) { |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 514 | gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); |
| 515 | } else { |
| 516 | cclear(sizex - wherex() - |
| 517 | strlen(menus->desktopmenu->title) - 1); |
| 518 | } |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 519 | draw_menu(menus->desktopmenu, menus->desktopmenu == menus->open); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 520 | |
| 521 | revers(0); |
| 522 | } |
| 523 | /*-----------------------------------------------------------------------------------*/ |
| 524 | static unsigned char |
| 525 | s_ctk_draw_height(void) |
| 526 | { |
| 527 | return sizey; |
| 528 | } |
| 529 | /*-----------------------------------------------------------------------------------*/ |
| 530 | static unsigned char |
| 531 | s_ctk_draw_width(void) |
| 532 | { |
| 533 | return sizex; |
| 534 | } |
| 535 | /*-----------------------------------------------------------------------------------*/ |
| 536 | static unsigned short |
| 537 | s_ctk_mouse_xtoc(unsigned short x) |
| 538 | { |
| 539 | return x / 8; |
| 540 | } |
| 541 | /*-----------------------------------------------------------------------------------*/ |
| 542 | static unsigned short |
| 543 | s_ctk_mouse_ytoc(unsigned short y) |
| 544 | { |
| 545 | return y / 8; |
| 546 | } |
| 547 | /*-----------------------------------------------------------------------------------*/ |
| 548 | static const struct ctk_draw_service_interface interface = |
| 549 | {CTK_DRAW_SERVICE_VERSION, |
| 550 | 1, |
| 551 | 1, |
| 552 | 1, |
| 553 | s_ctk_draw_init, |
| 554 | s_ctk_draw_clear, |
| 555 | s_ctk_draw_clear_window, |
| 556 | s_ctk_draw_window, |
| 557 | s_ctk_draw_dialog, |
| 558 | s_ctk_draw_widget, |
| 559 | s_ctk_draw_menus, |
| 560 | s_ctk_draw_width, |
| 561 | s_ctk_draw_height, |
| 562 | s_ctk_mouse_xtoc, |
| 563 | s_ctk_mouse_ytoc, |
| 564 | }; |
| 565 | |
| 566 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 567 | EK_PROCESS(proc, CTK_DRAW_SERVICE_NAME ": text", EK_PRIO_NORMAL, |
| 568 | eventhandler, NULL, (void *)&interface); |
| 569 | |
| 570 | /*--------------------------------------------------------------------------*/ |
| 571 | LOADER_INIT_FUNC(ctk_conio_service_init, arg) |
adamdunkels | 8478bee | 2004-09-12 17:54:12 +0000 | [diff] [blame] | 572 | { |
| 573 | s_ctk_draw_init(); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 574 | ek_service_start(CTK_DRAW_SERVICE_NAME, &proc); |
| 575 | } |
| 576 | /*--------------------------------------------------------------------------*/ |
| 577 | EK_EVENTHANDLER(eventhandler, ev, data) |
| 578 | { |
| 579 | EK_EVENTHANDLER_ARGS(ev, data); |
| 580 | |
| 581 | switch(ev) { |
| 582 | case EK_EVENT_INIT: |
| 583 | case EK_EVENT_REPLACE: |
adamdunkels | 8478bee | 2004-09-12 17:54:12 +0000 | [diff] [blame] | 584 | s_ctk_draw_init(); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 585 | ctk_restore(); |
| 586 | break; |
| 587 | case EK_EVENT_REQUEST_REPLACE: |
| 588 | ek_replace((struct ek_proc *)data, NULL); |
| 589 | LOADER_UNLOAD(); |
| 590 | break; |
| 591 | } |
| 592 | } |
| 593 | /*--------------------------------------------------------------------------*/ |