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