toppane.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #include "pch.h"
  2. /////////////////////////////////////////////////////////////////////////////
  3. //
  4. // TopPane
  5. //
  6. /////////////////////////////////////////////////////////////////////////////
  7. class TopPaneSurfaceSite : public SurfaceSite {
  8. private:
  9. TopPane* m_ptopPane;
  10. public:
  11. TopPaneSurfaceSite(TopPane* ptopPane) :
  12. m_ptopPane(ptopPane)
  13. {
  14. }
  15. void UpdateSurface(Surface* psurface)
  16. {
  17. m_ptopPane->RepaintSurface();
  18. }
  19. };
  20. /////////////////////////////////////////////////////////////////////////////
  21. //
  22. // TopPane
  23. //
  24. /////////////////////////////////////////////////////////////////////////////
  25. TopPane::TopPane(Engine* pengine, SurfaceType stype, bool bColorKey, TopPaneSite* psite, Pane* pchild) :
  26. Pane(pchild),
  27. m_pengine(pengine),
  28. m_stype(stype),
  29. m_psurface(pengine->CreateSurface(WinPoint(1, 1), stype, new TopPaneSurfaceSite(this))),
  30. m_psite(psite),
  31. m_bColorKey(bColorKey),
  32. m_bNeedLayout(true)
  33. {
  34. if (m_bColorKey) {
  35. m_psurface->SetColorKey(Color(0, 0, 0));
  36. }
  37. SetSize(WinPoint(1, 1));
  38. }
  39. void TopPane::RepaintSurface()
  40. {
  41. m_bNeedPaint = true;
  42. m_bPaintAll = true;
  43. }
  44. void TopPane::NeedLayout()
  45. {
  46. if (!m_bNeedLayout) {
  47. m_bNeedLayout = true;
  48. m_psite->SizeChanged();
  49. }
  50. }
  51. void TopPane::NeedPaintInternal()
  52. {
  53. if (!m_bNeedPaint) {
  54. m_bNeedPaint = true;
  55. m_psite->SurfaceChanged();
  56. }
  57. }
  58. void TopPane::Paint(Surface* psurface)
  59. {
  60. // psurface->FillSurface(Color(0.8f, 0.5f, 1.0f));
  61. }
  62. void TopPane::Evaluate()
  63. {
  64. if (m_bNeedLayout) {
  65. m_bNeedLayout = false;
  66. WinPoint sizeOld = GetSize();
  67. UpdateLayout();
  68. if (GetSize() != sizeOld) {
  69. m_bNeedPaint = true;
  70. m_bPaintAll = true;
  71. m_psurface = NULL;
  72. m_psurface =
  73. m_pengine->CreateSurface(
  74. GetSize(),
  75. m_stype,
  76. new TopPaneSurfaceSite(this)
  77. );
  78. if (m_bColorKey) {
  79. m_psurface->SetColorKey(Color(0, 0, 0));
  80. }
  81. }
  82. }
  83. }
  84. void TopPane::UpdateLayout()
  85. {
  86. DefaultUpdateLayout();
  87. }
  88. bool g_bPaintAll = false;
  89. void TopPane::UpdateBits()
  90. {
  91. ZEnter("TopPane::UpdateBits()");
  92. if (m_bNeedPaint) {
  93. ZTrace("m_bNeedPaint == true");
  94. if (CalcPaint()) {
  95. m_bNeedPaint = true;
  96. m_bPaintAll = true;
  97. }
  98. ZTrace("after CalcPaint() m_bNeedPaint ==" + ZString(m_bNeedPaint));
  99. ZTrace("after CalcPaint() m_bPaintAll ==" + ZString(m_bPaintAll ));
  100. m_bPaintAll |= g_bPaintAll;
  101. InternalPaint(m_psurface);
  102. m_bNeedPaint = false;
  103. }
  104. ZExit("TopPane::UpdateBits()");
  105. }
  106. const WinPoint& TopPane::GetSurfaceSize()
  107. {
  108. Evaluate();
  109. return GetSize();
  110. }
  111. Surface* TopPane::GetSurface()
  112. {
  113. Evaluate();
  114. UpdateBits();
  115. return m_psurface;
  116. }
  117. Point TopPane::TransformLocalToImage(const WinPoint& point)
  118. {
  119. return
  120. m_psite->TransformLocalToImage(
  121. GetPanePoint(
  122. Point::Cast(point)
  123. )
  124. );
  125. }
  126. Point TopPane::GetPanePoint(const Point& point)
  127. {
  128. return
  129. Point(
  130. point.X(),
  131. (float)GetSize().Y() - 1.0f - point.Y()
  132. );
  133. }
  134. MouseResult TopPane::HitTest(IInputProvider* pprovider, const Point& point, bool bCaptured)
  135. {
  136. return Pane::HitTest(pprovider, GetPanePoint(point), bCaptured);
  137. }
  138. MouseResult TopPane::Button(
  139. IInputProvider* pprovider,
  140. const Point& point,
  141. int button,
  142. bool bCaptured,
  143. bool bInside,
  144. bool bDown
  145. ) {
  146. return Pane::Button(pprovider, GetPanePoint(point), button, bCaptured, bInside, bDown);
  147. }