QSelectTracker.h
Upload User: xp9161
Upload Date: 2009-12-21
Package Size: 70k
Code Size: 2k
Category:

Windows Develop

Development Platform:

Visual C++

  1. #pragma once
  2. // ==============
  3. // QSelectTracker
  4. //
  5. // This class maintains a CRect m_Rect, which can be sized by the mouse.
  6. // The rectangle starts with zero size at the starting point of Track().
  7. //
  8. // If Shift is pressed, the rectangle is a square, and dragging is
  9. // restricted to horizontal, vertical and diagonals.
  10. // 
  11. // If Alt is pressed, resizing occurs with respect to the center. The center is not moved.
  12. //
  13. // If the space bar is pressed, the rectangle is dragged.
  14. //===============================
  15. // Version 1.0, August 29, 2003
  16. // (c) Sjaak Priester, Amsterdam
  17. // www.sjaakpriester.nl
  18. //
  19. // Freeware. Use at your own risk. Comments welcome.
  20. #include "QTracker.h"
  21. class QSelectTracker :
  22. public QTracker
  23. {
  24. public:
  25. // Construction
  26. QSelectTracker(CWnd * pWnd);
  27. virtual ~QSelectTracker();
  28. // Methods
  29. CRect GetRect() const { return m_Rect; }
  30. void GetRect(LPRECT pRect) const { ((CRect *) pRect)->CopyRect(m_Rect); }
  31. // Get the resulting rectangle.
  32. void SetTrackPen(CPen * pPen);
  33. // Set the pen used for drawing the track rectangle
  34. // If pPen == NULL: set the default (dotted black, 1 pixel)
  35. // QRectTracker deletes the pen if no longer needed.
  36. int m_CenterSize;
  37. // The size of the midpoint drawn by tracking, in logical coordinates.
  38. // If zero, no midpoint is drawn. Default is 4.
  39. COLORREF m_colorCenter;
  40. // The color of the midpoint. Default is black.
  41. protected:
  42. // Overrides
  43. virtual int OnBeginTrack(UINT nFlags, CPoint point);
  44. virtual int OnEndTrack(int trackResult);
  45. virtual int OnMouseMessage(UINT msg, UINT nFlags, CPoint point);
  46. virtual void OnUpdate(CDC * pDC, UINT nMode);
  47. // Implementation
  48. void DrawCenter(CDC * pDC);
  49. CPoint RestrictPoint(CPoint point, CPoint pntBase, BOOL bDiagonalOnly);
  50. CRect m_Rect; // the current rectangle
  51. CPen *m_pTrackPen;
  52. };