home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pGraphics / StdGfx1.c
Encoding:
C/C++ Source or Header  |  1997-03-18  |  11.4 KB  |  385 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 13 Oct 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>StdGfx1.c<<   29 Jan 1997    13:28:53 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/StdGfx1 p:pLib/StartCode.o p:/pOS_RKRM/pGraphics/StdGfx1.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:pGadget/Gadget.h"
  56. #include "p:pGfx/StdGMap.h"
  57. #include "p:pGfx/StdCMap.h"
  58. #include "p:pGfx/GfxTags.h"
  59. #include "p:pGFX/RastPort.h"
  60. #include "p:pScreen/ScrTags.h"
  61. #include "p:pScreen/Window.h"
  62. #include "p:pScreen/Screen.h"
  63. #include "p:pIntui/IntuMsg.h"
  64. #include "p:pIntui/Tags.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.  
  71. #ifdef _____ME_____
  72.   #include "grund/inc_string.h"
  73.   #include "grund/inc_stdio.h"
  74. #else
  75.  #ifdef __cplusplus
  76.  extern "C" {
  77.  #endif
  78.   #include <string.h>
  79.   #include <stdio.h>
  80.  #ifdef __cplusplus
  81.  }
  82.  #endif
  83. #endif
  84.  
  85.  
  86. const CHAR *HelpText=
  87. ""
  88. ;
  89.  
  90. const CHAR *PrgHeader=
  91. "";
  92.  
  93. const CHAR *PrgVerText=
  94. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  95.  
  96.  
  97.  
  98. VOID DrawA(pOS_RastPort*,const pOS_IBox*);
  99. VOID DrawB(pOS_RastPort*,const pOS_IBox*);
  100. VOID DrawC(pOS_RastPort*,const pOS_IBox*);
  101. VOID DrawD(pOS_RastPort*,const pOS_IBox*);
  102. VOID DrawE(pOS_RastPort*,const pOS_IBox*);
  103.  
  104.  
  105.  
  106.  
  107. struct pOS_IntuiDevice *gb_IntuiBase;
  108. struct pOS_GfxBase *gb_GfxBase;
  109.  
  110. /*----------------------------------
  111. -----------------------------------*/
  112. #ifdef __cplusplus
  113. extern "C"
  114. #endif
  115.  
  116. VOID main()
  117. {
  118.   struct pOS_DosArgs* Args;
  119.   UWORD Err=0; //
  120.   ULONG Ops[1]={0};
  121.  
  122.   gb_IntuiBase=(pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  123.   gb_GfxBase=(pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
  124.  
  125.   Args=pOS_ReadDosArgs(
  126. //  0
  127. "NUM/N",
  128. Ops,sizeof(Ops)/sizeof(ULONG),
  129.  
  130.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  131.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  132.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  133.     TAG_END);
  134.  
  135.  
  136.   if(Args) {
  137.     static const CHAR *WinNames[]={
  138.       "(struct pOS_StdRGB8GfxMap*) - Test",
  139.       "(struct pOS_StdChunky8GfxMap*) - Test",
  140.       "(struct pOS_StdChunky8GfxMap*)+(struct pOS_StdRLColorMap*) - Test",
  141.       "(struct pOS_StdChunky8GfxMap*)+(struct pOS_StdRLColorMap*)  + TempMap - Test",
  142.       "(struct pOS_StdRGB8GfxMap*) + TempMap - Test",
  143.     };
  144.     ULONG Num=Ops[0] ? *((ULONG*)Ops[0]) : 0;
  145.     struct pOS_Window *Win;
  146.  
  147.     if(Num>4) Num=4;
  148.  
  149.     Win=pOS_OpenWindow(
  150.         SCRTAG_Title,    (ULONG)WinNames[Num],
  151.         SCRTAG_PubName,  (ULONG)"Workbench",
  152.         SCRTAG_Flags,    WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  153.                          WINFLGF_SizeGadget | WINFLGF_Activate |
  154.                          WINFLGF_CloseGadget | WINFLGF_Dragbar |
  155.                          WINFLGF_SizeBBottom,
  156.         SCRTAG_IDCMP,    IDCMP_CloseWindow   | IDCMP_StdSysMsg |
  157.                          IDCMP_RefreshWindow | IDCMP_NewSize,
  158.         SCRTAG_ZipGadget,TRUE,
  159.         TAG_DONE);
  160.     if(Win) {
  161.       struct pOS_IntuiMessage *Msg;
  162.       struct pOS_IBox Box;
  163.       BOOL Ende=FALSE;
  164.  
  165.       pOS_GetWindowIBox(Win,&Box,NULL);
  166.  
  167.       while(!Ende) {
  168.         if(DOSSIGF_CTRL_C & pOS_WaitSignal((1<<Win->win_UserPort->mp_SigBit) | DOSSIGF_CTRL_C)) break;
  169.  
  170.         while(Msg=(pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  171.  
  172.           switch(Msg->im_Class) {
  173.  
  174.             case IDCMP_RefreshWindow:
  175.               if(pOS_BeginRefresh(Win,NULL)) {
  176.                 switch(Num) {
  177.                   case 0: DrawA(Win->win_RastPort,&Box); break;
  178.                   case 1: DrawB(Win->win_RastPort,&Box); break;
  179.                   case 2: DrawC(Win->win_RastPort,&Box); break;
  180.                   case 3: DrawD(Win->win_RastPort,&Box); break;
  181.                   case 4: DrawE(Win->win_RastPort,&Box); break;
  182.                 }
  183.                 pOS_EndRefresh(Win,TRUE);
  184.               }
  185.               break;
  186.  
  187.             case IDCMP_NewSize:
  188.               pOS_GetWindowIBox(Win,&Box,NULL);
  189.               break;
  190.  
  191.             case IDCMP_CloseWindow:  Ende=TRUE; break;
  192.  
  193.             default:
  194.               if(pOS_SysIMessage(Msg)) Msg=NULL;
  195.           }
  196.           if(Msg) pOS_ReplyMsg(&Msg->im_Message);
  197.         }
  198.       }
  199.       pOS_CloseWindow(Win);
  200.     }
  201.     else printf("Cannot open window\n");
  202.  
  203.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  204.   }
  205.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  206.  
  207.   pOS_SetShellFail(Err);
  208.  
  209.   pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
  210.   pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
  211. }
  212.  
  213.  
  214. VOID DrawA(pOS_RastPort* rp,const pOS_IBox *box)
  215. {
  216.   pOS_StdRGB8GfxMap *GfxMap;
  217.  
  218.   GfxMap=(pOS_StdRGB8GfxMap*)pOS_AllocGfxMap(NULL,
  219.            GFXTAG_Width,    box->Width,
  220.            GFXTAG_Height,   box->Height,
  221.            GFXTAG_GfxType,  GFXMAPTYP_StdRGB8,
  222.            TAG_END);
  223.   if(GfxMap) {
  224.     ULONG x;
  225.     for(x=0; x<box->Width; ++x) GfxMap->rgbgm_R[x]=x;
  226.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->rgbgm_R[x*box->Width],GfxMap->rgbgm_R,box->Width);
  227.  
  228.     for(x=0; x<box->Width; ++x) GfxMap->rgbgm_G[x]=255-x*2;
  229.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->rgbgm_G[x*box->Width],GfxMap->rgbgm_G,box->Width);
  230.  
  231.     for(x=0; x<box->Width; ++x) GfxMap->rgbgm_B[x]=x*4;
  232.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->rgbgm_B[x*box->Width],GfxMap->rgbgm_B,box->Width);
  233.  
  234.     pOS_WriteStdGfxMapRastPort(&GfxMap->rgbgm_Gfx,0,0,
  235.                   rp,box->Left,box->Top,box->Width,box->Height,0);
  236.     pOS_FreeGfxMap(&GfxMap->rgbgm_Gfx);
  237.   }
  238. }
  239.  
  240.  
  241. VOID DrawB(pOS_RastPort* rp,const pOS_IBox *box)
  242. {
  243.   pOS_StdChunky8GfxMap *GfxMap;
  244.  
  245.   GfxMap=(pOS_StdChunky8GfxMap*)pOS_AllocGfxMap(NULL,
  246.            GFXTAG_Width,    box->Width,
  247.            GFXTAG_Height,   box->Height,
  248.            GFXTAG_GfxType,  GFXMAPTYP_StdChunky8,
  249.            TAG_END);
  250.   if(GfxMap) {
  251.     ULONG x;
  252.     for(x=0; x<box->Width; ++x) GfxMap->ckgm_Chunky[x]=x/4;
  253.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->ckgm_Chunky[x*box->Width],GfxMap->ckgm_Chunky,box->Width);
  254.  
  255.     pOS_WriteStdGfxMapRastPort(&GfxMap->ckgm_Gfx,0,0,
  256.                   rp,box->Left,box->Top,box->Width,box->Height,0);
  257.     pOS_FreeGfxMap(&GfxMap->ckgm_Gfx);
  258.   }
  259. }
  260.  
  261.  
  262. VOID DrawC(pOS_RastPort* rp,const pOS_IBox *box)
  263. {
  264.   pOS_StdChunky8GfxMap *GfxMap;
  265.   pOS_StdRLColorMap    *ColorMap;
  266.  
  267.   ColorMap=(pOS_StdRLColorMap*)pOS_AllocColorMap(NULL,
  268.            GFXTAG_ColorType,   COLMAPTYP_StdRLut,
  269.            GFXTAG_Colors,      256,
  270.            TAG_END);
  271.  
  272.   GfxMap=(pOS_StdChunky8GfxMap*)pOS_AllocGfxMap(NULL,
  273.            GFXTAG_Width,       box->Width,
  274.            GFXTAG_Height,      box->Height,
  275.            GFXTAG_GfxType,     GFXMAPTYP_StdChunky8,
  276.            GFXTAG_CrtGfxMapEx, TRUE,
  277.            GFXTAG_ColorMap,    (ULONG)ColorMap,
  278.            TAG_END);
  279.  
  280.  
  281.   if(GfxMap && ColorMap) {
  282.     ULONG x;
  283.  
  284.     for(x=0; x<256; ++x) {
  285.       ColorMap->rlcm_Colors[x].rc_U.rc_E.rcue_R=x;
  286.       ColorMap->rlcm_Colors[x].rc_U.rc_E.rcue_G=x;
  287.       ColorMap->rlcm_Colors[x].rc_U.rc_E.rcue_B=x;
  288.     }
  289.  
  290.     for(x=0; x<box->Width; ++x) GfxMap->ckgm_Chunky[x]=x/2;
  291.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->ckgm_Chunky[x*box->Width],GfxMap->ckgm_Chunky,box->Width);
  292.  
  293.     pOS_WriteStdGfxMapRastPort(&GfxMap->ckgm_Gfx,0,0,
  294.                   rp,box->Left,box->Top,box->Width,box->Height,0);
  295.   }
  296.   if(GfxMap)   pOS_FreeGfxMap(&GfxMap->ckgm_Gfx);
  297.   if(ColorMap) pOS_FreeColorMap(&ColorMap->rlcm_CM);
  298. }
  299.  
  300.  
  301.  
  302. VOID DrawD(pOS_RastPort* rp,const pOS_IBox *box)
  303. {
  304.   pOS_StdChunky8GfxMap *GfxMap;
  305.   pOS_GfxMap *TempMap;
  306.   pOS_StdRLColorMap    *ColorMap;
  307.  
  308.   ColorMap=(pOS_StdRLColorMap*)pOS_AllocColorMap(NULL,
  309.            GFXTAG_ColorType,   COLMAPTYP_StdRLut,
  310.            GFXTAG_Colors,      256,
  311.            TAG_END);
  312.  
  313.   GfxMap=(pOS_StdChunky8GfxMap*)pOS_AllocGfxMap(NULL,
  314.            GFXTAG_Width,       box->Width,
  315.            GFXTAG_Height,      box->Height,
  316.            GFXTAG_GfxType,     GFXMAPTYP_StdChunky8,
  317.            GFXTAG_CrtGfxMapEx, TRUE,
  318.            GFXTAG_ColorMap,    (ULONG)ColorMap,
  319.            TAG_END);
  320.  
  321.   TempMap=pOS_AllocGfxMap(rp->rp_Base,
  322.            GFXTAG_Width,       box->Width,
  323.            GFXTAG_Height,      box->Height,
  324.            GFXTAG_CrtGfxMapEx, TRUE,
  325.            GFXTAG_FriendGfxMap,rp->rp_GfxMap,
  326.            TAG_DONE);
  327.  
  328.   if(ColorMap && GfxMap && TempMap) {
  329.     ULONG x;
  330.  
  331.     for(x=0; x<256; ++x) {
  332.       ColorMap->rlcm_Colors[x].rc_U.rc_E.rcue_R=x;
  333.       ColorMap->rlcm_Colors[x].rc_U.rc_E.rcue_G=x;
  334.       ColorMap->rlcm_Colors[x].rc_U.rc_E.rcue_B=x;
  335.     }
  336.  
  337.     for(x=0; x<box->Width; ++x) GfxMap->ckgm_Chunky[x]=x/2;
  338.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->ckgm_Chunky[x*box->Width],GfxMap->ckgm_Chunky,box->Width);
  339.  
  340.     pOS_WriteStdGfxMap(&GfxMap->ckgm_Gfx,0,0,TempMap,0,0,box->Width,box->Height,0,NULL);
  341.     pOS_BltGfxMapRastPort(TempMap,0,0,rp,box->Left,box->Top,box->Width,box->Height,BLTMINT_Copy);
  342.   }
  343.   if(GfxMap)  pOS_FreeGfxMap(&GfxMap->ckgm_Gfx);
  344.   if(TempMap) pOS_FreeGfxMap(TempMap);
  345.   if(ColorMap) pOS_FreeColorMap(&ColorMap->rlcm_CM);
  346. }
  347.  
  348.  
  349. VOID DrawE(pOS_RastPort* rp,const pOS_IBox *box)
  350. {
  351.   pOS_StdRGB8GfxMap *GfxMap;
  352.   pOS_GfxMap *TempMap;
  353.  
  354.   GfxMap=(pOS_StdRGB8GfxMap*)pOS_AllocGfxMap(NULL,
  355.            GFXTAG_Width,    box->Width,
  356.            GFXTAG_Height,   box->Height,
  357.            GFXTAG_GfxType,  GFXMAPTYP_StdRGB8,
  358.            TAG_END);
  359.  
  360.   TempMap=pOS_AllocGfxMap(rp->rp_Base,
  361.            GFXTAG_Width,       box->Width,
  362.            GFXTAG_Height,      box->Height,
  363.            GFXTAG_CrtGfxMapEx, TRUE,
  364.            GFXTAG_FriendGfxMap,rp->rp_GfxMap,
  365.            TAG_DONE);
  366.  
  367.   if(GfxMap && TempMap) {
  368.     ULONG x;
  369.     for(x=0; x<box->Width; ++x) GfxMap->rgbgm_R[x]=x;
  370.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->rgbgm_R[x*box->Width],GfxMap->rgbgm_R,box->Width);
  371.  
  372.     for(x=0; x<box->Width; ++x) GfxMap->rgbgm_G[x]=255-x*2;
  373.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->rgbgm_G[x*box->Width],GfxMap->rgbgm_G,box->Width);
  374.  
  375.     for(x=0; x<box->Width; ++x) GfxMap->rgbgm_B[x]=x*4;
  376.     for(x=1; x<box->Height; ++x) memcpy(&GfxMap->rgbgm_B[x*box->Width],GfxMap->rgbgm_B,box->Width);
  377.  
  378.     pOS_WriteStdGfxMap(&GfxMap->rgbgm_Gfx,0,0,TempMap,0,0,box->Width,box->Height,0,NULL);
  379.     pOS_BltGfxMapRastPort(TempMap,0,0,rp,box->Left,box->Top,box->Width,box->Height,BLTMINT_Copy);
  380.   }
  381.   if(GfxMap)  pOS_FreeGfxMap(&GfxMap->rgbgm_Gfx);
  382.   if(TempMap) pOS_FreeGfxMap(TempMap);
  383. }
  384.  
  385.