home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / boopsi / screenmodeclass / screenmodeclasstest.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  12KB  |  282 lines

  1. #include <proto/exec.h>
  2. #include <proto/asl.h>
  3. #include <proto/intuition.h>
  4. #include <clib/alib_protos.h>
  5. #include <proto/bgui.h>
  6. #include <proto/utility.h>
  7. #include <libraries/bgui_macros.h>
  8. #include "LibPerso:Boopsi/ScreenModeClass.h"
  9. #include <stdio.h>
  10.  
  11. #ifdef _DCC
  12. #include <lib/misc.h>
  13. #endif
  14.  
  15.  
  16. char *V_e_R_s_I_o_N= "ScreenModeClassTest 1.1 (29.9.95) Doguet Emmanuel";
  17.  
  18. /*
  19. **  Define ID of gadgets
  20. **/
  21. #define GD_BUTTON           0
  22. #define GD_GUI_MODE         1
  23. #define GD_INFO_WIN         2
  24. #define GD_CONTROL_MINSIZE  3
  25. #define GD_DO_WIDTH         4
  26. #define GD_DO_HEIGHT        5
  27. #define GD_DO_OVERSCAN      6
  28. #define GD_DO_AUTOSCROLL    7
  29. #define GD_SLEEP            8
  30. #define GD_MIN_WIDTH        9
  31. #define GD_MIN_HEIGHT       10
  32.  
  33. #define GAD_CNT             11
  34.  
  35.  
  36. /*
  37. **  Datas for the bgui window.
  38. **/
  39. Object          *WO_Main;
  40. struct Window   *MainWnd = NULL;
  41. ULONG           MainMask=NULL;
  42. Object          *MainGad[ GAD_CNT ];
  43.  
  44.  
  45. struct Library  *BGUIBase=NULL;
  46.  
  47.  
  48. /*
  49. **  Special version of GetAttr.
  50. **/
  51. ULONG GetAttrs( Object *obj, ULONG tag1, ... )
  52. {
  53. struct TagItem          *tstate = ( struct TagItem * )&tag1, *tag;
  54. ULONG                    num = 0L;
  55.  
  56.         while ( tag = NextTagItem( &tstate ))
  57.                 num += GetAttr( tag->ti_Tag, obj, ( ULONG * )tag->ti_Data );
  58.  
  59.         return( num );
  60. }
  61.  
  62.  
  63.  
  64.  
  65. main( int argc, char **argv )
  66. {
  67. Class   *ScreenModeClass=NULL;
  68. Object  *ScreenRequester=NULL;
  69. ULONG   t;
  70. BOOL    done=TRUE;
  71. int     rc;
  72. ULONG   Width, Height, Depth, ModeID, AutoScroll, Overscan;
  73.  
  74.     /*
  75.     **      Open the bgui.library
  76.     **/
  77.     if( !( BGUIBase = OpenLibrary( "bgui.library", 37 ) ))
  78.     {
  79.         printf("This demo use the bgui.library.\n");
  80.         return( 30 );
  81.     }
  82.  
  83.     /*
  84.     **      Init. the class.
  85.     **/
  86.     ScreenModeClass=InitScreenModeClass();
  87.  
  88.     if( ScreenModeClass )
  89.     {
  90.  
  91.         /*
  92.         **  Create a window.
  93.         **/
  94.         WO_Main = WindowObject,
  95.                     WINDOW_Title,           "ScreenMode class demo",
  96.                     WINDOW_RMBTrap,         TRUE,
  97.                     WINDOW_SmartRefresh,    TRUE,
  98.                     WINDOW_ScaleWidth,      10,
  99.                     WINDOW_AutoAspect,      TRUE,
  100.                     WINDOW_LockHeight,      TRUE,
  101.                     WINDOW_MasterGroup,
  102.  
  103.                     VGroupObject, VOffset( 2 ), HOffset( 4 ), Spacing( 4 ),
  104.  
  105.                     /*
  106.                     **  Tags...
  107.                     **/
  108.                     StartMember, HGroupObject, NeXTFrame, FrameTitle( "Tags.."), VOffset( 2 ), BOffset( 4 ), HOffset( 4+4 ), Spacing( 4 ), EqualWidth,
  109.                         StartMember, VGroupObject, Spacing( 4 ),
  110.                             StartMember, MainGad[ GD_GUI_MODE ] = CheckBox( "GUI MODE", 0, GD_GUI_MODE ), FixMinWidth, EndMember,
  111.                             StartMember, MainGad[ GD_INFO_WIN ] = CheckBox( "Info window", 0, GD_INFO_WIN ), FixMinWidth, EndMember,
  112.                             StartMember, MainGad[ GD_CONTROL_MINSIZE ] = CheckBox( "SMC_ControlMinSize", 0, GD_CONTROL_MINSIZE ), FixMinWidth, EndMember,
  113.                             StartMember, MainGad[ GD_SLEEP ] = CheckBox( "Sleep window", 0, GD_SLEEP ), FixMinWidth, EndMember,
  114.                             StartMember, MainGad[ GD_MIN_WIDTH ] = Integer("Min Width", 0, 3, GD_MIN_WIDTH ), NoAlign, FixMinHeight, EndMember,
  115.                         EndObject, FixMinWidth, EndMember,
  116.  
  117.                         VarSpace(1),
  118.  
  119.                         StartMember, VGroupObject, Spacing( 4 ),
  120.                             StartMember, MainGad[ GD_DO_WIDTH ] = CheckBox( "Do Width", 0, GD_DO_WIDTH ), FixMinWidth, EndMember,
  121.                             StartMember, MainGad[ GD_DO_HEIGHT ] = CheckBox( "Do Height", 0, GD_DO_HEIGHT ), FixMinWidth, EndMember,
  122.                             StartMember, MainGad[ GD_DO_OVERSCAN ] = CheckBox( "Do Overscan", 0, GD_DO_OVERSCAN ), FixMinWidth, EndMember,
  123.                             StartMember, MainGad[ GD_DO_AUTOSCROLL ] = CheckBox( "Do AutoScroll", 0, GD_DO_AUTOSCROLL ), FixMinWidth, EndMember,
  124.                             StartMember, MainGad[ GD_MIN_HEIGHT ] = Integer("Min Height", 0, 3, GD_MIN_HEIGHT ), NoAlign, FixMinHeight, EndMember,
  125.                         EndObject, FixMinWidth, EndMember,
  126.  
  127.                     EndObject, FixMinHeight, EndMember,         /* End of TAG group */
  128.  
  129.                     StartMember, MainGad[ GD_BUTTON ] = Button( "Screen mode requester", GD_BUTTON ), FixMinHeight, EndMember,
  130.  
  131.                     EndObject,          /* End of Main VGroup object */
  132.  
  133.                     EndObject;          /* End of WindowObject */
  134.  
  135.  
  136.  
  137.  
  138.  
  139.         if( WO_Main )
  140.         {
  141.             /*
  142.             **  Open a window.
  143.             **/
  144.             MainWnd = WindowOpen( WO_Main );
  145.             GetAttr( WINDOW_SigMask, WO_Main, &MainMask );
  146.  
  147.             /*
  148.             **  Create a ScreenMode object.
  149.             **/
  150.             ScreenRequester=NewObject( ScreenModeClass, NULL,
  151.                         SMC_InitialInfoPos,         SMC_INFOPOS_TopRight,
  152.                         SMC_InfoPosArround,         TRUE,
  153.                         ASLSM_Window,               MainWnd,
  154.                     TAG_END );
  155.         }
  156.  
  157.         if( MainWnd && ScreenRequester )
  158.         do{
  159.             Wait( MainMask );
  160.  
  161.             while (( rc = HandleEvent( WO_Main )) != WMHI_NOMORE )
  162.             {
  163.                 switch ( rc )
  164.                 {
  165.                     case WMHI_CLOSEWINDOW:      done = FALSE;
  166.                                                 break;
  167.  
  168.                     /*
  169.                     **      Tags to set or unset.
  170.                     **/
  171.                     case GD_GUI_MODE:           if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  172.                                                     SetAttrs( ScreenRequester, SMC_GUI_MODES, TRUE, TAG_END );
  173.                                                 else
  174.                                                     SetAttrs( ScreenRequester, SMC_GUI_MODES, FALSE, TAG_END );
  175.                                                 break;
  176.  
  177.                     case GD_INFO_WIN:           if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  178.                                                     SetAttrs( ScreenRequester, ASLSM_InitialInfoOpened, TRUE, TAG_END );
  179.                                                 else
  180.                                                     SetAttrs( ScreenRequester, ASLSM_InitialInfoOpened, FALSE, TAG_END );
  181.                                                 break;
  182.  
  183.                     case GD_CONTROL_MINSIZE:    if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  184.                                                     SetAttrs( ScreenRequester, SMC_ControlMinSize ,TRUE, TAG_END );
  185.                                                 else
  186.                                                     SetAttrs( ScreenRequester, SMC_ControlMinSize, FALSE, TAG_END );
  187.                                                 break;   
  188.  
  189.                     case GD_DO_WIDTH:           if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  190.                                                     SetAttrs( ScreenRequester, ASLSM_DoWidth, TRUE, TAG_END );
  191.                                                 else
  192.                                                     SetAttrs( ScreenRequester, ASLSM_DoWidth, FALSE, TAG_END );
  193.                                                 break;
  194.  
  195.                     case GD_DO_HEIGHT:          if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  196.                                                     SetAttrs( ScreenRequester, ASLSM_DoHeight, TRUE, TAG_END );
  197.                                                 else
  198.                                                     SetAttrs( ScreenRequester, ASLSM_DoHeight, FALSE, TAG_END );
  199.                                                 break;
  200.  
  201.                     case GD_DO_OVERSCAN:        if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  202.                                                     SetAttrs( ScreenRequester, ASLSM_DoOverscanType,TRUE, TAG_END );
  203.                                                 else
  204.                                                     SetAttrs( ScreenRequester, ASLSM_DoOverscanType, FALSE, TAG_END );
  205.                                                 break;
  206.  
  207.                     case GD_DO_AUTOSCROLL:      if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  208.                                                     SetAttrs( ScreenRequester, ASLSM_DoAutoScroll,TRUE, TAG_END );
  209.                                                 else
  210.                                                     SetAttrs( ScreenRequester, ASLSM_DoAutoScroll, FALSE, TAG_END );
  211.                                                 break;
  212.  
  213.                     case GD_SLEEP:              if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  214.                                                     SetAttrs( ScreenRequester, ASLSM_SleepWindow,TRUE, TAG_END );
  215.                                                 else
  216.                                                     SetAttrs( ScreenRequester, ASLSM_SleepWindow, FALSE, TAG_END );
  217.                                                 break;
  218.  
  219.                     case GD_MIN_WIDTH:          GetAttr( STRINGA_LongVal, MainGad[ rc ], &t );
  220.                                                 SetAttrs( ScreenRequester, ASLSM_MinWidth, t, TAG_END );
  221.                                                 break;
  222.  
  223.                     case GD_MIN_HEIGHT:         GetAttr( STRINGA_LongVal, MainGad[ rc ], &t );
  224.                                                 SetAttrs( ScreenRequester, ASLSM_MinHeight, t, TAG_END );
  225.                                                 break;
  226.  
  227.                     /*
  228.                     **  Popup the screen mode requester.
  229.                     **/
  230.                     case GD_BUTTON:             if( ScreenModeReq( ScreenRequester ) )
  231.                                                 {
  232.                                                     GetAttrs( ScreenRequester,
  233.                                                                 SMC_DisplayWidth,   &Width,
  234.                                                                 SMC_DisplayHeight,  &Height,
  235.                                                                 SMC_DisplayID,      &ModeID,
  236.                                                                 SMC_AutoScroll,     &AutoScroll,
  237.                                                                 SMC_OverscanType,   &Overscan,
  238.                                                                 SMC_DisplayDepth,   &Depth,
  239.                                                                 TAG_END );
  240.  
  241.                                                     printf("\nModeID= 0x%x\nSize= %d x %d x %d\nAutoScroll=  %s\nOverscanType= %d\n",
  242.                                                                 ModeID, Width, Height, Depth,
  243.                                                                 AutoScroll ? "TRUE":"FALSE",
  244.                                                                 Overscan );
  245.                                                 }
  246.                                                 break;
  247.                 }
  248.             }
  249.  
  250.         } while( done );
  251.  
  252.         /*
  253.         **      Close and dispose the window.
  254.         **/
  255.         if( WO_Main )
  256.             DisposeObject( WO_Main );
  257.  
  258.         /*
  259.         **      Dispose the ScreenMode object.
  260.         **/
  261.         DisposeObject( ScreenRequester );
  262.  
  263.         /*
  264.         **      Dispose the class.
  265.         **/
  266.         FreeScreenModeClass( ScreenModeClass );
  267.     }
  268.  
  269.     CloseLibrary( BGUIBase );
  270.  
  271.     return(0);
  272. }
  273.  
  274.  
  275. #ifdef _DCC
  276. int wbmain( struct WBStartup *w )
  277. {
  278.     OpenConsole( "CON:0/450//100/ScreenModeClass demo/AUTO" );
  279.     return( main( 0, NULL ) );
  280. }
  281. #endif
  282.