home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / fm2000 / fmoutput.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-04  |  9.5 KB  |  365 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.  
  21. #include <proto/all.h>
  22. #include <exec/types.h>
  23. #include <dos.h>
  24. #include <string.h>
  25. #include "fmnode.h"
  26. #include "fmlocale.h"
  27.  
  28. void setsliders(struct FMList*);
  29. struct FMNode *iteratenode(struct FMNode**);
  30.  
  31. extern struct FMConfig *fmconfig;
  32. extern struct FMMain fmmain;
  33. extern UBYTE space[];
  34.  
  35. static void outputline(struct FMList *list,struct FMNode *node,WORD maxlen,WORD offset,WORD xx,WORD yy)
  36. {
  37. UBYTE varatxt[512];
  38. UBYTE *ptr1,*ptr2;
  39. WORD rlen,len,cnt1,apu1;
  40. struct DirListLayout *dll;
  41.  
  42. memseti(varatxt,32,fmmain.maxdirlistwidth+1);
  43. Move(fmmain.rp,xx,yy+fmmain.listbaseline);
  44. rlen=0;
  45. if (node&&node->succ) {
  46.     if(node->flags&NSELECTED)
  47.         SetDrMd(fmmain.rp,JAM2|INVERSVID);
  48.         else
  49.         SetDrMd(fmmain.rp,JAM2);
  50.     if(node->flags&(NASSIGN|NDIRECTORY))
  51.         SetAPen(fmmain.rp,fmconfig->dirpen);
  52.         else
  53.         SetAPen(fmmain.rp,fmconfig->filepen);
  54.     if(node->flags&NDEVICE) SetAPen(fmmain.rp,fmconfig->devicepen);
  55.     if(node->flags&NKEYBOARD)
  56.         SetBPen(fmmain.rp,fmconfig->hilipen);
  57.         else
  58.         SetBPen(fmmain.rp,fmconfig->backpen);
  59.     ptr2=varatxt;
  60.     if (list->flags & LDIRLIST) {
  61.         for(cnt1=0;cnt1<5;cnt1++) {
  62.             dll=&fmconfig->dl[cnt1];
  63.             switch(dll->type)
  64.             {
  65.             case 0:
  66.             ptr1=NDLENGTH(node);
  67.             break;    
  68.             case 1:
  69.             ptr1=NDFILE(node);
  70.             break;    
  71.             case 2:
  72.             ptr1=NDPROT(node);
  73.             break;    
  74.             case 3:
  75.             ptr1=NDDATE(node);
  76.             break;    
  77.             case 4:
  78.             ptr1=NDCOMM(node);
  79.             break;
  80.             }
  81.             len=strlen(ptr1);
  82.             if(dll->rightlock) {
  83.                 ptr2=varatxt+list->li->visiblelinesw-dll->width;
  84.             }
  85.             if(dll->rightaligned) {
  86.                 apu1=dll->width-len;
  87.                 if(apu1<0) apu1=0;
  88.                 CopyMem(ptr1,ptr2+apu1,len);
  89.             } else {
  90.                 CopyMem(ptr1,ptr2,len);
  91.             }
  92.             ptr2+=dll->width;
  93.             *ptr2++=32;
  94.         }
  95.     } else {
  96.         CopyMem(NDFILE(node),ptr2,strlen(NDFILE(node)));
  97.         ptr2+=8;
  98.         if (node->flags & NDEVICE) {
  99.             CopyMem(NDCOMM(node),ptr2,strlen(NDCOMM(node)));
  100.             ptr2=varatxt+list->li->visiblelinesw-6;
  101.             CopyMem(NDCOMM(node)+fmmain.commlen/2,ptr2,strlen(NDCOMM(node)+fmmain.commlen/2));
  102.         }
  103.     }
  104.     rlen=fmmain.maxdirlistwidth-offset;
  105.     if (rlen>maxlen) rlen=maxlen;
  106.     if (rlen>0) Text(fmmain.rp,&varatxt[offset],rlen); else rlen=0;
  107. } else {
  108.     SetDrMd(fmmain.rp,JAM2);
  109. }
  110. if (rlen<maxlen) Text(fmmain.rp,space,maxlen-rlen);
  111. }
  112.  
  113. void scrollndraw(void)
  114. {
  115. //fline=line to draw
  116. //liney=pixel offset
  117. //samount=scroll amount
  118. //nlines=lines to draw
  119.  
  120. WORD xx,yy,aa;
  121. struct FMList *list;
  122. struct FMNode *node;
  123. struct ReqScrollStruct *rscroll;
  124. struct ListInfo *li;
  125. WORD fline,liney,samount,nlines;
  126.  
  127. fline=(WORD)getreg(REG_D0);
  128. liney=(WORD)getreg(REG_D1);
  129. samount=(WORD)getreg(REG_D2);
  130. nlines=(WORD)getreg(REG_D3);
  131. rscroll=(struct ReqScrollStruct*)getreg(REG_A0);
  132. if (!fmmain.ikkuna) return;
  133. ObtainSemaphore(&fmmain.gfxsema);
  134. SetFont(fmmain.rp,fmmain.listfont);
  135. list=rscroll->fmlist;
  136. li=list->li;
  137. yy=li->diry; xx=li->dirx;
  138. node=(struct FMNode*)list;
  139. iteratenode(&node);
  140. if (!rscroll->flags) {
  141.     if(rscroll->LineSpacing==1) {
  142.         samount*=fmmain.listysize;
  143.         liney*=fmmain.listysize;
  144.     }
  145.     ScrollRaster(fmmain.rp,0,samount,xx,yy,xx+li->dirwidth-1,yy+li->dirheight-1);
  146.     yy+=liney;
  147.     list->firstline=rscroll->TopEntryNumber;
  148.     while(fline>0) { fline--; iteratenode(&node); }
  149.     while(nlines>0) {
  150.         nlines--;
  151.         outputline(list,node,li->visiblelinesw,list->firstlinew,xx,yy);
  152.         iteratenode(&node);
  153.         yy+=fmmain.listysize;
  154.     }
  155. } else {
  156.     if(rscroll->LineSpacing==1) {
  157.         samount*=fmmain.listxsize;
  158.         liney*=fmmain.listxsize;
  159.     }
  160.     ScrollRaster(fmmain.rp,samount,0,xx,yy,xx+li->dirwidth-1,yy+li->dirheight-1);
  161.     aa=list->firstline;
  162.     while(aa>0) { iteratenode(&node); aa--; }
  163.     xx+=liney;
  164.     list->firstlinew=rscroll->TopEntryNumber;
  165.     if (nlines) {
  166.         for(aa=0;aa<li->visiblelines;aa++) {
  167.             outputline(list,node,nlines,fline,xx,yy);
  168.             iteratenode(&node);
  169.             yy+=fmmain.listysize;
  170.         }
  171.     }
  172.     }
  173. SetDrMd(fmmain.rp,JAM2);
  174. SetBPen(fmmain.rp,fmconfig->backpen);
  175. SetFont(fmmain.rp,fmmain.txtfont);
  176. ReleaseSemaphore(&fmmain.gfxsema);
  177. }
  178.  
  179. void outputlistline(struct FMList *list,struct FMNode *node)
  180. {
  181. struct FMNode *node2;
  182. struct ListInfo *li;
  183. WORD cnt=0,yy;
  184.  
  185. li=list->li;
  186. if (!fmmain.ikkuna||!li) return;
  187. node2=(struct FMNode*)list;
  188. iteratenode(&node2);
  189. while(node!=node2) { iteratenode(&node2); cnt++; }
  190. cnt-=list->firstline;
  191. yy=li->diry;
  192. if (cnt<li->visiblelines) {
  193.     ObtainSemaphore(&fmmain.gfxsema);
  194.     SetFont(fmmain.rp,fmmain.listfont);
  195.     yy+=cnt*fmmain.listysize;
  196.     outputline(list,node,li->visiblelinesw,list->firstlinew,li->dirx,yy);
  197.     SetDrMd(fmmain.rp,JAM2);
  198.     SetBPen(fmmain.rp,fmconfig->backpen);
  199.     SetFont(fmmain.rp,fmmain.txtfont);
  200.     ReleaseSemaphore(&fmmain.gfxsema);
  201. }
  202. }
  203.  
  204. void drawall(struct ReqScrollStruct *rscroll)
  205. {
  206. struct FMList *list;
  207. struct ListInfo *li;
  208. struct FMNode *node;
  209. WORD aa,yy;
  210.  
  211. list=rscroll->fmlist;
  212. li=list->li;
  213. if (!fmmain.ikkuna||!li) return;
  214. ObtainSemaphore(&fmmain.gfxsema);
  215. SetFont(fmmain.rp,fmmain.listfont);
  216. yy=li->diry;
  217. node=(struct FMNode*)list;
  218. iteratenode(&node);
  219. aa=list->firstline;
  220. while(aa>0) { iteratenode(&node); aa--; }
  221. for(aa=0;aa<li->visiblelines;aa++) {
  222.     outputline(list,node,li->visiblelinesw,list->firstlinew,li->dirx,yy);
  223.     iteratenode(&node);
  224.     yy+=fmmain.listysize;
  225. }
  226. SetDrMd(fmmain.rp,JAM2);
  227. SetBPen(fmmain.rp,fmconfig->backpen);
  228. SetFont(fmmain.rp,fmmain.txtfont);
  229. ReleaseSemaphore(&fmmain.gfxsema);
  230. }
  231.  
  232. void outputlist(struct FMList *list)
  233. {
  234. if(list&&list->li) {
  235.     updatelist(list);
  236.     fmoutput(list);
  237. }
  238. }
  239.  
  240. void fmoutput(struct FMList *list)
  241. {
  242. if (fmmain.ikkuna&&list->li) {
  243.     list->li->rscroll1.NumEntries=list->totlines;
  244.     list->li->rscroll2.NumEntries=list->totlinesw;
  245.     drawall(&list->li->rscroll1);
  246.     list->li->rscroll1.TopEntryNumber=list->firstline;
  247.     list->li->rscroll2.TopEntryNumber=list->firstlinew;
  248. }
  249. }
  250.  
  251. void updatelist(struct FMList *list)
  252. {
  253. struct FMNode *node;
  254. LONG totlines,firstline,visiblelines;
  255. WORD aa=0;
  256.  
  257. node=(struct FMNode*)list;
  258. while(iteratenode(&node)) aa++;
  259. list->totlines=aa;
  260. totlines=list->totlines;
  261. firstline=list->firstline;
  262. visiblelines=list->li->visiblelines;
  263. if (totlines-firstline<visiblelines) firstline=totlines-visiblelines;
  264. if (firstline<0) firstline=0;
  265. list->firstline=firstline;
  266. list->totlinesw=fmmain.maxdirlistwidth;
  267. setsliders(list);
  268. }
  269.  
  270.  
  271. static void createsliderimage(struct Image *im,WORD type)
  272. {
  273. struct RastPort rp;
  274. struct BitMap bm;
  275. WORD apu1,width,height;
  276. UBYTE *ptr1;
  277.  
  278. InitRastPort(&rp);
  279. InitBitMap(&bm,im->Depth,im->Width,im->Height);
  280. ptr1=(UBYTE*)im->ImageData;
  281. for(apu1=0;apu1<im->Depth;apu1++) {
  282.     bm.Planes[apu1]=ptr1;
  283.     ptr1+=RASSIZE(im->Width,im->Height);
  284. }
  285. rp.BitMap=&bm;
  286. width=im->Width-1;
  287. height=im->Height-1;
  288. SetAPen(&rp,fmconfig->sliderpen);
  289. RectFill(&rp,0,0,width,height);
  290. if(!type) SetAPen(&rp,fmconfig->whitepen); else SetAPen(&rp,fmconfig->blackpen);
  291. Move(&rp,0,im->Height);
  292. Draw(&rp,0,0);
  293. Draw(&rp,width-1,0);
  294. if(fmconfig->flags&MDOUBLED) {
  295.     Move(&rp,1,im->Height);
  296.     Draw(&rp,1,0);
  297. }
  298. if(type) SetAPen(&rp,fmconfig->whitepen); else SetAPen(&rp,fmconfig->blackpen);
  299. Move(&rp,width,0);
  300. Draw(&rp,width,height);
  301. Draw(&rp,1,height);
  302. if(fmconfig->flags&MDOUBLED) {
  303.     Move(&rp,width-1,im->Height);
  304.     Draw(&rp,width-1,1);
  305. }
  306. }
  307.  
  308. static void setpot(struct Gadget *gadg,UWORD overlap,UWORD totlines,UWORD vislines,UWORD topline,UWORD type)
  309. {
  310. UWORD hidden,body,pot;
  311. WORD oldpos;
  312. WORD size;
  313. struct PropInfo *pi;
  314.  
  315. if (totlines>vislines) hidden=totlines-vislines; else hidden=0;
  316. if (topline>hidden) topline=hidden;
  317. if (hidden>0) 
  318.     body=(UWORD)(((ULONG)(vislines-overlap)*MAXBODY)/(totlines-overlap));
  319.     else
  320.     body=MAXBODY;
  321. if (hidden>0)
  322.     pot=(UWORD)(((ULONG)topline*MAXPOT)/hidden);
  323.     else
  324.     pot=0;
  325. pi=(struct PropInfo*)gadg->SpecialInfo;
  326. if (fmmain.ikkuna) {
  327.     if (type) {
  328.         if(pi->HorizPot!=pot||pi->HorizBody!=body) {
  329.             NewModifyProp(gadg,fmmain.ikkuna,0,FREEHORIZ|PROPBORDERLESS,pot,MAXPOT,body,MAXBODY,1);
  330.             oldpos=RemoveGadget(fmmain.ikkuna,gadg);
  331.             size=((ULONG)body*(ULONG)(gadg->Width))/(ULONG)65535;
  332.             if(size<8) {
  333.                 size=8;
  334.                 if(fmconfig->flags&MDOUBLED) size*=2;
  335.             }
  336.             ((struct Image*)gadg->GadgetRender)->Width=((struct Image*)gadg->SelectRender)->Width=size;
  337.             createsliderimage((struct Image*)gadg->GadgetRender,0);
  338.             createsliderimage((struct Image*)gadg->SelectRender,1);
  339.             AddGadget(fmmain.ikkuna,gadg,oldpos);
  340.              RefreshGList(gadg,fmmain.ikkuna,0,1);
  341.         }
  342.     } else {
  343.         if(pi->VertPot!=pot||pi->VertBody!=body) {
  344.             NewModifyProp(gadg,fmmain.ikkuna,0,FREEVERT|PROPBORDERLESS,MAXPOT,pot,MAXBODY,body,1);
  345.             oldpos=RemoveGadget(fmmain.ikkuna,gadg);
  346.             size=((ULONG)body*(ULONG)(gadg->Height))/(ULONG)65535;
  347.             if(size<8) size=8;
  348.             ((struct Image*)gadg->GadgetRender)->Height=((struct Image*)gadg->SelectRender)->Height=size;
  349.             createsliderimage((struct Image*)gadg->GadgetRender,0);
  350.             createsliderimage((struct Image*)gadg->SelectRender,1);
  351.             AddGadget(fmmain.ikkuna,gadg,oldpos);
  352.             RefreshGList(gadg,fmmain.ikkuna,0,1);
  353.         }
  354.     }
  355. }
  356. }
  357.  
  358. void setsliders(struct FMList *list)
  359. {
  360. if(list->li&&fmmain.ikkuna) {
  361.     setpot(&list->li->slider1,1,list->totlines,list->li->visiblelines,list->firstline,0);
  362.     setpot(&list->li->slider2,1,list->totlinesw,list->li->visiblelinesw,list->firstlinew,1);
  363. }
  364. }
  365.