DEADSOFTWARE

build: remove old cp866 references from CMakeLists
[flatwaifu.git] / src / redraw.c
1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
16 /*
17 #include <stdlib.h>
18 #include <errno.h>
19 #include <string.h>
20 //#include "..\averr.h"
21 #include "vga.h"
22 #include "glob.h"
24 #define MAXRECT 500
26 typedef struct{short x,w,y,h;}rect;
28 static rect *rt,*rp;
29 static redraw_f *fn;
30 static short sl,st,sr,sb;
33 void *RD_init(short x,short w,short y,short h) {
34 rect *p;
36 if(!(p=malloc((MAXRECT*2+1)*sizeof(rect))))
37 {error(0,0,ENOMEM,NULL,NULL);return NULL;}//{error(EZ_VGALIB,ET_STD,ENOMEM,NULL,NULL);return NULL;}
38 p->x=x;p->w=x+w-1;p->y=y;p->h=y+h-1;
39 memset(p+1,0,MAXRECT*2*sizeof(rect));
40 return p;
41 }
43 void RD_start(void *p,redraw_f *f) {
44 rt=p;fn=f;
45 sl=rt->x;sr=rt->w;
46 st=rt->y;sb=rt->h;
47 ++rt;
48 rp=rt;
49 }
51 static void add(short x,short r,short y,short b) {
52 int i;
53 short rx,rr,ry,rb;
55 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
56 if(x>(rr=(rx=rp[i].x)+rp[i].w-1)) continue;
57 if(r<rx) continue;
58 if(y>(rb=(ry=rp[i].y)+rp[i].h-1)) continue;
59 if(b<ry) continue;
60 if(x<rx) add(x,rx-1,y,b);
61 if(r>rr) add(rr+1,r,y,b);
62 if(y<ry) add(max(rx,x),min(rr,r),y,ry-1);
63 if(b>rb) add(max(rx,x),min(rr,r),rb+1,b);
64 return;
65 }
66 for(i=0;i<MAXRECT;++i) if(!rp[i].w) {
67 rp[i].x=x;rp[i].y=y;rp[i].w=r-x+1;rp[i].h=b-y+1;
68 return;
69 }
70 }
72 void RD_rect(short x,short w,short y,short h) {
73 if(x>sr) return;
74 if(x+w<=sl) return;
75 if(y>sb) return;
76 if(y+h<=st) return;
77 w+=x-1;h+=y-1;
78 if(x<sl) x=sl;
79 if(y<st) y=st;
80 if(w>sr) w=sr;
81 if(h>sb) h=sb;
82 add(x,w,y,h);
83 }
85 void RD_spr(short x,short y,vgaimg *v) {
86 RD_rect(x-v->sx,v->w,y-v->sy,v->h);
87 }
89 void RD_spr2(short x,short y,vgaimg *v) {
90 RD_rect(x-v->w+v->sx,v->w,y-v->sy,v->h);
91 }
93 void RD_end(void) {
94 int i;
96 V_setscr(scrbuf);
97 rp=rt+MAXRECT;
98 for(i=0;i<MAXRECT;++i) if(rt[i].w) {
99 add(rt[i].x,rt[i].x+rt[i].w-1,rt[i].y,rt[i].y+rt[i].h-1);
101 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
102 scrx=rp[i].x;scrw=rp[i].w;scry=rp[i].y;scrh=rp[i].h;
103 fn();
105 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
106 V_copytoscr(rp[i].x,rp[i].w,rp[i].y,rp[i].h);
108 memcpy(rp,rt,MAXRECT*sizeof(rect));
109 memset(rt,0,MAXRECT*sizeof(rect));
111 */