home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / e / EasyGUI_v33b2.lha / Src / EasyGUI / led_test4.e < prev    next >
Text File  |  1997-02-13  |  3KB  |  128 lines

  1. -> This one shows the use of multi-window GUIs with PLUGINs.  A ticker is
  2. -> used, so the counting stops when none of the windows in the group is
  3. -> active!
  4. MODULE 'tools/easygui', 'tools/exceptions',
  5.        'graphics/text', 'intuition/intuition',
  6.        'plugins/led', 'plugins/ticker'
  7.  
  8. -> Global for multiforall().
  9. DEF gh:PTR TO guihandle
  10.  
  11. CONST NUM_VALUES=2
  12.  
  13. -> Store all the GUI data in one place.
  14. OBJECT mygui
  15.   -> In particular, keep PLUGIN references here.
  16.   ledplug:PTR TO led
  17.   ticker:PTR TO ticker
  18.   gh:PTR TO guihandle
  19.   gui
  20.   title
  21.   going
  22.   values[NUM_VALUES]:ARRAY OF INT
  23. ENDOBJECT
  24.  
  25. -> The main loop: create one window to start with.
  26. PROC main() HANDLE
  27.   DEF mh=NIL
  28.   mh:=multiinit()
  29.   create(mh)
  30.   multiloop(mh)
  31. EXCEPT DO
  32.   cleanmulti(mh)
  33.   report_exception()
  34. ENDPROC
  35.  
  36. -> Create a new GUI.
  37. PROC create(mh) HANDLE
  38.   DEF t, g, gui=NIL:PTR TO mygui
  39.   NEW gui
  40.   -> Allocate all PLUGINs for the GUI like this.
  41.   NEW gui.ledplug.led(NUM_VALUES,gui.values,TRUE)
  42.   NEW gui.ticker
  43.   -> Now we can try opening a GUI.
  44.   gui.gh:=addmultiA(mh,'BOOPSI in EasyGUI!',
  45.                    g:=NEW [ROWS,
  46.                      t:=NEW [TEXT,'LED Boopsi image tester...',NIL,TRUE,16],
  47.                      NEW [PLUGIN,{tick},gui.ticker],
  48.                      NEW [COLS,
  49.                         NEW [EQROWS,
  50.                           NEW [BUTTON,{runaction},'Run/Stop'],
  51.                           NEW [BUTTON,{spawn},'Spawn'],
  52.                           NEW [BUTTON,0,'Quit']
  53.                         ],
  54.                         NEW [PLUGIN,0,gui.ledplug]
  55.                      ]
  56.                    ],
  57.                    [EG_INFO,gui, EG_LEFT,Rnd(400), EG_TOP,Rnd(400),
  58.                     -> The cleanup routine will deallocate the PLUGINs used.
  59.                     EG_CLEAN,{cleanmygui}, EG_CLOSE,{close}, NIL])
  60.   gui.gui:=g
  61.   gui.title:=t
  62. EXCEPT
  63.   -> If there was any problem then it may have been the creation of PLUGINs
  64.   -> or addmultiA().  Luckily, addmultiA() (and guiinitA()) will *not* call
  65.   -> the EG_CLEAN function if they caused the problem, so we can (safely).
  66.   cleanmygui(gui)
  67.   ReThrow()
  68. ENDPROC
  69.  
  70. -> The custom clean up code for each GUI.
  71. PROC cleanmygui(gui:PTR TO mygui)
  72.   IF gui
  73.     disposegui(gui.gui)
  74.     END gui.ticker
  75.     END gui.ledplug
  76.     END gui
  77.   ENDIF
  78. ENDPROC
  79.  
  80. -> The action function creates a new GUI in the group.
  81. PROC spawn(info:PTR TO mygui) IS create(info.gh.mh)
  82.  
  83. -> The run/stop action.
  84. PROC runaction(info:PTR TO mygui)
  85.   IF info.going
  86.     -> Going, so stop.
  87.     info.going:=FALSE
  88.     settext(info.gh,info.title,'You stopped me!')
  89.   ELSE
  90.     -> Stopped, so go.
  91.     info.going:=TRUE
  92.     settext(info.gh,info.title,'Started counting...')
  93.     Delay(10)
  94.     settext(info.gh,info.title,'Counting...')
  95.   ENDIF
  96. ENDPROC
  97.  
  98. -> Tick!
  99. PROC tick(info:PTR TO mygui,t)
  100.   -> Go to next count for all open windows.
  101.   multiforall({gh},info.gh.mh,`IF gh.wnd THEN next(gh.info) ELSE 0)
  102. ENDPROC
  103.  
  104. -> Next count.
  105. PROC next(info:PTR TO mygui)
  106.   DEF l:PTR TO led,h,m
  107.   IF info.going
  108.     l:=info.ledplug
  109.     l.colon:=(l.colon=FALSE)
  110.     m:=info.values[1]+1
  111.     IF m=60
  112.       m:=0
  113.       h:=info.values[]+1
  114.       IF h=13
  115.         h:=0
  116.         info.going:=FALSE
  117.         settext(info.gh,info.title,'Finished!')
  118.       ENDIF
  119.       l.values[]:=h
  120.     ENDIF
  121.     l.values[1]:=m
  122.     l.redisplay()
  123.   ENDIF
  124. ENDPROC
  125.  
  126. -> Close function.
  127. PROC close(info:PTR TO mygui) IS cleangui(info.gh)
  128.