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