2 Copyright (C) 1998 BJ Eirich (aka vecna)
\r
3 This program is free software; you can redistribute it and/or
\r
4 modify it under the terms of the GNU General Public License
\r
5 as published by the Free Software Foundation; either version 2
\r
6 of the License, or (at your option) any later version.
\r
7 This program is distributed in the hope that it will be useful,
\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
10 See the GNU General Public Lic
\r
11 See the GNU General Public License for more details.
\r
12 You should have received a copy of the GNU General Public License
\r
13 along with this program; if not, write to the Free Software
\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
23 #include "keyboard.h"
\r
29 #include "vdriver.h"
\r
31 #include "smalfont.h"
\r
32 #include "guicomp.h"
\r
35 extern byte TileCmp(byte *one, byte *two); //zero
\r
37 // ================================= Data ====================================
\r
40 char ttile[256], ttile2[256];
\r
44 // ================================= Code ====================================
\r
46 int curtileptr(int row)
\r
55 y=((my-16)/jumper)*wide;
\r
60 void NormalButton(int x1, int y1, int x2, int y2, char *str)
\r
62 FilledBox(x1, y1, x2, y2, winbg);
\r
63 HLine(x1, y1, x2, black);
\r
64 VLine(x1, y1, y2, black);
\r
65 HLine(x1+1, y1+y2-1, x2-1, black);
\r
66 VLine(x1+x2-1, y1+1, y2-1, black);
\r
68 HLine(x1+1, y1+1, x2-2, brightw);
\r
69 VLine(x1+1, y1+1, y2-2, brightw);
\r
70 HLine(x1+2, y1+y2-2, x2-3, darkw);
\r
71 VLine(x1+x2-2, y1+2, y2-3, darkw);
\r
72 GotoXY(x1+((x2-pixels(str))/2), y1+3);
\r
76 void PressdButton(int x1, int y1, int x2, int y2, char *str)
\r
78 FilledBox(x1, y1, x2, y2, winbg);
\r
79 HLine(x1, y1, x2, black);
\r
80 VLine(x1, y1, y2, black);
\r
81 HLine(x1+1, y1+y2-1, x2-1, black);
\r
82 VLine(x1+x2-1, y1+1, y2-1, black);
\r
84 HLine(x1+1, y1+1, x2-2, darkw);
\r
85 VLine(x1+1, y1+1, y2-2, darkw);
\r
86 GotoXY(x1+((x2-pixels(str))/2)+1, y1+4);
\r
90 void RenderSelector()
\r
91 { unsigned char *img,i,j;
\r
94 int twide=320/tskip;
\r
95 int tdeep=((200+15)&~15)/tskip;
\r
99 for (i=0; i<tdeep; ++i)
\r
100 for (j=0; j<twide; ++j)
\r
102 img=vsp+(256*((i*twide)+j+selofs));
\r
103 if (((i*twide)+j+selofs)>=numtiles) img=vsp;
\r
104 CopyTile((j*tskip)+16,(i*tskip)+16,img);
\r
109 DrawHighlight( ((mx/tskip)*tskip)-(1+pad),
\r
110 ((my/tskip)*tskip)-(1+pad));
\r
113 sprintf(strbuf,"MapEd %s Tile Selector - Tile %d/%d",ME2_VERSION,curtileptr(selofs),numtiles);
\r
114 Window(16,z,336,z+40,strbuf);
\r
115 HLine(278, z+11, 53, darkw);
\r
116 VLine(278, z+11, 25, darkw);
\r
117 VLine(330, z+12, 24, brightw);
\r
118 HLine(279, z+35, 51, brightw);
\r
119 if (curmode==0) PressdButton(290, z+12, 40, 12, "Select");
\r
120 else NormalButton(290, z+12, 40, 12, "Select");
\r
121 if (curmode==1) PressdButton(290, z+23, 40, 12, "Edit");
\r
122 else NormalButton(290, z+23, 40, 12, "Edit");
\r
123 if (th) PressdButton(279, z+12, 12, 12, "H");
\r
124 else NormalButton(279, z+12, 12, 12, "H");
\r
125 if (pad) PressdButton(279, z+23, 12, 12, "P");
\r
126 else NormalButton(279, z+23, 12, 12, "P");
\r
128 HLine(219, z+11, 52, darkw);
\r
129 VLine(219, z+11, 25, darkw);
\r
130 VLine(270, z+12, 24, brightw);
\r
131 HLine(220, z+35, 50, brightw);
\r
132 NormalButton(220, z+12, 50, 12, "Import VSP");
\r
133 NormalButton(220, z+23, 50, 12, "Import PCX");
\r
135 HLine(160, z+11, 52, darkw);
\r
136 VLine(160, z+11, 25, darkw);
\r
137 VLine(211, z+12, 24, brightw);
\r
138 HLine(161, z+35, 50, brightw);
\r
139 NormalButton(161, z+12, 50, 12, "Add Tiles");
\r
140 NormalButton(161, z+23, 50, 12, "Animation");
\r
142 HLine(26, z+10, 20, darkw);
\r
143 VLine(26, z+10, 20, darkw);
\r
144 HLine(27, z+29, 19, brightw);
\r
145 VLine(45, z+11, 19, brightw);
\r
146 FilledBox(27, z+11, 18, 18, black);
\r
147 CopyTile(28, z+12, ttile2);
\r
148 GotoXY(20, z+32); printstring("Clipboard");
\r
151 void FlipX(unsigned short edtile)
\r
155 if (edtile>=numtiles) return;
\r
156 memcpy(ttile,&vsp[edtile*256],256);
\r
161 vsp[((edtile)*256)+(j*16)+i]=ttile[(j*16)+(15-i)];
\r
164 void FlipY(unsigned short edtile)
\r
168 if (edtile>=numtiles) return;
\r
169 memcpy(ttile,&vsp[edtile*256],256);
\r
174 vsp[((edtile)*256)+(j*16)+i]=ttile[((15-j)*16)+i];
\r
177 void FlipZ(unsigned short edtile)
\r
181 if (edtile>=numtiles) return;
\r
182 memcpy(ttile,&vsp[edtile*256],256);
\r
187 vsp[((edtile)*256)+(j*16)+i]=ttile[(i*16)+j];
\r
190 void DrawHighlight(int x, int y)
\r
192 if (x<10 || y<10 || x>330 || y>sy+10) return;
\r
193 HLine(x, y, 18, white);
\r
194 HLine(x, y+17, 18, white);
\r
195 VLine(x, y, 18, white);
\r
196 VLine(x+17, y, 18, white);
\r
199 void TileSelector()
\r
200 { int z, ct, k,j,m;
\r
203 int ms_down=0; // aen
\r
206 while (!key[SCAN_ESC])
\r
217 if (my>tsy-2) ms_down=1;
\r
218 if (my<18) ms_up=1;
\r
221 if ((key[SCAN_DOWN] || (ms_down && (!(systemtime%10)))) && selofs<65319)
\r
223 if (!pad) selofs=selofs+20;
\r
228 if ((key[SCAN_UP] || (ms_up && (!(systemtime%10)))) && selofs>17)
\r
230 if (!pad) selofs-=20;
\r
240 if (pad) Message("Tile padding enabled.",100);
\r
241 else Message("Tile padding disabled.",100);
\r
247 if (th) Message("Tile Highlight enabled.",100);
\r
248 else Message("Tile Highlight disabled.",100);
\r
251 if (key[SCAN_X]) FlipX(curtileptr(selofs));
\r
252 if (key[SCAN_Y]) FlipY(curtileptr(selofs));
\r
253 if (key[SCAN_Z]) FlipZ(curtileptr(selofs));
\r
254 if (key[SCAN_V]) VSPAnimDialog();
\r
255 if (key[SCAN_CTRL] && key[SCAN_C])
\r
257 memcpy(ttile2, (char *) (vsp+(256*curtileptr(selofs))), 256);
\r
260 if (key[SCAN_CTRL] && key[SCAN_S])
\r
262 if (curtileptr(selofs) >= numtiles) return;
\r
263 memcpy((char *) (vsp+(256*curtileptr(selofs))), ttile2, 256);
\r
267 if (key[SCAN_CTRL] && key[SCAN_T])
\r
269 if (curtileptr(selofs) >= numtiles) return;
\r
272 d=(char *) (vsp+(256*curtileptr(selofs)));
\r
273 for (z=0; z<256; z++)
\r
281 if (key[SCAN_CTRL] && key[SCAN_D] && !key[SCAN_ALT])
\r
285 z=curtileptr(selofs);
\r
288 memcpy(vsp+(z*256),vsp+((z+1)*256),((numtiles-z-1)*256));
\r
292 // zero: Super Delete Mode!
\r
293 // wimpy delete irks me.
\r
294 if (key[SCAN_CTRL] && key[SCAN_D] && key[SCAN_ALT])
\r
298 z=curtileptr(selofs);
\r
303 memcpy(vsp+(z*256),vsp+((z+1)*256),((numtiles-z-1)*256));
\r
305 for(k=0;k<numlayers;k++)
\r
307 for(j=0; j<layer[k].sizey; j++)
\r
309 for(m=0; m<layer[k].sizex; m++)
\r
311 if(layers[k][j*layer[k].sizex+m]==z) layers[k][j*layer[k].sizex+m]=0;
\r
312 if(layers[k][j*layer[k].sizex+m]>z) layers[k][j*layer[k].sizex+m]--;
\r
319 // zero: Super Insert Mode!
\r
320 // wimpy insert irks me.
\r
321 if (key[SCAN_CTRL] && key[SCAN_I] && key[SCAN_ALT])
\r
324 ct=curtileptr(selofs);
\r
325 if (ct <= numtiles)
\r
328 s=(char *) valloc((numtiles+1)*256, "s_ins",0);
\r
329 memcpy(s, vsp, (numtiles*256));
\r
330 vfree(vsp); vsp=s; s=0;
\r
331 for (z=numtiles-1; z>=ct; z--)
\r
332 memcpy(vsp+((z+1)*256),vsp+(z*256),256);
\r
333 memset(vsp+(ct*256), 0, 256);
\r
336 for(k=0;k<numlayers;k++)
\r
338 for(j=0; j<layer[k].sizey; j++)
\r
340 for(m=0; m<layer[k].sizex; m++)
\r
342 if(layers[k][j*layer[k].sizex+m]>=ct) layers[k][j*layer[k].sizex+m]++;
\r
348 if (key[SCAN_CTRL] && key[SCAN_I] && !key[SCAN_ALT])
\r
351 ct=curtileptr(selofs);
\r
352 if (ct <= numtiles)
\r
355 s=(char *)valloc((numtiles+1)*256,"s_ins",0);
\r
356 memcpy(s, vsp, (numtiles*256));
\r
357 vfree(vsp); vsp=s; s=0;
\r
358 for (z=numtiles-1; z>=ct; z--)
\r
359 memcpy(vsp+((z+1)*256),vsp+(z*256),256);
\r
360 memset(vsp+(ct*256), 0, 256);
\r
367 TEtile=curtileptr(selofs); // middle tile initially
\r
368 if (TEtile<numtiles)
\r
371 TEsource=vsp+(256*TEtile);
\r
378 if (mb==1 && my<(tsy-40) && !curmode)
\r
380 if (curtileptr(selofs)<numtiles)
\r
382 lt=curtileptr(selofs);
\r
387 if (mb==2 && my<(tsy-40) && !curmode)
\r
389 if (curtileptr(selofs)<numtiles)
\r
391 rt=curtileptr(selofs);
\r
396 if (mb && my<(tsy-40) && curmode)
\r
399 TEtile=curtileptr(selofs); // middle tile initially
\r
400 if (TEtile<numtiles)
\r
404 TEsource=vsp+(256*TEtile);
\r
411 if (mb && mx>290 && mx<330 && my>z+12 && my<z+23)
\r
415 Message("Tile select mode.",100);
\r
417 if (mb && mx>290 && mx<330 && my>z+23 && my<z+47)
\r
421 Message("Tile edit mode.",100);
\r
423 if (mb && mx>278 && mx<289 && my>z+12 && my<z+23)
\r
427 if (th) Message("Tile Highlight enabled.",100);
\r
428 else Message("Tile Highlight disabled.",100);
\r
431 if (mb && mx>278 && mx<289 && my>z+23 && my<z+47)
\r
436 if (pad) Message("Tile padding enabled.",100);
\r
437 else Message("Tile padding disabled.",100);
\r
440 if (mb && mx>161 && mx<210 && my>z+12 && my<z+23)
\r
443 PressdButton(161, z+12, 50, 12, "Add Tiles");
\r
453 if (mb && mx>161 && mx<210 && my>z+23 && my<z+47)
\r
455 PressdButton(161, z+23, 50, 12, "Animation");
\r
465 if (mb && mx>220 && mx<270 && my>z+12 && my<z+24)
\r
467 PressdButton(220, z+12, 50, 12, "Import VSP");
\r
478 if (mb && mx>220 && mx<270 && my>z+23 && my<z+47)
\r
480 PressdButton(220, z+23, 50, 12, "Import PCX");
\r
496 Message("MAP/VSP saved.",100);
\r
503 int vaxsize=150, vaysize=66;
\r
504 int vaxofs=20, vayofs=20;
\r
506 void VSPAnimDialog()
\r
507 { char done=0, moving=0, i=0;
\r
508 int mxo, myo, cursorblink;
\r
509 char ctf=0, cb=0, c, t, *str, bleh;
\r
510 char nstr1[80], nstr2[80], nstr3[80], nstr4[80];
\r
515 sprintf(nstr1, "%d", vspanim[i].start);
\r
516 sprintf(nstr2, "%d", vspanim[i].finish);
\r
517 sprintf(nstr3, "%d", vspanim[i].delay);
\r
518 sprintf(nstr4, "%d", vspanim[i].mode);
\r
525 if (ctf && systemtime >= cursorblink)
\r
528 cursorblink = systemtime+40;
\r
535 if (vaxofs<16) vaxofs = 16;
\r
536 if (vayofs<16) vayofs = 16;
\r
537 if (vaxofs+vaxsize>335) vaxofs = 336-vaxsize;
\r
538 if (vayofs+vaysize>sy+16) vayofs = (sy+16)-vaysize;
\r
541 Window(vaxofs, vayofs, vaxofs+vaxsize, vayofs+vaysize, "VSP Animation Editor");
\r
542 CopyTile(vaxofs+110, vayofs+16, (char *) (vsp+(256*tileidx[vspanim[i].start])));
\r
543 GotoXY(vaxofs+4, vayofs+12); printstring("Start");
\r
544 TextField(vaxofs+25, vayofs+11, 60, nstr1, ctf == 1 ? cb : 0);
\r
545 GotoXY(vaxofs+11, vayofs+22); printstring("End");
\r
546 TextField(vaxofs+25, vayofs+21, 60, nstr2, ctf == 2 ? cb : 0);
\r
547 GotoXY(vaxofs+4, vayofs+32); printstring("Delay");
\r
548 TextField(vaxofs+25, vayofs+31, 60, nstr3, ctf == 3 ? cb : 0);
\r
549 GotoXY(vaxofs+6, vayofs+42); printstring("Mode");
\r
550 TextField(vaxofs+25, vayofs+41, 60, nstr4, ctf == 4 ? cb : 0);
\r
551 GotoXY(vaxofs+2, vayofs+56); printstring("Strand");
\r
552 GotoXY(vaxofs+104, vayofs+33); printstring("Preview");
\r
553 HLine(vaxofs+1, vayofs+51, 148, white);
\r
554 Button(vaxofs+85, vayofs+54, "OK");
\r
555 Button(vaxofs+117, vayofs+54, "Update");
\r
556 GotoXY(vaxofs+30, vayofs+56);
\r
557 sprintf(strbuf, "%d", i); printstring(strbuf);
\r
564 if (mb==1 && mx>vaxofs+25 && mx<vaxofs+60+25 && my>vayofs+11 && my<vayofs+9+11 && !moving)
\r
566 ctf=1; str=nstr1; cb=1;
\r
567 cursorblink=systemtime+40; continue;
\r
570 if (mb==1 && mx>vaxofs+25 && mx<vaxofs+60+25 && my>vayofs+21 && my<vayofs+9+21 && !moving)
\r
572 ctf=2; str=nstr2; cb=1;
\r
573 cursorblink=systemtime+40; continue;
\r
576 if (mb==1 && mx>vaxofs+25 && mx<vaxofs+60+25 && my>vayofs+31 && my<vayofs+9+31 && !moving)
\r
578 ctf=3; str=nstr3; cb=1;
\r
579 cursorblink=systemtime+40; continue;
\r
582 if (mb==1 && mx>vaxofs+25 && mx<vaxofs+60+25 && my>vayofs+41 && my<vayofs+9+41 && !moving)
\r
584 ctf=4; str=nstr4; cb=1;
\r
585 cursorblink=systemtime+40; continue;
\r
588 if ((mb==1 && mx>vaxofs+85 && mx<vaxofs+30+85 && my>vayofs+54 && my<vayofs+10+54 && !moving) || (key[SCAN_ENTER] && !ctf))
\r
590 // insert code for button "OK" here
\r
592 ButtonPressed(vaxofs+85, vayofs+54, "OK");
\r
600 WaitRelease(); continue;
\r
603 if (mb==1 && mx>vaxofs+117 && mx<vaxofs+30+117 && my>vayofs+54 && my<vayofs+10+54 && !moving)
\r
605 // insert code for button "Update" here
\r
606 vspanim[i].start=atoi(nstr1);
\r
607 vspanim[i].finish=atoi(nstr2);
\r
608 vspanim[i].delay=atoi(nstr3);
\r
609 vspanim[i].mode=atoi(nstr4);
\r
611 ButtonPressed(vaxofs+117, vayofs+54, "Update");
\r
619 WaitRelease(); continue;
\r
622 if (mb==1 && mx>(vaxofs+vaxsize-9) && (mx<vaxofs+vaxsize-2)
\r
623 && my>(vayofs+1) && (my<vayofs+8) && !moving)
\r
630 if (mb==1 && mx>vaxofs && mx<vaxofs+vaxsize && my>vayofs && my<(vayofs+9) && !moving)
\r
638 if (mb==1 && !moving)
\r
648 if (key[SCAN_LSHIFT] || key[SCAN_RSHIFT]) c=key_shift_tbl[last_pressed];
\r
649 else c=key_ascii_tbl[last_pressed];
\r
651 if (last_pressed==SCAN_UP)
\r
653 vspanim[i].start=atoi(nstr1);
\r
654 vspanim[i].finish=atoi(nstr2);
\r
655 vspanim[i].delay=atoi(nstr3);
\r
656 vspanim[i].mode=atoi(nstr4);
\r
657 if (i<99) i++; else i=0;
\r
658 last_pressed=0; key[SCAN_UP]=0;
\r
659 sprintf(nstr1, "%d", vspanim[i].start);
\r
660 sprintf(nstr2, "%d", vspanim[i].finish);
\r
661 sprintf(nstr3, "%d", vspanim[i].delay);
\r
662 sprintf(nstr4, "%d", vspanim[i].mode);
\r
665 if (last_pressed==SCAN_DOWN)
\r
667 vspanim[i].start=atoi(nstr1);
\r
668 vspanim[i].finish=atoi(nstr2);
\r
669 vspanim[i].delay=atoi(nstr3);
\r
670 vspanim[i].mode=atoi(nstr4);
\r
671 if (i) i--; else i=99;
\r
672 last_pressed=0; key[SCAN_DOWN]=0;
\r
673 sprintf(nstr1, "%d", vspanim[i].start);
\r
674 sprintf(nstr2, "%d", vspanim[i].finish);
\r
675 sprintf(nstr3, "%d", vspanim[i].delay);
\r
676 sprintf(nstr4, "%d", vspanim[i].mode);
\r
679 if (last_pressed==SCAN_ESC)
\r
686 if (last_pressed==SCAN_ENTER)
\r
695 if (last_pressed==SCAN_TAB && !key[SCAN_LSHIFT])
\r
699 case 0: ctf=1; str=nstr1; break;
\r
700 case 1: ctf=2; str=nstr2; break;
\r
701 case 2: ctf=3; str=nstr3; break;
\r
702 case 3: ctf=4; str=nstr4; break;
\r
703 case 4: ctf=0; str=0; break;
\r
707 cb=1; cursorblink=systemtime+40;
\r
711 if (last_pressed==SCAN_TAB && key[SCAN_LSHIFT])
\r
715 case 0: ctf=4; str=nstr4; break;
\r
716 case 1: ctf=0; str=0; break;
\r
717 case 2: ctf=1; str=nstr1; break;
\r
718 case 3: ctf=2; str=nstr2; break;
\r
719 case 4: ctf=3; str=nstr3; break;
\r
723 cb=1; cursorblink=systemtime+40;
\r
730 if (last_pressed==SCAN_BACKSP && strlen(str))
\r
732 str[strlen(str)-1]=0;
\r
733 key[SCAN_BACKSP]=0;
\r
737 else if (last_pressed==SCAN_BACKSP)
\r
749 // memset(&vadelay, 0, 100);
\r
750 // for (i=0; i<numtiles; i++)
\r
752 vspanim[i].start=atoi(nstr1);
\r
753 vspanim[i].finish=atoi(nstr2);
\r
754 vspanim[i].delay=atoi(nstr3);
\r
755 vspanim[i].mode=atoi(nstr4);
\r
760 int atxsize=150, atysize=39;
\r
761 int atxofs=80, atyofs=50;
\r
763 void AddTilesDialog()
\r
764 { char done=0, moving=0;
\r
765 int mxo, myo, cursorblink, at=0; //, i;
\r
766 char ctf=0, cb=0, c, t, *str, bleh;
\r
771 sprintf(nstr1, "%d", at);
\r
778 if (ctf && systemtime >= cursorblink)
\r
781 cursorblink = systemtime+40;
\r
788 if (atxofs<16) atxofs = 16;
\r
789 if (atyofs<16) atyofs = 16;
\r
790 if (atxofs+atxsize>335) atxofs = 336-atxsize;
\r
791 if (atyofs+atysize>sy+16) atyofs = (sy+16)-atysize;
\r
794 Window(atxofs, atyofs, atxofs+atxsize, atyofs+atysize, "Allocate Additional Tiles");
\r
795 GotoXY(atxofs+12, atyofs+15); printstring("Alloc Tiles:");
\r
796 TextField(atxofs+56, atyofs+13, 80, nstr1, ctf == 1 ? cb : 0);
\r
797 Button(atxofs+85, atyofs+26, "OK");
\r
798 Button(atxofs+117, atyofs+26, "Cancel");
\r
805 if (mb==1 && mx>atxofs+56 && mx<atxofs+80+56 && my>atyofs+13 && my<atyofs+9+13 && !moving)
\r
807 ctf=1; str=nstr1; cb=1;
\r
808 cursorblink=systemtime+40; continue;
\r
811 if ((mb==1 && mx>atxofs+85 && mx<atxofs+30+85 && my>atyofs+26 && my<atyofs+10+26 && !moving) || (key[SCAN_ENTER] && !ctf))
\r
813 // insert code for button "OK" here
\r
816 str=(char *) valloc((numtiles+at)*256,"vsp data",0);
\r
817 memcpy(str,vsp,(numtiles*256));
\r
818 vfree(vsp); vsp=str; str=0; ctf=0;
\r
819 memset(vsp+(numtiles*256), 0, at*256);
\r
821 ButtonPressed(atxofs+85, atyofs+26, "OK");
\r
829 WaitRelease(); continue;
\r
832 if (mb==1 && mx>atxofs+117 && mx<atxofs+30+117 && my>atyofs+26 && my<atyofs+10+26 && !moving)
\r
834 // insert code for button "Cancel" here
\r
836 ButtonPressed(atxofs+117, atyofs+26, "Cancel");
\r
844 WaitRelease(); continue;
\r
847 if (mb==1 && mx>(atxofs+atxsize-9) && (mx<atxofs+atxsize-2)
\r
848 && my>(atyofs+1) && (my<atyofs+8) && !moving)
\r
855 if (mb==1 && mx>atxofs && mx<atxofs+atxsize && my>atyofs && my<(atyofs+9) && !moving)
\r
863 if (mb==1 && !moving)
\r
873 if (key[SCAN_LSHIFT] || key[SCAN_RSHIFT]) c=key_shift_tbl[last_pressed];
\r
874 else c=key_ascii_tbl[last_pressed];
\r
876 if (last_pressed==SCAN_ESC)
\r
883 if (last_pressed==SCAN_ENTER)
\r
892 if (last_pressed==SCAN_TAB && !key[SCAN_LSHIFT])
\r
896 case 0: ctf=1; str=nstr1; break;
\r
897 case 1: ctf=0; str=0; break;
\r
901 cb=1; cursorblink=systemtime+40;
\r
905 if (last_pressed==SCAN_TAB && key[SCAN_LSHIFT])
\r
909 case 0: ctf=1; str=nstr1; break;
\r
910 case 1: ctf=0; str=0; break;
\r
914 cb=1; cursorblink=systemtime+40;
\r
921 if (last_pressed==SCAN_BACKSP && strlen(str))
\r
923 str[strlen(str)-1]=0;
\r
924 key[SCAN_BACKSP]=0;
\r
928 else if (last_pressed==SCAN_BACKSP)
\r
942 // memset(&vadelay, 0, 100);
\r
943 // for (i=0; i<numtiles; i++)
\r
947 // ========================= Import *** Data/Code ============================
\r
949 char *ovsp, op, oh, openas;
\r
952 word tilesrippedthissession;
\r
953 byte *implist; //zero
\r
955 void RenderImport()
\r
956 { unsigned char *img,i,j;
\r
957 int z, jumper,wide,deep;
\r
962 deep=((200+15)&~15)/jumper;
\r
966 for (i=0; i<deep; i++)
\r
967 for (j=0; j<wide; j++)
\r
969 at=(i*wide)+j+sofs;
\r
971 if (at>=ontiles) img=ovsp;
\r
972 CopyTile((j*jumper)+16,(i*jumper)+16,img);
\r
973 if(at<ontiles) if(implist[at]) ColorGrid((j*jumper)+16,(i*jumper)+16,7); //zero
\r
978 DrawHighlight(((mx/jumper)*jumper)-(1+pad),
\r
979 ((my/jumper)*jumper)-(1+pad));
\r
982 sprintf(strbuf,"Import Tiles %d/%d",curtileptr(sofs),ontiles);
\r
983 Window(16,z,336,z+40,strbuf);
\r
984 sprintf(strbuf,"Tiles imported this session: %d",tilesrippedthissession);
\r
985 GotoXY(176-(pixels(strbuf)/2),z+20); printstring(strbuf);
\r
995 tilesrippedthissession=0;
\r
996 implist=(byte *)malloc(ontiles); //zero
\r
997 memset(implist,0,ontiles); //zero
\r
998 while (!key[SCAN_ESC])
\r
1005 if (key[SCAN_DOWN] && sofs<65319)
\r
1007 if (!pad) sofs=sofs+20;
\r
1011 if (key[SCAN_UP] && sofs>17)
\r
1013 if (!pad) sofs-=20;
\r
1017 /*all by zero here in this scan_b thing*/
\r
1021 Message("Building duplicate import list",200);
\r
1022 for(bloop1=0; bloop1<ontiles; bloop1++)
\r
1024 for(bloop2=0; bloop2<numtiles; bloop2++)
\r
1026 if(TileCmp(vsp+bloop2*256,ovsp+bloop1*256))
\r
1028 implist[bloop1]=1;
\r
1034 //all by zero here in this scan_a thing
\r
1037 Message("Importing all tiles",200);
\r
1039 for(bloop1=0; bloop1<ontiles; bloop1++)
\r
1041 str=(char *) valloc((numtiles+1)*256,"vsp data",0);
\r
1042 memcpy(str, vsp, (numtiles*256));
\r
1043 vfree(vsp); vsp=str; str=0;
\r
1044 memcpy(vsp+(numtiles*256), ovsp+(bloop1*256), 256);
\r
1050 //all by zero here in this scan_n thing
\r
1053 Message("Importing all new tiles",200);
\r
1055 for(bloop1=0; bloop1<ontiles; bloop1++)
\r
1057 for(bloop2=0; bloop2<numtiles; bloop2++)
\r
1059 if(TileCmp(vsp+bloop2*256,ovsp+bloop1*256))
\r
1061 implist[bloop1]=1;
\r
1066 for(bloop1=0; bloop1<ontiles; bloop1++)
\r
1068 if(!implist[bloop1])
\r
1070 str=(char *) valloc((numtiles+1)*256,"vsp data",0);
\r
1071 memcpy(str, vsp, (numtiles*256));
\r
1072 vfree(vsp); vsp=str; str=0;
\r
1073 memcpy(vsp+(numtiles*256), ovsp+(bloop1*256), 256);
\r
1080 if (mb==1 && my<(tsy-40) && curtileptr(sofs)<ontiles)
\r
1082 lt=curtileptr(sofs);
\r
1083 implist[lt]=1; //zero
\r
1084 str=(char *) valloc((numtiles+1)*256,"vsp data",0);
\r
1085 memcpy(str, vsp, (numtiles*256));
\r
1086 vfree(vsp); vsp=str; str=0;
\r
1087 memcpy(vsp+(numtiles*256), ovsp+(lt*256), 256);
\r
1089 tilesrippedthissession++;
\r
1091 sprintf(strbuf,"Tile %d imported.",lt);
\r
1092 Message(strbuf, 200);
\r
1097 vfree(implist); //zero
\r
1106 memset(fname, 0, 60);
\r
1107 bmode=1; oh=th; th=0;
\r
1108 Browse(1,"*.vsp","","","",&fname);
\r
1109 if (strlen(fname)<3) return;
\r
1110 if (!(f=fopen(fname,"rb")))
\r
1111 errf("VSP file %s not found.",fname);
\r
1112 WaitRelease(); th=oh; bmode=0;
\r
1114 fread(&ver, 1, 2, f);
\r
1115 if (ver!=2 && ver!=3)
\r
1116 errf("VSP file %s is not the correct VSP format.",fname);
\r
1117 fread(strbuf, 1, 768, f);
\r
1118 fread(&ontiles, 1, 2, f);
\r
1119 ovsp=(char *) valloc(256*ontiles,"ovsp",0);
\r
1122 fread(ovsp, 256, ontiles, f);
\r
1125 fread(&bsize, 1, 4, f);
\r
1126 ReadCompressedLayer1(ovsp, 256*ontiles, f);
\r
1137 int OPxsize=100, OPysize=40;
\r
1138 int OPxofs=100, OPyofs=70;
\r
1141 { char done=0, moving=0;
\r
1142 int mxo, myo, cursorblink;
\r
1143 char ctf=0, cb=0, c, t, *str;
\r
1151 if (ctf && systemtime >= cursorblink)
\r
1154 cursorblink = systemtime+40;
\r
1158 OPxofs = (mx-mxo);
\r
1159 OPyofs = (my-myo);
\r
1160 if (!mb) moving=0;
\r
1161 if (OPxofs<16) OPxofs = 16;
\r
1162 if (OPyofs<16) OPyofs = 16;
\r
1163 if (OPxofs+OPxsize>335) OPxofs = 336-OPxsize;
\r
1164 if (OPyofs+OPysize>sy+16) OPyofs = (sy+16)-OPysize;
\r
1167 Window(OPxofs, OPyofs, OPxofs+OPxsize, OPyofs+OPysize, "Open PCX As");
\r
1168 Button(OPxofs+21, OPyofs+18, "Tileset");
\r
1169 Button(OPxofs+50, OPyofs+18, "Image");
\r
1173 CheckTimerStuff();
\r
1176 if (mb==1 && mx>OPxofs+21 && mx<OPxofs+30+21 && my>OPyofs+18 && my<OPyofs+10+18 && !moving)
\r
1178 // insert code for button "Tileset" here
\r
1179 ButtonPressed(OPxofs+21, OPyofs+18, "Tileset");
\r
1188 WaitRelease(); continue;
\r
1191 if (mb==1 && mx>OPxofs+50 && mx<OPxofs+30+50 && my>OPyofs+18 && my<OPyofs+10+18 && !moving)
\r
1193 // insert code for button "Image" here
\r
1194 ButtonPressed(OPxofs+50, OPyofs+18, "Image");
\r
1203 WaitRelease(); continue;
\r
1206 if (mb==1 && mx>(OPxofs+OPxsize-9) && (mx<OPxofs+OPxsize-2)
\r
1207 && my>(OPyofs+1) && (my<OPyofs+8) && !moving)
\r
1214 if (mb==1 && mx>OPxofs && mx<OPxofs+OPxsize && my>OPyofs && my<(OPyofs+9) && !moving)
\r
1222 if (mb==1 && !moving)
\r
1232 if (key[SCAN_LSHIFT] || key[SCAN_RSHIFT]) c=key_shift_tbl[last_pressed];
\r
1233 else c=key_ascii_tbl[last_pressed];
\r
1235 if (last_pressed==SCAN_ESC)
\r
1242 if (last_pressed==SCAN_ENTER)
\r
1244 key[SCAN_ENTER]=0;
\r
1254 if (last_pressed==SCAN_BACKSP && strlen(str))
\r
1256 str[strlen(str)-1]=0;
\r
1257 key[SCAN_BACKSP]=0;
\r
1261 else if (last_pressed==SCAN_BACKSP)
\r
1275 char manufacturer;
\r
1278 char bits_per_pixel;
\r
1285 char color_planes;
\r
1286 short bytes_per_line;
\r
1287 short palette_type;
\r
1296 void ReadPCXLine(unsigned char *dest)
\r
1302 c=fgetc(pcxf) & 0xff;
\r
1304 if ((c & 0xc0)==0xc0)
\r
1307 for (i=0; i<run; i++)
\r
1308 dest[vidoffset+n+i]=c;
\r
1312 dest[vidoffset+n]=c;
\r
1315 } while (n<bytes);
\r
1318 void LoadPCXHeader(char *fname)
\r
1322 if (!(pcxf=fopen(fname,"rb"))) err("Could not open specified PCX file.");
\r
1323 fread(&manufacturer,1,1,pcxf);
\r
1324 fread(&version,1,1,pcxf);
\r
1325 fread(&encoding,1,1,pcxf);
\r
1326 fread(&bits_per_pixel,1,1,pcxf);
\r
1327 fread(&xmin,1,2,pcxf);
\r
1328 fread(&ymin,1,2,pcxf);
\r
1329 fread(&xmax,1,2,pcxf);
\r
1330 fread(&ymax,1,2,pcxf);
\r
1331 fread(&hres,1,2,pcxf);
\r
1332 fread(&vres,1,2,pcxf);
\r
1333 fread(&palette,1,48,pcxf);
\r
1334 fread(&reserved,1,1,pcxf);
\r
1335 fread(&color_planes,1,1,pcxf);
\r
1336 fread(&bytes_per_line,1,2,pcxf);
\r
1337 fread(&palette_type,1,2,pcxf);
\r
1338 fread(&filler,1,58,pcxf);
\r
1339 fseek(pcxf,-768L,SEEK_END);
\r
1340 fread(pal,1,768,pcxf);
\r
1341 fseek(pcxf,128L,SEEK_SET);
\r
1342 width=xmax-xmin+1;
\r
1343 depth=ymax-ymin+1;
\r
1344 bytes=bytes_per_line;
\r
1346 for (i=0; i<768; i++)
\r
1347 pal[i]=pal[i] >> 2;
\r
1348 set_intensity(63);
\r
1351 void LoadPCXHeaderNP(char *fname)
\r
1353 pcxf=fopen(fname,"rb");
\r
1354 if (!pcxf) err("Could not open specified PCX file.");
\r
1355 fread(&manufacturer,1,1,pcxf);
\r
1356 fread(&version,1,1,pcxf);
\r
1357 fread(&encoding,1,1,pcxf);
\r
1358 fread(&bits_per_pixel,1,1,pcxf);
\r
1359 fread(&xmin,1,2,pcxf);
\r
1360 fread(&ymin,1,2,pcxf);
\r
1361 fread(&xmax,1,2,pcxf);
\r
1362 fread(&ymax,1,2,pcxf);
\r
1363 fread(&hres,1,2,pcxf);
\r
1364 fread(&vres,1,2,pcxf);
\r
1365 fread(&palette,1,48,pcxf);
\r
1366 fread(&reserved,1,1,pcxf);
\r
1367 fread(&color_planes,1,1,pcxf);
\r
1368 fread(&bytes_per_line,1,2,pcxf);
\r
1369 fread(&palette_type,1,2,pcxf);
\r
1370 fread(&filler,1,58,pcxf);
\r
1371 width=xmax-xmin+1;
\r
1372 depth=ymax-ymin+1;
\r
1373 bytes=bytes_per_line;
\r
1376 // grabs a tile from the ovsp buffer (transit tile bay)
\r
1377 int GrabTileAt(int x, int y, int z, int check_dup)
\r
1384 for (a=0; a<16; a++)
\r
1386 memcpy(tvsp+(a*16), s, 16);
\r
1392 for (a=0; a<z; a++)
\r
1393 if (!memcmp(tvsp, ovsp+(a*256), 256)) return 0;
\r
1396 memcpy(ovsp+(z*256), tvsp, 256);
\r
1403 int wide,deep; // grabbable x&y tiles
\r
1404 int add,jumper; // related to grab coords
\r
1406 bmode=1; oh=th; th=0;
\r
1407 Browse(1,"*.pcx","","","",fname);
\r
1409 if (strlen(fname)<3) return;
\r
1416 LoadPCXHeader(fname);
\r
1418 // temp pcx buffer for grabs
\r
1419 t=(char *) valloc(width*depth,"pcx buf",0);
\r
1421 for (i=0; i<depth; i++)
\r
1423 vidoffset=width*i;
\r
1429 deep=((depth&~15)+add)/jumper;
\r
1430 wide=(width+add)/jumper;
\r
1432 ontiles=wide*deep;
\r
1433 ovsp=(char *) valloc(ontiles*256,"ovsp",0); // temp tilebay
\r
1436 for (i=0; i<deep; i++) // grab all tiles
\r
1437 for (j=0; j<wide; j++)
\r
1439 z+=GrabTileAt((j*jumper)+add, (i*jumper)+add, z, openas);
\r
1442 ontiles = z; // tiles successfully grabbed
\r