home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / BGUI / bgui_e / sources / examples / TestPalette.e < prev    next >
Encoding:
Text File  |  1999-08-26  |  10.3 KB  |  264 lines

  1. /*
  2. **      TestPalette.e
  3. **
  4. **      (C) Copyright 1995 Jaba Development.
  5. **      (C) Copyright 1995 Jan van den Baard.
  6. **          All Rights Reserved.
  7. **
  8. **      Heavely modified by Dominique Dutoit, 5/1/96
  9. **      Updated on 11-Aug-96
  10. **      Updated on 01-Feb-97 : You need BGUI 41.8 to run this example!!!
  11. */
  12.  
  13. OPT OSVERSION=37
  14. OPT PREPROCESS
  15.  
  16. MODULE 'libraries/bgui',
  17.        'libraries/bguim',
  18.        'libraries/gadtools',
  19.        'bgui',
  20.        'bgui/bgui_image',
  21.        'bgui/bgui_obsolete',
  22.        'tools/boopsi',
  23.        'tools/installhook',
  24.        'utility/tagitem',
  25.        'utility/hooks',
  26.        'intuition/classes',
  27.        'intuition/classusr',
  28.        'intuition/gadgetclass',
  29.        'intuition/intuition',
  30.        'intuition',
  31.        'exec/types',
  32.        'amigalib/boopsi'
  33.  
  34. DEF     mybuttonclass:PTR TO iclass
  35. /*
  36.  *      Object ID's.
  37.  */
  38. CONST   ID_QUIT= 1,
  39.         ID_FRAME=2,
  40.         ID_SFRAME=3,
  41.         ID_LABEL=4,
  42.         ID_SLABEL=5
  43.  
  44. /*
  45.  *  The button we use is a very simple subclass from the
  46.  *  BGUI buttonclass to accept only drops from the four
  47.  *  paletteclass objects in this demo or from other palette
  48.  *  class objects from another task or window when they have
  49.  *  the same ID as we use here.
  50.  */
  51. PROC mybuttondispatch( cl:PTR TO iclass, obj:PTR TO object, bmsg )
  52.     DEF rc, pen, tag, i, j, imsg:msg
  53.     DEF gad:PTR TO gadget, dragmsg:PTR TO bmDragMsg, dragpnt:PTR TO bmDragPoint
  54.  
  55.     imsg := bmsg
  56.     i := imsg.methodid
  57.  
  58.     SELECT i
  59.         CASE    BASE_DRAGQUERY
  60.                 /*
  61.                  *  We only accept drops from our paletteclass objects.
  62.                  *  The test here is a bit simple but this way it does
  63.                  *  allow for drops from another task. Just run this demo
  64.                  *  twice and DragNDrop from one window to another.
  65.                  */
  66.                 dragpnt := imsg
  67.                 gad := dragpnt.source
  68.                 IF ( gad.gadgetid >= ID_FRAME ) AND ( gad.gadgetid <= ID_SLABEL )
  69.                     rc := BQR_ACCEPT
  70.                 ELSE
  71.                     rc := BQR_REJECT
  72.                 ENDIF
  73.  
  74.         CASE    BASE_DROPPED
  75.                 /*
  76.                  *  Get the pen from the object.
  77.                  */
  78.                 dragmsg := imsg
  79.                 GetAttr( PALETTE_CurrentColor, dragmsg.source, {pen} )
  80.  
  81.                 /*
  82.                  *  Let's see what has been dropped...
  83.                  */
  84.                 gad := dragmsg.source
  85.                 j := gad.gadgetid
  86.                 SELECT j
  87.                     CASE    ID_FRAME
  88.                             tag := FRM_BackPen
  89.  
  90.                     CASE    ID_SFRAME
  91.                             tag := FRM_SelectedBackPen
  92.  
  93.                     CASE    ID_LABEL
  94.                             tag := LAB_Pen
  95.  
  96.                     CASE    ID_SLABEL
  97.                             tag := LAB_SelectedPen
  98.  
  99.                 ENDSELECT
  100.  
  101.                 /*
  102.                  *  Set the pen. The superclass will force
  103.                  *  a refresh on the object when the drop has
  104.                  *  been made.
  105.                  */
  106.                 SetAttrsA( obj, [ tag, pen, TAG_END ] )
  107.                 rc := 1
  108.  
  109.         DEFAULT
  110.                 rc := doSuperMethodA( cl, obj, bmsg )
  111.  
  112.     ENDSELECT
  113. ENDPROC rc
  114.  
  115. /*
  116.  *  Setup our button class.
  117.  */
  118. PROC makemybuttonclass()
  119.     DEF cl:PTR TO iclass, super:PTR TO iclass
  120.  
  121.     /*
  122.      * Get a pointer to our superclass.
  123.      */
  124.     IF ( super := BgUI_GetClassPtr( BGUI_BUTTON_GADGET ))
  125.         /*
  126.          * Make our class.
  127.          */
  128.          IF ( cl := MakeClass( NIL, NIL, super, 0, 0 ))
  129.              /*
  130.               * Setup our dispatcher.
  131.               */
  132.             installhook( cl.dispatcher, {mybuttondispatch} )
  133.          ENDIF
  134.      ENDIF
  135. ENDPROC cl
  136.  
  137. PROC main()
  138.      DEF window
  139.      DEF wo_window, go_quit, go_b, go_pal[ 4 ]:ARRAY OF LONG
  140.      DEF signal = 0, rc, a
  141.      DEF defpens[ 4 ]:ARRAY OF LONG
  142.      DEF running = TRUE
  143.  
  144.      defpens := [ 0, 3, 1, 1]
  145.  
  146.      /*
  147.      **      Open BGUI.
  148.      **/
  149.      IF ( bguibase := OpenLibrary( BGUINAME, BGUIVERSION ))
  150.              /*
  151.               * And our drop-buton class.
  152.               */
  153.               IF ( mybuttonclass := makemybuttonclass() )
  154.               /*
  155.                * I assume a depth of three
  156.                * (8 colors) here for simplicity.
  157.                */
  158.                FOR a := 0 TO 3
  159.                    go_pal[ a ] := PaletteObject,
  160.                                         FRM_Type,             FRTYPE_BUTTON,
  161.                                         FRM_Recessed,         TRUE,
  162.                                         PALETTE_Depth,        3,
  163.                                         PALETTE_CurrentColor, defpens[ a ],
  164.                                         GA_ID,                a + 2,
  165.                                         BT_DragObject,        TRUE,
  166.                                     EndObject
  167.                ENDFOR
  168.                /*
  169.                **  Create the window object.
  170.                **/
  171.                wo_window := WindowObject,
  172.                      WINDOW_Title,           'PaletteClass Demo',
  173.                      WINDOW_SmartRefresh,    TRUE,
  174.                      WINDOW_RMBTrap,         TRUE,
  175.                      WINDOW_AutoAspect,      TRUE,
  176.                      WINDOW_AutoKeyLabel,    TRUE,
  177.                      WINDOW_IDCMP,           IDCMP_MOUSEMOVE,
  178.                      WINDOW_MasterGroup,
  179.                          VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  180.                              GROUP_BackFill,    SHINE_RASTER,
  181.                                  StartMember,
  182.                                      InfoFixed( NIL, '\ecAs you can see the colors of the below button\nare normal but when you change the colors with\nthe palette objects the colors of the button change.\n\nYou can also pickup the color and drop it onto the\nbutton. \ebDragNDrop\en in action.', NIL, 8 ),
  183.                                  EndMember,
  184.                                  StartMember,
  185.                                      HGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  186.                                          FRM_Type,          FRTYPE_BUTTON,
  187.                                          FRM_Recessed,      TRUE,
  188.                                          StartMember, go_b := NewObjectA( mybuttonclass, NIL,
  189.                                                                          [ FRM_Type,         FRTYPE_BUTTON,
  190.                                                                            LAB_Label,        'Palette Demo',
  191.                                                                            BT_DropObject,    TRUE,
  192.                                                                            TAG_END] ), EndMember,
  193.                                      EndObject, FixMinHeight,
  194.                                  EndMember,
  195.                                  StartMember,
  196.                                      HGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  197.                                          FRM_Type,           FRTYPE_BUTTON,
  198.                                          FRM_Recessed,       TRUE,
  199.                                          StartMember,
  200.                                              VGroupObject, Spacing( 4 ),
  201.                                                  LAB_Label,  'Background:',
  202.                                                  LAB_Place,  PLACE_ABOVE,
  203.                                                  StartMember, go_pal[ 0 ], EndMember,
  204.                                                  StartMember, go_pal[ 1 ], EndMember,
  205.                                              EndObject,
  206.                                          EndMember,
  207.                                          StartMember,
  208.                                              VGroupObject, Spacing( 4 ),
  209.                                                  LAB_Label,  'Label:',
  210.                                                  LAB_Place,  PLACE_ABOVE,
  211.                                                  StartMember, go_pal[ 2 ], EndMember,
  212.                                                  StartMember, go_pal[ 3 ], EndMember,
  213.                                              EndObject,
  214.                                          EndMember,
  215.                                      EndObject,
  216.                                  EndMember,
  217.                                  StartMember,
  218.                                      HGroupObject,
  219.                                          VarSpace( DEFAULT_WEIGHT ),
  220.                                          StartMember, go_quit := KeyButton( '_Quit', ID_QUIT ), EndMember,
  221.                                          VarSpace( DEFAULT_WEIGHT ),
  222.                                      EndObject, FixMinHeight,
  223.                                  EndMember,
  224.                          EndObject,
  225.                EndObject
  226.  
  227.                /*
  228.                **      Object created OK?
  229.                **/
  230.                IF ( wo_window )
  231.                   AddMap( go_pal[ 0 ], go_b, [ PALETTE_CurrentColor, FRM_BackPen,        TAG_END ] )
  232.                   AddMap( go_pal[ 1 ], go_b, [ PALETTE_CurrentColor, FRM_SelectedBackPen,TAG_END ] )
  233.                   AddMap( go_pal[ 2 ], go_b, [ PALETTE_CurrentColor, LAB_Pen,            TAG_END ] )
  234.                   AddMap( go_pal[ 3 ], go_b, [ PALETTE_CurrentColor, LAB_SelectedPen,    TAG_END ] )
  235.                   IF ( window := WindowOpen( wo_window ) )
  236.                      GetAttr( WINDOW_SigMask, wo_window, {signal} )
  237.                          WHILE running = TRUE
  238.                                Wait( signal )
  239.                                WHILE ( rc := HandleEvent( wo_window )) <> WMHI_NOMORE
  240.                                      SELECT rc
  241.                                             CASE    WMHI_CLOSEWINDOW
  242.                                                     running := FALSE
  243.                                             CASE    ID_QUIT
  244.                                                     running := FALSE
  245.                                      ENDSELECT
  246.                                ENDWHILE
  247.                          ENDWHILE
  248.                   ELSE
  249.                      WriteF( 'Unable to open the window\n' )
  250.                   ENDIF
  251.                   DisposeObject( wo_window )
  252.                ELSE
  253.                   WriteF( 'Unable to create a window object\n' )
  254.                ENDIF
  255.                FreeClass( mybuttonclass )
  256.           ELSE
  257.               WriteF( 'Unable to create custom class\n' )
  258.           ENDIF
  259.           CloseLibrary(bguibase)
  260.      ELSE
  261.          WriteF( 'Unable to open the bgui.library\n' )
  262.      ENDIF
  263. ENDPROC NIL
  264.