home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / fm2000 / showpic.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-04  |  17.2 KB  |  636 lines

  1. /*
  2.      Filemaster - Multitasking directory utility.
  3.      Copyright (C) 2000  Toni Wilen
  4.      
  5.      This program is free software; you can redistribute it and/or
  6.      modify it under the terms of the GNU General Public License
  7.      as published by the Free Software Foundation; either version 2
  8.      of the License, or (at your option) any later version.
  9.      
  10.      This program is distributed in the hope that it will be useful,
  11.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.      GNU General Public License for more details.
  14.      
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22. #include <graphics/gfxbase.h>
  23. #include <graphics/displayinfo.h>
  24. #include <intuition/gadgetclass.h>
  25. #include <datatypes/datatypes.h>
  26. #include <datatypes/datatypesclass.h>
  27. #include <datatypes/pictureclass.h>
  28. #include <proto/datatypes.h>
  29. #include <dos/dos.h>
  30. #include <proto/all.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include "fmnode.h"
  34. #include "child.h"
  35. #include "fmdos.h"
  36. #include "ilbm.h"
  37. #include "fmlocale.h"
  38.  
  39. WORD showpicture(struct FMHandle*,struct CMenuConfig*);
  40. WORD showicon(struct FMHandle*,struct CMenuConfig*);
  41. WORD showfont(struct FMHandle*,struct CMenuConfig*);
  42. LONG rbytes(struct FMHandle*,UBYTE*,LONG,LONG*);
  43. WORD decode(struct FMHandle*,struct ShowScreen*,struct FMBitMapHeader*,LONG);
  44. void clipit(WORD,WORD,struct Rectangle*,struct Rectangle*,struct Rectangle*,struct Rectangle*,struct Rectangle*);
  45. extern WORD __asm unpack(register __a0 UBYTE**,register __a1 struct BitMap*,register __a2 WORD*,register __d0 WORD,register __d1 LONG,register __d2 WORD,register __d3 UBYTE,register __a6 struct ShowScreen*);
  46. extern WORD __asm unpacknp(register __a0 UBYTE**,register __a1 struct BitMap*,register __a2 WORD*,register __d0 WORD,register __d1 LONG,register __d2 WORD,register __d3 UBYTE,register __a6 struct ShowScreen*);
  47. void __asm initbitmapi(register __d0 WORD);
  48.  
  49. ULONG power2(WORD);
  50. ULONG modefallback(ULONG,WORD,WORD,WORD);
  51.  
  52. extern struct FMConfig *fmconfig;
  53. extern struct GfxBase *GfxBase;
  54. extern struct FMMain fmmain;
  55.  
  56. static void pictureinfo(struct FMHandle *h,WORD width,WORD height,WORD deep,ULONG modeid,UBYTE *name)
  57. {
  58. WORD apu1;
  59. LONG apu3;
  60. struct DisplayInfo di;
  61. ULONG infotags[10];
  62.  
  63. h->owner->fmmessage2[0]=0;
  64. if(width&&height) {
  65.     apu3=power2(deep);
  66.     infotags[0]=0; infotags[1]=0; infotags[2]=0; infotags[3]=0;
  67.     if (GetDisplayInfoData(0,(UBYTE*)&di,sizeof(struct DisplayInfo),DTAG_DISP,modeid)>0) {
  68.         apu1=0;
  69.         if(di.PixelSpeed<=35)
  70.             infotags[apu1++]=(ULONG)getstring(MSG_SHOWPIC_SHIRES);
  71.         else if(di.PixelSpeed<=70)
  72.             infotags[apu1++]=(ULONG)getstring(MSG_SHOWPIC_HIRES);
  73.         if(di.PropertyFlags&DIPF_IS_LACE) infotags[apu1++]=(ULONG)getstring(MSG_SHOWPIC_LACE);
  74.         if(di.PropertyFlags&DIPF_IS_HAM) {
  75.             if(deep<=6) {
  76.                 infotags[apu1++]=(ULONG)getstring(MSG_SHOWPIC_HAM6);
  77.                 apu3=4096;
  78.             } else {
  79.                 infotags[apu1++]=(ULONG)getstring(MSG_SHOWPIC_HAM8);
  80.                 apu3=262144;
  81.             }
  82.         }
  83.         if(di.PropertyFlags&DIPF_IS_EXTRAHALFBRITE) infotags[apu1++]=(ULONG)getstring(MSG_SHOWPIC_EHB);
  84.     }    
  85.     sformat(h->owner->fmmessage2,getstring(MSG_SHOWPIC_INFO2),width,height,deep,apu3,infotags[0],infotags[1],infotags[2]);
  86. }
  87. sformat(h->owner->fmmessage1,getstring(MSG_SHOWPIC_INFO1),name,h->filename,h->size);
  88. fmmessage(h->owner);
  89. }
  90.  
  91. void __saveds showpic(void)
  92. {
  93. struct ProcMsg *pm;
  94. struct FMList *slist;
  95. register struct FMNode *node;
  96. struct FMHandle *h;
  97. WORD ret;
  98.  
  99. pm=sinitproc();
  100. slist=fmmain.sourcedir;
  101. if (!(setalloc(slist,1))) {
  102.     initproc(0,0);
  103.     goto endi;
  104. }
  105. initproc(slist,pm->cmc->label);
  106. priority(pm->cmc);
  107. ret=0;
  108. if(sselected(slist,1)) {
  109.     while((node=findselnode(slist))) {
  110.         if (h=openfile(slist,NDFILE(node),OFNORMAL|OFDECRUNCH)) {
  111.             ret=isdatatypes(h,GID_PICTURE);
  112.             if(ret==-99) {
  113.                 if (!Strnicmp(h->filename+strlen(h->filename)-5,".info",5)) {
  114.                     ret=showicon(h,pm->cmc);
  115.                 } else if (!Strnicmp(h->filename+strlen(h->filename)-5,".font",5)) {
  116.                     ret=showfont(h,pm->cmc);
  117.                 } else {        
  118.                     ret=showpicture(h,pm->cmc);
  119.                 }
  120.             }
  121.             closefile(h);
  122.         }
  123.         node->flags&=~NSELECTED;
  124.         outputlistline(slist,node);
  125.         if (!ret) break;
  126.     }
  127. }
  128. endproc(slist);
  129. endi:
  130. deinitproc(pm);
  131. }
  132.  
  133. WORD showdatatypepicture(struct FMHandle *h,struct DataType *dt,struct CMenuConfig *cmc)
  134. {
  135. struct DataTypeHeader *dth;
  136. Object *obj;
  137. struct ShowScreen shows;
  138. struct BitMapHeader *bmhd=0;
  139. ULONG modeid=0;
  140. struct BitMap *bm;
  141. struct gpLayout layout;
  142. ULONG *creg,*palette=0;
  143. LONG ncol,crsize,palsize;
  144. UBYTE *src;
  145. LONG type;
  146. WORD ret=0;
  147.  
  148. changename(h->owner,cmc->label);
  149. priority(cmc);
  150.  
  151. memseti(&shows,0,sizeof(struct ShowScreen));
  152. dth=dt->dtn_Header;
  153. if(h->flags&OFDECRUNCH) {
  154.     type=DTST_RAM;
  155.     src=h->decbuffer;
  156. } else {
  157.     type=DTST_FILE;
  158.     src=h->filename;
  159. }
  160. pictureinfo(h,0,0,0,0,dth->dth_Name);
  161. if(!(obj=NewDTObject(src,DTA_SourceType,type,DTA_GroupID,GID_PICTURE,PDTA_Remap,0,TAG_DONE))) goto error;
  162. if(GetDTAttrs(obj,PDTA_ModeID,&modeid,PDTA_BitMapHeader,&bmhd,TAG_DONE)!=2) goto error;
  163. pictureinfo(h,bmhd->bmh_Width,bmhd->bmh_Height,bmhd->bmh_Depth,modeid,dth->dth_Name);
  164. layout.MethodID=DTM_PROCLAYOUT;
  165. layout.gpl_GInfo=0;
  166. layout.gpl_Initial=TRUE;
  167. if(!DoDTMethodA(obj,0,0,(Msg)&layout)) goto error;
  168. if(GetDTAttrs(obj,PDTA_BitMap,&bm,PDTA_CRegs,&creg,PDTA_NumColors,&ncol,TAG_DONE)!=3) goto error;
  169. if(!bm||!creg||!ncol) goto error;
  170. crsize=(ncol*3)*4;
  171. palsize=crsize+2*4;
  172. palette=allocvec(h->owner,palsize,MEMF_CLEAR);
  173. if(!palette) goto error;
  174. palette[0]=ncol<<16;
  175. CopyMem(creg,&palette[1],crsize);
  176. if(openshowscreen(h->owner,bmhd->bmh_Width,bmhd->bmh_Height,bmhd->bmh_Depth,modeid,bmhd->bmh_Width,bmhd->bmh_Height,bmhd->bmh_Depth,&shows)) {
  177.     LoadRGB32(&shows.screen->ViewPort,palette);
  178.     BltBitMap(bm,0,0,shows.bitmap,0,0,bmhd->bmh_Width,bmhd->bmh_Height,0xC0,0xFF,0);
  179.     WaitBlit();
  180.     SetPointer(shows.window,shows.mouse,2,16,0,0);
  181.     ret=waitbutton(shows.window)+1;
  182.     closeshowscreen(&shows);
  183. }
  184. goto picerr;
  185. error:
  186. if(!ret) requestmsg(h->owner->workname,0,MSG_OK,MSG_MAIN_DATATYPEERROR,dth->dth_Name);
  187. picerr:
  188. freemem(palette);
  189. if(obj) DisposeDTObject(obj);
  190. return(ret);
  191. }
  192.                     
  193.  
  194. WORD showpicture(struct FMHandle *h,struct CMenuConfig *cmc)
  195. {
  196. struct ShowScreen shows;
  197. struct FMList *list;
  198. ULONG modeid;
  199. struct FMBitMapHeader bmhd;
  200.  
  201. UBYTE *cmap=0;
  202. ULONG longi1, longi2, len1;
  203. ULONG ifflen;
  204. WORD fbmhd=0,fmodeid=0,fcmap=0,retcode=0;
  205.  
  206. ULONG cmaplen;
  207. WORD wide,high,deep,sdeep;
  208. WORD apu1;
  209.  
  210. #ifndef V39
  211. UBYTE *ptr1;
  212. #endif
  213. #ifdef V39
  214. ULONG apu3;
  215. ULONG *cmapapu1;
  216. WORD apu2;
  217. #endif
  218.  
  219. memseti(&shows,0,sizeof(struct ShowScreen));
  220. list=h->owner;
  221. changename(list,cmc->label);
  222. priority(cmc);
  223. if (readbufferfile(h,&longi1,4)!=4) goto serr;
  224. sformat(list->fmmessage1,getstring(MSG_FILECLICK_PICTURE),"ILBM",h->filename);
  225. fmmessage(list);
  226. modeid=fmodeid=0;
  227. wide=320;high=256;sdeep=deep=1;
  228.  
  229. if (readbufferfile(h,&ifflen,4)!=4) goto serr;
  230. if (readbufferfile(h,&longi2,4)!=4) goto serr;
  231. ifflen-=4;
  232. if (longi1!='FORM'||longi2!='ILBM') {
  233.     requestmsg(list->workname,0,MSG_OK,MSG_SHOWPIC_NOPICTURE,h->filename);
  234.     goto serr;
  235. }
  236. if (ifflen>h->size-8) goto scorrupt;
  237. for(;;) {
  238.     if (readbufferfile(h,&longi1,4)!=4) goto serr;
  239.     if (readbufferfile(h,&len1,4)!=4) goto serr;
  240.     ifflen-=8;
  241.     if (longi1=='BODY') break;
  242.     switch(longi1)
  243.     {
  244.         case 'BMHD':
  245.         if (len1!=sizeof(struct FMBitMapHeader)) goto scorrupt;
  246.         if (readbufferfile(h,&bmhd,len1)!=len1) goto serr;
  247.         ifflen-=len1;
  248.         fbmhd=1;
  249.         wide=(RowBytes(bmhd.w))>=(RowBytes(bmhd.pageWidth))?bmhd.w:bmhd.pageWidth;
  250.         high=MAX(bmhd.h,bmhd.pageHeight);
  251.         deep=bmhd.nPlanes;
  252.         sdeep=deep<=8?deep:8;
  253.         if(bmhd.compression>1) goto scorrupt;
  254.         break;
  255.         case 'CAMG':
  256.         if (len1!=4) goto scorrupt;
  257.         if (readbufferfile(h,&modeid,len1)!=len1) goto serr;
  258.         ifflen-=len1;
  259.         fmodeid=1;
  260.         break;
  261.         case 'CMAP':
  262.         cmaplen=len1;
  263.         if (!(cmap=allocvec(list,cmaplen,0))) goto serr;
  264.         if (readbufferfile(h,cmap,cmaplen)!=cmaplen) goto serr;
  265.         ifflen-=cmaplen;
  266.         if (cmaplen&1) {
  267.             if (seek(h,1,OFFSET_CURRENT)<0) goto serr;
  268.             ifflen--;
  269.         }
  270.         fcmap=1;
  271.         break;
  272.         default:
  273.         if (len1&1) len1++;
  274.         if (seek(h,len1,OFFSET_CURRENT)<0) goto serr;
  275.         ifflen-=len1;
  276.         break;
  277.     }
  278. }    
  279. if (!fbmhd) goto scorrupt;
  280. if(fmodeid&(!(modeid&MONITOR_ID_MASK))||((modeid&EXTENDED_MODE)&&(!(modeid&0xFFFF0000)))) modeid&=(~(EXTENDED_MODE|SPRITES|GENLOCK_AUDIO|GENLOCK_VIDEO|VP_HIDE));
  281. if(fmodeid&(modeid&0xFFFF0000)&&(!(modeid&0x00001000))) fmodeid=0;
  282. if(!fmodeid) {
  283.     modeid=0;
  284.     if (wide>=640) modeid|=HIRES;
  285.     if (high>=400) modeid|=LACE;
  286.     if (deep==6) modeid|=HAM;
  287. }
  288. pictureinfo(h,wide,high,deep,modeid,"ILBM");
  289.  
  290. if (!openshowscreen(list,wide,high,sdeep,modeid,wide,high,sdeep,&shows)) goto serr;
  291.  
  292. if (fcmap) {
  293. #ifdef V39
  294. if (!(bmhd.Flags&BMHDF_CMAPOK)) {
  295.     apu2=0; for(apu1=0;apu1<cmaplen;apu1++) { if (cmap[apu1]&0x0f) apu2=1; }
  296.     if (!apu2) {
  297.         for(apu1=0;apu1<cmaplen;apu1++) cmap[apu1]|=cmap[apu1]>>4;
  298.     }
  299. }
  300. if (!(cmapapu1=allocvec(list,3*cmaplen*4+8,MEMF_CLEAR))) goto serr;
  301. cmapapu1[0]=(cmaplen/3)<<16;
  302. for(apu1=0;apu1<cmaplen;apu1++) {
  303.     apu3=cmap[apu1];
  304.     cmapapu1[apu1+1]=(apu3<<24)|(apu3<<16)|(apu3<<8)|apu3;
  305. }
  306. LoadRGB32(&shows.screen->ViewPort,cmapapu1);
  307. freemem(cmapapu1);
  308. #else
  309. ptr1=cmap;
  310. for(apu1=0;apu1<cmaplen/3;apu1++) {
  311.     SetRGB4(&shows.screen->ViewPort,apu1,ptr1[0]>>4,ptr1[1]>>4,ptr1[2]>>4);
  312.     ptr1+=3;
  313. }
  314. #endif
  315. }
  316.  
  317. if(!(retcode=decode(h,&shows,&bmhd,ifflen))) {
  318.     SetPointer(shows.window,shows.mouse,2,16,0,0);
  319.     retcode=waitbutton(shows.window);
  320. }
  321. retcode++;
  322. goto serr;
  323.  
  324. scorrupt:
  325. requestmsg(list->workname,0,MSG_OK,MSG_SHOWPIC_CORRUPT,h->filename,"ILBM");
  326. serr:
  327. closeshowscreen(&shows);
  328. freemem(cmap);
  329. return(retcode);
  330. }
  331.  
  332. WORD decode(struct FMHandle *h,struct ShowScreen *shows,struct FMBitMapHeader *bmhd,LONG ifflen)
  333. {
  334. LONG bufsize,nbufsize;
  335. UBYTE *bufptr,*bufend;
  336. WORD apu1,ret=0;
  337. UBYTE *ptr1;
  338. struct BitMap *bm;
  339. //struct BitMap bm2;
  340. struct Window *win;
  341.  
  342. win=shows->window;
  343. bm=shows->tempbm;
  344.  
  345. bufsize=h->bufsize; bufend=h->buffer+bufsize;
  346. if (!(nbufsize=rbytes(h,h->buffer,bufsize,&ifflen))) goto decerr;
  347. apu1=0;
  348. for(;;) {
  349.     bufptr=h->buffer;
  350.     if (bmhd->compression==1)
  351.         unpack(&bufptr,bm,&apu1,bmhd->h,nbufsize,((bmhd->w+15)>>4)<<1,bmhd->masking,shows);
  352.         else
  353.         unpacknp(&bufptr,bm,&apu1,bmhd->h,nbufsize,((bmhd->w+15)>>4)<<1,bmhd->masking,shows);
  354.     if (apu1==bmhd->h) break;
  355.     ret=testbutton(win);
  356.     if(ret) break;
  357.     ptr1=h->buffer;
  358.     while(bufptr!=bufend) *ptr1++=*bufptr++;
  359.     if (!(rbytes(h,ptr1,bufend-ptr1,&ifflen))) goto decerr;
  360. }
  361. decerr:
  362. return(ret);
  363. }
  364.  
  365. LONG rbytes(struct FMHandle *h,UBYTE *bptr,LONG bsize,LONG *ifflen)
  366. {
  367. LONG len;
  368.  
  369. if (!*ifflen) return(0);
  370. len=*ifflen;
  371. if (len>bsize) len=bsize;
  372. if (readbufferfile(h,bptr,len)!=len) return(0);
  373. *ifflen-=len;
  374. return(len);
  375. }
  376.  
  377.  
  378. void clipit(WORD wide,WORD high,
  379.     struct Rectangle *spos,struct Rectangle *dclip,
  380.     struct Rectangle *txto,struct Rectangle *stdo,
  381.     struct Rectangle *maxo)
  382. {
  383. struct  Rectangle *besto;
  384. WORD minx,maxx,miny,maxy;
  385. WORD txtw,txth,stdw,stdh,bestw,besth;
  386.  
  387. txtw=txto->MaxX-txto->MinX+1;
  388. txth=txto->MaxY-txto->MinY+1;
  389. stdw=stdo->MaxX-stdo->MinX+1;
  390. stdh=stdo->MaxY-stdo->MinY+1;
  391.  
  392. if((wide<=txtw)&&(high<=txth)) {
  393.     besto=txto;
  394.     bestw=txtw;
  395.     besth=txth;
  396. } else {
  397.     besto=stdo;
  398.     bestw=stdw;
  399.     besth=stdh;
  400. }
  401. spos->MinX=minx=besto->MinX-((wide-bestw)>>1);
  402. maxx=wide+minx-1;
  403. if(maxx>maxo->MaxX) maxx=maxo->MaxX;
  404. if(minx<maxo->MinX) minx=maxo->MinX;
  405. spos->MinY=miny=besto->MinY-((high-besth)>>1);
  406. spos->MinY=miny=MIN(spos->MinY,txto->MinY);
  407. maxy=high+miny-1;
  408. if(maxy>maxo->MaxY) maxy=maxo->MaxY;
  409. if(miny<maxo->MinY) miny=maxo->MinY;
  410. dclip->MinX=minx;
  411. dclip->MinY=miny;
  412. dclip->MaxX=maxx;
  413. dclip->MaxY=maxy;
  414. }
  415.  
  416. ULONG power2(WORD exp)
  417. {
  418. ULONG ret=1;
  419. while(exp--) ret<<=1;
  420. return(ret);
  421. }
  422.  
  423. #define MODE_ID_MASK (LACE|HIRES|HAM|EXTRA_HALFBRITE)
  424. ULONG modefallback(ULONG oldmode,WORD wide,WORD high,WORD deep)
  425. {
  426. ULONG newmode,bestmode;
  427. struct TagItem tags[6];
  428.  
  429. if(fmmain.kick>=39) {
  430.     tags[0].ti_Tag = BIDTAG_DIPFMustHave;
  431.     tags[0].ti_Data = (oldmode & HAM ? DIPF_IS_HAM : 0);
  432.     tags[0].ti_Data |= (oldmode & EXTRA_HALFBRITE ? DIPF_IS_EXTRAHALFBRITE : 0);
  433.     tags[1].ti_Tag = BIDTAG_NominalWidth;
  434.     tags[1].ti_Data = wide;
  435.     tags[2].ti_Tag = BIDTAG_NominalHeight;
  436.     tags[2].ti_Data = high;
  437.     tags[3].ti_Tag = BIDTAG_Depth;
  438.     tags[3].ti_Data = deep;
  439.     tags[4].ti_Tag = BIDTAG_SourceID;
  440.     tags[4].ti_Data = (FindDisplayInfo(oldmode) ? oldmode : (oldmode & (~(MONITOR_ID_MASK | SPRITES|GENLOCK_AUDIO|GENLOCK_VIDEO|VP_HIDE))));
  441.     tags[5].ti_Tag = TAG_DONE;
  442.     if((bestmode = BestModeIDA(tags)) != INVALID_ID) newmode = bestmode;
  443. } else {
  444.         newmode = oldmode & MODE_ID_MASK;
  445. }
  446. if(ModeNotAvailable(newmode)) {
  447.     newmode=0;
  448.     if (wide>=640) newmode|=HIRES;
  449.     if (high>=400) newmode|=LACE;
  450.     if (deep==6) newmode|=HAM;
  451. }
  452. return(newmode);
  453. }
  454.  
  455. WORD openshowscreen(struct FMList *list,WORD wide,WORD high,WORD deep,ULONG modeid,WORD realw,WORD realh,WORD reald,struct ShowScreen *shows)
  456. {
  457. struct Rectangle spos, dclip, txto, stdo, maxo;
  458. WORD oscan,apu2;
  459. ULONG scrtags[24];
  460. #ifndef V39
  461. WORD apu1;
  462. #endif
  463. extern struct GfxBase *GfxBase;
  464.  
  465. memseti(scrtags,0,24*4);
  466. shows->gfxbase=GfxBase;shows->tempbm=0;
  467. shows->screen=0; shows->window=0; shows->bitmap=0; shows->mouse=0;
  468. shows->mouse=allocvec(list,32,MEMF_CHIP|MEMF_CLEAR);
  469. if(!shows->mouse) goto serr;
  470. #ifdef V39
  471. if(!(shows->bitmap=AllocBitMap(realw,realh,reald,BMF_CLEAR|BMF_DISPLAYABLE|BMF_INTERLEAVED,0))) {
  472.     if(!(shows->bitmap=AllocBitMap(realw,realh,reald,BMF_CLEAR|BMF_DISPLAYABLE,0))) {
  473.         requestmsg(list->workname,0,MSG_OK,MSG_MAIN_ERRNOBITMAP);
  474.         goto serr;
  475.     }
  476. }
  477. #else
  478. if(!(shows->bitmap=allocmem(sizeof(struct BitMap)))) goto serr;
  479. InitBitMap(shows->bitmap,reald,realw,realh);
  480. apu2=1;
  481. for(apu1=0;apu1<reald;apu1++) {
  482.     if(!(shows->bitmap->Planes[apu1]=allocvec(0,RASSIZE(realw,realh),MEMF_CHIP|MEMF_CLEAR))) apu2=0;
  483. }
  484. if(!apu2) {
  485.     requestmsg(list->workname,0,MSG_OK,MSG_MAIN_ERRNOBITMAP);
  486.     goto serr;
  487. }
  488. #endif
  489. if(ModeNotAvailable(modeid)) modeid=modefallback(modeid,wide,high,deep);
  490.  
  491. spos.MinX=0; spos.MinY=0;
  492. oscan=((QueryOverscan(modeid,&txto,OSCAN_TEXT))&&(QueryOverscan(modeid,&stdo,OSCAN_STANDARD))&&(QueryOverscan(modeid,&maxo,OSCAN_MAX)));
  493.  
  494. scrtags[0]=SA_Left; scrtags[1]=spos.MinX;
  495. scrtags[2]=SA_Top; scrtags[3]=spos.MinY;
  496. scrtags[4]=SA_Width; scrtags[5]=wide;
  497. scrtags[6]=SA_Height; scrtags[7]=high;
  498. scrtags[8]=SA_Depth;if(fmmain.kick<39&&deep>6) scrtags[9]=6; else scrtags[9]=deep;
  499. scrtags[10]=SA_Type; scrtags[11]=CUSTOMSCREEN;
  500. scrtags[12]=SA_BitMap; scrtags[13]=(ULONG)(shows->bitmap);
  501. scrtags[14]=SA_DisplayID; scrtags[15]=modeid;
  502. scrtags[16]=SA_Quiet; scrtags[17]=1;
  503. scrtags[18]=SA_AutoScroll; scrtags[19]=1;
  504. scrtags[20]=SA_BackFill; scrtags[21]=(ULONG)LAYERS_NOBACKFILL;
  505. if (oscan) {
  506.     clipit(wide,high,&spos,&dclip,&txto,&stdo,&maxo);
  507.     scrtags[22]=SA_DClip; scrtags[23]=(ULONG)&dclip;
  508. }
  509.  
  510. if (!(shows->screen=OpenScreenTagList(0,(struct TagItem*)scrtags))) {
  511.     requestmsg(list->workname,0,MSG_OK,MSG_MAIN_SCRERR1);
  512.     goto serr;
  513. }
  514. if (!(shows->window=OpenWindowTags(0,
  515.     WA_Left,0,WA_Top,0,WA_Width,wide,WA_Height,high,
  516.     WA_IDCMP,IDCMP_MOUSEBUTTONS|IDCMP_ACTIVEWINDOW|IDCMP_VANILLAKEY,
  517.     WA_Flags,WFLG_BACKDROP|WFLG_BORDERLESS|WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_NOCAREREFRESH,
  518.     WA_BackFill,LAYERS_NOBACKFILL,WA_SimpleRefresh,TRUE,
  519.     WA_CustomScreen,shows->screen,WA_BusyPointer,TRUE,
  520.     TAG_DONE))) {
  521.     requestmsg(list->workname,0,MSG_OK,MSG_MAIN_WINERR1);
  522.     goto serr;
  523. }
  524.  
  525. apu2=1;
  526. #ifndef V39
  527. shows->tempbm=allocmem(sizeof(struct BitMap));
  528. if(shows->tempbm) {
  529.     InitBitMap(shows->tempbm,reald,realw,1);
  530.     for(apu1=0;apu1<reald;apu1++) {
  531.         if(!(shows->tempbm->Planes[apu1]=allocvec(0,shows->tempbm->BytesPerRow,MEMF_CHIP|MEMF_CLEAR))) apu2=0;
  532.     }
  533. }
  534. #else
  535. shows->tempbm=AllocBitMap(realw,1,reald,BMF_CLEAR,0);
  536. #endif
  537. CopyMem(&shows->screen->RastPort,&shows->temprp,sizeof(struct RastPort));
  538. shows->temprp.Layer=0;shows->temprp.BitMap=shows->tempbm;
  539. if(!shows->tempbm||!apu2) {
  540.     requestmsg(list->workname,0,MSG_OK,MSG_MAIN_ERRNOBITMAP);
  541.     goto serr;
  542. }
  543. return(1);
  544. serr:
  545. closeshowscreen(shows);
  546. return(0);
  547. }
  548.  
  549. void closeshowscreen(struct ShowScreen *shows)
  550. {
  551. #ifndef V39
  552. WORD apu1;
  553. #endif
  554.  
  555. if(shows->window) {
  556.     ClearPointer(shows->window);
  557.     CloseWindow(shows->window);
  558. }
  559. freemem(shows->mouse);
  560. if(shows->screen) CloseScreen(shows->screen);
  561. if(shows->bitmap) {
  562.     #ifdef V39
  563.     FreeBitMap(shows->bitmap);
  564.     #else
  565.     for(apu1=0;apu1<8;apu1++) freemem(shows->bitmap->Planes[apu1]);
  566.     freemem(shows->bitmap);    
  567.     #endif
  568. }
  569. if(shows->tempbm) {
  570.     #ifndef V39
  571.     for(apu1=0;apu1<8;apu1++) freemem(shows->tempbm->Planes[apu1]);
  572.     freemem(shows->tempbm);
  573.     #else
  574.     FreeBitMap(shows->tempbm);
  575.     #endif
  576. }
  577. shows->screen=0; shows->window=0; shows->bitmap=0; shows->mouse=0;
  578. shows->tempbm=0;
  579. }
  580.  
  581. WORD testbutton(struct Window *win)
  582. {
  583. struct IntuiMessage *im;
  584. WORD ret=0;
  585.  
  586. while((im=(struct IntuiMessage*)GetMsg(win->UserPort))) {
  587.     if (im->Class==IDCMP_MOUSEBUTTONS) {
  588.         if(im->Code==SELECTDOWN) ret=1;
  589.         if(im->Code==MENUDOWN) ret=-1;
  590.     }
  591.     if (im->Class==IDCMP_VANILLAKEY) {
  592.         if(im->Code==13) ret=1;
  593.         if(im->Code==27) ret=-1;
  594.     }
  595.     ReplyMsg((struct Message*)im);
  596. }    
  597. return(ret);
  598. }
  599. WORD waitbutton(struct Window *window)
  600. {
  601. ULONG class;
  602. UWORD code;
  603. WORD ignorebutton=0,started=1;
  604. WORD ret=0;
  605.  
  606. for(;;) {
  607.     if(smallevent(window,&class,&code)) {
  608.         ret=-1;
  609.         break;
  610.     }
  611.     if(ignorebutton) ignorebutton--;
  612.     if(class==IDCMP_ACTIVEWINDOW&&!started) ignorebutton=2; else started=0;
  613.     if(class==IDCMP_MOUSEBUTTONS&&!ignorebutton) {
  614.         if(code==SELECTDOWN) {
  615.             ret=1;
  616.             break;
  617.         }
  618.         if(code==MENUDOWN) {
  619.             ret=-1;
  620.             break;
  621.         }
  622.     }
  623.     if(class==IDCMP_VANILLAKEY) {
  624.         if(code==0x0d) {
  625.             ret=1;
  626.             break;
  627.         }
  628.         if(code==27) {
  629.             ret=-1;
  630.             break;
  631.         }
  632.     }
  633. }
  634. return(ret);
  635. }
  636.