home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Internet / Strony_WWW / Opus4.x / DOpus414JRsrc.lha / DirectoryOpus4 / Config / screen_screenmode.c < prev    next >
C/C++ Source or Header  |  2000-03-23  |  13KB  |  324 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "config.h"
  32. #include <proto/cybergraphics.h>
  33. #include <cybergraphx/cybergraphics.h>
  34.  
  35. initscreenmodes()
  36. {
  37.     int pal,count,minw,minh,defw,depth,needdef=0,overx,overy,oldcount=0;
  38.     struct Screen scrbuf,*wbscreen;
  39.     char buf[256],namebuf[180];
  40.     struct DimensionInfo *dimension;
  41.     DisplayInfoHandle *handle;
  42.     struct List *pubscreenlist;
  43.     struct PubScreenNode *pubscreen;
  44.     ULONG modeid;
  45.     struct Library *CyberGfxBase;
  46.  
  47.     dimension=(struct DimensionInfo *)buf;
  48.     count=0; depth=4;
  49.  
  50.     if (version2 && (wbscreen=LockPubScreen("Workbench"))) {
  51.         modeid=GetVPModeID(&(wbscreen->ViewPort));
  52.         if ((handle=FindDisplayInfo(modeid))) {
  53.             GetDisplayInfoData(handle,buf,256,DTAG_DIMS,0);
  54.             depth=dimension->MaxDepth;
  55.         }
  56.         UnlockPubScreen(NULL,wbscreen);
  57.     }
  58.     GetWBScreen(&scrbuf);
  59.  
  60.     if (version2) {
  61.         CyberGfxBase = OpenLibrary("cybergraphics.library",0);
  62.         modeid=INVALID_ID;
  63.         while ((modeid=NextDisplayInfo(modeid))!=INVALID_ID) {
  64.             if (!ModeNotAvailable(modeid) &&
  65.                 (handle=FindDisplayInfo(modeid)) &&
  66.                 (GetDisplayInfoData(handle,namebuf,128,DTAG_NAME,0)) &&
  67.                 (GetDisplayInfoData(handle,buf,256,DTAG_DIMS,0))) {
  68.                 if (CyberGfxBase)
  69.                  {
  70.                   if (IsCyberModeID(modeid))
  71.                    {
  72.                     minw = GetCyberIDAttr(CYBRIDATTR_WIDTH,modeid);
  73.                     dimension->MinRasterHeight = dimension->MaxRasterHeight = GetCyberIDAttr(CYBRIDATTR_HEIGHT,modeid);
  74.                     dimension->MaxDepth = GetCyberIDAttr(CYBRIDATTR_DEPTH,modeid);
  75.                     dimension->TxtOScan.MaxX = minw-1;
  76.                     dimension->TxtOScan.MinX = 0;
  77.                     dimension->TxtOScan.MaxY = dimension->MinRasterHeight-1;
  78.                     dimension->TxtOScan.MinY = 0;
  79.                    }
  80.                  }
  81.                 else if (modeid&HIRES_KEY || modeid&HIRESLACE_KEY) minw=640;
  82.                 else {
  83.                     minw=dimension->MinRasterWidth;
  84.                     if (minw<160) minw*=10;
  85.                 }
  86.                 minh=dimension->MinRasterHeight; if (minh<200) minh=200;
  87.                 defw=(dimension->TxtOScan.MaxX-dimension->TxtOScan.MinX)+1;
  88.                 if (minw>=640 && defw>=640) {
  89.                     count+=addscreenmode(((struct NameInfo *)namebuf)->Name,
  90.                         minw,minh,
  91.                         dimension->MaxRasterWidth,dimension->MaxRasterHeight,
  92.                         defw,(dimension->TxtOScan.MaxY-dimension->TxtOScan.MinY)+1,
  93.                         dimension->MaxDepth,modeid);
  94.                 }
  95.             }
  96.         }
  97.         if (count==0) needdef=1;
  98.         else {
  99.             sortscreenmodes(count,0);
  100.             oldcount=count;
  101.         }
  102.         if (pubscreenlist=LockPubScreenList()) {
  103.             pubscreen=(struct PubScreenNode *)pubscreenlist->lh_Head;
  104.             while (pubscreen->psn_Node.ln_Succ) {
  105.                 if (strcmp(pubscreen->psn_Node.ln_Name,"Workbench")!=0 &&
  106.                     pubscreen->psn_Screen->Width>=640 &&
  107.                     pubscreen->psn_Screen->Height>=200 &&
  108.                     pubscreen->psn_Screen->RastPort.BitMap->Depth>1) {
  109.  
  110.                     lsprintf(namebuf,"%s:%s",pubscreen->psn_Node.ln_Name,cfg_string[STR_SCREEN_MODE_USE]);
  111.                     count+=addscreenmode(namebuf,
  112.                         640,200,
  113.                         pubscreen->psn_Screen->Width,pubscreen->psn_Screen->Height,
  114.                         pubscreen->psn_Screen->Width,pubscreen->psn_Screen->Height,
  115.                         pubscreen->psn_Screen->RastPort.BitMap->Depth,MODE_PUBLICSCREENUSE);
  116. /*
  117.                     modeid=GetVPModeID(&pubscreen->psn_Screen->ViewPort);
  118.                     if ((handle=FindDisplayInfo(modeid))) {
  119.                         GetDisplayInfoData(handle,buf,256,DTAG_DIMS,0);
  120.                         a=dimension->MaxDepth;
  121.                     }
  122.                     else a=4;
  123.  
  124.                     lsprintf(namebuf,"%s:%s",pubscreen->psn_Node.ln_Name,cfg_string[STR_SCREEN_MODE_CLONE]);
  125.                     count+=addscreenmode(namebuf,
  126.                         pubscreen->psn_Screen->Width,pubscreen->psn_Screen->Height,
  127.                         0,0,
  128.                         0,0,
  129.                         a,MODE_PUBLICSCREENCLONE);
  130. */
  131.                 }
  132.                 pubscreen=(struct PubScreenNode *)pubscreen->psn_Node.ln_Succ;
  133.             }
  134.             UnlockPubScreenList();
  135.         }
  136.      CloseLibrary(CyberGfxBase);
  137.     }
  138.     else needdef=1;
  139.  
  140.     if (needdef) {
  141.         pal=GfxBase->DisplayFlags&PAL;
  142.         overx=704-GfxBase->NormalDisplayColumns;
  143.         if (overx<0) overx=0;
  144.         overy=((pal)?290:240)-GfxBase->NormalDisplayRows;
  145.         if (overy<0) overy=0;
  146.  
  147.         count+=addscreenmode(pal?"PAL:High Res":"NTSC:High Res",
  148.             640,200,
  149.             GfxBase->NormalDisplayColumns+overx,GfxBase->NormalDisplayRows+overy,
  150.             GfxBase->NormalDisplayColumns,GfxBase->NormalDisplayRows,
  151.             4,HIRES_KEY);
  152.         count+=addscreenmode(pal?"PAL:High Res Laced":"NTSC:High Res Laced",
  153.             640,200,
  154.             GfxBase->NormalDisplayColumns+overx,(GfxBase->NormalDisplayRows+overy)*2,
  155.             GfxBase->NormalDisplayColumns,GfxBase->NormalDisplayRows*2,
  156.             4,HIRESLACE_KEY);
  157.     }
  158.  
  159.     count+=addscreenmode(cfg_string[STR_MODE_WORKBENCH_USE],
  160.         640,200,
  161.         scrbuf.Width,scrbuf.Height,
  162.         scrbuf.Width,scrbuf.Height,
  163.         scrbuf.RastPort.BitMap->Depth,MODE_WORKBENCHUSE);
  164.     count+=addscreenmode(cfg_string[STR_MODE_WORKBENCH_CLONE],
  165.         scrbuf.Width,scrbuf.Height,
  166.         0,0,
  167.         0,0,
  168.         depth,MODE_WORKBENCHCLONE);
  169.  
  170.     if (count>oldcount) sortscreenmodes(count-oldcount,oldcount);
  171.     return(count);
  172. }
  173.  
  174. addscreenmode(name,minw,minh,maxw,maxh,defw,defh,depth,mode)
  175. char *name;
  176. UWORD minw,minh,maxw,maxh,defw,defh,depth;
  177. ULONG mode;
  178. {
  179.     struct ScreenMode *scrmode;
  180.  
  181.     screenmode=firstmode;
  182.     while (screenmode) {
  183.         if (LStrCmpI(screenmode->name,name)==0) return(0);
  184.         if (!screenmode->next) break;
  185.         screenmode=screenmode->next;
  186.     }
  187.  
  188.     if (scrmode=LAllocRemember(&screenkey,sizeof(struct ScreenMode),MEMF_CLEAR)) {
  189.         if (screenmode) screenmode->next=scrmode;
  190.         else firstmode=scrmode;
  191.         strcpy(scrmode->name,name);
  192.         scrmode->minw=minw; scrmode->minh=minh;
  193.         if (maxw==0) scrmode->maxw=minw; else scrmode->maxw=maxw;
  194.         if (maxh==0) scrmode->maxh=minh; else scrmode->maxh=maxh;
  195.         if (defw==0) scrmode->defw=minw; else scrmode->defw=defw;
  196.         if (defh==0) scrmode->defh=minh; else scrmode->defh=defh;
  197.         scrmode->maxdepth=(depth>4)?4:depth;
  198.         scrmode->mode=mode;
  199.         return(1);
  200.     }
  201.     return(0);
  202. }
  203.  
  204. struct ScreenMode *showdisplaydesc()
  205. {
  206.     struct ScreenMode *mode;
  207.     char buf[80];
  208.  
  209.     SetAPen(rp,screen_pens[0].pen);
  210.     RectFill(rp,x_off+238,y_off+140,x_off+509,y_off+179);
  211.     SetAPen(rp,screen_pens[1].pen);
  212.     if (!(mode=getscreenmode(screenmodeview.itemselected))) return(NULL);
  213.     lsprintf(buf,"%-16s: %ld %s %ld",cfg_string[STR_MINIMUM_SIZE],mode->minw,cfg_string[STR_BY],mode->minh);
  214.     UScoreText(rp,buf,x_off+240,y_off+147,-1);
  215.     lsprintf(buf,"%-16s: %ld %s %ld",cfg_string[STR_MAXIMUM_SIZE],mode->maxw,cfg_string[STR_BY],mode->maxh);
  216.     UScoreText(rp,buf,x_off+240,y_off+155,-1);
  217.     lsprintf(buf,"%-16s: %ld %s %ld",cfg_string[STR_DEFAULT_SIZE],mode->defw,cfg_string[STR_BY],mode->defh);
  218.     UScoreText(rp,buf,x_off+240,y_off+163,-1);
  219.     lsprintf(buf,"%-16s: %ld",cfg_string[STR_MAXIMUM_COLORS],(1<<mode->maxdepth));
  220.     UScoreText(rp,buf,x_off+240,y_off+171,-1);
  221.     return(mode);
  222. }
  223.  
  224. void fixmodegads(mode)
  225. struct ScreenMode *mode;
  226. {
  227.     lsprintf(screenwidth_buf,"%ld",config->scrw);
  228.     lsprintf(screenheight_buf,"%ld",config->scrh);
  229.     if (config->scrdepth<2) config->scrdepth+=2;
  230.     if (config->scrdepth>((mode)?mode->maxdepth:4))
  231.         config->scrdepth=((mode)?mode->maxdepth:4);
  232.     lsprintf(screendepth_buf,"%ld",(1<<config->scrdepth));
  233.     if (mode && !(screenmodegads[SCREENMODE_WIDTH-300].Flags&GADGDISABLED)) {
  234.         if (!(CheckNumGad(&screenmodegads[SCREENMODE_WIDTH-300],Window,mode->minw,mode->maxw)))
  235.             RefreshStrGad(&screenmodegads[SCREENMODE_WIDTH-300],Window);
  236.     }
  237.     if (mode && !(screenmodegads[SCREENMODE_HEIGHT-300].Flags&GADGDISABLED)) {
  238.         if (!(CheckNumGad(&screenmodegads[SCREENMODE_HEIGHT-300],Window,mode->minh,mode->maxh)))
  239.             RefreshStrGad(&screenmodegads[SCREENMODE_HEIGHT-300],Window);
  240.     }
  241.     EnableGadget(&screenmodegads[SCREENMODE_DEPTH-300],rp,0,0);
  242.     RefreshStrGad(&screenmodegads[SCREENMODE_DEPTH-300],Window);
  243.     if (mode) {
  244.         if (mode->maxdepth==2 ||
  245.             (version2<OSVER_39 && 
  246.                 (mode->mode==MODE_WORKBENCHUSE || mode->mode==MODE_PUBLICSCREENUSE))) {
  247.             DisableGadget(&screenmodegads[SCREENMODE_DEPTH-300],rp,0,0);
  248.             FixSliderBody(Window,&screenmodegads[SCREENMODE_SLIDER-300],1,1,0);
  249.         }
  250.         else FixSliderBody(Window,&screenmodegads[SCREENMODE_SLIDER-300],mode->maxdepth-1,1,0);
  251.     }
  252.     FixSliderPot(Window,&screenmodegads[SCREENMODE_SLIDER-300],config->scrdepth-2,mode->maxdepth-1,1,2);
  253. }
  254.  
  255. void fixdefaultgads(mode)
  256. struct ScreenMode *mode;
  257. {
  258.     if (config->screenflags&SCRFLAGS_DEFWIDTH ||
  259.         mode->mode==MODE_WORKBENCHCLONE ||
  260.         mode->mode==MODE_PUBLICSCREENCLONE) {
  261.         config->screenflags|=SCRFLAGS_DEFWIDTH;
  262.         screenmodegads[SCREENMODE_DEFWIDTH-300].Flags|=SELECTED;
  263.         DisableGadget(&screenmodegads[SCREENMODE_WIDTH-300],rp,0,0);
  264.     }
  265.     else {
  266.         screenmodegads[SCREENMODE_DEFWIDTH-300].Flags&=~SELECTED;
  267.         EnableGadget(&screenmodegads[SCREENMODE_WIDTH-300],rp,0,0);
  268.     }
  269.     if (config->screenflags&SCRFLAGS_DEFHEIGHT ||
  270.         mode->mode==MODE_WORKBENCHCLONE ||
  271.         mode->mode==MODE_PUBLICSCREENCLONE) {
  272.         config->screenflags|=SCRFLAGS_DEFHEIGHT;
  273.         screenmodegads[SCREENMODE_DEFHEIGHT-300].Flags|=SELECTED;
  274.         DisableGadget(&screenmodegads[SCREENMODE_HEIGHT-300],rp,0,0);
  275.     }
  276.     else {
  277.         screenmodegads[SCREENMODE_DEFHEIGHT-300].Flags&=~SELECTED;
  278.         EnableGadget(&screenmodegads[SCREENMODE_HEIGHT-300],rp,0,0);
  279.     }
  280.     if (mode->maxdepth==2 ||
  281.         (version2<OSVER_39 && 
  282.             (mode->mode==MODE_WORKBENCHUSE || mode->mode==MODE_PUBLICSCREENUSE)))
  283.         DisableGadget(&screenmodegads[SCREENMODE_DEPTH-300],rp,0,0);
  284.     else EnableGadget(&screenmodegads[SCREENMODE_DEPTH-300],rp,0,0);
  285.  
  286.     EnableGadget(&screenmodegads[SCREENMODE_DEFWIDTH-300],rp,2,1);
  287.     EnableGadget(&screenmodegads[SCREENMODE_DEFHEIGHT-300],rp,2,1);
  288.     RefreshGList(&screenmodegads[SCREENMODE_DEFWIDTH-300],Window,NULL,2);
  289.     if (mode->mode==MODE_WORKBENCHCLONE || mode->mode==MODE_PUBLICSCREENCLONE) {
  290.         DisableGadget(&screenmodegads[SCREENMODE_DEFWIDTH-300],rp,2,1);
  291.         DisableGadget(&screenmodegads[SCREENMODE_DEFHEIGHT-300],rp,2,1);
  292.     }
  293. }
  294.  
  295. void sortscreenmodes(count,off)
  296. int count,off;
  297. {
  298.     int gap,i,j;
  299.     struct ScreenMode *mode1,*mode2;
  300.  
  301.     for (gap=count/2;gap>0;gap/=2)
  302.         for (i=gap;i<count;i++)
  303.             for (j=i-gap;j>=0;j-=gap) {
  304.                 mode1=getscreenmode(j+off);
  305.                 mode2=getscreenmode(j+gap+off);
  306.                 if (!mode1 || !mode2 || LStrCmpI(mode1->name,mode2->name)<=0) break;
  307.                 SwapMem((char *)mode1->name,(char *)mode2->name,sizeof(struct ScreenMode)-4);
  308.             }
  309. }
  310.  
  311. struct ScreenMode *getscreenmode(m)
  312. int m;
  313. {
  314.     struct ScreenMode *mode;
  315.     int a;
  316.  
  317.     mode=firstmode;
  318.     for (a=0;a<m;a++) {
  319.         if (!mode) break;
  320.         mode=mode->next;
  321.     }
  322.     return(mode);
  323. }
  324.