PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [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 | * |
| 32 | * $Id: ctk-conio-service.c,v 1.12 2006/05/28 20:38:19 oliverschmidt Exp $ |
| 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 | // The revers function does nothing in our conio driver anyway. |
| 57 | #define revers(x) |
| 58 | |
PulkoMandy | c0f22c7 | 2023-05-04 23:02:20 +0200 | [diff] [blame^] | 59 | #if 0 |
| 60 | static void revers(bool invert) |
| 61 | { |
| 62 | static bool isInverted; |
| 63 | if (isInverted == invert) |
| 64 | return; |
| 65 | |
| 66 | __asm |
| 67 | call 0xBB9C |
| 68 | __endasm |
| 69 | } |
| 70 | #endif |
| 71 | |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 72 | /*-----------------------------------------------------------------------------------*/ |
| 73 | static void |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 74 | s_ctk_draw_init(void) |
| 75 | { |
| 76 | (void)bgcolor(SCREENCOLOR); |
| 77 | (void)bordercolor(BORDERCOLOR); |
PulkoMandy | 25ff050 | 2014-07-03 09:55:24 +0200 | [diff] [blame] | 78 | clrscr(); |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 79 | screensize(&sizex, &sizey); |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 80 | } |
| 81 | /*-----------------------------------------------------------------------------------*/ |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 82 | |
| 83 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 84 | static void customchr(const unsigned char* data) __naked __preserves_regs(c, d, e) |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 85 | { |
| 86 | __asm |
Adrien Destugues | 69a6e72 | 2017-06-03 10:17:17 +0200 | [diff] [blame] | 87 | ; Cant use SCR SET MATRIX because some of our icons are in RAM under 0x4000. |
PulkoMandy | 0627a36 | 2014-07-03 18:55:34 +0200 | [diff] [blame] | 88 | ; SCR SET MATRIX then gets data from the firmware ROM... |
| 89 | ld a,#0x19 |
| 90 | call 0xBB5a |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 91 | ld a,#0xff |
PulkoMandy | 0627a36 | 2014-07-03 18:55:34 +0200 | [diff] [blame] | 92 | call 0xBB5a |
| 93 | ld b,#8 |
| 94 | 00001$: |
| 95 | ld a,(hl) |
| 96 | call 0xbb5a |
| 97 | inc hl |
| 98 | djnz 00001$ |
| 99 | ret |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 100 | __endasm; |
| 101 | } |
| 102 | |
| 103 | |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 104 | static void |
| 105 | draw_widget(struct ctk_widget *w, |
| 106 | unsigned char x, unsigned char y, |
| 107 | unsigned char clipx, |
| 108 | unsigned char clipy, |
| 109 | unsigned char clipy1, unsigned char clipy2, |
| 110 | unsigned char focus) |
| 111 | { |
| 112 | unsigned char xpos, ypos, xscroll; |
| 113 | unsigned char i, j; |
Adrien Destugues | 69a6e72 | 2017-06-03 10:17:17 +0200 | [diff] [blame] | 114 | char c; |
| 115 | const char* text; |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 116 | unsigned char len, wfocus; |
| 117 | |
| 118 | wfocus = 0; |
| 119 | if(focus & CTK_FOCUS_WINDOW) { |
| 120 | (void)textcolor(WIDGETCOLOR_FWIN); |
| 121 | if(focus & CTK_FOCUS_WIDGET) { |
| 122 | (void)textcolor(WIDGETCOLOR_FOCUS); |
| 123 | wfocus = 1; |
| 124 | } |
| 125 | } else if(focus & CTK_FOCUS_DIALOG) { |
| 126 | (void)textcolor(WIDGETCOLOR_DIALOG); |
| 127 | if(focus & CTK_FOCUS_WIDGET) { |
| 128 | (void)textcolor(WIDGETCOLOR_FOCUS); |
| 129 | wfocus = 1; |
| 130 | } |
| 131 | } else { |
| 132 | (void)textcolor(WIDGETCOLOR); |
| 133 | } |
| 134 | |
| 135 | xpos = x + w->x; |
| 136 | ypos = y + w->y; |
| 137 | |
| 138 | switch(w->type) { |
| 139 | case CTK_WIDGET_SEPARATOR: |
| 140 | if(ypos >= clipy1 && ypos < clipy2) { |
| 141 | chlinexy(xpos, ypos, w->w); |
| 142 | } |
| 143 | break; |
| 144 | case CTK_WIDGET_LABEL: |
| 145 | text = w->widget.label.text; |
| 146 | for(i = 0; i < w->h; ++i) { |
| 147 | if(ypos >= clipy1 && ypos < clipy2) { |
| 148 | gotoxy(xpos, ypos); |
| 149 | cputsn(text, w->w); |
| 150 | if(w->w - (wherex() - xpos) > 0) { |
| 151 | cclear(w->w - (wherex() - xpos)); |
| 152 | } |
| 153 | } |
| 154 | ++ypos; |
| 155 | text += w->w; |
| 156 | } |
| 157 | break; |
| 158 | case CTK_WIDGET_BUTTON: |
| 159 | if(ypos >= clipy1 && ypos < clipy2) { |
| 160 | revers(wfocus != 0); |
| 161 | cputcxy(xpos, ypos, '['); |
| 162 | cputsn(w->widget.button.text, w->w); |
| 163 | cputc(']'); |
| 164 | revers(0); |
| 165 | } |
| 166 | break; |
| 167 | case CTK_WIDGET_HYPERLINK: |
| 168 | if(ypos >= clipy1 && ypos < clipy2) { |
| 169 | (void)textcolor(WIDGETCOLOR_HLINK); |
| 170 | revers(wfocus == 0); |
| 171 | gotoxy(xpos, ypos); |
| 172 | cputsn(w->widget.button.text, w->w); |
| 173 | revers(0); |
| 174 | } |
| 175 | break; |
| 176 | case CTK_WIDGET_TEXTENTRY: |
| 177 | text = w->widget.textentry.text; |
| 178 | xscroll = 0; |
| 179 | if(w->widget.textentry.xpos >= w->w - 1) { |
| 180 | xscroll = w->widget.textentry.xpos - w->w + 1; |
| 181 | } |
| 182 | for(j = 0; j < w->h; ++j) { |
| 183 | if(ypos >= clipy1 && ypos < clipy2) { |
| 184 | if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && |
| 185 | w->widget.textentry.ypos == j) { |
| 186 | revers(0); |
| 187 | cputcxy(xpos, ypos, '>'); |
| 188 | c = 1; |
| 189 | for(i = 0; i < w->w; ++i) { |
| 190 | if(c != 0) { |
| 191 | c = text[i + xscroll]; |
| 192 | } |
| 193 | revers(i == w->widget.textentry.xpos - xscroll); |
| 194 | if(c == 0) { |
| 195 | cputc(' '); |
| 196 | } else { |
| 197 | cputc(c); |
| 198 | } |
| 199 | } |
| 200 | revers(0); |
| 201 | cputc('<'); |
| 202 | } else { |
| 203 | revers(wfocus != 0 && j == w->widget.textentry.ypos); |
| 204 | cvlinexy(xpos, ypos, 1); |
PulkoMandy | c0f22c7 | 2023-05-04 23:02:20 +0200 | [diff] [blame^] | 205 | gotoxy(xpos + 1, ypos); |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 206 | cputsn(text, w->w); |
| 207 | i = wherex(); |
| 208 | if(i - xpos - 1 < w->w) { |
| 209 | cclear(w->w - (i - xpos) + 1); |
| 210 | } |
| 211 | cvline(1); |
| 212 | } |
| 213 | } |
| 214 | ++ypos; |
| 215 | text += w->widget.textentry.len + 1; |
| 216 | } |
| 217 | revers(0); |
| 218 | break; |
| 219 | case CTK_WIDGET_ICON: |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 220 | |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 221 | if(ypos >= clipy1 && ypos < clipy2) { |
| 222 | revers(wfocus != 0); |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 223 | #if CTK_CONF_ICON_BITMAPS |
| 224 | gotoxy(xpos, ypos); |
| 225 | if(w->widget.icon.bitmap != NULL) { |
Adrien Destugues | 69a6e72 | 2017-06-03 10:17:17 +0200 | [diff] [blame] | 226 | const unsigned char* ptr = w->widget.icon.bitmap; |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 227 | for(i = 0; i < 3; ++i) { |
| 228 | gotoxy(xpos, ypos); |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 229 | //gotox(xpos); gotoy(ypos); |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 230 | if(ypos >= clipy1 && ypos < clipy2) { |
| 231 | customchr(ptr); |
| 232 | cputc(0xff); |
| 233 | ptr += 8; |
| 234 | customchr(ptr); |
| 235 | cputc(0xff); |
| 236 | ptr += 8; |
| 237 | customchr(ptr); |
| 238 | cputc(0xff); |
| 239 | ptr += 8; |
| 240 | } |
| 241 | ++ypos; |
| 242 | } |
| 243 | } |
| 244 | #elif CTK_CONF_ICON_TEXTMAPS |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 245 | gotoxy(xpos, ypos); |
| 246 | if(w->widget.icon.textmap != NULL) { |
| 247 | for(i = 0; i < 3; ++i) { |
| 248 | gotoxy(xpos, ypos); |
| 249 | if(ypos >= clipy1 && ypos < clipy2) { |
| 250 | cputc(w->widget.icon.textmap[0 + 3 * i]); |
| 251 | cputc(w->widget.icon.textmap[1 + 3 * i]); |
| 252 | cputc(w->widget.icon.textmap[2 + 3 * i]); |
| 253 | } |
| 254 | ++ypos; |
| 255 | } |
| 256 | } |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 257 | #endif |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 258 | x = xpos; |
| 259 | |
| 260 | len = strlen(w->widget.icon.title); |
| 261 | if(x + len >= sizex) { |
| 262 | x = sizex - len; |
| 263 | } |
| 264 | |
| 265 | gotoxy(x, ypos); |
| 266 | if(ypos >= clipy1 && ypos < clipy2) { |
| 267 | cputs(w->widget.icon.title); |
| 268 | } |
| 269 | revers(0); |
| 270 | } |
| 271 | break; |
| 272 | |
| 273 | default: |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | /*-----------------------------------------------------------------------------------*/ |
| 278 | static void |
| 279 | s_ctk_draw_widget(struct ctk_widget *w, |
| 280 | unsigned char focus, |
| 281 | unsigned char clipy1, |
| 282 | unsigned char clipy2) |
| 283 | { |
| 284 | struct ctk_window *win = w->window; |
| 285 | unsigned char posx, posy; |
| 286 | |
| 287 | posx = win->x + 1; |
| 288 | posy = win->y + 2; |
| 289 | |
| 290 | if(w == win->focused) { |
| 291 | focus |= CTK_FOCUS_WIDGET; |
| 292 | } |
| 293 | |
| 294 | draw_widget(w, posx, posy, |
| 295 | posx + win->w, |
| 296 | posy + win->h, |
| 297 | clipy1, clipy2, |
| 298 | focus); |
| 299 | |
| 300 | #ifdef CTK_CONIO_CONF_UPDATE |
| 301 | CTK_CONIO_CONF_UPDATE(); |
| 302 | #endif /* CTK_CONIO_CONF_UPDATE */ |
| 303 | } |
| 304 | /*-----------------------------------------------------------------------------------*/ |
| 305 | |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 306 | static void clearrect(unsigned char y2, unsigned char x2, |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 307 | unsigned char y1, unsigned char x1) __naked __z88dk_callee |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 308 | { |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 309 | // Y2 is in A |
| 310 | // X2 is in L |
| 311 | // Stack has: |
| 312 | // - Return value |
| 313 | // - Y1 |
| 314 | // - X1 |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 315 | __asm |
PulkoMandy | c0f22c7 | 2023-05-04 23:02:20 +0200 | [diff] [blame^] | 316 | LD d,l |
| 317 | LD e,A |
| 318 | |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 319 | pop bc ; RV |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 320 | pop hl ; x1 y1 |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 321 | push bc |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 322 | |
| 323 | call 0xBB99 ; TXT GET PAPER |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 324 | |
| 325 | ; A contains PAPER number |
| 326 | |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 327 | call 0xBC2C ; SCR INK ENCODE |
| 328 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 329 | ; A contains encoded PEN |
| 330 | |
| 331 | ; Here we need: |
| 332 | ; H = X1 |
| 333 | ; L = Y1 |
| 334 | ; D = X2 |
| 335 | ; E = Y2 |
| 336 | ; A = encoded pen |
| 337 | |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 338 | jp 0xBC44 ; SCR FILL BOX |
| 339 | __endasm; |
| 340 | } |
| 341 | |
| 342 | static void |
| 343 | s_ctk_draw_clear_window(struct ctk_window *window, |
| 344 | unsigned char focus, |
| 345 | unsigned char clipy1, |
| 346 | unsigned char clipy2) |
| 347 | { |
| 348 | unsigned char i; |
| 349 | unsigned char h; |
| 350 | |
| 351 | /* |
| 352 | if(focus & CTK_FOCUS_WINDOW) { |
| 353 | (void)textcolor(WINDOWCOLOR_FOCUS); |
| 354 | } else { |
| 355 | (void)textcolor(WINDOWCOLOR); |
| 356 | } |
| 357 | */ |
| 358 | |
PulkoMandy | 25ff050 | 2014-07-03 09:55:24 +0200 | [diff] [blame] | 359 | i = window->y + 2; // +1 for the border, +1 for ctk > cpc conversion |
| 360 | h = i + window->h; |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 361 | |
PulkoMandy | 0627a36 | 2014-07-03 18:55:34 +0200 | [diff] [blame] | 362 | if (i >= clipy2 || h < clipy1) |
| 363 | return; |
| 364 | |
PulkoMandy | 25ff050 | 2014-07-03 09:55:24 +0200 | [diff] [blame] | 365 | if (i < clipy1) i = clipy1; |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 366 | if (h >= clipy2) h = clipy2 - 1; |
PulkoMandy | 25ff050 | 2014-07-03 09:55:24 +0200 | [diff] [blame] | 367 | |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 368 | clearrect(h, window->x + window->w, i, window->x + 1); |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 369 | } |
| 370 | /*-----------------------------------------------------------------------------------*/ |
| 371 | static void |
| 372 | draw_window_contents(struct ctk_window *window, unsigned char focus, |
| 373 | unsigned char clipy1, unsigned char clipy2, |
| 374 | unsigned char x1, unsigned char x2, |
| 375 | unsigned char y1, unsigned char y2) |
| 376 | { |
| 377 | struct ctk_widget *w; |
| 378 | unsigned char wfocus; |
| 379 | |
| 380 | /* Draw inactive widgets. */ |
| 381 | for(w = window->inactive; w != NULL; w = w->next) { |
| 382 | draw_widget(w, x1, y1, x2, y2, |
| 383 | clipy1, clipy2, |
| 384 | focus); |
| 385 | } |
| 386 | |
| 387 | /* Draw active widgets. */ |
| 388 | for(w = window->active; w != NULL; w = w->next) { |
| 389 | wfocus = focus; |
| 390 | if(w == window->focused) { |
| 391 | wfocus |= CTK_FOCUS_WIDGET; |
| 392 | } |
| 393 | |
| 394 | draw_widget(w, x1, y1, x2, y2, |
| 395 | clipy1, clipy2, |
| 396 | wfocus); |
| 397 | } |
| 398 | |
| 399 | #ifdef CTK_CONIO_CONF_UPDATE |
| 400 | CTK_CONIO_CONF_UPDATE(); |
| 401 | #endif /* CTK_CONIO_CONF_UPDATE */ |
| 402 | } |
| 403 | /*-----------------------------------------------------------------------------------*/ |
| 404 | static void |
| 405 | s_ctk_draw_window(struct ctk_window *window, unsigned char focus, |
| 406 | unsigned char clipy1, unsigned char clipy2, |
| 407 | unsigned char draw_borders) |
| 408 | { |
| 409 | unsigned char x, y; |
| 410 | unsigned char h; |
| 411 | unsigned char x1, y1, x2, y2; |
| 412 | |
| 413 | if(window->y + 1 >= clipy2) { |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | x = window->x; |
| 418 | y = window->y + 1; |
| 419 | x1 = x + 1; |
| 420 | y1 = y + 1; |
| 421 | x2 = x1 + window->w; |
| 422 | y2 = y1 + window->h; |
| 423 | |
| 424 | if(draw_borders) { |
| 425 | |
| 426 | /* Draw window frame. */ |
| 427 | if(focus & CTK_FOCUS_WINDOW) { |
| 428 | (void)textcolor(WINDOWCOLOR_FOCUS); |
| 429 | } else { |
| 430 | (void)textcolor(WINDOWCOLOR); |
| 431 | } |
| 432 | |
| 433 | if(y >= clipy1) { |
| 434 | cputcxy(x, y, CH_ULCORNER); |
| 435 | gotoxy(wherex() + window->titlelen + CTK_CONF_WINDOWMOVE * 2, wherey()); |
| 436 | chline(window->w - (wherex() - x) - 2); |
| 437 | cputcxy(x2, y, CH_URCORNER); |
| 438 | } |
| 439 | |
| 440 | h = window->h; |
| 441 | |
| 442 | if(clipy1 > y1) { |
| 443 | if(clipy1 - y1 < h) { |
| 444 | h = clipy1 - y1; |
| 445 | y1 = clipy1; |
| 446 | } else { |
| 447 | h = 0; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | if(clipy2 < y1 + h) { |
| 452 | if(y1 >= clipy2) { |
| 453 | h = 0; |
| 454 | } else { |
| 455 | h = clipy2 - y1; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | cvlinexy(x, y1, h); |
| 460 | cvlinexy(x2, y1, h); |
| 461 | |
| 462 | if(y + window->h >= clipy1 && |
| 463 | y + window->h < clipy2) { |
| 464 | cputcxy(x, y2, CH_LLCORNER); |
| 465 | chlinexy(x1, y2, window->w); |
| 466 | cputcxy(x2, y2, CH_LRCORNER); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | draw_window_contents(window, focus, clipy1, clipy2, |
| 471 | x1, x2, y + 1, y2); |
| 472 | } |
| 473 | /*-----------------------------------------------------------------------------------*/ |
| 474 | static void |
| 475 | s_ctk_draw_dialog(struct ctk_window *dialog) |
| 476 | { |
| 477 | unsigned char x, y; |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 478 | unsigned char x1, y1, x2, y2; |
| 479 | |
| 480 | (void)textcolor(DIALOGCOLOR); |
| 481 | |
| 482 | x = dialog->x; |
| 483 | y = dialog->y + 1; |
| 484 | |
| 485 | x1 = x + 1; |
| 486 | y1 = y + 1; |
| 487 | x2 = x1 + dialog->w; |
| 488 | y2 = y1 + dialog->h; |
| 489 | |
| 490 | /* Draw dialog frame. */ |
| 491 | cvlinexy(x, y1, |
| 492 | dialog->h); |
| 493 | cvlinexy(x2, y1, |
| 494 | dialog->h); |
| 495 | |
| 496 | chlinexy(x1, y, |
| 497 | dialog->w); |
| 498 | chlinexy(x1, y2, |
| 499 | dialog->w); |
| 500 | |
| 501 | cputcxy(x, y, CH_ULCORNER); |
| 502 | cputcxy(x, y2, CH_LLCORNER); |
| 503 | cputcxy(x2, y, CH_URCORNER); |
| 504 | cputcxy(x2, y2, CH_LRCORNER); |
| 505 | |
| 506 | /* Clear dialog contents. */ |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 507 | clearrect(y2 - 1, x1 + dialog->w - 1, y1, x1); |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 508 | |
| 509 | draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, |
| 510 | x1, x2, y1, y2); |
| 511 | } |
| 512 | /*-----------------------------------------------------------------------------------*/ |
| 513 | static void |
| 514 | s_ctk_draw_clear(unsigned char y1, unsigned char y2) __naked |
| 515 | { |
| 516 | __asm |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 517 | pop de |
| 518 | pop hl |
| 519 | push hl |
| 520 | push de |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 521 | |
| 522 | push af |
| 523 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 524 | ld e,h |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 525 | ld h,#1 |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 526 | ld d,#40 |
| 527 | |
PulkoMandy | 0627a36 | 2014-07-03 18:55:34 +0200 | [diff] [blame] | 528 | dec e |
PulkoMandy | c53d0f6 | 2014-07-01 22:35:10 +0200 | [diff] [blame] | 529 | |
| 530 | call 0xBB99 ; TXT GET PAPER |
| 531 | call 0xBC2C ; SCR INK ENCODE |
| 532 | |
| 533 | call 0xBC44 ; SCR FILL BOX |
| 534 | |
| 535 | pop af |
| 536 | ret |
| 537 | __endasm; |
| 538 | } |
| 539 | /*-----------------------------------------------------------------------------------*/ |
| 540 | static void |
| 541 | draw_menu(struct ctk_menu *m, unsigned char open) |
| 542 | { |
| 543 | unsigned char x, x2, y; |
| 544 | |
| 545 | if(open) { |
| 546 | x = x2 = wherex(); |
| 547 | if(x2 + CTK_CONF_MENUWIDTH > sizex) { |
| 548 | x2 = sizex - CTK_CONF_MENUWIDTH; |
| 549 | } |
| 550 | |
| 551 | for(y = 0; y < m->nitems; ++y) { |
| 552 | if(y == m->active) { |
| 553 | (void)textcolor(ACTIVEMENUITEMCOLOR); |
| 554 | } else { |
| 555 | (void)textcolor(SCREENCOLOR); |
| 556 | } |
| 557 | gotoxy(x2, y + 1); |
| 558 | if(m->items[y].title[0] == '-') { |
| 559 | chline(CTK_CONF_MENUWIDTH); |
| 560 | } else { |
| 561 | cputs(m->items[y].title); |
| 562 | } |
| 563 | if(x2 + CTK_CONF_MENUWIDTH > wherex()) { |
| 564 | cclear(x2 + CTK_CONF_MENUWIDTH - wherex()); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | gotoxy(x, 0); |
| 569 | (void)textcolor(OPENMENUCOLOR); |
| 570 | } |
| 571 | |
| 572 | cputs(m->title); |
| 573 | cputc(' '); |
| 574 | } |
| 575 | /*-----------------------------------------------------------------------------------*/ |
| 576 | static void |
| 577 | s_ctk_draw_menus(struct ctk_menus *menus) |
| 578 | { |
| 579 | struct ctk_menu *m; |
| 580 | |
| 581 | /* Draw menus */ |
| 582 | (void)bgcolor(MENUCOLOR); |
| 583 | (void)textcolor(SCREENCOLOR); |
| 584 | gotoxy(0, 0); |
| 585 | cputc(' '); |
| 586 | for(m = menus->menus->next; m != NULL; m = m->next) { |
| 587 | draw_menu(m, m == menus->open); |
| 588 | } |
| 589 | |
| 590 | /* Draw desktopmenu */ |
| 591 | if(wherex() + strlen(menus->desktopmenu->title) + 1 >= sizex) { |
| 592 | gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); |
| 593 | } else { |
| 594 | cclear(sizex - wherex() - |
| 595 | strlen(menus->desktopmenu->title) - 1); |
| 596 | } |
| 597 | draw_menu(menus->desktopmenu, menus->desktopmenu == menus->open); |
| 598 | |
| 599 | (void)bgcolor(SCREENCOLOR); |
| 600 | } |
| 601 | /*-----------------------------------------------------------------------------------*/ |
| 602 | static unsigned char |
| 603 | s_ctk_draw_height(void) |
| 604 | { |
| 605 | return sizey; |
| 606 | } |
| 607 | /*-----------------------------------------------------------------------------------*/ |
| 608 | static unsigned char |
| 609 | s_ctk_draw_width(void) |
| 610 | { |
| 611 | return sizex; |
| 612 | } |
| 613 | /*-----------------------------------------------------------------------------------*/ |
| 614 | static unsigned short |
| 615 | s_ctk_mouse_xtoc(unsigned short x) |
| 616 | { |
| 617 | return x / 8; |
| 618 | } |
| 619 | /*-----------------------------------------------------------------------------------*/ |
| 620 | static unsigned short |
| 621 | s_ctk_mouse_ytoc(unsigned short y) |
| 622 | { |
| 623 | return y / 8; |
| 624 | } |
| 625 | /*-----------------------------------------------------------------------------------*/ |
| 626 | static const struct ctk_draw_service_interface interface = |
| 627 | {CTK_DRAW_SERVICE_VERSION, |
| 628 | 1, |
| 629 | 1, |
| 630 | 1, |
| 631 | s_ctk_draw_init, |
| 632 | s_ctk_draw_clear, |
| 633 | s_ctk_draw_clear_window, |
| 634 | s_ctk_draw_window, |
| 635 | s_ctk_draw_dialog, |
| 636 | s_ctk_draw_widget, |
| 637 | s_ctk_draw_menus, |
| 638 | s_ctk_draw_width, |
| 639 | s_ctk_draw_height, |
| 640 | s_ctk_mouse_xtoc, |
| 641 | s_ctk_mouse_ytoc, |
| 642 | }; |
| 643 | |
| 644 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 645 | EK_PROCESS(proc, CTK_DRAW_SERVICE_NAME ": text", EK_PRIO_NORMAL, |
| 646 | eventhandler, NULL, (void *)&interface); |
| 647 | |
| 648 | /*--------------------------------------------------------------------------*/ |
| 649 | LOADER_INIT_FUNC(ctk_conio_service_init, arg) |
| 650 | { |
| 651 | s_ctk_draw_init(); |
| 652 | ek_service_start(CTK_DRAW_SERVICE_NAME, &proc); |
| 653 | } |
| 654 | /*--------------------------------------------------------------------------*/ |
| 655 | EK_EVENTHANDLER(eventhandler, ev, data) |
| 656 | { |
| 657 | EK_EVENTHANDLER_ARGS(ev, data); |
| 658 | |
| 659 | switch(ev) { |
| 660 | case EK_EVENT_INIT: |
| 661 | case EK_EVENT_REPLACE: |
| 662 | s_ctk_draw_init(); |
| 663 | ctk_restore(); |
| 664 | break; |
| 665 | case EK_EVENT_REQUEST_REPLACE: |
| 666 | ek_replace((struct ek_proc *)data, NULL); |
| 667 | LOADER_UNLOAD(); |
| 668 | break; |
| 669 | } |
| 670 | } |
| 671 | /*--------------------------------------------------------------------------*/ |