home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FACETV.ZIP / RESPWIND.CPP < prev    next >
C/C++ Source or Header  |  1994-01-05  |  6KB  |  221 lines

  1. /************************************************************************
  2. **
  3. ** @(#)respwind.cpp    01/05/94    Chris Ahlstrom
  4. **
  5. ** C++ version, requires Turbo Vision by Borland
  6. **
  7. **    This module interfaces C++ with the standard FACE response
  8. ** light code (in FACE.LIB), and with code for handling various kinds
  9. ** of button devices.
  10. **
  11. **    This module has functions very similar to those of
  12. ** response.cpp, but this module only handles mouse events for
  13. ** a response box implemented in a window.
  14. **
  15. **    This modules calls routines from the ResponseInterior class to
  16. ** implement the lights.  See respintr.cpp for the types of lights
  17. ** implemented.
  18. **
  19. **    The lights are mapped onto a byte.  Whereever a bit is set,
  20. ** the corresponding "light" gets turned on.  Some convenient labels
  21. ** are added, too, to represent combinations of lights.
  22. **
  23. *************************************************************************/
  24.  
  25. #define RESPWIND_cpp
  26.  
  27. #include <stdio.h>
  28. #include <conio.h>
  29. #include <ctype.h>
  30.  
  31. #include "mkbutton.h"        // ResponseButton creation class
  32. #include "rbuttons.h"        // ResponseButton class
  33. #include "respwind.h"        // ResponseDevice class
  34. #include "respvga.h"        // declares/defines virtualBox
  35.  
  36.  
  37.  
  38. /************************************************************************
  39. ** ResponseDevice
  40. **
  41. **    Can't make copies and such until we write the copy constructor
  42. ** and assignment operator.
  43. **
  44. *************************************************************************/
  45.  
  46. ResponseDevice::ResponseDevice
  47. (
  48.     ResponseType device,
  49.     const TRect& bounds,
  50.     const char *atitle,
  51.     short anumber
  52. ) :
  53.     TWindow    (bounds, atitle, anumber),
  54.     TWindowInit    (ResponseDevice::initFrame),
  55.     buttons    (makeResponseButton(device))
  56. {
  57.     TRect wbounds = getExtent();        // size of window
  58.     wbounds.grow(-1, -1);            // fit it in window
  59.     subInterior = new ResponseInterior        // make an interior
  60.     (
  61.     virtualBox, wbounds
  62.     );
  63.     if (subInterior)
  64.     insert(subInterior);            // put it in window
  65. }
  66.  
  67.  
  68. /************************************************************************
  69. ** ~ResponseDevice
  70. *************************************************************************/
  71.  
  72. ResponseDevice::~ResponseDevice()
  73. {
  74.     // In Turbo Vision, the interior of the window (pointed to by
  75.     // subInterior), will automatically be deleted.  I doubt this
  76.     // will hold true using Object Windows... check.
  77.  
  78.     if (buttons)
  79.     delete buttons;
  80. }
  81.  
  82.  
  83. /************************************************************************
  84. ** getPalette
  85. *************************************************************************/
  86.  
  87. TPalette&
  88. ResponseDevice::getPalette() const
  89. {
  90.     static TPalette palette(cpRespPalette, sizeof(cpRespPalette)-1);
  91.     return palette;
  92. }
  93.  
  94.  
  95. /************************************************************************
  96. ** startScreen
  97. *************************************************************************/
  98.  
  99. ResponseSet
  100. ResponseDevice::startScreen()
  101. {
  102.     ResponseSet status = RESPONSE_NORMAL;
  103.  
  104.     subInterior->light(RESP_ALL_ON);             // show first display
  105.     if (buttons && (buttons->waitKey() == BOTH_BUTTONS)) // wait for subject
  106.     status = RESPONSE_QUIT;
  107.     subInterior->light(RESP_ALL_OFF);             // turn off all lights
  108.  
  109.     return status;
  110. }
  111.  
  112.  
  113. /************************************************************************
  114. ** Encapsulating routines:
  115. **
  116. **    ResponseDevice::readyLight
  117. **    ResponseDevice::responseOff
  118. **    ResponseDevice::intervalLight
  119. **    ResponseDevice::answerLight
  120. **    ResponseDevice::responseFeedback
  121. **
  122. *************************************************************************/
  123.  
  124. void
  125. ResponseDevice::readyLight ()
  126. {
  127.     subInterior->light(RESP_READY);    // Ready light
  128. }
  129.  
  130.  
  131. void
  132. ResponseDevice::responseOff ()
  133. {
  134.     subInterior->light(RESP_ALL_OFF);
  135. }
  136.  
  137.  
  138. void
  139. ResponseDevice::intervalLight
  140. (
  141.     ushort interval
  142. )
  143. {
  144.     subInterior->light(interval << RESP_INTV_BITS);
  145. }
  146.  
  147.  
  148. void
  149. ResponseDevice::answerLight ()
  150. {
  151.     subInterior->light(RESP_ANSWER);
  152. }
  153.  
  154.  
  155. int
  156. ResponseDevice::responseFeedback
  157. (
  158.     int stimulus
  159. )
  160. {
  161.     int tkey, mask;
  162.  
  163.     subInterior->light(RESP_ANSWER);        // light answer light
  164.     if (buttons)
  165.     tkey = buttons->waitKey();        // wait for subject
  166.     subInterior->light(RESP_ALL_OFF);        // turn off answer light
  167.  
  168.     if (tkey != BOTH_BUTTONS)            // exit button(s)?
  169.     {
  170.     mask = lightMask2AFC(stimulus, tkey);
  171.     subInterior->light(mask);        // light feedback light
  172.     }
  173.     return tkey;
  174. }
  175.  
  176.  
  177. void
  178. ResponseDevice::pause ()
  179. {
  180.     if (buttons)
  181.     (void) buttons->waitKey();        // wait for subject
  182. }
  183.  
  184.  
  185. /************************************************************************
  186. ** lightMask2AFC
  187. **
  188. **    Makes it easy to determine which lights get
  189. ** turned on during a 2AFC task.  It accepts a stimulus code and a
  190. ** response code, and generates the correct mask for turning on the
  191. ** proper combination of lights.  Input values for stimulus and
  192. ** response must be either 1 or 2.
  193. **
  194. *************************************************************************/
  195.  
  196. int
  197. ResponseDevice::lightMask2AFC
  198. (
  199.     int stimulus,                // range: 1 or 2
  200.     int response                // range: 1 or 2
  201. )
  202. {
  203.     int mask;
  204.  
  205.     if
  206.     (
  207.     (stimulus < 1) || (stimulus > 2) ||
  208.     (response < 1) || (response > 2)
  209.     )
  210.     {
  211.     mask = RESP_FAILURE;
  212.     }
  213.     else
  214.     {
  215.     mask = 1 << ((stimulus-1) + (INTERVAL_1-1));
  216.     mask = mask | (1 << ((response-1) + (RESPONSE_1-1)));
  217.     }
  218.     return mask;
  219. }
  220.  
  221.