ObjBase.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) =USTC= Fu Li
  3. *
  4. * Author : Fu Li
  5. * Create : 2003-3-30
  6. * Home : http://www.crazy-bit.com/
  7. * Mail : crazybit@263.net
  8. * History :
  9. */
  10. #ifndef __PCL_OBJECT_BASE__2003_03_30__H__
  11. #define __PCL_OBJECT_BASE__2003_03_30__H__
  12. #include "StdDefine.h"
  13. class FCObject ;
  14. class FCObjGraph ;
  15. //=============================================================================
  16. /**
  17. * The root of all objects
  18. */
  19. class FCObject
  20. {
  21. public:
  22. virtual ~FCObject() {}
  23. /**
  24. * Save object to memory / load object from memory.
  25. * @param bSave : save(true) or load(false)
  26. * @return return written/loaded bytes.
  27. */
  28. virtual int Serialize (bool bSave, BYTE* pSave) {return 0;}
  29. };
  30. //=============================================================================
  31. /**
  32. * Basic graphic object (encapsulate object's coordinate).
  33. */
  34. class FCObjGraph : public FCObject
  35. {
  36. public:
  37. FCObjGraph() {m_ptObj.x = m_ptObj.y = 0;}
  38. FCObjGraph& operator= (const FCObjGraph& GraphObj) {m_ptObj = GraphObj.m_ptObj; return *this;}
  39. /**
  40. * Save graphic object to memory / load graphic object from memory.
  41. * @see FCObject::Serialize
  42. */
  43. virtual int Serialize (bool bSave, BYTE* pSave)
  44. {
  45. bSave ? (*(POINT*)pSave = m_ptObj) : (m_ptObj = *(POINT*)pSave) ;
  46. return sizeof(m_ptObj) ;
  47. }
  48. /**
  49. * @name Object's position
  50. * object's position on canvas.
  51. */
  52. //@{
  53. /// Set position of graph.
  54. void SetGraphObjPos (int xPos, int yPos) {m_ptObj.x=xPos; m_ptObj.y=yPos;}
  55. /// Set position of graph.
  56. void SetGraphObjPos (const POINT& pos) {m_ptObj = pos;}
  57. /// Get position of graph.
  58. POINT GetGraphObjPos() const {return m_ptObj;}
  59. /// Offset position of graph.
  60. void OffsetGraphObj (int xOff, int yOff) {m_ptObj.x += xOff; m_ptObj.y += yOff;}
  61. //@}
  62. /**
  63. * @name Coordinate transformation
  64. * canvas <==> layer
  65. */
  66. //@{
  67. /// canvas ==> layer
  68. void Canvas_to_Layer (POINT& pt) const
  69. {
  70. pt.x -= m_ptObj.x ; pt.y -= m_ptObj.y ;
  71. }
  72. void Canvas_to_Layer (RECT& rc) const
  73. {
  74. rc.left -= m_ptObj.x ;
  75. rc.top -= m_ptObj.y ;
  76. rc.right -= m_ptObj.x ;
  77. rc.bottom -= m_ptObj.y ;
  78. }
  79. /// layer ==> canvas
  80. void Layer_to_Canvas (POINT& pt) const
  81. {
  82. pt.x += m_ptObj.x ; pt.y += m_ptObj.y ;
  83. }
  84. void Layer_to_Canvas (RECT& rc) const
  85. {
  86. rc.left += m_ptObj.x ;
  87. rc.top += m_ptObj.y ;
  88. rc.right += m_ptObj.x ;
  89. rc.bottom += m_ptObj.y ;
  90. }
  91. //@}
  92. private:
  93. POINT m_ptObj ; // object position on canvas
  94. };
  95. //=============================================================================
  96. // inline implement
  97. //=============================================================================
  98. #endif