PCL_interface_zoom.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) =USTC= Fu Li
  3. *
  4. * Author : Fu Li
  5. * Create : 2005-2-27
  6. * Home : http://www.crazy-bit.com/
  7. * Mail : crazybit@263.net
  8. * History :
  9. */
  10. #ifndef __PCL_INTERFACE_ZOOMSCALE__2005_02_27__H__
  11. #define __PCL_INTERFACE_ZOOMSCALE__2005_02_27__H__
  12. #include "StdDefine.h"
  13. class PCL_Interface_ZoomScale ;
  14. //=============================================================================
  15. /**
  16. * Zoom scale support.
  17. */
  18. class PCL_Interface_ZoomScale
  19. {
  20. public:
  21. PCL_Interface_ZoomScale() : m_nScale(1) {}
  22. virtual ~PCL_Interface_ZoomScale() {}
  23. /** Set zoom scale. */
  24. void SetZoomScale (int nScale) {m_nScale = nScale; assert(nScale != 0);}
  25. /** Get zoom scale. */
  26. int GetZoomScale() const {return m_nScale;}
  27. /** @name Coordinate transformation
  28. scaled <==> actual
  29. */
  30. //@{
  31. /// Convert point.
  32. void Scaled_to_Actual (POINT& pt) const
  33. {
  34. if (m_nScale > 1)
  35. {
  36. pt.x /= m_nScale ;
  37. pt.y /= m_nScale ;
  38. }
  39. else
  40. if (m_nScale < -1)
  41. {
  42. pt.x *= -m_nScale ;
  43. pt.y *= -m_nScale ;
  44. }
  45. }
  46. /// Convert rect.
  47. void Scaled_to_Actual (RECT& rc) const
  48. {
  49. Scaled_to_Actual (*(POINT*)&rc.left) ;
  50. Scaled_to_Actual (*(POINT*)&rc.right) ;
  51. }
  52. /// Convert point.
  53. void Actual_to_Scaled (POINT& pt) const
  54. {
  55. if (m_nScale > 1)
  56. {
  57. pt.x *= m_nScale ;
  58. pt.y *= m_nScale ;
  59. }
  60. else
  61. if (m_nScale < -1)
  62. {
  63. pt.x /= -m_nScale ;
  64. pt.y /= -m_nScale ;
  65. }
  66. }
  67. /// Convert rect.
  68. void Actual_to_Scaled (RECT& rc) const
  69. {
  70. Actual_to_Scaled (*(POINT*)&rc.left) ;
  71. Actual_to_Scaled (*(POINT*)&rc.right) ;
  72. }
  73. //@}
  74. private:
  75. int m_nScale ;
  76. } ;
  77. //=============================================================================
  78. // inline implement
  79. //=============================================================================
  80. #endif