home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rox.zip / spinner.rox < prev    next >
Text File  |  1994-04-08  |  3KB  |  134 lines

  1. :class spinner
  2.  
  3. :vars sem1 sem2 sem3 state row col
  4.  
  5. :*-------------------------------------------------------------------
  6. :* initialize
  7. :*-------------------------------------------------------------------
  8. :method init
  9.    if (0 = RoxQueryClassLoaded("EventSem")) then
  10.       rc = RoxLoadDLL("roxsem")
  11.  
  12.    sem1 = RoxCreate("EventSem")
  13.    sem2 = RoxCreate("EventSem")
  14.    sem3 = RoxCreate("MutexSem")
  15.  
  16.    state = 0
  17.  
  18.    if RxFuncQuery("SysLoadFuncs") then
  19.       do
  20.       rc = RxFuncAdd("SysLoadFuncs","REXXUtil","SysLoadFuncs")
  21.       rc = SysLoadFuncs()
  22.       end
  23.  
  24.    return
  25.  
  26. :*-------------------------------------------------------------------
  27. :* terminate
  28. :*-------------------------------------------------------------------
  29. :method deinit
  30.    rc = RoxDestroy(sem1)
  31.    rc = RoxDestroy(sem2)
  32.    return
  33.  
  34. :*-------------------------------------------------------------------
  35. :* start spinner - 2
  36. :*-------------------------------------------------------------------
  37. :method spin2
  38.  
  39.    spin.0  = "-"
  40.    spin.1  = "\"
  41.    spin.2  = "|"
  42.    spin.3  = "/"
  43.    spin.4  = "-"
  44.    spin.5  = "\"
  45.    spin.6  = "|"
  46.    spin.7  = "/"
  47.  
  48.    index   = -1
  49.  
  50.    g = .reset(sem1)
  51.    g = .reset(sem2)
  52.  
  53.    do while (.query(sem1) = 0)
  54.  
  55.       /*---------------------------------------------------------------
  56.        * increment spin state
  57.        *---------------------------------------------------------------*/
  58.       index = index + 1
  59.       index = index // 8
  60.  
  61.       /*---------------------------------------------------------------
  62.        * write spin character
  63.        *---------------------------------------------------------------*/
  64.       rc = .request(sem3)
  65.  
  66.       parse value SysCurPos(row,col) with origRow origCol
  67.       rc = charout(,spin.index)
  68.       rc = SysCurPos(origRow,origCol)
  69.  
  70.       rc = .release(sem3)
  71.  
  72.    end
  73.  
  74.    parse value SysCurPos(row,col) with origRow origCol
  75.    rc = charout(," ")
  76.    rc = SysCurPos(origRow,origCol)
  77.  
  78.    g = .post(sem2)
  79.  
  80.    return ""
  81.  
  82. :*-------------------------------------------------------------------
  83. :* start spinner
  84. :*-------------------------------------------------------------------
  85. :method spin
  86.  
  87.    if (state = 1) then
  88.       return self
  89.  
  90.    state = 1
  91.  
  92.    parse value SysCurPos() with row col
  93.  
  94.    rc = RoxSendThread("spin2",self)
  95.  
  96.    return self
  97.  
  98. :*-------------------------------------------------------------------
  99. :* stop
  100. :*-------------------------------------------------------------------
  101. :method stop
  102.  
  103.    state = 0
  104.  
  105.    g = .post(sem1)
  106.    g = .wait(sem2)
  107.  
  108.    state = 0
  109.  
  110.    return self
  111.  
  112. :*-------------------------------------------------------------------
  113. :* suspend
  114. :*-------------------------------------------------------------------
  115. :method suspend
  116.    if (state = 0) then
  117.       return self
  118.  
  119.    rc = .request(sem3)
  120.  
  121.    return rc
  122.  
  123. :*-------------------------------------------------------------------
  124. :* resume
  125. :*-------------------------------------------------------------------
  126. :method resume
  127.    if (state = 0) then
  128.       return self
  129.  
  130.    rc = .release(sem3)
  131.  
  132.    return rc
  133.  
  134.