 #compact 
 % Title "ConsoleG Demo: Fade Out"

  % WindowStyle WS_OVERLAPPEDWINDOW
  % Animated

  $filename "t.exe"
 'uses RTL64
  uses ConsoleG
 
  BeginScript

  sub main()
  ==========
  static sys tally
  sys hWnd=Gwnd

  'DISPLAY AND FADE OUT
  if not picking then
    static sys Counter '60Hz Frame counter
    counter++
    if counter>180 'AFTER 3 SECONDS
      int WindowOpacity
      int t=(counter-180)*255/120 '2 sec fade
      if t>255 then t=255
      WindowOpacity=255-t
      if counter=300 '5 SECONDS
        CloseScene 'REQUEST SHUT DOWN
      end if 
      'Set WS_EX_LAYERED on this window 
      SetWindowLongPtr(hwnd, GWL_EXSTYLE,
      GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED)
      SetLayeredWindowAttributes(hwnd, 0, WindowOpacity, LWA_ALPHA);
    end if
  end if


  static int  z, y, x
  static quad t1,t2

  if opening then 'FIRST CALL ONLY
    timemark t1
  end if

  if closing then 'FINAL CALL BEFORE SHUTDOWN
    'mbox "Bye!"
    'exit sub
  end if

  if not pick then
    static sys tally
    tally++
    pushstate
    move 0,0
    timemark t2
    scale 1.5
    double td=timediff(t2,t1)
    SYSTEMTIME st : getLocalTime st
    '
    macro pr(a,b) 'PRINTING LIST
      pushstate : color .5,1,1 : print a : popstate
      pushstate : color 1,1,.5 : move 8 : print b : popstate
      printl ""
    end macro
    '
    pr "System Time:   ", left(timeStr(st),21)
    pr "Lapsed Time:   ", str(td,3)+"  "
    pr "10ms Count:    ", str(tickCount*2)
    pr "Frame Count:   ", str(tally++)
   'pr "Action Code:   ", str(act)
   'pr "Picked ID:     ", str(picked)
   'pr "Keyboard Code: ", str(keyd)

    popstate
  end if

  end sub 'main

  EndScript