home *** CD-ROM | disk | FTP | other *** search
- /***************************************
- HTBKnob.dll
-
- KnobDlg.cpp
-
- Copyright TransEra Corporation 1999
- ***************************************/
- #include "stdafx.h"
- #include "HTBknob.h"
- #include "KnobDlg.h"
- #include <math.h>
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define TIMERVAL 100 // Timer timeout value
- #define POS1_X 125 // Needle position 1 X value
- #define POS1_Y 35 // Needle position 1 Y value
- #define POS2_X 165 // Needle position 2 X value
- #define POS2_Y 75 // Needle position 2 Y value
- #define POS3_X 165 // Needle position 3 X value
- #define POS3_Y 125 // Needle position 3 Y value
- #define POS4_X 125 // Needle position 4 X value
- #define POS4_Y 165 // Needle position 4 Y value
- #define POS5_X 75 // Needle position 5 X value
- #define POS5_Y 165 // Needle position 5 Y value
- #define POS6_X 35 // Needle position 6 X value
- #define POS6_Y 125 // Needle position 6 Y value
- #define POS7_X 35 // Needle position 7 X value
- #define POS7_Y 75 // Needle position 7 Y value
- #define POS8_X 75 // Needle position 8 X value
- #define POS8_Y 35 // Needle position 8 Y value
- #define POS1_OUT 1 // Knob position number 1
- #define POS2_OUT 2 // Knob position number 2
- #define POS3_OUT 3 // Knob position number 3
- #define POS4_OUT 4 // Knob position number 4
- #define POS5_OUT 5 // Knob position number 5
- #define POS6_OUT 6 // Knob position number 6
- #define POS7_OUT 7 // Knob position number 7
- #define POS8_OUT 8 // Knob position number 8
- #define GREY_COLOR 189 // Back ground color
- #define COLOR_MAX 255 // Max color element value
- #define COLOR_MIN 0 // Min color element value
- #define CIRC_TL 30 // Top left circle element
- #define CIRC_LR 170 // Lower right circle element
- #define NEEDLE_SIDES 3 // A triangle has how many sides?
- #define FONT_SIZE 150 // Size of the display font
- #define FONT_TYPE "Arial" // Font Name
- #define DLG_X_SIZE 210 // Dialog box width
- #define DLG_Y_SIZE 270 // Dialog Box height
- #define POS_FMT_STR "Setting=%d"// Position Text formatting string
- #define OUT_TEXT_1X 125 // X position of "1"
- #define OUT_TEXT_1Y 15 // Y position of "1"
- #define OUT_TEXT_1VAL "1" // Display symbol "1"
- #define OUT_TEXT_2X 167 // X position of "2"
- #define OUT_TEXT_2Y 60 // Y position of "2"
- #define OUT_TEXT_2VAL "2" // Display symbol "2"
- #define OUT_TEXT_3X 167 // X position of "3"
- #define OUT_TEXT_3Y 120 // Y position of "3"
- #define OUT_TEXT_3VAL "3" // Display symbol "3"
- #define OUT_TEXT_4X 125 // X position of "4"
- #define OUT_TEXT_4Y 165 // Y position of "4"
- #define OUT_TEXT_4VAL "4" // Display symbol "4"
- #define OUT_TEXT_5X 60 // X position of "5"
- #define OUT_TEXT_5Y 165 // Y position of "5"
- #define OUT_TEXT_5VAL "5" // Display symbol "5"
- #define OUT_TEXT_6X 20 // X position of "6"
- #define OUT_TEXT_6Y 120 // Y position of "6"
- #define OUT_TEXT_6VAL "6" // Display symbol "6"
- #define OUT_TEXT_7X 20 // X position of "7"
- #define OUT_TEXT_7Y 60 // Y position of "7"
- #define OUT_TEXT_7VAL "7" // Display symbol "7"
- #define OUT_TEXT_8X 60 // X position of "8"
- #define OUT_TEXT_8Y 15 // Y position of "8"
- #define OUT_TEXT_8VAL "8" // Display symbol "8"
- #define OUT_VALX 60 // X position of Knob Value
- #define OUT_VALY 200 // Y position of Knob Value
- #define BOUND_POS_1 20 // Boundary Position 1
- #define BOUND_POS_2 50 // Boundary Position 2
- #define BOUND_POS_3 60 // Boundary Position 3
- #define BOUND_POS_4 90 // Boundary Position 4
- #define BOUND_POS_5 110 // Boundary Position 5
- #define BOUND_POS_6 140 // Boundary Position 6
- #define BOUND_POS_7 150 // Boundary Position 7
- #define BOUND_POS_8 180 // Boundary Position 8
- #define NDL_BSE_POS1 91 // Needle Nase position 1
- #define NDL_BSE_POS2 97 // Needle Nase position 2
- #define NDL_BSE_POS3 103 // Needle Nase position 3
- #define NDL_BSE_POS4 109 // Needle Nase position 4
- #define STRT_DGRS 23 // Starting degrees
-
- int iXPos = 0; // Mouse click X position
- int iYPos = 0; // Mouse click Y position
-
- int iXval = POS1_X; // Needle Position variable X
- int iYval = POS1_Y; // Needle Position variable Y
- int iNdeg = STRT_DGRS; // Degree value for point of needle
- int ilbx = NDL_BSE_POS1; // X posistion of Needle left side base
- int ilby = NDL_BSE_POS2; // Y posistion of Needle left side base
- int irbx = NDL_BSE_POS4; // X posistion of Needle right side base
- int irby = NDL_BSE_POS3; // Y posistion of Needle right side base
-
- short sOutText = POS1_OUT;
-
- CPoint m_Point;
-
- KnobDlg::KnobDlg(CWnd* pParent /*=NULL*/)
- : CDialog(KnobDlg::IDD, pParent) {
- //{{AFX_DATA_INIT(KnobDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
-
-
- void KnobDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(KnobDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(KnobDlg, CDialog)
- //{{AFX_MSG_MAP(KnobDlg)
- ON_WM_PAINT()
- ON_WM_TIMER()
- ON_WM_LBUTTONDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: KnobDlg::OnInitDialog
-
- Description: Initializes window position and attributes
-
- Return type: BOOL
-
- Notes: Starts timer and sets all of the values as characteristics
- from HTBasic.
-
- */
- BOOL KnobDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- SetWindowPos(FromHandle(m_hWnd), g_Xpos, g_Ypos,
- DLG_X_SIZE, DLG_Y_SIZE, SWP_NOZORDER );
- SetTimer(1,TIMERVAL,NULL);
- return TRUE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: KnobDlg::OnPaint
-
- Description: Paints shapes, lines and colors onto dialog window
-
- Return type: void
-
- Notes: The actual "painting" is done within this function
- while some computations are done to position the
- needle in the correct place.
-
- */
- void KnobDlg::OnPaint()
- {
- CString Disp;
- CFont font;
- CPaintDC dc(this);
-
- CBrush grey (RGB(GREY_COLOR, GREY_COLOR, GREY_COLOR));
- CBrush red (RGB(COLOR_MAX, COLOR_MIN, COLOR_MIN));
- dc.SelectObject(&grey);
- dc.Ellipse(CIRC_TL, CIRC_TL, CIRC_LR, CIRC_LR);
-
- POINT needle[NEEDLE_SIDES] = {ilbx, ilby ,irbx , irby ,iXval, iYval};
- dc.SelectObject(&red);
- dc.Polygon(needle, NEEDLE_SIDES);
- Disp.Format(POS_FMT_STR, sOutText);
- font.CreatePointFont(FONT_SIZE,_T(FONT_TYPE));
- dc.SelectObject(&font);
- dc.SetBkMode(TRANSPARENT);
- dc.TextOut(OUT_VALX,OUT_VALY, Disp);
- dc.TextOut(OUT_TEXT_1X, OUT_TEXT_1Y, OUT_TEXT_1VAL);
- dc.TextOut(OUT_TEXT_2X, OUT_TEXT_2Y, OUT_TEXT_2VAL);
- dc.TextOut(OUT_TEXT_3X, OUT_TEXT_3Y, OUT_TEXT_3VAL);
- dc.TextOut(OUT_TEXT_4X, OUT_TEXT_4Y, OUT_TEXT_4VAL);
- dc.TextOut(OUT_TEXT_5X, OUT_TEXT_5Y, OUT_TEXT_5VAL);
- dc.TextOut(OUT_TEXT_6X, OUT_TEXT_6Y, OUT_TEXT_6VAL);
- dc.TextOut(OUT_TEXT_7X, OUT_TEXT_7Y, OUT_TEXT_7VAL);
- dc.TextOut(OUT_TEXT_8X, OUT_TEXT_8Y, OUT_TEXT_8VAL);
-
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: KnobDlg::OnTimer
-
- Description: Updates and tracks Dialog window
-
- Return type: void
- Argument: UINT nIDEvent
-
- Notes: This function makes the visual display move or update
- based on teh invalidation.
-
- */
- void KnobDlg::OnTimer(UINT nIDEvent)
- {
- Invalidate();
- CDialog::OnTimer(nIDEvent);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: KnobDlg::OnLButtonDown
-
- Description: takes input from the mouse.
-
- Return type: void
- Argument: UINT nFlags
- Argument: CPoint point
-
- Notes: when the mouse is clicked in a certain area. This function
- takes those X and Y coordinates and decides if they are within
- the area of all of the different values on the knob. if they are
- it moves the needle there and then sends a message back to HTBasic
- to change the value inb that pointer.
-
- */
- void KnobDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
-
- m_Point = point;
- iXPos = m_Point.x;
- iYPos = m_Point.y; //swing
-
- if (iXPos > BOUND_POS_5 && iXPos < BOUND_POS_6 && iYPos > BOUND_POS_1 && iYPos < BOUND_POS_2)
- { // Position 1
- iXval = POS1_X;
- iYval = POS1_Y;
- ilbx = NDL_BSE_POS1;
- ilby = NDL_BSE_POS2;
- irbx = NDL_BSE_POS4;
- irby = NDL_BSE_POS3;
- sOutText = POS1_OUT;
- *RetVal = sOutText;
- }
- if (iXPos > BOUND_POS_7 && iXPos < BOUND_POS_8 && iYPos > BOUND_POS_3 && iYPos < BOUND_POS_4)
- { // Position 2
- iXval = POS2_X;
- iYval = POS2_Y;
- ilbx = NDL_BSE_POS2;
- ilby = NDL_BSE_POS1;
- irbx = NDL_BSE_POS3;
- irby = NDL_BSE_POS4;
- sOutText = POS2_OUT;
- *RetVal = sOutText;
- }
- if (iXPos > BOUND_POS_7 && iXPos < BOUND_POS_8 && iYPos > BOUND_POS_5 && iYPos < BOUND_POS_6)
- { // Position 3
- iXval = POS3_X;
- iYval = POS3_Y;
- ilbx = NDL_BSE_POS3;
- ilby = NDL_BSE_POS1;
- irbx = NDL_BSE_POS2;
- irby = NDL_BSE_POS4;
- sOutText = POS3_OUT;
- * RetVal = sOutText;
- }
- if (iXPos > BOUND_POS_5 && iXPos < BOUND_POS_6 && iYPos > BOUND_POS_7 && iYPos < BOUND_POS_8)
- { // Position 4
- iXval = POS4_X;
- iYval = POS4_Y;
- ilbx = NDL_BSE_POS4;
- ilby = NDL_BSE_POS2;
- irbx = NDL_BSE_POS1;
- irby = NDL_BSE_POS3;
- sOutText = POS4_OUT;
- * RetVal = sOutText;
- }
- if (iXPos > BOUND_POS_3 && iXPos < BOUND_POS_4 && iYPos > BOUND_POS_7 && iYPos < BOUND_POS_8)
- { // Position 5
- iXval = POS5_X;
- iYval = POS5_Y;
- ilbx = NDL_BSE_POS4;
- ilby = NDL_BSE_POS3;
- irbx = NDL_BSE_POS1;
- irby = NDL_BSE_POS2;
- sOutText = POS5_OUT;
- * RetVal = sOutText;
- }
- if (iXPos > BOUND_POS_1 && iXPos < BOUND_POS_2 && iYPos > BOUND_POS_5 && iYPos < BOUND_POS_6)
- { // Position 6
- iXval = POS6_X;
- iYval = POS6_Y;
- ilbx = NDL_BSE_POS3;
- ilby = NDL_BSE_POS4;
- irbx = NDL_BSE_POS2;
- irby = NDL_BSE_POS1;
- sOutText = POS6_OUT;
- * RetVal = sOutText;
- }
- if (iXPos > BOUND_POS_1 && iXPos < BOUND_POS_2 && iYPos > BOUND_POS_3 && iYPos < BOUND_POS_4)
- { // Position 7
- iXval = POS7_X;
- iYval = POS7_Y;
- ilbx = NDL_BSE_POS2;
- ilby = NDL_BSE_POS4;
- irbx = NDL_BSE_POS3;
- irby = NDL_BSE_POS1;
- sOutText = POS7_OUT;
- * RetVal = sOutText;
- }
- if (iXPos > BOUND_POS_3 && iXPos < BOUND_POS_4 && iYPos > BOUND_POS_1 && iYPos < BOUND_POS_2)
- { // Position 8
- iXval = POS8_X;
- iYval = POS8_Y;
- ilbx = NDL_BSE_POS1;
- ilby = NDL_BSE_POS3;
- irbx = NDL_BSE_POS4;
- irby = NDL_BSE_POS2;
- sOutText = POS8_OUT;
- * RetVal = sOutText;
- }
-
- CDialog::OnLButtonDown(nFlags, point);
- }
-