blob: 5233899a359ce81d9d72e67211c7a2d2cedd2133 [file] [log] [blame]
adamdunkels7e4982c2003-03-19 16:26:18 +00001/*
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. All advertising materials mentioning features or use of this
15 * software must display the following acknowledgement:
16 * This product includes software developed by Adam Dunkels.
17 * 4. The name of the author may not be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * This file is part of the "ctk" console GUI toolkit for cc65
34 *
adamdunkels23b30d52003-08-15 18:46:25 +000035 * $Id: ctk-hires.c,v 1.6 2003/08/15 18:46:25 adamdunkels Exp $
adamdunkels7e4982c2003-03-19 16:26:18 +000036 *
37 */
adamdunkels77e47062003-04-17 15:09:31 +000038
adamdunkels7e4982c2003-03-19 16:26:18 +000039#include "ctk.h"
40#include "ctk-draw.h"
adamdunkels77e47062003-04-17 15:09:31 +000041#include "ctk-hires.h"
42#include "ctk-hires-asm.h"
43
44#include "ctk-hires-theme.h"
adamdunkels7e4982c2003-03-19 16:26:18 +000045
46#include <string.h>
47
48#ifndef NULL
49#define NULL (void *)0
50#endif /* NULL */
51
52#define SCREEN_HEIGHT 25
53#define SCREEN_WIDTH 40
54
55#define SCREENADDR 0xdc00
56#define HIRESADDR 0xe000
57
58static unsigned char lineptr;
59
adamdunkels77e47062003-04-17 15:09:31 +000060unsigned char ctk_hires_cursx, ctk_hires_cursy;
61unsigned char ctk_hires_reversed;
62unsigned char ctk_hires_color;
63unsigned char ctk_hires_underline;
adamdunkels7e4982c2003-03-19 16:26:18 +000064
adamdunkelsc1c84be2003-08-09 13:26:22 +000065/*static unsigned char cchar;
adamdunkels7e4982c2003-03-19 16:26:18 +000066
67static unsigned char tmp01;
68static unsigned char tmph, tmpl, tmpborder;
adamdunkelsc1c84be2003-08-09 13:26:22 +000069static unsigned char *tmpptr;*/
adamdunkels7e4982c2003-03-19 16:26:18 +000070
71
72static unsigned char x, y, i;
adamdunkelsc1c84be2003-08-09 13:26:22 +000073/*static unsigned char h;*/
adamdunkels7e4982c2003-03-19 16:26:18 +000074static unsigned char wfocus;
75static unsigned char x1, y1, x2, y2;
76
adamdunkels77e47062003-04-17 15:09:31 +000077struct ctk_hires_windowparams ctk_hires_windowparams;
78unsigned char *ctk_hires_bitmapptr;
adamdunkels7e4982c2003-03-19 16:26:18 +000079/*-----------------------------------------------------------------------------------*/
80/* Tables. */
81
adamdunkels77e47062003-04-17 15:09:31 +000082unsigned short ctk_hires_yscreenaddr[25] =
adamdunkels7e4982c2003-03-19 16:26:18 +000083 {0 * SCREEN_WIDTH + SCREENADDR, 1 * SCREEN_WIDTH + SCREENADDR,
84 2 * SCREEN_WIDTH + SCREENADDR, 3 * SCREEN_WIDTH + SCREENADDR,
85 4 * SCREEN_WIDTH + SCREENADDR, 5 * SCREEN_WIDTH + SCREENADDR,
86 6 * SCREEN_WIDTH + SCREENADDR, 7 * SCREEN_WIDTH + SCREENADDR,
87 8 * SCREEN_WIDTH + SCREENADDR, 9 * SCREEN_WIDTH + SCREENADDR,
88 10 * SCREEN_WIDTH + SCREENADDR, 11 * SCREEN_WIDTH + SCREENADDR,
89 12 * SCREEN_WIDTH + SCREENADDR, 13 * SCREEN_WIDTH + SCREENADDR,
90 14 * SCREEN_WIDTH + SCREENADDR, 15 * SCREEN_WIDTH + SCREENADDR,
91 16 * SCREEN_WIDTH + SCREENADDR, 17 * SCREEN_WIDTH + SCREENADDR,
92 18 * SCREEN_WIDTH + SCREENADDR, 19 * SCREEN_WIDTH + SCREENADDR,
93 20 * SCREEN_WIDTH + SCREENADDR, 21 * SCREEN_WIDTH + SCREENADDR,
94 22 * SCREEN_WIDTH + SCREENADDR, 23 * SCREEN_WIDTH + SCREENADDR,
95 24 * SCREEN_WIDTH + SCREENADDR};
96
adamdunkels77e47062003-04-17 15:09:31 +000097unsigned short ctk_hires_yhiresaddr[25] =
adamdunkels7e4982c2003-03-19 16:26:18 +000098 {0 * 320 + HIRESADDR, 1 * 320 + HIRESADDR,
99 2 * 320 + HIRESADDR, 3 * 320 + HIRESADDR,
100 4 * 320 + HIRESADDR, 5 * 320 + HIRESADDR,
101 6 * 320 + HIRESADDR, 7 * 320 + HIRESADDR,
102 8 * 320 + HIRESADDR, 9 * 320 + HIRESADDR,
103 10 * 320 + HIRESADDR, 11 * 320 + HIRESADDR,
104 12 * 320 + HIRESADDR, 13 * 320 + HIRESADDR,
105 14 * 320 + HIRESADDR, 15 * 320 + HIRESADDR,
106 16 * 320 + HIRESADDR, 17 * 320 + HIRESADDR,
107 18 * 320 + HIRESADDR, 19 * 320 + HIRESADDR,
108 20 * 320 + HIRESADDR, 21 * 320 + HIRESADDR,
109 22 * 320 + HIRESADDR, 23 * 320 + HIRESADDR,
110 24 * 320 + HIRESADDR};
adamdunkels77e47062003-04-17 15:09:31 +0000111extern struct ctk_hires_theme ctk_hires_theme;
112struct ctk_hires_theme *ctk_hires_theme_ptr = &ctk_hires_theme;
adamdunkels7e4982c2003-03-19 16:26:18 +0000113/*-----------------------------------------------------------------------------------*/
adamdunkels77e47062003-04-17 15:09:31 +0000114#define hires_wherex() ctk_hires_cursx
115#define hires_revers(c) ctk_hires_reversed = c
116#define hires_color(c) ctk_hires_color = c
117#define hires_underline(c) ctk_hires_underline = c
adamdunkels7e4982c2003-03-19 16:26:18 +0000118/*-----------------------------------------------------------------------------------*/
adamdunkelsc1c84be2003-08-09 13:26:22 +0000119static void __fastcall__
adamdunkels7e4982c2003-03-19 16:26:18 +0000120hires_cvline(unsigned char length)
121{
adamdunkels23b30d52003-08-15 18:46:25 +0000122 static unsigned char i;
adamdunkels7e4982c2003-03-19 16:26:18 +0000123
124 for(i = 0; i < length; ++i) {
adamdunkels77e47062003-04-17 15:09:31 +0000125 ctk_hires_cputc('|');
126 --ctk_hires_cursx;
127 ++ctk_hires_cursy;
adamdunkels7e4982c2003-03-19 16:26:18 +0000128 }
129}
130/*-----------------------------------------------------------------------------------*/
adamdunkelsc1c84be2003-08-09 13:26:22 +0000131static void __fastcall__
adamdunkels7e4982c2003-03-19 16:26:18 +0000132hires_gotoxy(unsigned char x, unsigned char y)
133{
adamdunkels77e47062003-04-17 15:09:31 +0000134 ctk_hires_cursx = x;
135 ctk_hires_cursy = y;
adamdunkels7e4982c2003-03-19 16:26:18 +0000136}
137/*-----------------------------------------------------------------------------------*/
adamdunkelsc1c84be2003-08-09 13:26:22 +0000138static void __fastcall__
adamdunkels7e4982c2003-03-19 16:26:18 +0000139hires_cclearxy(unsigned char x, unsigned char y, unsigned char length)
140{
141 hires_gotoxy(x, y);
adamdunkels77e47062003-04-17 15:09:31 +0000142 ctk_hires_cclear(length);
adamdunkels7e4982c2003-03-19 16:26:18 +0000143}
144/*-----------------------------------------------------------------------------------*/
adamdunkelsc1c84be2003-08-09 13:26:22 +0000145static void __fastcall__
adamdunkels7e4982c2003-03-19 16:26:18 +0000146hires_chlinexy(unsigned char x, unsigned char y, unsigned char length)
147{
148 hires_gotoxy(x, y);
adamdunkels77e47062003-04-17 15:09:31 +0000149 ctk_hires_chline(length);
adamdunkels7e4982c2003-03-19 16:26:18 +0000150}
151/*-----------------------------------------------------------------------------------*/
adamdunkelsc1c84be2003-08-09 13:26:22 +0000152static void __fastcall__
adamdunkels7e4982c2003-03-19 16:26:18 +0000153hires_cvlinexy(unsigned char x, unsigned char y, unsigned char length)
154{
155 hires_gotoxy(x, y);
156 hires_cvline(length);
157}
158/*-----------------------------------------------------------------------------------*/
adamdunkelsc1c84be2003-08-09 13:26:22 +0000159static void __fastcall__
adamdunkels7e4982c2003-03-19 16:26:18 +0000160hires_cputcxy(unsigned char x, unsigned char y, char c)
161{
162 hires_gotoxy(x, y);
adamdunkels77e47062003-04-17 15:09:31 +0000163 ctk_hires_cputc(c);
adamdunkels7e4982c2003-03-19 16:26:18 +0000164}
165/*-----------------------------------------------------------------------------------*/
adamdunkelsc1c84be2003-08-09 13:26:22 +0000166static void
adamdunkels7e4982c2003-03-19 16:26:18 +0000167clear_line(unsigned char line)
168{
169 lineptr = line;
adamdunkels77e47062003-04-17 15:09:31 +0000170 asm("lda %v", lineptr);
adamdunkels7e4982c2003-03-19 16:26:18 +0000171 asm("asl");
172 asm("tax");
adamdunkels77e47062003-04-17 15:09:31 +0000173 asm("lda %v,x", ctk_hires_yhiresaddr);
adamdunkels7e4982c2003-03-19 16:26:18 +0000174 asm("sta ptr2");
adamdunkels77e47062003-04-17 15:09:31 +0000175 asm("lda %v+1,x", ctk_hires_yhiresaddr);
adamdunkels7e4982c2003-03-19 16:26:18 +0000176 asm("sta ptr2+1");
adamdunkels77e47062003-04-17 15:09:31 +0000177 asm("lda %v,x", ctk_hires_yscreenaddr);
adamdunkels7e4982c2003-03-19 16:26:18 +0000178 asm("sta ptr1");
adamdunkels77e47062003-04-17 15:09:31 +0000179 asm("lda %v+1,x", ctk_hires_yscreenaddr);
adamdunkels7e4982c2003-03-19 16:26:18 +0000180 asm("sta ptr1+1");
181
182
183 asm("sei");
184 asm("lda $01");
185 asm("pha");
186 asm("lda #$30");
187 asm("sta $01");
188 asm("ldy #39");
adamdunkels77e47062003-04-17 15:09:31 +0000189 asm("ldx %v", lineptr);
190 asm("lda %v+%w,x", ctk_hires_theme,
191 offsetof(struct ctk_hires_theme, backgroundpatterncolors));
adamdunkels7e4982c2003-03-19 16:26:18 +0000192 asm("clearlineloop1:");
193 asm("sta (ptr1),y");
194 asm("dey");
195 asm("bpl clearlineloop1");
196 asm("pla");
197 asm("sta $01");
198 asm("cli");
199
200
adamdunkels77e47062003-04-17 15:09:31 +0000201 asm("lda %v", lineptr);
202 /* asm("and #7");*/
adamdunkels7e4982c2003-03-19 16:26:18 +0000203 asm("asl");
adamdunkels77e47062003-04-17 15:09:31 +0000204 asm("asl");
adamdunkels7e4982c2003-03-19 16:26:18 +0000205 asm("asl");
206 asm("tax");
207 asm("ldy #0");
208 asm("clearlineloop2:");
adamdunkels77e47062003-04-17 15:09:31 +0000209 asm("lda %v+%w+0,x", ctk_hires_theme,
210 offsetof(struct ctk_hires_theme, backgroundpattern));
adamdunkels7e4982c2003-03-19 16:26:18 +0000211 asm("sta (ptr2),y");
212 asm("iny");
adamdunkels77e47062003-04-17 15:09:31 +0000213 asm("lda %v+%w+1,x", ctk_hires_theme,
214 offsetof(struct ctk_hires_theme, backgroundpattern));
adamdunkels7e4982c2003-03-19 16:26:18 +0000215 asm("sta (ptr2),y");
216 asm("iny");
adamdunkels77e47062003-04-17 15:09:31 +0000217 asm("lda %v+%w+2,x", ctk_hires_theme,
218 offsetof(struct ctk_hires_theme, backgroundpattern));
adamdunkels7e4982c2003-03-19 16:26:18 +0000219 asm("sta (ptr2),y");
220 asm("iny");
adamdunkels77e47062003-04-17 15:09:31 +0000221 asm("lda %v+%w+3,x", ctk_hires_theme,
222 offsetof(struct ctk_hires_theme, backgroundpattern));
adamdunkels7e4982c2003-03-19 16:26:18 +0000223 asm("sta (ptr2),y");
224 asm("iny");
adamdunkels77e47062003-04-17 15:09:31 +0000225 asm("lda %v+%w+4,x", ctk_hires_theme,
226 offsetof(struct ctk_hires_theme, backgroundpattern));
227 asm("sta (ptr2),y");
228 asm("iny");
229 asm("lda %v+%w+5,x", ctk_hires_theme,
230 offsetof(struct ctk_hires_theme, backgroundpattern));
231 asm("sta (ptr2),y");
232 asm("iny");
233 asm("lda %v+%w+6,x", ctk_hires_theme,
234 offsetof(struct ctk_hires_theme, backgroundpattern));
235 asm("sta (ptr2),y");
236 asm("iny");
237 asm("lda %v+%w+7,x", ctk_hires_theme,
238 offsetof(struct ctk_hires_theme, backgroundpattern));
239 asm("sta (ptr2),y");
240 asm("iny");
adamdunkels7e4982c2003-03-19 16:26:18 +0000241 asm("bne clearlineloop2");
242
243 asm("inc ptr2+1");
244
245 asm("ldy #0");
246 asm("clearlineloop3:");
adamdunkels77e47062003-04-17 15:09:31 +0000247 asm("lda %v+%w+0,x", ctk_hires_theme,
248 offsetof(struct ctk_hires_theme, backgroundpattern));
adamdunkels7e4982c2003-03-19 16:26:18 +0000249 asm("sta (ptr2),y");
250 asm("iny");
adamdunkels77e47062003-04-17 15:09:31 +0000251 asm("lda %v+%w+1,x", ctk_hires_theme,
252 offsetof(struct ctk_hires_theme, backgroundpattern));
adamdunkels7e4982c2003-03-19 16:26:18 +0000253 asm("sta (ptr2),y");
254 asm("iny");
adamdunkels77e47062003-04-17 15:09:31 +0000255 asm("lda %v+%w+2,x", ctk_hires_theme,
256 offsetof(struct ctk_hires_theme, backgroundpattern));
adamdunkels7e4982c2003-03-19 16:26:18 +0000257 asm("sta (ptr2),y");
258 asm("iny");
adamdunkels77e47062003-04-17 15:09:31 +0000259 asm("lda %v+%w+3,x", ctk_hires_theme,
260 offsetof(struct ctk_hires_theme, backgroundpattern));
adamdunkels7e4982c2003-03-19 16:26:18 +0000261 asm("sta (ptr2),y");
262 asm("iny");
adamdunkels77e47062003-04-17 15:09:31 +0000263 asm("lda %v+%w+4,x", ctk_hires_theme,
264 offsetof(struct ctk_hires_theme, backgroundpattern));
265 asm("sta (ptr2),y");
266 asm("iny");
267 asm("lda %v+%w+5,x", ctk_hires_theme,
268 offsetof(struct ctk_hires_theme, backgroundpattern));
269 asm("sta (ptr2),y");
270 asm("iny");
271 asm("lda %v+%w+6,x", ctk_hires_theme,
272 offsetof(struct ctk_hires_theme, backgroundpattern));
273 asm("sta (ptr2),y");
274 asm("iny");
275 asm("lda %v+%w+7,x", ctk_hires_theme,
276 offsetof(struct ctk_hires_theme, backgroundpattern));
277 asm("sta (ptr2),y");
278 asm("iny");
adamdunkels7e4982c2003-03-19 16:26:18 +0000279 asm("cpy #$40");
280 asm("bne clearlineloop3");
281
282}
283/*-----------------------------------------------------------------------------------*/
284static void
285nmi2(void)
286{
287 asm("pla");
288 asm("sta $01");
289 asm("pla");
290 asm("rti");
291}
292/*-----------------------------------------------------------------------------------*/
293static void
294nmi(void)
295{
296 asm("sei");
297 asm("pha");
298 asm("inc $d020");
299 asm("lda $01");
300 asm("pha");
301 asm("lda #$36");
302 asm("sta $01");
303 asm("lda #>_nmi2");
304 asm("pha");
305 asm("lda #<_nmi2");
306 asm("pha");
307 asm("php");
308 asm("jmp ($0318)");
309
310 nmi2();
311}
312/*-----------------------------------------------------------------------------------*/
313static void
314setup_nmi(void)
315{
316 asm("lda #<_nmi");
317 asm("sta $fffa");
318 asm("lda #>_nmi");
319 asm("sta $fffb");
320 return;
321 nmi();
322}
323/*-----------------------------------------------------------------------------------*/
324void
325ctk_draw_init(void)
326{
adamdunkels77e47062003-04-17 15:09:31 +0000327 unsigned char i, *ptr1, *ptr2;
328
adamdunkels7e4982c2003-03-19 16:26:18 +0000329 setup_nmi();
330
331 /* Turn on hires mode, bank 0 ($c000 - $ffff) and $e000/$c000 for
332 hires/colors. */
333 VIC.ctrl1 = 0x3b; /* $D011 */
334 VIC.addr = 0x78; /* $D018 */
335 VIC.ctrl2 = 0xc8; /* $D016 */
adamdunkels7e4982c2003-03-19 16:26:18 +0000336 CIA2.pra = 0x00; /* $DD00 */
337
adamdunkels77e47062003-04-17 15:09:31 +0000338 VIC.bordercolor = ctk_hires_theme.bordercolor; /* $D020 */
339 VIC.bgcolor0 = ctk_hires_theme.screencolor; /* $D021 */
340
adamdunkels7e4982c2003-03-19 16:26:18 +0000341 /* Fill color memory. */
342 asm("sei");
343 asm("lda $01");
344 asm("pha");
345 asm("lda #$30");
346 asm("sta $01");
347 asm("ldx #0");
348 asm("lda #$c0");
349 asm("fillcolorloop:");
350 asm("sta $dc00,x");
351 asm("sta $dd00,x");
352 asm("sta $de00,x");
353 asm("sta $df00,x");
354 asm("inx");
355 asm("bne fillcolorloop");
adamdunkels77e47062003-04-17 15:09:31 +0000356
357 /* Setup sprite pointers */
358 asm("ldx #$fd");
359 asm("stx $dff8");
360 asm("inx");
361 asm("stx $dff9");
adamdunkels7e4982c2003-03-19 16:26:18 +0000362 asm("pla");
363 asm("sta $01");
364 asm("cli");
365
366 /* Fill hires memory with 0. */
367
368 asm("lda $fd");
369 asm("pha");
370 asm("lda $fe");
371 asm("pha");
372 asm("lda #0");
373 asm("sta $fd");
374 asm("lda #$e0");
375 asm("sta $fe");
376 asm("ldy #0");
377 asm("lda #0");
378 asm("clrscrnloop:");
379 asm("lda #$55");
380 asm("sta ($fd),y");
381 asm("iny");
382 asm("lda #$aa");
383 asm("sta ($fd),y");
384 asm("iny");
385 asm("bne clrscrnloop");
386 asm("inc $fe");
387 asm("lda $fe");
388 asm("cmp #$ff");
389 asm("bne clrscrnloop");
390
391 asm("ldy #$00");
392 asm("clrscrnloop2:");
393 asm("lda #$55");
394 asm("sta $ff00,y");
395 asm("iny");
396 asm("lda #$aa");
397 asm("sta $ff00,y");
398 asm("iny");
399 asm("cpy #$40");
400 asm("bne clrscrnloop2");
401
402
403 asm("pla");
404 asm("sta $fe");
405 asm("pla");
406 asm("sta $fd");
407
adamdunkels7e4982c2003-03-19 16:26:18 +0000408
adamdunkels77e47062003-04-17 15:09:31 +0000409 ctk_draw_clear(0, SCREEN_HEIGHT);
410
411 /* Setup mouse pointer sprite. */
412 asm("lda %v+%w", ctk_hires_theme,
413 offsetof(struct ctk_hires_theme, pointermaskcolor));
414 asm("sta $d027");
415 asm("lda %v+%w", ctk_hires_theme,
416 offsetof(struct ctk_hires_theme, pointercolor));
417 asm("sta $d028");
418
419 ptr1 = ctk_hires_theme.pointer;
420 ptr2 = (unsigned char *)0xff40;
421
422 for(i = 0; i < 0x80; ++i) {
423 *ptr2++ = *ptr1++;
424 }
425
adamdunkels7e4982c2003-03-19 16:26:18 +0000426 return;
427}
428/*-----------------------------------------------------------------------------------*/
adamdunkelsc1c84be2003-08-09 13:26:22 +0000429static void __fastcall__
adamdunkelsd7422082003-08-05 13:57:01 +0000430draw_widget(register struct ctk_widget *w,
adamdunkels7e4982c2003-03-19 16:26:18 +0000431 unsigned char x, unsigned char y,
432 unsigned char clipy1, unsigned char clipy2,
433 unsigned char focus)
434{
adamdunkels23b30d52003-08-15 18:46:25 +0000435 static unsigned char xpos, ypos, xscroll;
436 static unsigned char i;
437 static char c;
438 static unsigned char len;
439 char *text;
440
adamdunkels7e4982c2003-03-19 16:26:18 +0000441 xpos = x + w->x;
442 ypos = y + w->y;
adamdunkels7e4982c2003-03-19 16:26:18 +0000443
444 switch(w->type) {
445 case CTK_WIDGET_SEPARATOR:
adamdunkels77e47062003-04-17 15:09:31 +0000446 hires_color(ctk_hires_theme.separatorcolors[focus]);
adamdunkels7e4982c2003-03-19 16:26:18 +0000447 if(ypos >= clipy1 && ypos < clipy2) {
448 hires_chlinexy(xpos, ypos, w->w);
449 }
450 break;
451 case CTK_WIDGET_LABEL:
adamdunkels77e47062003-04-17 15:09:31 +0000452 hires_color(ctk_hires_theme.labelcolors[focus]);
adamdunkels7e4982c2003-03-19 16:26:18 +0000453 text = w->widget.label.text;
adamdunkels41343612003-07-31 23:23:25 +0000454 for(i = 0; i < w->h; ++i) {
adamdunkels7e4982c2003-03-19 16:26:18 +0000455 if(ypos >= clipy1 && ypos < clipy2) {
456 hires_gotoxy(xpos, ypos);
adamdunkels77e47062003-04-17 15:09:31 +0000457 ctk_hires_cputsn(text, w->w);
adamdunkels7e4982c2003-03-19 16:26:18 +0000458 if(w->w - (hires_wherex() - xpos) > 0) {
adamdunkels77e47062003-04-17 15:09:31 +0000459 ctk_hires_cclear(w->w - (hires_wherex() - xpos));
adamdunkels7e4982c2003-03-19 16:26:18 +0000460 }
461 }
462 ++ypos;
463 text += w->w;
464 }
465 break;
466 case CTK_WIDGET_BUTTON:
467 if(ypos >= clipy1 && ypos < clipy2) {
adamdunkels77e47062003-04-17 15:09:31 +0000468 hires_color(ctk_hires_theme.buttonleftcolors[focus]);
adamdunkels7e4982c2003-03-19 16:26:18 +0000469 hires_gotoxy(xpos, ypos);
adamdunkels77e47062003-04-17 15:09:31 +0000470 ctk_hires_draw_buttonleft();
471 hires_color(ctk_hires_theme.buttoncolors[focus]);
adamdunkels7e4982c2003-03-19 16:26:18 +0000472 hires_gotoxy(xpos + 1, ypos);
adamdunkels77e47062003-04-17 15:09:31 +0000473 ctk_hires_cputsn(w->widget.button.text, w->w);
474 hires_color(ctk_hires_theme.buttonrightcolors[focus]);
475 ctk_hires_draw_buttonright();
adamdunkels7e4982c2003-03-19 16:26:18 +0000476 }
477 break;
478 case CTK_WIDGET_HYPERLINK:
479 if(ypos >= clipy1 && ypos < clipy2) {
adamdunkels77e47062003-04-17 15:09:31 +0000480 hires_color(ctk_hires_theme.hyperlinkcolors[focus]);
adamdunkels7e4982c2003-03-19 16:26:18 +0000481 hires_underline(1);
482 hires_gotoxy(xpos, ypos);
adamdunkels77e47062003-04-17 15:09:31 +0000483 ctk_hires_cputsn(w->widget.button.text, w->w);
adamdunkels7e4982c2003-03-19 16:26:18 +0000484 hires_underline(0);
485 }
486 break;
487 case CTK_WIDGET_TEXTENTRY:
adamdunkels77e47062003-04-17 15:09:31 +0000488 hires_color(ctk_hires_theme.textentrycolors[focus]);
adamdunkels7e4982c2003-03-19 16:26:18 +0000489 text = w->widget.textentry.text;
490 if(focus & CTK_FOCUS_WIDGET &&
491 w->widget.textentry.state != CTK_TEXTENTRY_EDIT) {
492 hires_revers(1);
493 } else {
494 hires_revers(0);
495 }
496 xscroll = 0;
497 if(w->widget.textentry.xpos >= w->w - 1) {
498 xscroll = w->widget.textentry.xpos - w->w + 1;
499 }
adamdunkels77e47062003-04-17 15:09:31 +0000500 if(ypos >= clipy1 && ypos < clipy2) {
501 if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT) {
502 hires_revers(0);
503 hires_cputcxy(xpos, ypos, '>');
504 for(i = 0; i < w->w; ++i) {
505 c = text[i + xscroll];
506 if(i == w->widget.textentry.xpos - xscroll) {
507 hires_revers(1);
508 } else {
adamdunkels7e4982c2003-03-19 16:26:18 +0000509 hires_revers(0);
510 }
adamdunkels77e47062003-04-17 15:09:31 +0000511 if(c == 0) {
512 ctk_hires_cputc(' ');
513 } else {
514 ctk_hires_cputc(c);
adamdunkels7e4982c2003-03-19 16:26:18 +0000515 }
adamdunkels77e47062003-04-17 15:09:31 +0000516 hires_revers(0);
adamdunkels7e4982c2003-03-19 16:26:18 +0000517 }
adamdunkels77e47062003-04-17 15:09:31 +0000518 ctk_hires_cputc('<');
519 } else {
520 hires_cputcxy(xpos, ypos, '|');
521 /* hires_gotoxy(xpos + 1, ypos); */
522 ctk_hires_cputsn(text, w->w);
523 i = hires_wherex();
524 if(i - xpos - 1 < w->w) {
525 ctk_hires_cclear(w->w - (i - xpos) + 1);
526 }
527 ctk_hires_cputc('|');
adamdunkels7e4982c2003-03-19 16:26:18 +0000528 }
adamdunkels7e4982c2003-03-19 16:26:18 +0000529 }
530 hires_revers(0);
531 break;
532 case CTK_WIDGET_ICON:
533 if(ypos >= clipy1 && ypos < clipy2) {
adamdunkels77e47062003-04-17 15:09:31 +0000534 hires_color(ctk_hires_theme.iconcolors[focus]);
adamdunkels7e4982c2003-03-19 16:26:18 +0000535
adamdunkels9e046b42003-04-24 17:05:41 +0000536 x = xpos;
adamdunkels7e4982c2003-03-19 16:26:18 +0000537 len = strlen(w->widget.icon.title);
538 if(x + len >= SCREEN_WIDTH) {
539 x = SCREEN_WIDTH - len;
540 }
541
adamdunkels9e046b42003-04-24 17:05:41 +0000542 if(ypos + 3 < clipy2) {
543 hires_gotoxy(x, ypos + 3);
544 ctk_hires_cputsn(w->widget.icon.title, len);
545 }
546
547 hires_gotoxy(xpos, ypos);
548 if(w->widget.icon.bitmap != NULL) {
549 ctk_hires_bitmapptr = w->widget.icon.bitmap;
550 for(i = 0; i < 3; ++i) {
551 if(ypos >= clipy1 && ypos < clipy2) {
552 hires_gotoxy(xpos, ypos);
553 ctk_hires_draw_bitmapline(3);
554 }
555 ctk_hires_bitmapptr += 3 * 8;
556 ++ypos;
557 }
558
559 /* draw_bitmap_icon(w->widget.icon.bitmap);*/
560 }
561
adamdunkels7e4982c2003-03-19 16:26:18 +0000562 }
563 break;
adamdunkels77e47062003-04-17 15:09:31 +0000564 case CTK_WIDGET_BITMAP:
565 hires_color(ctk_hires_theme.bitmapcolors[focus]);
566 ctk_hires_bitmapptr = w->widget.bitmap.bitmap;
adamdunkels41343612003-07-31 23:23:25 +0000567 for(i = 0; i < w->h; ++i) {
adamdunkels77e47062003-04-17 15:09:31 +0000568 if(ypos >= clipy1 && ypos < clipy2) {
569 hires_gotoxy(xpos, ypos);
570 ctk_hires_draw_bitmapline(w->w);
571 }
572 ctk_hires_bitmapptr += w->w * 8;
573 ++ypos;
574 }
575 break;
576
adamdunkels7e4982c2003-03-19 16:26:18 +0000577 default:
578 break;
579 }
580}
581/*-----------------------------------------------------------------------------------*/
582void
583ctk_draw_widget(struct ctk_widget *w,
584 unsigned char focus,
585 unsigned char clipy1,
586 unsigned char clipy2)
587{
588 struct ctk_window *win = w->window;
589 unsigned char posx, posy;
590
591 posx = win->x + 1;
592 posy = win->y + 2;
593
594 if(w == win->focused) {
595 focus |= CTK_FOCUS_WIDGET;
596 }
597
598 draw_widget(w, posx, posy,
599 clipy1, clipy2,
600 focus);
601}
602/*-----------------------------------------------------------------------------------*/
603void
adamdunkelsd7422082003-08-05 13:57:01 +0000604ctk_draw_clear_window(register struct ctk_window *window,
adamdunkelsa6e7a8e2003-04-08 19:12:02 +0000605 unsigned char focus,
606 unsigned char clipy1,
607 unsigned char clipy2)
608{
adamdunkels23b30d52003-08-15 18:46:25 +0000609 static unsigned char h;
adamdunkelsa6e7a8e2003-04-08 19:12:02 +0000610
adamdunkels77e47062003-04-17 15:09:31 +0000611 hires_color(ctk_hires_theme.windowcolors[focus]);
adamdunkelsa6e7a8e2003-04-08 19:12:02 +0000612
613 h = window->y + 2 + window->h;
614 /* Clear window contents. */
615 for(i = window->y + 2; i < h; ++i) {
adamdunkels9e046b42003-04-24 17:05:41 +0000616 if(i >= clipy1 && i <= clipy2) {
adamdunkelsa6e7a8e2003-04-08 19:12:02 +0000617 hires_cclearxy(window->x + 1, i, window->w);
618 }
619 }
620}
621/*-----------------------------------------------------------------------------------*/
622void
adamdunkels7e4982c2003-03-19 16:26:18 +0000623ctk_draw_window(register struct ctk_window *window,
624 unsigned char focus,
625 unsigned char clipy1, unsigned char clipy2)
626{
627 register struct ctk_widget *w;
adamdunkels7e4982c2003-03-19 16:26:18 +0000628 x = window->x;
629 y = window->y + 1;
630
631 ++clipy2;
632
adamdunkels9e046b42003-04-24 17:05:41 +0000633 if(clipy2 <= y) {
adamdunkels7e4982c2003-03-19 16:26:18 +0000634 return;
635 }
adamdunkels77e47062003-04-17 15:09:31 +0000636
adamdunkels9e046b42003-04-24 17:05:41 +0000637 /* hires_color(ctk_hires_theme.windowcolors[focus+1]);*/
adamdunkels77e47062003-04-17 15:09:31 +0000638
adamdunkels7e4982c2003-03-19 16:26:18 +0000639 x1 = x + 1;
640 y1 = y + 1;
adamdunkels9e046b42003-04-24 17:05:41 +0000641 /* x2 = x1 + window->w;
642 y2 = y1 + window->h;*/
adamdunkels77e47062003-04-17 15:09:31 +0000643
adamdunkels7e4982c2003-03-19 16:26:18 +0000644 hires_gotoxy(x, y);
adamdunkels77e47062003-04-17 15:09:31 +0000645 ctk_hires_windowparams.w = window->w;
646 ctk_hires_windowparams.h = window->h;
adamdunkels7e4982c2003-03-19 16:26:18 +0000647 if(clipy1 < y) {
adamdunkels77e47062003-04-17 15:09:31 +0000648 ctk_hires_windowparams.clipy1 = 0;
adamdunkels7e4982c2003-03-19 16:26:18 +0000649 } else {
adamdunkels77e47062003-04-17 15:09:31 +0000650 ctk_hires_windowparams.clipy1 = clipy1 - y;
adamdunkels7e4982c2003-03-19 16:26:18 +0000651 }
adamdunkels77e47062003-04-17 15:09:31 +0000652 ctk_hires_windowparams.clipy2 = clipy2 - y;
653 ctk_hires_windowparams.color1 = ctk_hires_theme.windowcolors[focus+1];
654 ctk_hires_windowparams.color2 = ctk_hires_theme.windowcolors[focus];
655 ctk_hires_windowparams.title = window->title;
656 ctk_hires_windowparams.titlelen = window->titlelen;
adamdunkels7e4982c2003-03-19 16:26:18 +0000657
adamdunkels9e046b42003-04-24 17:05:41 +0000658 if(ctk_hires_windowparams.clipy1 < ctk_hires_windowparams.clipy2 &&
659 ctk_hires_windowparams.clipy2 > 0) {
660 ctk_hires_draw_windowborders();
adamdunkels7e4982c2003-03-19 16:26:18 +0000661 }
adamdunkels41343612003-07-31 23:23:25 +0000662
adamdunkels7e4982c2003-03-19 16:26:18 +0000663 focus = focus & CTK_FOCUS_WINDOW;
664
665 /* Draw inactive widgets. */
666 for(w = window->inactive; w != NULL; w = w->next) {
667 draw_widget(w, x1, y1,
668 clipy1, clipy2,
669 focus);
670 }
671
672 /* Draw active widgets. */
673 for(w = window->active; w != NULL; w = w->next) {
674 wfocus = focus;
675 if(w == window->focused) {
676 wfocus |= CTK_FOCUS_WIDGET;
677 }
678 draw_widget(w, x1, y1,
679 clipy1, clipy2,
680 wfocus);
681 }
682}
683/*-----------------------------------------------------------------------------------*/
684void
685ctk_draw_dialog(register struct ctk_window *dialog)
686{
687 register struct ctk_widget *w;
688
adamdunkels77e47062003-04-17 15:09:31 +0000689 hires_color(ctk_hires_theme.windowcolors[CTK_FOCUS_DIALOG]);
adamdunkels7e4982c2003-03-19 16:26:18 +0000690
691 /* x = (SCREEN_WIDTH - dialog->w) / 2;
692 y = (SCREEN_HEIGHT - 1 - dialog->h) / 2; */
693 x = dialog->x;
694 y = dialog->y + 1;
695
696
697 x1 = x + 1;
698 y1 = y + 1;
699 x2 = x1 + dialog->w;
700 y2 = y1 + dialog->h;
701
702
703 /* Draw dialog frame. */
704
705 hires_cvlinexy(x, y1,
706 dialog->h);
707 hires_cvlinexy(x2, y1,
708 dialog->h);
709
710 hires_chlinexy(x1, y,
711 dialog->w);
712 hires_chlinexy(x1, y2,
713 dialog->w);
714
715 hires_cputcxy(x, y, CH_ULCORNER);
716 hires_cputcxy(x, y2, CH_LLCORNER);
717 hires_cputcxy(x2, y, CH_URCORNER);
718 hires_cputcxy(x2, y2, CH_LRCORNER);
719
720
721 /* Clear window contents. */
722 for(i = y1; i < y2; ++i) {
723 hires_cclearxy(x1, i, dialog->w);
724 }
725
adamdunkels7e4982c2003-03-19 16:26:18 +0000726 /* Draw inactive widgets. */
727 for(w = dialog->inactive; w != NULL; w = w->next) {
728 draw_widget(w, x1, y1,
729 0, SCREEN_HEIGHT, CTK_FOCUS_DIALOG);
730 }
731
732
733 /* Draw active widgets. */
734 for(w = dialog->active; w != NULL; w = w->next) {
735 wfocus = CTK_FOCUS_DIALOG;
736 if(w == dialog->focused) {
737 wfocus |= CTK_FOCUS_WIDGET;
738 }
739 draw_widget(w, x1, y1,
740 0, SCREEN_HEIGHT, wfocus);
741 }
742
743}
744/*-----------------------------------------------------------------------------------*/
745void
746ctk_draw_clear(unsigned char y1, unsigned char y2)
747{
748 for(i = y1; i < y2; ++i) {
749 clear_line(i);
750 }
751}
752/*-----------------------------------------------------------------------------------*/
753static void
adamdunkelsd7422082003-08-05 13:57:01 +0000754draw_menu(register struct ctk_menu *m)
adamdunkels7e4982c2003-03-19 16:26:18 +0000755{
adamdunkels23b30d52003-08-15 18:46:25 +0000756 static unsigned char x, x2, y;
adamdunkels7e4982c2003-03-19 16:26:18 +0000757
adamdunkels77e47062003-04-17 15:09:31 +0000758 hires_color(ctk_hires_theme.openmenucolor);
adamdunkels7e4982c2003-03-19 16:26:18 +0000759 x = hires_wherex();
adamdunkels77e47062003-04-17 15:09:31 +0000760 ctk_hires_cputsn(m->title, m->titlelen);
761 ctk_hires_cputc(' ');
adamdunkels7e4982c2003-03-19 16:26:18 +0000762 x2 = hires_wherex();
763 if(x + CTK_CONF_MENUWIDTH > SCREEN_WIDTH) {
764 x = SCREEN_WIDTH - CTK_CONF_MENUWIDTH;
765 }
766 for(y = 0; y < m->nitems; ++y) {
767 if(y == m->active) {
adamdunkels77e47062003-04-17 15:09:31 +0000768 hires_color(ctk_hires_theme.activemenucolor);
adamdunkels7e4982c2003-03-19 16:26:18 +0000769 } else {
adamdunkels77e47062003-04-17 15:09:31 +0000770 hires_color(ctk_hires_theme.menucolor);
adamdunkels7e4982c2003-03-19 16:26:18 +0000771 }
772 hires_gotoxy(x, y + 1);
773 if(m->items[y].title[0] == '-') {
adamdunkels77e47062003-04-17 15:09:31 +0000774 ctk_hires_chline(CTK_CONF_MENUWIDTH);
adamdunkels7e4982c2003-03-19 16:26:18 +0000775 } else {
adamdunkels77e47062003-04-17 15:09:31 +0000776 ctk_hires_cputsn(m->items[y].title,
adamdunkels7e4982c2003-03-19 16:26:18 +0000777 strlen(m->items[y].title));
778 }
adamdunkels77e47062003-04-17 15:09:31 +0000779 ctk_hires_cclear(x + CTK_CONF_MENUWIDTH - hires_wherex());
adamdunkels7e4982c2003-03-19 16:26:18 +0000780 hires_revers(0);
781 }
782 hires_gotoxy(x2, 0);
adamdunkels77e47062003-04-17 15:09:31 +0000783 hires_color(ctk_hires_theme.menucolor);
adamdunkels7e4982c2003-03-19 16:26:18 +0000784}
785/*-----------------------------------------------------------------------------------*/
786void
787ctk_draw_menus(struct ctk_menus *menus)
788{
789 struct ctk_menu *m;
adamdunkels23b30d52003-08-15 18:46:25 +0000790
adamdunkels7e4982c2003-03-19 16:26:18 +0000791 /* Draw menus */
adamdunkels77e47062003-04-17 15:09:31 +0000792 hires_color(ctk_hires_theme.menucolor);
adamdunkels7e4982c2003-03-19 16:26:18 +0000793 hires_gotoxy(0, 0);
794 hires_revers(0);
adamdunkels77e47062003-04-17 15:09:31 +0000795 ctk_hires_cputc(' ');
adamdunkels7e4982c2003-03-19 16:26:18 +0000796 for(m = menus->menus->next; m != NULL; m = m->next) {
adamdunkels7e4982c2003-03-19 16:26:18 +0000797 if(m != menus->open) {
adamdunkels77e47062003-04-17 15:09:31 +0000798 ctk_hires_cputsn(m->title, m->titlelen);
799 ctk_hires_cputc(' ');
adamdunkels41343612003-07-31 23:23:25 +0000800 } else {
adamdunkels7e4982c2003-03-19 16:26:18 +0000801 draw_menu(m);
802 }
803 }
adamdunkels77e47062003-04-17 15:09:31 +0000804 ctk_hires_cclear(SCREEN_WIDTH - hires_wherex() -
adamdunkels7e4982c2003-03-19 16:26:18 +0000805 strlen(menus->desktopmenu->title) - 1);
806
807 /* Draw desktopmenu */
808 if(menus->desktopmenu != menus->open) {
adamdunkels77e47062003-04-17 15:09:31 +0000809 ctk_hires_cputsn(menus->desktopmenu->title,
adamdunkels7e4982c2003-03-19 16:26:18 +0000810 menus->desktopmenu->titlelen);
adamdunkels77e47062003-04-17 15:09:31 +0000811 ctk_hires_cputc(' ');
adamdunkels7e4982c2003-03-19 16:26:18 +0000812 } else {
813 draw_menu(menus->desktopmenu);
814 }
815
816}
817/*-----------------------------------------------------------------------------------*/
818unsigned char
819ctk_draw_height(void)
820{
821 return SCREEN_HEIGHT;
822}
823/*-----------------------------------------------------------------------------------*/
824unsigned char
825ctk_draw_width(void)
826{
827 return SCREEN_WIDTH;
828}
829/*-----------------------------------------------------------------------------------*/