home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / grafix / boards / cybergfx4043.lha / cybershare / devdocs / examples / cybersavegio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-31  |  10.5 KB  |  430 lines

  1. /* cybergraphics saver - (C) Vision Factor Development 1994 31/12/94
  2.  
  3.    Saver for Photogenics
  4.    Photogenics © Almathera 1994, All Rights Reserved
  5.  
  6. REQUIRES: SAS C V6.50 or higher.
  7.  
  8. */
  9.  
  10.     #include <exec/types.h>
  11.     #include <clib/exec_protos.h>
  12.     #include <dos/dos.h>
  13.     #include <pragmas/exec_pragmas.h>
  14.     #include <cybergraphics/cybergraphics.h>
  15.     #include <intuition/intuition.h>
  16.     #include <pragmas/intuition_pragmas.h>
  17.     #include <pragmas/cybergraphics_pragmas.h>
  18.     #include <proto/exec.h>
  19.     #include <proto/intuition.h>
  20.     #include <proto/graphics.h>
  21.     #include <proto/cybergraphics.h>
  22.     #include "pgs_protos.h"
  23.     #include "pgs_pragmas.h"
  24.     #include "gio.h"
  25.  
  26. struct    TagItem CModeTags[]=
  27.     {
  28.      CYBRMREQ_Screen,0,
  29.      CYBRMREQ_MinDepth,15,
  30.      CYBRMREQ_MaxDepth,32,
  31.      CYBRMREQ_WinTitle,(ULONG)"Select CyBERgraphics ScreenMode",
  32.      CYBRMREQ_OKText,(ULONG)"OK",
  33.      CYBRMREQ_CancelText,(ULONG)"Cancel",
  34.      TAG_DONE
  35.     };
  36.  
  37.  
  38. struct Library *CyberGfxBase;
  39.  
  40. /* prototypes */
  41. __asm ULONG __saveds GioInfo(void);
  42. __asm ULONG __saveds GioExamine(register __a0 struct GIOData *giodata);
  43. __asm ULONG __saveds GioRead(register __a0 struct GIOData *giodata);
  44. __asm ULONG __saveds GioWrite(register __a0 struct GIOData *giodata);
  45. /* end of prototypes */
  46.  
  47.  
  48. __asm ULONG __saveds GioInfo(void)
  49. {
  50.     return(GIOF_SAVER24);
  51. }
  52.  
  53. __asm ULONG __saveds GioExamine(register __a0 struct GIOData *giodata)
  54. {
  55.  return(0L);
  56. }
  57.  
  58. #define DOSBase giodata->DOSBase
  59. #define PgsBase giodata->PgsBase
  60. #define IntuitionBase giodata->IntuitionBase
  61.  
  62. __asm ULONG __saveds GioRead(register __a0 struct GIOData *giodata)
  63. {
  64.  return(0L);
  65. }
  66.  
  67. WriteRect(struct GIOData *giodata,UWORD SrcX,UWORD SrcY,UWORD SrcMod,struct RastPort *rp,UWORD DestX,UWORD DestY,UWORD SizeX,UWORD SizeY);
  68.  
  69. WriteRect(struct GIOData *giodata,UWORD SrcX,UWORD SrcY,UWORD SrcMod,struct RastPort *rp,UWORD DestX,UWORD DestY,UWORD SizeX,UWORD SizeY)
  70. {
  71.  int i,j;
  72.  UBYTE *peeker;
  73.  
  74.  for(i=0;i<SizeY;i++)
  75.  {
  76.     peeker=GetLine(giodata,i+SrcY);
  77.     WritePixelArray(peeker,SrcX,0,SizeX*3,rp,DestX,DestY+i,SizeX,1,RECTFMT_RGB);
  78.     ReleaseLine(giodata,i+SrcY);
  79.  };
  80. }
  81.  
  82. __asm ULONG __saveds GioWrite(register __a0 struct GIOData *giodata)
  83. {
  84.     if (giodata->Depth == 24)
  85.     {
  86.      int ScrWidth,ScrHeight,OffX=0,OffY=0,DispWidth,DispHeight;
  87.  
  88.     if(CyberGfxBase=OpenLibrary("cybergraphics.library",40))
  89.     {
  90.      struct Screen *Scr,*PScr;
  91.      struct RastPort *rp;
  92.      struct BitMap *bm;
  93.      long    depth;
  94.      int Width,Height;
  95.      ULONG    ModeID;
  96.  
  97.      PScr=(ULONG)giodata->PgsScreen;
  98.      ModeID=GetVPModeID(&PScr->ViewPort);
  99.      if(IsCyberModeID(ModeID))
  100.      {
  101.       depth=GetCyberIDAttr(CYBRIDATTR_DEPTH,ModeID);
  102.      }
  103.      else
  104.      {
  105.           depth=8;
  106.      }
  107.  
  108.     if(depth <= 8)
  109.     {
  110.      CModeTags[0].ti_Data=PScr;
  111.      ModeID=CModeRequestTagList(0L,CModeTags);
  112.  
  113.      Width = giodata->Width; Height = giodata->Height;
  114.  
  115.      if(Scr=(struct Screen *)OpenScreenTags(0L,SA_DisplayID,ModeID,
  116.                            SA_ShowTitle,0,
  117.                            SA_Title,0,
  118.                            SA_Quiet,1,
  119.                            SA_AutoScroll,1,
  120.                            SA_Overscan,1,
  121.                            SA_Depth,8,
  122.                            TAG_DONE))
  123.      {
  124.       struct Window *Wnd;
  125.       ShowTitle(Scr,0L); // We don't want a title bar !
  126.       ScrWidth=Scr->Width; ScrHeight=Scr->Height;
  127.       if(Wnd=(struct Window *)OpenWindowTags(0L,WA_Activate,1,
  128.                             WA_CustomScreen,Scr,
  129.                             WA_Width,Scr->Width,
  130.                             WA_Height,Scr->Height,
  131.                             WA_Borderless,1,
  132.                             WA_Backdrop,1,
  133.                             WA_Title,0,
  134.                             WA_Flags,WFLG_RMBTRAP,
  135.                             WA_IDCMP,IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS,
  136.                             TAG_DONE))
  137.       {
  138.        struct IntuiMessage *imsg;
  139.        BOOL end=FALSE,UpdateDis=TRUE;
  140.  
  141.  
  142.         DispWidth=ScrWidth; if(Width < ScrWidth) DispWidth = Width;
  143.        DispHeight=ScrHeight; if(Height < ScrHeight) DispHeight = Height;
  144.  
  145.        while(!end)
  146.        {
  147.         if(UpdateDis)
  148.         {
  149.         WriteRect(giodata,OffX,OffY,Width,Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop,DispWidth,DispHeight);
  150.          };
  151.         UpdateDis=FALSE;
  152.  
  153.        WaitPort(Wnd->UserPort);
  154.  
  155.        while(imsg=(struct IntuiMessage *)GetMsg(Wnd->UserPort))
  156.        {
  157.         ULONG IClass=imsg->Class;
  158.         UWORD IQual=imsg->Qualifier;
  159.         UWORD ICode=imsg->Code;
  160.         UWORD StepX,StepY;
  161.      
  162.         switch(IClass)
  163.         {
  164.          case MOUSEBUTTONS:    switch(ICode)
  165.                 {
  166.                  case    IECODE_LBUTTON:
  167.                     end=TRUE;
  168.                     break;
  169.                 }
  170.                 break;
  171.          case RAWKEY:
  172.         if(IQual & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  173.                 {
  174.                  StepX=StepY=1;
  175.                 }
  176.                 else
  177.                 {
  178.                  StepX=50;
  179.                  StepY=50;
  180.                 };
  181.  
  182.                 switch(ICode)
  183.                 {
  184.                  case CURSORUP: // CSUP
  185.                     if(OffY!=0)
  186.                     {
  187.                      OffY-=StepY;
  188.                      if(OffY < 0)
  189.                      {
  190.                       StepY+=OffY;
  191.                       OffY=0;
  192.                      }
  193.                      if(StepY != 0)
  194.                      {
  195.                       MovePixelArray(0,0,&Scr->RastPort,0,StepY,DispWidth,DispHeight-StepY);
  196.                       WriteRect(giodata,OffX,OffY,Width,&Scr->RastPort,Wnd->BorderLeft,Wnd->BorderTop,DispWidth,StepY);
  197.                      }
  198.                     };
  199.                     break;
  200.                  case CURSORDOWN: // CSDN
  201.                     if(Height > DispHeight)
  202.                     {
  203.                     OffY+=StepY;
  204.                     if(OffY > Height-DispHeight)
  205.                     {
  206.                      StepY-=(OffY - (Height - DispHeight));
  207.                      OffY=Height-DispHeight;
  208.                      if(OffY < 0) OffY=0;
  209.                     };
  210.                      if(StepY != 0)
  211.                      {
  212.                       MovePixelArray(0,StepY,&Scr->RastPort,0,0,DispWidth,DispHeight-StepY);
  213.                       WriteRect(giodata,OffX,OffY+DispHeight-StepY,Width,Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop+DispHeight-StepY,DispWidth,StepY);
  214.                      }
  215.                     };
  216.                     break;
  217.                  case CURSORRIGHT: // CSRT
  218.                     if(Width > DispWidth)
  219.                     {
  220.                     OffX+=StepX;
  221.                     if(OffX > Width-DispWidth)
  222.                     {
  223.                      StepX-=(OffX - (Width - DispWidth));
  224.                      OffX=Width-DispWidth;
  225.                      if(OffX < 0) OffX=0;
  226.                     };
  227.                      if(StepX != 0)
  228.                      {
  229.                       MovePixelArray(StepX,0,&Scr->RastPort,0,0,DispWidth-StepX,DispHeight);
  230.                       WriteRect(giodata,OffX+DispWidth-StepX,OffY,Width,Wnd->RPort,Wnd->BorderLeft+DispWidth-StepX,Wnd->BorderTop,StepX,DispHeight);
  231.                      }
  232.                     };
  233.                     break;
  234.                  case CURSORLEFT: // CSLT
  235.                     if(OffX!=0)
  236.                     {
  237.                      OffX-=StepX;
  238.                      if(OffX < 0)
  239.                      {
  240.                       StepX+=OffX;
  241.                       OffX=0;
  242.                      }
  243.                      if(StepX != 0)
  244.                      {
  245.                       MovePixelArray(0,0,&Scr->RastPort,StepX,0,DispWidth-StepX,DispHeight);
  246.                       WriteRect(giodata,OffX,OffY,Width,Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop,StepX,DispHeight);
  247.                      }
  248.                     };
  249.                     break;
  250.                 }
  251.                 break;
  252.       } // end of switch
  253.      } // end of while 
  254.         } // end of while(!end)
  255.        CloseWindow(Wnd);
  256.        } // end of OpenWindow
  257.        else giodata->Error = LOAD_RAMERR;
  258.        CloseScreen(Scr);
  259.       } // end of OpenScreen
  260.       else giodata->Error = LOAD_RAMERR;
  261.  
  262.     }
  263.     else
  264.     {
  265.       struct Window *Wnd;
  266.       int WndWidth,WndHeight;
  267.       ScrWidth=PScr->Width; ScrHeight=PScr->Height;
  268.       WndWidth=ScrWidth; WndHeight=ScrHeight;
  269.      Width = giodata->Width; Height = giodata->Height;
  270.       if(Width < ScrWidth) WndWidth=Width;
  271.       if(Height < ScrWidth) WndHeight=Height;
  272.  
  273.       if(Wnd=(struct Window *)OpenWindowTags(0L,WA_Activate,1,
  274.                             WA_CustomScreen,PScr,
  275.                             WA_Width,WndWidth,
  276.                             WA_Height,WndHeight,
  277.                             WA_SmartRefresh,1,
  278.                             WA_DepthGadget,1,
  279.                             WA_SizeGadget,1,
  280.                             WA_DragBar,1,
  281.                             WA_CloseGadget,1,
  282.                             WA_MaxWidth,Width,WA_MaxHeight,Height,
  283.                             WA_MinWidth,200,WA_MinHeight,40,
  284.                             WA_Title,"CyberGraphics Render Window",
  285.                             WA_Flags,WFLG_ACTIVATE,
  286.                             WA_IDCMP,IDCMP_RAWKEY|IDCMP_CLOSEWINDOW|IDCMP_NEWSIZE,
  287.                             TAG_DONE))
  288.       {
  289.        struct IntuiMessage *imsg;
  290.        BOOL end=FALSE,UpdateDis=TRUE;
  291.         rp=Wnd->RPort;
  292.  
  293.        WndWidth=Wnd->Width-Wnd->BorderLeft-Wnd->BorderRight;
  294.        WndHeight=Wnd->Height-Wnd->BorderTop-Wnd->BorderBottom;
  295.         DispWidth=WndWidth; if(Width < WndWidth) DispWidth = Width;
  296.        DispHeight=WndHeight; if(Height < WndHeight) DispHeight = Height;
  297.  
  298.        while(!end)
  299.        {
  300.         if(UpdateDis)
  301.         {
  302.         WriteRect(giodata,OffX,OffY,Width,Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop,DispWidth,DispHeight);
  303.          };
  304.         UpdateDis=FALSE;
  305.  
  306.        WaitPort(Wnd->UserPort);
  307.  
  308.        while(imsg=(struct IntuiMessage *)GetMsg(Wnd->UserPort))
  309.        {
  310.         ULONG IClass=imsg->Class;
  311.         UWORD IQual=imsg->Qualifier;
  312.         UWORD ICode=imsg->Code;
  313.         UWORD StepX,StepY;
  314.      
  315.         switch(IClass)
  316.         {
  317.          case IDCMP_CLOSEWINDOW:    end=TRUE;
  318.                     break;
  319.          case IDCMP_NEWSIZE:
  320.  
  321.        WndWidth=Wnd->Width-Wnd->BorderLeft-Wnd->BorderRight;
  322.        WndHeight=Wnd->Height-Wnd->BorderTop-Wnd->BorderBottom;
  323.         DispWidth=WndWidth; if(Width < WndWidth) DispWidth = Width;
  324.        DispHeight=WndHeight; if(Height < WndHeight) DispHeight = Height;
  325.  
  326.                     WriteRect(giodata,OffX,OffY,Width,Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop,DispWidth,DispHeight);
  327.                     break;
  328.          case IDCMP_RAWKEY:
  329.         if(IQual & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  330.                 {
  331.                  StepX=StepY=1;
  332.                 }
  333.                 else
  334.                 {
  335.                  StepX=50;
  336.                  StepY=50;
  337.                 };
  338.  
  339.                 switch(ICode)
  340.                 {
  341.                  case CURSORUP: // CSUP
  342.                     if(OffY!=0)
  343.                     {
  344.                      OffY-=StepY;
  345.                      if(OffY < 0)
  346.                      {
  347.                       StepY+=OffY;
  348.                       OffY=0;
  349.                      }
  350.                      if(StepY != 0)
  351.                      {
  352. //                      MovePixelArray(0,0,&Scr->RastPort,0,StepY,DispWidth,DispHeight-StepY);
  353.                       WriteRect(giodata,OffX,OffY,Width,Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop,DispWidth,StepY);
  354.                      }
  355.                     };
  356.                     break;
  357.                  case CURSORDOWN: // CSDN
  358.                     if(Height > DispHeight)
  359.                     {
  360.                     OffY+=StepY;
  361.                     if(OffY > Height-DispHeight)
  362.                     {
  363.                      StepY-=(OffY - (Height - DispHeight));
  364.                      OffY=Height-DispHeight;
  365.                      if(OffY < 0) OffY=0;
  366.                     };
  367.                      if(StepY != 0)
  368.                      {
  369. //                      MovePixelArray(0,StepY,&Scr->RastPort,0,0,DispWidth,DispHeight-StepY);
  370.                       WriteRect(giodata,OffX,OffY+DispHeight-StepY,Width,Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop+DispHeight-StepY,DispWidth,StepY);
  371.                      }
  372.                     };
  373.                     break;
  374.                  case CURSORRIGHT: // CSRT
  375.                     if(Width > DispWidth)
  376.                     {
  377.                     OffX+=StepX;
  378.                     if(OffX > Width-DispWidth)
  379.                     {
  380.                      StepX-=(OffX - (Width - DispWidth));
  381.                      OffX=Width-DispWidth;
  382.                      if(OffX < 0) OffX=0;
  383.                     };
  384.                      if(StepX != 0)
  385.                      {
  386. //                      MovePixelArray(StepX,0,&Scr->RastPort,0,0,DispWidth-StepX,DispHeight);
  387.                       WriteRect(giodata,OffX+DispWidth-StepX,OffY,Width,Wnd->RPort,Wnd->BorderLeft+DispWidth-StepX,Wnd->BorderTop,StepX,DispHeight);
  388.                      }
  389.                     };
  390.                     break;
  391.                  case CURSORLEFT: // CSLT
  392.                     if(OffX!=0)
  393.                     {
  394.                      OffX-=StepX;
  395.                      if(OffX < 0)
  396.                      {
  397.                       StepX+=OffX;
  398.                       OffX=0;
  399.                      }
  400.                      if(StepX != 0)
  401.                      {
  402. //                      MovePixelArray(0,0,&Scr->RastPort,StepX,0,DispWidth-StepX,DispHeight);
  403.                       WriteRect(giodata,OffX,OffY,Width,Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop,StepX,DispHeight);
  404.                      }
  405.                     };
  406.                     break;
  407.                 }
  408.                 break;
  409.       } // end of switch
  410.      } // end of while 
  411.         } // end of while(!end)
  412.        CloseWindow(Wnd);
  413.        } // end of OpenWindow
  414.        else giodata->Error = LOAD_RAMERR;
  415.  
  416.     }
  417.  
  418.       CloseLibrary(CyberGfxBase);
  419.      }
  420.      else giodata->Error = LOAD_SYSERR;
  421.     }
  422.     else
  423.     {
  424.      giodata->Error = LOAD_WRONGTYPE;
  425.     }
  426.  return(0L);
  427. }
  428.  
  429.     
  430.