home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FACETV.ZIP / TINPMOUS.H < prev    next >
C/C++ Source or Header  |  1993-12-09  |  5KB  |  188 lines

  1. /************************************************************************
  2. **
  3. ** @(#)tinpmous.h    05/27/92    Chris Ahlstrom
  4. **
  5. ** C++ version
  6. **
  7. **    Contains, at present, an interface to the menu fields.
  8. ** Added support for byte-sized radio-buttons and check-boxes.
  9. **
  10. *************************************************************************/
  11.  
  12. #if !defined(TINPMOUS_h)                // { TINPMOUS_h
  13. #define TINPMOUS_h
  14.  
  15. #include "tinput.h"                // for TInputXXX classes
  16. #include "tv_menu.h"                // for Range declaration
  17.  
  18.  
  19.  
  20. /************************************************************************
  21. ** MouseButton
  22. **
  23. **    Reflects the possible states (statuses) of the buttons on the
  24. ** mouse.  Each button on the mouse is represented by a bit.  If the
  25. ** bit is set, then the button was down at the time the status of
  26. ** the buttons was obtained.
  27. **
  28. *************************************************************************/
  29.  
  30. typedef enum
  31. {
  32.     NO_MOUSE_BUTTON    = 0x00,
  33.     LEFT_MOUSE_BUTTON    = 0x01,
  34.     RIGHT_MOUSE_BUTTON    = 0x02,
  35.     BOTH_MOUSE_BUTTONS    = 0x03,
  36.     CENTER_MOUSE_BUTTON    = 0x04
  37.  
  38. } MouseButton;
  39.  
  40.  
  41.  
  42. /***********************************************************************
  43. ** TInputFloatControl
  44. **
  45. **    Class for control of numeric variables using the mouse
  46. ** and the up/down arrows on the PC keyboard.
  47. **
  48. ************************************************************************/
  49.  
  50. class TInputFloatControl : public TInputFloat
  51. {
  52.  
  53. public:                // base class functions & overrides
  54.  
  55.     TInputFloatControl        // constructor
  56.     (
  57.     const TRect& bounds,    // rectangle for Float's input-line
  58.     int fmaxLen,        // maximum length to use for buffer
  59.     const Range& code,    // range of internal representation
  60.     char *formatstring,    // desired display format
  61.     int mapped,        // should remapping be performed?
  62.     const Range& user,    // range of user's representation
  63.     int exponential,    // 1=using exponential mapping
  64.     int maxmickey,        // highest mouse changes we support
  65.     int maxkey,        // highest key changes we support
  66.     CtrlFunction ctrlf    // function to use for control
  67.     );
  68.     // ~TInputFloatControl();
  69.  
  70.     virtual void handleEvent(TEvent& event);    // override for mouse handling
  71.  
  72. protected:            // base class function
  73.  
  74.     TInputFloatControl( StreamableInit ) : TInputFloat( streamableInit ) {};
  75.  
  76. public:                // base class pointer
  77.  
  78.     static const char * const name;
  79.  
  80. private:            // functions not provided by base class
  81.  
  82.     void setupMouseMapping    // make equation for mouse<-->user conversions
  83.     (
  84.     void
  85.     );
  86.     void setupKeyMapping    // make equation for key<-->user conversions
  87.     (
  88.     void
  89.     );
  90.     double userMouseMapping    // convert mouse y-value to user range
  91.     (
  92.     int mousevalue        // current value of mouse y-mickey
  93.     );
  94.     double userKeyMapping    // convert key value to user range
  95.     (
  96.     int keyvalue        // current value of key counter
  97.     );
  98.     int mouseMapping        // convert user value to mouse range
  99.     (
  100.     double uservalue    // value of numeric field
  101.     );
  102.     int keyMapping        // convert user value to key range
  103.     (
  104.     double uservalue    // value of the numeric field
  105.     );
  106.     double handleKeyControl    // handle the keystroke properly
  107.     (
  108.     int key            // the keystroke (up or down arrow)
  109.     );
  110.     double handleMouseControl
  111.     (
  112.     void
  113.     );
  114.     int mouseCorrect
  115.     (
  116.     int ypos
  117.     );
  118.  
  119. private:            // utility functions for mappings
  120.  
  121.     double userMouseLinear
  122.     (
  123.     double mousevalue
  124.     );
  125.     double userMouseExp
  126.     (
  127.     double mousevalue
  128.     );
  129.     double userKeyLinear
  130.     (
  131.     double keyvalue
  132.     );
  133.     double userKeyExp
  134.     (
  135.     double keyvalue
  136.     );
  137.     double mouseLinear
  138.     (
  139.     double uservalue
  140.     );
  141.     double mouseExp
  142.     (
  143.     double uservalue
  144.     );
  145.     double keyLinear
  146.     (
  147.     double uservalue
  148.     );
  149.     double keyExp
  150.     (
  151.     double uservalue
  152.     );
  153.  
  154. private:            // parameters of the mapping
  155.  
  156.     MapType mouseKeyMap;    // is mapping linear or exponential?
  157.  
  158.     int mouseMin;        // minimum y-value of mouse [  0]
  159.     int mouseMax;        // minimum y-value of mouse [  0]
  160.     double mouseSlope;        // slope used in mapping equation
  161.  
  162.     int keyMin;            // minimum y-value of key [  0]
  163.     int keyMax;            // minimum y-value of key [  0]
  164.     double keySlope;        // slope used in mapping equation
  165.  
  166.     double userMin;        // maximum value of user-variable
  167.     double userMax;        // maximum value of user-variable
  168.  
  169.     CtrlFunction userControl;    // function to use values on
  170.  
  171. private:            // values of our mapped variables
  172.  
  173.     int yMouse;            // current value of mouse cursor
  174.     int yMouseOld;        // previous value of mouse cursor
  175.     int yKey;            // current value of key count
  176.     int yKeyOld;        // previous value of key count
  177.     double oldValue;        // original value of user variable
  178.  
  179. private:
  180.  
  181.     int inControl;        // set to 1 if mouse/keys are in control
  182.  
  183. };
  184.  
  185.  
  186. #endif                            // } TINPMOUS_h
  187.  
  188.