home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pLayer / ScreenBF.c < prev   
Encoding:
C/C++ Source or Header  |  1997-03-18  |  6.3 KB  |  219 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 22 Oct 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>ScreenBF.c<<   29 Jan 1997    13:32:25 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/ScreenBF p:pLib/StartCode.o p:/pOS_RKRM/pLayer/ScreenBF.c p:pLib/StdIO.o -l pOSStub -l pOS
  10.  
  11. /***********************************************************
  12.   pOS programing example - Copyright (C) 1995-97 proDAD
  13.  
  14.   This code was written as an easy to understand example,
  15.   how to program pOS features. It is provided 'as-is',
  16.   without any express or implied warranty.
  17.  
  18.   Permission is hereby granted to use, copy and modify
  19.   this source code for any purpose, without fee, subject
  20.   to the following conditions:
  21.  
  22.     (1) This notice may not be removed or altered from any
  23.         source distribution.
  24.  
  25.     (2) Altered source versions must be plainly marked as
  26.         such, and must not be misrepresented as being
  27.         the original source code.
  28.  
  29.     (3) If only executable code is distributed, then the
  30.         accompanying documentation have to state that
  31.         "this software is based in part on examples of
  32.         the pOS developer packet".
  33.  
  34.     (4) Permission for use of this code is granted only
  35.         if the user accepts full responsibility for any
  36.         undesirable consequences. proDAD accept NO LIABILITY
  37.         for damages of any kind.
  38.  
  39.   ©proDAD
  40. ***********************************************************/
  41.  
  42. /*\
  43. *** Example:
  44. ***
  45. \*/
  46.  
  47.  
  48. #define __COMPUTER_AMIGA 1
  49.  
  50. #include "p:pExec/Types.h"
  51. #include "p:pExec/Callback.h"
  52. #include "p:pDOS/ArgTags.h"
  53. #include "p:pDOS/DosSig.h"
  54. #include "p:pDOS/DosErrors.h"
  55. #include "p:pGFX/GfxMap.h"
  56. #include "p:pGFX/GfxTags.h"
  57. #include "p:pGFX/RastPort.h"
  58. #include "p:pGadget/Gadget.h"
  59. #include "p:pScreen/ScrTags.h"
  60. #include "p:pScreen/Screen.h"
  61. #include "p:pDtType/DtTags.h"
  62. #include "p:pDtType/Picture.h"
  63. #include "p:proto/pLibExt.h"
  64. #include "p:proto/pExec2.h"
  65. #include "p:proto/pDOS2.h"
  66. #include "p:proto/pIntui2.h"
  67. #include "p:proto/pLayer2.h"
  68. #include "p:proto/pGFX2.h"
  69. #include "p:proto/pDtType2.h"
  70.  
  71.  
  72. #ifdef _____ME_____
  73.   #include "grund/inc_string.h"
  74.   #include "grund/inc_stdio.h"
  75. #else
  76.  #ifdef __cplusplus
  77.  extern "C" {
  78.  #endif
  79.   #include <string.h>
  80.   #include <stdio.h>
  81.  #ifdef __cplusplus
  82.  }
  83.  #endif
  84. #endif
  85.  
  86. #ifndef MIN
  87.  #define MIN(a,b) ( (a) > (b) ? (b) : (a) )
  88. #endif
  89.  
  90.  
  91.  
  92. const CHAR *HelpText=
  93. ""
  94. ;
  95.  
  96. const CHAR *PrgHeader=
  97. "";
  98.  
  99. const CHAR *PrgVerText=
  100. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  101.  
  102.  
  103. struct pOS_IntuiDevice *gb_IntuiBase;
  104. struct pOS_LayerBase   *gb_LayerBase;
  105. struct pOS_GfxBase     *gb_GfxBase;
  106. struct pOS_DataTypeBase *gb_DtTypeBase;
  107.  
  108.  
  109. /*----------------------------------
  110. -----------------------------------*/
  111. BOOL CallBack_func(_R_A0 const struct pOS_Callback* cb,
  112.                    _R_A1 struct pOS_LayerHookData* data)
  113. {
  114.   const struct pOS_GfxMap *const PMap=(struct pOS_GfxMap*)cb->cb_UserData[0];
  115.   const struct pOS_Screen *const Scr=(struct pOS_Screen*)cb->cb_UserData[1];
  116.   struct pOS_GfxMap *const GM=data->lyhd_LayerInfo->li_GfxMap;
  117.   struct pOS_GfxLibrary *const Lib=GM->gm_Base;
  118.  
  119.   SLONG SX=data->lyhd_Bounds.MinX-data->lyhd_OriginX;
  120.   SLONG SY=data->lyhd_Bounds.MinY-data->lyhd_OriginY;
  121.   ULONG Width,Height,X,Y,PX,PY;
  122.  
  123.   if(SY>=Scr->scr_BarHeight)
  124.        SY-=Scr->scr_BarHeight;
  125.   else SY =PMap->gm_Height-Scr->scr_BarHeight;
  126.  
  127.   SX %= PMap->gm_Width;
  128.   SY %= PMap->gm_Height;
  129.  
  130.   for(PY=SY, Y=data->lyhd_Bounds.MinY; Y<=data->lyhd_Bounds.MaxY; Y+=Height) {
  131.     Height=MIN( data->lyhd_Bounds.MaxY-Y+1, PMap->gm_Height-PY);
  132.     if(Height>0) {
  133.  
  134.       for(PX=SX, X=data->lyhd_Bounds.MinX; X<=data->lyhd_Bounds.MaxX; X+=Width) {
  135.         Width=MIN( data->lyhd_Bounds.MaxX-X+1, PMap->gm_Width-PX);
  136.         if(Width>0) {
  137.           pOS_BltGfxMap(PMap,PX,PY,GM,X,Y,Width,Height,BLTMINT_Copy);
  138.         }
  139.         PX=0;
  140.       }
  141.     }
  142.     PY=0;
  143.   }
  144.   return(TRUE); // *** keinen weiteren CB aufrufen
  145. }
  146.  
  147.  
  148. /*----------------------------------
  149. -----------------------------------*/
  150. #ifdef __cplusplus
  151. extern "C"
  152. #endif
  153.  
  154. VOID main()
  155. {
  156.   struct pOS_DosArgs* Args;
  157.   UWORD Err=0;
  158.   ULONG Ops[1]={0};
  159.  
  160.   gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  161.   gb_LayerBase=(struct pOS_LayerBase*)pOS_OpenLibrary("pLayer.library",0);
  162.   gb_GfxBase=(struct pOS_GfxBase*)pOS_OpenLibrary("pGraphics.library",0);
  163.   gb_DtTypeBase=(struct pOS_DataTypeBase*)pOS_OpenLibrary("pDtType.library",0);
  164.  
  165.   Args=pOS_ReadDosArgs(
  166. // 0
  167. "FILE/A",
  168. Ops,sizeof(Ops)/sizeof(ULONG),
  169.  
  170.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  171.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  172.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  173.     TAG_END);
  174.  
  175.   if(Args) {
  176.     struct pOS_Screen* Scr;
  177.  
  178.     if(Scr=pOS_LockPubScreen("Workbench")) {
  179.       struct pOS_Callback  CB;
  180.       struct pOS_DataType *DT;
  181.       struct pOS_GfxMap   *BgFillMap=NULL;
  182.  
  183.       DT=pOS_CreateFHDTObject(NULL,(dosname_t*)Ops[0],pOS_DTFORM_PICTURE,NULL,
  184.            DCLTAG_Remap,            TRUE,                     // remap erlauben
  185.            PICTURETAG_GfxMapPtr,    (ULONG)&BgFillMap,        // result
  186.            PICTURETAG_RemapMode,    0,                        // Mode => friend
  187.            PICTURETAG_FriendGfxMap, (ULONG)Scr->scr_RastPort->rp_GfxMap,
  188.            TAG_END);
  189.       if(DT) pOS_DeleteDTObject(DT);
  190.       else pOS_PrintDosErr(NULL,(CHAR*)Ops[0],0);
  191.  
  192.       if(BgFillMap) {
  193.         ww_InitNode(&CB.cb_Node); // only in debug-mode
  194.         CB.cb_Code=( ULONG(*)(_R_A0 const pOS_Callback*,_R_A1 APTR) ) CallBack_func;
  195.         CB.cb_UserData[0]=(ULONG)BgFillMap;
  196.         CB.cb_UserData[1]=(ULONG)Scr;
  197.  
  198.         pOS_AddLayerInfoHook(Scr->scr_LayerInfo,&CB,TRUE);
  199.         printf("Installed ... (Abort CTRL-C) ");
  200.         pOS_WaitSignal(DOSSIGF_CTRL_C);
  201.         pOS_RemLayerInfoHook(Scr->scr_LayerInfo,&CB,TRUE);
  202.         printf("... removed\n");
  203.         pOS_FreeGfxMap(BgFillMap);
  204.       }
  205.       pOS_UnlockPubScreen(Scr);
  206.     }
  207.     else printf("Cannot lock PubScreen\n");
  208.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  209.   }
  210.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  211.  
  212.   pOS_SetShellFail(Err);
  213.  
  214.   pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
  215.   pOS_CloseLibrary((struct pOS_Library*)gb_LayerBase);
  216.   pOS_CloseLibrary((struct pOS_Library*)gb_GfxBase);
  217.   pOS_CloseLibrary((struct pOS_Library*)gb_DtTypeBase);
  218. }
  219.