home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 18 Feb 1997 : hb
-
- $AUT Holger Burkarth
- $DAT >>Win4.c<< 18 Feb 1997 09:34:49 - (C) ProDAD
- *******************************************************************/
-
- //##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
-
- /***********************************************************
- 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
- ***********************************************************/
-
- /*\
- *** Example:
- ***
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:pGadget/Gadget.h"
- #include "p:pGFX/GfxTags.h"
- #include "p:pGFX/StdGMap.h"
- #include "p:pScreen/ScrTags.h"
- #include "p:pScreen/Window.h"
- #include "p:pScreen/Screen.h"
- #include "p:pIntui/GClass.h"
- #include "p:pIntui/IntuMsg.h"
- #include "p:pIntui/Tags.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
- #include "p:proto/pIntui2.h"
- #include "p:proto/pGfx2.h"
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1997 by proDAD) (Created by Holger Burkarth)";
-
-
- struct pOS_IntuiDevice *gb_IntuiBase;
- struct pOS_GfxBase *gb_GfxBase;
-
-
- /*\
- *** Größe der GfxMap in Pixeln.
- \*/
- #define _GFX_WIDTH 128
- #define _GFX_HEIGHT 96
-
-
-
- VOID DrawGfx(struct pOS_StdRGB8GfxMap *gfxMap,ULONG idx);
-
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[1]={0};
-
- /*\
- *** Benötigte Libs öffnen
- \*/
- gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
- gb_GfxBase=(struct pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
-
-
- Args=pOS_ReadDosArgs(
- //
- "",
- Ops,sizeof(Ops)/sizeof(ULONG),
-
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- TAG_END);
-
- if(Args) {
- struct pOS_Screen *Scr;
- struct pOS_Window *Win;
- struct pOS_Gadget *Gad,*GfxGad,*HGad,*But1Gad,*But2Gad;
- struct pOS_GfxMap *GfxMap=NULL;
-
- /*\
- *** Std-GfxMap erzeugen, in die direkt geschrieben werden kann.
- *** GFXMAPTYP_StdRGB8 => struct pOS_StdRGB8GfxMap
- \*/
- GfxMap=pOS_AllocGfxMap(NULL,
- GFXTAG_Width, _GFX_WIDTH,
- GFXTAG_Height, _GFX_HEIGHT,
- GFXTAG_GfxType, GFXMAPTYP_StdRGB8,
- GFXTAG_GfxFlags, GFXMAPF_Clear,
- TAG_END);
-
-
- if(GfxMap) {
- if(Scr=pOS_LockPubScreen(NULL)) {
- const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
-
- /*\
- *** Ein Gadget erzeugen, das als Render ein igfx-Objekt enthält. Das Gadget
- *** löscht am Ende den Render autom. Dem igfx-Objekt wird unsere GfxMap
- *** übergeben, die nicht autom. gelöscht wird. Der System-Layouter
- *** ist in der Lage, aus GfxMap-Maße das Gadget-Layout zu berechnen.
- \*/
- GfxGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,"gadget.class",0,
- ICLTAG_NoSelect, TRUE,
- ICLTAG_Render, (ULONG)pOS_NewIObject(NULL,"igfx.class",0,
- ICLTAG_DrawInfo, (ULONG)Dri,
- IOGFXTAG_GfxMap, (ULONG)GfxMap,
- TAG_END),
- TAG_END);
-
-
- /*\
- *** Zwei Button-Gadget erzeugen, die auch mit ShortKeys arbeiten.
- \*/
- But1Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GButtonClass],0,
- ICLTAG_DrawInfo, (ULONG)Dri,
- IOBJTAG_StaticString, (ULONG)"_Start",
- ICLTAG_ShortKey, (ULONG)'S',
- ICLTAG_RelVerify, TRUE,
- IOBJTAG_Underscore, '_',
- TAG_DONE);
-
- But2Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GButtonClass],0,
- ICLTAG_DrawInfo, (ULONG)Dri,
- IOBJTAG_StaticString, (ULONG)"Sto_pp",
- ICLTAG_ShortKey, (ULONG)'P',
- ICLTAG_RelVerify, TRUE,
- IOBJTAG_Underscore, '_',
- TAG_DONE);
-
-
- /*\
- *** Damit die Buttons horizontal positioniert werden, muß eine horizontale Gruppe
- *** als Layout verwendet werden.
- \*/
- HGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
- GRPGADTAG_SpaceHoriz, 4,
- GRPGADTAG_Horiz, TRUE,
- GRPGADTAG_AddGadget, (ULONG)But1Gad,
- GRPGADTAG_AddGadget, (ULONG)But2Gad,
- TAG_END);
-
-
- /*\
- *** Gesamte Gadget-Gruppe bilden.
- \*/
- Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
- ICLTAG_AutoDelete, TRUE,
- GRPGADTAG_BorLeft, 8,
- GRPGADTAG_BorTop, 8,
- GRPGADTAG_BorRight, 8,
- GRPGADTAG_BorBottom, 8,
- GRPGADTAG_SpaceVert, 8,
- GRPGADTAG_AddGadget, (ULONG)GfxGad,
- GRPGADTAG_AddGadget, (ULONG)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GBarClass],0,ICLTAG_DrawInfo, (ULONG)Dri,TAG_DONE),
- GRPGADTAG_AddGadget, (ULONG)HGad,
- ICLTAG_Gwk, 1,
- TAG_DONE);
-
- Win=pOS_OpenWindow(
- SCRTAG_Title, (ULONG)"Window-4",
- SCRTAG_Screen, (ULONG)Scr,
- SCRTAG_Flags, WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
- WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar,
- SCRTAG_IDCMP, IDCMP_CloseWindow | IDCMP_StdSysMsg,
- SCRTAG_AutoSizeGadget, (ULONG)Gad,
- SCRTAG_UnderMouse, TRUE,
- TAG_DONE);
-
- if(Win) {
- struct pOS_IntuiMessage *Msg;
- ULONG Counter=0;
- BOOL Ende=FALSE,Run=TRUE;
-
- while(!Ende) {
- ULONG Sig;
-
- Sig=pOS_WaitSignal( (1<<Win->win_UserPort->mp_SigBit) | DOSSIGF_CTRL_C);
- if(Sig & DOSSIGF_CTRL_C) Ende=TRUE;
-
- while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
- switch(Msg->im_Class) {
-
- case IDCMP_GadgetUp:
- if(Msg->im_IAddress==(APTR)But1Gad) {
- printf("Gadget 'But1Gad'\n"); Run=TRUE;
- }
- else if(Msg->im_IAddress==(APTR)But2Gad) {
- printf("Gadget 'But2Gad'\n"); Run=FALSE;
- }
- break;
-
- case IDCMP_IntuiTicks:
- if(Run) {
- DrawGfx((struct pOS_StdRGB8GfxMap*)GfxMap,Counter);
- Counter+=5;
-
- /*\
- *** Mittels dem Gadget-Refresh wird unsere GfxMap neu gezeichnet.
- \*/
- pOS_RefreshGadgetsMd(Win,GfxGad,1,GCLMTHRE_Update);
- }
- break;
-
- case IDCMP_CloseWindow: Ende=TRUE; break;
-
- /*\
- *** Nachrichtenauswertung ans System weiterreichen. (Refresh)
- \*/
- default: if(pOS_SysIMessage(Msg)) Msg=NULL;
- }
-
- if(Msg) pOS_ReplyMsg(&Msg->im_Message);
- }
- }
- pOS_CloseWindow(Win);
- }
- else printf("Cannot open window\n");
- pOS_UnlockPubScreen(Scr);
- }
- else printf("Cannot lock PubScreen\n");
-
- /*\
- *** GfxMap freigeben.
- \*/
- pOS_FreeGfxMap(GfxMap);
- }
- else printf("Cannot create GfxMap\n");
-
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else Err=DOSFAIL_FAIL; /* vollkommen fehlgeschlagen */
-
- pOS_SetShellFail(Err);
-
- /*\
- *** Libs wieder schließen
- \*/
- pOS_CloseLibrary((struct pOS_Library*)gb_GfxBase);
- pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
- }
-
-
-
- /*----------------------------------
-
- GfxMap irgendwie beschreiben. ;-)
-
- -----------------------------------*/
- VOID DrawGfx(struct pOS_StdRGB8GfxMap *gfxMap,ULONG idx)
- {
- ULONG h;
- UBYTE *R,*G,*B;
- ULONG M=(idx>>8)*3;
- idx &= 0xff;
-
- R=gfxMap->rgbgm_R;
- G=gfxMap->rgbgm_G;
- B=gfxMap->rgbgm_B;
-
- for(h=gfxMap->rgbgm_Gfx.gm_Height; h>0; --h) {
- memset(R,idx,gfxMap->rgbgm_Gfx.gm_Width);
- memset(G,M,gfxMap->rgbgm_Gfx.gm_Width);
- memset(B,128-idx+M,gfxMap->rgbgm_Gfx.gm_Width);
-
- idx=(idx+3) & 0xff;
- R+=gfxMap->rgbgm_Gfx.gm_Width;
- G+=gfxMap->rgbgm_Gfx.gm_Width;
- B+=gfxMap->rgbgm_Gfx.gm_Width;
- }
- }
-
-
-