home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 29 Nov 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>AmigaGad.c<< 29 Nov 1996 12:06:09 - (C) ProDAD
- *******************************************************************/
-
- //##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
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Library.h"
- #include "p:pExec/Resident.h"
- #include "p:pExec/Class.h"
- #include "p:pExec/Task.h"
- #include "p:pExec/Diagnos.h"
- #include "p:pExec/TstTags.h"
- #include "p:pDOS/Segment.h"
- #include "p:pDOS/DosTags.h"
- #include "p:pGadget/Gadget.h"
- #include "p:pScreen/DrawInfo.h"
- #include "p:pGfx/StdGMap.h"
- #include "p:pGfx/RastPort.h"
- #include "p:pIntui/GClass.h"
- #include "p:pIntui/Tags.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pIntui2.h"
- #include "p:proto/pList.h"
- #include "p:proto/pUtil2.h"
- #include "p:proto/pGfx2.h"
- #include "p:proto/pGadget2.h"
-
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_limits.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <limits.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- struct pOS_ExecBase* gb_ExecBase;
- struct pOS_ExecLibFunction* gb_ExecLib;
- struct pOS_UtilityBase *gb_UtilityBase;
- struct pOS_GadgetBase *gb_GadgetBase;
- struct pOS_GfxBase *gb_GfxBase;
-
-
- struct AmigaGadLib
- {
- pOS_Library amg_Lib;
- pOS_NClass *amg_CGadClass;
- };
-
-
- extern ULONG *FuncTable[];
- const CHAR LibraryName[] ="amigagad.library";
- const CHAR LibraryIDName[]="amigagad.library 1.0 ("__DATE2__")";
-
- const pOS_TagItem LibraryDescribe[]=
- {
- EXTSTTAG_MainOSID, pOS_MAINOSID,
- TAG_END
- };
-
-
- BOOL pLibMain(_R_LB pOS_ExecBase*,_R_A0 AmigaGadLib*);
-
- pOS_ResidentLibInit InitTable=
- {
- sizeof(AmigaGadLib),
- FuncTable,
- NULL,
- (BOOL(*)(_R_LB pOS_ExecBase*,_R_A0 pOS_Library*))pLibMain
- };
-
-
- /*----------------------------------
- Wird in dieser Library nicht benötigt.
- -----------------------------------*/
- BOOL Open_func(_R_LB AmigaGadLib*) { return(1); }
- VOID Close_func(_R_LB AmigaGadLib*) {}
- ULONG Reserved_func(_R_LB AmigaGadLib*) { return(0); }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- pOS_SegmentLst* Expunge_func(_R_LB AmigaGadLib* lib)
- {
- if(lib->amg_Lib.lib_OpenCnt==0) { /* alle Verwender aben pOS_CloseLibrary() aufgerufen */
- pOS_SegmentLst* Seg=lib->amg_Lib.lib_Segm;
-
- pOS_ListRemove(&lib->amg_Lib.lib_Node);
-
- if(lib->amg_CGadClass) pOS_DeleteClass(lib->amg_CGadClass);
-
- _pOS_FreeLibraryMem2(&lib->amg_Lib); /* Lib-Memory freigeben */
-
- pOS_CloseLibrary((pOS_Library*)gb_GadgetBase);
- pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
- pOS_CloseLibrary((pOS_Library*)gb_UtilityBase);
- return(Seg);
- }
- return(0);
- }
-
-
- ULONG *FuncTable[]=
- {
- (ULONG*)Open_func,
- (ULONG*)Close_func,
- (ULONG*)Expunge_func,
- // ------------
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- (ULONG*)Reserved_func,
- // ------------
-
- (ULONG*)ULONG_MAX
- };
-
-
-
- /*******************************************************************************/
-
- #define GFLG_GADGHIGHBITS 0x0003
- #define GFLG_GADGHCOMP 0x0000 /* Complement the select box */
- #define GFLG_GADGHBOX 0x0001 /* Draw a box around the image */
- #define GFLG_GADGHIMAGE 0x0002 /* Blast in this alternate image */
- #define GFLG_GADGHNONE 0x0003 /* don't highlight */
-
- #define GFLG_GADGIMAGE 0x0004 /* set if GadgetRender and SelectRender
- * point to an Image structure, clear
- * if they point to Border structures
- */
-
-
- struct Image
- {
- SWORD LeftEdge;
- SWORD TopEdge;
- UWORD Width;
- UWORD Height;
- UWORD Depth;
- UWORD *ImageData;
- UBYTE PlanePick, PlaneOnOff;
- struct Image *NextImage;
- };
-
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID pOSp_AmigaGadDraw(pOS_RastPort* rp,APTR obj,SLONG ox,SLONG oy,UWORD type)
- {
- switch(type) {
-
- case 1: // struct Image
- {
- struct Image *im=(struct Image*)obj;
- pOS_StdPlanarGfxMap GM;
- ULONG Size,Offset;
- UWORD d;
-
- memset(&GM,0,sizeof(GM)); // *** Zur Sicherheit
- GM.plgm_Gfx.gm_Type = GFXMAPTYP_StdPlanar;
-
- for(; im; im=im->NextImage) {
- GM.plgm_Gfx.gm_Width =im->Width;
- GM.plgm_Gfx.gm_Height=im->Height;
- GM.plgm_BytesPerRow=((im->Width+15)>>4)<<1;
- GM.plgm_Depth=im->Depth;
- Offset=0;
- Size=GM.plgm_BytesPerRow*GM.plgm_Gfx.gm_Height/sizeof(UWORD);
- for(d=0; d<im->Depth; ++d, Offset+=Size) {
- GM.plgm_Planes[d]=(UBYTE*) &im->ImageData[Offset];
- }
- pOS_WriteStdGfxMapRastPort(&GM.plgm_Gfx,0,0,
- (struct pOS_RastPort*)rp,ox+im->LeftEdge,oy+im->TopEdge,
- GM.plgm_Gfx.gm_Width,GM.plgm_Gfx.gm_Height,
- 0);
- }
- }
- break;
- }
- }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID pOSp_DrawGadgetTypeBool(pOS_RastPort* RP,pOS_Gadget* Gad,
- const pOS_Rectangle *Rect)
- {
- UWORD Flg=Gad->gad_Flags & GFLG_GADGHIGHBITS;
- UWORD Type=(Gad->gad_Flags & GFLG_GADGIMAGE) ? 1:2;
-
- if(Gad->gad_Flags & GFLG_Selected) {
- if(Flg==GFLG_GADGHCOMP) {
- pOS_SetDrMd(RP,DRMD_Complement);
- pOS_DrawRectFill(RP,Rect->MinX,Rect->MinY,Rect->MaxX,Rect->MaxY);
- }
- else if(Flg==GFLG_GADGHIMAGE) {
- if(Gad->gad_Select)
- pOSp_AmigaGadDraw(RP,Gad->gad_Select,Rect->MinX,Rect->MinY,Type);
- }
- }
- else {
- if(Gad->gad_Render)
- pOSp_AmigaGadDraw(RP,Gad->gad_Render,Rect->MinX,Rect->MinY,Type);
- }
- }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- ULONG pOSp_AmigaGadDispatcher(_R_LB pOS_ExecBase* exec,_R_A0 const pOS_Class* cl,
- _R_A1 APTR obj,_R_A2 pOS_GadgetMethod* mth)
- {
- ULONG ret=0;
-
- switch(mth->imth_Method) {
-
- case GCLMTH_Render:
- {
- pOS_Gadget *const Gad=(pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
- pOS_RastPort *RP;
- pOS_Rectangle Rect;
- if(RP=pOS_ObtainGRastPort(Gad,mth->imth_U.imth_Render.imre_Info)) {
- pOS_CalcGadgetBox(mth->imth_U.imth_Render.imre_Info->ici_Window,Gad,&Rect);
-
- switch(Gad->gad_Type & GTYP_GTypeMask) {
-
- case GTYP_BoolGadget:
- pOSp_DrawGadgetTypeBool(RP,Gad,&Rect);
- break;
- }
- if( (Gad->gad_Flags & GFLG_Disabled)
- && !(Gad->gad_Flags & GFLG_PrivateDisable))
- {
- pOS_DrawDisableRect(RP,Rect.MinX,Rect.MinY,Rect.MaxX,Rect.MaxY);
- }
- pOS_ReleaseGRastPort(mth->imth_U.imth_Render.imre_Info,RP);
- }
- }
- break;
-
-
- // -----
- case ICLMTH_Dispose:
- {
- pOS_Gadget *const Gad=(pOS_Gadget*)pOS_GetObjectRootAdr(cl,obj);
- Gad->gad_Select=NULL; Gad->gad_Render=NULL; Gad->gad_Lable=NULL;
- ret=pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);
- }
- break;
-
-
- default: ret=pOS_DoAbsMethodA(cl,obj,(pOS_Method*)mth);
- }
-
- return(ret);
- }
-
-
- /*******************************************************************************/
-
-
- /*----------------------------------
- -----------------------------------*/
- BOOL pLibMain(_R_LB pOS_ExecBase* exec,_R_A0 AmigaGadLib* lib)
- {
- #ifdef __pOS_EXECPRECODE
- extern struct pOS_ExecBase* gb_ExecBase;
- extern struct pOS_ExecLibFunction* gb_ExecLib;
-
- gb_ExecBase=(struct pOS_ExecBase*)exec;
- gb_ExecLib=*((struct pOS_ExecLibFunction**)lib->amg_Lib.lib_Segm->sel_Seg.seg_Reserved2);
- gb_UtilityBase=(pOS_UtilityBase*)pOS_OpenLibrary("pUtility.library",0);
- gb_GadgetBase=(pOS_GadgetBase*)pOS_OpenLibrary("pGadget.library",0);
- gb_GfxBase=(pOS_GfxBase*)pOS_OpenLibrary("pGraphics.library",0);
- #else
- #error hier fehlt etwas
- #endif
-
- lib->amg_CGadClass=
- pOS_CreateClass("AmigaGad.class","gadget.class",NULL,
- (APTR)pOSp_AmigaGadDispatcher,0,0);
- return(lib->amg_CGadClass!=NULL);
- }
-
-
-