#INCLUDE "button.module"
#INCLUDE "course.module"

-- An example control process.  It disables each button that is clicked.
PROC control(CHAN BYTE scr!, [][]CHAN BUTTONCFG configure!, CHAN BYTE quit?, [][]CHAN CLICK click?)
  VAL INT buttons IS (SIZE configure):
  MOBILE []BYTE incoming.name:
  INITIAL BOOL flip IS TRUE:
  INITIAL BOOL run IS TRUE:
  WHILE run
    ALT
      ALT i = 0 FOR (SIZE click)
        ALT j = 0 FOR (SIZE click[0])
          click[i][j] ? incoming.name
            SEQ
              out.int(i, 0, scr)
              scr ! ','
              out.int(j, 0, scr)
              out.string(incoming.name, 0, scr)
              out.string(" clicked*c*n", 0, scr)
              configure[i][j] ! disable
              configure[i][j] ! name; "Big Fish"
              out.int(i, 0, scr)
              scr ! ','
              out.int(j, 0, scr)
              out.string(" disabled*c*n", 0, scr)
      BYTE tmp:
      quit ? tmp
        SEQ
          out.string(" got quit - quitting*c*n", 0, scr)
          run := FALSE
:

PROC main(CHAN BYTE kyb?, scr!, CHAN BYTE err!)
  -- The size of the window
  VAL INT resolution.x IS 800:
  VAL INT resolution.y IS 600:
  -- The number of buttons 
  VAL INT nr.of.buttons.x IS 6:
  VAL INT nr.of.buttons.y IS 4:
  -- Listens to the close button/events on the window
  CHAN BYTE quit:
  -- The channels down which button clicks are reported.
  [nr.of.buttons.x][nr.of.buttons.y]CHAN CLICK click:
  -- The button configuration channels
  [nr.of.buttons.x][nr.of.buttons.y]CHAN BUTTONCFG configure:
  PAR
    -- Set up graphics window
    setup.button.window(click!, configure?, err!, quit!, resolution.x, resolution.y)
    -- Start the 'control' proc that configures all the buttons
    control(scr!, configure!, quit?, click?)
:


