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 | acdf6e9 | 2005-05-04 22:04:35 +0000 | [diff] [blame^] | 32 | * $Id: ctk-conio-service.c,v 1.10 2005/05/04 22:04:35 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) { |
oliverschmidt | 6307bff | 2005-05-04 19:54:50 +0000 | [diff] [blame] | 138 | revers(wfocus != 0); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 139 | cputcxy(xpos, ypos, '['); |
| 140 | cputsn(w->widget.button.text, w->w); |
| 141 | cputc(']'); |
| 142 | revers(0); |
| 143 | } |
| 144 | break; |
| 145 | case CTK_WIDGET_HYPERLINK: |
| 146 | if(ypos >= clipy1 && ypos < clipy2) { |
oliverschmidt | 6307bff | 2005-05-04 19:54:50 +0000 | [diff] [blame] | 147 | revers(wfocus == 0); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 148 | gotoxy(xpos, ypos); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 149 | (void)textcolor(WIDGETCOLOR_HLINK); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 150 | cputsn(w->widget.button.text, w->w); |
| 151 | revers(0); |
| 152 | } |
| 153 | break; |
| 154 | case CTK_WIDGET_TEXTENTRY: |
| 155 | text = w->widget.textentry.text; |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 156 | xscroll = 0; |
| 157 | if(w->widget.textentry.xpos >= w->w - 1) { |
| 158 | xscroll = w->widget.textentry.xpos - w->w + 1; |
| 159 | } |
| 160 | for(j = 0; j < w->h; ++j) { |
| 161 | if(ypos >= clipy1 && ypos < clipy2) { |
| 162 | if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && |
| 163 | w->widget.textentry.ypos == j) { |
| 164 | revers(0); |
| 165 | cputcxy(xpos, ypos, '>'); |
| 166 | for(i = 0; i < w->w; ++i) { |
| 167 | c = text[i + xscroll]; |
oliverschmidt | 6307bff | 2005-05-04 19:54:50 +0000 | [diff] [blame] | 168 | revers(i == w->widget.textentry.xpos - xscroll); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 169 | if(c == 0) { |
| 170 | cputc(' '); |
| 171 | } else { |
| 172 | cputc(c); |
| 173 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 174 | } |
oliverschmidt | acdf6e9 | 2005-05-04 22:04:35 +0000 | [diff] [blame^] | 175 | revers(0); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 176 | cputc('<'); |
| 177 | } else { |
oliverschmidt | acdf6e9 | 2005-05-04 22:04:35 +0000 | [diff] [blame^] | 178 | revers(wfocus != 0 && j == w->widget.textentry.ypos); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 179 | cvlinexy(xpos, ypos, 1); |
| 180 | gotoxy(xpos + 1, ypos); |
| 181 | cputsn(text, w->w); |
| 182 | i = wherex(); |
| 183 | if(i - xpos - 1 < w->w) { |
| 184 | cclear(w->w - (i - xpos) + 1); |
| 185 | } |
| 186 | cvline(1); |
| 187 | } |
| 188 | } |
| 189 | ++ypos; |
| 190 | text += w->w; |
| 191 | } |
| 192 | revers(0); |
| 193 | break; |
| 194 | case CTK_WIDGET_ICON: |
| 195 | if(ypos >= clipy1 && ypos < clipy2) { |
oliverschmidt | 6307bff | 2005-05-04 19:54:50 +0000 | [diff] [blame] | 196 | revers(wfocus != 0); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 197 | gotoxy(xpos, ypos); |
| 198 | if(w->widget.icon.textmap != NULL) { |
| 199 | for(i = 0; i < 3; ++i) { |
| 200 | gotoxy(xpos, ypos); |
| 201 | if(ypos >= clipy1 && ypos < clipy2) { |
| 202 | cputc(w->widget.icon.textmap[0 + 3 * i]); |
| 203 | cputc(w->widget.icon.textmap[1 + 3 * i]); |
| 204 | cputc(w->widget.icon.textmap[2 + 3 * i]); |
| 205 | } |
| 206 | ++ypos; |
| 207 | } |
| 208 | } |
| 209 | x = xpos; |
| 210 | |
| 211 | len = strlen(w->widget.icon.title); |
| 212 | if(x + len >= sizex) { |
| 213 | x = sizex - len; |
| 214 | } |
| 215 | |
| 216 | gotoxy(x, ypos); |
| 217 | if(ypos >= clipy1 && ypos < clipy2) { |
| 218 | cputs(w->widget.icon.title); |
| 219 | } |
| 220 | revers(0); |
| 221 | } |
| 222 | break; |
| 223 | |
| 224 | default: |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | /*-----------------------------------------------------------------------------------*/ |
| 229 | static void |
| 230 | s_ctk_draw_widget(struct ctk_widget *w, |
| 231 | unsigned char focus, |
| 232 | unsigned char clipy1, |
| 233 | unsigned char clipy2) |
| 234 | { |
| 235 | struct ctk_window *win = w->window; |
| 236 | unsigned char posx, posy; |
| 237 | |
| 238 | posx = win->x + 1; |
| 239 | posy = win->y + 2; |
| 240 | |
| 241 | if(w == win->focused) { |
| 242 | focus |= CTK_FOCUS_WIDGET; |
| 243 | } |
| 244 | |
| 245 | draw_widget(w, posx, posy, |
| 246 | posx + win->w, |
| 247 | posy + win->h, |
| 248 | clipy1, clipy2, |
| 249 | focus); |
| 250 | |
| 251 | #ifdef CTK_CONIO_CONF_UPDATE |
| 252 | CTK_CONIO_CONF_UPDATE(); |
| 253 | #endif /* CTK_CONIO_CONF_UPDATE */ |
| 254 | } |
| 255 | /*-----------------------------------------------------------------------------------*/ |
| 256 | static void |
| 257 | s_ctk_draw_clear_window(struct ctk_window *window, |
| 258 | unsigned char focus, |
| 259 | unsigned char clipy1, |
| 260 | unsigned char clipy2) |
| 261 | { |
| 262 | unsigned char i; |
| 263 | unsigned char h; |
| 264 | |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 265 | if(focus & CTK_FOCUS_WINDOW) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 266 | (void)textcolor(WINDOWCOLOR_FOCUS); |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 267 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 268 | (void)textcolor(WINDOWCOLOR); |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 269 | } |
| 270 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 271 | h = window->y + 2 + window->h; |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 272 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 273 | /* Clear window contents. */ |
| 274 | for(i = window->y + 2; i < h; ++i) { |
| 275 | if(i >= clipy1 && i < clipy2) { |
| 276 | cclearxy(window->x + 1, i, window->w); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | /*-----------------------------------------------------------------------------------*/ |
| 281 | static void |
| 282 | draw_window_contents(struct ctk_window *window, unsigned char focus, |
| 283 | unsigned char clipy1, unsigned char clipy2, |
| 284 | unsigned char x1, unsigned char x2, |
| 285 | unsigned char y1, unsigned char y2) |
| 286 | { |
| 287 | struct ctk_widget *w; |
| 288 | unsigned char wfocus; |
| 289 | |
| 290 | /* Draw inactive widgets. */ |
| 291 | for(w = window->inactive; w != NULL; w = w->next) { |
| 292 | draw_widget(w, x1, y1, x2, y2, |
| 293 | clipy1, clipy2, |
| 294 | focus); |
| 295 | } |
| 296 | |
| 297 | /* Draw active widgets. */ |
| 298 | for(w = window->active; w != NULL; w = w->next) { |
| 299 | wfocus = focus; |
| 300 | if(w == window->focused) { |
| 301 | wfocus |= CTK_FOCUS_WIDGET; |
| 302 | } |
| 303 | |
| 304 | draw_widget(w, x1, y1, x2, y2, |
| 305 | clipy1, clipy2, |
| 306 | wfocus); |
| 307 | } |
| 308 | |
| 309 | #ifdef CTK_CONIO_CONF_UPDATE |
| 310 | CTK_CONIO_CONF_UPDATE(); |
| 311 | #endif /* CTK_CONIO_CONF_UPDATE */ |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 312 | } |
| 313 | /*-----------------------------------------------------------------------------------*/ |
| 314 | static void |
| 315 | s_ctk_draw_window(struct ctk_window *window, unsigned char focus, |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 316 | unsigned char clipy1, unsigned char clipy2, |
| 317 | unsigned char draw_borders) |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 318 | { |
| 319 | unsigned char x, y; |
| 320 | unsigned char h; |
| 321 | unsigned char x1, y1, x2, y2; |
| 322 | |
| 323 | if(window->y + 1 >= clipy2) { |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | x = window->x; |
| 328 | y = window->y + 1; |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 329 | x1 = x + 1; |
| 330 | y1 = y + 1; |
| 331 | x2 = x1 + window->w; |
| 332 | y2 = y1 + window->h; |
| 333 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 334 | if(draw_borders) { |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 335 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 336 | /* Draw window frame. */ |
| 337 | if(focus & CTK_FOCUS_WINDOW) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 338 | (void)textcolor(WINDOWCOLOR_FOCUS); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 339 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 340 | (void)textcolor(WINDOWCOLOR); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | if(y >= clipy1) { |
| 344 | cputcxy(x, y, CH_ULCORNER); |
oliverschmidt | 7b9025d | 2005-03-18 01:08:35 +0000 | [diff] [blame] | 345 | gotoxy(wherex() + window->titlelen + CTK_CONF_WINDOWMOVE * 2, wherey()); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 346 | chline(window->w - (wherex() - x) - 2); |
| 347 | cputcxy(x2, y, CH_URCORNER); |
| 348 | } |
| 349 | |
| 350 | h = window->h; |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 351 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 352 | if(clipy1 > y1) { |
| 353 | if(clipy1 - y1 < h) { |
| 354 | h = clipy1 - y1; |
| 355 | y1 = clipy1; |
| 356 | } else { |
| 357 | h = 0; |
| 358 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 359 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 360 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 361 | if(clipy2 < y1 + h) { |
| 362 | if(y1 >= clipy2) { |
| 363 | h = 0; |
| 364 | } else { |
| 365 | h = clipy2 - y1; |
| 366 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 367 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 368 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 369 | cvlinexy(x, y1, h); |
| 370 | cvlinexy(x2, y1, 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(y + window->h >= clipy1 && |
| 373 | y + window->h < clipy2) { |
| 374 | cputcxy(x, y2, CH_LLCORNER); |
| 375 | chlinexy(x1, y2, window->w); |
| 376 | cputcxy(x2, y2, CH_LRCORNER); |
| 377 | } |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 378 | } |
| 379 | |
oliverschmidt | e99386b | 2004-12-27 22:03:04 +0000 | [diff] [blame] | 380 | draw_window_contents(window, focus, clipy1, clipy2, |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 381 | x1, x2, y + 1, y2); |
| 382 | } |
| 383 | /*-----------------------------------------------------------------------------------*/ |
| 384 | static void |
| 385 | s_ctk_draw_dialog(struct ctk_window *dialog) |
| 386 | { |
| 387 | unsigned char x, y; |
| 388 | unsigned char i; |
| 389 | unsigned char x1, y1, x2, y2; |
| 390 | |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 391 | (void)textcolor(DIALOGCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 392 | |
| 393 | x = dialog->x; |
| 394 | y = dialog->y + 1; |
| 395 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 396 | x1 = x + 1; |
| 397 | y1 = y + 1; |
| 398 | x2 = x1 + dialog->w; |
| 399 | y2 = y1 + dialog->h; |
| 400 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 401 | /* Draw dialog frame. */ |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 402 | cvlinexy(x, y1, |
| 403 | dialog->h); |
| 404 | cvlinexy(x2, y1, |
| 405 | dialog->h); |
| 406 | |
| 407 | chlinexy(x1, y, |
| 408 | dialog->w); |
| 409 | chlinexy(x1, y2, |
| 410 | dialog->w); |
| 411 | |
| 412 | cputcxy(x, y, CH_ULCORNER); |
| 413 | cputcxy(x, y2, CH_LLCORNER); |
| 414 | cputcxy(x2, y, CH_URCORNER); |
| 415 | cputcxy(x2, y2, CH_LRCORNER); |
| 416 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 417 | /* Clear dialog contents. */ |
| 418 | for(i = y1; i < y2; ++i) { |
| 419 | cclearxy(x1, i, dialog->w); |
| 420 | } |
| 421 | |
| 422 | draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, |
| 423 | x1, x2, y1, y2); |
| 424 | } |
| 425 | /*-----------------------------------------------------------------------------------*/ |
| 426 | static void |
| 427 | s_ctk_draw_clear(unsigned char y1, unsigned char y2) |
| 428 | { |
| 429 | unsigned char i; |
| 430 | |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 431 | (void)textcolor(BACKGROUNDCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 432 | for(i = y1; i < y2; ++i) { |
| 433 | cclearxy(0, i, sizex); |
| 434 | } |
| 435 | } |
| 436 | /*-----------------------------------------------------------------------------------*/ |
| 437 | static void |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 438 | draw_menu(struct ctk_menu *m, unsigned char open) |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 439 | { |
| 440 | unsigned char x, x2, y; |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 441 | |
| 442 | if(open) { |
| 443 | x = x2 = wherex(); |
| 444 | if(x2 + CTK_CONF_MENUWIDTH > sizex) { |
| 445 | x2 = sizex - CTK_CONF_MENUWIDTH; |
| 446 | } |
| 447 | |
| 448 | for(y = 0; y < m->nitems; ++y) { |
| 449 | if(y == m->active) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 450 | (void)textcolor(ACTIVEMENUITEMCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 451 | revers(0); |
| 452 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 453 | (void)textcolor(MENUCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 454 | revers(1); |
| 455 | } |
| 456 | gotoxy(x2, y + 1); |
| 457 | if(m->items[y].title[0] == '-') { |
| 458 | chline(CTK_CONF_MENUWIDTH); |
| 459 | } else { |
| 460 | cputs(m->items[y].title); |
| 461 | } |
| 462 | if(x2 + CTK_CONF_MENUWIDTH > wherex()) { |
| 463 | cclear(x2 + CTK_CONF_MENUWIDTH - wherex()); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | gotoxy(x, 0); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 468 | (void)textcolor(OPENMENUCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 469 | revers(0); |
| 470 | } |
| 471 | |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 472 | cputs(m->title); |
| 473 | cputc(' '); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 474 | (void)textcolor(MENUCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 475 | revers(1); |
| 476 | } |
| 477 | /*-----------------------------------------------------------------------------------*/ |
| 478 | static void |
| 479 | s_ctk_draw_menus(struct ctk_menus *menus) |
| 480 | { |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 481 | struct ctk_menu *m; |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 482 | |
| 483 | /* Draw menus */ |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 484 | (void)textcolor(MENUCOLOR); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 485 | gotoxy(0, 0); |
| 486 | revers(1); |
| 487 | cputc(' '); |
| 488 | for(m = menus->menus->next; m != NULL; m = m->next) { |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 489 | draw_menu(m, m == menus->open); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 490 | } |
| 491 | |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 492 | /* Draw desktopmenu */ |
| 493 | if(wherex() + strlen(menus->desktopmenu->title) + 1 >= sizex) { |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 494 | gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); |
| 495 | } else { |
| 496 | cclear(sizex - wherex() - |
| 497 | strlen(menus->desktopmenu->title) - 1); |
| 498 | } |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 499 | draw_menu(menus->desktopmenu, menus->desktopmenu == menus->open); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 500 | |
| 501 | revers(0); |
| 502 | } |
| 503 | /*-----------------------------------------------------------------------------------*/ |
| 504 | static unsigned char |
| 505 | s_ctk_draw_height(void) |
| 506 | { |
| 507 | return sizey; |
| 508 | } |
| 509 | /*-----------------------------------------------------------------------------------*/ |
| 510 | static unsigned char |
| 511 | s_ctk_draw_width(void) |
| 512 | { |
| 513 | return sizex; |
| 514 | } |
| 515 | /*-----------------------------------------------------------------------------------*/ |
| 516 | static unsigned short |
| 517 | s_ctk_mouse_xtoc(unsigned short x) |
| 518 | { |
| 519 | return x / 8; |
| 520 | } |
| 521 | /*-----------------------------------------------------------------------------------*/ |
| 522 | static unsigned short |
| 523 | s_ctk_mouse_ytoc(unsigned short y) |
| 524 | { |
| 525 | return y / 8; |
| 526 | } |
| 527 | /*-----------------------------------------------------------------------------------*/ |
| 528 | static const struct ctk_draw_service_interface interface = |
| 529 | {CTK_DRAW_SERVICE_VERSION, |
| 530 | 1, |
| 531 | 1, |
| 532 | 1, |
| 533 | s_ctk_draw_init, |
| 534 | s_ctk_draw_clear, |
| 535 | s_ctk_draw_clear_window, |
| 536 | s_ctk_draw_window, |
| 537 | s_ctk_draw_dialog, |
| 538 | s_ctk_draw_widget, |
| 539 | s_ctk_draw_menus, |
| 540 | s_ctk_draw_width, |
| 541 | s_ctk_draw_height, |
| 542 | s_ctk_mouse_xtoc, |
| 543 | s_ctk_mouse_ytoc, |
| 544 | }; |
| 545 | |
| 546 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 547 | EK_PROCESS(proc, CTK_DRAW_SERVICE_NAME ": text", EK_PRIO_NORMAL, |
| 548 | eventhandler, NULL, (void *)&interface); |
| 549 | |
| 550 | /*--------------------------------------------------------------------------*/ |
| 551 | LOADER_INIT_FUNC(ctk_conio_service_init, arg) |
adamdunkels | 8478bee | 2004-09-12 17:54:12 +0000 | [diff] [blame] | 552 | { |
| 553 | s_ctk_draw_init(); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 554 | ek_service_start(CTK_DRAW_SERVICE_NAME, &proc); |
| 555 | } |
| 556 | /*--------------------------------------------------------------------------*/ |
| 557 | EK_EVENTHANDLER(eventhandler, ev, data) |
| 558 | { |
| 559 | EK_EVENTHANDLER_ARGS(ev, data); |
| 560 | |
| 561 | switch(ev) { |
| 562 | case EK_EVENT_INIT: |
| 563 | case EK_EVENT_REPLACE: |
adamdunkels | 8478bee | 2004-09-12 17:54:12 +0000 | [diff] [blame] | 564 | s_ctk_draw_init(); |
adamdunkels | 60612e7 | 2004-08-09 20:21:30 +0000 | [diff] [blame] | 565 | ctk_restore(); |
| 566 | break; |
| 567 | case EK_EVENT_REQUEST_REPLACE: |
| 568 | ek_replace((struct ek_proc *)data, NULL); |
| 569 | LOADER_UNLOAD(); |
| 570 | break; |
| 571 | } |
| 572 | } |
| 573 | /*--------------------------------------------------------------------------*/ |