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

  1.  
  2. /*******************************************************************
  3.  $CRT 22 Oct 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>SuperWin.c<<   02 Mar 1997    11:04:51 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/SuperWin p:pLib/StartCode.o p:/pOS_RKRM/pIntui/SuperWin.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:pGadget/PropGad.h"
  57. #include "p:pLayer/Clip.h"
  58. #include "p:pScreen/ScrTags.h"
  59. #include "p:pScreen/Window.h"
  60. #include "p:pScreen/Screen.h"
  61. #include "p:pGFX/GfxTags.h"
  62. #include "p:pGFX/GfxMap.h"
  63. #include "p:pGFX/RastPort.h"
  64. #include "p:pIntui/IntuMsg.h"
  65. #include "p:pIntui/Tags.h"
  66. #include "p:pDtType/DtTags.h"
  67. #include "p:pDtType/Picture.h"
  68. #include "p:proto/pLibExt.h"
  69. #include "p:proto/pExec2.h"
  70. #include "p:proto/pDOS2.h"
  71. #include "p:proto/pIntui2.h"
  72. #include "p:proto/pGFX2.h"
  73. #include "p:proto/pDtType2.h"
  74. #include "p:proto/pLayer2.h"
  75.  
  76. #ifdef _____ME_____
  77.   #include "grund/inc_string.h"
  78.   #include "grund/inc_stdio.h"
  79. #else
  80.  #ifdef __cplusplus
  81.  extern "C" {
  82.  #endif
  83.   #include <string.h>
  84.   #include <stdio.h>
  85.  #ifdef __cplusplus
  86.  }
  87.  #endif
  88. #endif
  89.  
  90.  
  91. const CHAR *HelpText=
  92. ""
  93. ;
  94.  
  95. const CHAR *PrgHeader=
  96. "";
  97.  
  98. const CHAR *PrgVerText=
  99. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  100.  
  101.  
  102. struct pOS_IntuiDevice *gb_IntuiBase;
  103. struct pOS_GfxBase *gb_GfxBase;
  104. struct pOS_DataTypeBase *gb_DtTypeBase;
  105. struct pOS_LayerBase *gb_LayerBase;
  106.  
  107. VOID CalcSliders(pOS_Window*,pOS_Gadget*,pOS_Gadget*,UWORD width,UWORD height);
  108. VOID MoveSliders(pOS_Window*,pOS_Gadget*,pOS_Gadget*,UWORD width,UWORD height);
  109.  
  110.  
  111. /*----------------------------------
  112. -----------------------------------*/
  113. #ifdef __cplusplus
  114. extern "C"
  115. #endif
  116.  
  117. VOID main()
  118. {
  119.   pOS_DosArgs* Args;
  120.   UWORD Err=0;
  121.   ULONG Ops[1]={0};
  122.  
  123.   gb_IntuiBase=(pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  124.   gb_GfxBase=(pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
  125.   gb_DtTypeBase=(pOS_DataTypeBase*)pOS_OpenLibrary("pDtType.library",0);
  126.   gb_LayerBase=(pOS_LayerBase*)pOS_OpenLibrary("pLayer.library",0);
  127.  
  128.  
  129.   Args=pOS_ReadDosArgs(
  130. // 0
  131. "",
  132. Ops,sizeof(Ops)/sizeof(ULONG),
  133.  
  134.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  135.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  136.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  137.     TAG_END);
  138.  
  139.   if(Args) {
  140.     pOS_Window *Win;
  141.     pOS_Screen *Scr;
  142.     pOS_GfxMap *SuperMap;
  143.     pOS_Gadget *HPropGad,*VPropGad;
  144.     UWORD GWidth =256;
  145.     UWORD GHeight=256;
  146.  
  147.     if(Scr=pOS_LockPubScreen("Workbench")) {
  148.       pOS_WBox Box;
  149.       const pOS_DrawInfo *Dri=Scr->scr_DrawInfo;
  150.  
  151.       SuperMap=pOS_AllocGfxMap(Dri->dri_Base,
  152.            GFXTAG_Width,        GWidth,
  153.            GFXTAG_Height,       GHeight,
  154.            GFXTAG_FriendGfxMap, (ULONG)Scr->scr_RastPort->rp_GfxMap,
  155.            GFXTAG_GfxFlags,     GFXMAPF_Draw | GFXMAPF_Clear,
  156.            TAG_END);
  157.  
  158.  
  159.  
  160.       pOS_GetWindowBorder(Scr,&Box,WINFLGF_SizeBBottom | WINFLGF_SizeBRight,
  161.                           GFLG_RelWidth | GFLG_RelBottom,
  162.                           GACT_BottomBorder);
  163.  
  164.       HPropGad=(pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GPropClass],0,
  165.         ICLTAG_DrawInfo,      (ULONG)Scr->scr_DrawInfo,
  166.         ICLTAG_Immediate,     TRUE,
  167.         ICLTAG_UpdateGadget,  TRUE,
  168.         ICLTAG_Left,          Box.Left+3,
  169.         ICLTAG_RelBottom,     Box.Top+3,
  170.         ICLTAG_RelWidth,      Box.Width-6,
  171.         ICLTAG_Height,        Box.Height-6,
  172.         ICLTAG_AutoDelete,    TRUE,
  173.         ICLTAG_TopBorder,     TRUE,
  174.         ICLTAG_GadBorderType, GADBORTYP_None,
  175.         PRGADTAG_CreateUDGads,TRUE,
  176.         PRGADTAG_Flags,       PRGADF_FreeHoriz,
  177.         PRGADTAG_Visible,     GWidth,
  178.         PRGADTAG_Total,       GWidth,
  179.         TAG_END);
  180.  
  181.       pOS_GetWindowBorder(Scr,&Box,WINFLGF_SizeBBottom | WINFLGF_SizeBRight,
  182.                           GFLG_RelRight | GFLG_RelHeight,
  183.                           GACT_RightBorder);
  184.  
  185.       VPropGad=(pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GPropClass],0,
  186.         ICLTAG_DrawInfo,      (ULONG)Scr->scr_DrawInfo,
  187.         ICLTAG_Immediate,     TRUE,
  188.         ICLTAG_UpdateGadget,  TRUE,
  189.         ICLTAG_RelRight,      Box.Left+3,
  190.         ICLTAG_Top,           Box.Top+3,
  191.         ICLTAG_Width,         Box.Width-6,
  192.         ICLTAG_RelHeight,     Box.Height-6,
  193.         ICLTAG_AutoDelete,    TRUE,
  194.         ICLTAG_RightBorder,   TRUE,
  195.         ICLTAG_GadBorderType, GADBORTYP_None,
  196.         PRGADTAG_CreateUDGads,TRUE,
  197.         PRGADTAG_Flags,       PRGADF_FreeVert,
  198.         PRGADTAG_Visible,     GHeight,
  199.         PRGADTAG_Total,       GHeight,
  200.         TAG_END);
  201.  
  202.  
  203.       if(SuperMap) {
  204.         Win=pOS_OpenWindow(
  205.             SCRTAG_Title,   (ULONG)"SuperGfx-Window",
  206.             SCRTAG_PubName, (ULONG)"Workbench",
  207.             SCRTAG_Flags,   WINFLGF_DepthGadget | WINFLGF_GimmeZeroZero
  208.                            | WINFLGF_Activate | WINFLGF_CloseGadget
  209.                            | WINFLGF_Dragbar | WINFLGF_SizeGadget
  210.                            | WINFLGF_SizeBBottom | WINFLGF_SizeBRight,
  211.             SCRTAG_IDCMP,   IDCMP_CloseWindow | IDCMP_VanillaKey
  212.                            | IDCMP_GadgetDown | IDCMP_GadgetUp | IDCMP_UpdateGadget
  213.                            | IDCMP_NewSize,
  214.             SCRTAG_Width,       GWidth/2,
  215.             SCRTAG_Height,      GHeight/2,
  216.             SCRTAG_InnerMinWidth, 20,
  217.             SCRTAG_InnerMinHeight,20,
  218.             SCRTAG_InnerMaxWidth, GWidth,
  219.             SCRTAG_InnerMaxHeight,GHeight,
  220.             SCRTAG_ZipGadget,   TRUE,
  221.             SCRTAG_SuperGfxMap, (ULONG)SuperMap,
  222.             SCRTAG_Gadget,      (ULONG)HPropGad,
  223.             SCRTAG_Gadget,      (ULONG)VPropGad,
  224.             TAG_DONE);
  225.  
  226.         if(Win) {
  227.           pOS_IntuiMessage *Msg;
  228.           BOOL Ende=FALSE;
  229.  
  230.           pOS_DrawRectFill(Win->win_RastPort,120,120,160,160);
  231.  
  232.           CalcSliders(Win,HPropGad,VPropGad,GWidth,GHeight);
  233.  
  234.           while(!Ende) {
  235.             pOS_WaitPort(Win->win_UserPort);
  236.             while(Msg=(pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  237.               switch(Msg->im_Class) {
  238.  
  239.  
  240.                 case IDCMP_GadgetUp:
  241.                 case IDCMP_GadgetDown:
  242.                 case IDCMP_UpdateGadget:
  243.                   if( (pOS_Gadget*)Msg->im_IAddress==HPropGad
  244.                      || (pOS_Gadget*)Msg->im_IAddress==VPropGad) {
  245.                     MoveSliders(Win,HPropGad,VPropGad,GWidth,GHeight);
  246.                   }
  247.                   break;
  248.  
  249.  
  250.                 case IDCMP_NewSize:
  251.                   CalcSliders(Win,HPropGad,VPropGad,GWidth,GHeight);
  252.                   break;
  253.  
  254.                 case IDCMP_CloseWindow:  Ende=TRUE; break;
  255.               }
  256.               if(pOS_SysIMessage(Msg)==FALSE)
  257.                     pOS_ReplyMsg(&Msg->im_Message);
  258.             }
  259.           }
  260.           pOS_CloseWindow(Win);
  261.         }
  262.         else printf("Cannot open window\n");
  263.         pOS_FreeGfxMap(SuperMap);
  264.       }
  265.       else printf("Cannot create SuperGfxMap\n");
  266.       pOS_UnlockPubScreen(Scr);
  267.     }
  268.     else printf("Cannot lock PubScreen\n");
  269.  
  270.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  271.   }
  272.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  273.  
  274.   pOS_SetShellFail(Err);
  275.  
  276.   pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
  277.   pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
  278.   pOS_CloseLibrary((pOS_Library*)gb_DtTypeBase);
  279.   pOS_CloseLibrary((pOS_Library*)gb_LayerBase);
  280. }
  281.  
  282.  
  283.  
  284. /*----------------------------------
  285. -----------------------------------*/
  286. VOID CalcSliders(pOS_Window* win,pOS_Gadget* hgad,pOS_Gadget* vgad,
  287.                  UWORD width,UWORD height)
  288. {
  289.   pOS_IBox Box;
  290.  
  291.   pOS_GetWindowIBox(win,&Box,NULL);
  292.   if(hgad)
  293.     pOS_SetGadgetAttrs(win,hgad,
  294.       PRGADTAG_Visible,  Box.Width,
  295.       TAG_END);
  296.  
  297.   if(vgad)
  298.     pOS_SetGadgetAttrs(win,vgad,
  299.       PRGADTAG_Visible,  Box.Height,
  300.       TAG_END);
  301. }
  302.  
  303.  
  304. /*----------------------------------
  305. -----------------------------------*/
  306. VOID MoveSliders(pOS_Window* win,pOS_Gadget* hgad,pOS_Gadget* vgad,
  307.                  UWORD width,UWORD height)
  308. {
  309.   ULONG Value;
  310.   SLONG Diff;
  311.   pOS_Layer *const Ly=win->win_Layer;
  312.  
  313.   if(hgad) {
  314.     pOS_GetGadgetAttr(NULL,hgad,PRGADTAG_Top, &Value);
  315.  
  316.     Diff=-Ly->ly_ScrollX-Value;
  317.     if(Diff!=0) pOS_ScrollLayer(Ly,Diff,0);
  318.   }
  319.   if(vgad) {
  320.     pOS_GetGadgetAttr(NULL,vgad,PRGADTAG_Top,&Value);
  321.  
  322.     Diff=-Ly->ly_ScrollY-Value;
  323.     if(Diff!=0) pOS_ScrollLayer(Ly,0,Diff);
  324.   }
  325. }
  326.