home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / objectiv.lha / Examples / Manx / demogadget2.c < prev    next >
C/C++ Source or Header  |  1992-10-21  |  10KB  |  301 lines

  1. /*
  2. ** $Filename: demogadget2.c $
  3. ** $Release : 1.0           $
  4. ** $Revision: 1.274         $
  5. ** $Date    : 21/10/92      $
  6. **
  7. **
  8. ** (C) Copyright 1992 Davide Massarenti
  9. **              All Rights Reserved
  10. **
  11. ** MANX 5.2: cc -ps -wdrunpo -so <name>.c
  12. **           ln -o <name> <name>.o -lOGTglue -lc16
  13. **
  14. */
  15.  
  16. #include <OGT/ObjectiveGadTools.h>
  17.  
  18. #define ARGS_TEMPLATE "FONT/K,SIZE/N"
  19. #define ARGS_FONT       (0)
  20. #define ARGS_SIZE       (1)
  21. #define ARGS_NUMOF      (2)
  22.  
  23. static LONG args[ ARGS_NUMOF ];
  24.  
  25.  
  26. static char Class_Group   [] =    GROUP_OGT_CLASS;
  27. static char Class_Button  [] =   BUTTON_OGT_CLASS;
  28. static char Class_Scroller[] = SCROLLER_OGT_CLASS;
  29.  
  30. struct TextAttr  MyAttr = { "courier.font", 18 };
  31. struct TextFont *MyFont;
  32.  
  33. APTR                     VInfo;
  34. struct Window           *Win;
  35. Object                 **Gads;
  36. struct RDArgs           *Ra;
  37.  
  38.  
  39. struct TagItem WindowDescTags[] =
  40. {
  41.    { OVI_GimmeZeroZero, TRUE                                    },
  42.    { WA_Title         , "DemoGadget2"                           },
  43.    { WA_Activate      , TRUE                                    },
  44.    { WA_SimpleRefresh , TRUE                                    },
  45.    { WA_NoCareRefresh , TRUE                                    },
  46.    { WA_DepthGadget   , TRUE                                    },
  47.    { WA_SizeGadget    , TRUE                                    },
  48.    { WA_SizeBBottom   , TRUE                                    },
  49.    { WA_SizeBRight    , TRUE                                    },
  50.    { WA_DragBar       , TRUE                                    },
  51.    { WA_Left          , 300                                     },
  52.    { WA_Top           , 150                                     },
  53.    { WA_Width         , 280                                     },
  54.    { WA_Height        , 200                                     },
  55.    { WA_MinWidth      , 180                                     },
  56.    { WA_MinHeight     , 70                                      },
  57.    { WA_MaxWidth      , 2000                                    },
  58.    { WA_MaxHeight     , 2000                                    },
  59.    { WA_IDCMP         , (IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE) },
  60.    { WA_CloseGadget   , TRUE                                    },
  61.    { TAG_DONE                                                   },
  62. };
  63.  
  64.  
  65. struct TagItem Object1Desc[] = /* GROUP_OGT_CLASS */
  66. {
  67.    { GA_ID          , 1                  },
  68.  
  69.    { OGT_ScaleTop   , OGT_FontRelative   },
  70.    { OGT_ScaleWidth , OGT_DomainRelative },
  71.    { OGT_ScaleHeight, OGT_DomainRelative },
  72.    { GA_Left        , 2                  },
  73.    { GA_Top         , 12                 },
  74.    { GA_Width       , 50                 },
  75.    { GA_Height      , 25                 },
  76.  
  77.    { GA_Text        , "Pro_va"           },
  78.    { OGT_DrawFrame  , TRUE               },
  79.    { TAG_DONE                            },
  80. };
  81.  
  82. struct TagItem Object2Desc[] = /* BUTTON_OGT_CLASS */
  83. {
  84.    { GA_ID               , 2                       },
  85.    { GA_Immediate        , TRUE                    },
  86.    { GA_Selected         , TRUE                    },
  87.  
  88.    { OGT_ScaleWidth      , OGT_DomainRelative      },
  89.    { OGT_ScaleHeight     , OGT_DomainRelative      },
  90.    { OGT_DomainXscale    , 140                     },
  91.    { OGT_DomainYscale    , 50                      },
  92.    { GA_Left             , 4                       },
  93.    { GA_Top              , 2                       },
  94.    { GA_Width            , 26                      },
  95.    { GA_Height           , 11                      },
  96.  
  97.    { GA_Text             , "_Primo"                },
  98.    { OGT_TextPlacement   , OGT_Text_RIGHT          },
  99.    { OGTBU_VectorImageDef, OGTBU_VectorImage_Check },
  100.    { TAG_DONE                                      },
  101. };
  102.  
  103. struct TagItem Object3Desc[] = /* BUTTON_OGT_CLASS */
  104. {
  105.    { GA_ID               , 3                                     },
  106.    { GA_Immediate        , TRUE                                  },
  107.    { GA_Selected         , TRUE                                  },
  108.  
  109.    { OGT_SetPosReference , OGT_Y_Mode_Align                      },
  110.    { OGT_SetDimReference , (OGT_X_Mode_Align | OGT_Y_Mode_Align) },
  111.    { GA_Top              , 2                                     },
  112.  
  113.    { GA_Text             , "_Secondo"                            },
  114.    { OGT_TextPlacement   , OGT_Text_RIGHT                        },
  115.    { OGTBU_VectorImageDef, OGTBU_VectorImage_Check               },
  116.    { TAG_DONE                                                    },
  117. };
  118.  
  119. struct TagItem Object4Desc[] = /* BUTTON_OGT_CLASS */
  120. {
  121.    { GA_ID               , 4                                     },
  122.    { GA_Immediate        , TRUE                                  },
  123.    { GA_Selected         , TRUE                                  },
  124.  
  125.    { OGT_SetPosReference , OGT_Y_Mode_Align                      },
  126.    { OGT_SetDimReference , (OGT_X_Mode_Align | OGT_Y_Mode_Align) },
  127.    { GA_Top              , 2                                     },
  128.  
  129.    { GA_Text             , "_Terzo"                              },
  130.    { OGT_TextPlacement   , OGT_Text_RIGHT                        },
  131.    { OGTBU_VectorImageDef, OGTBU_VectorImage_Check               },
  132.    { TAG_DONE                                                    },
  133. };
  134.  
  135. struct TagItem Object5Desc[] = /* SCROLLER_OGT_CLASS */
  136. {
  137.    { GA_ID              , 5                  },
  138.    { GA_Immediate       , TRUE               },
  139.    { GA_FollowMouse     , TRUE               },
  140.    { GA_RelVerify       , TRUE               },
  141.  
  142.    { OGT_SetPosReference, OGT_Y_Mode_Align   },
  143.    { OGT_SetDimReference, OGT_X_Dim_Relative },
  144.    { OGT_DomainXscale   , 140                },
  145.    { OGT_DomainYscale   , 50                 },
  146.    { GA_Left            , 0                  },
  147.    { GA_Top             , 2                  },
  148.    { GA_Width           , -12                },
  149.    { GA_Height          , 9                  },
  150.  
  151.    { GA_Text            , "_Quarto"          },
  152.    { OGT_TextPlacement  , OGT_Text_RIGHT     },
  153.  
  154.    { PGA_Freedom        , FREEHORIZ          },
  155.    { PGA_NewLook        , TRUE               },
  156.    { PGA_Top            , 10                 },
  157.    { PGA_Visible        , 10                 },
  158.    { PGA_Total          , 100                },
  159.    { TAG_DONE                                },
  160. };
  161.  
  162.  
  163. struct TagItem Obj6toObj2[] =
  164. {
  165.    { PGA_Top,  GA_Left },
  166.    { TAG_DONE          },
  167. };
  168.  
  169. struct TagItem Object6Desc[] = /* SCROLLER_OGT_CLASS */
  170. {
  171.    { GA_ID              , 6                  },
  172.    { GA_Immediate       , TRUE               },
  173.    { GA_FollowMouse     , TRUE               },
  174.    { GA_RelVerify       , TRUE               },
  175.  
  176.    { OGT_SetPosHandle   , OGT_Y_Bottom       },
  177.    { OGT_SetDimReference, OGT_X_Dim_Relative },
  178.    { GA_Left            , 0                  },
  179.    { GA_RelBottom       , 0                  },
  180.    { GA_Height          , 9                  },
  181.  
  182.    { GA_Text            , "_Muove"           },
  183.    { OGT_TextPlacement  , OGT_Text_ABOVE     },
  184.  
  185.    { PGA_Freedom        , FREEHORIZ          },
  186.    { PGA_Top            , 10                 },
  187.    { PGA_Visible        , 10                 },
  188.    { PGA_Total          , 100                },
  189.    { TAG_DONE                                },
  190. };
  191.  
  192. struct OGT_ObjectSettings ListOfObjects[] =
  193. {
  194.    { Class_Group   , Object1Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  195.    { Class_Button  , Object2Desc, NULL, 0           , OGT_NOOBJECT },
  196.    { Class_Button  , Object3Desc, NULL, 0           , OGT_NOOBJECT },
  197.    { Class_Button  , Object4Desc, NULL, 0           , OGT_NOOBJECT },
  198.    { Class_Scroller, Object5Desc, NULL, 0           , OGT_NOOBJECT },
  199.    { Class_Scroller, Object6Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  200.    { NULL                                                          },
  201. };
  202.  
  203. struct OGT_ObjectLink ListOfLinks[] =
  204. {
  205.    { 5           , 1, Obj6toObj2 },
  206.    { OGT_NOOBJECT                },
  207. };
  208.  
  209. static void cleanup           ( char *str );
  210. static void goHandleWindowWait( void      );
  211. static BOOL goHandleWindow    ( void      );
  212.  
  213. void main( void )
  214. {
  215.    if(!OpenOGT()) cleanup( "no objectivegadtools library\n" );
  216.  
  217.    if(!(Ra = ReadArgs( ARGS_TEMPLATE, args, NULL ))) cleanup( "can't parse args\n" );
  218.  
  219.    if(args[ ARGS_FONT ]) MyAttr.ta_Name  =  (void  *)args[ ARGS_FONT ];
  220.    if(args[ ARGS_SIZE ]) MyAttr.ta_YSize = *(ULONG *)args[ ARGS_SIZE ];
  221.  
  222.    if(MyAttr.ta_Name)
  223.    {
  224.       if(!(MyFont = OpenDiskFont( &MyAttr ))) cleanup( "can't open font!!\n" );
  225.    }
  226.  
  227.    while(1)
  228.    {
  229.       VInfo = OGT_GetVisualInfo( NULL, OGT_TextFont, (ULONG)MyFont         ,
  230.                                        TAG_MORE    , (ULONG)WindowDescTags );
  231.  
  232.       if(VInfo == NULL) cleanup( "can't open my window.\n" );
  233.  
  234.       if(!OGT_BuildObjects( VInfo, ListOfObjects, ListOfLinks, &Gads )) cleanup( "can't create objects" );
  235.  
  236.       Win = OGT_GetWindowPtr( VInfo );
  237.  
  238.       goHandleWindowWait();
  239.  
  240.       DisposeObject( Gads[ 4 ] ); Gads[ 4 ] = NULL;
  241.  
  242.       goHandleWindowWait();
  243.  
  244.       DisposeObject( Gads[ 2 ] ); Gads[ 2 ] = NULL;
  245.  
  246.       goHandleWindowWait();
  247.  
  248.  
  249.       break;
  250.    }
  251.  
  252.    cleanup( "all done" );
  253. }
  254.  
  255. static void cleanup( char *str )
  256. {
  257.    if(str) Printf( "%s\n", str );
  258.  
  259.    if(Ra    ) FreeArgs          ( Ra     );
  260.    if(Gads  ) FreeVec           ( Gads   );
  261.    if(VInfo ) OGT_FreeVisualInfo( VInfo  );
  262.    if(MyFont) CloseFont         ( MyFont );
  263.  
  264.    CloseOGT();
  265.  
  266.    Exit( 0 );
  267. }
  268.  
  269. static void goHandleWindowWait( void )
  270. {
  271.    BOOL keeprunning = TRUE;
  272.  
  273.    while(keeprunning)
  274.    {
  275.       Wait( 1L << Win->UserPort->mp_SigBit );
  276.  
  277.       keeprunning = goHandleWindow();
  278.    }
  279. }
  280.  
  281. static BOOL goHandleWindow( void )
  282. {
  283.    BOOL                 keeprunning = TRUE;
  284.  
  285.    struct IntuiMessage *imsg;
  286.  
  287.    while(keeprunning && (imsg = OGT_GetMsg( VInfo )))
  288.    {
  289.       switch(imsg->Class)
  290.       {
  291.          case IDCMP_CLOSEWINDOW:
  292.             keeprunning = FALSE;
  293.             break;
  294.       }
  295.  
  296.       OGT_ReplyMsg( imsg );
  297.    }
  298.  
  299.    return( keeprunning );
  300. }
  301.