home *** CD-ROM | disk | FTP | other *** search
- /***************************************************
- HTBMeter.dll
-
- MeterDlg.cpp
-
- Copyright TransEra Corporation 1999
- ***************************************************/
- #include "stdafx.h"
- #include "HTBmeter.h"
- #include "MeterDlg.h"
- #include "DialogThread.h"
- #include <math.h>
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define TIMERVAL 100 // Time timeout value
- #define PI 3.1415926535 // Used in calculating angles and radians
- #define SCALE_ANGLE 45 // Offset Angle
- #define SCALE_MULT 1.5 // Scale multiplier
- #define X_SIZE 158 // X size of dialog box
- #define Y_SIZE 175 // Y size of dialog box
- #define COLOR_MIN 0 // Lowest int value for color definition
- #define COLOR_MAX 255 // Highest int value for color definition
- #define FLT_MULTI 70.0 // Scaling for inputs
- #define HALF 180.0 // Half of a circle [180 degrees]
- #define ORIGIN 0 // Starting point [0]
- #define M_BOX_HEIGHT 100 // Height of outline box containing meter
- #define M_BOX_WIDTH 150 // Width of outline box containing meter
- #define M_TEXT_BOX 120 // Text box which displays values
- #define START_ANGLE 75 // Angle showing boundary of meter
- #define STOP_ANGLE 100 // Angle showing boundary of meter
- #define GREY_COLOR 189 // Integer containing background color element
- #define NEG_LABELX 3 // X position of "-1" on meter face
- #define NEG_LABELY 28 // X position of "-1" on meter face
- #define NEGATIVE_SYMBOL "-1" // Text to be displayed
- #define Z_LABEL_X 72 // X position of "0" on meter face
- #define Z_LABEL_Y 1 // Y position of "0" on meter face
- #define Z_SYMBOL "0" // Text to be displayed
- #define POS_LABELX 130 // X position of "+1" on meter face
- #define POS_LABELY 28 // Y position of "+1" on meter face
- #define POS_SYMBOL "+1" // Text to be displayed
- #define TXT_FRMT_STR1 "X=%d" // Formatting of X CString
- #define TXT_FRMT_STR2 "Y=%d" // Formatting of X CString
- #define TXT_FRMT_STR3 "d=%2.0f" // Formatting of degrees CString
- #define NEEDLE_PTS 3 // How many sides in a triangle?
- #define NEEDLE_LX_POS 72 // Needle base left X position
- #define NEEDLE_WIDTH 6 // Needle thickness at base
- #define X_VAL_T_OUT1 60 // X position of actual degrees value
- #define Y_VAL_T_OUT1 125 // Y position of actual degrees value
- #define X_VAL_T_OUT2 15 // X position of actual "X" value
- #define Y_VAL_T_OUT2 122 // Y position of actual "X" value
- #define X_VAL_T_OUT3 100 // X position of actual "Y" value
- #define Y_VAL_T_OUT3 122 // Y position of actual "Y" value
- #define HASH_MARKX1 75 // X position of Hashmark 1
- #define HASH_MARKY1 15 // Y position of Hashmark 1
- #define HASH_MARKX2 132 // X position of Hashmark 2
- #define HASH_MARKY2 42 // Y position of Hashmark 2
- #define HASH_MARKX3 16 // X position of Hashmark 3
- #define HASH_MARKY3 42 // Y position of Hashmark 3
- #define HMX1 75 // X Start position of hash mark 1
- #define HMY1 23 // Y Start position of hash mark 1
- #define HMX2 126 // X Start position of hash mark 2
- #define HMY2 48 // Y Start position of hash mark 2
- #define HMX3 22 // X Start position of hash mark 3
- #define HMY3 48 // Y Start position of hash mark 3
-
- MeterDlg::MeterDlg(CWnd* pParent /*=NULL*/)
- : CDialog(MeterDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(MeterDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
-
- void MeterDlg::DoDataExchange(CDataExchange* pDX)
- {
-
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(MeterDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(MeterDlg, CDialog)
- //{{AFX_MSG_MAP(MeterDlg)
- ON_WM_PAINT()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: MeterDlg::OnInitDialog
-
- Description: Initializes the Dialog box window
-
- Return type: BOOL
-
- Notes: This function sets all of the attributes
- in the dialog box window before it is
- created.
-
- */
- BOOL MeterDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- SetWindowPos(FromHandle(m_hWnd), g_Xpos, g_Ypos, X_SIZE, Y_SIZE, SWP_NOZORDER);
- SetTimer(1,TIMERVAL,NULL);
- return TRUE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: MeterDlg::OnPaint
-
- Description: Paints data onto dialog box window
-
- Return type: void
-
- Notes: Paints the needle, hash marks, box and text,
- all in real-time as it is recieved from HTBasic.
- Some complicated computations take place within
- this function.
-
- */
- void MeterDlg::OnPaint()
- {
- CPaintDC dc(this);
- CString sNumOut, sXout, sYout;
- CBrush RedColor (RGB(COLOR_MAX, COLOR_MIN, COLOR_MIN)); // Color of needle
- double Yres = 0; // Y resolution
- double Xres = 0; // X resolution
- int iXpos, iYpos;
- double dDegVal = 0; // degrees
- float Multiplier = FLT_MULTI; // Scaling Multiplier
-
- dDegVal = (*g_pBasicVar) * SCALE_MULT + SCALE_ANGLE;
- Xres = Multiplier*((cos(dDegVal*PI/HALF))); // X Degrees-> X Radians -> X degrees
- Yres = Multiplier*((sin(dDegVal*PI/HALF))); // Y Degrees-> Y Radians -> Y degrees
- iXpos = START_ANGLE - (int) Xres;
- iYpos = STOP_ANGLE - (int) Yres;
- POINT aPoint = { ORIGIN, M_BOX_HEIGHT };
- POINT bPoint = { M_BOX_WIDTH, M_BOX_HEIGHT };
- POINT cPoint = { M_BOX_WIDTH, ORIGIN };
- POINT dPoint = { ORIGIN,ORIGIN };
- POINT ePoint = { ORIGIN, M_TEXT_BOX };
- POINT fPoint = { M_BOX_WIDTH, M_TEXT_BOX };
- POINT gPoint = { M_BOX_WIDTH, M_BOX_HEIGHT };
- POINT h1 = { HASH_MARKX1, HASH_MARKY1 };
- POINT h2 = { HASH_MARKX2, HASH_MARKY2 };
- POINT h3 = { HASH_MARKX3, HASH_MARKY3 };
- POINT needle[NEEDLE_PTS] = {NEEDLE_LX_POS,M_BOX_HEIGHT, iXpos, iYpos,
- (NEEDLE_LX_POS + NEEDLE_WIDTH), M_BOX_HEIGHT };
- // Start Draw Box and hash marks //
- dc.MoveTo(ORIGIN, ORIGIN);
- dc.LineTo(aPoint);
- dc.LineTo(bPoint);
- dc.LineTo(cPoint);
- dc.LineTo(dPoint);
- dc.LineTo(ePoint);
- dc.LineTo(fPoint);
- dc.LineTo(gPoint);
- dc.MoveTo(HMX1, HMY1);
- dc.LineTo(h1);
- dc.MoveTo(HMX2,HMY2);
- dc.LineTo(h2);
- dc.MoveTo(HMX3, HMY3);
- dc.LineTo(h3);
- // end box and hash marks
- dc.SetBkColor(RGB(GREY_COLOR, GREY_COLOR, GREY_COLOR));
- dc.TextOut(NEG_LABELX, NEG_LABELY, NEGATIVE_SYMBOL);
- dc.TextOut(Z_LABEL_X, Z_LABEL_Y, Z_SYMBOL);
- dc.TextOut(POS_LABELX, POS_LABELY, POS_SYMBOL);
- sXout.Format(_T(TXT_FRMT_STR1), iXpos);
- sYout.Format(_T(TXT_FRMT_STR2), iYpos);
- sNumOut.Format(_T(TXT_FRMT_STR3), dDegVal);
- dc.SelectObject(&RedColor);
- dc.Polygon(needle, NEEDLE_PTS);
- dc.TextOut(X_VAL_T_OUT1, Y_VAL_T_OUT1, sNumOut);
- dc.TextOut(X_VAL_T_OUT2, Y_VAL_T_OUT2, sXout);
- dc.TextOut(X_VAL_T_OUT3, Y_VAL_T_OUT3, sYout);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: MeterDlg::OnTimer
-
- Description: This is what happens when the timer strobes
-
- Return type: void
- Argument: UINT nIDEvent
-
- Notes: When the timer fires, the dialog box window is invalidated.
- that is, it updates everything and the nre-paints it by
- calling the OnPaint() over and over until basic tells it to
- quit.
- */
- void MeterDlg::OnTimer(UINT nIDEvent)
- {
- Invalidate();
- CDialog::OnTimer(nIDEvent);
- }
-