Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

RmMFCSliderEdit.h

00001 //=================================================================================================//
00002 // filename: RmMFCSliderEdit.h                                                                     //
00003 //                                                                                                 //
00004 //           ATI Research, Inc.                                                                    //
00005 //           3D Application Research Group                                                         //
00006 //                                                                                                 //
00007 // description: Desclaration file for a numeric edit control with a popup slider that can be used  //
00008 //           to modify a float variable                                                            //
00009 //                                                                                                 //
00010 // notes:  To use this slider edit control:                                                        //
00011 //                                                                                                 //
00012 //    1. Create an edit control in your dialog                                                     //
00013 //    2. In your declaration file for that dialog (.h) create a variable of type CRmSliderEdit for   //
00014 //       that control                                                                              //
00015 //    3. In DoDataExchange(..) method of your dialog add DDX_CRmSliderEdit(..) as defined at the     //
00016 //       bottom of this file                                                                       //
00017 //    4. If you want to capture when the control has changed, add                                  //
00018 //          ON_EN_CHANGE( IDC_YOUR_CONTROL_ID, YourSliderEditUpdateMethod )                        //
00019 //       to the message map.                                                                       //
00020 //                                                                                                 //
00021 //       Retrieve the value of the control by calling GetNumericValue() method of that control.    //
00022 //       HOWEVER: this method gets called _every_ time that the slider edit control changed its    //
00023 //       text, even if the user just moved the window and the text got repainted.                  //
00024 //    5. If you just want to capture the slider changed event only when the popup slider changed   //
00025 //       the value of the control, add                                                             //                                         
00026 //          ON_MESSAGE( MSG_SLIDER_UPDATE, OnYourMethodSliderUpdate)                               //
00027 //       where                                                                                     //
00028 //          OnYourMethodSliderUpdate( UINT lParam, LONG wParam ) is a message handler function     //
00029 //       where wParam is not used, and lParam should be cast to CRmSliderEdit* which will point to   //
00030 //       the control that sent that message.                                                       //
00031 //                                                                                                 //
00032 //=================================================================================================//
00033 //   (C) 2004 ATI Research, Inc.  All rights reserved.                                             //
00034 //=================================================================================================//
00035 
00036 #ifndef _RM_MFC_UTILITIES_SLIDER_EDIT_H_
00037 #define _RM_MFC_UTILITIES_SLIDER_EDIT_H_
00038 
00039 #include <MFCUtilities/RmMFCTypes.h>
00040 #include <MFCUtilities/RmMFCNumericEdit.h>
00041 #include <MFCUtilities/RmMFCSliderEdit.h>
00042 
00043 // Forward Declaration
00044 class CPopupSlider;
00045 
00046 enum MouseButtonState
00047 {
00048    BUTTON_UP       = 0,
00049    BUTTON_DOWN     = 1,
00050    BUTTON_DISABLED = 2
00051 };
00052 
00053 #define NUM_SLIDER_NOTCHES    300
00054 
00055 // These constants are used to create popup slider ranges for editing the variables:
00056 #define MIN_NUM_EDIT   -100.0f
00057 #define MAX_NUM_EDIT    100.0f
00058 
00059 class RMMFCUTIL_API CRmSliderEdit: public CRmNumericEdit
00060 {
00061 
00062 public:
00063 
00064    // Default Constructor:
00065         CRmSliderEdit();        
00066    virtual ~CRmSliderEdit() {};
00067 
00068    // Create an instance of this control (manually):
00069    virtual BOOL Create( BOOL  bAlign, DWORD dwExStyle, LPCTSTR lpszWindowName, 
00070                         DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
00071 
00072    // Initialize this control:
00073    void Init( CWnd* pParent, float fValue, float fMin = MIN_NUM_EDIT, 
00074                                            float fMax = MAX_NUM_EDIT, 
00075                                            bool  bClamp = false,
00076                                            int   nNumNotches = NUM_SLIDER_NOTCHES, 
00077                                            int   nPrecision  = CTRL_DEFAULT_PRECISION,
00078                                            bool  bSigned     = true );
00079 
00080    // Sets whether the slider button belonging to this control is aligned on the right
00081    // or on the left of the edit field:
00082         void    SetAlignment( BOOL bAlign = TRUE /* TRUE == align to the left, FALSE == align to the right*/)
00083    {
00084       m_bAlign = bAlign;
00085    };
00086 
00087    void SetData( float fValue, 
00088                  float fMin        = MIN_NUM_EDIT, 
00089                  float fMax        = MAX_NUM_EDIT, 
00090                  bool  bClamp      = false,
00091                  int   nNumNotches = NUM_SLIDER_NOTCHES, 
00092                  int   nPrecision  = CTRL_DEFAULT_PRECISION,
00093                  bool  bSigned     = true );
00094             
00095    // Gets the range of the slider control     
00096    void GetSliderRange( float &fMin, float &fMax, bool &bClamp )
00097    {
00098       fMin     = m_fMin;
00099       fMax     = m_fMax;
00100       bClamp   = m_bClamp;
00101       
00102    } // end void GetSliderRange( float &fMin, float &fMax, bool &bClamp )
00103    
00104    // Sets the range of the slider control     
00105    void SetSliderRange( float fMin, float fMax, bool bClamp )
00106    {
00107       m_fMin   = fMin;
00108       m_fMax   = fMax;
00109       m_bClamp = bClamp;
00110       
00111    } // end void SetSliderRange( float fMin, float fMax, bool bClamp )
00112    
00113 protected:
00114 
00115    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
00116    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
00117         afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
00118         afx_msg UINT OnNcHitTest(CPoint point);
00119         afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
00120         afx_msg void OnNcPaint();
00121    afx_msg void OnUpdate();
00122    afx_msg void OnEnable(BOOL bEnable);
00123    afx_msg void OnSize(UINT nType, int nCx, int nCy);
00124         afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
00125    afx_msg void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );
00126 
00127 
00128    afx_msg LRESULT OnSliderDelta( WPARAM wParam, LPARAM lParam );
00129    afx_msg LRESULT OnSliderClose( WPARAM wParam, LPARAM lParam );
00130    afx_msg LRESULT OnSliderRangeChanged( WPARAM wParam, LPARAM lParam );
00131 
00132         DECLARE_MESSAGE_MAP()
00133 
00134 protected:
00135 
00136    // These methods handle the popup slider button on the control:
00137    void SliderButtonClicked();  
00138    void DrawSliderButton( MouseButtonState nState = BUTTON_UP );        
00139 
00140    // Checks if a given point is inside the slider's button's rect
00141    BOOL IsScreenPtInSliderButtonRect( CPoint point );   
00142 
00143         void CheckPositionRange();
00144         int  GetPosPerc();
00145 
00146         void OnInvalidInput();
00147 
00148    int  GetIntPosition();
00149 
00150 //----Class data members:
00151 protected:
00152 
00153    float    m_fMin, m_fMax;   // The range for this control, also used as the range for the popup slider
00154    bool     m_bClamp;         // Clamping flag
00155    int      m_nNumNotches;    // The number of "notches" to be used for slider
00156 
00157         BOOL     m_bAlign;         // Describes whether the popup slider is aligned on the right or the left of the edit field
00158         BOOL            m_bMouseCaptured;       // Has a mouse button been captured
00159         CRect      m_rcButtonRect;      // Window coordinates of the mouse button
00160 
00161    MouseButtonState m_buttonState;   // Current button state (up, down, or disabled)
00162 
00163    CPopupSlider* m_pSlider;   // The popup slider 
00164 
00165    CWnd* m_pParent;           // Parent window of this control, it will receive MSG_SLIDER_UPDATE when
00166                               // the popup slider's value was changed
00167 
00168 };
00169 
00170 //---------------------------------------------------------------------------------/
00171 // Since I allow the user to align the slider button on the left or on the right,  /
00172 // I need to define separate DDX method ( bAlign = TRUE means that the slider      /
00173 // will be aligned on the left of the control, and bAlign = FALSE means that it's  /
00174 // going to be aligned on the right.                                               /
00175 //---------------------------------------------------------------------------------/
00176 RMMFCUTIL_API void DDX_CRmSliderEdit( CDataExchange *pDX, int nIDC, CRmSliderEdit &rCFEC, BOOL bAlign);
00177 
00178 #endif 

Generated on Fri Feb 25 16:08:39 2005 for RenderMonkey SDK by doxygen 1.3.6