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 | e43cb18 | 2006-05-28 20:38:19 +0000 | [diff] [blame] | 32 | * $Id: ctk-conio.c,v 1.24 2006/05/28 20:38:19 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 | { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 76 | (void)bgcolor(SCREENCOLOR); |
| 77 | (void)bordercolor(BORDERCOLOR); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 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) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 97 | (void)textcolor(WIDGETCOLOR_FWIN); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 98 | if(focus & CTK_FOCUS_WIDGET) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 99 | (void)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) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 103 | (void)textcolor(WIDGETCOLOR_DIALOG); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 104 | if(focus & CTK_FOCUS_WIDGET) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 105 | (void)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 { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 109 | (void)textcolor(WIDGETCOLOR); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 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) { |
oliverschmidt | 6307bff | 2005-05-04 19:54:50 +0000 | [diff] [blame] | 137 | revers(wfocus != 0); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 138 | cputcxy(xpos, ypos, '['); |
| 139 | cputsn(w->widget.button.text, w->w); |
| 140 | cputc(']'); |
| 141 | revers(0); |
| 142 | } |
| 143 | break; |
| 144 | case CTK_WIDGET_HYPERLINK: |
| 145 | if(ypos >= clipy1 && ypos < clipy2) { |
oliverschmidt | 6307bff | 2005-05-04 19:54:50 +0000 | [diff] [blame] | 146 | revers(wfocus == 0); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 147 | gotoxy(xpos, ypos); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 148 | (void)textcolor(WIDGETCOLOR_HLINK); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 149 | cputsn(w->widget.button.text, w->w); |
| 150 | revers(0); |
| 151 | } |
| 152 | break; |
| 153 | case CTK_WIDGET_TEXTENTRY: |
| 154 | text = w->widget.textentry.text; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 155 | xscroll = 0; |
| 156 | if(w->widget.textentry.xpos >= w->w - 1) { |
| 157 | xscroll = w->widget.textentry.xpos - w->w + 1; |
| 158 | } |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 159 | for(j = 0; j < w->h; ++j) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 160 | if(ypos >= clipy1 && ypos < clipy2) { |
| 161 | if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && |
| 162 | w->widget.textentry.ypos == j) { |
| 163 | revers(0); |
| 164 | cputcxy(xpos, ypos, '>'); |
oliverschmidt | e43cb18 | 2006-05-28 20:38:19 +0000 | [diff] [blame] | 165 | c = 1; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 166 | for(i = 0; i < w->w; ++i) { |
oliverschmidt | e43cb18 | 2006-05-28 20:38:19 +0000 | [diff] [blame] | 167 | if(c != 0) { |
| 168 | c = text[i + xscroll]; |
| 169 | } |
oliverschmidt | 6307bff | 2005-05-04 19:54:50 +0000 | [diff] [blame] | 170 | revers(i == w->widget.textentry.xpos - xscroll); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 171 | if(c == 0) { |
| 172 | cputc(' '); |
| 173 | } else { |
| 174 | cputc(c); |
| 175 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 176 | } |
oliverschmidt | acdf6e9 | 2005-05-04 22:04:35 +0000 | [diff] [blame] | 177 | revers(0); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 178 | cputc('<'); |
| 179 | } else { |
oliverschmidt | acdf6e9 | 2005-05-04 22:04:35 +0000 | [diff] [blame] | 180 | revers(wfocus != 0 && j == w->widget.textentry.ypos); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 181 | cvlinexy(xpos, ypos, 1); |
| 182 | gotoxy(xpos + 1, ypos); |
| 183 | cputsn(text, w->w); |
| 184 | i = wherex(); |
| 185 | if(i - xpos - 1 < w->w) { |
| 186 | cclear(w->w - (i - xpos) + 1); |
| 187 | } |
| 188 | cvline(1); |
| 189 | } |
| 190 | } |
| 191 | ++ypos; |
oliverschmidt | cd6c30b | 2005-05-05 20:54:16 +0000 | [diff] [blame] | 192 | text += w->widget.textentry.len + 1; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 193 | } |
| 194 | revers(0); |
| 195 | break; |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 196 | #if CTK_CONF_ICONS |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 197 | case CTK_WIDGET_ICON: |
| 198 | if(ypos >= clipy1 && ypos < clipy2) { |
oliverschmidt | 6307bff | 2005-05-04 19:54:50 +0000 | [diff] [blame] | 199 | revers(wfocus != 0); |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 200 | #if CTK_CONF_ICON_TEXTMAPS |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 201 | if(w->widget.icon.textmap != NULL) { |
| 202 | for(i = 0; i < 3; ++i) { |
| 203 | gotoxy(xpos, ypos); |
| 204 | if(ypos >= clipy1 && ypos < clipy2) { |
| 205 | cputc(w->widget.icon.textmap[0 + 3 * i]); |
| 206 | cputc(w->widget.icon.textmap[1 + 3 * i]); |
| 207 | cputc(w->widget.icon.textmap[2 + 3 * i]); |
| 208 | } |
| 209 | ++ypos; |
| 210 | } |
| 211 | } |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 212 | #endif /* CTK_CONF_ICON_TEXTMAPS */ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 213 | |
| 214 | len = strlen(w->widget.icon.title); |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 215 | if(xpos + len >= sizex) { |
| 216 | xpos = sizex - len; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 217 | } |
| 218 | |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 219 | gotoxy(xpos, ypos); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 220 | if(ypos >= clipy1 && ypos < clipy2) { |
| 221 | cputs(w->widget.icon.title); |
| 222 | } |
| 223 | revers(0); |
| 224 | } |
| 225 | break; |
oliverschmidt | a98def5 | 2004-06-27 18:32:10 +0000 | [diff] [blame] | 226 | #endif /* CTK_CONF_ICONS */ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 227 | |
| 228 | default: |
| 229 | break; |
| 230 | } |
| 231 | } |
| 232 | /*-----------------------------------------------------------------------------------*/ |
| 233 | void |
| 234 | ctk_draw_widget(struct ctk_widget *w, |
| 235 | unsigned char focus, |
| 236 | unsigned char clipy1, |
| 237 | unsigned char clipy2) |
| 238 | { |
| 239 | struct ctk_window *win = w->window; |
| 240 | unsigned char posx, posy; |
| 241 | |
| 242 | posx = win->x + 1; |
| 243 | posy = win->y + 2; |
| 244 | |
| 245 | if(w == win->focused) { |
| 246 | focus |= CTK_FOCUS_WIDGET; |
| 247 | } |
| 248 | |
| 249 | draw_widget(w, posx, posy, |
| 250 | posx + win->w, |
| 251 | posy + win->h, |
| 252 | clipy1, clipy2, |
| 253 | focus); |
adamdunkels | fe32f8d | 2003-04-28 20:31:48 +0000 | [diff] [blame] | 254 | |
| 255 | #ifdef CTK_CONIO_CONF_UPDATE |
| 256 | CTK_CONIO_CONF_UPDATE(); |
| 257 | #endif /* CTK_CONIO_CONF_UPDATE */ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 258 | } |
| 259 | /*-----------------------------------------------------------------------------------*/ |
| 260 | void |
| 261 | ctk_draw_clear_window(struct ctk_window *window, |
| 262 | unsigned char focus, |
| 263 | unsigned char clipy1, |
| 264 | unsigned char clipy2) |
| 265 | { |
| 266 | unsigned char i; |
| 267 | unsigned char h; |
| 268 | |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 269 | if(focus & CTK_FOCUS_WINDOW) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 270 | (void)textcolor(WINDOWCOLOR_FOCUS); |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 271 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 272 | (void)textcolor(WINDOWCOLOR); |
oliverschmidt | 0e144fb | 2004-08-12 21:52:03 +0000 | [diff] [blame] | 273 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 274 | |
| 275 | h = window->y + 2 + window->h; |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 276 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 277 | /* Clear window contents. */ |
| 278 | for(i = window->y + 2; i < h; ++i) { |
| 279 | if(i >= clipy1 && i < clipy2) { |
| 280 | cclearxy(window->x + 1, i, window->w); |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 285 | static void |
| 286 | draw_window_contents(struct ctk_window *window, unsigned char focus, |
| 287 | unsigned char clipy1, unsigned char clipy2, |
| 288 | unsigned char x1, unsigned char x2, |
| 289 | unsigned char y1, unsigned char y2) |
| 290 | { |
| 291 | struct ctk_widget *w; |
| 292 | unsigned char wfocus; |
| 293 | |
| 294 | /* Draw inactive widgets. */ |
| 295 | for(w = window->inactive; w != NULL; w = w->next) { |
| 296 | draw_widget(w, x1, y1, x2, y2, |
| 297 | clipy1, clipy2, |
| 298 | focus); |
| 299 | } |
| 300 | |
| 301 | /* Draw active widgets. */ |
| 302 | for(w = window->active; w != NULL; w = w->next) { |
| 303 | wfocus = focus; |
| 304 | if(w == window->focused) { |
| 305 | wfocus |= CTK_FOCUS_WIDGET; |
| 306 | } |
| 307 | |
| 308 | draw_widget(w, x1, y1, x2, y2, |
| 309 | clipy1, clipy2, |
| 310 | wfocus); |
| 311 | } |
| 312 | |
adamdunkels | fe32f8d | 2003-04-28 20:31:48 +0000 | [diff] [blame] | 313 | #ifdef CTK_CONIO_CONF_UPDATE |
| 314 | CTK_CONIO_CONF_UPDATE(); |
| 315 | #endif /* CTK_CONIO_CONF_UPDATE */ |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 316 | } |
| 317 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 318 | void |
| 319 | ctk_draw_window(struct ctk_window *window, unsigned char focus, |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 320 | unsigned char clipy1, unsigned char clipy2, |
| 321 | unsigned char draw_borders) |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 322 | { |
| 323 | unsigned char x, y; |
| 324 | unsigned char h; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 325 | unsigned char x1, y1, x2, y2; |
| 326 | |
| 327 | if(window->y + 1 >= clipy2) { |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | x = window->x; |
| 332 | y = window->y + 1; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 333 | x1 = x + 1; |
| 334 | y1 = y + 1; |
| 335 | x2 = x1 + window->w; |
| 336 | y2 = y1 + window->h; |
| 337 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 338 | if(draw_borders) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 339 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 340 | /* Draw window frame. */ |
| 341 | if(focus & CTK_FOCUS_WINDOW) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 342 | (void)textcolor(WINDOWCOLOR_FOCUS); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 343 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 344 | (void)textcolor(WINDOWCOLOR); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | if(y >= clipy1) { |
| 348 | cputcxy(x, y, CH_ULCORNER); |
oliverschmidt | 7b9025d | 2005-03-18 01:08:35 +0000 | [diff] [blame] | 349 | gotoxy(wherex() + window->titlelen + CTK_CONF_WINDOWMOVE * 2, wherey()); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 350 | chline(window->w - (wherex() - x) - 2); |
| 351 | cputcxy(x2, y, CH_URCORNER); |
| 352 | } |
| 353 | |
| 354 | h = window->h; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 355 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 356 | if(clipy1 > y1) { |
| 357 | if(clipy1 - y1 < h) { |
| 358 | h = clipy1 - y1; |
| 359 | y1 = clipy1; |
| 360 | } else { |
| 361 | h = 0; |
| 362 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 363 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 364 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 365 | if(clipy2 < y1 + h) { |
| 366 | if(y1 >= clipy2) { |
| 367 | h = 0; |
| 368 | } else { |
| 369 | h = clipy2 - y1; |
| 370 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 371 | } |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 372 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 373 | cvlinexy(x, y1, h); |
| 374 | cvlinexy(x2, y1, h); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 375 | |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 376 | if(y + window->h >= clipy1 && |
| 377 | y + window->h < clipy2) { |
| 378 | cputcxy(x, y2, CH_LLCORNER); |
| 379 | chlinexy(x1, y2, window->w); |
| 380 | cputcxy(x2, y2, CH_LRCORNER); |
| 381 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 382 | } |
| 383 | |
oliverschmidt | e99386b | 2004-12-27 22:03:04 +0000 | [diff] [blame] | 384 | draw_window_contents(window, focus, clipy1, clipy2, |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 385 | x1, x2, y + 1, y2); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 386 | } |
| 387 | /*-----------------------------------------------------------------------------------*/ |
| 388 | void |
| 389 | ctk_draw_dialog(struct ctk_window *dialog) |
| 390 | { |
| 391 | unsigned char x, y; |
| 392 | unsigned char i; |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 393 | unsigned char x1, y1, x2, y2; |
| 394 | |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 395 | (void)textcolor(DIALOGCOLOR); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 396 | |
| 397 | x = dialog->x; |
| 398 | y = dialog->y + 1; |
| 399 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 400 | x1 = x + 1; |
| 401 | y1 = y + 1; |
| 402 | x2 = x1 + dialog->w; |
| 403 | y2 = y1 + dialog->h; |
| 404 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 405 | /* Draw dialog frame. */ |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 406 | cvlinexy(x, y1, |
| 407 | dialog->h); |
| 408 | cvlinexy(x2, y1, |
| 409 | dialog->h); |
| 410 | |
| 411 | chlinexy(x1, y, |
| 412 | dialog->w); |
| 413 | chlinexy(x1, y2, |
| 414 | dialog->w); |
| 415 | |
| 416 | cputcxy(x, y, CH_ULCORNER); |
| 417 | cputcxy(x, y2, CH_LLCORNER); |
| 418 | cputcxy(x2, y, CH_URCORNER); |
| 419 | cputcxy(x2, y2, CH_LRCORNER); |
| 420 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 421 | /* Clear dialog contents. */ |
| 422 | for(i = y1; i < y2; ++i) { |
| 423 | cclearxy(x1, i, dialog->w); |
| 424 | } |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 425 | |
adamdunkels | a45d8a1 | 2003-04-08 07:22:13 +0000 | [diff] [blame] | 426 | draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, |
| 427 | x1, x2, y1, y2); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 428 | } |
| 429 | /*-----------------------------------------------------------------------------------*/ |
| 430 | void |
| 431 | ctk_draw_clear(unsigned char y1, unsigned char y2) |
| 432 | { |
| 433 | unsigned char i; |
| 434 | |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 435 | (void)textcolor(BACKGROUNDCOLOR); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 436 | for(i = y1; i < y2; ++i) { |
| 437 | cclearxy(0, i, sizex); |
| 438 | } |
| 439 | } |
| 440 | /*-----------------------------------------------------------------------------------*/ |
| 441 | static void |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 442 | draw_menu(struct ctk_menu *m, unsigned char open) |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 443 | { |
| 444 | unsigned char x, x2, y; |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 445 | |
| 446 | if(open) { |
| 447 | x = x2 = wherex(); |
| 448 | if(x2 + CTK_CONF_MENUWIDTH > sizex) { |
| 449 | x2 = sizex - CTK_CONF_MENUWIDTH; |
| 450 | } |
| 451 | |
| 452 | for(y = 0; y < m->nitems; ++y) { |
| 453 | if(y == m->active) { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 454 | (void)textcolor(ACTIVEMENUITEMCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 455 | revers(0); |
| 456 | } else { |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 457 | (void)textcolor(MENUCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 458 | revers(1); |
| 459 | } |
| 460 | gotoxy(x2, y + 1); |
| 461 | if(m->items[y].title[0] == '-') { |
| 462 | chline(CTK_CONF_MENUWIDTH); |
| 463 | } else { |
| 464 | cputs(m->items[y].title); |
| 465 | } |
| 466 | if(x2 + CTK_CONF_MENUWIDTH > wherex()) { |
| 467 | cclear(x2 + CTK_CONF_MENUWIDTH - wherex()); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | gotoxy(x, 0); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 472 | (void)textcolor(OPENMENUCOLOR); |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 473 | revers(0); |
| 474 | } |
| 475 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 476 | cputs(m->title); |
| 477 | cputc(' '); |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 478 | (void)textcolor(MENUCOLOR); |
oliverschmidt | d9a9107 | 2004-07-29 11:49:45 +0000 | [diff] [blame] | 479 | revers(1); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 480 | } |
| 481 | /*-----------------------------------------------------------------------------------*/ |
| 482 | void |
| 483 | ctk_draw_menus(struct ctk_menus *menus) |
| 484 | { |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 485 | struct ctk_menu *m; |
adamdunkels | 62393fb | 2003-07-30 23:31:56 +0000 | [diff] [blame] | 486 | |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 487 | /* Draw menus */ |
oliverschmidt | 7fdf5f5 | 2005-03-29 20:30:32 +0000 | [diff] [blame] | 488 | (void)textcolor(MENUCOLOR); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 489 | gotoxy(0, 0); |
| 490 | revers(1); |
adamdunkels | e68091d | 2003-04-16 18:29:10 +0000 | [diff] [blame] | 491 | cputc(' '); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 492 | for(m = menus->menus->next; m != NULL; m = m->next) { |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 493 | draw_menu(m, m == menus->open); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 494 | } |
| 495 | |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 496 | /* Draw desktopmenu */ |
| 497 | if(wherex() + strlen(menus->desktopmenu->title) + 1 >= sizex) { |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 498 | gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); |
| 499 | } else { |
| 500 | cclear(sizex - wherex() - |
| 501 | strlen(menus->desktopmenu->title) - 1); |
| 502 | } |
oliverschmidt | 2b1582b | 2005-03-15 14:19:40 +0000 | [diff] [blame] | 503 | draw_menu(menus->desktopmenu, menus->desktopmenu == menus->open); |
adamdunkels | 09c28b6 | 2003-04-02 10:17:52 +0000 | [diff] [blame] | 504 | |
| 505 | revers(0); |
| 506 | } |
| 507 | /*-----------------------------------------------------------------------------------*/ |
| 508 | unsigned char |
| 509 | ctk_draw_height(void) |
| 510 | { |
| 511 | return sizey; |
| 512 | } |
| 513 | /*-----------------------------------------------------------------------------------*/ |
| 514 | unsigned char |
| 515 | ctk_draw_width(void) |
| 516 | { |
| 517 | return sizex; |
| 518 | } |
| 519 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca2cbe5 | 2004-07-04 11:38:43 +0000 | [diff] [blame] | 520 | int |
| 521 | ctk_arch_isprint(char c) |
| 522 | { |
| 523 | return isprint(c); |
| 524 | } |