home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBMeter / MeterDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  7.4 KB  |  211 lines

  1. /***************************************************
  2. HTBMeter.dll
  3.  
  4. MeterDlg.cpp
  5.  
  6. Copyright TransEra Corporation 1999 
  7. ***************************************************/
  8. #include "stdafx.h"
  9. #include "HTBmeter.h"
  10. #include "MeterDlg.h"
  11. #include "DialogThread.h"
  12. #include <math.h>
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. #define TIMERVAL        100                // Time timeout value
  21. #define PI                3.1415926535    // Used in calculating angles and radians    
  22. #define    SCALE_ANGLE        45                // Offset Angle
  23. #define    SCALE_MULT        1.5                // Scale multiplier
  24. #define X_SIZE            158                // X size of dialog box
  25. #define Y_SIZE            175                // Y size of dialog box
  26. #define COLOR_MIN        0                // Lowest int value for color definition
  27. #define COLOR_MAX        255                // Highest int value for color definition
  28. #define FLT_MULTI        70.0            // Scaling for inputs 
  29. #define HALF            180.0            // Half of a circle [180 degrees]
  30. #define ORIGIN            0                // Starting point [0]
  31. #define M_BOX_HEIGHT    100                // Height of outline box containing meter
  32. #define M_BOX_WIDTH        150                // Width of outline box containing meter
  33. #define M_TEXT_BOX        120                // Text box which displays values
  34. #define START_ANGLE        75                // Angle showing boundary of meter
  35. #define STOP_ANGLE        100                // Angle showing boundary of meter    
  36. #define GREY_COLOR        189                // Integer containing background color element
  37. #define NEG_LABELX        3                // X position of "-1" on meter face
  38. #define NEG_LABELY        28                // X position of "-1" on meter face
  39. #define NEGATIVE_SYMBOL    "-1"            // Text to be displayed
  40. #define Z_LABEL_X        72                // X position of "0" on meter face
  41. #define Z_LABEL_Y        1                // Y position of "0" on meter face
  42. #define Z_SYMBOL        "0"                // Text to be displayed
  43. #define POS_LABELX        130                // X position of "+1" on meter face
  44. #define POS_LABELY        28                // Y position of "+1" on meter face    
  45. #define POS_SYMBOL        "+1"            // Text to be displayed
  46. #define TXT_FRMT_STR1    "X=%d"            // Formatting of X CString 
  47. #define TXT_FRMT_STR2    "Y=%d"            // Formatting of X CString
  48. #define TXT_FRMT_STR3    "d=%2.0f"        // Formatting of degrees CString
  49. #define NEEDLE_PTS        3                // How many sides in a triangle?
  50. #define NEEDLE_LX_POS    72                // Needle base left X position
  51. #define NEEDLE_WIDTH    6                // Needle thickness at base    
  52. #define X_VAL_T_OUT1    60                // X position of actual degrees value
  53. #define Y_VAL_T_OUT1    125                // Y position of actual degrees value
  54. #define X_VAL_T_OUT2    15                // X position of actual "X" value
  55. #define Y_VAL_T_OUT2    122                // Y position of actual "X" value
  56. #define X_VAL_T_OUT3    100                // X position of actual "Y" value
  57. #define Y_VAL_T_OUT3    122                // Y position of actual "Y" value
  58. #define HASH_MARKX1        75                // X position of Hashmark 1
  59. #define HASH_MARKY1        15                // Y position of Hashmark 1
  60. #define HASH_MARKX2        132                // X position of Hashmark 2
  61. #define HASH_MARKY2        42                // Y position of Hashmark 2
  62. #define HASH_MARKX3        16                // X position of Hashmark 3    
  63. #define HASH_MARKY3        42                // Y position of Hashmark 3
  64. #define HMX1            75                // X Start position of hash mark 1
  65. #define HMY1            23                // Y Start position of hash mark 1
  66. #define HMX2            126                // X Start position of hash mark 2    
  67. #define HMY2            48                // Y Start position of hash mark 2
  68. #define HMX3            22                // X Start position of hash mark 3    
  69. #define HMY3            48                // Y Start position of hash mark 3
  70.  
  71. MeterDlg::MeterDlg(CWnd* pParent /*=NULL*/)
  72.     : CDialog(MeterDlg::IDD, pParent) 
  73. {
  74.     //{{AFX_DATA_INIT(MeterDlg)
  75.         // NOTE: the ClassWizard will add member initialization here
  76.     //}}AFX_DATA_INIT
  77. }
  78.  
  79. void MeterDlg::DoDataExchange(CDataExchange* pDX) 
  80. {
  81.     
  82.     CDialog::DoDataExchange(pDX);
  83.     //{{AFX_DATA_MAP(MeterDlg)
  84.         // NOTE: the ClassWizard will add DDX and DDV calls here
  85.     //}}AFX_DATA_MAP
  86. }
  87.  
  88.  
  89. BEGIN_MESSAGE_MAP(MeterDlg, CDialog)
  90.     //{{AFX_MSG_MAP(MeterDlg)
  91.     ON_WM_PAINT()
  92.     ON_WM_TIMER()
  93.     //}}AFX_MSG_MAP
  94. END_MESSAGE_MAP()
  95.  
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. /*
  99.     Function:        MeterDlg::OnInitDialog
  100.  
  101.     Description:    Initializes the Dialog box window
  102.  
  103.     Return type:    BOOL 
  104.  
  105.     Notes:            This function sets all of the attributes 
  106.                     in the dialog box window  before it is 
  107.                     created.
  108.         
  109. */
  110. BOOL MeterDlg::OnInitDialog()  
  111. {
  112.     CDialog::OnInitDialog();    
  113.     SetWindowPos(FromHandle(m_hWnd), g_Xpos, g_Ypos, X_SIZE, Y_SIZE, SWP_NOZORDER);
  114.     SetTimer(1,TIMERVAL,NULL);            
  115.     return TRUE;  
  116. }
  117.  
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120. /*
  121.     Function:        MeterDlg::OnPaint
  122.  
  123.     Description:    Paints data onto dialog box window
  124.  
  125.     Return type:    void 
  126.  
  127.     Notes:            Paints the needle, hash marks, box and text,
  128.                     all in real-time as it is recieved from HTBasic.
  129.                     Some complicated computations take place within 
  130.                     this function.    
  131.         
  132. */
  133. void MeterDlg::OnPaint()  
  134. {
  135.     CPaintDC dc(this); 
  136.     CString sNumOut, sXout, sYout;
  137.     CBrush RedColor        (RGB(COLOR_MAX, COLOR_MIN, COLOR_MIN));        // Color of needle
  138.     double Yres = 0;                                                // Y resolution
  139.     double Xres = 0;                                                // X resolution
  140.     int iXpos, iYpos; 
  141.     double dDegVal = 0;                                                // degrees
  142.     float Multiplier = FLT_MULTI;                                    // Scaling Multiplier
  143.  
  144.     dDegVal = (*g_pBasicVar) * SCALE_MULT + SCALE_ANGLE;        
  145.     Xres = Multiplier*((cos(dDegVal*PI/HALF)));                        // X Degrees-> X Radians -> X degrees
  146.     Yres = Multiplier*((sin(dDegVal*PI/HALF)));                        // Y Degrees-> Y Radians -> Y degrees
  147.     iXpos = START_ANGLE  - (int) Xres;
  148.     iYpos = STOP_ANGLE - (int) Yres;
  149.     POINT aPoint = { ORIGIN, M_BOX_HEIGHT };
  150.     POINT bPoint = { M_BOX_WIDTH, M_BOX_HEIGHT };
  151.     POINT cPoint = { M_BOX_WIDTH, ORIGIN };
  152.     POINT dPoint = { ORIGIN,ORIGIN };
  153.     POINT ePoint = { ORIGIN, M_TEXT_BOX };
  154.     POINT fPoint = { M_BOX_WIDTH, M_TEXT_BOX };
  155.     POINT gPoint = { M_BOX_WIDTH, M_BOX_HEIGHT };
  156.     POINT h1 = { HASH_MARKX1, HASH_MARKY1 };
  157.     POINT h2 = { HASH_MARKX2, HASH_MARKY2 };
  158.     POINT h3 = { HASH_MARKX3, HASH_MARKY3 };
  159.     POINT needle[NEEDLE_PTS] = {NEEDLE_LX_POS,M_BOX_HEIGHT, iXpos, iYpos,
  160.                 (NEEDLE_LX_POS + NEEDLE_WIDTH), M_BOX_HEIGHT };
  161.     // Start Draw Box and hash marks  //
  162.     dc.MoveTo(ORIGIN, ORIGIN);
  163.     dc.LineTo(aPoint);
  164.     dc.LineTo(bPoint);
  165.     dc.LineTo(cPoint);
  166.     dc.LineTo(dPoint);
  167.     dc.LineTo(ePoint);
  168.     dc.LineTo(fPoint);
  169.     dc.LineTo(gPoint);
  170.     dc.MoveTo(HMX1, HMY1);
  171.     dc.LineTo(h1);
  172.     dc.MoveTo(HMX2,HMY2);
  173.     dc.LineTo(h2);
  174.     dc.MoveTo(HMX3, HMY3);
  175.     dc.LineTo(h3);
  176.     // end box and hash marks 
  177.     dc.SetBkColor(RGB(GREY_COLOR, GREY_COLOR, GREY_COLOR));
  178.     dc.TextOut(NEG_LABELX, NEG_LABELY, NEGATIVE_SYMBOL);
  179.     dc.TextOut(Z_LABEL_X, Z_LABEL_Y, Z_SYMBOL);
  180.     dc.TextOut(POS_LABELX, POS_LABELY, POS_SYMBOL);
  181.     sXout.Format(_T(TXT_FRMT_STR1), iXpos);
  182.     sYout.Format(_T(TXT_FRMT_STR2), iYpos);
  183.     sNumOut.Format(_T(TXT_FRMT_STR3), dDegVal);    
  184.     dc.SelectObject(&RedColor);
  185.     dc.Polygon(needle, NEEDLE_PTS);    
  186.     dc.TextOut(X_VAL_T_OUT1, Y_VAL_T_OUT1, sNumOut);
  187.     dc.TextOut(X_VAL_T_OUT2, Y_VAL_T_OUT2, sXout);
  188.     dc.TextOut(X_VAL_T_OUT3, Y_VAL_T_OUT3, sYout); 
  189. }
  190.  
  191.  
  192. /////////////////////////////////////////////////////////////////////////////
  193. /*
  194.     Function:        MeterDlg::OnTimer
  195.  
  196.     Description:    This is what happens when the timer strobes
  197.  
  198.     Return type:    void 
  199.     Argument:        UINT nIDEvent
  200.  
  201.     Notes:            When the timer fires, the dialog box window is invalidated.
  202.                     that is, it updates everything and the nre-paints it by 
  203.                     calling the  OnPaint() over and over until basic tells it to
  204.                     quit.
  205. */
  206. void MeterDlg::OnTimer(UINT nIDEvent)  
  207. {    
  208.     Invalidate();    
  209.     CDialog::OnTimer(nIDEvent);
  210. }
  211.