home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pLayer / ClipWinReg.c next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  8.4 KB  |  309 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 30 Jan 1997 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>ClipWinReg.c<<   30 Jan 1997    13:50:00 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/ClipWinReg p:pLib/StartCode.o p:/pOS_RKRM/pLayer/ClipWinReg.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. #define NOMYDEBUG
  50.  
  51. #include "p:pExec/Types.h"
  52. #include "p:pDOS/ArgTags.h"
  53. #include "p:pDOS/DosSig.h"
  54. #include "p:pDOS/DosErrors.h"
  55. #include "p:pGFX/Text.h"
  56. #include "p:pGFX/Color.h"
  57. #include "p:pLayer/Region.h"
  58. #include "p:pLayer/Clip.h"
  59. #include "p:pScreen/ScrTags.h"
  60. #include "p:pScreen/Window.h"
  61. #include "p:pScreen/Screen.h"
  62. #include "p:pIntui/IntuMsg.h"
  63. #include "p:pIntui/Tags.h"
  64. #include "p:pIntui/WinFlags.h"
  65. #include "p:proto/pLibExt.h"
  66. #include "p:proto/pExec2.h"
  67. #include "p:proto/pDOS2.h"
  68. #include "p:proto/pIntui2.h"
  69. #include "p:proto/pGFX2.h"
  70. #include "p:proto/pLayer2.h"
  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.  
  87. const CHAR *HelpText=
  88. ""
  89. ;
  90.  
  91. const CHAR *PrgHeader=
  92. "";
  93.  
  94. const CHAR *PrgVerText=
  95. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  96.  
  97.  
  98. struct pOS_IntuiDevice *gb_IntuiBase;
  99. struct pOS_GfxBase     *gb_GfxBase;
  100. struct pOS_LayerBase   *gb_LayerBase;
  101.  
  102.  
  103. BOOL CalcRegion(struct pOS_Window *win,struct pOS_Region* reg);
  104. VOID DrawGfx(struct pOS_Window *win,ULONG pen);
  105.  
  106.  
  107.  
  108.  
  109. /*----------------------------------
  110. -----------------------------------*/
  111. #ifdef __cplusplus
  112. extern "C"
  113. #endif
  114.  
  115. VOID main()
  116. {
  117.   struct pOS_DosArgs* Args;
  118.   UWORD Err=0;
  119.   ULONG Ops[1]={0};
  120.  
  121.   gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  122.   gb_GfxBase=(struct pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
  123.   gb_LayerBase=(struct pOS_LayerBase*)pOS_OpenLibrary("pLayer.library",0);
  124.  
  125.   Args=pOS_ReadDosArgs(
  126. "REFRESH_MODE/N",
  127. Ops,sizeof(Ops)/sizeof(ULONG),
  128.  
  129.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  130.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  131.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  132.     TAG_END);
  133.  
  134.  
  135.   if(Args) {
  136.     struct pOS_Window   *Win;
  137.     struct pOS_Screen   *Scr;
  138.     struct pOS_Region   *Region;
  139.     struct pOS_ColorMap *ColorMap;
  140.     struct pOS_RColor   RC;
  141.     ULONG Ticks=0,Pen,ActIdx=0;
  142.     const ULONG RMode=Ops[0] ? *((ULONG*)Ops[0]) : 0;
  143.  
  144.     static const ULONG ColTab[][3]={
  145.       {0,    0,    0},
  146.       {255,    0,    0},
  147.       {0,    255,    0},
  148.       {0,    0,    255},
  149.     };
  150.  
  151.  
  152.  
  153.     RC.rc_U.rc_E.rcue_A=255;
  154.  
  155.     Region=pOS_CreateRegion();
  156.  
  157.     if(Region) {
  158.       if(Scr=pOS_LockPubScreen(NULL)) {
  159.         const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
  160.  
  161.         Win=pOS_OpenWindow(
  162.             SCRTAG_Screen,     (ULONG)Scr,
  163.             SCRTAG_Flags,      WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  164.                                WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar,
  165.             SCRTAG_IDCMP,      IDCMP_CloseWindow | IDCMP_RefreshWindow | IDCMP_IntuiTicks,
  166.             SCRTAG_Width,      256,
  167.             SCRTAG_Height,     256,
  168.             SCRTAG_UnderMouse, TRUE,
  169.             SCRTAG_AutoAdjust, TRUE,
  170.             TAG_DONE);
  171.  
  172.         if(Win) {
  173.           struct pOS_IntuiMessage *Msg;
  174.           BOOL Ende=FALSE;
  175.  
  176.           ColorMap=pOS_GetIColorMap(NULL,Win);
  177.           CalcRegion(Win,Region);
  178.  
  179.           RC.rc_U.rc_E.rcue_R=ColTab[ActIdx][0];
  180.           RC.rc_U.rc_E.rcue_G=ColTab[ActIdx][1];
  181.           RC.rc_U.rc_E.rcue_B=ColTab[ActIdx][2];
  182.  
  183.           Pen=pOS_ObtainColorPen(ColorMap,~0,&RC,
  184.                   OTCOLPF_Shared | OTCOLPF_Force | OTCOLPF_Flow | OTCOLPF_Display);
  185.  
  186.           while(!Ende) {
  187.             if(DOSSIGF_CTRL_C & pOS_WaitSignal((1<<Win->win_UserPort->mp_SigBit) | DOSSIGF_CTRL_C)) break;
  188.  
  189.             while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  190.  
  191.               switch(Msg->im_Class) {
  192.                 case IDCMP_CloseWindow:  Ende=TRUE; break;
  193.  
  194.                 case IDCMP_RefreshWindow:
  195.                   if(pOS_BeginRefresh(Win,&Region->rg_List)) {
  196.                     DrawGfx(Win,Pen);
  197.                     pOS_EndRefresh(Win,TRUE);
  198.                   }
  199.                   pOS_ReplyMsg(&Msg->im_Message);
  200.                   Msg=NULL;
  201.                   break;
  202.  
  203.  
  204.                 case IDCMP_IntuiTicks:
  205.                   if(++Ticks>=10) {
  206.                     Ticks=0;
  207.                     pOS_ReleaseColorPen(ColorMap,Pen);
  208.                     if(++ActIdx>=4) ActIdx=0;
  209.                     RC.rc_U.rc_E.rcue_R=ColTab[ActIdx][0];
  210.                     RC.rc_U.rc_E.rcue_G=ColTab[ActIdx][1];
  211.                     RC.rc_U.rc_E.rcue_B=ColTab[ActIdx][2];
  212.                     Pen=pOS_ObtainColorPen(ColorMap,~0,&RC,
  213.                        OTCOLPF_Shared | OTCOLPF_Force | OTCOLPF_Flow | OTCOLPF_Display);
  214.  
  215. /*\
  216. *** Das System kann jederzeit den Zeichenvorgang unterbrechen.
  217. \*/
  218.                     if(RMode==0) {
  219.                       struct pOS_Region *Reg;
  220.  
  221.                       Reg=pOS_InstallClipRegion(Win->win_Layer,Region);
  222.                       DrawGfx(Win,Pen);
  223.                       pOS_InstallClipRegion(Win->win_Layer,Reg);
  224.                     }
  225.  
  226. /*\
  227. *** Einfachste Variante. :-)
  228. \*/
  229.                     else if(RMode==1) {
  230.                       pOS_InvalidWindowRect(Win,NULL,INVALWINF_CreateMsg);
  231.                     }
  232.  
  233. /*\
  234. *** Schnellste Clipping-Variante, das System kann den Vorgang nicht unterbrechen.
  235. *** => darf nur kurze Zeit gelockt sein
  236. \*/
  237.                     else if(RMode==2) {
  238.                       pOS_LayerClip Clip;
  239.                       if(pOS_LockClipLayer(Win->win_Layer,&Clip,&Region->rg_List,0)) {
  240.                         DrawGfx(Win,Pen);
  241.                         pOS_UnlockClipLayer(Win->win_Layer,&Clip);
  242.                       }
  243.                     }
  244.                   }
  245.                   break;
  246.  
  247.               }
  248.  
  249.               if(Msg) { if(pOS_SysIMessage(Msg)) Msg=NULL; }
  250.               if(Msg) pOS_ReplyMsg(&Msg->im_Message);
  251.             }
  252.           }
  253.           pOS_CloseWindow(Win);
  254.           pOS_ReleaseColorPen(ColorMap,Pen);
  255.         }
  256.         else printf("Cannot open window\n");
  257.  
  258.         pOS_UnlockPubScreen(Scr);
  259.       }
  260.       else printf("Cannot lock PubScreen\n");
  261.       pOS_DeleteRegion(Region);
  262.     }
  263.     else printf("Cannot create Region\n");
  264.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  265.   }
  266.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  267.  
  268.   pOS_SetShellFail(Err);
  269.  
  270.   pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
  271.   pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
  272.   pOS_CloseLibrary((pOS_Library*)gb_LayerBase);
  273. }
  274.  
  275.  
  276.  
  277. /*----------------------------------
  278. -----------------------------------*/
  279. BOOL CalcRegion(struct pOS_Window *win,struct pOS_Region* reg)
  280. {
  281.   pOS_Rectangle Rect={30,30,win->win_Width-60,win->win_Height-60};
  282.  
  283.   pOS_ClearRegion(reg,®->rg_List); // *** erase all region datas
  284.  
  285.   return( pOS_OrRectRegion(reg,&Rect) );
  286. }
  287.  
  288. /*----------------------------------
  289. -----------------------------------*/
  290. VOID DrawGfx(struct pOS_Window *win,ULONG pen)
  291. {
  292.   struct pOS_RastPort *const RP=win->win_RastPort;
  293.   ULONG i;
  294.  
  295.   pOS_SetAPen(RP,pen);
  296.   for(i=0; i<win->win_Height; i+=5) {
  297.     pOS_SetPosition(RP,0,i);
  298.     pOS_DrawLine(RP,8192,i);
  299.   }
  300. }
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.