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

  1.  
  2. /*******************************************************************
  3.  $CRT 29 Nov 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>AmigaGad.c<<   29 Nov 1996    12:06:09 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/libs/AmigaGad.library p:pLib/LibCode.o p:/pOS_RKRM/pGadgets/AmigaGad.c -l pOSStub -l CPPList -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. #define __COMPUTER_AMIGA 1
  43. #define NOMYDEBUG
  44.  
  45. #include "p:pExec/Library.h"
  46. #include "p:pExec/Resident.h"
  47. #include "p:pExec/Class.h"
  48. #include "p:pExec/Task.h"
  49. #include "p:pExec/Diagnos.h"
  50. #include "p:pExec/TstTags.h"
  51. #include "p:pDOS/Segment.h"
  52. #include "p:pDOS/DosTags.h"
  53. #include "p:pGadget/Gadget.h"
  54. #include "p:pScreen/DrawInfo.h"
  55. #include "p:pGfx/StdGMap.h"
  56. #include "p:pGfx/RastPort.h"
  57. #include "p:pIntui/GClass.h"
  58. #include "p:pIntui/Tags.h"
  59. #include "p:proto/pLibExt.h"
  60. #include "p:proto/pExec2.h"
  61. #include "p:proto/pIntui2.h"
  62. #include "p:proto/pList.h"
  63. #include "p:proto/pUtil2.h"
  64. #include "p:proto/pGfx2.h"
  65. #include "p:proto/pGadget2.h"
  66.  
  67.  
  68. #ifdef _____ME_____
  69.   #include "grund/inc_string.h"
  70.   #include "grund/inc_limits.h"
  71.   #include "grund/inc_stdio.h"
  72. #else
  73.  #ifdef __cplusplus
  74.  extern "C" {
  75.  #endif
  76.   #include <string.h>
  77.   #include <limits.h>
  78.   #include <stdio.h>
  79.  #ifdef __cplusplus
  80.  }
  81.  #endif
  82. #endif
  83.  
  84.  
  85. struct pOS_ExecBase* gb_ExecBase;
  86. struct pOS_ExecLibFunction* gb_ExecLib;
  87. struct pOS_UtilityBase *gb_UtilityBase;
  88. struct pOS_GadgetBase *gb_GadgetBase;
  89. struct pOS_GfxBase *gb_GfxBase;
  90.  
  91.  
  92. struct AmigaGadLib
  93. {
  94.   pOS_Library  amg_Lib;
  95.   pOS_NClass  *amg_CGadClass;
  96. };
  97.  
  98.  
  99. extern ULONG *FuncTable[];
  100. const CHAR LibraryName[]  ="amigagad.library";
  101. const CHAR LibraryIDName[]="amigagad.library 1.0 ("__DATE2__")";
  102.  
  103. const pOS_TagItem LibraryDescribe[]=
  104. {
  105.   EXTSTTAG_MainOSID, pOS_MAINOSID,
  106.   TAG_END
  107. };
  108.  
  109.  
  110. BOOL pLibMain(_R_LB pOS_ExecBase*,_R_A0 AmigaGadLib*);
  111.  
  112. pOS_ResidentLibInit InitTable=
  113. {
  114.   sizeof(AmigaGadLib),
  115.   FuncTable,
  116.   NULL,
  117.   (BOOL(*)(_R_LB pOS_ExecBase*,_R_A0 pOS_Library*))pLibMain
  118. };
  119.  
  120.  
  121. /*----------------------------------
  122.  Wird in dieser Library nicht benötigt.
  123. -----------------------------------*/
  124. BOOL Open_func(_R_LB AmigaGadLib*)      { return(1); }
  125. VOID Close_func(_R_LB AmigaGadLib*)     {}
  126. ULONG Reserved_func(_R_LB AmigaGadLib*) { return(0); }
  127.  
  128.  
  129.  
  130. /*----------------------------------
  131. -----------------------------------*/
  132. pOS_SegmentLst* Expunge_func(_R_LB AmigaGadLib* lib)
  133. {
  134.   if(lib->amg_Lib.lib_OpenCnt==0) {          /* alle Verwender aben pOS_CloseLibrary() aufgerufen */
  135.     pOS_SegmentLst* Seg=lib->amg_Lib.lib_Segm;
  136.  
  137.     pOS_ListRemove(&lib->amg_Lib.lib_Node);
  138.  
  139.     if(lib->amg_CGadClass) pOS_DeleteClass(lib->amg_CGadClass);
  140.  
  141.     _pOS_FreeLibraryMem2(&lib->amg_Lib); /* Lib-Memory freigeben */
  142.  
  143.     pOS_CloseLibrary((pOS_Library*)gb_GadgetBase);
  144.     pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
  145.     pOS_CloseLibrary((pOS_Library*)gb_UtilityBase);
  146.     return(Seg);
  147.   }
  148.   return(0);
  149. }
  150.  
  151.  
  152. ULONG *FuncTable[]=
  153. {
  154.  (ULONG*)Open_func,
  155.  (ULONG*)Close_func,
  156.  (ULONG*)Expunge_func,
  157. // ------------
  158.  (ULONG*)Reserved_func,
  159.  (ULONG*)Reserved_func,
  160.  (ULONG*)Reserved_func,
  161.  (ULONG*)Reserved_func,
  162.  (ULONG*)Reserved_func,
  163.  (ULONG*)Reserved_func,
  164.  (ULONG*)Reserved_func,
  165.  (ULONG*)Reserved_func,
  166. // ------------
  167.  
  168.  (ULONG*)ULONG_MAX
  169. };
  170.  
  171.  
  172.  
  173. /*******************************************************************************/
  174.  
  175. #define GFLG_GADGHIGHBITS 0x0003
  176. #define GFLG_GADGHCOMP    0x0000  /* Complement the select box */
  177. #define GFLG_GADGHBOX     0x0001  /* Draw a box around the image */
  178. #define GFLG_GADGHIMAGE   0x0002  /* Blast in this alternate image */
  179. #define GFLG_GADGHNONE    0x0003  /* don't highlight */
  180.  
  181. #define GFLG_GADGIMAGE    0x0004  /* set if GadgetRender and SelectRender
  182.                                    * point to an Image structure, clear
  183.                                    * if they point to Border structures
  184.                                    */
  185.  
  186.  
  187. struct Image
  188. {
  189.   SWORD   LeftEdge;
  190.   SWORD   TopEdge;
  191.   UWORD   Width;
  192.   UWORD   Height;
  193.   UWORD   Depth;
  194.   UWORD  *ImageData;
  195.   UBYTE   PlanePick, PlaneOnOff;
  196.   struct Image *NextImage;
  197. };
  198.  
  199.  
  200.  
  201. /*----------------------------------
  202. -----------------------------------*/
  203. VOID pOSp_AmigaGadDraw(pOS_RastPort* rp,APTR obj,SLONG ox,SLONG oy,UWORD type)
  204. {
  205.   switch(type) {
  206.  
  207.     case 1:   // struct Image
  208.       {
  209.         struct Image *im=(struct Image*)obj;
  210.         pOS_StdPlanarGfxMap GM;
  211.         ULONG Size,Offset;
  212.         UWORD d;
  213.  
  214.         memset(&GM,0,sizeof(GM)); // *** Zur Sicherheit
  215.         GM.plgm_Gfx.gm_Type = GFXMAPTYP_StdPlanar;
  216.  
  217.         for(; im; im=im->NextImage) {
  218.           GM.plgm_Gfx.gm_Width =im->Width;
  219.           GM.plgm_Gfx.gm_Height=im->Height;
  220.           GM.plgm_BytesPerRow=((im->Width+15)>>4)<<1;
  221.           GM.plgm_Depth=im->Depth;
  222.           Offset=0;
  223.           Size=GM.plgm_BytesPerRow*GM.plgm_Gfx.gm_Height/sizeof(UWORD);
  224.           for(d=0; d<im->Depth; ++d, Offset+=Size) {
  225.             GM.plgm_Planes[d]=(UBYTE*) &im->ImageData[Offset];
  226.           }
  227.           pOS_WriteStdGfxMapRastPort(&GM.plgm_Gfx,0,0,
  228.              (struct pOS_RastPort*)rp,ox+im->LeftEdge,oy+im->TopEdge,
  229.              GM.plgm_Gfx.gm_Width,GM.plgm_Gfx.gm_Height,
  230.              0);
  231.         }
  232.       }
  233.       break;
  234.   }
  235. }
  236.  
  237.  
  238.  
  239. /*----------------------------------
  240. -----------------------------------*/
  241. VOID pOSp_DrawGadgetTypeBool(pOS_RastPort* RP,pOS_Gadget* Gad,
  242.                              const pOS_Rectangle *Rect)
  243. {
  244.   UWORD Flg=Gad->gad_Flags & GFLG_GADGHIGHBITS;
  245.   UWORD Type=(Gad->gad_Flags & GFLG_GADGIMAGE) ? 1:2;
  246.  
  247.   if(Gad->gad_Flags & GFLG_Selected) {
  248.     if(Flg==GFLG_GADGHCOMP) {
  249.       pOS_SetDrMd(RP,DRMD_Complement);
  250.       pOS_DrawRectFill(RP,Rect->MinX,Rect->MinY,Rect->MaxX,Rect->MaxY);
  251.     }
  252.     else if(Flg==GFLG_GADGHIMAGE) {
  253.       if(Gad->gad_Select)
  254.          pOSp_AmigaGadDraw(RP,Gad->gad_Select,Rect->MinX,Rect->MinY,Type);
  255.     }
  256.   }
  257.   else {
  258.     if(Gad->gad_Render)
  259.        pOSp_AmigaGadDraw(RP,Gad->gad_Render,Rect->MinX,Rect->MinY,Type);
  260.   }
  261. }
  262.  
  263.  
  264.  
  265. /*----------------------------------
  266. -----------------------------------*/
  267. ULONG pOSp_AmigaGadDispatcher(_R_LB pOS_ExecBase* exec,_R_A0 const pOS_Class* cl,
  268.                              _R_A1 APTR obj,_R_A2 pOS_GadgetMethod* mth)
  269. {
  270.   ULONG ret=0;
  271.  
  272.   switch(mth->imth_Method) {
  273.  
  274.     case GCLMTH_Render:
  275.       {
  276.         pOS_Gadget *const Gad=(pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
  277.         pOS_RastPort *RP;
  278.         pOS_Rectangle Rect;
  279.         if(RP=pOS_ObtainGRastPort(Gad,mth->imth_U.imth_Render.imre_Info)) {
  280.           pOS_CalcGadgetBox(mth->imth_U.imth_Render.imre_Info->ici_Window,Gad,&Rect);
  281.  
  282.           switch(Gad->gad_Type & GTYP_GTypeMask) {
  283.  
  284.             case GTYP_BoolGadget:
  285.               pOSp_DrawGadgetTypeBool(RP,Gad,&Rect);
  286.               break;
  287.           }
  288.           if(     (Gad->gad_Flags & GFLG_Disabled)
  289.               && !(Gad->gad_Flags & GFLG_PrivateDisable))
  290.           {
  291.             pOS_DrawDisableRect(RP,Rect.MinX,Rect.MinY,Rect.MaxX,Rect.MaxY);
  292.           }
  293.           pOS_ReleaseGRastPort(mth->imth_U.imth_Render.imre_Info,RP);
  294.         }
  295.       }
  296.       break;
  297.  
  298.  
  299. // -----
  300.     case ICLMTH_Dispose:
  301.       {
  302.         pOS_Gadget *const Gad=(pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
  303.         Gad->gad_Select=NULL; Gad->gad_Render=NULL; Gad->gad_Lable=NULL;
  304.         ret=pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);
  305.       }
  306.       break;
  307.  
  308.  
  309.     default: ret=pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);
  310.   }
  311.  
  312.   return(ret);
  313. }
  314.  
  315.  
  316. /*******************************************************************************/
  317.  
  318.  
  319. /*----------------------------------
  320. -----------------------------------*/
  321. BOOL pLibMain(_R_LB pOS_ExecBase* exec,_R_A0 AmigaGadLib* lib)
  322. {
  323. #ifdef __pOS_EXECPRECODE
  324.   extern struct pOS_ExecBase* gb_ExecBase;
  325.   extern struct pOS_ExecLibFunction* gb_ExecLib;
  326.  
  327.   gb_ExecBase=(struct pOS_ExecBase*)exec;
  328.   gb_ExecLib=*((struct pOS_ExecLibFunction**)lib->amg_Lib.lib_Segm->sel_Seg.seg_Reserved2);
  329.   gb_UtilityBase=(pOS_UtilityBase*)pOS_OpenLibrary("pUtility.library",0);
  330.   gb_GadgetBase=(pOS_GadgetBase*)pOS_OpenLibrary("pGadget.library",0);
  331.   gb_GfxBase=(pOS_GfxBase*)pOS_OpenLibrary("pGraphics.library",0);
  332. #else
  333.  #error hier fehlt etwas
  334. #endif
  335.  
  336.   lib->amg_CGadClass=
  337.      pOS_CreateClass("AmigaGad.class","gadget.class",NULL,
  338.                      (APTR)pOSp_AmigaGadDispatcher,0,0);
  339.   return(lib->amg_CGadClass!=NULL);
  340. }
  341.  
  342.  
  343.