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

  1. /***************************************
  2. HTBKnob.dll
  3.  
  4. KnobDlg.cpp
  5.  
  6. Copyright TransEra Corporation 1999
  7. ***************************************/
  8. #include "stdafx.h"
  9. #include "HTBknob.h"
  10. #include "KnobDlg.h"
  11. #include <math.h>
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. #define TIMERVAL            100            // Timer timeout value
  20. #define POS1_X                125            // Needle position 1 X value
  21. #define POS1_Y                35            // Needle position 1 Y value
  22. #define POS2_X                165            // Needle position 2 X value
  23. #define POS2_Y                75            // Needle position 2 Y value
  24. #define POS3_X                165            // Needle position 3 X value
  25. #define POS3_Y                125            // Needle position 3 Y value
  26. #define POS4_X                125            // Needle position 4 X value
  27. #define POS4_Y                165            // Needle position 4 Y value
  28. #define POS5_X                75            // Needle position 5 X value
  29. #define POS5_Y                165            // Needle position 5 Y value
  30. #define POS6_X                35            // Needle position 6 X value
  31. #define POS6_Y                125            // Needle position 6 Y value
  32. #define POS7_X                35            // Needle position 7 X value
  33. #define POS7_Y                75            // Needle position 7 Y value
  34. #define POS8_X                75            // Needle position 8 X value
  35. #define POS8_Y                35            // Needle position 8 Y value    
  36. #define POS1_OUT            1            // Knob position number 1
  37. #define POS2_OUT            2            // Knob position number 2
  38. #define POS3_OUT            3            // Knob position number 3
  39. #define POS4_OUT            4            // Knob position number 4
  40. #define POS5_OUT            5            // Knob position number 5
  41. #define POS6_OUT            6            // Knob position number 6
  42. #define POS7_OUT            7            // Knob position number 7
  43. #define POS8_OUT            8            // Knob position number 8
  44. #define GREY_COLOR            189            // Back ground color
  45. #define COLOR_MAX            255            // Max color element value
  46. #define COLOR_MIN            0            // Min color element value
  47. #define CIRC_TL                30            // Top left circle element
  48. #define CIRC_LR                170            // Lower right circle element
  49. #define NEEDLE_SIDES        3            // A triangle has how many sides?
  50. #define FONT_SIZE            150            // Size of the display font
  51. #define FONT_TYPE            "Arial"        // Font Name
  52. #define DLG_X_SIZE            210            // Dialog box width
  53. #define DLG_Y_SIZE            270            // Dialog Box height
  54. #define POS_FMT_STR            "Setting=%d"// Position Text formatting string
  55. #define OUT_TEXT_1X            125            // X position of "1"
  56. #define OUT_TEXT_1Y            15            // Y position of "1"
  57. #define OUT_TEXT_1VAL        "1"            // Display symbol "1"
  58. #define OUT_TEXT_2X            167            // X position of "2"
  59. #define OUT_TEXT_2Y            60            // Y position of "2"
  60. #define OUT_TEXT_2VAL        "2"            // Display symbol "2"
  61. #define OUT_TEXT_3X            167            // X position of "3"
  62. #define OUT_TEXT_3Y            120            // Y position of "3"
  63. #define OUT_TEXT_3VAL        "3"            // Display symbol "3"
  64. #define OUT_TEXT_4X            125            // X position of "4"
  65. #define OUT_TEXT_4Y            165            // Y position of "4"
  66. #define OUT_TEXT_4VAL        "4"            // Display symbol "4"
  67. #define OUT_TEXT_5X            60            // X position of "5"
  68. #define OUT_TEXT_5Y            165            // Y position of "5"
  69. #define OUT_TEXT_5VAL        "5"            // Display symbol "5"
  70. #define OUT_TEXT_6X            20            // X position of "6"
  71. #define OUT_TEXT_6Y            120            // Y position of "6"
  72. #define OUT_TEXT_6VAL        "6"            // Display symbol "6"
  73. #define OUT_TEXT_7X            20            // X position of "7"
  74. #define OUT_TEXT_7Y            60            // Y position of "7"
  75. #define OUT_TEXT_7VAL        "7"            // Display symbol "7"
  76. #define OUT_TEXT_8X            60            // X position of "8"
  77. #define OUT_TEXT_8Y            15            // Y position of "8"
  78. #define OUT_TEXT_8VAL        "8"            // Display symbol "8"
  79. #define OUT_VALX            60            // X position of Knob Value
  80. #define OUT_VALY            200            // Y position of Knob Value
  81. #define BOUND_POS_1            20            // Boundary Position 1
  82. #define BOUND_POS_2            50            // Boundary Position 2
  83. #define BOUND_POS_3            60            // Boundary Position 3
  84. #define BOUND_POS_4            90            // Boundary Position 4
  85. #define BOUND_POS_5            110            // Boundary Position 5
  86. #define BOUND_POS_6            140            // Boundary Position 6
  87. #define BOUND_POS_7            150            // Boundary Position 7
  88. #define BOUND_POS_8            180            // Boundary Position 8
  89. #define NDL_BSE_POS1        91            // Needle Nase position 1
  90. #define NDL_BSE_POS2        97            // Needle Nase position 2
  91. #define NDL_BSE_POS3        103            // Needle Nase position 3
  92. #define NDL_BSE_POS4        109            // Needle Nase position 4
  93. #define STRT_DGRS            23            // Starting degrees
  94.  
  95. int iXPos = 0;                    // Mouse click X position
  96. int    iYPos = 0;                    // Mouse click Y position
  97.  
  98. int iXval = POS1_X;                // Needle Position variable X        
  99. int iYval = POS1_Y;                // Needle Position variable Y                    
  100. int iNdeg = STRT_DGRS;            // Degree value for point of needle
  101. int ilbx = NDL_BSE_POS1;        // X posistion of Needle left side base
  102. int ilby = NDL_BSE_POS2;        // Y posistion of Needle left side base
  103. int irbx = NDL_BSE_POS4;        // X posistion of Needle right side base
  104. int irby = NDL_BSE_POS3;        // Y posistion of Needle right side base    
  105.  
  106. short  sOutText = POS1_OUT;
  107.  
  108. CPoint m_Point;
  109.  
  110. KnobDlg::KnobDlg(CWnd* pParent /*=NULL*/)
  111.     : CDialog(KnobDlg::IDD, pParent) {
  112.     //{{AFX_DATA_INIT(KnobDlg)
  113.         // NOTE: the ClassWizard will add member initialization here
  114.     //}}AFX_DATA_INIT
  115. }
  116.  
  117.  
  118. void KnobDlg::DoDataExchange(CDataExchange* pDX) 
  119. {
  120.     CDialog::DoDataExchange(pDX);
  121.     //{{AFX_DATA_MAP(KnobDlg)
  122.         // NOTE: the ClassWizard will add DDX and DDV calls here
  123.     //}}AFX_DATA_MAP
  124. }
  125.  
  126.  
  127. BEGIN_MESSAGE_MAP(KnobDlg, CDialog)
  128.     //{{AFX_MSG_MAP(KnobDlg)
  129.     ON_WM_PAINT()
  130.     ON_WM_TIMER()
  131.     ON_WM_LBUTTONDOWN()
  132.     //}}AFX_MSG_MAP
  133. END_MESSAGE_MAP()
  134.  
  135.  
  136.  
  137. /////////////////////////////////////////////////////////////////////////////
  138. /*
  139.     Function:        KnobDlg::OnInitDialog
  140.  
  141.     Description:    Initializes window position and attributes
  142.  
  143.     Return type:    BOOL 
  144.  
  145.     Notes:            Starts timer and sets all of the values as characteristics 
  146.                     from HTBasic.
  147.         
  148. */
  149. BOOL KnobDlg::OnInitDialog()  
  150. {
  151.     CDialog::OnInitDialog();    
  152.     SetWindowPos(FromHandle(m_hWnd), g_Xpos, g_Ypos,
  153.                 DLG_X_SIZE, DLG_Y_SIZE, SWP_NOZORDER );
  154.     SetTimer(1,TIMERVAL,NULL);        
  155.     return TRUE;  
  156. }
  157.  
  158.  
  159. /////////////////////////////////////////////////////////////////////////////
  160. /*
  161.     Function:        KnobDlg::OnPaint
  162.  
  163.     Description:    Paints shapes, lines and colors onto dialog window
  164.  
  165.     Return type:    void 
  166.  
  167.     Notes:            The actual "painting" is done within this function
  168.                     while some computations are done to position the 
  169.                     needle in the correct place.
  170.         
  171. */
  172. void KnobDlg::OnPaint()  
  173. {
  174.     CString Disp;
  175.     CFont font;                
  176.     CPaintDC dc(this);
  177.  
  178.     CBrush grey    (RGB(GREY_COLOR, GREY_COLOR, GREY_COLOR));
  179.     CBrush red    (RGB(COLOR_MAX, COLOR_MIN, COLOR_MIN));
  180.     dc.SelectObject(&grey);
  181.     dc.Ellipse(CIRC_TL, CIRC_TL, CIRC_LR, CIRC_LR);
  182.     
  183.     POINT needle[NEEDLE_SIDES] = {ilbx, ilby ,irbx , irby ,iXval, iYval};
  184.     dc.SelectObject(&red);
  185.     dc.Polygon(needle, NEEDLE_SIDES);
  186.     Disp.Format(POS_FMT_STR, sOutText);
  187.     font.CreatePointFont(FONT_SIZE,_T(FONT_TYPE));
  188.     dc.SelectObject(&font);
  189.     dc.SetBkMode(TRANSPARENT);
  190.     dc.TextOut(OUT_VALX,OUT_VALY, Disp);
  191.     dc.TextOut(OUT_TEXT_1X, OUT_TEXT_1Y, OUT_TEXT_1VAL);
  192.     dc.TextOut(OUT_TEXT_2X, OUT_TEXT_2Y, OUT_TEXT_2VAL);
  193.     dc.TextOut(OUT_TEXT_3X, OUT_TEXT_3Y, OUT_TEXT_3VAL);
  194.     dc.TextOut(OUT_TEXT_4X, OUT_TEXT_4Y, OUT_TEXT_4VAL);
  195.     dc.TextOut(OUT_TEXT_5X, OUT_TEXT_5Y, OUT_TEXT_5VAL);
  196.     dc.TextOut(OUT_TEXT_6X, OUT_TEXT_6Y, OUT_TEXT_6VAL);
  197.     dc.TextOut(OUT_TEXT_7X, OUT_TEXT_7Y, OUT_TEXT_7VAL);
  198.     dc.TextOut(OUT_TEXT_8X, OUT_TEXT_8Y, OUT_TEXT_8VAL);    
  199.     
  200. }
  201.  
  202.  
  203. /////////////////////////////////////////////////////////////////////////////
  204. /*
  205.     Function:        KnobDlg::OnTimer
  206.  
  207.     Description:    Updates and tracks Dialog window    
  208.  
  209.     Return type:    void 
  210.     Argument:        UINT nIDEvent
  211.  
  212.     Notes:            This function makes the visual display move or update
  213.                     based on teh invalidation.
  214.         
  215. */
  216. void KnobDlg::OnTimer(UINT nIDEvent)  
  217. {    
  218.     Invalidate();    
  219.     CDialog::OnTimer(nIDEvent);
  220. }
  221.  
  222.  
  223. /////////////////////////////////////////////////////////////////////////////
  224. /*
  225.     Function:        KnobDlg::OnLButtonDown
  226.  
  227.     Description:    takes input from the mouse.
  228.  
  229.     Return type:    void 
  230.     Argument:        UINT nFlags
  231.     Argument:        CPoint point
  232.  
  233.     Notes:            when the mouse is clicked in a certain area.  This function
  234.                     takes those X and Y coordinates and decides if they are within
  235.                     the area of all of the different values on the knob.  if they are
  236.                     it moves the needle there and then sends a message back to HTBasic
  237.                     to change the value inb that pointer.
  238.         
  239. */
  240. void KnobDlg::OnLButtonDown(UINT nFlags, CPoint point)  
  241. {
  242.  
  243.         m_Point = point;
  244.         iXPos = m_Point.x;
  245.         iYPos = m_Point.y; //swing
  246.  
  247.     if (iXPos > BOUND_POS_5 && iXPos < BOUND_POS_6 && iYPos > BOUND_POS_1 && iYPos < BOUND_POS_2) 
  248.     {    // Position 1    
  249.         iXval = POS1_X;
  250.         iYval = POS1_Y;
  251.         ilbx = NDL_BSE_POS1;
  252.         ilby = NDL_BSE_POS2;
  253.         irbx = NDL_BSE_POS4;
  254.         irby = NDL_BSE_POS3;
  255.         sOutText = POS1_OUT;
  256.         *RetVal = sOutText;
  257.     }    
  258.     if (iXPos > BOUND_POS_7 && iXPos < BOUND_POS_8 && iYPos > BOUND_POS_3 && iYPos < BOUND_POS_4) 
  259.     {    // Position 2    
  260.         iXval = POS2_X;
  261.         iYval = POS2_Y;
  262.         ilbx = NDL_BSE_POS2;
  263.         ilby = NDL_BSE_POS1;
  264.         irbx = NDL_BSE_POS3;
  265.         irby = NDL_BSE_POS4;
  266.         sOutText = POS2_OUT;
  267.         *RetVal =  sOutText;
  268.     }
  269.     if (iXPos > BOUND_POS_7 && iXPos < BOUND_POS_8 && iYPos > BOUND_POS_5 && iYPos < BOUND_POS_6) 
  270.     { // Position 3    
  271.         iXval = POS3_X;
  272.         iYval = POS3_Y;
  273.         ilbx = NDL_BSE_POS3;
  274.         ilby = NDL_BSE_POS1;
  275.         irbx = NDL_BSE_POS2;
  276.         irby = NDL_BSE_POS4;
  277.         sOutText = POS3_OUT;
  278.         * RetVal = sOutText;
  279.     }
  280.     if (iXPos > BOUND_POS_5 && iXPos < BOUND_POS_6 && iYPos > BOUND_POS_7 && iYPos < BOUND_POS_8) 
  281.     { // Position 4
  282.         iXval = POS4_X;
  283.         iYval = POS4_Y;
  284.         ilbx = NDL_BSE_POS4;
  285.         ilby = NDL_BSE_POS2;
  286.         irbx = NDL_BSE_POS1;
  287.         irby = NDL_BSE_POS3;
  288.         sOutText = POS4_OUT;
  289.         * RetVal = sOutText;
  290.     }
  291.     if (iXPos > BOUND_POS_3 && iXPos < BOUND_POS_4 && iYPos > BOUND_POS_7 && iYPos < BOUND_POS_8) 
  292.     {    // Position 5    
  293.         iXval = POS5_X;
  294.         iYval = POS5_Y;
  295.         ilbx = NDL_BSE_POS4;
  296.         ilby = NDL_BSE_POS3;
  297.         irbx = NDL_BSE_POS1;
  298.         irby = NDL_BSE_POS2;
  299.         sOutText = POS5_OUT;
  300.         * RetVal = sOutText;
  301.     }
  302.     if (iXPos > BOUND_POS_1 && iXPos < BOUND_POS_2 && iYPos > BOUND_POS_5 && iYPos < BOUND_POS_6) 
  303.     {    // Position 6    
  304.         iXval = POS6_X;
  305.         iYval = POS6_Y;
  306.         ilbx = NDL_BSE_POS3;
  307.         ilby = NDL_BSE_POS4;
  308.         irbx = NDL_BSE_POS2;
  309.         irby = NDL_BSE_POS1;
  310.         sOutText = POS6_OUT;
  311.         * RetVal = sOutText;
  312.     }
  313.     if (iXPos > BOUND_POS_1 && iXPos < BOUND_POS_2 && iYPos > BOUND_POS_3 && iYPos < BOUND_POS_4) 
  314.     {        // Position 7    
  315.         iXval = POS7_X;
  316.         iYval = POS7_Y;
  317.         ilbx = NDL_BSE_POS2;
  318.         ilby = NDL_BSE_POS4;
  319.         irbx = NDL_BSE_POS3;
  320.         irby = NDL_BSE_POS1;
  321.         sOutText = POS7_OUT;
  322.         * RetVal = sOutText;
  323.     }
  324.     if (iXPos > BOUND_POS_3 && iXPos < BOUND_POS_4 && iYPos > BOUND_POS_1 && iYPos < BOUND_POS_2) 
  325.     {        // Position 8    
  326.         iXval = POS8_X;
  327.         iYval = POS8_Y;
  328.         ilbx = NDL_BSE_POS1;
  329.         ilby = NDL_BSE_POS3;
  330.         irbx = NDL_BSE_POS4;
  331.         irby = NDL_BSE_POS2;
  332.         sOutText = POS8_OUT;
  333.         * RetVal = sOutText;
  334.     }
  335.     
  336.     CDialog::OnLButtonDown(nFlags, point);
  337. }
  338.