home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pIntui / Win4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  9.3 KB  |  340 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 18 Feb 1997 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>Win4.c<<   18 Feb 1997    09:34:49 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/Win4 p:pLib/StartCode.o p:/pOS_RKRM/pIntui/Win4.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/GfxTags.h"
  57. #include "p:pGFX/StdGMap.h"
  58. #include "p:pScreen/ScrTags.h"
  59. #include "p:pScreen/Window.h"
  60. #include "p:pScreen/Screen.h"
  61. #include "p:pIntui/GClass.h"
  62. #include "p:pIntui/IntuMsg.h"
  63. #include "p:pIntui/Tags.h"
  64. #include "p:proto/pLibExt.h"
  65. #include "p:proto/pExec2.h"
  66. #include "p:proto/pDOS2.h"
  67. #include "p:proto/pIntui2.h"
  68. #include "p:proto/pGfx2.h"
  69.  
  70. #ifdef _____ME_____
  71.   #include "grund/inc_string.h"
  72.   #include "grund/inc_stdio.h"
  73. #else
  74.  #ifdef __cplusplus
  75.  extern "C" {
  76.  #endif
  77.   #include <string.h>
  78.   #include <stdio.h>
  79.  #ifdef __cplusplus
  80.  }
  81.  #endif
  82. #endif
  83.  
  84.  
  85. const CHAR *HelpText=
  86. ""
  87. ;
  88.  
  89. const CHAR *PrgHeader=
  90. "";
  91.  
  92. const CHAR *PrgVerText=
  93. "$VER: 1.0 ("__DATE2__") (Copyright 1997 by proDAD) (Created by Holger Burkarth)";
  94.  
  95.  
  96. struct pOS_IntuiDevice *gb_IntuiBase;
  97. struct pOS_GfxBase *gb_GfxBase;
  98.  
  99.  
  100. /*\
  101. *** Größe der GfxMap in Pixeln.
  102. \*/
  103. #define _GFX_WIDTH  128
  104. #define _GFX_HEIGHT 96
  105.  
  106.  
  107.  
  108. VOID DrawGfx(struct pOS_StdRGB8GfxMap *gfxMap,ULONG idx);
  109.  
  110.  
  111.  
  112. /*----------------------------------
  113. -----------------------------------*/
  114. #ifdef __cplusplus
  115. extern "C"
  116. #endif
  117.  
  118. VOID main()
  119. {
  120.   struct pOS_DosArgs* Args;
  121.   UWORD Err=0;
  122.   ULONG Ops[1]={0};
  123.  
  124. /*\
  125. *** Benötigte Libs öffnen
  126. \*/
  127.   gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  128.   gb_GfxBase=(struct pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
  129.  
  130.  
  131.   Args=pOS_ReadDosArgs(
  132. //
  133. "",
  134. Ops,sizeof(Ops)/sizeof(ULONG),
  135.  
  136.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  137.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  138.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  139.     TAG_END);
  140.  
  141.   if(Args) {
  142.     struct pOS_Screen *Scr;
  143.     struct pOS_Window *Win;
  144.     struct pOS_Gadget *Gad,*GfxGad,*HGad,*But1Gad,*But2Gad;
  145.     struct pOS_GfxMap *GfxMap=NULL;
  146.  
  147. /*\
  148. *** Std-GfxMap erzeugen, in die direkt geschrieben werden kann.
  149. *** GFXMAPTYP_StdRGB8 => struct pOS_StdRGB8GfxMap
  150. \*/
  151.     GfxMap=pOS_AllocGfxMap(NULL,
  152.         GFXTAG_Width,       _GFX_WIDTH,
  153.         GFXTAG_Height,      _GFX_HEIGHT,
  154.         GFXTAG_GfxType,     GFXMAPTYP_StdRGB8,
  155.         GFXTAG_GfxFlags,    GFXMAPF_Clear,
  156.         TAG_END);
  157.  
  158.  
  159.     if(GfxMap) {
  160.       if(Scr=pOS_LockPubScreen(NULL)) {
  161.         const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
  162.  
  163. /*\
  164. *** Ein Gadget erzeugen, das als Render ein igfx-Objekt enthält. Das Gadget
  165. *** löscht am Ende den Render autom. Dem igfx-Objekt wird unsere GfxMap
  166. *** übergeben, die nicht autom. gelöscht wird. Der System-Layouter
  167. *** ist in der Lage, aus GfxMap-Maße das Gadget-Layout zu berechnen.
  168. \*/
  169.         GfxGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,"gadget.class",0,
  170.           ICLTAG_NoSelect, TRUE,
  171.           ICLTAG_Render,   (ULONG)pOS_NewIObject(NULL,"igfx.class",0,
  172.                                      ICLTAG_DrawInfo,   (ULONG)Dri,
  173.                                      IOGFXTAG_GfxMap,   (ULONG)GfxMap,
  174.                                      TAG_END),
  175.           TAG_END);
  176.  
  177.  
  178. /*\
  179. *** Zwei Button-Gadget erzeugen, die auch mit ShortKeys arbeiten.
  180. \*/
  181.         But1Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GButtonClass],0,
  182.           ICLTAG_DrawInfo,      (ULONG)Dri,
  183.           IOBJTAG_StaticString, (ULONG)"_Start",
  184.           ICLTAG_ShortKey,      (ULONG)'S',
  185.           ICLTAG_RelVerify,     TRUE,
  186.           IOBJTAG_Underscore,    '_',
  187.           TAG_DONE);
  188.  
  189.         But2Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GButtonClass],0,
  190.           ICLTAG_DrawInfo,      (ULONG)Dri,
  191.           IOBJTAG_StaticString, (ULONG)"Sto_pp",
  192.           ICLTAG_ShortKey,      (ULONG)'P',
  193.           ICLTAG_RelVerify,     TRUE,
  194.           IOBJTAG_Underscore,    '_',
  195.           TAG_DONE);
  196.  
  197.  
  198. /*\
  199. *** Damit die Buttons horizontal positioniert werden, muß eine horizontale Gruppe
  200. *** als Layout verwendet werden.
  201. \*/
  202.         HGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
  203.           GRPGADTAG_SpaceHoriz,  4,
  204.           GRPGADTAG_Horiz,       TRUE,
  205.           GRPGADTAG_AddGadget,   (ULONG)But1Gad,
  206.           GRPGADTAG_AddGadget,   (ULONG)But2Gad,
  207.           TAG_END);
  208.  
  209.  
  210. /*\
  211. *** Gesamte Gadget-Gruppe bilden.
  212. \*/
  213.         Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
  214.           ICLTAG_AutoDelete,    TRUE,
  215.           GRPGADTAG_BorLeft,    8,
  216.           GRPGADTAG_BorTop,     8,
  217.           GRPGADTAG_BorRight,   8,
  218.           GRPGADTAG_BorBottom,  8,
  219.           GRPGADTAG_SpaceVert,  8,
  220.           GRPGADTAG_AddGadget,  (ULONG)GfxGad,
  221.           GRPGADTAG_AddGadget,  (ULONG)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GBarClass],0,ICLTAG_DrawInfo, (ULONG)Dri,TAG_DONE),
  222.           GRPGADTAG_AddGadget,  (ULONG)HGad,
  223.           ICLTAG_Gwk,           1,
  224.           TAG_DONE);
  225.  
  226.         Win=pOS_OpenWindow(
  227.             SCRTAG_Title,   (ULONG)"Window-4",
  228.             SCRTAG_Screen,  (ULONG)Scr,
  229.             SCRTAG_Flags,   WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  230.                             WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar,
  231.             SCRTAG_IDCMP,   IDCMP_CloseWindow | IDCMP_StdSysMsg,
  232.             SCRTAG_AutoSizeGadget, (ULONG)Gad,
  233.             SCRTAG_UnderMouse,     TRUE,
  234.             TAG_DONE);
  235.  
  236.         if(Win) {
  237.           struct pOS_IntuiMessage *Msg;
  238.           ULONG Counter=0;
  239.           BOOL Ende=FALSE,Run=TRUE;
  240.  
  241.           while(!Ende) {
  242.             ULONG Sig;
  243.  
  244.             Sig=pOS_WaitSignal( (1<<Win->win_UserPort->mp_SigBit) | DOSSIGF_CTRL_C);
  245.             if(Sig & DOSSIGF_CTRL_C) Ende=TRUE;
  246.  
  247.             while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  248.               switch(Msg->im_Class) {
  249.  
  250.                 case IDCMP_GadgetUp:
  251.                   if(Msg->im_IAddress==(APTR)But1Gad) {
  252.                     printf("Gadget 'But1Gad'\n"); Run=TRUE;
  253.                   }
  254.                   else if(Msg->im_IAddress==(APTR)But2Gad) {
  255.                     printf("Gadget 'But2Gad'\n"); Run=FALSE;
  256.                   }
  257.                   break;
  258.  
  259.                 case IDCMP_IntuiTicks:
  260.                   if(Run) {
  261.                     DrawGfx((struct pOS_StdRGB8GfxMap*)GfxMap,Counter);
  262.                     Counter+=5;
  263.  
  264. /*\
  265. *** Mittels dem Gadget-Refresh wird unsere GfxMap neu gezeichnet.
  266. \*/
  267.                     pOS_RefreshGadgetsMd(Win,GfxGad,1,GCLMTHRE_Update);
  268.                   }
  269.                   break;
  270.  
  271.                 case IDCMP_CloseWindow:  Ende=TRUE; break;
  272.  
  273. /*\
  274. *** Nachrichtenauswertung ans System weiterreichen. (Refresh)
  275. \*/
  276.                 default: if(pOS_SysIMessage(Msg)) Msg=NULL;
  277.               }
  278.  
  279.               if(Msg) pOS_ReplyMsg(&Msg->im_Message);
  280.             }
  281.           }
  282.           pOS_CloseWindow(Win);
  283.         }
  284.         else printf("Cannot open window\n");
  285.         pOS_UnlockPubScreen(Scr);
  286.       }
  287.       else printf("Cannot lock PubScreen\n");
  288.  
  289. /*\
  290. *** GfxMap freigeben.
  291. \*/
  292.       pOS_FreeGfxMap(GfxMap);
  293.     }
  294.     else printf("Cannot create GfxMap\n");
  295.  
  296.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  297.   }
  298.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  299.  
  300.   pOS_SetShellFail(Err);
  301.  
  302. /*\
  303. *** Libs wieder schließen
  304. \*/
  305.   pOS_CloseLibrary((struct pOS_Library*)gb_GfxBase);
  306.   pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
  307. }
  308.  
  309.  
  310.  
  311. /*----------------------------------
  312.  
  313.   GfxMap irgendwie beschreiben. ;-)
  314.  
  315. -----------------------------------*/
  316. VOID DrawGfx(struct pOS_StdRGB8GfxMap *gfxMap,ULONG idx)
  317. {
  318.   ULONG h;
  319.   UBYTE *R,*G,*B;
  320.   ULONG M=(idx>>8)*3;
  321.   idx &= 0xff;
  322.  
  323.   R=gfxMap->rgbgm_R;
  324.   G=gfxMap->rgbgm_G;
  325.   B=gfxMap->rgbgm_B;
  326.  
  327.   for(h=gfxMap->rgbgm_Gfx.gm_Height; h>0; --h) {
  328.     memset(R,idx,gfxMap->rgbgm_Gfx.gm_Width);
  329.     memset(G,M,gfxMap->rgbgm_Gfx.gm_Width);
  330.     memset(B,128-idx+M,gfxMap->rgbgm_Gfx.gm_Width);
  331.  
  332.     idx=(idx+3) & 0xff;
  333.     R+=gfxMap->rgbgm_Gfx.gm_Width;
  334.     G+=gfxMap->rgbgm_Gfx.gm_Width;
  335.     B+=gfxMap->rgbgm_Gfx.gm_Width;
  336.   }
  337. }
  338.  
  339.  
  340.