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

  1. /************************************************************************
  2. **
  3. ** @(#)tinpextd.h    06/09/93    Chris Ahlstrom
  4. **
  5. ** C++
  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(TINPEXTD_h)                // { TINPEXTD_h
  13. #define TINPEXTD_h
  14.  
  15.  
  16. #if !defined(Uses_TInputLine)            // { Uses_TInputLine
  17. #define Uses_TEvent
  18. #define Uses_TInputLine
  19. #define Uses_TKeys
  20. #define Uses_TRect
  21. #define Uses_TStreamable
  22. #define Uses_TStreamableClass
  23. #include <tv.h>                    // Turbo Vision declarations
  24. #endif                        // } Uses_TInputLine
  25.  
  26. #include "tv_menu.h"                // for Range declaration
  27.  
  28.  
  29. /***********************************************************************
  30. ** TExtended
  31. **
  32. **    This class is a minor extension of TInputLine designed to
  33. ** serve as a base class for numeric data types that we want to
  34. ** map.
  35. **
  36. **    It is an abstract base class, since two functions are pure
  37. ** virtual.
  38. **
  39. ************************************************************************/
  40.  
  41. #define TINPUT_NO_EXTENDED    0
  42. #define TINPUT_EXTENDED        1
  43.  
  44. class TExtended : public TInputLine
  45. {
  46.  
  47. public:
  48.  
  49.     TExtended
  50.     (
  51.     const TRect& bounds,
  52.     int aMaxLen,
  53.     const Range& code,
  54.     char *formatstring,
  55.     int mapped,
  56.     const Range& user
  57.     );
  58.  
  59.     //~TExtended();
  60.  
  61.     virtual void handleEvent(TEvent& event);    // override for mouse handling
  62.  
  63.     virtual void mapToUser();        // change to user units
  64.     virtual void mapToCode();        // change to code units
  65.     virtual double getValue() = 0;    // get current value (byte, long...)
  66.     virtual void putValue(double) = 0;    // put current value back
  67.     virtual void updateValue() = 0;    // redisplay current value
  68.  
  69. protected:
  70.  
  71.     TExtended( StreamableInit ) : TInputLine( streamableInit ) {};
  72.  
  73. protected:            // code for remapping the displayed values
  74.  
  75.     int useMap;                // 1 if the mapping is to be used
  76.     double codeValue;            // current value in internal scale
  77.     double codeMin;            // minimum value in internal scale
  78.     double codeMax;            // maximum value in internal scale
  79.     double userValue;            // current value in user's scale
  80.     double userMin;            // minimum value in user's scale
  81.     double userMax;            // maximum value in user's scale
  82.  
  83. public:                // base class pointer
  84.  
  85.     static const char * const name;
  86.  
  87. private:            // functions not provided by base class
  88.  
  89.     void setupMouseMapping    // make equation for mouse<-->user conversions
  90.     (
  91.     double min,
  92.     double max
  93.     );
  94.     void setupKeyMapping    // make equation for key<-->user conversions
  95.     (
  96.     double min,
  97.     double max
  98.     );
  99.     double userMouseMapping    // convert mouse y-value to user range
  100.     (
  101.     int mousevalue        // current value of mouse y-mickey
  102.     );
  103.     double userKeyMapping    // convert key value to user range
  104.     (
  105.     int keyvalue        // current value of key counter
  106.     );
  107.     int mouseMapping        // convert user value to mouse range
  108.     (
  109.     double uservalue    // value of numeric field
  110.     );
  111.     int keyMapping        // convert user value to key range
  112.     (
  113.     double uservalue    // value of the numeric field
  114.     );
  115.     void handleKeyControl    // handle the keystroke properly
  116.     (
  117.     int key            // the keystroke (up or down arrow)
  118.     );
  119.     void handleMouseControl
  120.     (
  121.     void
  122.     );
  123.     int mouseCorrect
  124.     (
  125.     int ypos
  126.     );
  127.  
  128. private:            // parameters of the mapping
  129.  
  130.     int mouseMin;        // minimum y-value of mouse [  0]
  131.     int mouseMax;        // minimum y-value of mouse [  0]
  132.     double muserMin;        // mouse's user-minimum
  133.     double muserMax;        // mouse's user-maximum
  134.     double mouseSlope;        // slope used in mapping equation
  135.  
  136.     int keyMin;            // minimum y-value of key [  0]
  137.     int keyMax;            // minimum y-value of key [  0]
  138.     double kuserMin;        // key's user-minimum
  139.     double kuserMax;        // key's user-maximum
  140.     double keySlope;        // slope used in mapping equation
  141.  
  142. private:            // values of our mapped variables
  143.  
  144.     int yMouse;            // current value of mouse cursor
  145.     int yMouseOld;        // previous value of mouse cursor
  146.     int yKey;            // current value of key count
  147.     int yKeyOld;        // previous value of key count
  148.     double oldValue;        // original value of user variable
  149.  
  150. private:
  151.  
  152.     int inControl;        // set to 1 if mouse/keys are in control
  153.  
  154. };
  155.  
  156.  
  157.  
  158.  
  159. #endif                            // } TINPEXTD_h
  160.  
  161.